// Path: base/src/main/java/ru/bartwell/ultradebugger/base/html/ErrorPage.java
// public class ErrorPage extends Page {
// 
//     public ErrorPage(String errorText) {
//         this(errorText, true);
//     }
// 
//     public ErrorPage(String errorText, boolean showHomeButton) {
//         Content content = new Content();
//         content.add(new RawContentPart("<p align=\"center\">" + errorText + "</p>"));
//         setContent(content);
//         setTitle("Error");
//         showHomeButton(showHomeButton);
//     }
// }
// 
// Path: base/src/main/java/ru/bartwell/ultradebugger/base/model/HttpResponse.java
// public class HttpResponse {
// 
//     private static final String CONTENT_TYPE_TEXT_HTML = "text/html";
// 
//     @NonNull
//     private Status mStatus;
//     @NonNull
//     private String mContentType;
//     @Nullable
//     private String mContent;
//     @Nullable
//     private InputStream mStream;
//     private long mContentLength;
//     @NonNull
//     Map<String, String> mHeaders = new HashMap<>();
// 
//     public HttpResponse(@NonNull String content) {
//         mStatus = Status.OK;
//         mContentType = CONTENT_TYPE_TEXT_HTML;
//         mContent = content;
//     }
// 
//     @SuppressWarnings("WeakerAccess")
//     public HttpResponse(@NonNull String contentType, @NonNull InputStream stream, long contentLength) {
//         mStatus = Status.OK;
//         mContentType = contentType;
//         mStream = stream;
//         mContentLength = contentLength;
//     }
// 
//     public HttpResponse(@NonNull String contentType, @NonNull InputStream stream) {
//         this(contentType, stream, -1);
//     }
// 
//     public HttpResponse(@NonNull Status status) {
//         mStatus = status;
//         mContentType = CONTENT_TYPE_TEXT_HTML;
//     }
// 
//     @Nullable
//     public String getContent() {
//         return mContent;
//     }
// 
//     @NonNull
//     public String getContentType() {
//         return mContentType;
//     }
// 
//     @NonNull
//     public Status getStatus() {
//         return mStatus;
//     }
// 
//     @Nullable
//     public InputStream getStream() {
//         return mStream;
//     }
// 
//     public long getContentLength() {
//         return mContentLength;
//     }
// 
//     public void addHeader(@NonNull String name, @NonNull String value) {
//         mHeaders.put(name, value);
//     }
// 
//     @NonNull
//     public Map<String, String> getHeaders() {
//         return mHeaders;
//     }
// 
//     public enum Status {
//         OK(200, "OK"),
//         BAD_REQUEST(400, "Bad request"),
//         NOT_FOUND(404, "Not found"),
//         INTERNAL_SERVER_ERROR(500, "Internal server error");
// 
//         private int mCode;
//         private String mDescription;
// 
//         Status(int code, String description) {
//             mCode = code;
//             mDescription = description;
//         }
// 
//         public int getCode() {
//             return mCode;
//         }
// 
//         public String getDescription() {
//             return mDescription;
//         }
//     }
// }


import android.annotation.TargetApi;
import android.app.Activity;
import android.content.pm.PackageManager;
import android.os.Build;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import java.lang.reflect.Field;
import java.util.Map;
import ru.bartwell.ultradebugger.base.html.ErrorPage;
import ru.bartwell.ultradebugger.base.model.HttpResponse;
            Field activitiesField = activityThreadClass.getDeclaredField("mActivities");
            activitiesField.setAccessible(true);

            Map<Object, Object> activities = (Map<Object, Object>) activitiesField.get(activityThread);
            if (activities == null)
                return null;

            for (Object activityRecord : activities.values()) {
                Class activityRecordClass = activityRecord.getClass();
                Field pausedField = activityRecordClass.getDeclaredField("paused");
                pausedField.setAccessible(true);
                if (!pausedField.getBoolean(activityRecord)) {
                    Field activityField = activityRecordClass.getDeclaredField("activity");
                    activityField.setAccessible(true);
                    Activity activity = (Activity) activityField.get(activityRecord);
                    return activity;
                }
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
        return null;
    }

    @Nullable
    public static HttpResponse requestPermissions(@NonNull String ... permissions) {
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
            Activity activity = getCurrentActivity();
            if (activity != null && !checkSelfPermissions(activity, permissions)) {
                activity.requestPermissions(permissions, 0);
// Path: base/src/main/java/ru/bartwell/ultradebugger/base/html/ErrorPage.java
// public class ErrorPage extends Page {
// 
//     public ErrorPage(String errorText) {
//         this(errorText, true);
//     }
// 
//     public ErrorPage(String errorText, boolean showHomeButton) {
//         Content content = new Content();
//         content.add(new RawContentPart("<p align=\"center\">" + errorText + "</p>"));
//         setContent(content);
//         setTitle("Error");
//         showHomeButton(showHomeButton);
//     }
// }
// 
// Path: base/src/main/java/ru/bartwell/ultradebugger/base/model/HttpResponse.java
// public class HttpResponse {
// 
//     private static final String CONTENT_TYPE_TEXT_HTML = "text/html";
// 
//     @NonNull
//     private Status mStatus;
//     @NonNull
//     private String mContentType;
//     @Nullable
//     private String mContent;
//     @Nullable
//     private InputStream mStream;
//     private long mContentLength;
//     @NonNull
//     Map<String, String> mHeaders = new HashMap<>();
// 
//     public HttpResponse(@NonNull String content) {
//         mStatus = Status.OK;
//         mContentType = CONTENT_TYPE_TEXT_HTML;
//         mContent = content;
//     }
// 
//     @SuppressWarnings("WeakerAccess")
//     public HttpResponse(@NonNull String contentType, @NonNull InputStream stream, long contentLength) {
//         mStatus = Status.OK;
//         mContentType = contentType;
//         mStream = stream;
//         mContentLength = contentLength;
//     }
// 
//     public HttpResponse(@NonNull String contentType, @NonNull InputStream stream) {
//         this(contentType, stream, -1);
//     }
// 
//     public HttpResponse(@NonNull Status status) {
//         mStatus = status;
//         mContentType = CONTENT_TYPE_TEXT_HTML;
//     }
// 
//     @Nullable
//     public String getContent() {
//         return mContent;
//     }
// 
//     @NonNull
//     public String getContentType() {
//         return mContentType;
//     }
// 
//     @NonNull
//     public Status getStatus() {
//         return mStatus;
//     }
// 
//     @Nullable
//     public InputStream getStream() {
//         return mStream;
//     }
// 
//     public long getContentLength() {
//         return mContentLength;
//     }
// 
//     public void addHeader(@NonNull String name, @NonNull String value) {
//         mHeaders.put(name, value);
//     }
// 
//     @NonNull
//     public Map<String, String> getHeaders() {
//         return mHeaders;
//     }
// 
//     public enum Status {
//         OK(200, "OK"),
//         BAD_REQUEST(400, "Bad request"),
//         NOT_FOUND(404, "Not found"),
//         INTERNAL_SERVER_ERROR(500, "Internal server error");
// 
//         private int mCode;
//         private String mDescription;
// 
//         Status(int code, String description) {
//             mCode = code;
//             mDescription = description;
//         }
// 
//         public int getCode() {
//             return mCode;
//         }
// 
//         public String getDescription() {
//             return mDescription;
//         }
//     }
// }


// Path: base/src/main/java/ru/bartwell/ultradebugger/base/utils/CommonUtils.java
import android.annotation.TargetApi;
import android.app.Activity;
import android.content.pm.PackageManager;
import android.os.Build;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import java.lang.reflect.Field;
import java.util.Map;
import ru.bartwell.ultradebugger.base.html.ErrorPage;
import ru.bartwell.ultradebugger.base.model.HttpResponse;

            Field activitiesField = activityThreadClass.getDeclaredField("mActivities");
            activitiesField.setAccessible(true);

            Map<Object, Object> activities = (Map<Object, Object>) activitiesField.get(activityThread);
            if (activities == null)
                return null;

            for (Object activityRecord : activities.values()) {
                Class activityRecordClass = activityRecord.getClass();
                Field pausedField = activityRecordClass.getDeclaredField("paused");
                pausedField.setAccessible(true);
                if (!pausedField.getBoolean(activityRecord)) {
                    Field activityField = activityRecordClass.getDeclaredField("activity");
                    activityField.setAccessible(true);
                    Activity activity = (Activity) activityField.get(activityRecord);
                    return activity;
                }
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
        return null;
    }

    @Nullable
    public static HttpResponse requestPermissions(@NonNull String ... permissions) {
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
            Activity activity = getCurrentActivity();
            if (activity != null && !checkSelfPermissions(activity, permissions)) {
                activity.requestPermissions(permissions, 0);
                return new HttpResponse(new ErrorPage("This module require additional permissions. Please allow it on your smartphone and reload this page.").toHtml());