导航菜单

页面标题

页面副标题

Tasker v6.6.3 - MonitorService.java 源代码

正在查看: Tasker v6.6.3 应用的 MonitorService.java JAVA 源代码文件

本页面展示 JAVA 反编译生成的源代码文件,支持语法高亮显示。 仅供安全研究与技术分析使用,严禁用于任何非法用途。请遵守相关法律法规。


package net.dinglisch.android.taskerm;

import android.annotation.SuppressLint;
import android.annotation.TargetApi;
import android.app.ActivityManager;
import android.app.AlarmManager;
import android.app.Notification;
import android.app.NotificationManager;
import android.app.PendingIntent;
import android.app.UiModeManager;
import android.bluetooth.BluetoothAdapter;
import android.bluetooth.BluetoothDevice;
import android.bluetooth.BluetoothProfile;
import android.content.BroadcastReceiver;
import android.content.ClipboardManager;
import android.content.ComponentName;
import android.content.ContentResolver;
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
import android.content.SharedPreferences;
import android.content.SyncStatusObserver;
import android.content.res.Configuration;
import android.content.res.Resources;
import android.database.Cursor;
import android.hardware.Sensor;
import android.hardware.SensorEvent;
import android.hardware.SensorEventListener;
import android.hardware.SensorManager;
import android.location.Location;
import android.location.LocationListener;
import android.location.LocationManager;
import android.media.AudioManager;
import android.net.ConnectivityManager;
import android.net.NetworkInfo;
import android.net.Uri;
import android.net.wifi.ScanResult;
import android.net.wifi.WifiInfo;
import android.net.wifi.WifiManager;
import android.nfc.NfcAdapter;
import android.nfc.NfcManager;
import android.os.BadParcelableException;
import android.os.Build;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.os.Parcel;
import android.os.PowerManager;
import android.provider.CallLog;
import android.provider.Settings;
import android.telephony.TelephonyDisplayInfo;
import android.telephony.TelephonyManager;
import android.text.TextUtils;
import android.text.format.DateFormat;
import android.util.Log;
import android.widget.RemoteViews;
import com.joaomgcd.taskerm.helper.HelperMonitorService;
import com.joaomgcd.taskerm.securesettings.AccessibilitySettingObservable;
import com.joaomgcd.taskerm.spawn.RFactory;
import com.joaomgcd.taskerm.util.ExtensionsContextKt;
import com.joaomgcd.taskerservercommon.ConstantsCommonTaskerServer;
import cyanogenmod.alarmclock.ClockContract;
import cyanogenmod.app.ProfileManager;
import cyanogenmod.os.Build;
import java.io.File;
import java.lang.ref.WeakReference;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Calendar;
import java.util.Collection;
import java.util.Collections;
import java.util.Comparator;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.ConcurrentLinkedDeque;
import java.util.concurrent.CopyOnWriteArrayList;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.TimeoutException;
import net.dinglisch.android.tasker.PluginResultReceiver;
import net.dinglisch.android.taskerm.MonitorService;
import net.dinglisch.android.taskerm.RunLog;
import net.dinglisch.android.taskerm.bp;
import net.dinglisch.android.taskerm.d6;
import net.dinglisch.android.taskerm.fn;
import net.dinglisch.android.taskerm.ho;
import net.dinglisch.android.taskerm.io;
import net.dinglisch.android.taskerm.ji;
import net.dinglisch.android.taskerm.ud;
import vf.a;

public class MonitorService extends MyService implements xf.d7, ze.e {
    private static long R1;
    private static long S1;
    private static volatile Boolean T1;
    private static volatile long U1;
    private static Map<String, ScanResult> V1;
    private static Map<String, Long> W1;
    private static long X1;
    private static long Y1;
    private static volatile Boolean Z1;
    private static Map<String, h1> a2;
    private static Map<String, h1> b2;
    private static String[][] c2;
    private static String d2;
    private static String e2;
    private static boolean f2;
    private static Map<Integer, Long> g2;
    private static float h2;
    private static float i2;
    private static float j2;
    private static float k2;
    private static final LinkedList<Integer> l2;
    private static boolean m2;
    private static boolean n2;
    private static boolean o2;
    private static pg.v1 p2;
    private static pg.v1 q2;
    private static final String[] w1;
    private static final long[] x1;
    private static final String[] y1;
    private static final int z1;
    private List<String> A;
    private SharedPreferences A0;
    private String B;
    public fo B0;
    private String C;
    private Set<Integer> C0;
    private Set<ComponentName> D;
    private PendingIntent D0;
    private long E;
    private long E0;
    private Location F;
    private Object F0;
    private long G;
    private PendingIntent G0;
    private int H;
    private long H0;
    private long I;
    private PendingIntent[] I0;
    private long J;
    private Object J0;
    private ClipboardManager.OnPrimaryClipChangedListener K;
    private long[] K0;
    private w1 L;
    private PendingIntent L0;
    private w1 M;
    private Object M0;
    private Object N;
    private long N0;
    private PhoneStateListenerCommon O;
    private Set<Integer> O0;
    private boolean P;
    private Map<Integer, wo> P0;
    private PendingIntent Q;
    private Map<Integer, v1> Q0;
    private boolean R;
    private Map<Integer, f1> R0;
    private boolean S;
    private Map<Integer, n7> S0;
    private int T;
    private Map<Integer, a0> T0;
    private int U;
    private Map<Integer, e0> U0;
    private boolean V;
    public Map<Integer, List<Integer>> V0;
    private BroadcastReceiver W;
    public Map<Integer, List<Integer>> W0;
    private int X;
    private List<bh> X0;
    private WifiManager.WifiLock Y;
    private com.joaomgcd.taskerm.util.h Y0;
    private int Z;
    private HashMap<Integer, List<bn>> Z0;
    private long a0;
    public List<ReceiverDynamicUser> a1;
    private long b0;
    private List<ReceiverDynamic> b1;
    private Map<String, Object> c0;
    private Set<String> c1;
    private int d0;
    private Map<Integer, net.dinglisch.android.taskerm.c> d1;
    private BroadcastReceiver e0;
    private final Object e1;
    private Handler f0;
    private Map<Integer, Integer> f1;
    private long g0;
    public ConcurrentLinkedDeque<Intent> g1;
    private long h0;
    private boolean h1;
    private int i0;
    private long i1;
    private BluetoothProfile.ServiceListener j0;
    private long j1;
    private int[] k0;
    private long k1;
    private Handler l0;
    private long l1;
    private boolean[] m0;
    private long m1;
    private ug[] n0;
    private zg.k0 n1;
    private SensorEventListener[] o0;
    private AccessibilitySettingObservable o1;
    private Sensor[] p0;
    public HelperMonitorService p1;
    private long q0;
    private ti.b q1;
    private long r0;
    private final Object r1;
    private final boolean[] s;
    private Handler s0;
    private final Object s1;
    private final boolean[] t;
    private SensorManager t0;
    private List<z> u;
    private ActivityManager u0;
    private String v;
    private AlarmManager v0;
    private long w;
    private ContentResolver w0;
    private long x;
    private LocationManager x0;
    private List<String> y;
    private WifiManager y0;
    private List<String> z;
    private Resources z0;
    private static final Object t1 = new Object();
    private static final int[] u1 = {0, -16777216, -10066330, -5592406, -1, -3407872, -30720, -10053376, -16737844, -8947849};
    private static final int[] v1 = {-1, 110, 30, 30, 150, 100, 80, 80, 50, 10, 10, 140, 160, 105, 105, 105, 105, 105, 105, 120, 40, 107, 145, 125, 103, 104, 122, 123, 142, 143, 40, 106, 2, 10, 175, 180, 80, 12, 185, 161, 10, 195, 154, 14, 135, 182, 141, 16, 148, 149, 136};
    private static final String[] A1 = {"WIFI-EN", "BT-EN", "BT-PAIR", "BT-LE-PAIR", "BT-UNKNOWN", "BT-LE-UNKNOWN", "APP-SERV", "APP-FORE", "MEDIA-HELD"};
    private static final Object B1 = new Object();
    private static final int[] C1 = {22, 0, 15, 12, 13, 16, 19, 24, 21, 17};
    private static final String[] D1 = {"stepsWhenOff", "accelWhenOff", "accelWhenOff", "proxWhenOff", "lightWhenOff", "pressureWhenOff", "tempWhenOff", "heartWhenOff", "humidityWhenOff", "magnetWhenOff"};
    private static final int[] E1 = {2, 1, 1, 1, 1, 1, 2, 2, 2, 2};
    private static final String[] F1 = {"STEP", "ACCEL", "SHAKE", "PROX", "LIGHT", "PRESSURE", "TEMP", "HEART", "HUMIDITY", "MAGNET"};
    private static Map<String, Integer> G1 = new HashMap();
    private static String H1 = "";
    private static long I1 = -1;
    private static boolean J1 = false;
    private static volatile int K1 = -1;
    private static volatile String L1 = null;
    private static String M1 = "";
    private static volatile int N1 = -1;
    private static volatile Map<Long, String> O1 = new HashMap();
    private static Map<Integer, Location> P1 = new ConcurrentHashMap();
    private static Map<String, LocationListener> Q1 = new HashMap();

    class a implements SensorEventListener {
        a() {
        }

        @Override
        public void onAccuracyChanged(Sensor sensor, int i) {
        }

        @Override
        public void onSensorChanged(SensorEvent sensorEvent) {
            long currentTimeMillis = System.currentTimeMillis();
            if (currentTimeMillis - MonitorService.this.k1 > 5000) {
                if (MonitorService.this.N2(sensorEvent, 8, 1)) {
                    try {
                        float f = sensorEvent.values[0];
                        if (MonitorService.this.A5(185)) {
                            MonitorService.this.G7(38, (int) f, true);
                        }
                        wp.S1(MonitorService.this, 44, String.valueOf(f));
                    } catch (Exception e) {
                        o7.H("M", "onSensorChanged (humidity)", e);
                    }
                }
                MonitorService.this.k1 = currentTimeMillis;
            }
        }
    }

    private class a0 {
        float[] a;
        float[] b;
        float[] c;
        int d;
        boolean e;
        float g;
        float h;
        float i;
        long j;
        float l;
        int m;
        int f = 0;
        long k = Long.MAX_VALUE;
        private boolean n = false;

        public a0(int i, float f, long j, String str, String str2) {
            this.e = false;
            this.l = f;
            this.j = j;
            this.d = i;
            ArrayList arrayList = new ArrayList();
            ArrayList arrayList2 = new ArrayList();
            ArrayList arrayList3 = new ArrayList();
            boolean a0 = i2.a0(str2, arrayList, arrayList2, arrayList3);
            this.e = !a0;
            if (!a0) {
                o7.G("M", "bad data for gesture " + str);
                return;
            }
            int size = arrayList.size();
            this.m = size;
            this.a = new float[size];
            this.b = new float[size];
            this.c = new float[size];
            for (int i2 = 0; i2 < this.m; i2++) {
                this.a[i2] = ((Float) arrayList.get(i2)).floatValue();
                this.b[i2] = ((Float) arrayList2.get(i2)).floatValue();
                this.c[i2] = ((Float) arrayList3.get(i2)).floatValue();
            }
            this.g = this.a[0];
            this.h = this.b[0];
            this.i = this.c[0];
        }

        private void d() {
            this.f = 0;
            this.g = this.a[0];
            this.h = this.b[0];
            this.i = this.c[0];
        }

        public boolean a(float f, float f2, float f3, long j) {
            if (Math.abs(this.g - f) >= this.l || Math.abs(this.h - f2) >= this.l || Math.abs(this.i - f3) >= this.l) {
                if (this.f <= 0) {
                    return false;
                }
                if (this.k == Long.MAX_VALUE) {
                    this.k = j;
                }
                if (j - this.k <= this.j) {
                    return false;
                }
                d();
                this.k = Long.MAX_VALUE;
                return false;
            }
            this.k = Long.MAX_VALUE;
            int i = this.f + 1;
            this.f = i;
            if (i == this.m) {
                d();
                return true;
            }
            this.g = this.a[i];
            this.h = this.b[i];
            this.i = this.c[i];
            return false;
        }

        public int b() {
            return this.f;
        }

        public boolean c() {
            return this.n;
        }

        public void e(boolean z) {
            if (this.n && !z) {
                d();
            }
            this.n = z;
        }
    }

    class b implements SensorEventListener {
        b() {
        }

        @Override
        public void onAccuracyChanged(Sensor sensor, int i) {
        }

        @Override
        public void onSensorChanged(SensorEvent sensorEvent) {
            long currentTimeMillis = System.currentTimeMillis();
            if (currentTimeMillis - MonitorService.this.l1 > 5000) {
                if (MonitorService.this.N2(sensorEvent, 5, 1)) {
                    try {
                        float f = sensorEvent.values[0];
                        if (MonitorService.this.A5(104)) {
                            MonitorService.this.G7(25, (int) f, true);
                        }
                        wp.S1(MonitorService.this, 65, String.valueOf(f));
                    } catch (Exception e) {
                        o7.H("M", "onSensorChanged (pressure)", e);
                    }
                }
                MonitorService.this.l1 = currentTimeMillis;
            }
        }
    }

    static class b0 extends Handler {
        WeakReference<MonitorService> a;

        b0(MonitorService monitorService) {
            this.a = new WeakReference<>(monitorService);
        }

        public static void b(MonitorService monitorService) {
            try {
                monitorService.A2(true, "MSHandler");
                er.k(monitorService.getApplicationContext(), "SmsObserver");
            } catch (NullPointerException e) {
                o7.l("M", "SMSobserver", e);
            }
        }

        @Override
        public void handleMessage(Message message) {
            final MonitorService monitorService = this.a.get();
            monitorService.t3(new Runnable() {
                @Override
                public final void run() {
                    MonitorService.b0.b(MonitorService.this);
                }
            }, "MSHandler");
        }
    }

    class c implements SensorEventListener {
        c() {
        }

        @Override
        public void onAccuracyChanged(Sensor sensor, int i) {
        }

        @Override
        public void onSensorChanged(SensorEvent sensorEvent) {
            long currentTimeMillis = System.currentTimeMillis();
            if (currentTimeMillis - MonitorService.this.m1 > 1000) {
                if (MonitorService.this.N2(sensorEvent, 9, 3)) {
                    try {
                        float[] fArr = sensorEvent.values;
                        float f = fArr[0];
                        float f2 = fArr[1];
                        float f3 = fArr[2];
                        float abs = Math.abs(f);
                        float abs2 = Math.abs(f2);
                        float abs3 = Math.abs(f3);
                        float f4 = abs + abs2 + abs3;
                        o7.f("M", "x: " + f + " y: " + f2 + " x: " + f3 + " tot: " + f4);
                        if (MonitorService.this.A5(106)) {
                            MonitorService.this.N7(31, new float[]{abs, abs2, abs3}, true);
                        }
                        wp.S1(MonitorService.this, 59, String.valueOf(f4));
                    } catch (Exception e) {
                        o7.H("M", "onSensorChanged (magnet)", e);
                    }
                }
                MonitorService.this.m1 = currentTimeMillis;
            }
        }
    }

    static class c0 extends Handler {
        WeakReference<MonitorService> a;

        c0(MonitorService monitorService) {
            this.a = new WeakReference<>(monitorService);
        }

        public static void b(int i, int i2, MonitorService monitorService) {
            if (i == 0) {
                try {
                    o7.f("M", "got ss " + i2 + " last " + MonitorService.N1);
                    if (i2 != MonitorService.N1) {
                        monitorService.G7(22, i2, true);
                        MonitorService.N1 = i2;
                        if (wp.e1(18)) {
                            wp.F1(monitorService, 18);
                            return;
                        }
                        return;
                    }
                    return;
                } catch (NullPointerException e) {
                    o7.l("M", "phoneStateListenerSig", e);
                    return;
                }
            }
            if (i != 1) {
                if (i == 2) {
                    o7.f("M", "-- got service state");
                    try {
                        if (i2 == 0) {
                            if (MonitorService.K1 != i2) {
                                gi.m();
                            }
                            monitorService.S2();
                        } else if (i2 == 1 || i2 == 2 || i2 == 3) {
                            o7.f("M", "no service, clear cell data");
                            MonitorService.N1 = -1;
                            MonitorService.O8(null);
                            if (wp.e1(17)) {
                                wp.C1(monitorService, 17);
                            }
                            if (wp.e1(18)) {
                                wp.F1(monitorService, 18);
                            }
                            if (wp.e1(78)) {
                                wp.C(monitorService, 78);
                            }
                        } else {
                            o7.k("M", "unknown service state: " + i2);
                        }
                        if (MonitorService.K1 != i2 && wp.e1(19)) {
                            wp.F1(monitorService, 19);
                        }
                        MonitorService.K1 = i2;
                        return;
                    } catch (NullPointerException e2) {
                        o7.l("M", "phoneStateListenerServ", e2);
                        return;
                    }
                }
                if (i != 3) {
                    return;
                }
            }
            try {
                if (monitorService.X9(8)) {
                    o7.f("M", "ignore cell update, in final wakelock stages");
                    return;
                }
                if (monitorService.O == null) {
                    o7.f("M", "ignore cell info, listener is null");
                    return;
                }
                if (i == 3) {
                    o7.f("M", "-- got cell info update");
                    MonitorService.s2(monitorService, true);
                } else {
                    o7.f("M", "-- got cell loc update");
                    monitorService.w7(monitorService.O.getLastLocation());
                }
                monitorService.E2(7, true);
                if (MonitorService.n2) {
                    return;
                }
                monitorService.P9();
            } catch (NullPointerException e3) {
                o7.l("M", "phoneStateListenerLoc", e3);
            }
        }

        @Override
        public void handleMessage(Message message) {
            final MonitorService monitorService = this.a.get();
            if (monitorService == null) {
                return;
            }
            final int i = message.what;
            final int i2 = message.arg1;
            monitorService.x3(new Runnable() {
                @Override
                public final void run() {
                    MonitorService.c0.b(i, i2, monitorService);
                }
            }, "PhoneStateHandler handleMessage");
        }
    }

    class d implements BluetoothProfile.ServiceListener {
        d() {
        }

        @Override
        public void onServiceConnected(int i, BluetoothProfile bluetoothProfile) {
            for (BluetoothDevice bluetoothDevice : bluetoothProfile.getConnectedDevices()) {
                MonitorService monitorService = MonitorService.this;
                monitorService.u4(monitorService, bluetoothDevice, true, "onServiceConnected", false);
            }
        }

        @Override
        public void onServiceDisconnected(int i) {
        }
    }

    static class d0 extends Handler {
        WeakReference<MonitorService> a;

        d0(MonitorService monitorService) {
            this.a = new WeakReference<>(monitorService);
        }

        public void c(MonitorService monitorService, float f, int i) {
            StringBuffer stringBuffer = new StringBuffer();
            stringBuffer.append("proxbuffer: level: ");
            stringBuffer.append(f);
            stringBuffer.append(" acc: ");
            stringBuffer.append(i);
            if (f < MonitorService.j2) {
                o7.f("M", "new prox min: " + f);
                MonitorService.j2 = f;
                monitorService.x7("pmi", f);
            }
            if (f > MonitorService.k2) {
                o7.f("M", "new prox max: " + f);
                MonitorService.k2 = f;
                monitorService.x7("pma", f);
            }
            if (MonitorService.k2 <= MonitorService.j2) {
                o7.f("M", "ignoring prox reading " + f + ", max <= min " + MonitorService.k2 + " < " + MonitorService.j2);
            } else {
                monitorService.M7(23, f >= MonitorService.j2 && f < MonitorService.k2, true);
            }
            o7.f("M", stringBuffer.toString());
        }

        @Override
        public void handleMessage(Message message) {
            final MonitorService monitorService = this.a.get();
            if (monitorService == null) {
                return;
            }
            final float f = message.arg1;
            final int i = message.arg2;
            monitorService.x3(new Runnable() {
                @Override
                public final void run() {
                    MonitorService.d0.this.c(monitorService, f, i);
                }
            }, "ProxHandler handleMessageSync");
        }
    }

    class e extends BroadcastReceiver {
        e() {
        }

        @Override
        public void onReceive(Context context, Intent intent) {
            try {
                com.joaomgcd.taskerm.util.ac M0 = com.joaomgcd.taskerm.util.ac.M0(context);
                if (!M0.i0()) {
                    MonitorService.this.p1.p0(M0.Q0());
                    return;
                }
                long currentTimeMillis = System.currentTimeMillis();
                MonitorService.this.X++;
                List<ScanResult> scanResults = MonitorService.this.y0.getScanResults();
                if (pp.F(scanResults)) {
                    o7.f("M", "got empty scan results after : " + (currentTimeMillis - MonitorService.this.a0) + "ms");
                } else {
                    o7.f("M", "got scan results after : " + (currentTimeMillis - MonitorService.this.a0) + "ms");
                    MonitorService.this.b0 = currentTimeMillis;
                    for (ScanResult scanResult : scanResults) {
                        o7.f("M", "new result for " + scanResult.BSSID + " / " + scanResult.SSID);
                        MonitorService.V1.put(scanResult.BSSID, scanResult);
                        MonitorService.W1.put(scanResult.BSSID, Long.valueOf(currentTimeMillis));
                    }
                }
                MonitorService.this.E2(170, true);
                MonitorService monitorService = MonitorService.this;
                if (monitorService.c2(170, monitorService.a0)) {
                    MonitorService.this.R9(true);
                }
            } catch (Throwable th2) {
                o7.l("M", "wifiScanResultsReceiver", th2);
            }
        }
    }

    private class e0 {
        private final float[] a;
        private float[] b;
        private int c;
        private int d;
        private int e;
        private int f;
        private boolean g = false;
        private int h;
        private float i;
        private long j;
        private long k;

        public e0(int i, j2 j2Var, float f) {
            float[] fArr = {45.0f, 33.0f, 25.0f, 10.0f, 1.5f};
            this.a = fArr;
            int i2 = 0;
            this.c = i;
            this.d = j2Var.y(1).v();
            this.e = j2Var.y(0).v();
            this.f = j2Var.y(2).v();
            this.b = new float[fArr.length];
            while (true) {
                float[] fArr2 = this.a;
                if (i2 >= fArr2.length) {
                    d();
                    return;
                } else {
                    this.b[i2] = (fArr2[i2] / 100.0f) * f;
                    i2++;
                }
            }
        }

        private void d() {
            this.h = 0;
            this.k = 0L;
            this.i = Float.MAX_VALUE;
            this.j = Long.MAX_VALUE;
        }

        public boolean b(float f, float f2, float f3, long j, long j2) {
            int i = this.d;
            float[] fArr = this.b;
            if (fArr == null || fArr.length < i || j - this.k <= 1000000000) {
                return false;
            }
            int i2 = this.e;
            if (i2 != 0) {
                f = i2 == 1 ? f3 : f2;
            }
            if (Math.abs(f) <= fArr[i]) {
                if (j - this.j <= 1000000000) {
                    return false;
                }
                d();
                return false;
            }
            float f4 = this.i;
            if (f4 == Float.MAX_VALUE || ((f4 >= 0.0f && f < 0.0f) || (f4 < 0.0f && f >= 0.0f))) {
                this.h++;
                this.i = f;
                this.j = j;
            }
            if (this.h <= this.f) {
                return false;
            }
            d();
            this.k = j;
            return true;
        }

        public boolean c() {
            return this.g;
        }

        public void e(boolean z) {
            if (this.g && !z) {
                d();
            }
            this.g = z;
        }
    }

    class f extends Handler {
        f() {
        }

        @Override
        public void handleMessage(Message message) {
            MonitorService.this.p1.Q1((BluetoothDevice) message.getData().getParcelable("android.bluetooth.device.extra.DEVICE"));
        }
    }

    private static class f0 extends Handler {
        WeakReference<MonitorService> a;

        f0(MonitorService monitorService) {
            this.a = new WeakReference<>(monitorService);
        }

        @Override
        public void handleMessage(Message message) {
            MonitorService monitorService = this.a.get();
            if (monitorService != null) {
                monitorService.c5(message.what);
            }
        }
    }

    class g extends BroadcastReceiver {
        g() {
        }

        @Override
        public void onReceive(Context context, Intent intent) {
            String action = intent.getAction();
            if (action.equals("android.bluetooth.adapter.action.DISCOVERY_STARTED")) {
                o7.f("M", "BT discovery started");
                return;
            }
            if (action.equals("android.bluetooth.adapter.action.DISCOVERY_FINISHED")) {
                o7.f("M", "BT discovery finished");
                if (MonitorService.this.i0 == 2) {
                    MonitorService.this.j9();
                    return;
                }
                return;
            }
            if (action.equals("android.bluetooth.device.action.FOUND") || action.equals("android.bluetooth.device.action.ACL_CONNECTED")) {
                BluetoothDevice bluetoothDevice = (BluetoothDevice) intent.getParcelableExtra("android.bluetooth.device.extra.DEVICE");
                o7.f("M", action + " for " + bluetoothDevice);
                MonitorService monitorService = MonitorService.this;
                monitorService.p1.y0(monitorService.w4(bluetoothDevice, 0, "scanResultReceiver," + action));
            }
        }
    }

    class h implements Comparator<io> {
        h() {
        }

        @Override
        public int compare(io ioVar, io ioVar2) {
            return Long.compare(ioVar.c(), ioVar2.c());
        }
    }

    class i extends BroadcastReceiver {
        final int a;
        final String b;
        final bn c;

        i(int i, String str, bn bnVar) {
            this.a = i;
            this.b = str;
            this.c = bnVar;
        }

        @Override
        public void onReceive(Context context, Intent intent) {
            boolean L0;
            io c = MonitorService.this.B0.c(this.a);
            boolean z = false;
            if (intent.hasExtra("net.dinglisch.android.tasker.EXTRA_NSR_DEPRECATED") && c != null) {
                o7.f("M", "plugin requested settings restore cancel for pid " + this.a);
                c.D1(false);
            }
            int resultCode = getResultCode();
            switch (resultCode) {
                case 16:
                case 17:
                    break;
                case 18:
                    MonitorService monitorService = MonitorService.this;
                    monitorService.P6(monitorService, "UNKNOWN", this.b, this.c);
                    if (!this.c.H1()) {
                        o7.f("M", this.b + ": no cached query result, do nothing");
                        return;
                    }
                    resultCode = this.c.v1();
                    o7.f("M", this.b + ": retrieved cached query result: " + resultCode);
                    z = true;
                    break;
                default:
                    o7.k("M", this.b + ": unexpected state result code " + resultCode);
                    return;
            }
            if (resultCode == 16) {
                MonitorService monitorService2 = MonitorService.this;
                monitorService2.P6(monitorService2, "SATISFIED", this.b, this.c);
                L0 = !this.c.L0();
                if (!z) {
                    Bundle o = ji.o(this.b, getResultExtras(true));
                    o7.v(this.b + "vars", o);
                    MonitorService monitorService3 = MonitorService.this;
                    com.joaomgcd.taskerm.util.b7.l0(monitorService3.B0, monitorService3, c, o, "queryStatePluginonReceive");
                    com.joaomgcd.taskerm.structuredoutput.j.d(o, this.c);
                    this.c.g1(this.b, o);
                }
            } else {
                MonitorService monitorService4 = MonitorService.this;
                monitorService4.P6(monitorService4, "UNSATISFIED", this.b, this.c);
                L0 = this.c.L0();
            }
            if (this.c.K0() != L0) {
                StringBuilder sb = new StringBuilder();
                sb.append(this.b);
                sb.append(": change state status ");
                sb.append(L0 ? "inactive -> active" : "active -> inactive");
                o7.f("M", sb.toString());
                this.c.Q0(L0);
                if (MonitorService.this.B0.V(this.a)) {
                    HashSet hashSet = new HashSet();
                    hashSet.add(Integer.valueOf(this.a));
                    MonitorService.this.R4(hashSet, null, null, "queryStatePluginBroadcast", false);
                } else {
                    o7.G("M", "not handling changes for unknown profile ID " + this.a + ", from plugin code " + this.c.j());
                }
            }
            if (z) {
                return;
            }
            this.c.f1(resultCode);
            o7.f("M", this.b + ": cache query result code " + resultCode);
        }
    }

    class j extends BroadcastReceiver {
        final int a;
        final j2 b;
        final String c;

        j(int i, j2 j2Var, String str) {
            this.a = i;
            this.b = j2Var;
            this.c = str;
        }

        @Override
        public void onReceive(Context context, Intent intent) {
            MonitorService.this.U4(getResultCode(), this.a, this.b, this.c, getResultExtras(true), getAbortBroadcast());
        }
    }

    class k implements Comparator<io> {
        k() {
        }

        @Override
        public int compare(io ioVar, io ioVar2) {
            if (!ioVar.Z0(1) || !ioVar2.Z0(1)) {
                if (ioVar.Z0(3) && ioVar2.Z0(3)) {
                    return Float.valueOf(((n7) ioVar.T0(3)).m1()).compareTo(Float.valueOf(((n7) ioVar2.T0(3)).m1()));
                }
                return 0;
            }
            wo woVar = (wo) ioVar.T0(1);
            wo woVar2 = (wo) ioVar2.T0(1);
            MonitorService monitorService = MonitorService.this;
            Bundle l0 = com.joaomgcd.taskerm.util.b7.l0(monitorService.B0, monitorService, ioVar, null, "enlistActiveProfiles1");
            MonitorService monitorService2 = MonitorService.this;
            return Integer.valueOf(woVar.w1() ? woVar.h1(MonitorService.this, l0) : 0).compareTo(Integer.valueOf(woVar2.w1() ? woVar2.h1(MonitorService.this, com.joaomgcd.taskerm.util.b7.l0(monitorService2.B0, monitorService2, ioVar2, null, "enlistActiveProfiles2")) : 0));
        }
    }

    class l extends Handler {
        final Set a;
        final boolean b;

        l(Set set, boolean z) {
            this.a = set;
            this.b = z;
        }

        @Override
        public void handleMessage(Message message) {
            if (MonitorService.J1) {
                this.a.add(8);
            }
            USBHandler.f(MonitorService.this, this.a);
            MonitorService.this.L7(4, this.a, this.b);
        }
    }

    class m extends Handler {
        m() {
        }

        public void b(BluetoothDevice bluetoothDevice) {
            MonitorService monitorService = MonitorService.this;
            monitorService.p1.y0(monitorService.w4(bluetoothDevice, 2, "gatt ocsc"));
        }

        @Override
        public void handleMessage(Message message) {
            final BluetoothDevice bluetoothDevice = (BluetoothDevice) message.getData().getParcelable("android.bluetooth.device.extra.DEVICE");
            MonitorService.this.x3(new Runnable() {
                @Override
                public final void run() {
                    MonitorService.m.this.b(bluetoothDevice);
                }
            }, "pingMatchingPairedBTDevices");
        }
    }

    class n implements SyncStatusObserver {
        n() {
        }

        @Override
        public void onStatusChanged(int i) {
            o7.f("M", "sync change " + i);
            MonitorService.this.v7(true);
        }
    }

    class o implements bp.a {
        o() {
        }

        @Override
        public void a() {
            long currentTimeMillis = System.currentTimeMillis() - MonitorService.this.E;
            long o4 = MonitorService.this.o4();
            o7.f("M", "sm triggered checkPeriod " + o4 + "ms elapsedSinceLastCheckMS " + currentTimeMillis + "ms");
            if (currentTimeMillis >= o4) {
                o7.f("M", "past initial period, start check");
                MonitorService.this.r5(false);
                return;
            }
            long j = o4 - currentTimeMillis;
            o7.f("M", "within initial period, set alarm for remaining " + j + "ms");
            if (j >= 3000) {
                MonitorService.this.z9(j, false);
            } else {
                o7.f("M", "< 3s remaining, check immediately");
                MonitorService.this.r5(false);
            }
        }
    }

    class p implements LocationListener {
        final String i;

        p(String str) {
            this.i = str;
        }

        @Override
        public void onLocationChanged(Location location) {
            double d;
            float f;
            float accuracy = location.getAccuracy();
            double latitude = location.getLatitude();
            double longitude = location.getLongitude();
            o7.f("M", "FIX: " + this.i + " A:" + ((int) accuracy));
            for (Map.Entry entry : MonitorService.this.S0.entrySet()) {
                Integer num = (Integer) entry.getKey();
                int intValue = num.intValue();
                n7 n7Var = (n7) entry.getValue();
                Location location2 = (Location) MonitorService.P1.get(num);
                if (location2 != null && latitude == location2.getLatitude() && longitude == location2.getLongitude() && accuracy == location2.getAccuracy()) {
                    f = accuracy;
                    d = latitude;
                } else {
                    d = latitude;
                    f = accuracy;
                    if (n7Var.b1(latitude, longitude, accuracy, this.i, n7.s1(MonitorService.this.x0, "gps"))) {
                        HashSet hashSet = new HashSet();
                        hashSet.add(num);
                        MonitorService.this.S4(hashSet, null, "locationChanged");
                        MonitorService.P1.put(num, location);
                        MonitorService.this.t8(intValue, location);
                        MonitorService.this.d9(intValue, n7Var, "locListener");
                    }
                }
                accuracy = f;
                latitude = d;
            }
            long currentTimeMillis = System.currentTimeMillis();
            if (!this.i.equals("gps")) {
                MonitorService.this.L9("network");
                n7.G1(MonitorService.this, location);
                wp.r(MonitorService.this);
                return;
            }
            wp.K1(System.currentTimeMillis() - location.getTime());
            location.setTime(currentTimeMillis);
            if (n7.Z0(MonitorService.this.F, location)) {
                MonitorService.this.H++;
                if (MonitorService.this.H > 1) {
                    MonitorService.this.L9("gps");
                    if (MonitorService.n2 && MonitorService.this.s[1]) {
                        MonitorService.this.p8(1);
                    }
                }
            } else {
                MonitorService.this.H = 0;
            }
            MonitorService.this.F = location;
            n7.F1(MonitorService.this, location);
            wp.q(MonitorService.this);
        }

        @Override
        public void onProviderDisabled(String str) {
        }

        @Override
        public void onProviderEnabled(String str) {
        }

        @Override
        public void onStatusChanged(String str, int i, Bundle bundle) {
        }
    }

    class q implements SensorEventListener {
        float i = Float.MAX_VALUE;
        float q = Float.MAX_VALUE;
        float r = Float.MAX_VALUE;
        private long s = 0;

        q() {
        }

        @Override
        public void onAccuracyChanged(Sensor sensor, int i) {
        }

        @Override
        public void onSensorChanged(SensorEvent sensorEvent) {
            if (MonitorService.this.N2(sensorEvent, 2, 3)) {
                float[] fArr = sensorEvent.values;
                float f = fArr[0];
                float f2 = fArr[1];
                float f3 = fArr[2];
                long j = sensorEvent.timestamp;
                long j2 = this.s;
                float f4 = j - j2;
                float f5 = ((f - this.i) / f4) * 1.0E7f;
                float f6 = ((f2 - this.q) / f4) * 1.0E7f;
                float f7 = ((f3 - this.r) / f4) * 1.0E7f;
                if (j2 != 0) {
                    for (e0 e0Var : MonitorService.this.U0.values()) {
                        if (e0Var.c() && e0Var.b(f5, f6, f7, sensorEvent.timestamp, this.s)) {
                            MonitorService.this.K5("net.dinglisch.android.tasker.SHAKUM", e0Var.c);
                        }
                    }
                }
                this.i = f;
                this.q = f2;
                this.r = f3;
                this.s = sensorEvent.timestamp;
            }
        }
    }

    class r implements SensorEventListener {
        private long i = -1;
        private int q = -1;
        private long r = 0;

        r() {
        }

        public void b(SensorEvent sensorEvent) {
            int i;
            if (MonitorService.this.N2(sensorEvent, 1, 3)) {
                float[] fArr = sensorEvent.values;
                float f = fArr[0];
                float f2 = fArr[1];
                float f3 = fArr[2];
                if (sensorEvent.timestamp - this.r >= MonitorService.this.r0) {
                    long currentTimeMillis = System.currentTimeMillis();
                    try {
                        if (MonitorService.this.A5(120) && currentTimeMillis - this.i > 500) {
                            int Z3 = MonitorService.this.Z3(f, f2, f3, r10.A0.getInt("oss", 0));
                            o7.f("M", String.valueOf(f) + "," + f2 + "," + f + " ori: " + Z3 + " last ori: " + this.q);
                            if (Z3 == this.q) {
                                boolean C5 = MonitorService.this.C5(19);
                                if (C5) {
                                    Integer E3 = pp.E3(MonitorService.this.n4(19, 0));
                                    if (E3 == null) {
                                        o7.G("M", "bad recorded state");
                                        i = -2;
                                    } else {
                                        i = E3.intValue();
                                    }
                                } else {
                                    i = -1;
                                }
                                if (!C5 || (i != -2 && Z3 != i)) {
                                    o7.f("M", "record ori: " + Z3);
                                    MonitorService.this.H7(19, Z3, true, true);
                                }
                            } else {
                                this.q = Z3;
                            }
                            this.i = currentTimeMillis;
                        }
                    } catch (Exception e) {
                        o7.H("M", "onSensorChanged (ori)", e);
                    }
                    try {
                        if (MonitorService.this.T0.size() > 0) {
                            boolean z = false;
                            for (a0 a0Var : MonitorService.this.T0.values()) {
                                if (a0Var.c()) {
                                    if (a0Var.a(f, f2, f3, sensorEvent.timestamp)) {
                                        MonitorService.this.K5("net.dinglisch.android.tasker.GESTRUM", a0Var.d);
                                    } else if (a0Var.b() != 0) {
                                        z = true;
                                    }
                                }
                            }
                            if (z) {
                                if (MonitorService.this.r0 != 20000000) {
                                    MonitorService.this.t0.unregisterListener(this);
                                    if (MonitorService.this.t0.registerListener(this, MonitorService.this.p0[1], 2)) {
                                        MonitorService.this.r0 = 20000000L;
                                    } else {
                                        MonitorService.this.R8(0, false);
                                        o7.k("M", "failed to re-register with sensor manager (UI rate)");
                                    }
                                }
                            } else if (MonitorService.this.r0 != MonitorService.this.q0) {
                                MonitorService.this.t0.unregisterListener(this);
                                if (MonitorService.this.t0.registerListener(this, MonitorService.this.p0[1], 3)) {
                                    MonitorService monitorService = MonitorService.this;
                                    monitorService.r0 = monitorService.q0;
                                } else {
                                    MonitorService.this.R8(0, false);
                                    o7.k("M", "failed to re-register with sensor manager (initial rate)");
                                }
                            }
                        }
                    } catch (Exception e2) {
                        o7.H("M", "onSensorChanged (gesture)", e2);
                    }
                    this.r = sensorEvent.timestamp;
                }
            }
        }

        @Override
        public void onAccuracyChanged(Sensor sensor, int i) {
        }

        @Override
        public void onSensorChanged(final SensorEvent sensorEvent) {
            MonitorService.this.p1.P(new Runnable() {
                @Override
                public final void run() {
                    MonitorService.r.this.b(sensorEvent);
                }
            });
        }
    }

    class s implements SensorEventListener {
        s() {
        }

        @Override
        public void onAccuracyChanged(Sensor sensor, int i) {
        }

        @Override
        public void onSensorChanged(SensorEvent sensorEvent) {
            if (MonitorService.this.N2(sensorEvent, 3, 1)) {
                try {
                    Sensor sensor = sensorEvent.sensor;
                    o7.f("M", "prox: level: " + sensorEvent.values[0] + " acc " + sensorEvent.accuracy + " max: " + (sensor != null ? sensor.getMaximumRange() : -1.0f));
                    if (MonitorService.this.s0 == null) {
                        o7.f("M", "ignore, prox buffer null");
                        return;
                    }
                    Message obtainMessage = MonitorService.this.s0.obtainMessage(0, (int) sensorEvent.values[0], sensorEvent.accuracy);
                    MonitorService.this.s0.removeMessages(0);
                    MonitorService.this.s0.sendMessageDelayed(obtainMessage, 150L);
                } catch (Exception e) {
                    o7.H("M", "onSensorChanged (prox)", e);
                }
            }
        }
    }

    class t implements SensorEventListener {
        private float i = -1.0f;

        t() {
        }

        @Override
        public void onAccuracyChanged(Sensor sensor, int i) {
        }

        @Override
        public void onSensorChanged(SensorEvent sensorEvent) {
            int i = 0;
            float f = sensorEvent.values[0];
            float f2 = this.i;
            long j = (long) (f2 == -1.0f ? 1.0f : f - f2);
            o7.f("M", "step " + f + " last " + this.i + " elapsed " + j);
            int i2 = 309;
            List<Integer> list = MonitorService.this.V0.get(309);
            if (list == null) {
                return;
            }
            for (Integer num : list) {
                io c = MonitorService.this.B0.c(num.intValue());
                if (c != null && c.h1() && c.t0() == c.I0() - 1) {
                    int O0 = c.O0(3);
                    j2 j2Var = (j2) c.T0(7);
                    int v = j2Var.y(i).v();
                    o7.f("M", "step: pid " + num + ": steps wanted: " + v + " pcount " + O0);
                    if (j > 0) {
                        long j2 = j;
                        while (true) {
                            O0++;
                            j2--;
                            if (v == 0 || O0 % v == 0) {
                                j2 j2Var2 = new j2(i2);
                                j2Var2.B1(i, O0);
                                j2Var.Q0(true);
                                if (MonitorService.this.x2(c, j2Var2, null)) {
                                    MonitorService.g2.put(num, Long.valueOf(System.currentTimeMillis()));
                                }
                                j2Var.w0();
                                o7.f("M", "step event " + O0);
                            }
                            if (j2 <= 0) {
                                break;
                            }
                            i = 0;
                            i2 = 309;
                        }
                        c.I1(3, O0);
                    }
                }
                i = 0;
                i2 = 309;
            }
            this.i = f;
        }
    }

    class u implements SensorEventListener {
        u() {
        }

        @Override
        public void onAccuracyChanged(Sensor sensor, int i) {
        }

        @Override
        public void onSensorChanged(SensorEvent sensorEvent) {
            if (MonitorService.this.N2(sensorEvent, 4, 1)) {
                MonitorService.this.p1.K2(sensorEvent);
            }
        }
    }

    class v implements SensorEventListener {
        v() {
        }

        @Override
        public void onAccuracyChanged(Sensor sensor, int i) {
        }

        @Override
        public void onSensorChanged(SensorEvent sensorEvent) {
            long currentTimeMillis = System.currentTimeMillis();
            if (currentTimeMillis - MonitorService.this.i1 > 5000) {
                if (MonitorService.this.N2(sensorEvent, 6, 1)) {
                    try {
                        float f = sensorEvent.values[0];
                        if (MonitorService.this.A5(180)) {
                            MonitorService.this.G7(35, (int) f, true);
                        }
                        wp.S1(MonitorService.this, 85, String.valueOf(f));
                    } catch (Exception e) {
                        o7.H("M", "onSensorChanged (temp)", e);
                    }
                }
                MonitorService.this.i1 = currentTimeMillis;
            }
        }
    }

    class w implements SensorEventListener {
        w() {
        }

        @Override
        public void onAccuracyChanged(Sensor sensor, int i) {
        }

        @Override
        public void onSensorChanged(SensorEvent sensorEvent) {
            long currentTimeMillis = System.currentTimeMillis();
            if (currentTimeMillis - MonitorService.this.j1 > 500) {
                int i = sensorEvent.accuracy;
                int i2 = -1;
                if (i != -1) {
                    if (i == 0) {
                        i2 = -2;
                    } else {
                        if (MonitorService.this.N2(sensorEvent, 7, 1)) {
                            try {
                                i2 = (int) sensorEvent.values[0];
                            } catch (Exception e) {
                                o7.H("M", "onSensorChanged (" + MonitorService.F1[7] + ")", e);
                            }
                        }
                        i2 = -3;
                    }
                }
                o7.f("M", "record level: " + i2);
                if (MonitorService.this.A5(182)) {
                    MonitorService.this.G7(45, i2, true);
                }
                wp.S1(MonitorService.this, 40, String.valueOf(i2));
                MonitorService.this.j1 = currentTimeMillis;
            }
        }
    }

    private static class x extends Handler {
        WeakReference<MonitorService> a;
        int b;

        x(MonitorService monitorService, int i) {
            this.a = new WeakReference<>(monitorService);
            this.b = i;
        }

        @Override
        public void handleMessage(Message message) {
            MonitorService monitorService = this.a.get();
            try {
                o7.f("M", "received calendar observer update: " + ug.k(this.b));
                monitorService.x4(this.b);
                er.k(monitorService.getApplicationContext(), ug.L(this.b));
            } catch (NullPointerException e) {
                o7.l("M", "calobserver", e);
            }
        }
    }

    static class y extends Handler {
        WeakReference<MonitorService> a;

        y(MonitorService monitorService) {
            this.a = new WeakReference<>(monitorService);
        }

        public static void b(MonitorService monitorService) {
            try {
                monitorService.A7(true);
                monitorService.C7(true);
                er.k(monitorService.getApplicationContext(), "CallLogObserver");
            } catch (NullPointerException e) {
                o7.l("M", "callLogObserver", e);
            }
        }

        @Override
        public void handleMessage(Message message) {
            final MonitorService monitorService = this.a.get();
            monitorService.t3(new Runnable() {
                @Override
                public final void run() {
                    MonitorService.y.b(MonitorService.this);
                }
            }, "CallLogHandler");
        }
    }

    public interface z {
        void a(int i, int i2, boolean z, boolean z2);

        void b(int i, boolean z, boolean z2, boolean z3);
    }

    static {
        String[] strArr = {"APP", "LOC-GPS", "LOC-NET", "WIFI-CHECK", "USER-ABSENT-WAKE", "WIFI-ENABLE", "GPS-TIMEOUT", "WIFI-TIMEOUT", "USER-ABSENT-WAKE-FINAL", "LOC-CELL", "PQ", "BT", "BT-ENABLE", "BT-TIMEOUT"};
        w1 = strArr;
        x1 = new long[strArr.length];
        String[] strArr2 = {"ACC", "LOC-GPS", "LOC-NET", "WIFI", "TIME", "APP", "CAL", "FOBS", "MBUT", "CLOG", "PSTATE", "ACCESS", "PROX", "LIGHT", "SMS", "SHAKE", "PRESSURE", "MAGNET", "CLIP", "TEMP", "BT", "HUMIDITY", "STEPC", "SYNC", "HEART", "CUSTOM-SETTINGS", "ACCESSIBILITY_SERVICES"};
        y1 = strArr2;
        z1 = strArr2.length;
        Boolean bool = Boolean.FALSE;
        T1 = bool;
        U1 = 0L;
        V1 = new ConcurrentHashMap();
        W1 = new HashMap();
        Z1 = bool;
        a2 = new ConcurrentHashMap();
        b2 = new HashMap();
        c2 = new String[51][];
        d2 = null;
        e2 = null;
        f2 = false;
        g2 = new ConcurrentHashMap();
        l2 = new LinkedList<>();
        m2 = true;
        n2 = true;
        o2 = false;
    }

    public MonitorService() {
        int i3 = z1;
        this.s = new boolean[i3];
        this.t = new boolean[i3];
        this.u = new ArrayList();
        this.v = null;
        this.w = -2L;
        this.x = -2L;
        this.B = "";
        this.C = "";
        this.D = null;
        this.F = null;
        this.H = 0;
        this.I = 0L;
        this.J = 0L;
        this.K = null;
        this.L = null;
        this.M = null;
        this.N = null;
        this.O = null;
        this.P = false;
        this.Q = null;
        this.R = false;
        this.S = false;
        this.V = false;
        this.W = null;
        this.X = 0;
        this.Y = null;
        this.Z = 0;
        this.c0 = null;
        this.d0 = 0;
        this.e0 = null;
        this.f0 = null;
        this.i0 = 0;
        this.j0 = null;
        this.k0 = new int[]{5, 1, 2, 3, 20};
        this.m0 = new boolean[A1.length];
        this.n0 = new ug[ug.D()];
        this.o0 = new SensorEventListener[10];
        this.p0 = new Sensor[10];
        this.q0 = -1L;
        this.s0 = null;
        this.t0 = null;
        this.u0 = null;
        this.v0 = null;
        this.w0 = null;
        this.x0 = null;
        this.y0 = null;
        this.B0 = null;
        this.C0 = null;
        this.D0 = null;
        this.E0 = 0L;
        this.F0 = new Object();
        this.G0 = null;
        this.I0 = new PendingIntent[ug.D()];
        this.J0 = new Object();
        this.K0 = new long[ug.D()];
        this.L0 = null;
        this.M0 = new Object();
        this.d1 = null;
        this.e1 = new Object();
        this.f1 = null;
        this.h1 = false;
        this.i1 = 0L;
        this.j1 = 0L;
        this.k1 = 0L;
        this.l1 = 0L;
        this.m1 = 0L;
        this.n1 = new zg.k0(this);
        this.o1 = new AccessibilitySettingObservable(this);
        this.p1 = new HelperMonitorService(this);
        this.r1 = new Object();
        this.s1 = new Object();
    }

    public void A2(boolean z2, String str) {
        o7.f("M", "----------- " + str + ": CHECK MS (UPD: " + z2 + ") ------------- ");
        this.y.clear();
        this.z.clear();
        this.A.clear();
        M2(z2);
        z2(z2);
        if (z2) {
            E2(147, z2);
        }
        o7.f("M", "check MS done");
    }

    private void A3(int i3, boolean z2) {
        String j3;
        if (i3 == 411 || i3 == 307 || (j3 = i2.j(i3)) == null) {
            return;
        }
        if (!pp.O1()) {
            mh.R(this, j3, z2);
        } else if (j3.equals(ReceiverStaticPhoneState.class.getName())) {
            ReceiverStaticPhoneState.b(z2);
        } else if (j3.equals(ReceiverStaticNotification.class.getName())) {
            ReceiverStaticNotification.b(z2);
        }
    }

    private void A4(Bundle bundle, boolean z2) {
        if (!bundle.containsKey("android.intent.extra.DOCK_STATE")) {
            o7.k("M", "DOCK_EVENT with no DOCK_STATE");
            return;
        }
        int i3 = bundle.getInt("android.intent.extra.DOCK_STATE");
        if (i3 == 0) {
            M7(6, false, z2);
            M7(7, false, z2);
            M7(36, false, z2);
        } else {
            if (i3 == 1) {
                M7(7, true, z2);
                return;
            }
            if (i3 == 2) {
                M7(6, true, z2);
                return;
            }
            if (i3 == 9 || i3 == 10) {
                M7(36, true, z2);
                return;
            }
            o7.k("M", "DOCK_EVENT with unrecognized DOCK_STATE: " + i3);
        }
    }

    public boolean A5(int i3) {
        Map<Integer, List<Integer>> map = this.W0;
        return map != null && map.containsKey(Integer.valueOf(i3));
    }

    @SuppressLint({"MissingPermission"})
    public void A7(boolean z2) {
        if (pp.z(this, "android.permission.READ_CALL_LOG", "MrecordMissedCalls")) {
            try {
                Cursor query = this.w0.query(CallLog.Calls.CONTENT_URI, new String[]{"number", "date"}, pp.Z1(new String[]{"type=3", "new=1"}), null, "date DESC");
                ArrayList arrayList = new ArrayList();
                if (query == null) {
                    o7.G("M", "missedCallCheck: null cursor from CallLog");
                } else {
                    while (query.moveToNext()) {
                        String string = query.getString(0);
                        arrayList.add(string);
                        if (z2) {
                            long j3 = query.getLong(1);
                            if (j3 > I1) {
                                sendBroadcast(new Intent("net.dinglisch.android.tasker.MCALLMYUM").putExtra("num", string));
                                I1 = j3;
                            }
                        }
                    }
                    query.close();
                }
                L7(21, arrayList, z2);
            } catch (Exception e3) {
                o7.l("M", "recordMissedCalls", e3);
            }
        }
    }

    private void A8() {
        File file;
        Iterator<Integer> it = this.B0.p2().iterator();
        while (it.hasNext()) {
            int intValue = it.next().intValue();
            io c3 = this.B0.c(intValue);
            Bundle l0 = com.joaomgcd.taskerm.util.b7.l0(this.B0, this, c3, null, "checkMatchTimesDays");
            for (int i3 = 0; i3 < c3.I0(); i3++) {
                if (c3.V0(i3) == 7) {
                    j2 j2Var = (j2) c3.S0(i3);
                    int j3 = j2Var.j();
                    if (i2.q(j3) == 30) {
                        String A2 = this.p1.A2(j2Var, 0, l0);
                        if (A2.startsWith(File.separator)) {
                            file = new File(A2);
                        } else {
                            File c1 = pp.c1();
                            file = c1 != null ? new File(c1, A2) : null;
                        }
                        if (file != null && file.exists()) {
                            Integer l22 = this.p1.l2(j2Var);
                            if (l22 == null) {
                                l22 = Integer.valueOf(bh.g(j3, file.isDirectory()));
                            }
                            this.X0.add(new bh(this, file.toString(), j3, l22.intValue(), intValue));
                        }
                    }
                }
            }
        }
    }

    private void A9() {
        synchronized (this.M0) {
            try {
                if (this.L0 == null) {
                    boolean z2 = false;
                    boolean Y6 = Y6(false);
                    o7.f("M", "startUAAA: need alarm: " + Y6);
                    if (Y6) {
                        this.E = System.currentTimeMillis();
                        boolean V3 = Settings.V3(this);
                        if (V3) {
                            boolean d3 = bp.d(this);
                            o7.f("M", "wantMotionDetect: " + V3 + " have: " + d3);
                            if (d3) {
                                z2 = k9();
                            }
                        }
                        if (!z2) {
                            long o4 = o4();
                            o7.f("M", "not listening SM, set alarm for " + o4);
                            z9(o4, true);
                        }
                    }
                } else {
                    o7.f("M", "don't start user-absent updates alarm / SM listener, alarm already set");
                }
            } catch (Throwable th2) {
                throw th2;
            }
        }
    }

    private boolean B2(String str) {
        boolean z2 = false;
        for (Map.Entry<Integer, f1> entry : this.R0.entrySet()) {
            f1 value = entry.getValue();
            if (value.Z0(this, str, this.D)) {
                d9(entry.getKey().intValue(), value, "checkMatchApp");
                z2 = true;
            }
        }
        return z2;
    }

    private void B3(boolean z2) {
        if (A5(150)) {
            boolean z3 = !z2 && x5(150);
            mh.R(this, USBHandler.class.getName(), z3);
            USBHandler.o(this, z3);
        }
    }

    private void B4(String str, Bundle bundle, List<j2> list) {
        String C = i2.C(str);
        o7.f("M", "handleEmailReceived: " + str + " -> " + C);
        j2 j2Var = new j2(425);
        StringBuilder sb = new StringBuilder();
        sb.append(C);
        sb.append(".intent.extra.FROM");
        String sb2 = sb.toString();
        String string = bundle.containsKey(sb2) ? bundle.getString(sb2) : "";
        String str2 = C + ".intent.extra.SUBJECT";
        String string2 = bundle.containsKey(str2) ? bundle.getString(str2) : "";
        String str3 = C + ".intent.extra.CC";
        String string3 = bundle.containsKey(str3) ? bundle.getString(str3) : "";
        String str4 = C + ".intent.extra.ACCOUNT";
        String string4 = bundle.containsKey(str4) ? bundle.getString(str4) : "";
        j2Var.o0(0, string);
        j2Var.o0(1, string2);
        j2Var.o0(2, string4);
        list.add(j2Var);
        Calendar x2 = ug.x();
        wp.S1(this, 33, string);
        wp.S1(this, 34, string3);
        wp.S1(this, 35, string2);
        wp.S1(this, 36, ug.i(this, x2));
        wp.S1(this, 37, ug.o(x2));
    }

    private boolean B5() {
        return A5(3) || y5(2080);
    }

    public void B6() {
        A2(false, "monitorResume");
    }

    private void B7(boolean z2) {
        NfcAdapter defaultAdapter;
        NfcManager s2 = ExtensionsContextKt.s2(this);
        M7(41, (s2 == null || (defaultAdapter = s2.getDefaultAdapter()) == null) ? false : defaultAdapter.isEnabled(), z2);
    }

    public static boolean B8(Context context) {
        return new com.joaomgcd.taskerm.util.yd(context).m();
    }

    @SuppressLint({"MissingPermission"})
    private void B9() {
        if (com.joaomgcd.taskerm.util.ac.M0(this).h0()) {
            o7.f("M", "start user-absent cell check");
            this.P = true;
            LocationManager S3 = S3();
            if (S3 != null) {
                if (this.Q != null) {
                    o7.f("M", "hmm, still have cell workaround intent... removing it");
                    S3.removeProximityAlert(this.Q);
                }
                if (this.A0.getBoolean("workForLoc", false)) {
                    o7.f("M", "startUserAbsentCellCheck: register a proximity alarm for cell workaround");
                    Intent intent = new Intent("xaskdn29021sn1naa");
                    intent.setComponent(new ComponentName(this, (Class<?>) ReceiverStaticAlwaysOn.class));
                    PendingIntent service = PendingIntent.getService(this, -1, intent, com.joaomgcd.taskerm.util.bi.m(1342177280, intent));
                    this.Q = service;
                    S3.addProximityAlert(0.0d, 0.0d, 1.7014117E38f, x1[9] + 500, service);
                }
            }
            gi.m();
            x9(9);
        }
    }

    private void C2(int i3) {
        if (this.x0 != null) {
            for (Map.Entry<Integer, Location> entry : P1.entrySet()) {
                Location value = entry.getValue();
                Integer key = entry.getKey();
                int intValue = key.intValue();
                if (i3 == -1 || i3 == intValue) {
                    n7 n7Var = this.S0.get(key);
                    if (n7Var.b1(value.getLatitude(), value.getLongitude(), value.getAccuracy(), value.getProvider(), n7.s1(this.x0, "gps"))) {
                        d9(intValue, n7Var, "checkMatchLocs");
                    }
                }
            }
        }
    }

    private void C3(boolean z2) {
        if (A5(105)) {
            mh.R(this, WebSearchHandler.class.getName(), !z2 && x5(105) && U6(8));
        }
    }

    private void C4(Bundle bundle) {
        if (bundle == null) {
            o7.k("BroadcastDecode", "error no intent extras");
            return;
        }
        String str = (String) pp.w0("BroadcastDecode", bundle, "task_name", String.class, true);
        if (str != null) {
            o7.f("M", "external call, task name " + str);
            Bundle bundle2 = null;
            if (!Settings.g1(this)) {
                if (!Kid.b(this)) {
                    pp.e0(this, 2131887519, 2131887284, 1);
                }
                ExecuteService.F0(this, str, null, false);
                o7.k("BroadcastDecode", "external access not enabled");
                return;
            }
            fo foVar = this.B0;
            if (foVar == null) {
                o7.G("M", "handleExternalCall no aptData");
                return;
            }
            fn M = foVar.M(str);
            if (M == null) {
                o7.f("M", "task " + str + " doesn't exist, read actions from intent");
                M = fo.Z1();
                if (Q1(M, bundle)) {
                    M.C(str);
                    Integer num = (Integer) pp.w0("BroadcastDecode", bundle, "task_priority", Integer.class, false);
                    if (num != null) {
                        if (TaskerIntent.e(num.intValue())) {
                            M.D2(num.intValue());
                        } else {
                            o7.G("BroadcastDecode", "task priority out of range, ignoring");
                        }
                    }
                } else {
                    M = null;
                }
            }
            if (M == null) {
                pp.e0(this, 2131887465, 2131887147, 0);
                ExecuteService.F0(this, str, null, false);
                return;
            }
            ArrayList arrayList = (ArrayList) pp.w0("BroadcastDecode", bundle, "params", ArrayList.class, false);
            if (arrayList != null) {
                if (arrayList.size() == 0) {
                    o7.G("BroadcastDecode", "ignoring empty param list");
                } else {
                    bundle2 = new Bundle();
                    for (int i3 = 0; i3 < arrayList.size(); i3++) {
                        String str2 = (String) arrayList.get(i3);
                        if (str2 == null) {
                            o7.G("BroadcastDecode", "ignoring null param value index " + i3);
                        } else {
                            String h1 = fn.h1(i3 + 1);
                            if (!wp.c1(h1)) {
                                o7.G("BroadcastDecode", "param: " + h1 + ": invalid variable name");
                            } else if (wp.W0(h1)) {
                                bundle2.putString(h1, str2);
                            } else {
                                o7.G("BroadcastDecode", "param: " + h1 + ": not a local variable name");
                            }
                        }
                    }
                }
            }
            ArrayList arrayList2 = (ArrayList) pp.w0("BroadcastDecode", bundle, "varNames", ArrayList.class, false);
            if (arrayList2 != null) {
                if (arrayList2.size() == 0) {
                    o7.G("BroadcastDecode", "ignoring empty names list");
                } else {
                    ArrayList arrayList3 = (ArrayList) pp.w0("BroadcastDecode", bundle, "varValues", ArrayList.class, true);
                    if (arrayList3 != null) {
                        if (arrayList3.size() != arrayList2.size()) {
                            o7.G("BroadcastDecode", "ignoring inconsistent var names and values lists");
                        } else {
                            if (bundle2 == null) {
                                bundle2 = new Bundle();
                            }
                            for (int i4 = 0; i4 < arrayList2.size(); i4++) {
                                String str3 = (String) arrayList2.get(i4);
                                String str4 = (String) arrayList3.get(i4);
                                if (str3 == null) {
                                    o7.G("BroadcastDecode", "ignoring null var name index " + i4);
                                } else if (str4 == null) {
                                    o7.G("BroadcastDecode", "ignoring null var value index " + i4);
                                } else if (!wp.c1(str3)) {
                                    o7.G("BroadcastDecode", "var: " + str3 + ": invalid name");
                                } else if (wp.W0(str3)) {
                                    bundle2.putString(str3, str4);
                                } else {
                                    o7.G("BroadcastDecode", "var: " + str3 + ": not a local variable name");
                                }
                            }
                        }
                    }
                }
            }
            ExecuteService.d6(this, M, 2, -1, -1, -1, null, null, "external", bundle2);
        }
    }

    public boolean C5(int i3) {
        return c2[i3] != null;
    }

    public void C6(int i3, String str) {
        if (!T6(i3)) {
            o7.f("M", y1[i3] + ": " + str + ": monitor restart: not running");
            return;
        }
        if (!this.s[i3]) {
            M9(i3, "resume");
            o7.f("M", y1[i3] + ": " + str + ": monitor restart: not needed, stop");
            return;
        }
        if (i3 != 5) {
            o7.f("M", y1[i3] + ": " + str + ": monitor resumption");
        }
        switch (i3) {
            case 0:
                O1(true);
                break;
            case 1:
                h9("gps");
                x9(1);
                break;
            case 2:
                h9("network");
                x9(2);
                break;
            case 3:
                x9(3);
                if (!C9(U6(0))) {
                    E2(170, true);
                    break;
                }
                break;
            case 4:
                W8();
                break;
            case 5:
                x9(0);
                break;
            case ClockContract.InstancesColumns.MISSED_STATE:
                l9(true);
                break;
            case 7:
                o9(false);
                this.X0.clear();
                A8();
                o9(true);
                break;
            case 8:
                pp.r1(this, true, false);
                break;
            case 9:
                m9(true);
                break;
            case 10:
                s9(true);
                break;
            case 11:
                MyAccessibilityService.t(this.U);
                break;
            case 12:
                k7(true);
                break;
            case 13:
                L6(true);
                break;
            case 14:
                if (this.w == -2) {
                    this.w = -1L;
                    t3(new Runnable() {
                        @Override
                        public final void run() {
                            MonitorService.this.B6();
                        }
                    }, "resumeMonitorIfNecessary");
                }
                p9(true);
                break;
            case 15:
                c9(true);
                break;
            case 16:
                e7(true);
                break;
            case 17:
                R6(true);
                break;
            case 18:
                n9(true);
                break;
            case 19:
                T9(true);
                break;
            case 20:
                x9(11);
                if (!f9()) {
                    E2(4, true);
                    break;
                }
                break;
            case 21:
                E5(true);
                break;
            case 22:
                H9(true);
                break;
            case 23:
                v9(true);
                break;
            case 24:
                D5(true);
                break;
            case 25:
                this.p1.I1(this.B0, this.n1);
                break;
            case 26:
                this.p1.E1(this.o1);
                break;
            default:
                o7.k("M", "bad monitor: " + i3);
                break;
        }
    }

    @SuppressLint({"MissingPermission"})
    public void C7(boolean z2) {
        if (com.joaomgcd.taskerm.util.ac.c0(this).h0() && pp.z(this, "android.permission.READ_CALL_LOG", "MrecordOutgoingCall")) {
            try {
                Cursor query = this.w0.query(CallLog.Calls.CONTENT_URI, new String[]{"number", "date", "duration"}, pp.Z1(new String[]{"type=2", "new=1"}), null, "date DESC");
                if (query == null) {
                    o7.G("M", "recordOutgoingCall: null cursor from CallLog");
                    return;
                }
                if (query.moveToFirst()) {
                    String string = query.getString(0);
                    long j3 = query.getLong(1);
                    wp.S1(this, 15, string);
                    wp.S1(this, 13, String.valueOf(query.getLong(2)));
                    wp.S1(this, 12, ug.h(this, j3));
                    wp.S1(this, 16, ug.m(j3));
                    String r2 = xg.r(this, string, "display_name");
                    if (!TextUtils.isEmpty(r2)) {
                        string = r2;
                    }
                    wp.S1(this, 14, string);
                }
                query.close();
            } catch (Exception e3) {
                o7.l("M", "recordOutgoingCall", e3);
            }
        }
    }

    public static void C8(Context context, boolean z2) {
        if (!z2 || pp.L2(context, MonitorService.class.getName())) {
            Intent intent = new Intent(context, (Class<?>) MonitorService.class);
            intent.putExtra("eventType", 9987);
            M6(context, intent);
        }
    }

    private boolean C9(boolean z2) {
        if (this.y0 == null) {
            o7.k("M", oh.g(this, 2131887730, new Object[0]));
        } else if (this.Z != 0) {
            o7.f("M", "start wifi scan: already scanning");
        } else {
            Y2(170);
            int wifiState = this.y0.getWifiState();
            if (wifiState == 4) {
                o7.f("M", "startWifiScan: wifi state unknown, continuing anyway");
            } else {
                WifiManager.WifiLock wifiLock = this.Y;
                if (wifiLock == null) {
                    wifiLock = this.y0.createWifiLock(2, "Tasker.MonitorService");
                    this.Y = wifiLock;
                } else {
                    o7.G("M", "already had wifiLock...");
                }
                if (wifiLock == null) {
                    o7.G("M", "failed to acquire wifi lock");
                } else if (wifiLock.isHeld()) {
                    o7.G("M", "already held wifi lock");
                } else {
                    wifiLock.setReferenceCounted(false);
                    wifiLock.acquire();
                }
                if (z2 && wifiState != 1 && wifiState != 2) {
                    o7.f("M", "skip wifi enable, not currently DISABLED or ENABLING");
                    z2 = false;
                }
                if (z2) {
                    int a3 = ud.x.b(this) ? ud.d1.a(this.y0) : 1;
                    o7.f("M", "wifi enable: tether state: " + a3);
                    if (a3 == 2 || a3 == 3) {
                        o7.f("M", "skip wifi enable, wifi tether enabl(ed|ing)");
                        z2 = false;
                    }
                }
                if (z2) {
                    boolean z3 = wifiState == 2;
                    if (z3 || this.y0.setWifiEnabled(true)) {
                        this.Z = 1;
                        if (!z3) {
                            T8(true, "startWifiScan");
                        }
                        R1 = System.currentTimeMillis();
                        S1 = 0L;
                        x9(5);
                    } else {
                        o7.G("M", "failed to start wifi enable process");
                    }
                }
                if (this.Z != 1) {
                    D9();
                }
            }
        }
        return this.Z != 0;
    }

    private List<fn> D3(Set<Integer> set, List<io> list, long j3) {
        ArrayList arrayList;
        synchronized (this.s1) {
            try {
                Iterator<Integer> it = set.iterator();
                ArrayList arrayList2 = new ArrayList();
                while (it.hasNext()) {
                    io c3 = this.B0.c(it.next().intValue());
                    if (g2(c3)) {
                        arrayList2.add(c3);
                    }
                }
                arrayList = new ArrayList();
                Collections.sort(arrayList2, new k());
                for (int i3 = 0; i3 < arrayList2.size(); i3++) {
                    io ioVar = (io) arrayList2.get(i3);
                    boolean z2 = list != null && j7(ioVar, list);
                    if (!z2) {
                        g2.put(Integer.valueOf(ioVar.C0()), Long.valueOf(j3));
                    }
                    this.Y0.add(ioVar);
                    if (!z2) {
                        o7.f("M", "profile -> active: " + ioVar.H0());
                        RunLog.K0(this, this.A0, io.a.Active, ioVar);
                        e9(ioVar, false, "enlist");
                        int Q0 = ioVar.Q0(0);
                        if (Q0 != -1) {
                            fn T = this.B0.T(Q0);
                            if (T == null) {
                                o7.k("M", "enlistActiveProfiles: bad enter task ID " + Q0);
                            } else {
                                fn q0 = T.q0();
                                q0.D2(ioVar.L0());
                                if (ioVar.q1()) {
                                    v8(this.B0.T(Q0));
                                }
                                if (ioVar.r0()) {
                                    q0.z2(ioVar.C0());
                                }
                                q0.F(ioVar.F0());
                                q0.B2(ioVar.k1("enter"));
                                arrayList.add(q0);
                            }
                        }
                        if (!ioVar.c1(1) && ioVar.e0()) {
                            this.B0.v4(false);
                            w3(ioVar);
                        }
                    }
                }
            } catch (Throwable th2) {
                throw th2;
            }
        }
        return arrayList;
    }

    private void D4(Bundle bundle, boolean z2) {
        int i3 = bundle.getInt("state", -1);
        int i4 = bundle.getInt("microphone");
        o7.f("M", "HEADSET: state: " + i3 + " mic: " + i4);
        if (i3 == 0) {
            M7(3, false, z2);
            M7(2, false, z2);
        } else if (i4 == 1) {
            M7(3, true, z2);
        } else {
            M7(2, true, z2);
        }
    }

    private void D5(boolean z2) {
        if (pp.z(this, "android.permission.BODY_SENSORS", "MheartRateStartStop")) {
            t9(7, z2, 3, new w());
        }
    }

    public void D6() {
        if (this.f0 == null) {
            this.f0 = new f();
        }
    }

    private void D7(boolean z2) {
        boolean z3;
        if (ud.i0.b()) {
            z3 = ud.i0.h(ud.i0.c(getApplicationContext()));
        } else {
            o7.k("M", "recordPowerSaveState: no API");
            z3 = false;
        }
        M7(43, z3, z2);
    }

    public static void D8(Context context, int i3, String str, String str2, String str3) {
        Intent intent = new Intent("net.dinglisch.android.tasker.SMSUM");
        intent.setPackage(context.getPackageName());
        intent.putExtra("num", str).putExtra("bdy", str2).putExtra("mmsbdy", str3).putExtra("acct", i3);
        context.sendBroadcast(intent);
    }

    private void D9() {
        boolean z2;
        if (this.y0.getWifiState() == 3 || h2(this.y0)) {
            if (!this.y0.pingSupplicant()) {
                o7.f("M", "startWifiScan II: supplicant not responding, continuing anyway");
            }
            try {
                z2 = this.y0.startScan();
            } catch (Exception e3) {
                o7.H("M", "swfsp2: start scan", e3);
                z2 = false;
            }
            if (z2) {
                this.Z = 2;
                this.a0 = System.currentTimeMillis();
                this.b0 = -1L;
                o7.f("M", "started scan at " + this.a0);
                x9(7);
            } else {
                o7.f("M", "wifi reports failed to start scan");
            }
        } else {
            o7.f("M", "start wifi scan II: wifi not enabled and Always Scan not available");
        }
        if (this.Z != 2) {
            R9(true);
        }
    }

    private void E3(io ioVar, int i3, Bundle bundle) {
        int Q0 = ioVar.Q0(i3);
        if (Q0 != -1) {
            fn T = this.B0.T(Q0);
            if (T != null) {
                T.D2((i3 == 0 ? 1 : 0) + ioVar.L0());
                ExecuteService.d6(this, T, 0, -1, -1, ioVar.r0() ? ioVar.C0() : -1, null, null, ioVar.k1("enter"), bundle);
            } else {
                o7.G("M", "exeTaskByType: bad task ID: " + Q0);
            }
        }
    }

    private void E4(boolean z2) {
        int i3 = getResources().getConfiguration().hardKeyboardHidden;
        if (i3 == 2) {
            M7(8, false, z2);
        } else if (i3 == 1) {
            M7(8, true, z2);
        }
    }

    private void E5(boolean z2) {
        t9(8, z2, 3, new a());
    }

    public void E6(List list) {
        this.p1.v3(list);
    }

    private void E7() {
        LinkedList linkedList = new LinkedList();
        if (this.Y0 != null) {
            Iterator it = new LinkedList(this.Y0).iterator();
            while (it.hasNext()) {
                io ioVar = (io) it.next();
                if (ioVar != null && ioVar.e1() && ioVar.x() && !linkedList.contains(ioVar.getName())) {
                    linkedList.add(ioVar.getName());
                }
            }
        }
        try {
            S9(66, linkedList);
        } catch (StackOverflowError unused) {
            o7.G("M", "recordProfilesActive: caught infinite recursion setting %PACTIVE");
        }
        try {
            L7(28, linkedList, true);
        } catch (StackOverflowError unused2) {
            o7.G("M", "recordProfilesActive: caught infinite recursion recording active profiles");
        }
    }

    public static void E8(Context context, boolean z2) {
        Intent intent = new Intent(context, (Class<?>) MonitorService.class);
        intent.putExtra("eventType", 9995);
        intent.putExtra("sreamo", z2);
        M6(context, intent);
    }

    public static void E9(Context context, Intent intent, int i3) {
        F9(context, intent, i3, false);
    }

    private void F2(int i3, int[] iArr, boolean z2) {
        HashSet hashSet = new HashSet();
        if (i3 == -1) {
            for (Integer num : this.W0.keySet()) {
                if (!an.O(num.intValue())) {
                    hashSet.add(num);
                }
            }
        } else if (an.O(i3)) {
            o7.G("M", "checkMatchStates: ignoring plugin state " + i3);
        } else {
            hashSet.add(Integer.valueOf(i3));
        }
        if (iArr != null) {
            for (int i4 : iArr) {
                hashSet.remove(Integer.valueOf(i4));
            }
        }
        G2(hashSet, z2);
    }

    private List<fn> F3(Set<Integer> set) {
        ArrayList arrayList = new ArrayList();
        ArrayList arrayList2 = new ArrayList(this.Y0);
        int size = arrayList2.size();
        for (int i3 = 0; i3 < size; i3++) {
            io ioVar = (io) arrayList2.get(i3);
            int Q0 = ioVar.Q0(0);
            if (Q0 != -1) {
                fn T = this.B0.T(Q0);
                if (T == null) {
                    o7.k("M", "gacm: unknown task id " + Q0 + " in profile " + ioVar.H0());
                } else {
                    fn q0 = T.q0();
                    fn Z12 = fo.Z1();
                    Z12.D2(ioVar.L0() + 2002);
                    for (net.dinglisch.android.taskerm.c cVar : q0.D0()) {
                        if (set.contains(Integer.valueOf(cVar.j()))) {
                            Z12.Z(cVar);
                        }
                    }
                    arrayList.add(Z12);
                }
            }
        }
        return arrayList;
    }

    private void F5(boolean z2, int i3, int i4, int i5) {
        if (z2 && this.p0[i3] == null) {
            o7.f("M", "setup " + F1[i3] + " sensor");
            this.p0[i3] = this.t0.getDefaultSensor(i4);
            if (this.p0[i3] == null) {
                if (this.s[C1[i3]]) {
                    if (i3 == 6 || i3 == 8) {
                        o7.f("M", "no temp sensor for temp or humidity var");
                        return;
                    } else {
                        pp.a0(this, 2131887863, oh.g(this, i5, new Object[0]).toLowerCase());
                        return;
                    }
                }
                return;
            }
            if (i4 == 1) {
                if (this.q0 == -1) {
                    this.q0 = this.A0.getLong("acMSr", 300L) * 1000000;
                    return;
                }
                return;
            }
            if (i3 == 4 && A5(103)) {
                h2 = P3("lmi", Float.MAX_VALUE);
                i2 = P3("lma", Float.MIN_VALUE);
                o7.f("M", "initialized light range to " + h2 + ConstantsCommonTaskerServer.ID_SEPARATOR + i2);
                return;
            }
            if (i3 == 3 && A5(125)) {
                j2 = P3("pmi", Float.MAX_VALUE);
                k2 = P3("pma", Float.MIN_VALUE);
                o7.f("M", "initialized prox range to " + j2 + ConstantsCommonTaskerServer.ID_SEPARATOR + k2);
            }
        }
    }

    public void F6(ug ugVar, int i3) {
        if (ugVar.V()) {
            return;
        }
        ugVar.S(new x(this, i3), this, new com.joaomgcd.taskerm.util.f() {
            @Override
            public final void a(Object obj) {
                MonitorService.this.E6((List) obj);
            }
        }, this.B0.Y2(2102));
    }

    private void F7() {
        LinkedList linkedList = new LinkedList();
        List<io> O12 = this.B0.O1();
        Collections.sort(O12, new h());
        for (io ioVar : O12) {
            if (ioVar.x() && !linkedList.contains(ioVar.getName())) {
                linkedList.add(ioVar.getName());
            }
        }
        S9(67, linkedList);
    }

    public static void F8(Context context) {
        Intent intent = new Intent("net.dinglisch.android.tasker.MSC");
        intent.setPackage(context.getPackageName());
        context.sendBroadcast(intent);
    }

    public static void F9(Context context, Intent intent, int i3, boolean z2) {
        if (z2) {
            com.joaomgcd.taskerm.util.t2.g(intent);
        }
        M6(context, L5(context, intent, i3));
    }

    private void G2(java.util.Set<java.lang.Integer> r41, boolean r42) {
        throw new UnsupportedOperationException("Method not decompiled: net.dinglisch.android.taskerm.MonitorService.G2(java.util.Set, boolean):void");
    }

    public static int[] G3() {
        int[] iArr;
        LinkedList<Integer> linkedList = l2;
        synchronized (linkedList) {
            try {
                int size = linkedList.size();
                iArr = new int[size];
                for (int i3 = 0; i3 < size; i3++) {
                    iArr[i3] = l2.get(i3).intValue();
                }
            } catch (Throwable th2) {
                throw th2;
            }
        }
        return iArr;
    }

    private void G4(java.util.Set<java.lang.Integer> r6, java.util.List<net.dinglisch.android.taskerm.io> r7, java.lang.String r8) {
        throw new UnsupportedOperationException("Method not decompiled: net.dinglisch.android.taskerm.MonitorService.G4(java.util.Set, java.util.List, java.lang.String):void");
    }

    private boolean G5() {
        this.v0 = (AlarmManager) gi.d(this, "alarm", "M", "initManagers");
        this.y0 = (WifiManager) gi.d(this, "wifi", "M", "initManagers");
        if (this.v0 == null) {
            o7.k("M", "no alarm manager, exiting");
            return false;
        }
        ContentResolver contentResolver = getContentResolver();
        this.w0 = contentResolver;
        if (contentResolver == null) {
            o7.G("M", "no content resolver, can't change system settings");
        }
        if (getPackageManager() != null) {
            return true;
        }
        o7.k("M", "no package manager, exiting");
        return false;
    }

    public void G6(boolean z2) {
        for (final int i3 = 0; i3 < ug.D(); i3++) {
            final ug ugVar = this.n0[i3];
            if (ugVar != null) {
                if (!z2) {
                    o7.f("M", "stopCal: " + ug.k(i3) + ": " + z2);
                    i2(i3);
                    ugVar.T();
                } else {
                    if (!this.p1.G0(com.joaomgcd.taskerm.util.ac.b0(this))) {
                        return;
                    }
                    o7.f("M", "startCal: " + ug.k(i3) + ": " + z2);
                    H8(i3);
                    try {
                        this.p1.F(new Runnable() {
                            @Override
                            public final void run() {
                                MonitorService.this.F6(ugVar, i3);
                            }
                        });
                    } catch (Throwable th2) {
                        o7.l("M", "stopCal: couldn't start updates", th2);
                    }
                }
            }
        }
    }

    public void G7(int i3, int i4, boolean z2) {
        K7(i3, Integer.toString(i4), z2, false);
    }

    public static void G8(Context context) {
        M6(context, new Intent(context, (Class<?>) MonitorService.class).putExtra("eventType", 9983));
    }

    public static void G9(Context context, Intent intent, int i3) {
        intent.setComponent(new ComponentName(context, MonitorService.class.getName()));
        intent.putExtra("UserIntentPIDExtra", i3);
        M6(context, intent);
    }

    private void H2() {
        for (Map.Entry<Integer, v1> entry : this.Q0.entrySet()) {
            v1 value = entry.getValue();
            if (value.Z0()) {
                d9(entry.getKey().intValue(), value, "checkMatchTDD");
            }
        }
        for (Map.Entry<Integer, wo> entry2 : this.P0.entrySet()) {
            wo value2 = entry2.getValue();
            Integer key = entry2.getKey();
            int intValue = key.intValue();
            io c3 = this.B0.c(intValue);
            Bundle l0 = com.joaomgcd.taskerm.util.b7.l0(this.B0, this, c3, null, "checkMatchTimesDays");
            boolean a1 = value2.a1(this, l0);
            if (value2.A1(this, l0)) {
                if (c3 != null && c3.h1()) {
                    if (g2.containsKey(key) && System.currentTimeMillis() - g2.get(key).longValue() <= 60000) {
                        o7.f("M", "skip instant check, less than a minute since last");
                    } else if (x2(c3, null, null)) {
                        long H = ug.H(System.currentTimeMillis());
                        long currentTimeMillis = System.currentTimeMillis();
                        if (H > currentTimeMillis) {
                            o7.k("M", "startOfMinute " + H + " > curtime " + currentTimeMillis);
                        }
                        g2.put(key, Long.valueOf(H));
                    }
                }
                value2.w0();
            } else if (a1) {
                d9(intValue, value2, "checkMatchTDT");
            }
        }
    }

    private long H3() {
        return this.A0.getLong("btpiod", 120L) * 1000;
    }

    private void H5() {
        U8(((PowerManager) gi.d(getApplicationContext(), "power", "M", "initSS")).isScreenOn());
        n2 = B8(this) && !dh.d(this);
    }

    public void H6() {
        o7.f("M", "Clipboard changed. Broadcasting variable change");
        wp.F1(this, 20);
        this.p1.w3(ue.q.y(this));
    }

    public void H7(int i3, int i4, boolean z2, boolean z3) {
        K7(i3, Integer.toString(i4), z2, z3);
    }

    private void H8(int i3) {
        if (com.joaomgcd.taskerm.util.ac.b0(this).h0()) {
            i2(i3);
            synchronized (this.J0) {
                try {
                    ug ugVar = this.n0[i3];
                    if (ugVar == null) {
                        o7.k("M", "setCalendarAlarm: no calendar for " + ug.k(i3));
                    } else {
                        long C = ugVar.C(this);
                        if (C == -1) {
                            o7.f("M", "...no next time");
                        } else if (C == -2) {
                            pp.a0(this, 2131887906, new Object[0]);
                        } else {
                            I8(i3, C);
                        }
                    }
                } catch (Throwable th2) {
                    throw th2;
                }
            }
        }
    }

    private void H9(boolean z2) {
        u9(0, z2, 3, new t(), true);
    }

    private void I2(fo foVar, fo foVar2) {
        for (io ioVar : foVar2.s2(-2)) {
            if (!ioVar.h1()) {
                w3(ioVar);
            }
        }
    }

    private Bundle I3() {
        Intent z2 = this.p1.z2(new IntentFilter("android.intent.action.BATTERY_CHANGED"));
        if (z2 == null) {
            return null;
        }
        return z2.getExtras();
    }

    private void I4() {
        Log.d("M", "not starting, no config");
        Z7();
    }

    private void I5(boolean z2, boolean z3) {
        long[] jArr = x1;
        jArr[0] = this.A0.getLong("lperiod", 1500L);
        jArr[1] = this.A0.getLong("guped", 120L) * 1000;
        jArr[2] = this.A0.getLong("luped", 30L) * 1000;
        jArr[3] = this.A0.getLong("wfpiod", 120L) * 1000;
        jArr[4] = this.A0.getLong("sows", 60L) * 1000;
        jArr[5] = 1000;
        jArr[12] = 750;
        jArr[11] = this.A0.getLong("btpiod", 120L) * 1000;
        jArr[6] = this.A0.getLong("gupt", 90L) * 1000;
        if (z2) {
            jArr[7] = V3();
            o7.f("M", "set initial wifi timeout to " + V3() + "ms (max)");
        }
        if (z3) {
            jArr[13] = U3();
            o7.f("M", "set initial BT timeout to " + U3() + "ms (max)");
        }
        jArr[8] = 2000;
        jArr[9] = 2000;
        jArr[10] = 200;
    }

    public void I6(int i3) {
        M9(i3, "tidyUp");
    }

    private void I7(int i3, long j3, boolean z2) {
        K7(i3, Long.toString(j3), z2, false);
    }

    private void I8(int i3, long j3) {
        i2(i3);
        Calendar calendar = Calendar.getInstance();
        calendar.setTimeInMillis(j3);
        o7.f("M", "nextcal: " + ug.k(i3) + ": " + ug.r(calendar, true) + " " + ug.i(this, calendar));
        long currentTimeMillis = j3 - System.currentTimeMillis();
        if (currentTimeMillis < 0) {
            o7.k("M", "bug: trying to set cal alarm in the past, diff " + currentTimeMillis);
            this.K0[i3] = 0;
            return;
        }
        Intent intent = new Intent(this, (Class<?>) ReceiverStaticInternal.class);
        intent.setAction("net.dinglisch.android.tasker.CALARUM");
        intent.putExtra("csrc", i3);
        this.I0[i3] = PendingIntent.getBroadcast(this, i3, intent, com.joaomgcd.taskerm.util.bi.m(268435456, intent));
        this.K0[i3] = j3;
        R7(i3, "setCalendarAlarmAux");
    }

    private boolean I9() {
        boolean z2;
        synchronized (Q1) {
            try {
                z2 = this.Z != 0 || this.i0 != 0 || Q1.size() > 0 || this.P;
            } finally {
            }
        }
        return z2;
    }

    private int J2(Bundle bundle, boolean z2) {
        return K2(bundle, z2, false, false);
    }

    private boolean J3(int i3) throws Settings.SettingNotFoundException {
        int N0 = pp.N0(this.w0, i3);
        if (N0 != -1) {
            return N0 != 0;
        }
        throw new Settings.SettingNotFoundException("no setting for action code " + i3);
    }

    private boolean J5(boolean z2) {
        qg.b.b(this);
        this.B0 = fo.w1(this);
        boolean z3 = false;
        if (this.B0 != null) {
            com.joaomgcd.taskerm.util.df.q(this);
            o7.f("M", "struct");
            d3(z2);
            o7.f("M", "scan data");
            z8();
            HelperMonitorService.b3(this.V0);
            HelperMonitorService.c3(this.W0.keySet());
            this.G = 0L;
            i8();
            o7.f("M", "done cals");
            this.u0 = (ActivityManager) gi.d(this, "activity", "M", "init");
            o7.f("M", "rescan vars");
            l8(false);
            c3();
            o7.f("M", "recalc action set");
            this.B0.v4(false);
            o7.f("M", "receivers");
            try {
                l3(true);
                this.p1.b2();
                lf.e.e(this.p1);
                this.p1.X1();
                pp.V2(this, false, "M.initialize");
                a9();
                this.p1.q3();
                k3();
                B3(false);
                y3(false);
            } catch (Exception e3) {
                o7.k("M", "init: exception from component toggle: " + e3.toString());
            }
            o7.f("M", "loc setup");
            try {
                if (this.S0.size() > 0) {
                    LocationManager locationManager = (LocationManager) gi.d(this, "location", "M", "init");
                    this.x0 = locationManager;
                    if (locationManager == null) {
                        o7.k("M", oh.g(this, 2131887719, new Object[0]));
                    } else {
                        j8();
                    }
                    o7.f("M", "got locs");
                }
            } catch (Exception e4) {
                o7.k("M", "init: exception from loc setup: " + e4.toString());
            }
            o7.f("M", "sensor");
            O2();
            o7.f("M", "pen var");
            F7();
            z3 = true;
        } else {
            o7.G("M", "not starting due to failed config read");
            Z7();
        }
        o7.f("M", "done init: " + z3);
        return z3;
    }

    public void J6(Bundle bundle, eh.b bVar, eh.b bVar2, io ioVar, HashSet hashSet, we.e eVar, w4 w4Var) {
        if (eVar.Q() == null) {
            return;
        }
        eh.c P = eVar.P(this, w4Var, bundle);
        if (bVar.a() && !bVar.c(P)) {
            eVar.T(false);
            eVar.W(this, ioVar, w4Var);
        } else {
            if (bVar2.d(P)) {
                eVar.T(false);
                eVar.W(this, ioVar, w4Var);
                return;
            }
            if (!((sn) w4Var).K0()) {
                bVar2.e(P);
            }
            hashSet.add(eVar.Q());
            eVar.T(true);
            eVar.R(this, ioVar, w4Var, bundle);
        }
    }

    private void J8(long j3) {
        j2();
        o7.f("M", "set cooldown alarm for " + j3 + "ms");
        Intent intent = new Intent(this, (Class<?>) ReceiverStaticInternal.class);
        intent.setAction("net.dinglisch.android.tasker.COOLORUM");
        this.G0 = PendingIntent.getBroadcast(this, 0, intent, com.joaomgcd.taskerm.util.bi.m(268435456, intent));
        this.H0 = System.currentTimeMillis() + j3;
        S7("set");
    }

    private void J9(boolean z2) {
        o7.f("M", "stop BT scan");
        N9(12);
        N9(13);
        this.i0 = 0;
        if (i1.q()) {
            i1.t(this);
        }
        if (z2) {
            j3();
        }
        Q9();
    }

    private int K2(Bundle bundle, boolean z2, boolean z3, boolean z4) {
        if (bundle == null) {
            bundle = I3();
        }
        int e22 = e2(bundle);
        if (z3 && e22 <= 0) {
            o7.f("M", "cps: plugged battery extras not updated yet. Setting to 1");
            e22 = 1;
        }
        if (z4) {
            o7.f("M", "cps: plugged came from disconnected event so set to 0");
            e22 = 0;
        }
        o7.f("M", "cps: plugged: " + e22);
        if (e22 == 1) {
            M7(9, true, z2);
        } else if (e22 == 2) {
            M7(10, true, z2);
        } else if (e22 == 4) {
            M7(33, true, z2);
        } else if (e22 > 0) {
            M7(40, true, z2);
        } else {
            M7(40, false, z2);
            M7(9, false, z2);
            M7(10, false, z2);
            M7(33, false, z2);
        }
        int s2 = pp.s(bundle);
        G7(11, s2, z2);
        G7(46, bundle.getInt("temperature", -1), z2);
        return s2;
    }

    public static String K3() {
        return L1;
    }

    public void K5(String str, int i3) {
        Intent intent = new Intent();
        intent.putExtra("eventType", 9996);
        intent.putExtra("eventAct", str);
        intent.putExtra("eventConID", i3);
        R1(intent, -1, true);
    }

    public static long K6() {
        long currentTimeMillis;
        synchronized (T1) {
            currentTimeMillis = System.currentTimeMillis() - U1;
            o7.f("M", "lastWifiDisableAgoMS: " + currentTimeMillis);
        }
        return currentTimeMillis;
    }

    private void K7(int i3, String str, boolean z2, boolean z3) {
        if (!z3) {
            try {
                if (C5(i3) && n4(i3, 0).equals(str)) {
                    return;
                }
            } catch (Throwable th2) {
                o7.l("M", "recordState", th2);
                return;
            }
        }
        O7(i3, new String[]{str}, z2);
    }

    public static void K8(Context context, boolean z2) {
        pp.S0(context).edit().putBoolean(ClockContract.AlarmsColumns.ENABLED, z2).commit();
    }

    private void K9() {
        try {
            stopForeground(true);
        } catch (Exception e3) {
            o7.f("M", "stopForeground: " + e3.getMessage());
        }
    }

    private void L2(String str, Bundle bundle, List<j2> list) {
        int i3 = 0;
        while (true) {
            String[] strArr = d6.l.a;
            if (i3 >= strArr.length) {
                return;
            }
            if (str.equals(strArr[i3])) {
                j2 j2Var = new j2(447);
                j2Var.B1(0, i3);
                String str2 = d6.l.b[i3];
                if (bundle.containsKey(str2)) {
                    j2Var.B1(1, bundle.getInt(str2));
                } else {
                    o7.G("M", str + ": no extra: " + str2);
                }
                String str3 = d6.l.c[i3];
                if (str3 != null && bundle.containsKey(str3)) {
                    ArrayList<String> stringArrayList = bundle.getStringArrayList(str3);
                    if (pp.F(stringArrayList)) {
                        o7.G("M", str + ": no extra " + str3);
                    } else {
                        StringBuilder sb = new StringBuilder();
                        Iterator<String> it = stringArrayList.iterator();
                        while (it.hasNext()) {
                            String next = it.next();
                            if (sb.length() > 0) {
                                sb.append("\n");
                            }
                            sb.append(next);
                        }
                        j2Var.o0(2, sb.toString());
                    }
                }
                list.add(j2Var);
                return;
            }
            i3++;
        }
    }

    public static int L3() {
        return K1;
    }

    private static Intent L5(Context context, Intent intent, int i3) {
        Bundle bundle;
        Intent intent2 = new Intent(context, (Class<?>) MonitorService.class);
        intent2.putExtra("eventType", 9996);
        String action = intent.getAction();
        try {
            bundle = intent.getExtras();
        } catch (Throwable th2) {
            o7.l("M", "Error getting system event intent extras", th2);
            bundle = null;
        }
        if (bundle != null) {
            intent2.putExtra("eventExt", bundle);
        }
        intent2.putExtra("eventAct", action);
        String dataString = intent.getDataString();
        if (dataString != null) {
            intent2.putExtra("eventDt", dataString);
        }
        if (i3 != -1) {
            intent2.putExtra("eventConID", i3);
        }
        if ("android.provider.Telephony.SMS_RECEIVED".equals(action) || "android.intent.action.DATA_SMS_RECEIVED".equals(action)) {
            intent2.putExtra("eventOrigIntent", intent.toUri(1).toString());
        }
        return intent2;
    }

    private void L6(boolean z2) {
        u9(4, z2, 3, new u(), true);
    }

    public void L7(int i3, Collection<?> collection, boolean z2) {
        String[] strArr;
        if (collection != null) {
            strArr = new String[collection.size()];
            int i4 = 0;
            for (Object obj : collection) {
                if (obj == null) {
                    obj = "";
                }
                strArr[i4] = obj.toString();
                i4++;
            }
        } else {
            strArr = null;
        }
        O7(i3, strArr, z2);
    }

    private void L8(boolean z2) {
        if (Settings.R3(this, this.A0)) {
            Notification ca = ca(true, z2);
            if (ca == null) {
                o7.G("M", "setForegroundState: null notification");
                return;
            }
            try {
                com.joaomgcd.taskerm.util.c0.v(this, Integer.MAX_VALUE, ca);
            } catch (IllegalArgumentException e3) {
                o7.H("M", "startForeground: id 2147483647", e3);
            }
        }
    }

    public void L9(String str) {
        if (this.x0 != null) {
            synchronized (Q1) {
                if (Q1.containsKey(str)) {
                    try {
                        this.x0.removeUpdates(Q1.get(str));
                    } catch (Exception e3) {
                        o7.k("M", "removing " + str + " listener: " + e3.toString());
                    }
                    Q1.remove(str);
                }
            }
        }
        if (str.equals("gps")) {
            N9(6);
        }
        Q9();
    }

    private void M2(boolean z2) {
        Cursor cursor;
        o7.f("M", "update: " + z2 + " lastSeenTime: " + j4(this.w));
        if (pp.z(this, "android.permission.READ_SMS", "McheckMS")) {
            try {
                cursor = this.w0.query(Uri.parse("content://sms/inbox"), new String[]{"date", "address", "body"}, "read=0", null, "_id");
            } catch (Exception e3) {
                o7.H("M", "query SMS inbox", e3);
                cursor = null;
            }
            if (cursor == null) {
                o7.G("M", "checkSMS: null cursor");
                return;
            }
            while (cursor.moveToNext()) {
                long j3 = cursor.getLong(0);
                String string = cursor.getString(1);
                String string2 = cursor.getString(2);
                o7.f("M", "THIS STAMP: " + j3 + " THIS TIME: " + j4(j3));
                if (j3 > this.w) {
                    this.w = j3;
                    if (z2 && pp.g() < 19) {
                        D8(this, 2, string, string2, null);
                    }
                }
                P7(2, string, string2, j3);
            }
            cursor.close();
        }
    }

    private int M3() {
        return this.A0.getInt("sbl", 0);
    }

    private void M4(Bundle bundle, boolean z2) {
        M7(48, !bundle.getBoolean("penInsert"), z2);
    }

    public static int M5(Object obj, Object obj2) {
        return ((Long) obj2).compareTo((Long) obj);
    }

    public static void M6(Context context, Intent intent) {
        xg.e2.x2(N6(context, intent), context);
    }

    public void M7(int i3, boolean z2, boolean z3) {
        K7(i3, Boolean.toString(z2), z3, false);
    }

    public static void M8() {
        synchronized (Z1) {
            Z1 = Boolean.FALSE;
        }
    }

    private void M9(int i3, String str) {
        if (T6(i3)) {
            o7.f("M", y1[i3] + ": " + str + ": monitor stop");
            switch (i3) {
                case 0:
                    O1(false);
                    break;
                case 1:
                    L9("gps");
                    N9(1);
                    break;
                case 2:
                    N9(2);
                    L9("network");
                    break;
                case 3:
                    N9(3);
                    R9(true);
                    break;
                case 4:
                    m2();
                    break;
                case 5:
                    N9(0);
                    break;
                case ClockContract.InstancesColumns.MISSED_STATE:
                    l9(false);
                    break;
                case 7:
                    o9(false);
                    this.X0.clear();
                    break;
                case 8:
                    pp.r1(this, false, false);
                    break;
                case 9:
                    m9(false);
                    break;
                case 10:
                    s9(false);
                    break;
                case 11:
                    MyAccessibilityService.t(0);
                    break;
                case 12:
                    k7(false);
                    break;
                case 13:
                    L6(false);
                    break;
                case 14:
                    p9(false);
                    break;
                case 15:
                    c9(false);
                    break;
                case 16:
                    e7(false);
                    break;
                case 17:
                    R6(false);
                    break;
                case 18:
                    n9(false);
                    break;
                case 19:
                    T9(false);
                    break;
                case 20:
                    N9(11);
                    J9(true);
                    break;
                case 21:
                    E5(false);
                    break;
                case 22:
                    H9(false);
                    break;
                case 23:
                    v9(false);
                    break;
                case 24:
                    D5(false);
                    break;
                case 25:
                    this.n1.i();
                    break;
                case 26:
                    this.p1.U1();
                    break;
                default:
                    o7.k("M", "bad monitor: " + i3);
                    break;
            }
            R8(i3, false);
        }
    }

    public boolean N2(SensorEvent sensorEvent, int i3, int i4) {
        if (sensorEvent == null) {
            o7.f("M", "sensor event: " + F1[i3] + ": null");
        } else {
            float[] fArr = sensorEvent.values;
            if (fArr == null) {
                o7.f("M", "sensor event: " + F1[i3] + ": null values");
            } else {
                if (fArr.length >= i4) {
                    return true;
                }
                o7.f("M", "sensor event: " + F1[i3] + ": vals = " + sensorEvent.values.length);
            }
        }
        return false;
    }

    private RemoteViews N3(String str, int i3, int i4) {
        RemoteViews remoteViews = new RemoteViews(getPackageName(), pp.g() >= 16 ? 2131494245 : 2131494244);
        remoteViews.setImageViewResource(2131296973, i4);
        int i5 = u1[i3];
        remoteViews.setTextColor(2131297640, i3 == 9 ? -16777216 : i5);
        remoteViews.setTextColor(2131297001, i5);
        remoteViews.setTextViewText(2131297640, mh.s(this));
        remoteViews.setTextViewText(2131297001, str);
        remoteViews.setTextViewText(2131297632, DateFormat.getTimeFormat(this).format(ug.x().getTime()));
        return remoteViews;
    }

    private void N4(Bundle bundle, boolean z2) {
        M7(49, bundle.getBoolean("isShow"), true);
    }

    public void N5(BluetoothDevice bluetoothDevice, String str, int i3) {
        long currentTimeMillis = System.currentTimeMillis();
        int b3 = ud.g.d() ? ud.g.b(bluetoothDevice) : 1;
        o7.f("M", str + ": result: " + bluetoothDevice.getName() + ", " + bluetoothDevice.getAddress() + " defaultType: " + i3 + " detectedType " + b3);
        this.d0 = this.d0 + 1;
        this.h0 = currentTimeMillis;
        StringBuilder sb = new StringBuilder();
        sb.append("got scan result after : ");
        sb.append(currentTimeMillis - this.g0);
        sb.append("ms");
        o7.f("M", sb.toString());
        String address = bluetoothDevice.getAddress();
        if (a2.containsKey(address)) {
            a2.get(address).u(currentTimeMillis);
        } else {
            h1 h1Var = new h1(bluetoothDevice, false);
            if (b3 == 0) {
                o7.f("M", "handleScanResult: correcting unknown device type to default " + i3);
                h1Var.w(i3);
            }
            a2.put(address, h1Var);
        }
        E2(4, true);
        if (c2(4, this.g0)) {
            J9(true);
        }
    }

    public static ti.b N6(final Context context, final Intent intent) {
        return xg.e2.A0(ExtensionsContextKt.U2(context).E().getValue(), new Runnable() {
            @Override
            public final void run() {
                MonitorService.W5(context, intent);
            }
        }).q(new yi.d() {
            @Override
            public final void accept(Object obj) {
                o7.l("M", "Couldn't lockAndStartService", (Throwable) obj);
            }
        }).v();
    }

    public void N7(int i3, float[] fArr, boolean z2) {
        String[] strArr = new String[fArr.length];
        for (int i4 = 0; i4 < fArr.length; i4++) {
            strArr[i4] = String.valueOf(fArr[i4]);
        }
        O7(i3, strArr, z2);
    }

    public static void N8(String str) {
        synchronized (T1) {
            o7.f("M", "setKeepWifiOn: " + str);
            T1 = Boolean.FALSE;
        }
    }

    private boolean N9(int i3) {
        Handler handler = this.l0;
        if (handler == null || !X9(i3)) {
            return false;
        }
        o7.f("M", "stop timer: " + w1[i3]);
        handler.removeMessages(i3);
        return true;
    }

    private void O1(boolean z2) {
        u9(1, z2, 3, new r(), true);
    }

    private void O2() {
        throw new UnsupportedOperationException("Method not decompiled: net.dinglisch.android.taskerm.MonitorService.O2():void");
    }

    public static String O3(Context context) {
        return Kid.b(context) ? fo.w1(context).w(0).getIcon().getName() : "cust_notification";
    }

    private void O6(String str) {
        String str2 = "";
        int i3 = 0;
        for (int i4 = 0; i4 < z1; i4++) {
            if (this.s[i4]) {
                str2 = str2 + y1[i4] + " ";
            }
        }
        if (str2.length() == 0) {
            str2 = "none";
        }
        o7.f("M", str + ": needed monitors: " + str2);
        StringBuilder sb = new StringBuilder();
        sb.append("needed flags:");
        while (true) {
            String[] strArr = A1;
            if (i3 >= strArr.length) {
                o7.f("M", sb.toString());
                o7.f("M", "needed pstate-types: " + this.T + " access-types: " + this.U);
                return;
            }
            if (U6(i3)) {
                sb.append(' ');
                sb.append(strArr[i3]);
            }
            i3++;
        }
    }

    private void O7(int i3, String[] strArr, boolean z2) {
        c2[i3] = strArr;
        if (z2) {
            E2(v1[i3], z2);
        }
    }

    public static void O8(String str) {
        o7.f("M", "set lastCellID: " + str);
        L1 = str;
    }

    private void O9() {
        L9("gps");
        L9("network");
        if (this.Z != 0) {
            R9(true);
        }
        if (this.i0 != 0) {
            J9(true);
        }
        P9();
    }

    private void P1() {
        if (er.j("Sensor")) {
            return;
        }
        er.f(this, "Sensor", false, true);
    }

    private void P2(io ioVar) {
        if (ioVar.Z0(3)) {
            n7 n7Var = (n7) ioVar.T0(3);
            if ((T6(1) && n7Var.o1()) || (T6(2) && n7Var.p1())) {
                C2(ioVar.C0());
            }
        }
        if (ioVar.Z0(1)) {
            wo woVar = (wo) ioVar.T0(1);
            if (woVar.a1(this, com.joaomgcd.taskerm.util.b7.l0(this.B0, this, ioVar, null, "checkSingleProfileMatches"))) {
                d9(ioVar.C0(), woVar, "checkSingeMatchTime");
            }
        }
        if (ioVar.Z0(2)) {
            v1 v1Var = (v1) ioVar.T0(2);
            if (v1Var.Z0()) {
                d9(ioVar.C0(), v1Var, "checkSingeMatchDate");
            }
        }
        if (ioVar.Z0(0) && T6(5)) {
            f1 f1Var = (f1) ioVar.T0(0);
            if (f1Var.Z0(this, this.B, this.D)) {
                d9(ioVar.C0(), f1Var, "checkSingeMatchApp");
            }
        }
        HashSet hashSet = new HashSet();
        for (int i3 = 4; i3 <= 6; i3++) {
            if (ioVar.Z0(i3)) {
                bn bnVar = (bn) ioVar.T0(i3);
                int j3 = bnVar.j();
                if (j3 == 170 || j3 == 4 || j3 == 5) {
                    hashSet.add(Integer.valueOf(bnVar.j()));
                } else if (an.O(j3)) {
                    t7(ioVar, ioVar.C0(), bnVar);
                }
            }
        }
        Iterator it = hashSet.iterator();
        while (it.hasNext()) {
            F2(((Integer) it.next()).intValue(), null, false);
        }
    }

    private float P3(String str, float f3) {
        return pp.S0(this).getFloat(str, f3);
    }

    private void P4(int i3, j2 j2Var, Bundle bundle) {
        if (!this.B0.V(i3)) {
            o7.G("M", "handlePluginEvent: unknown profile ID " + i3);
            return;
        }
        io c3 = this.B0.c(i3);
        if (!c3.h1()) {
            o7.f("M", "handlePluginEvent: profile disabled");
            return;
        }
        j2Var.Q0(true);
        if (x2(c3, null, bundle)) {
            g2.put(Integer.valueOf(i3), Long.valueOf(System.currentTimeMillis()));
        }
        j2Var.w0();
    }

    public void P6(Context context, String str, String str2, sn snVar) {
        o7.f("M", "received " + str + " from plugin " + str2 + " / " + snVar.d(context));
    }

    private void P7(int i3, String str, String str2, long j3) {
        if (A5(147)) {
            try {
                Calendar t2 = ug.t(j3);
                String g3 = t2 != null ? ug.g(t2) : null;
                if (g3 == null) {
                    g3 = Build.UNKNOWN;
                }
                o7.f("M", "record ms from " + str + " date " + g3 + " flags " + i3);
            } catch (Exception e3) {
                o7.H("M", "getDateString", e3);
            }
            this.y.add(str);
            this.z.add(str2);
            this.A.add(String.valueOf(i3));
        }
    }

    private void P8(String str, String str2) {
        this.B = str;
        o7.f("M", "handleTimerApp set last new package accessibility from " + str2 + ": " + str);
    }

    public void P9() {
        o7.f("M", "stop user-absent cell check");
        f8();
        this.P = false;
        N9(9);
        Q9();
    }

    private void Q2(int i3, String str, int i4, boolean z2) {
        if (this.s[i3]) {
            o7.f("M", "checkStartStop: " + y1[i3] + ": needMonitor: " + this.s[i3] + " want when off: " + da(str, i4, z2) + "  plugged: " + z2);
            if (z2) {
                if (T6(i3) || da(str, i4, true) <= 0) {
                    return;
                }
                i9(i3);
                return;
            }
            if (T6(i3) && da(str, i4, false) == 0) {
                M9(i3, "powerChange");
            }
        }
    }

    public void P5(Intent intent) {
        String stringExtra = intent.getStringExtra("title");
        boolean z2 = false;
        for (int i3 = 0; i3 < 10; i3++) {
            if (D1[i3].equals(stringExtra)) {
                W4(i3, stringExtra);
                z2 = true;
            }
        }
        if (z2) {
            return;
        }
        if (stringExtra.equals("appcheckMethod")) {
            ba("handlePrefsIntent");
            if (f1.w1(this)) {
                Q8(ip.a(this, 600000L), "handlePrefsIntent");
            }
            if (this.s[5]) {
                i9(5);
                return;
            } else {
                M9(5, "hpi");
                return;
            }
        }
        if (stringExtra.equals("mFn")) {
            if (Settings.R3(this, this.A0)) {
                L8(true);
                return;
            } else {
                K9();
                k2();
                return;
            }
        }
        if (!stringExtra.equals("lfdd")) {
            I5(stringExtra.equals("wfpiod") || stringExtra.equals("wip") || stringExtra.equals("lfdd"), stringExtra.equals("btpiod") || stringExtra.equals("bttp") || stringExtra.equals("lfdd"));
            return;
        }
        synchronized (this.M0) {
            try {
                if (this.L0 != null && !er.j("Tasker.UserAbsentWakelock")) {
                    o2();
                    A9();
                }
            } finally {
            }
        }
    }

    public void Q5(String str) {
        o7.f("M", "handle time alarm: " + str);
        H2();
        S4(this.O0, null, "timeAlarm");
        if (T6(4)) {
            r8(4, "handleTimeAlarm");
        }
    }

    private void Q6(Intent intent, Bundle bundle, String str) {
        if (bundle != null) {
            o7.f("M", "QUERY PLUGIN: " + str + " / " + intent.getAction() + " " + bundle.size() + " bundle keys");
        } else {
            o7.f("M", "QUERY EVENT PLUGIN: " + str + " / " + intent.getAction() + ": no extras");
        }
        ComponentName component = intent.getComponent();
        if (component == null) {
            o7.k("M", str + ": null component name");
            return;
        }
        o7.f("M", str + ": plugin comp: " + component.getPackageName() + "/" + component.getClassName());
    }

    private void Q7(final boolean z2, final long j3) {
        final HashSet hashSet = new HashSet();
        if (j3 > 0) {
            this.p1.O(new Runnable() {
                @Override
                public final void run() {
                    MonitorService.this.t6(hashSet, z2, j3);
                }
            });
            return;
        }
        if (J1) {
            hashSet.add(8);
        }
        USBHandler.f(this, hashSet);
        L7(4, hashSet, z2);
    }

    private void Q8(String str, String str2) {
        this.C = str;
        o7.f("M", "handleTimerApp set last new package appusage from " + str2 + ": " + str);
    }

    private void Q9() {
        if (n2 || I9() || !N9(4)) {
            return;
        }
        x9(8);
    }

    private void R1(Intent intent, int i3, boolean z2) {
        this.p1.G1(intent, i3, z2);
    }

    private void R2(boolean z2) {
        for (int i3 = 0; i3 < 10; i3++) {
            Q2(C1[i3], D1[i3], E1[i3], z2);
        }
    }

    private String R3(byte[] bArr) {
        String str = null;
        try {
            Parcel obtain = Parcel.obtain();
            obtain.unmarshall(bArr, 0, bArr.length);
            obtain.setDataPosition(0);
            for (int i3 = 0; i3 < 5; i3++) {
                obtain.readInt();
            }
            obtain.readLong();
            obtain.readInt();
            str = obtain.readString();
            obtain.recycle();
            return str;
        } catch (Exception e3) {
            o7.k("M", "getLabelFromRawAlarm: " + e3.toString());
            return str;
        }
    }

    public void R4(Set<Integer> set, List<io> list, Bundle bundle, String str, boolean z2) {
        o7.f("M", "handleProfileChanges (" + str + ")");
        long currentTimeMillis = System.currentTimeMillis();
        e3(set);
        HashSet hashSet = new HashSet();
        LinkedList linkedList = new LinkedList();
        List<fn> g3 = g3(this.B0, this.Y0, hashSet, false, linkedList);
        if (z2) {
            g3.addAll(f3(this.B0, this.p1.i2()));
        }
        List<fn> F3 = F3(hashSet);
        List<fn> D3 = D3(set, list, currentTimeMillis);
        fn i4 = i4(false);
        if (i4 != null) {
            o7.f("M", "RESTORE: " + i4.u1(this.z0));
            if (linkedList.size() == 1) {
                int intValue = linkedList.get(0).intValue();
                if (this.B0.V(intValue) && this.B0.c(intValue).r0()) {
                    i4.z2(intValue);
                }
            }
            F3.add(i4);
        }
        boolean z3 = false;
        for (int i3 = 0; i3 < g3.size(); i3++) {
            fn fnVar = g3.get(i3);
            if (bundle != null) {
                fnVar.F(null);
                z3 = true;
            }
            F3.add(fnVar);
        }
        boolean z4 = false;
        for (int i5 = 0; i5 < D3.size(); i5++) {
            fn fnVar2 = D3.get(i5);
            if (bundle != null) {
                fnVar2.r((Bundle) bundle.clone());
                z4 = true;
            }
            F3.add(fnVar2);
        }
        E7();
        S6(F3, false, false);
        ca(false, true);
        Z2();
        G4(set, list, str + ":handleProfileChanges");
        if (z4) {
            Iterator<fn> it = D3.iterator();
            while (it.hasNext()) {
                it.next().F(null);
            }
        }
        if (z3) {
            Iterator<fn> it2 = g3.iterator();
            while (it2.hasNext()) {
                it2.next().F(null);
            }
        }
        o7.f("M", "handleProfileChanges: done");
    }

    public void R5() {
        if (h7(-1) && !X9(10)) {
            er.k(this, "M");
        }
    }

    private void R6(boolean z2) {
        t9(9, z2, 3, new c());
    }

    private void R7(int i3, String str) {
        o7.f("M", "AC refresh cal: src " + i3 + " / " + str);
        synchronized (this.J0) {
            try {
                if (this.I0[i3] != null) {
                    if (this.K0[i3] == 0) {
                        o7.f("M", "refresh next time: skipping, it's zero");
                    } else {
                        o7.f("M", "refresh cal alarm: " + ug.k(i3) + ": " + ug.m(this.K0[i3]) + " " + ug.h(this, this.K0[i3]));
                        wo.C1(this.v0, 0, this.K0[i3], this.I0[i3], wo.K1(this, B8(this)), "M/refreshCal");
                    }
                }
            } catch (Throwable th2) {
                throw th2;
            }
        }
    }

    public void R8(int i3, boolean z2) {
        this.t[i3] = z2;
    }

    public void R9(boolean z2) {
        o7.f("M", "stop wifi scan");
        N9(5);
        N9(7);
        this.Z = 0;
        b8();
        if (z2) {
            n3();
        }
        Q9();
    }

    private boolean S1(String str, boolean z2) {
        if (str == null) {
            return false;
        }
        Intent intent = new Intent();
        intent.putExtra("eventType", 9997);
        intent.putExtra("pkg", str);
        R1(intent, -1, z2);
        return true;
    }

    public void S2() {
        TelephonyManager telephonyManager;
        if (!wp.e1(78) || (telephonyManager = (TelephonyManager) gi.d(this, "phone", "M", "checkTelChange")) == null) {
            return;
        }
        String networkOperatorName = telephonyManager.getNetworkOperatorName();
        if (networkOperatorName.equals(wp.A0(this, 78))) {
            return;
        }
        wp.S1(this, 78, networkOperatorName);
    }

    private LocationManager S3() {
        LocationManager locationManager = this.x0;
        if (locationManager == null) {
            locationManager = (LocationManager) gi.d(this, "location", "M", "getLocalLocMan");
        }
        if (locationManager == null) {
            o7.f("M", oh.g(this, 2131887719, new Object[0]));
        }
        return locationManager;
    }

    public void S4(Set<Integer> set, List<io> list, String str) {
        R4(set, list, null, str, false);
    }

    public void S5(String str, String str2) {
        fl.J(this, str, str2);
    }

    private void S6(List<fn> list, boolean z2, boolean z3) {
        Collections.sort(list, new fn.d());
        for (int i3 = 0; i3 < list.size(); i3++) {
            fn fnVar = list.get(i3);
            fn q0 = fnVar.q0();
            for (int c1 = q0.c1() - 1; c1 >= 0; c1--) {
                int j3 = q0.A0(c1).j();
                if (z0.g(j3)) {
                    int i4 = i3 + 1;
                    while (i4 < list.size()) {
                        fn fnVar2 = list.get(i4);
                        int i5 = 0;
                        while (true) {
                            if (i5 >= fnVar2.c1()) {
                                break;
                            }
                            net.dinglisch.android.taskerm.c A0 = fnVar2.A0(i5);
                            if (A0 != null && A0.j() == j3 && A0.L()) {
                                q0.r0(c1);
                                i4 = list.size();
                                break;
                            }
                            i5++;
                        }
                        i4++;
                    }
                }
            }
            if (q0.c1() > 0 && !z3) {
                ExecuteService.d6(this, q0, z2 ? 1 : 0, -1, -1, q0.Y0(), null, null, fnVar.H1() ? fnVar.i1() : null, fnVar.n() ? fnVar.l() : null);
            }
        }
    }

    private void S7(String str) {
        o7.f("M", "AC refresh cooldown alarm: " + str);
        PendingIntent pendingIntent = this.G0;
        if (pendingIntent != null) {
            wo.C1(this.v0, 0, this.H0, pendingIntent, wo.K1(this, B8(this)), "M/cooldown/" + str);
        }
    }

    private static void S8(boolean z2) {
        synchronized (Z1) {
            Z1 = Boolean.valueOf(z2);
        }
    }

    private void S9(int i3, Collection<String> collection) {
        StringBuilder sb = new StringBuilder();
        if (collection.size() > 0) {
            sb.append(",");
        }
        Iterator<String> it = collection.iterator();
        while (it.hasNext()) {
            sb.append(it.next());
            sb.append(",");
        }
        String sb2 = sb.toString();
        if (wp.w0(this, wp.I0(i3)).equals(sb2)) {
            return;
        }
        wp.S1(this, i3, sb2);
    }

    private void T2(String str, String[] strArr, int i3, List<j2> list) {
        for (int i4 = 0; i4 < strArr.length; i4++) {
            if (str.equals(strArr[i4])) {
                j2 j2Var = new j2(i3);
                j2Var.B1(0, i4);
                list.add(j2Var);
                return;
            }
        }
    }

    private void T4(java.lang.String r11, int r12) {
        throw new UnsupportedOperationException("Method not decompiled: net.dinglisch.android.taskerm.MonitorService.T4(java.lang.String, int):void");
    }

    public void T5(String str, String str2) {
        fl.K(this, str, str2, null);
    }

    private boolean T6(int i3) {
        return this.t[i3];
    }

    private void T7(String str) {
        synchronized (this.F0) {
            try {
                if (this.D0 != null) {
                    if (this.E0 == 0) {
                        o7.f("M", "refresh next time: skipping, it's zero");
                    } else {
                        o7.f("M", "refresh next time: " + ug.m(this.E0));
                        wo.C1(this.v0, 0, this.E0, this.D0, wo.K1(this, B8(this)), "M/refreshTime/" + str);
                    }
                }
            } catch (Throwable th2) {
                throw th2;
            }
        }
    }

    private static void T8(boolean z2, String str) {
        synchronized (T1) {
            o7.f("M", "setNeedDisable: " + str + " -> " + z2);
            T1 = Boolean.valueOf(z2);
        }
    }

    private void T9(boolean z2) {
        t9(6, z2, 3, new v());
    }

    private void U1(io ioVar, int i3) {
        for (int i4 = 4; i4 <= 6; i4++) {
            if (ioVar.Z0(i4) && ((bn) ioVar.T0(i4)).j() == i3) {
                List<bn> list = this.Z0.get(Integer.valueOf(i3));
                if (list == null) {
                    list = Collections.synchronizedList(new LinkedList());
                    this.Z0.put(Integer.valueOf(i3), list);
                }
                list.add((bn) ioVar.T0(i4));
            }
        }
    }

    private boolean U2(String str) {
        boolean z2;
        Iterator<wo> it = this.P0.values().iterator();
        while (true) {
            if (!it.hasNext()) {
                z2 = false;
                break;
            }
            if (it.next().z1(str)) {
                z2 = true;
                break;
            }
        }
        if (z2) {
            b5("varchange: " + str);
        }
        return z2;
    }

    private long U3() {
        return Math.min(Math.min(o4() - 15000, H3() - 15000), 45000L);
    }

    public void U4(int i3, int i4, j2 j2Var, String str, Bundle bundle, boolean z2) {
        switch (i3) {
            case 16:
                P6(this, "SATISFIED", str, j2Var);
                Bundle o3 = ji.o(str, bundle);
                if (o3 == null) {
                    o3 = new Bundle();
                }
                com.joaomgcd.taskerm.structuredoutput.j.d(o3, j2Var);
                P4(i4, j2Var, o3);
                break;
            case 17:
                P6(this, "UNSATISFIED", str, j2Var);
                break;
            case 18:
                P6(this, "UNKNOWN", str, j2Var);
                break;
            default:
                o7.k("M", "pid: " + i4 + ": unexpected plugin event result code " + i3 + " abort: " + z2 + " from " + str);
                P6(this, "UNEXPECTED", str, j2Var);
                o7.v("intentExtras", bundle);
                break;
        }
    }

    public static void U5() throws Exception {
    }

    private void U7(String str) {
        T7(str);
        for (int i3 = 0; i3 < ug.D(); i3++) {
            R7(i3, str);
        }
    }

    private void U8(boolean z2) {
        m2 = z2;
        o2 = true;
    }

    private void U9() {
        V9(false);
    }

    private void V1() {
        IntentFilter intentFilter = new IntentFilter();
        if (wp.e1(60)) {
            o7.f("M", "need monitor playing track");
            if (mh.J(getPackageManager(), "mobi.beyondpod")) {
                o7.f("M", "add beyondpod listener");
                intentFilter.addAction("mobi.beyondpod.action.PLAYBACK_STATUS");
            }
            if (mh.J(getPackageManager(), "com.maxmpz.audioplayer")) {
                o7.f("M", "add poweramp listener");
                intentFilter.addAction("com.maxmpz.audioplayer.TRACK_CHANGED");
                intentFilter.addAction("com.maxmpz.audioplayer.STATUS_CHANGED");
            }
            if (mh.H(getPackageManager(), d6.j.a)) {
                o7.f("M", "add phantom listener");
                intentFilter.addAction(d6.j.b);
            }
            intentFilter.addAction("com.android.music.metachanged");
            intentFilter.addAction("com.android.music.playstatechanged");
            intentFilter.addAction("com.android.music.playbackcomplete");
        }
        if (wp.e1(39)) {
            intentFilter.addAction("android.location.PROVIDERS_CHANGED");
        }
        if (wp.e1(90)) {
            intentFilter.addAction(UiModeManager.ACTION_ENTER_CAR_MODE);
            intentFilter.addAction(UiModeManager.ACTION_EXIT_CAR_MODE);
            intentFilter.addAction(UiModeManager.ACTION_ENTER_DESK_MODE);
            intentFilter.addAction(UiModeManager.ACTION_EXIT_DESK_MODE);
            intentFilter.addAction("androidx.car.app.connection.action.CAR_CONNECTION_UPDATED");
        }
        if (wp.e1(63) && !this.c1.contains("net.dinglisch.android.tasker.NNORUM")) {
            intentFilter.addAction("net.dinglisch.android.tasker.NNORUM");
        }
        if (((f1.v1(this) && U6(7)) || (MyAccessibilityService.a() && wp.e1(103))) && !this.c1.contains("net.dinglisch.android.tasker.NWINNY")) {
            intentFilter.addAction("net.dinglisch.android.tasker.NWINNY");
        }
        if (wp.g1() && !this.c1.contains("net.dinglisch.android.tasker.SMSUM")) {
            intentFilter.addAction("net.dinglisch.android.tasker.SMSUM");
            if (pp.g() >= 19 && pp.z(this, "android.permission.RECEIVE_SMS", "MregisterIntent2")) {
                intentFilter.addAction("android.provider.Telephony.SMS_RECEIVED");
            }
        }
        intentFilter.setPriority(999);
        X7(intentFilter, false, -1);
    }

    private void V2() {
        LinkedList<Integer> linkedList = l2;
        synchronized (linkedList) {
            linkedList.clear();
        }
    }

    private long V3() {
        return Math.min(Math.min(o4() - 15000, r4() - 15000), 20000L);
    }

    private j2 V4(int i3, String str, String str2, int i4, String str3) {
        Calendar x2 = ug.x();
        wp.S1(this, 79, str);
        wp.S1(this, 82, ug.i(this, x2));
        wp.S1(this, 84, ug.o(x2));
        if (i3 == 2) {
            wp.S1(this, 81, str2);
            wp.C(this, 83);
        } else {
            wp.S1(this, 83, str2);
            if (str3 != null) {
                wp.S1(this, 81, str3);
            } else {
                wp.C(this, 81);
            }
        }
        String r2 = TextUtils.isEmpty(str) ? null : xg.r(this, str, "display_name");
        if (TextUtils.isEmpty(r2)) {
            r2 = str;
        }
        wp.S1(this, 80, r2);
        String b3 = new a.C0133a.C0134a(this).b(i4);
        j2 j2Var = new j2(7);
        j2Var.B1(0, i3);
        j2Var.o0(1, str);
        j2Var.o0(2, str2);
        j2Var.o0(3, b3);
        j2Var.o0(4, str3);
        return j2Var;
    }

    private boolean V6() {
        return (this.T & 16) > 0 || W6();
    }

    private void V7(String str) {
        synchronized (this.M0) {
            try {
                PendingIntent pendingIntent = this.L0;
                if (pendingIntent != null) {
                    wo.C1(this.v0, 0, this.N0, pendingIntent, wo.K1(this, B8(this)), "M/userAbsentRefresh");
                }
            } catch (Throwable th2) {
                throw th2;
            }
        }
    }

    public static void V8(Context context, String str) {
        Intent intent = new Intent("net.dinglisch.android.tasker.ICOMUM");
        intent.putExtra("title", str);
        intent.setComponent(new ComponentName(context, MonitorService.class.getName()));
        M6(context, intent);
    }

    private void V9(boolean z2) {
        o7.f("M", "tidyup");
        B3(true);
        y3(true);
        C3(true);
        m3();
        l3(false);
        this.p1.c2(false);
        this.p1.Y1(false);
        o7.f("M", "rewrite rec");
        pp.V2(this, true, "M.tidyUp");
        k8();
        e8();
        d8();
        c8();
        j2();
        o2();
        if (!o2 || !n2) {
            o7.f("M", "user-absent activities");
            O9();
        }
        this.j0 = null;
        o7.f("M", "stop monitors");
        for (final int i3 = 0; i3 < z1; i3++) {
            this.p1.F(new Runnable() {
                @Override
                public final void run() {
                    MonitorService.this.I6(i3);
                }
            });
        }
        if (!z2) {
            eh.m.g().G(this);
            gf.k.h().G(this);
        }
        this.p1.y3(new String[0]);
        o7.f("M", "unreg internal receivers");
        List<ReceiverDynamic> f4 = f4();
        if (f4 != null) {
            Iterator<ReceiverDynamic> it = f4.iterator();
            while (it.hasNext()) {
                aa(it.next(), "dynamic");
            }
            f4.clear();
        }
        com.joaomgcd.taskerm.util.df.w(this);
        this.p1.A3();
        lf.e.i();
        this.p1.W2();
        this.c1.clear();
        o7.f("M", "destroy cals");
        i3();
        this.V = false;
        o7.f("M", "tidy up done");
    }

    private void W1(Notification.Builder builder) {
        if (!Kid.a() && Settings.H2(this) && ud.f0.h()) {
            String str = mh.B() + ".ReceiverStaticInternal";
            for (int i3 = 0; i3 < 3; i3++) {
                String F12 = Settings.F1(this, i3);
                if (!TextUtils.isEmpty(F12)) {
                    Intent intent = new Intent("net.dinglisch.android.tasker.MNUM");
                    intent.setClassName(getPackageName(), str);
                    intent.putExtra("type", 2);
                    intent.setData(Uri.parse("task://" + Uri.encode(F12)));
                    ud.f0.a(builder, 2131231046, F12, PendingIntent.getBroadcast(this, -1, intent, com.joaomgcd.taskerm.util.bi.m(134217728, intent)));
                } else if (i3 == 0 && !ep.l0(this)) {
                    Intent intent2 = new Intent("net.dinglisch.android.tasker.MNUM");
                    intent2.setClassName(getPackageName(), str);
                    intent2.putExtra("type", 1);
                    ud.f0.a(builder, 2131231041, oh.g(this, 2131888831, new Object[0]), PendingIntent.getBroadcast(this, -1, intent2, com.joaomgcd.taskerm.util.bi.m(134217728, intent2)));
                }
            }
        }
    }

    private void W2() {
        synchronized (t1) {
            P8("", "clearAppMonitorVars");
            Q8("", "clearAppMonitorVars");
        }
    }

    private long W3() {
        return this.A0.getLong("bttp", 15L) * 1000;
    }

    private void W4(int i3, String str) {
        int i4 = E1[i3];
        if (!B8(this)) {
            Q2(C1[i3], str, i4, p2());
        }
        if (da(str, i4, false) == 2) {
            P1();
        } else {
            a8();
        }
    }

    public static void W5(Context context, Intent intent) {
        int i3;
        if (d2(context)) {
            HelperMonitorService.U2(context);
        } else {
            HelperMonitorService.J2(context).y(new yi.a() {
                @Override
                public final void run() {
                    MonitorService.U5();
                }
            }, new yi.d() {
                @Override
                public final void accept(Object obj) {
                    o7.g("M", "Couldn't create tasker stopped notification on event", (Throwable) obj);
                }
            });
            Bundle extras = intent.getExtras();
            boolean z2 = false;
            if (extras == null || !extras.containsKey("eventType")) {
                i3 = -1;
            } else {
                i3 = extras.getInt("eventType");
                if (i3 == 9995 || i3 == 9987) {
                    z2 = true;
                }
            }
            if (!z2) {
                String string = i3 == 9996 ? extras.getString("eventAct") : intent.getAction();
                if (string == null) {
                    string = "?";
                }
                o7.f("M", "ignoring event when disabled: " + string);
                return;
            }
        }
        er.e(context, "M");
        synchronized (B1) {
            try {
                com.joaomgcd.taskerm.util.c0.C(context, intent, ExtensionsContextKt.s1(context), true, true);
            } catch (Exception e3) {
                o7.l("M", "On start service", e3);
            }
        }
    }

    private boolean W6() {
        return (this.T & 1024) > 0;
    }

    private void W7(int i3, j2 j2Var) {
        int j3 = j2Var.j();
        boolean d1 = i2.b(j3) ? j2Var.d1() : false;
        int i4 = this.z0.getIntArray(RFactory.layout.multiple_select_dialog_item)[j2Var.p1()];
        IntentFilter intentFilter = new IntentFilter();
        for (String str : i2.H(j2Var)) {
            if (str != null) {
                intentFilter.addAction(str);
                if (pp.g() >= 19 && str.equals("net.dinglisch.android.tasker.SMSUM") && pp.z(this, "android.permission.RECEIVE_SMS", "MregisterIntent")) {
                    intentFilter.addAction("android.provider.Telephony.SMS_RECEIVED");
                }
            }
        }
        intentFilter.setPriority(i4);
        String v2 = i2.v(j3);
        if (v2 != null) {
            intentFilter.addDataScheme(v2);
        }
        X7(intentFilter, d1, i3);
    }

    private void W8() {
        io ioVar;
        m2();
        synchronized (this.F0) {
            try {
                Calendar x2 = ug.x();
                x2.add(1, 2);
                Calendar x3 = ug.x();
                fo foVar = this.B0;
                boolean z2 = false;
                for (Integer num : this.O0) {
                    int intValue = num.intValue();
                    if (foVar != null) {
                        ioVar = foVar.c(intValue);
                        if (ioVar != null && !ioVar.h1()) {
                        }
                    } else {
                        ioVar = null;
                    }
                    Calendar l1 = wo.l1(this, x3, this.P0.get(num), 0, 0, com.joaomgcd.taskerm.util.b7.l0(foVar, this, ioVar, null, "setTimeAlarm"));
                    if (l1.getTimeInMillis() < x2.getTimeInMillis()) {
                        x2 = l1;
                    }
                    z2 = true;
                }
                if (z2) {
                    if (x2.getTimeInMillis() - System.currentTimeMillis() < 0) {
                        o7.f("M", "bug: trying to set alarm in the past " + x2.getTimeInMillis() + "/" + System.currentTimeMillis() + ", defaulting to 20 seconds in future");
                        x2 = ug.x();
                        x2.roll(13, 20);
                    }
                    Intent intent = new Intent(this, (Class<?>) ReceiverStaticInternal.class);
                    intent.setAction("net.dinglisch.android.tasker.ALARUM");
                    this.D0 = PendingIntent.getBroadcast(this, 0, intent, com.joaomgcd.taskerm.util.bi.m(268435456, intent));
                    this.E0 = x2.getTimeInMillis();
                    o7.f("M", "set next time: " + ug.r(x2, true) + " " + ug.i(this, x2));
                    T7("setTimeAlarm");
                } else {
                    o7.G("M", "no next time found");
                }
            } catch (Throwable th2) {
                throw th2;
            }
        }
    }

    private boolean W9(int i3) {
        boolean z2;
        int b3;
        synchronized (b2) {
            try {
                z2 = false;
                for (h1 h1Var : b2.values()) {
                    if (h1Var.n() && (b3 = h1Var.b()) > i3) {
                        o7.f("M", h1Var.k() + ": timeout, age " + b3 + ">" + i3);
                        h1Var.D();
                        z2 = true;
                    }
                }
            } catch (Throwable th2) {
                throw th2;
            }
        }
        return z2;
    }

    private void X1(String str) {
        synchronized (O1) {
            try {
                long currentTimeMillis = System.currentTimeMillis();
                ArrayList arrayList = new ArrayList();
                for (Map.Entry<Long, String> entry : O1.entrySet()) {
                    Long key = entry.getKey();
                    long longValue = key.longValue();
                    if (entry.getValue().equals(str) || currentTimeMillis - longValue > 86400000) {
                        arrayList.add(key);
                    }
                }
                Iterator it = arrayList.iterator();
                while (it.hasNext()) {
                    O1.remove((Long) it.next());
                }
                O1.put(Long.valueOf(System.currentTimeMillis()), str);
            } catch (Throwable th2) {
                throw th2;
            }
        }
    }

    private void X2(String str) {
        o7.f("M", "clear flags (" + str + "): " + Thread.currentThread().getName());
        Arrays.fill(this.s, false);
        eh.m.g().E();
        gf.k.h().E();
        Iterator<Map.Entry<Integer, a0>> it = this.T0.entrySet().iterator();
        while (it.hasNext()) {
            it.next().getValue().e(false);
        }
        Iterator<Map.Entry<Integer, e0>> it2 = this.U0.entrySet().iterator();
        while (it2.hasNext()) {
            it2.next().getValue().e(false);
        }
        this.Z0.clear();
        Arrays.fill(this.m0, false);
        this.T = 0;
        this.U = 0;
        this.V = false;
    }

    @TargetApi(24)
    private int X3() {
        TelephonyManager telephonyManager;
        if (!this.p1.G0(com.joaomgcd.taskerm.util.ac.W0(this)) || (telephonyManager = (TelephonyManager) gi.d(this, "phone", "M", "gmnt")) == null) {
            return 0;
        }
        int networkType = com.joaomgcd.taskerm.util.r.g() ? telephonyManager.getNetworkType() : telephonyManager.getDataNetworkType();
        o7.f("M", "getMobileNetworkType type: " + networkType);
        if (networkType == 0 || networkType == 1 || networkType == 2 || networkType == 4) {
            return 1;
        }
        if (networkType != 13) {
            switch (networkType) {
                case 8:
                case 9:
                case 10:
                    return 3;
                default:
                    o7.f("M", "unrecognized network type " + networkType + ". Defaulting to 3G.");
                    return 2;
            }
        }
        if (!com.joaomgcd.taskerm.util.r.k()) {
            TelephonyDisplayInfo h3 = HelperMonitorService.F.h(this, this.p1.j2());
            o7.f("M", "getMobileNetworkType telephonyDisplayInfo: " + h3);
            if (com.joaomgcd.taskerm.util.b7.z4(h3)) {
                return 5;
            }
        }
        return 4;
    }

    private void X4(Intent intent) {
        String str = this.v;
        this.v = intent.getStringExtra("title");
        if (c4() != 0) {
            ca(false, true);
            return;
        }
        o7.k("M", intent.getAction() + ": " + this.v + ": no ID");
        this.v = str;
    }

    private boolean X6() {
        for (int i3 = 0; i3 < 10; i3++) {
            if (this.s[C1[i3]] && da(D1[i3], E1[i3], false) == 2) {
                return true;
            }
        }
        return false;
    }

    private synchronized void X7(IntentFilter intentFilter, boolean z2, int i3) {
        if (this.p1.W1(intentFilter, i3)) {
            o7.f("M", "registerDynamic: not registering duplicate filter");
            return;
        }
        ReceiverDynamic receiverDynamic = new ReceiverDynamic(z2, i3 == -1 ? null : this.B0.c(i3), intentFilter, i3);
        try {
            if (this.p1.O2(receiverDynamic, intentFilter) != null) {
                receiverDynamic.c();
            }
            Iterator<String> actionsIterator = intentFilter.actionsIterator();
            while (actionsIterator.hasNext()) {
                String next = actionsIterator.next();
                if (!this.c1.contains(next)) {
                    this.c1.add(next);
                    o7.f("M", "register receiver action: " + next);
                }
            }
            f4().add(receiverDynamic);
        } catch (SecurityException e3) {
            o7.H("M", "registerDynamic", e3);
        }
    }

    private void X8() {
        ba("setWifiEnableFlag");
        boolean[] zArr = this.m0;
        boolean[] copyOf = Arrays.copyOf(zArr, zArr.length);
        X2("setWifiEnableFlag");
        this.m0 = Arrays.copyOf(copyOf, copyOf.length);
    }

    public boolean X9(int i3) {
        Handler handler = this.l0;
        return handler != null && handler.hasMessages(i3);
    }

    private void Y1() {
        long j3;
        long[] jArr = x1;
        long j4 = jArr[13];
        long W3 = W3();
        long U3 = U3();
        o7.f("M", "adjustBTTimeout: cur: " + j4 + "ms min: " + W3 + "ms max: " + U3 + "ms");
        if (this.h0 == -1) {
            o7.f("M", "didn't get scan result, add 2000ms");
            j3 = 2;
        } else {
            long currentTimeMillis = System.currentTimeMillis() - this.h0;
            long j5 = 0;
            if (currentTimeMillis > 300) {
                j5 = 0 - (currentTimeMillis / 4);
                o7.f("M", "had result " + currentTimeMillis + "ms ago, adjust by " + j5 + "ms");
            } else {
                o7.f("M", "had result " + currentTimeMillis + "ms ago, close enough, no change");
            }
            j3 = j5;
        }
        long j6 = jArr[13] + j3;
        jArr[13] = j6;
        if (j6 <= W3) {
            jArr[13] = W3;
            o7.f("M", "adjusted timeout to " + jArr[13] + "ms (min)");
            return;
        }
        if (j6 <= U3) {
            o7.f("M", "adjusted timeout to " + jArr[13] + "ms");
            return;
        }
        jArr[13] = U3;
        o7.f("M", "adjusted timeout to " + jArr[13] + "ms (max)");
    }

    private void Y2(int i3) {
        List<bn> list;
        if (this.Z0.containsKey(Integer.valueOf(i3)) && (list = this.Z0.get(Integer.valueOf(i3))) != null) {
            for (bn bnVar : new CopyOnWriteArrayList(list)) {
                o7.f("M", "clear check time for code " + i3);
                bnVar.v0();
            }
        }
    }

    private PendingIntent Y3() {
        Intent intent = new Intent("android.intent.action.MAIN");
        intent.addCategory("android.intent.category.LAUNCHER");
        intent.setComponent(new ComponentName(getPackageName(), Tasker.class.getName()));
        intent.addFlags(268435456);
        return PendingIntent.getActivity(this, 0, intent, com.joaomgcd.taskerm.util.bi.m(0, intent));
    }

    private void Y4(fn fnVar, Set<Integer> set) {
        if (fnVar == null) {
            o7.G("M", "handleSettingsDelist: null task");
            return;
        }
        for (int i3 = 0; i3 < fnVar.c1(); i3++) {
            int j3 = fnVar.A0(i3).j();
            if (this.f1.containsKey(Integer.valueOf(j3))) {
                this.f1.put(Integer.valueOf(j3), Integer.valueOf(this.f1.get(Integer.valueOf(j3)).intValue() - 1));
                if (set != null) {
                    set.add(Integer.valueOf(j3));
                }
            }
        }
    }

    public void Y5() {
        this.l0 = new f0(this);
    }

    private boolean Y6(boolean z2) {
        boolean[] zArr = this.s;
        if (zArr[3] || zArr[1] || zArr[2] || zArr[20] || V6()) {
            return true;
        }
        if (z2) {
            return false;
        }
        boolean[] zArr2 = this.s;
        if (!zArr2[4] && !zArr2[6]) {
            return false;
        }
        o7.f("M", "need user-absent alarm to refresh time alarm");
        return true;
    }

    private void Y8() {
        this.p1.d3();
        this.p1.O(new Runnable() {
            @Override
            public final void run() {
                MonitorService.this.D6();
            }
        });
    }

    private void Y9() {
        if (y5(307)) {
            for (Integer num : this.V0.get(307)) {
                io c3 = this.B0.c(num.intValue());
                if (c3.h1()) {
                    j2 j2Var = (j2) c3.T0(7);
                    j2Var.Q0(true);
                    if (x2(c3, new j2(307), null)) {
                        g2.put(num, Long.valueOf(System.currentTimeMillis()));
                    }
                    j2Var.w0();
                }
            }
        }
    }

    private final void Z1() {
        double d3;
        double d4;
        if (a2.size() > 0) {
            long o4 = o4();
            long H3 = H3();
            if (n2) {
                d3 = o4;
                d4 = H3;
            } else {
                double d5 = o4;
                d3 = H3;
                d4 = d5;
            }
            long currentTimeMillis = System.currentTimeMillis();
            for (h1 h1Var : a2.values()) {
                String a3 = h1Var.a();
                long e3 = currentTimeMillis - h1Var.e();
                double d6 = (float) (e3 / d3);
                long j3 = currentTimeMillis - ((long) (d6 * d4));
                o7.f("M", a3 + ": mult: " + d6 + " old: " + e3 + "ms new: " + (currentTimeMillis - j3) + "ms");
                h1Var.u(j3);
            }
        }
    }

    private void Z2() {
        LinkedList<Integer> linkedList = l2;
        synchronized (linkedList) {
            try {
                linkedList.clear();
                com.joaomgcd.taskerm.util.h hVar = this.Y0;
                if (hVar == null) {
                    return;
                }
                ArrayList arrayList = new ArrayList(hVar);
                int size = arrayList.size();
                for (int i3 = 0; i3 < size; i3++) {
                    l2.add(Integer.valueOf(((io) arrayList.get(i3)).C0()));
                }
            } catch (Throwable th2) {
                throw th2;
            }
        }
    }

    public int Z3(float f3, float f4, float f5, float f6) {
        float f7 = (f6 / 1.7f) + 2.0f;
        float abs = Math.abs(f3);
        float abs2 = Math.abs(f4);
        float abs3 = Math.abs(f5);
        float f8 = abs / f7;
        float f9 = abs2 / f7;
        float f10 = abs3 / f7;
        if (f3 + f4 < f5 && f5 > 0.0f && abs < f10 && abs2 < f10) {
            return 0;
        }
        float f11 = 0.0f - f3;
        if (f11 - f4 > f5 && f5 < 0.0f && abs < f10 && abs2 < f10) {
            return 1;
        }
        if (f3 + f5 < f4 && f4 > 0.0f && abs < f9 && abs3 < f9) {
            return 2;
        }
        if (f11 - f5 > f4 && f4 < 0.0f && abs < f9 && abs3 < f9) {
            return 3;
        }
        if (f4 + f5 >= f3 || f3 <= 0.0f || abs2 >= f8 || abs3 >= f8) {
            return (0.0f - f4) - f5 > f3 ? 5 : -1;
        }
        return 4;
    }

    public void Z5() {
        fl.W(this, null);
    }

    public static void Z6(Context context, String str) {
        if ("clock_alarm".equals(str)) {
            return;
        }
        Intent intent = new Intent("net.dinglisch.android.tasker.PREFUM");
        intent.putExtra("title", str);
        intent.setComponent(new ComponentName(context, MonitorService.class.getName()));
        M6(context, intent);
    }

    private void Z7() {
        final Runnable runnable = new Runnable() {
            @Override
            public final void run() {
                MonitorService.this.v6();
            }
        };
        this.p1.o0(HelperMonitorService.J2(this), new ik.a() {
            @Override
            public final Object e() {
                vj.e0 w6;
                w6 = MonitorService.w6(runnable);
                return w6;
            }
        }, new yi.d() {
            @Override
            public final void accept(Object obj) {
                MonitorService.x6(runnable, (Throwable) obj);
            }
        });
    }

    private void Z8() {
        if (this.e0 == null) {
            this.e0 = new g();
            IntentFilter intentFilter = new IntentFilter("android.bluetooth.device.action.ACL_CONNECTED");
            intentFilter.addAction("android.bluetooth.device.action.FOUND");
            intentFilter.addAction("android.bluetooth.adapter.action.DISCOVERY_FINISHED");
            intentFilter.addAction("android.bluetooth.adapter.action.DISCOVERY_STARTED");
            intentFilter.setPriority(-999);
            ExtensionsContextKt.W3(this, this.e0, intentFilter, null, this.p1.V().e());
        }
    }

    private void Z9(w1 w1Var) {
        if (w1Var == null) {
            return;
        }
        w1Var.a();
        this.w0.unregisterContentObserver(w1Var);
    }

    private final void a2() {
        double d3;
        double d4;
        if (W1.size() > 0) {
            long o4 = o4();
            long r4 = r4();
            if (n2) {
                d3 = o4;
                d4 = r4;
            } else {
                double d5 = o4;
                d3 = r4;
                d4 = d5;
            }
            long currentTimeMillis = System.currentTimeMillis();
            Iterator<Map.Entry<String, Long>> it = W1.entrySet().iterator();
            while (it.hasNext()) {
                W1.put(it.next().getKey(), Long.valueOf(currentTimeMillis - ((long) (((float) ((currentTimeMillis - r7.getValue().longValue()) / d3)) * d4))));
            }
        }
    }

    private void a3(fo foVar) {
        for (Integer num : this.W0.keySet()) {
            if (an.O(num.intValue())) {
                Iterator<Integer> it = this.W0.get(num).iterator();
                while (it.hasNext()) {
                    int intValue = it.next().intValue();
                    if (foVar.V(intValue)) {
                        io c3 = foVar.c(intValue);
                        io c4 = this.B0.c(intValue);
                        if (c4.c() == c3.c()) {
                            for (int i3 = 4; i3 <= 6; i3++) {
                                if (c4.Z0(i3) && c3.Z0(i3)) {
                                    bn bnVar = (bn) c3.T0(i3);
                                    bn bnVar2 = (bn) c4.T0(i3);
                                    int j3 = bnVar.j();
                                    int j4 = bnVar2.j();
                                    if (an.O(j4) && j3 == j4) {
                                        bnVar2.o1(bnVar);
                                        if (c4.h1() && c3.h1()) {
                                            bnVar2.Q0(bnVar.K0());
                                            bnVar2.n1(bnVar);
                                            o7.f("M", "profile " + c4.H0() + "/stype " + i3 + ": take over " + bnVar.K0() + " activation from old data");
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
            }
        }
    }

    public static pg.v1 a4(Context context, List<io> list) {
        if (list != null && list.size() > 0) {
            if (p2 == null) {
                p2 = new pg.v1("M", oh.g(context.getApplicationContext(), 2131890562, new Object[0]), "Main Tasker notification that shows status of active profiles and other info");
            }
            return p2;
        }
        if (q2 == null) {
            q2 = new pg.v1("Mno", oh.g(context, 2131890562, new Object[0]) + " (" + oh.g(context, 2131889258, new Object[0]) + ")", "Main Tasker notification that shows status of active profiles and other info");
        }
        return q2;
    }

    public void a6() {
        o7.f("M", "ICS workaround, repost service notification");
        if (d2(this)) {
            ca(false, true);
        }
    }

    private ti.b a7() {
        HelperMonitorService helperMonitorService = this.p1;
        return helperMonitorService.C(helperMonitorService.p2(), new Runnable() {
            @Override
            public final void run() {
                MonitorService.this.c6();
            }
        });
    }

    private void a8() {
        if (!er.j("Sensor") || X6()) {
            return;
        }
        er.k(this, "Sensor");
    }

    private void a9() {
        boolean z2;
        Iterator<Map.Entry<Integer, List<Integer>>> it = this.W0.entrySet().iterator();
        while (true) {
            int i3 = 2;
            int i4 = 6;
            if (!it.hasNext()) {
                break;
            }
            Map.Entry<Integer, List<Integer>> next = it.next();
            List<Integer> value = next.getValue();
            int intValue = next.getKey().intValue();
            if (!an.O(intValue)) {
                int i5 = 0;
                while (i5 < value.size()) {
                    int intValue2 = value.get(i5).intValue();
                    String str = null;
                    int i6 = 0;
                    while (i6 < i3) {
                        String p3 = i6 == 0 ? an.p(this, intValue) : an.q(this, intValue);
                        if (p3 != null && (str == null || !p3.equals(str))) {
                            IntentFilter intentFilter = new IntentFilter();
                            "android.net.conn.CONNECTIVITY_CHANGE".equals(p3);
                            intentFilter.addAction(p3);
                            if (intValue == 105) {
                                io c3 = this.B0.c(intValue2);
                                int i7 = 4;
                                while (i7 <= i4) {
                                    if (c3.Z0(i7)) {
                                        bn bnVar = (bn) c3.T0(i7);
                                        if (bnVar.j() == 105 && bnVar.i(3).T()) {
                                            z2 = true;
                                            break;
                                        }
                                    }
                                    i7++;
                                    i4 = 6;
                                }
                            }
                            z2 = false;
                            X7(intentFilter, z2, intValue2);
                            if (intValue == 110) {
                                this.p1.P2();
                            }
                            str = p3;
                        }
                        i6++;
                        i3 = 2;
                        i4 = 6;
                    }
                    i5++;
                    i3 = 2;
                    i4 = 6;
                }
            }
        }
        HashSet hashSet = new HashSet();
        HashSet hashSet2 = new HashSet();
        Set<Integer> Q = i2.Q();
        for (Map.Entry<Integer, List<Integer>> entry : this.V0.entrySet()) {
            Integer key = entry.getKey();
            int intValue3 = key.intValue();
            if (intValue3 == 599) {
                Iterator<Integer> it2 = entry.getValue().iterator();
                while (it2.hasNext()) {
                    Y7(it2.next().intValue(), new String[0]);
                }
            } else if (i2.c(intValue3) || intValue3 == 7) {
                hashSet2.add(key);
                List<Integer> value2 = entry.getValue();
                for (int i8 = 0; i8 < value2.size(); i8++) {
                    int intValue4 = value2.get(i8).intValue();
                    W7(intValue4, (j2) this.B0.c(intValue4).T0(7));
                }
            } else {
                hashSet.add(key);
            }
        }
        IntentFilter intentFilter2 = new IntentFilter();
        if (f1.v1(this) && this.B0.X2(0) && !hashSet2.contains(463)) {
            intentFilter2.addAction("net.dinglisch.android.tasker.NWINNY");
        }
        if (!hashSet2.contains(1000)) {
            intentFilter2.addAction("android.intent.action.USER_PRESENT");
        }
        if (!hashSet2.contains(413)) {
            intentFilter2.addAction("android.intent.action.ACTION_SHUTDOWN");
        }
        if (!hashSet2.contains(210)) {
            intentFilter2.addAction("android.intent.action.SCREEN_OFF");
        }
        if (!hashSet2.contains(208)) {
            intentFilter2.addAction("android.intent.action.SCREEN_ON");
        }
        if (A5(40)) {
            intentFilter2.addAction("android.intent.action.NEW_OUTGOING_CALL");
        }
        if (B5()) {
            intentFilter2.addAction("android.bluetooth.headset.action.STATE_CHANGED");
            intentFilter2.addAction("android.media.SCO_AUDIO_STATE_CHANGED");
            intentFilter2.addAction("android.bluetooth.device.action.ACL_CONNECTED");
            intentFilter2.addAction("android.bluetooth.device.action.ACL_DISCONNECTED");
            intentFilter2.addAction("android.bluetooth.a2dp.action.SINK_STATE_CHANGED");
            intentFilter2.addAction("android.bluetooth.adapter.action.CONNECTION_STATE_CHANGED");
        }
        if (!intentFilter2.hasAction("android.bluetooth.device.action.ACL_CONNECTED") && (this.B0.u3(341) || TaskerAppWidgetConfigure.o(this, 341))) {
            intentFilter2.addAction("android.bluetooth.device.action.ACL_CONNECTED");
            intentFilter2.addAction("android.bluetooth.device.action.ACL_DISCONNECTED");
        }
        if ((this.C0.contains(3) || B5()) && !A5(2)) {
            intentFilter2.addAction("android.bluetooth.adapter.action.STATE_CHANGED");
        }
        if (this.C0.contains(101)) {
            intentFilter2.addAction("android.net.wifi.WIFI_STATE_CHANGED");
        }
        if (this.C0.contains(0)) {
            intentFilter2.addAction("android.intent.action.AIRPLANE_MODE");
        }
        if (this.C0.contains(72)) {
            intentFilter2.addAction("android.media.RINGER_MODE_CHANGED");
        }
        intentFilter2.addAction("android.net.conn.TETHER_STATE_CHANGED");
        if ((this.C0.contains(46) || this.C0.contains(72)) && bi.n()) {
            intentFilter2.addAction("net.dinglisch.android.tasker.NSI.ACTION_FILTER_CHANGED");
        }
        if (this.C0.contains(93) || this.C0.contains(94) || this.C0.contains(95) || this.C0.contains(96) || this.C0.contains(97) || this.C0.contains(98) || this.C0.contains(99)) {
            intentFilter2.addAction("org.openintents.audio.action_volume_update");
            intentFilter2.addAction("android.media.VOLUME_CHANGED_ACTION");
        }
        if (!this.C0.contains("android.intent.action.ACTION_POWER_CONNECTED")) {
            intentFilter2.addAction("android.intent.action.ACTION_POWER_CONNECTED");
        }
        if (!this.C0.contains("android.intent.action.ACTION_POWER_DISCONNECTED")) {
            intentFilter2.addAction("android.intent.action.ACTION_POWER_DISCONNECTED");
        }
        intentFilter2.setPriority(999);
        if (intentFilter2.actionsIterator().hasNext()) {
            X7(intentFilter2, false, -1);
        }
        if (!hashSet2.contains(453) && !hashSet2.contains(450)) {
            IntentFilter intentFilter3 = new IntentFilter("android.intent.action.PACKAGE_ADDED");
            intentFilter3.addDataScheme("package");
            X7(intentFilter3, false, -1);
        }
        if (!hashSet2.contains(134)) {
            W7(-1, new j2(134));
        }
        if (hashSet2.contains(216)) {
            mh.R(this, LongPressSearch.class.getName(), hashSet2.contains(216));
        }
        Q.add(6);
        Iterator<Integer> it3 = wp.m0().iterator();
        while (it3.hasNext()) {
            if (wp.T0(it3.next().intValue()) && !hashSet2.contains(6)) {
                hashSet.add(6);
            }
        }
        for (Integer num : Q) {
            A3(num.intValue(), hashSet.contains(num));
        }
        V1();
    }

    private void b2() {
        long j3;
        long[] jArr = x1;
        long j4 = jArr[7];
        long j5 = this.A0.getLong("wip", 10L) * 1000;
        long V3 = V3();
        o7.f("M", "adjustWifiTimeout: cur: " + j4 + "ms min: " + j5 + "ms max: " + V3 + "ms");
        if (this.b0 == -1) {
            o7.f("M", "didn't get scan result, add 2000ms");
            j3 = 2;
        } else {
            long currentTimeMillis = System.currentTimeMillis() - this.b0;
            long j6 = 0;
            if (currentTimeMillis > 300) {
                j6 = 0 - (currentTimeMillis / 4);
                o7.f("M", "had result " + currentTimeMillis + "ms ago, adjust by " + j6 + "ms");
            } else {
                o7.f("M", "had result " + currentTimeMillis + "ms ago, close enough, no change");
            }
            j3 = j6;
        }
        long j7 = jArr[7] + j3;
        jArr[7] = j7;
        if (j7 <= j5) {
            jArr[7] = j5;
            o7.f("M", "adjusted timeout to " + jArr[7] + "ms (min)");
            return;
        }
        if (j7 <= V3) {
            o7.f("M", "adjusted timeout to " + jArr[7] + "ms");
            return;
        }
        jArr[7] = V3;
        o7.f("M", "adjusted timeout to " + jArr[7] + "ms (max)");
    }

    private void b3(fo foVar) {
        Iterator<Integer> it = foVar.p2().iterator();
        while (it.hasNext()) {
            int intValue = it.next().intValue();
            if (this.B0.V(intValue)) {
                this.B0.c(intValue).G1(foVar.c(intValue));
            }
        }
    }

    private static pg.v1 b4(MonitorService monitorService) {
        return a4(monitorService, monitorService.Y0);
    }

    private void b5(final String str) {
        x3(new Runnable() {
            @Override
            public final void run() {
                MonitorService.this.Q5(str);
            }
        }, "handleTimeAlarm");
    }

    public void b6() {
        if (d2(this)) {
            E9(this, new Intent("android.intent.action.BOOT_COMPLETED"), -1);
        }
        ge.q.h(this);
    }

    private void b8() {
        WifiManager.WifiLock wifiLock = this.Y;
        if (wifiLock != null) {
            try {
                wifiLock.release();
            } catch (SecurityException e3) {
                o7.H("M", "releaseWifiLock: " + e3.toString(), e3);
            } catch (Throwable th2) {
                o7.I("M", "releaseWifiLock Throwable: " + th2.toString(), th2);
            }
            this.Y = null;
        }
    }

    private void b9() {
        if (this.W == null) {
            e eVar = new e();
            this.W = eVar;
            ExtensionsContextKt.W3(this, eVar, new IntentFilter("android.net.wifi.SCAN_RESULTS"), null, this.p1.V().e());
        }
    }

    private void ba(java.lang.String r42) {
        throw new UnsupportedOperationException("Method not decompiled: net.dinglisch.android.taskerm.MonitorService.ba(java.lang.String):void");
    }

    public boolean c2(int i3, long j3) {
        List<bn> list = this.Z0.get(Integer.valueOf(i3));
        if (list == null) {
            return false;
        }
        CopyOnWriteArrayList copyOnWriteArrayList = new CopyOnWriteArrayList(list);
        Iterator it = copyOnWriteArrayList.iterator();
        int i4 = 0;
        while (it.hasNext()) {
            if (((sn) it.next()).A0() > j3) {
                i4++;
            }
        }
        if (i4 < copyOnWriteArrayList.size()) {
            return false;
        }
        o7.f("M", "allStatesChecked: for code " + i3 + ": results matched " + i4 + " contexts");
        return true;
    }

    private void c3() {
        if (A5(5) || y5(2102)) {
            for (int i3 = 0; i3 < ug.D(); i3++) {
                if (ug.M(getPackageManager(), i3)) {
                    this.n0[i3] = new ug(this.w0, i3);
                    o7.f("M", "have calendar source: " + ug.k(i3));
                } else {
                    this.n0[i3] = null;
                }
            }
        }
    }

    public void c6() {
        uh.b(this, "M");
        HelperMonitorService.U2(this);
        xg.h.m(new xf.k7());
        com.joaomgcd.taskerm.util.zc.z(this, false);
        Settings.p1(this.A0, pp.S0(this));
        t6.e(getBaseContext());
        this.z0 = getResources();
        for (int i3 = 13; i3 <= 18; i3++) {
            G7(i3, 0, false);
        }
        I5(true, true);
        this.p1.F(new Runnable() {
            @Override
            public final void run() {
                MonitorService.this.Y5();
            }
        });
        H1 = ug.I();
        V2();
        H5();
        o7.f("M", "init");
        if (G5() && J5(true)) {
            Arrays.fill(this.t, false);
            W9(5);
            q8();
            o7.f("M", "initial match checks");
            v3();
            o7.f("M", "initial match checks: done");
            X8();
            C3(false);
            z3();
            Y9();
            o7.f("M", "onCreate: handleProfileChanges");
            R4(this.B0.p2(), null, null, "onAfterInit", true);
            o7.f("M", "reshow overlay scenes");
            this.p1.F(new Runnable() {
                @Override
                public final void run() {
                    MonitorService.this.Z5();
                }
            });
            o7.f("M", "created");
            if (pp.O1()) {
                new Handler().postDelayed(new Runnable() {
                    @Override
                    public final void run() {
                        MonitorService.this.a6();
                    }
                }, 12000L);
            }
        }
        o7.f("M", "------------------ MONITOR STARTUP COMPLETE -----------------");
        if (com.joaomgcd.taskerm.util.zc.f(this)) {
            o7.f("M", "------------------ BOOT COMPLETED IN MONITOR STARTUP -----------------");
            this.p1.N(new Runnable() {
                @Override
                public final void run() {
                    MonitorService.this.b6();
                }
            });
        }
    }

    @SuppressLint({"MissingPermission"})
    private int c7() {
        Set<BluetoothDevice> bondedDevices;
        Object a3;
        if (!this.p1.G0(com.joaomgcd.taskerm.util.ac.a0(this)) || !this.Z0.containsKey(4) || (bondedDevices = i1.h(this).getBondedDevices()) == null) {
            return 0;
        }
        int i3 = 0;
        for (BluetoothDevice bluetoothDevice : bondedDevices) {
            o7.f("M", "test device: " + bluetoothDevice.getName() + " / " + bluetoothDevice.getAddress());
            List<bn> list = this.Z0.get(4);
            if (list == null) {
                return i3;
            }
            Iterator it = new CopyOnWriteArrayList(list).iterator();
            while (true) {
                if (!it.hasNext()) {
                    break;
                }
                if (((bn) it.next()).b1(this, bluetoothDevice)) {
                    o7.f("M", "device matches");
                    if (i1.p(getPackageManager()) && h1.C(bluetoothDevice.getType()) && ud.g.c() && U6(3)) {
                        Map<String, Object> map = this.c0;
                        if (map == null || !map.containsKey(bluetoothDevice.getAddress())) {
                            Object i4 = i1.i(new m());
                            if (i4 == null) {
                                o7.k("M", "no gatt callback");
                                a3 = null;
                            } else {
                                a3 = ud.g.a(bluetoothDevice, this, false, i4);
                                StringBuilder sb = new StringBuilder();
                                sb.append("got new gatt: ");
                                sb.append(a3 != null);
                                o7.f("M", sb.toString());
                                if (a3 != null) {
                                    if (this.c0 == null) {
                                        this.c0 = new HashMap();
                                    }
                                    this.c0.put(bluetoothDevice.getAddress(), a3);
                                }
                            }
                        } else {
                            o7.f("M", "use existing gatt");
                            a3 = this.c0.get(bluetoothDevice.getAddress());
                            if (!ud.h.b(a3)) {
                                o7.f("M", "connect failed");
                            }
                        }
                        if (a3 != null) {
                            o7.f("M", "started gatt connect for " + bluetoothDevice.getAddress());
                            i3++;
                        } else {
                            o7.G("M", "btScan: failed to get gatt for " + bluetoothDevice.getName());
                        }
                    } else if (U6(2)) {
                        if (bluetoothDevice.fetchUuidsWithSdp()) {
                            o7.f("M", "started fetch for " + bluetoothDevice.getName());
                            i3++;
                        } else {
                            o7.G("M", "btScan: failed to start fetch for " + bluetoothDevice.getName());
                        }
                    }
                }
            }
        }
        return i3;
    }

    private void c8() {
        if (this.c0 != null) {
            o7.f("M", "remove gatts");
            for (Map.Entry<String, Object> entry : this.c0.entrySet()) {
                String key = entry.getKey();
                Object value = entry.getValue();
                o7.f("M", "close gatt for " + key);
                ud.h.a(value);
            }
            this.c0 = null;
        }
    }

    private void c9(boolean z2) {
        u9(2, z2, 1, new q(), true);
    }

    public static boolean d2(Context context) {
        return pp.S0(context).getBoolean(ClockContract.AlarmsColumns.ENABLED, true);
    }

    private void d3(boolean z2) {
        this.P0 = new ConcurrentHashMap();
        this.R0 = new ConcurrentHashMap();
        this.S0 = new ConcurrentHashMap();
        this.Q0 = new ConcurrentHashMap();
        this.Z0 = new HashMap<>();
        this.C0 = new HashSet();
        this.X0 = new ArrayList();
        this.T0 = new HashMap();
        this.U0 = new HashMap();
        this.Y0 = new com.joaomgcd.taskerm.util.h();
        fo foVar = this.B0;
        if (foVar != null) {
            tc.e.d(this, this.p1.S(), foVar, this.Y0);
        }
        this.O0 = com.joaomgcd.taskerm.util.bi.n();
        this.V0 = new HashMap();
        this.W0 = new ConcurrentHashMap();
        this.a1 = Collections.synchronizedList(new LinkedList());
        this.b1 = new CopyOnWriteArrayList();
        this.c1 = new HashSet();
        if (z2) {
            this.d1 = new HashMap();
            this.f1 = new HashMap();
            this.y = new ArrayList();
            this.z = new ArrayList();
            this.A = new ArrayList();
            o7.f("M", "initing inbox");
            this.g1 = new ConcurrentLinkedDeque<>();
        }
    }

    private String d4(boolean z2) {
        ArrayList arrayList = new ArrayList(this.Y0);
        int size = arrayList.size();
        String str = "";
        if (size <= 0) {
            return "";
        }
        int i3 = 0;
        for (int i4 = 0; i4 < size; i4++) {
            io ioVar = (io) arrayList.get(i4);
            if (ioVar.d1()) {
                i3++;
            } else {
                if (i4 > 0) {
                    str = str + "|";
                }
                str = str + ioVar.l1(this);
            }
        }
        if (!Kid.b(this) && i3 > 0 && str.length() > 0) {
            str = str + "|+" + String.valueOf(i3);
        }
        if ((str.length() != 0 || i3 <= 0) && (z2 || str.length() <= 35)) {
            return str;
        }
        return pp.s0(getString(size == 1 ? 2131886160 : 2131886161), Integer.valueOf(size));
    }

    public void d5() {
        try {
            u2();
            if (this.s[5]) {
                r8(5, "handleTimerApp");
            } else {
                o7.f("M", "handleTimerApp not needed");
            }
        } catch (NullPointerException e3) {
            o7.l("M", "handleMessage:app:", e3);
        }
    }

    public void d6(Configuration configuration) {
        fl.W(this, configuration);
    }

    private void d7(NotificationManager notificationManager, Notification notification, boolean z2) {
        if (z2) {
            notificationManager.notify(Integer.MAX_VALUE, notification);
        } else {
            stopForeground(true);
            com.joaomgcd.taskerm.util.c0.v(this, Integer.MAX_VALUE, notification);
        }
    }

    private void d8() {
        this.f0 = null;
        this.p1.T2();
    }

    private int da(String str, int i3, boolean z2) {
        if (str == null) {
            return 1;
        }
        int i4 = this.A0.getInt(str, i3);
        if (i4 == 1) {
            return z2 ? 1 : 0;
        }
        if (i4 != 2) {
            return i4 != 3 ? 0 : 2;
        }
        return 1;
    }

    private int e2(Bundle bundle) {
        if (bundle == null) {
            return -1;
        }
        int i3 = bundle.getInt("plugged", -1);
        if (bundle.containsKey("charge_type") && pp.g() < 19) {
            o7.f("M", "bbtp: have charge_type key, pre KK SDK");
            if (i3 > 0) {
                o7.f("M", "bbtp: charge_type: " + bundle.getInt("charge_type", -1));
            }
        }
        return i3;
    }

    private void e3(Set<Integer> set) {
        if (!this.V) {
            o7.f("M", "deactiveUnmonitoredContexts: skip, flags not initialized");
            return;
        }
        Iterator<Integer> it = set.iterator();
        while (it.hasNext()) {
            int intValue = it.next().intValue();
            io c3 = this.B0.c(intValue);
            if (c3 == null) {
                o7.k("M", "dauc: pid " + intValue + " non-existant");
            } else if (c3.e1()) {
                for (int i3 = 0; i3 < c3.I0(); i3++) {
                    sn S0 = c3.S0(i3);
                    switch (S0.F0()) {
                        case 0:
                            if (!this.s[5] && !U6(6) && !U6(7)) {
                                o7.f("M", "p: " + c3.H0() + " set app inactive");
                                S0.Q0(false);
                                break;
                            }
                            break;
                        case 1:
                            if (this.s[4]) {
                                break;
                            } else {
                                o7.f("M", "p: " + c3.H0() + " set time inactive");
                                S0.Q0(false);
                                break;
                            }
                        case 2:
                            if (this.s[4]) {
                                break;
                            } else {
                                o7.f("M", "p: " + c3.H0() + " set day inactive");
                                S0.Q0(false);
                                break;
                            }
                        case 3:
                            n7 n7Var = (n7) S0;
                            boolean z2 = n7Var.o1() && this.s[1];
                            boolean z3 = n7Var.p1() && this.s[2];
                            if (!z3 && !z2) {
                                o7.f("M", "p: " + c3.H0() + " set loc inactive gps " + z2 + " net: " + z3);
                                S0.Q0(false);
                                break;
                            }
                            break;
                        case 4:
                        case 5:
                        case ClockContract.InstancesColumns.MISSED_STATE:
                            int j3 = ((bn) S0).j();
                            if (j3 != 4) {
                                if (j3 != 5) {
                                    if (j3 != 7) {
                                        if (j3 != 120) {
                                            if (j3 != 125) {
                                                if (j3 != 145) {
                                                    if (j3 != 147) {
                                                        if (j3 != 170) {
                                                            if (j3 != 180) {
                                                                if (j3 != 182) {
                                                                    if (j3 != 185) {
                                                                        if (j3 != 103) {
                                                                            if (j3 != 104) {
                                                                                if (j3 != 106) {
                                                                                    if (j3 == 107 && !this.s[9]) {
                                                                                        o7.f("M", "p: " + c3.H0() + " set missed call inactive");
                                                                                        S0.Q0(false);
                                                                                        break;
                                                                                    }
                                                                                } else if (this.s[17]) {
                                                                                    break;
                                                                                } else {
                                                                                    o7.f("M", "p: " + c3.H0() + " set magnet inactive");
                                                                                    S0.Q0(false);
                                                                                    break;
                                                                                }
                                                                            } else if (this.s[16]) {
                                                                                break;
                                                                            } else {
                                                                                o7.f("M", "p: " + c3.H0() + " set pressure inactive");
                                                                                S0.Q0(false);
                                                                                break;
                                                                            }
                                                                        } else if (this.s[13]) {
                                                                            break;
                                                                        } else {
                                                                            o7.f("M", "p: " + c3.H0() + " set light inactive");
                                                                            S0.Q0(false);
                                                                            break;
                                                                        }
                                                                    } else if (this.s[21]) {
                                                                        break;
                                                                    } else {
                                                                        o7.f("M", "p: " + c3.H0() + " set humidity inactive");
                                                                        S0.Q0(false);
                                                                        break;
                                                                    }
                                                                } else if (this.s[24]) {
                                                                    break;
                                                                } else {
                                                                    o7.f("M", "p: " + c3.H0() + " set heart rate inactive");
                                                                    S0.Q0(false);
                                                                    break;
                                                                }
                                                            } else if (this.s[19]) {
                                                                break;
                                                            } else {
                                                                o7.f("M", "p: " + c3.H0() + " set temp inactive");
                                                                S0.Q0(false);
                                                                break;
                                                            }
                                                        } else if (this.s[3]) {
                                                            break;
                                                        } else {
                                                            o7.f("M", "p: " + c3.H0() + " set wifi near inactive");
                                                            S0.Q0(false);
                                                            break;
                                                        }
                                                    } else if (this.s[14]) {
                                                        break;
                                                    } else {
                                                        o7.f("M", "p: " + c3.H0() + " set unread messageinactive");
                                                        S0.Q0(false);
                                                        break;
                                                    }
                                                }
                                            } else if (this.s[12]) {
                                                break;
                                            } else {
                                                o7.f("M", "p: " + c3.H0() + " set prox inactive");
                                                S0.Q0(false);
                                                break;
                                            }
                                        } else if (this.s[0]) {
                                            break;
                                        } else {
                                            o7.f("M", "p: " + c3.H0() + " set orientation inactive");
                                            S0.Q0(false);
                                            break;
                                        }
                                    }
                                    if (this.s[10]) {
                                        break;
                                    } else {
                                        o7.f("M", "p: " + c3.H0() + " set cell near/ss inactive");
                                        S0.Q0(false);
                                        break;
                                    }
                                } else if (this.s[6]) {
                                    break;
                                } else {
                                    o7.f("M", "p: " + c3.H0() + " set cal inactive");
                                    S0.Q0(false);
                                    break;
                                }
                            } else if (this.s[20]) {
                                break;
                            } else {
                                o7.f("M", "p: " + c3.H0() + " set bt near inactive");
                                S0.Q0(false);
                                break;
                            }
                    }
                }
            }
        }
    }

    private String e4(boolean z2, boolean z3) {
        String d4 = z2 ? "" : d4(z3);
        return TextUtils.isEmpty(d4) ? (this.B0 == null || !com.joaomgcd.taskerm.settings.d1.v(this)) ? getString(2131889258) : getString(2131889259, Integer.valueOf(this.B0.O1().size()), Integer.valueOf(this.B0.d2())) : d4;
    }

    private void e5() {
        O6("btchecktimeout");
        if (this.i0 != 0) {
            o7.G("M", "previous scan not finished (state " + this.i0 + "), stopping now");
            J9(false);
        }
        if (this.s[20]) {
            r8(20, "handleTimerBT");
        }
    }

    public void e6(final Configuration configuration) {
        if (A5(122)) {
            G7(26, configuration.orientation, true);
        }
        this.p1.F(new Runnable() {
            @Override
            public final void run() {
                MonitorService.this.d6(configuration);
            }
        });
    }

    private void e7(boolean z2) {
        t9(5, z2, 3, new b());
    }

    private void e8() {
        BroadcastReceiver broadcastReceiver = this.e0;
        if (broadcastReceiver != null) {
            aa(broadcastReceiver, "bt scan");
            this.e0 = null;
        }
    }

    private void e9(io ioVar, boolean z2, String str) {
        synchronized (this.u) {
            try {
                o7.f("M", "sig prof change: " + str + " pid: " + ioVar.C0() + " enabled: " + ioVar.h1() + " active: " + ioVar.e1());
                for (Object obj : this.u.toArray()) {
                    ((z) obj).b(ioVar.C0(), ioVar.h1(), ioVar.e1(), z2);
                }
            } catch (Throwable th2) {
                throw th2;
            }
        }
    }

    private boolean ea(boolean z2) {
        return o2 ? m2 : z2;
    }

    public static boolean f2(String str) {
        synchronized (b2) {
            try {
                for (h1 h1Var : b2.values()) {
                    if (!h1Var.n() || (!h1Var.a().equals(str) && !h1Var.i().equals(str))) {
                    }
                    return true;
                }
                return false;
            } finally {
            }
        }
    }

    private List<fn> f3(fo foVar, List<io> list) {
        return h3(foVar, list, null, false, null, false);
    }

    private void f5() {
        long currentTimeMillis = System.currentTimeMillis();
        if (currentTimeMillis - X1 > 15000) {
            g9();
            return;
        }
        long j3 = Y1;
        if (j3 == 0) {
            if (i1.h(this).getState() == 12) {
                Y1 = currentTimeMillis;
            }
            x9(12);
        } else if (currentTimeMillis - j3 >= 3000) {
            g9();
        } else {
            x9(12);
        }
    }

    public static final int f7(int i3) {
        return (i3 / 1001) * 1001;
    }

    private void f8() {
        if (this.Q == null) {
            return;
        }
        o7.f("M", "unregister cell workaround listener");
        LocationManager S3 = S3();
        if (S3 == null) {
            o7.k("M", "rcnw: null lm");
        } else {
            S3.removeProximityAlert(this.Q);
        }
        this.Q = null;
    }

    private boolean f9() {
        if (!com.joaomgcd.taskerm.util.ac.Z(this).i0()) {
            return false;
        }
        boolean U6 = U6(1);
        BluetoothAdapter h3 = i1.h(this);
        if (h3 == null) {
            o7.k("M", oh.g(this, 2131887716, new Object[0]));
        } else if (this.i0 != 0) {
            o7.f("M", "start BT scan: already scanning");
        } else {
            Y2(4);
            int state = h3.getState();
            if (U6 && state != 10 && state != 11) {
                o7.f("M", "skip BT enable, not currently OFF or TURNING ON");
                U6 = false;
            }
            if (U6) {
                boolean z2 = state == 11;
                if (z2 || h3.enable()) {
                    this.i0 = 1;
                    if (!z2) {
                        S8(true);
                    }
                    X1 = System.currentTimeMillis();
                    Y1 = 0L;
                    x9(12);
                } else {
                    o7.G("M", "failed to start BT enable process");
                }
            }
            if (this.i0 != 1) {
                g9();
            }
        }
        return this.i0 != 0;
    }

    private boolean g2(io ioVar) {
        if (ioVar != null) {
            return ioVar.e1() && ioVar.h1() && !i7(ioVar) && !j7(ioVar, this.Y0);
        }
        o7.G("M", "cmal: null profile");
        return false;
    }

    private List<fn> g3(fo foVar, List<io> list, Set<Integer> set, boolean z2, List<Integer> list2) {
        return h3(foVar, list, set, z2, list2, true);
    }

    public static List<String> g4() {
        ArrayList arrayList = new ArrayList();
        synchronized (O1) {
            try {
                Object[] array = O1.keySet().toArray();
                Arrays.sort(array, new Comparator() {
                    @Override
                    public final int compare(Object obj, Object obj2) {
                        int M5;
                        M5 = MonitorService.M5(obj, obj2);
                        return M5;
                    }
                });
                for (Object obj : array) {
                    arrayList.add(ug.m(((Long) obj).longValue()) + " " + O1.get((Long) obj));
                }
            } catch (Throwable th2) {
                throw th2;
            }
        }
        return arrayList;
    }

    public void g5() {
        v4();
    }

    public void g6(boolean z2, boolean z3) {
        com.joaomgcd.taskerm.util.bi.b0(1000L);
        K2(null, true, z2, z3);
    }

    private ti.b g7(final int i3) {
        return ti.b.t(new yi.a() {
            @Override
            public final void run() {
                MonitorService.this.o6(i3);
            }
        });
    }

    private void g9() {
        BluetoothAdapter h3 = i1.h(this);
        if (h3.getState() != 12) {
            o7.f("M", "start BT scan II: BT not enabled");
        } else if (U6(4)) {
            o7.f("M", "start standard BT scan");
            if (h3.startDiscovery()) {
                this.i0 = 2;
            } else {
                o7.G("M", "btScan: adapter reports failed to start scan");
            }
        } else if (j9()) {
            this.i0 = 2;
        }
        if (this.i0 != 2) {
            J9(true);
            return;
        }
        this.g0 = System.currentTimeMillis();
        this.h0 = -1L;
        x9(13);
        o7.f("M", "started scan at " + this.g0);
    }

    private boolean h2(WifiManager wifiManager) {
        return ud.d1.b() && ud.d1.e(wifiManager);
    }

    private List<fn> h3(fo foVar, List<io> list, Set<Integer> set, boolean z2, List<Integer> list2, boolean z3) {
        ArrayList arrayList;
        synchronized (this.s1) {
            try {
                arrayList = new ArrayList();
                for (int size = list.size() - 1; size >= 0; size--) {
                    io ioVar = list.get(size);
                    if (ioVar == null) {
                        o7.k("M", "dip: null profile on active list");
                    } else if (!ioVar.e1() || !ioVar.h1()) {
                        if (ioVar.q1()) {
                            int Q0 = ioVar.Q0(0);
                            if (z3 && Q0 != -1) {
                                Y4(foVar.T(Q0), set);
                            }
                        }
                        list.remove(size);
                        if (z3 && list2 != null) {
                            list2.add(Integer.valueOf(ioVar.C0()));
                        }
                        o7.f("M", "profile -> inactive: " + ioVar.H0());
                        RunLog.K0(this, this.A0, io.a.Inactive, ioVar);
                        e9(ioVar, false, "delist");
                        if (ioVar.c1(1)) {
                            int Q02 = ioVar.Q0(1);
                            fn T = foVar.T(Q02);
                            if (T == null) {
                                o7.G("M", "dip: unknown exit task ID: " + Q02);
                            } else {
                                fn q0 = T.q0();
                                q0.D2(ioVar.L0() + 1001);
                                if (ioVar.r0()) {
                                    q0.z2(ioVar.C0());
                                }
                                q0.B2(ioVar.k1("exit"));
                                q0.F(ioVar.F0());
                                arrayList.add(q0);
                            }
                            if (ioVar.e0() && !z2) {
                                this.B0.v4(true);
                                F7();
                                l8(true);
                                w3(ioVar);
                            }
                        }
                    }
                }
            } catch (Throwable th2) {
                throw th2;
            }
        }
        return arrayList;
    }

    private boolean h4(Bundle bundle) {
        if (!bundle.containsKey("android.intent.extra.REPLACING")) {
            return false;
        }
        Object obj = bundle.get("android.intent.extra.REPLACING");
        return (obj.getClass() == Boolean.TYPE || obj.getClass() == Boolean.class) ? bundle.getBoolean("android.intent.extra.REPLACING") : bundle.getInt("android.intent.extra.REPLACING", 0) != 0;
    }

    private void h5() {
        if (W6()) {
            o7.f("M", "cell timeout, check cell infos");
            if (s2(this, false)) {
                o7.f("M", "cell id changed, check match states");
                E2(7, true);
            } else {
                o7.f("M", "no cell id change");
            }
        }
        P9();
    }

    public void h6(List list, String str, List list2, Long l3) throws Exception {
        if (list != null) {
            Iterator it = list.iterator();
            while (it.hasNext()) {
                String str2 = (String) it.next();
                o7.f("M", "pkg " + str + " updated, query state plugin names " + str2);
                o7(str2, null);
            }
        }
        if (list2 != null) {
            Iterator it2 = list2.iterator();
            while (it2.hasNext()) {
                String str3 = (String) it2.next();
                o7.f("M", "pkg " + str + " updated, query event plugin names " + str3);
                o7(str3, null);
            }
        }
    }

    private void h8(int i3) {
        c2[i3] = null;
    }

    @SuppressLint({"MissingPermission"})
    private void h9(String str) {
        if (com.joaomgcd.taskerm.util.ac.M0(this).h0()) {
            synchronized (Q1) {
                try {
                    if (new com.joaomgcd.taskerm.util.ac(this, 12, com.joaomgcd.taskerm.util.ac.B0()).h0()) {
                        long currentTimeMillis = System.currentTimeMillis() - this.G;
                        if (str.equals("gps") && 1000 + currentTimeMillis < x1[1]) {
                            o7.f("M", "startLocUpdate: gps: not starting, last update ago = " + currentTimeMillis);
                        } else if (Q1.containsKey(str)) {
                            o7.G("M", "startLocUpdates: already registered for provider " + str);
                        } else {
                            LocationListener T3 = T3(str);
                            Q1.put(str, T3);
                            LocationManager locationManager = this.x0;
                            if (locationManager == null) {
                                o7.k("M", "startLocUpdates: couldn't start location updates with null location manager");
                            } else {
                                try {
                                    locationManager.requestLocationUpdates(str, 0L, 0.0f, T3, this.p1.V().f());
                                } catch (Throwable th2) {
                                    o7.l("M", "startLocUpdates: rlu failed with iae: xposed problem ?", th2);
                                }
                            }
                            if (str.equals("gps")) {
                                this.F = null;
                                this.H = 0;
                                this.G = System.currentTimeMillis();
                                if (n2) {
                                    x9(6);
                                }
                            }
                        }
                    }
                } catch (Throwable th3) {
                    throw th3;
                }
            }
        }
    }

    private void i2(int i3) {
        synchronized (this.J0) {
            try {
                if (this.I0[i3] != null) {
                    o7.f("M", "AC cancel cal alarm: " + ug.k(i3));
                    this.v0.cancel(this.I0[i3]);
                    this.I0[i3] = null;
                    this.K0[i3] = 0;
                }
            } catch (Throwable th2) {
                throw th2;
            }
        }
    }

    private void i3() {
        int i3 = 0;
        while (true) {
            ug[] ugVarArr = this.n0;
            if (i3 >= ugVarArr.length) {
                return;
            }
            ugVarArr[i3] = null;
            i3++;
        }
    }

    private fn i4(boolean z2) {
        ArrayList<Integer> arrayList = new ArrayList();
        synchronized (this.e1) {
            try {
                for (Integer num : this.d1.keySet()) {
                    num.intValue();
                    if (this.f1.get(num).intValue() == 0 || z2) {
                        arrayList.add(num);
                    }
                }
            } finally {
            }
        }
        if (arrayList.size() <= 0) {
            return null;
        }
        fn Z12 = fo.Z1();
        Z12.D2(Z12.m1() + 2002);
        for (Integer num2 : arrayList) {
            num2.intValue();
            synchronized (this.e1) {
                Z12.Z(this.d1.remove(num2));
                this.f1.remove(num2);
            }
        }
        for (int i3 = 0; i3 < Z12.c1(); i3++) {
            net.dinglisch.android.taskerm.c A0 = Z12.A0(i3);
            if (A0 != null && A0.j() == 808) {
                if (A0.i(0).v() == 0) {
                    Z12.U1(i3, 0);
                } else {
                    Z12.U1(i3, Z12.c1() - 1);
                }
            }
        }
        return Z12;
    }

    private void i5() {
        L9("gps");
        r8(1, "handleTimerGPS");
    }

    public void i6() {
        l8(true);
        this.B0.v4(false);
        G4(null, null, "EventCodesX.NEW_WIDGET");
    }

    private boolean i7(io ioVar) {
        int C0 = ioVar.C0();
        return g2.containsKey(Integer.valueOf(C0)) && ioVar.g1(g2.get(Integer.valueOf(C0)).longValue());
    }

    private void i8() {
        fo foVar = this.B0;
        if (foVar == null) {
            return;
        }
        HashSet hashSet = new HashSet();
        for (Map.Entry<Integer, Long> entry : g2.entrySet()) {
            Integer key = entry.getKey();
            int intValue = key.intValue();
            if (!foVar.V(intValue)) {
                hashSet.add(key);
            } else if (entry.getValue().longValue() > System.currentTimeMillis()) {
                if (foVar.c(intValue).e1()) {
                    o7.f("M", "too old last active, still active, set act time to now");
                    g2.put(key, Long.valueOf(System.currentTimeMillis()));
                } else {
                    o7.f("M", "too old last act, not active, remove last active entry");
                    hashSet.add(key);
                }
            }
        }
        Iterator it = hashSet.iterator();
        while (it.hasNext()) {
            g2.remove((Integer) it.next());
        }
    }

    private void i9(int i3) {
        if (T6(i3)) {
            o7.f("M", y1[i3] + ": monitor start: already started");
            return;
        }
        if (this.s[i3]) {
            R8(i3, true);
            if (i3 == 5) {
                W2();
            }
            r8(i3, "startMon");
            return;
        }
        o7.G("M", y1[i3] + ": monitor start: ignore, not needed");
    }

    private void j2() {
        PendingIntent pendingIntent = this.G0;
        if (pendingIntent != null) {
            o7.f("M", "cancel cooldown alarm");
            this.v0.cancel(pendingIntent);
            this.G0 = null;
        }
    }

    private void j3() {
        synchronized (Z1) {
            try {
                if (Z1.booleanValue()) {
                    BluetoothAdapter h3 = i1.h(this);
                    if (h3 != null) {
                        int state = h3.getState();
                        if (state != 13 && state != 10) {
                            if (h3.disable()) {
                                o7.f("M", "re-disabled BT");
                            } else {
                                o7.G("M", "failed to re-disable BT");
                            }
                        }
                        o7.f("M", "redisable BT: BT disabl(ing|ed) already, pull out!");
                    }
                    Z1 = Boolean.FALSE;
                }
            } catch (Throwable th2) {
                throw th2;
            }
        }
    }

    private String j4(long j3) {
        long j4 = this.w;
        return j4 < 0 ? String.valueOf(j4) : ug.m(j4);
    }

    private void j5() {
        L9("network");
        r8(2, "handleTimerNet");
    }

    public void j6(Intent intent) {
        T4(intent.getStringExtra("pfname"), intent.getIntExtra("pfttp", 2));
    }

    private boolean j7(io ioVar, List<io> list) {
        int C0 = ioVar.C0();
        Iterator<io> it = list.iterator();
        while (it.hasNext()) {
            if (it.next().C0() == C0) {
                return true;
            }
        }
        return false;
    }

    private void j8() {
        HashSet hashSet = new HashSet();
        Iterator<Map.Entry<Integer, Location>> it = P1.entrySet().iterator();
        while (it.hasNext()) {
            Integer key = it.next().getKey();
            io c3 = this.B0.c(key.intValue());
            if (!this.S0.containsKey(key) || (c3 != null && !c3.h1())) {
                hashSet.add(key);
            }
        }
        Iterator it2 = hashSet.iterator();
        while (it2.hasNext()) {
            P1.remove(it2.next());
        }
    }

    public boolean j9() {
        boolean z2;
        o7.f("M", "try pings on paired devices");
        if (c7() > 0) {
            z2 = true;
        } else {
            o7.G("M", "btScan: no matching paired devices ");
            z2 = false;
        }
        if (U6(5)) {
            if (i1.s(this, this.f0)) {
                o7.f("M", "started LE scan");
                return true;
            }
            o7.f("M", "failed to start BT LE scan");
        }
        return z2;
    }

    private void k2() {
        NotificationManager notificationManager = (NotificationManager) gi.d(this, "notification", "M", "umn");
        if (notificationManager != null) {
            try {
                notificationManager.cancel(Integer.MAX_VALUE);
            } catch (Exception e3) {
                o7.f("M", "cancelNotification: " + e3.getMessage());
            }
        }
    }

    private void k3() {
        if (A5(80)) {
            Iterator<Integer> it = this.W0.get(80).iterator();
            boolean z2 = false;
            boolean z3 = false;
            while (it.hasNext()) {
                io c3 = this.B0.c(it.next().intValue());
                for (int i3 = 4; i3 <= 6; i3++) {
                    if (c3.Z0(i3)) {
                        bn bnVar = (bn) c3.T0(i3);
                        if (bnVar.j() == 80) {
                            int v2 = bnVar.y(0).v();
                            if (v2 == 0) {
                                z2 = true;
                                z3 = true;
                            } else if (v2 == 1) {
                                z3 = true;
                            } else if (v2 != 2) {
                                o7.k("M", "disableEnablessDockingDummies: bad val");
                            } else {
                                z2 = true;
                            }
                        }
                    }
                }
            }
            mh.R(this, DockActivityDesk.class.getName(), z2);
            mh.R(this, DockActivityCar.class.getName(), z3);
        }
    }

    private boolean k4() {
        if (this.t0 == null) {
            o7.f("M", "setup sensor manager");
            this.t0 = bp.c(this, "M");
        }
        if (this.t0 == null) {
            pp.n0(this, 2131887727, new Object[0]);
        }
        return this.t0 != null;
    }

    private void k5() {
        this.J = 0L;
        t3(new Runnable() {
            @Override
            public final void run() {
                MonitorService.this.R5();
            }
        }, "handleTimerProcessQueue");
    }

    private void k7(boolean z2) {
        u9(3, z2, 3, new s(), true);
    }

    private void k8() {
        BroadcastReceiver broadcastReceiver = this.W;
        if (broadcastReceiver != null) {
            aa(broadcastReceiver, "wifi scan");
            this.W = null;
        }
    }

    private boolean k9() {
        o7.f("M", "start SM listener");
        if (!k4()) {
            return false;
        }
        bp.f(this.t0, bp.b(this), new o());
        return true;
    }

    private void l2() {
        synchronized (this.M0) {
            try {
                if (bp.d(this) && k4()) {
                    o7.f("M", "cancel SM listener");
                    bp.a(this.t0, bp.b(this));
                }
            } catch (Throwable th2) {
                throw th2;
            }
        }
    }

    private void l3(boolean z2) {
        if (Kid.b(this)) {
            ReceiverStaticInternal.b(true);
        } else if (pp.O1()) {
            ReceiverStaticInternal.b(z2);
        } else {
            mh.R(this, ReceiverStaticInternal.class.getName(), z2);
        }
    }

    public static int l4() {
        return N1;
    }

    private void l5() {
        O9();
        x9(8);
    }

    private void l7() {
        Iterator<Integer> it = this.V0.keySet().iterator();
        while (it.hasNext()) {
            int intValue = it.next().intValue();
            if (i2.X(intValue)) {
                o7.f("M", "queryAllEventPlugins: " + intValue + " / " + ji.D(ji.c.Event, intValue));
                p7(intValue, null);
            }
        }
    }

    private void l8(boolean z2) {
        boolean z3 = false;
        try {
            wp.y();
            this.B0.K4(this, TaskerAppWidgetConfigure.t(this, true), true, false);
        } catch (Exception e3) {
            o7.k("M", "init: exception from scanForVars: " + e3.toString());
        }
        o7.f("M", "rescan done");
        StringBuilder sb = new StringBuilder();
        Iterator<Integer> it = wp.m0().iterator();
        while (it.hasNext()) {
            int intValue = it.next().intValue();
            if (wp.T0(intValue)) {
                z3 = true;
            }
            if (sb.length() > 0) {
                sb.append(" ");
            }
            sb.append(wp.I0(intValue));
        }
        o7.f("M", "needed monitor vars: " + sb.toString());
        if (z2) {
            o7.f("M", "handle variable dependent receivers");
            if (z3) {
                A3(6, true);
            }
            V1();
        }
    }

    private void l9(final boolean z2) {
        t3(new Runnable() {
            @Override
            public final void run() {
                MonitorService.this.G6(z2);
            }
        }, "startStopCal");
    }

    private void m2() {
        synchronized (this.F0) {
            try {
                if (this.D0 != null) {
                    o7.f("M", "AC cancel time alarm");
                    this.v0.cancel(this.D0);
                    this.D0 = null;
                    this.E0 = 0L;
                }
            } catch (Throwable th2) {
                throw th2;
            }
        }
    }

    private void m3() {
        Iterator<Integer> it = i2.Q().iterator();
        while (it.hasNext()) {
            A3(it.next().intValue(), false);
        }
    }

    private String[] m4(int i3) {
        return c2[i3];
    }

    private void m5() {
        er.k(this, "Tasker.UserAbsentWakelock");
    }

    public void m6(Intent intent) {
        o8(intent.getBooleanExtra("sreamo", false));
    }

    private void m7() {
        Iterator<Integer> it = this.W0.keySet().iterator();
        while (it.hasNext()) {
            int intValue = it.next().intValue();
            if (an.O(intValue)) {
                o7.f("M", "queryAllStatePlugins: " + intValue + " / " + ji.D(ji.c.Condition, intValue));
                q7(intValue);
            }
        }
    }

    public static void m8(Context context, boolean z2) {
        n8(context, z2, false);
    }

    private void m9(boolean z2) {
        if (pp.z(this, "android.permission.READ_CALL_LOG", "MssCallLogging")) {
            if (!z2) {
                w1 w1Var = this.M;
                if (w1Var != null) {
                    Z9(w1Var);
                    this.M = null;
                    return;
                }
                return;
            }
            if (this.M != null) {
                o7.G("M", "CallLogObserver already started");
                return;
            }
            w1 w1Var2 = new w1(getApplicationContext(), "CallLogObserver", 100L, new y(this));
            this.M = w1Var2;
            this.w0.registerContentObserver(CallLog.CONTENT_URI, true, w1Var2);
        }
    }

    private void n2() {
        synchronized (this.M0) {
            try {
                if (this.L0 != null) {
                    o7.f("M", "AC cancel user-absent updates");
                    this.v0.cancel(this.L0);
                    this.L0 = null;
                }
            } catch (Throwable th2) {
                throw th2;
            }
        }
    }

    private void n3() {
        synchronized (T1) {
            try {
                if (T1.booleanValue()) {
                    WifiManager wifiManager = this.y0;
                    if (wifiManager != null) {
                        int wifiState = wifiManager.getWifiState();
                        if (wifiState == 4) {
                            o7.f("M", "redisable wifi: wifi in unknown state, continuing anyway");
                        } else if (!this.y0.pingSupplicant()) {
                            o7.f("M", "wifi near: re-disable wifi, supplicant not responding, continuing anyway");
                        }
                        if (wifiState != 0 && wifiState != 1) {
                            if (this.y0.setWifiEnabled(false)) {
                                U1 = System.currentTimeMillis();
                                o7.f("M", "re-disabled wifi");
                            } else {
                                o7.G("M", "failed to re-disable wifi");
                            }
                        }
                        o7.f("M", "redisable wifi: wifi disabl(ing|ed) already, pull out!");
                    }
                    T8(false, "M/disableWifiIfNec");
                }
            } catch (Throwable th2) {
                throw th2;
            }
        }
    }

    public String n4(int i3, int i4) {
        return c2[i3][i4];
    }

    private void n5() {
        L9("gps");
    }

    public void n6(int i3, final Intent intent, int i4) {
        switch (i3) {
            case 9982:
                o7(intent.getStringExtra("com.twofortyfouram.locale.intent.extra.ACTIVITY"), ho.b.c(intent));
                break;
            case 9983:
                x3(new Runnable() {
                    @Override
                    public final void run() {
                        MonitorService.this.i6();
                    }
                }, "EventCodesX.NEW_WIDGET");
                break;
            case 9984:
                x3(new Runnable() {
                    @Override
                    public final void run() {
                        MonitorService.this.z4();
                    }
                }, "handleCooldownAlarm");
                break;
            case 9985:
            case 9993:
            case 9994:
            default:
                o7.k("M", "unknown event type: " + i3 + ", action" + intent.getAction());
                break;
            case 9986:
                x3(new Runnable() {
                    @Override
                    public final void run() {
                        MonitorService.this.j6(intent);
                    }
                }, "handleProfileToggle");
                break;
            case 9987:
                Z7();
                break;
            case 9988:
                int intExtra = intent.getIntExtra("csrc", -1);
                if (intExtra != -1) {
                    o7.f("M", "cal alarm ding: " + ug.k(intExtra));
                    x4(intExtra);
                    break;
                } else {
                    o7.k("M", "received calendar alarm intent without source spec");
                    break;
                }
            case 9989:
                if (!z5((Intent) intent.getExtras().getParcelable("TaskerIntentIntentExtra"))) {
                    C4(intent.getBundleExtra("eventExt"));
                    break;
                }
                break;
            case 9990:
                String I = ug.I();
                if (I.length() == 0 || !H1.equals(I)) {
                    y4();
                }
                H1 = I;
                break;
            case 9991:
                i8();
                y4();
                break;
            case 9992:
                i8();
                y4();
                break;
            case 9995:
                if (i4 > 1) {
                    x3(new Runnable() {
                        @Override
                        public final void run() {
                            MonitorService.this.m6(intent);
                        }
                    }, "EventCodesX.START_MONITOR");
                    break;
                }
                break;
            case 9996:
                x3(new Runnable() {
                    @Override
                    public final void run() {
                        MonitorService.this.l6(intent);
                    }
                }, "handleSystemEvent");
                break;
            case 9997:
                x3(new Runnable() {
                    @Override
                    public final void run() {
                        MonitorService.this.k6(intent);
                    }
                }, "handleAppLaunch");
                break;
            case 9998:
                b5("alarm");
                break;
            case 9999:
                boolean booleanExtra = intent.getBooleanExtra("repeating", true);
                o7.f("M", "alarm ding: user-absent update (period " + o4() + "ms) repeating: " + booleanExtra);
                r5(booleanExtra);
                break;
        }
    }

    private void n7(final int i3, final j2 j2Var, final String str, Bundle bundle, Bundle bundle2) {
        Intent intent;
        ji.c cVar = ji.c.Event;
        boolean z2 = true;
        Intent R = ji.R(this, cVar, j2Var.j(), null, true);
        if (R == null) {
            intent = ji.R(this, cVar, j2Var.j(), null, false);
            z2 = false;
        } else {
            intent = R;
        }
        if (intent != null) {
            if (bundle2 != null) {
                ho.b.a(intent, bundle2);
            }
            if (bundle != null) {
                intent.putExtras(bundle);
            }
            Q6(intent, bundle, str);
            try {
                if (!z2) {
                    sendOrderedBroadcast(intent, null, new j(i3, j2Var, str), this.p1.o2().e(), 0, null, null);
                    o7.f("M", "send event broadcast pid " + i3 + " for " + str);
                    return;
                }
                com.joaomgcd.taskerm.util.zd zdVar = intent.getBooleanExtra("net.dinglisch.android.tasker.EXTRA_CAN_BIND_FIRE_SETTING", false) ? new com.joaomgcd.taskerm.util.zd(new com.joaomgcd.taskerm.util.f() {
                    @Override
                    public final void a(Object obj) {
                        ((Intent) obj).removeExtra("net.dinglisch.android.tasker.EXTRA_CAN_BIND_FIRE_SETTING");
                    }
                }) : null;
                final com.joaomgcd.taskerm.util.zd zdVar2 = zdVar;
                intent.putExtra("net.dinglisch.android.tasker.EXTRA_RESULT_RECEIVER", new PluginResultReceiver(this.p1.o2().e(), new ik.p() {
                    @Override
                    public final Object n(Object obj, Object obj2) {
                        vj.e0 q6;
                        q6 = MonitorService.this.q6(i3, j2Var, str, zdVar2, (Integer) obj, (Bundle) obj2);
                        return q6;
                    }
                }));
                com.joaomgcd.taskerm.util.c0.D(this, intent, intent.getIntExtra("net.dinglisch.android.tasker.EXTRA_TARGET_API", Build.VERSION.SDK_INT), false, false, zdVar);
                o7.f("M", "event service start pid " + i3 + " for " + str);
            } catch (Exception e3) {
                o7.H("M", str + ": queryPluginEvent", e3);
            }
        }
    }

    public static void n8(Context context, boolean z2, boolean z3) {
        boolean d22 = d2(context);
        boolean L2 = pp.L2(context, MonitorService.class.getName());
        o7.f("M", "restart: enabled: " + d22 + " running: " + L2 + " evenIfRunning: " + z2);
        if (!d22) {
            HelperMonitorService.J2(context).y(new yi.a() {
                @Override
                public final void run() {
                    MonitorService.z6();
                }
            }, new yi.d() {
                @Override
                public final void accept(Object obj) {
                    o7.g("M", "Couldn't create tasker stopped notification on restart", (Throwable) obj);
                }
            });
            return;
        }
        HelperMonitorService.U2(context);
        if (!L2 || z2) {
            E8(context, z3);
        }
    }

    private void n9(boolean z2) {
        o7.f("M", "ClipboardManager not null. startFlag: " + z2);
        if (!z2) {
            if (this.K != null) {
                o7.f("M", "remove clip listener");
                ue.q.H(this, this.K);
                this.K = null;
                return;
            }
            return;
        }
        if (this.K == null) {
            o7.f("M", "add clip listener");
            ClipboardManager.OnPrimaryClipChangedListener onPrimaryClipChangedListener = new ClipboardManager.OnPrimaryClipChangedListener() {
                @Override
                public final void onPrimaryClipChanged() {
                    MonitorService.this.H6();
                }
            };
            this.K = onPrimaryClipChangedListener;
            ue.q.o(this, onPrimaryClipChangedListener, this.B0, true);
        }
    }

    private void o2() {
        synchronized (this.M0) {
            n2();
            l2();
        }
    }

    private static boolean o3() {
        boolean booleanValue;
        synchronized (Z1) {
            booleanValue = Z1.booleanValue();
        }
        return booleanValue;
    }

    public long o4() {
        return this.A0.getLong("lfdd", 600L) * 1000;
    }

    private void o5() {
        O6("wifichecktimeout");
        if (this.Z != 0) {
            o7.G("M", "previous scan not finished (state " + this.Z + "), stopping now");
            R9(false);
        }
        if (this.s[3]) {
            r8(3, "handleTimerWifi");
        }
    }

    public void o6(final int i3) throws Exception {
        try {
            ConcurrentLinkedDeque<Intent> concurrentLinkedDeque = this.g1;
            boolean X9 = X9(10);
            int size = concurrentLinkedDeque.size();
            while (!X9 && size > 0) {
                long currentTimeMillis = System.currentTimeMillis() - this.J;
                if (currentTimeMillis > 200) {
                    this.I = 0L;
                } else {
                    this.I += currentTimeMillis;
                }
                if (this.I > 8000) {
                    x9(10);
                } else {
                    long currentTimeMillis2 = System.currentTimeMillis();
                    final Intent poll = concurrentLinkedDeque.poll();
                    if (poll == null) {
                        o7.h("M", "process inbox, null intent, size " + size + " startID: " + i3, true);
                        if (com.joaomgcd.taskerm.util.b7.u1(concurrentLinkedDeque)) {
                            concurrentLinkedDeque.clear();
                        }
                        X9 = X9(10);
                        size = concurrentLinkedDeque.size();
                    } else {
                        final int intExtra = poll.getIntExtra("eventType", -1);
                        if (o7.K()) {
                            o7.h("M", "process inbox, size " + size + " startID: " + i3 + " ecode " + intExtra, true);
                            if (intExtra != 9997) {
                                try {
                                    o7.z("pi", poll);
                                } catch (Throwable th2) {
                                    o7.g("M", "Couldn't log all extras", th2);
                                }
                            }
                        }
                        this.p1.F(new Runnable() {
                            @Override
                            public final void run() {
                                MonitorService.this.n6(intExtra, poll, i3);
                            }
                        });
                        long currentTimeMillis3 = System.currentTimeMillis();
                        this.J = currentTimeMillis3;
                        this.I += currentTimeMillis3 - currentTimeMillis2;
                    }
                }
                X9 = X9(10);
                size = concurrentLinkedDeque.size();
            }
        } catch (RuntimeException e3) {
            Throwable cause = e3.getCause();
            if (cause == null) {
                com.joaomgcd.taskerm.util.h5.m(e3, this, "processInboxBackground runtime");
            }
            if (cause instanceof InterruptedException) {
                o7.f("M", "Interrupted while processing inbox: " + cause);
            }
        } catch (Exception e4) {
            com.joaomgcd.taskerm.util.h5.m(e4, this, "processInboxBackground");
        }
    }

    private void o7(final String str, final Bundle bundle) {
        t3(new Runnable() {
            @Override
            public final void run() {
                MonitorService.this.r6(str, bundle);
            }
        }, "queryPluginsWithEditClass");
    }

    private void o8(boolean z2) {
        o7.f("M", "RESTART");
        o7.A("M", "restart");
        RunLog.N0(this, this.A0, RunLog.i.Restart);
        V9(z2);
        I5(true, true);
        this.p1.F(new Runnable() {
            @Override
            public final void run() {
                MonitorService.this.y6();
            }
        });
        com.joaomgcd.taskerm.util.h hVar = this.Y0;
        fo foVar = this.B0;
        this.x0 = null;
        if (J5(false)) {
            a3(foVar);
            b3(foVar);
            v3();
            I2(foVar, this.B0);
            t2(hVar, foVar);
            X8();
            C3(false);
            S4(this.B0.p2(), hVar, "restart");
        }
        Z2();
        o7.A("M", "restart end");
        o7.f("M", "RESTART DONE");
        xg.h.m(new xf.i7());
    }

    private void o9(boolean z2) {
        List<bh> list = this.X0;
        if (list == null) {
            return;
        }
        for (bh bhVar : new ArrayList(list)) {
            if (z2) {
                bhVar.c();
            } else {
                bhVar.d();
            }
        }
    }

    private boolean p2() {
        int e22;
        Bundle I3 = I3();
        return I3 != null && ((e22 = e2(I3)) == 1 || e22 == 2 || e22 == 4);
    }

    private static boolean p3() {
        boolean booleanValue;
        synchronized (T1) {
            booleanValue = T1.booleanValue();
        }
        return booleanValue;
    }

    private IntentFilter p4(io ioVar, j2 j2Var) {
        String N = wp.N(this, j2Var.N(0).w(), com.joaomgcd.taskerm.util.b7.l0(this.B0, this, ioVar, null, "registerUserReceiver"));
        int v2 = j2Var.y(1).v();
        int v3 = j2Var.y(2).v();
        String M = wp.M(this, j2Var.N(3).w());
        String M2 = wp.M(this, j2Var.N(4).w());
        IntentFilter intentFilter = new IntentFilter();
        if (!TextUtils.isEmpty(N)) {
            intentFilter.addAction(N);
        }
        String q1 = z0.q1(v2);
        if (!TextUtils.isEmpty(q1)) {
            intentFilter.addCategory(q1);
        }
        String q12 = z0.q1(v3);
        if (!TextUtils.isEmpty(q12)) {
            intentFilter.addCategory(q12);
        }
        if (!TextUtils.isEmpty(M)) {
            intentFilter.addDataScheme(M);
        }
        if (!TextUtils.isEmpty(M2)) {
            intentFilter.addDataScheme(M2);
        }
        intentFilter.setPriority(j2Var.p1());
        o7.f("M", "userIntentFilter: " + N + " c1: " + q1 + " c2: " + q12 + " s: " + M + " t: " + M2);
        return intentFilter;
    }

    private void p5() {
        long currentTimeMillis = System.currentTimeMillis();
        if (currentTimeMillis - R1 > 15000) {
            D9();
            return;
        }
        long j3 = S1;
        if (j3 == 0) {
            if (this.y0.getWifiState() == 3) {
                S1 = currentTimeMillis;
            }
            x9(5);
        } else if (currentTimeMillis - j3 >= 3000) {
            D9();
        } else {
            x9(5);
        }
    }

    private void p7(int i3, Bundle bundle) {
        if (i3 == -1) {
            o7.G("M", "queryPluginsWithEventCode: ignoring null code");
            return;
        }
        if (!i2.X(i3)) {
            o7.G("M", "queryPluginsWithEventCode: ignoring none-plugin code: " + i3);
            return;
        }
        if (!y5(i3)) {
            o7.f("M", "qpwec: no events with code " + i3 + ", hope plugin shuts down soon...");
            return;
        }
        o7.f("M", "queryPluginsWithEventCode: " + i3 + " / " + ji.D(ji.c.Event, i3));
        List<Integer> list = this.V0.get(Integer.valueOf(i3));
        if (list == null) {
            o7.G("M", "queryPluginsWithEventCode: ignoring no profile ids in code: " + i3);
            return;
        }
        Iterator<Integer> it = list.iterator();
        while (it.hasNext()) {
            int intValue = it.next().intValue();
            io c3 = this.B0.c(intValue);
            if (c3 == null) {
                o7.k("M", "qpwec: null profile, ID " + intValue);
            } else {
                j2 j2Var = (j2) c3.T0(7);
                if (j2Var == null) {
                    o7.k("M", "qpwec: null event context");
                } else if (j2Var.j() == i3) {
                    if (!c3.h1()) {
                        o7.f("M", "qpwec: " + c3.H0() + ": profile not enabled");
                    } else if (i7(c3)) {
                        o7.f("M", "qpwec: " + c3.H0() + ": cooling down");
                    } else if (c3.t0() < c3.I0() - 1) {
                        o7.f("M", "qpwec: " + c3.H0() + ": other contexts not all active");
                    } else {
                        o7.f("M", "qpwec: pid " + intValue);
                        String z2 = i2.z(j2Var.j());
                        n7(intValue, j2Var, z2, q4(c3, j2Var.a(0), z2), bundle);
                    }
                }
            }
        }
    }

    public boolean p8(int i3) {
        N9(i3);
        return x9(i3);
    }

    private void p9(boolean z2) {
        if (!z2) {
            w1 w1Var = this.L;
            if (w1Var != null) {
                Z9(w1Var);
                this.L = null;
                return;
            }
            return;
        }
        if (this.L != null) {
            o7.G("M", "smsObserver already started");
            return;
        }
        this.L = new w1(getApplicationContext(), "SmsObserver", 10L, new b0(this));
        ContentResolver contentResolver = this.w0;
        if (contentResolver == null) {
            o7.k("M", "register SMS observer failed! No content resolver.");
            return;
        }
        o7.f("M", "register SMS observer: uri: content://sms");
        try {
            contentResolver.registerContentObserver(Uri.parse("content://mms-sms"), false, this.L);
        } catch (Throwable th2) {
            o7.l("M", "register SMS observer failed with exception!", th2);
        }
    }

    private void q2(String str, Bundle bundle, List<j2> list) {
        String[] strArr = b6.b;
        int length = strArr.length;
        int i3 = 0;
        while (true) {
            if (i3 >= length) {
                break;
            }
            if (str.equals(strArr[i3])) {
                list.add(s4(bundle));
                break;
            }
            i3++;
        }
        for (String str2 : b6.c) {
            if (str.equals(str2)) {
                list.add(new j2(306));
                return;
            }
        }
    }

    private void q3(Runnable runnable, com.joaomgcd.taskerm.util.x7<?> x7Var, String str) {
        this.p1.z0(u3().u(x7Var.f()), runnable);
    }

    private Bundle q4(io ioVar, net.dinglisch.android.taskerm.f fVar, String str) {
        if (!fVar.k()) {
            return null;
        }
        fVar.y();
        return fVar.w(this, str, com.joaomgcd.taskerm.util.b7.l0(this.B0, this, ioVar, null, "getVariableExtrasFromBundle"));
    }

    public void q5() {
        R9(false);
        E2(170, true);
        n3();
        b2();
    }

    public vj.e0 q6(int i3, j2 j2Var, String str, com.joaomgcd.taskerm.util.zd zdVar, Integer num, Bundle bundle) {
        U4(num == null ? 18 : num.intValue(), i3, j2Var, str, bundle, false);
        if (zdVar != null) {
            zdVar.a();
        }
        return vj.e0.a;
    }

    private void q7(int i3) {
        o7.f("M", "queryPluginsWithStateCode " + i3);
        if (i3 == -1) {
            o7.G("M", "queryPluginsWithStateCode: ignoring null code");
            return;
        }
        if (!an.O(i3)) {
            o7.G("M", "queryPluginsWithStateCode: ignoring none-plugin code: " + i3);
            return;
        }
        if (this.W0.containsKey(Integer.valueOf(i3))) {
            o7.f("M", "queryPluginsWithStateCode: " + i3 + " / " + ji.D(ji.c.Condition, i3));
            List<Integer> list = this.W0.get(Integer.valueOf(i3));
            if (list == null) {
                return;
            }
            Iterator<Integer> it = list.iterator();
            while (it.hasNext()) {
                int intValue = it.next().intValue();
                io c3 = this.B0.c(intValue);
                if (c3 == null) {
                    o7.G("M", "qpwcs: state code " + i3 + " profile: " + intValue + " doesn't exist");
                } else if (c3.h1()) {
                    for (int i4 = 4; i4 <= 6; i4++) {
                        if (c3.Z0(i4)) {
                            bn bnVar = (bn) c3.T0(i4);
                            if (bnVar.j() == i3) {
                                o7.f("M", "queryPluginsWith: pid " + intValue);
                                t7(c3, intValue, bnVar);
                            }
                        }
                    }
                }
            }
        }
    }

    private void q8() {
        Location H12;
        SharedPreferences sharedPreferences = getSharedPreferences(d6.r, 0);
        SharedPreferences.Editor edit = sharedPreferences.edit();
        for (Map.Entry<String, ?> entry : sharedPreferences.getAll().entrySet()) {
            String key = entry.getKey();
            Integer num = new Integer(key);
            if (!this.S0.containsKey(num)) {
                edit.remove(key);
            } else if (!P1.containsKey(num) && (H12 = n7.H1((String) entry.getValue())) != null) {
                P1.put(num, H12);
            }
        }
        edit.commit();
    }

    private void q9(int i3) {
        if (!this.s[i3]) {
            if (T6(i3)) {
                M9(i3, "asNeeded");
            }
        } else {
            if (T6(i3)) {
                return;
            }
            if (n2) {
                i9(i3);
                return;
            }
            int J12 = pp.J1(i3, C1);
            if (J12 != -1) {
                if (da(D1[J12], E1[J12], p2()) > 0) {
                    i9(i3);
                }
            } else if (pp.J1(i3, this.k0) == -1) {
                i9(i3);
            }
        }
    }

    private void r2() {
        if (this.p1.G0(com.joaomgcd.taskerm.util.ac.a0(this))) {
            i1.h(this);
            BluetoothAdapter h3 = i1.h(this);
            int[] iArr = {1, 2, 3};
            for (int i3 = 0; i3 < 3; i3++) {
                int i4 = iArr[i3];
                if (h3.getProfileConnectionState(i4) == 2) {
                    try {
                        if (this.j0 == null) {
                            this.j0 = new d();
                        }
                        h3.getProfileProxy(this, this.j0, i4);
                    } catch (Exception e3) {
                        o7.g("M", "checkBTConnectionsViaProxy", e3);
                    }
                }
            }
        }
    }

    private void r3(fo foVar, List<io> list, boolean z2, boolean z3) {
        List<fn> g3 = g3(foVar, list, null, true, null);
        if (z3) {
            V2();
        } else {
            fn i4 = i4(z2);
            if (i4 != null) {
                g3.add(i4);
            }
        }
        S6(g3, z2, z3);
    }

    private long r4() {
        return this.A0.getLong("wfpiod", 120L) * 1000;
    }

    public void r5(boolean z2) {
        synchronized (this.M0) {
            try {
                o7.f("M", "handleUserAbsentAlarm: ignore repeating flag");
                o7.f("M", "handleUserAbsentAlarm: cancel non-repeating alarm to clear alarm data");
                n2();
                U7("userAbsentUpdate");
                if (Y6(true) && wp.v(this)) {
                    if (this.s[5]) {
                        u2();
                    }
                    u7(true, new int[]{170, 5, 3, 120, 107, 7, 4});
                    P9();
                    if (V6()) {
                        B9();
                    }
                    L9("gps");
                    if (this.s[1] && n7.s1(this.x0, "gps")) {
                        h9("gps");
                    }
                    L9("network");
                    if (this.s[2]) {
                        if (!n7.s1(this.x0, "network")) {
                            o7.f("M", "skipping NET updates, provider disabled");
                        } else if (pp.x1(this, -1)) {
                            h9("network");
                        } else {
                            o7.f("M", "skipping NET updates, no network");
                        }
                    }
                    if (this.Z != 0) {
                        R9(true);
                    }
                    if (this.i0 != 0) {
                        J9(true);
                    }
                    if (this.s[3] && !C9(U6(0))) {
                        E2(170, true);
                    }
                    if (this.s[20] && !f9()) {
                        E2(4, true);
                    }
                    if (Y6(true)) {
                        if (I9() && !w9(true)) {
                            o7.k("M", "couldn't acquire wakelock, stop user-absent checks for this time");
                            O9();
                        }
                    } else if (!Y6(false)) {
                        o2();
                    }
                    A9();
                }
            } catch (Throwable th2) {
                throw th2;
            }
        }
    }

    public void r6(String str, Bundle bundle) {
        o7.f("M", "queryPluginsWithEditClass: " + str);
        o7.v("pass through", bundle);
        int g3 = ji.g(ji.c.Event, null, str);
        if (g3 != -1) {
            p7(g3, bundle);
            return;
        }
        int g4 = ji.g(ji.c.Condition, null, str);
        if (g4 != -1) {
            q7(g4);
            return;
        }
        o7.G("M", "queryPluginsWithCode: class: " + str + ": unknown class");
    }

    private void r8(final int i3, final String str) {
        this.p1.O(new Runnable() {
            @Override
            public final void run() {
                MonitorService.this.C6(i3, str);
            }
        });
    }

    private void r9() {
        for (int i3 = 0; i3 < z1; i3++) {
            q9(i3);
        }
        eh.m.g().F(this);
        gf.k.h().F(this);
    }

    public static boolean s2(MonitorService monitorService, boolean z2) {
        o7.f("M", "checkCellInfos: use last: " + z2);
        List<Object> lastCellInfos = z2 ? monitorService.O.getLastCellInfos() : null;
        if (pp.F(lastCellInfos)) {
            o7.f("M", "empty update infos, query all infos from telephony manager");
            lastCellInfos = jo.b(monitorService, jo.p(monitorService));
        }
        if (pp.F(lastCellInfos)) {
            o7.f("M", "still empty update infos");
            return false;
        }
        o7.f("M", "checkCellInfos: have : " + lastCellInfos.size() + " infos");
        return monitorService.w7(jo.j(lastCellInfos));
    }

    public static void s3(Context context, boolean z2) {
        K8(context, false);
        pp.p3(context);
        F8(context);
        if (z2) {
            pp.e0(context, 2131886826, 2131891175, 1);
        }
    }

    private j2 s4(Bundle bundle) {
        if (bundle != null) {
            byte[] byteArray = bundle.containsKey("intent.extra.alarm_raw") ? bundle.getByteArray("intent.extra.alarm_raw") : bundle.containsKey("com.samsung.sec.android.clockpackage.alarm.ALARM_DATA") ? bundle.getByteArray("com.samsung.sec.android.clockpackage.alarm.ALARM_DATA") : null;
            r0 = byteArray != null ? R3(byteArray) : null;
            if (r0 == null && bundle.containsKey("alarm_label")) {
                r0 = bundle.getString("alarm_label");
            }
            if (r0 == null && bundle.containsKey("alarm_description")) {
                r0 = bundle.getString("alarm_description");
            }
        }
        if (r0 == null) {
            o7.f("M", "handleAlarmEvent: no alarm data and no label or descr extra");
            r0 = "";
        }
        j2 j2Var = new j2(305);
        j2Var.o0(0, r0);
        return j2Var;
    }

    private void s5(Intent intent) {
        int intExtra = intent.getIntExtra("UserIntentPIDExtra", -1);
        intent.removeExtra("UserIntentPIDExtra");
        fo foVar = this.B0;
        if (foVar == null) {
            return;
        }
        io c3 = foVar.c(intExtra);
        if (c3 == null) {
            o7.G("M", "handleUserIntent: no profile for ID " + intExtra);
            return;
        }
        if (c3.h1()) {
            j2 j2Var = new j2(599);
            String action = intent.getAction();
            if (action == null) {
                action = "";
            }
            int i3 = 0;
            j2Var.o0(0, action);
            if (!pp.F(intent.getCategories())) {
                Iterator<String> it = intent.getCategories().iterator();
                int i4 = 0;
                while (it.hasNext()) {
                    int j3 = z0.j(it.next());
                    if (j3 == -1) {
                        j3 = 0;
                    }
                    if (i4 < 2) {
                        j2Var.B1(i4 + 1, j3);
                    }
                    i4++;
                }
            }
            String scheme = intent.getScheme();
            if (scheme == null) {
                scheme = "";
            }
            j2Var.o0(3, scheme);
            String type = intent.getType();
            if (type == null) {
                type = "";
            }
            j2Var.o0(4, type);
            j2 j2Var2 = (j2) c3.T0(7);
            if (j2Var2 == null || !j2Var2.a1(j2Var, this, this.w0, null)) {
                return;
            }
            Bundle bundle = new Bundle();
            String dataString = intent.getDataString();
            if (dataString != null) {
                bundle.putString("%intent_data", dataString);
            }
            Bundle extras = intent.getExtras();
            if (extras != null) {
                for (String str : extras.keySet()) {
                    Object obj = extras.get(str);
                    String str2 = "%" + wp.b1(str.toLowerCase());
                    while (bundle.containsKey(str2)) {
                        str2 = str2 + "_dup";
                    }
                    if (obj == null) {
                        bundle.putString(str2, "");
                    } else if (obj.getClass() == String[].class) {
                        String[] strArr = (String[]) obj;
                        int i5 = i3;
                        while (i5 < strArr.length) {
                            StringBuilder sb = new StringBuilder();
                            sb.append(str2);
                            int i6 = i5 + 1;
                            sb.append(String.valueOf(i6));
                            bundle.putString(sb.toString(), strArr[i5]);
                            i5 = i6;
                        }
                    } else if (obj.getClass() == int[].class) {
                        int[] iArr = (int[]) obj;
                        int i7 = 0;
                        while (i7 < iArr.length) {
                            StringBuilder sb2 = new StringBuilder();
                            sb2.append(str2);
                            int i8 = i7 + 1;
                            sb2.append(String.valueOf(i8));
                            bundle.putString(sb2.toString(), String.valueOf(iArr[i7]));
                            i7 = i8;
                        }
                    } else if (obj.getClass() == ArrayList.class) {
                        ArrayList arrayList = (ArrayList) obj;
                        int i9 = 0;
                        while (i9 < arrayList.size()) {
                            StringBuilder sb3 = new StringBuilder();
                            sb3.append(str2);
                            int i10 = i9 + 1;
                            sb3.append(String.valueOf(i10));
                            bundle.putString(sb3.toString(), String.valueOf(arrayList.get(i9)));
                            i9 = i10;
                        }
                    } else {
                        try {
                            if (obj.getClass() == Bundle.class) {
                                ((Bundle) obj).size();
                                obj = com.joaomgcd.taskerm.util.b7.n2(com.joaomgcd.taskerm.util.b7.x1((Bundle) obj));
                            }
                        } catch (BadParcelableException e3) {
                            o7.H("M", "handleUserIntent", e3);
                        } catch (Throwable th2) {
                            o7.I("M", "handleUserIntent throwable", th2);
                        }
                        o7.f("M", "add var: " + str2);
                        bundle.putString(str2, obj.toString());
                    }
                    i3 = 0;
                }
            }
            if (x2(c3, j2Var, bundle)) {
                g2.put(Integer.valueOf(intExtra), Long.valueOf(System.currentTimeMillis()));
            }
            j2Var2.w0();
        }
    }

    public void s6() {
        synchronized (this.u) {
            try {
                List<io> s2 = this.B0.s2(-2);
                for (int i3 = 0; i3 < s2.size(); i3++) {
                    boolean z2 = true;
                    if (i3 >= s2.size() - 1) {
                        z2 = false;
                    }
                    io ioVar = s2.get(i3);
                    for (int i4 = 0; i4 < ioVar.I0(); i4++) {
                        d9(ioVar.C0(), ioVar.S0(i4), "queryState");
                    }
                    e9(ioVar, z2, "queryState");
                }
            } catch (Throwable th2) {
                throw th2;
            }
        }
    }

    private void s7(int i3, bn bnVar, String str, Bundle bundle) {
        Intent Q = ji.Q(this, ji.c.Condition, bnVar.j(), null);
        if (Q != null) {
            if (bundle != null) {
                Q.putExtras(bundle);
            }
            Q6(Q, bundle, str);
            try {
                sendOrderedBroadcast(Q, null, new i(i3, str, bnVar), this.p1.o2().e(), 0, null, null);
                o7.f("M", "send broadcast");
            } catch (Exception e3) {
                o7.H("M", str + ": queryPluginState", e3);
            }
        }
    }

    private net.dinglisch.android.taskerm.c s8(net.dinglisch.android.taskerm.c cVar) {
        int e3 = bi.e(this);
        if (e3 == -1) {
            return null;
        }
        net.dinglisch.android.taskerm.c cVar2 = new net.dinglisch.android.taskerm.c(312);
        cVar2.u1(0, z0.Q0(e3));
        return cVar2;
    }

    private void s9(boolean z2) {
        if (com.joaomgcd.taskerm.util.ac.V0(this).h0()) {
            TelephonyManager telephonyManager = (TelephonyManager) gi.d(this, "phone", "M", "sspsm");
            try {
                if (telephonyManager == null) {
                    o7.G("M", oh.g(this, 2131887728, new Object[0]));
                } else if (!z2) {
                    PhoneStateListenerCommon phoneStateListenerCommon = this.O;
                    if (phoneStateListenerCommon != null) {
                        telephonyManager.listen(phoneStateListenerCommon, 0);
                        this.O.stop();
                        this.O = null;
                    }
                } else if (this.O == null) {
                    PhoneStateListenerCommon phoneStateListenerCommon2 = PhoneStateListenerCommon.getInstance(this);
                    this.O = phoneStateListenerCommon2;
                    phoneStateListenerCommon2.setHandler(new c0(this));
                    telephonyManager.listen(this.O, this.T);
                } else {
                    o7.G("M", "PhoneMonitor already started");
                }
            } catch (Exception e3) {
                this.O = null;
                o7.k("M", "Couldn't start/stop phone state monitor. Start: " + z2 + "; " + e3.toString());
            }
        }
    }

    private void t2(List<io> list, fo foVar) {
        LinkedList linkedList = new LinkedList();
        Iterator<Integer> it = this.B0.p2().iterator();
        while (it.hasNext()) {
            io c3 = this.B0.c(it.next().intValue());
            if (g2(c3)) {
                linkedList.add(c3);
            }
        }
        LinkedList linkedList2 = new LinkedList();
        for (int i3 = 0; i3 < list.size(); i3++) {
            io ioVar = list.get(i3);
            if (!j7(ioVar, linkedList)) {
                ioVar.a0();
                linkedList2.add(ioVar);
            }
        }
        r3(foVar, linkedList2, false, false);
    }

    public void k6(Intent intent) {
        if (B2(intent.getStringExtra("pkg"))) {
            S4(this.R0.keySet(), null, "handleAppLaunch");
        }
    }

    private void t5(boolean z2) {
        if (z2 != n2) {
            n2 = z2;
            synchronized (this.M0) {
                if (n2) {
                    o7.f("M", "+++ user present +++");
                    o2();
                    w9(false);
                    synchronized (Q1) {
                        try {
                            if (Q1.containsKey("gps")) {
                                this.G = 0L;
                            }
                        } finally {
                        }
                    }
                    l2();
                    O9();
                    a2();
                    Z1();
                    u7(true, new int[]{170, 5, 3, 107, 120, 4});
                    r9();
                } else {
                    o7.f("M", "+++ user not present +++");
                    ExecuteService.Q0();
                    for (int i3 : this.k0) {
                        M9(i3, "userPresChange");
                    }
                    a2();
                    Z1();
                    A9();
                }
            }
        }
    }

    public void t6(Set set, boolean z2, long j3) {
        new l(set, z2).sendEmptyMessageDelayed(0, j3);
    }

    private void t7(io ioVar, int i3, bn bnVar) {
        String F = an.F(bnVar.j());
        s7(i3, bnVar, F, q4(ioVar, bnVar.a(0), F));
    }

    public void t8(int i3, Location location) {
        getSharedPreferences(d6.r, 0).edit().putString(Integer.toString(i3), n7.y1(location)).commit();
    }

    private void t9(int i3, boolean z2, int i4, SensorEventListener sensorEventListener) {
        u9(i3, z2, i4, sensorEventListener, false);
    }

    private boolean u2() {
        throw new UnsupportedOperationException("Method not decompiled: net.dinglisch.android.taskerm.MonitorService.u2():boolean");
    }

    private synchronized ti.b u3() {
        try {
            if (this.q1 == null) {
                d3(true);
                this.q1 = ExtensionsContextKt.U2(this).F().A(this.p1.Q()).g(a7()).j();
            }
        } catch (Throwable th2) {
            throw th2;
        }
        return this.q1;
    }

    public void u4(Context context, BluetoothDevice bluetoothDevice, boolean z2, String str, boolean z3) {
        BluetoothAdapter h3;
        o7.f("M", "received " + str + " connect " + z2);
        if (z3) {
            this.p1.t3(bluetoothDevice, z2);
        }
        if (!i1.d(context, bluetoothDevice)) {
            o7.f("M", "BT connect/disconnect: ignoring (unbonded and non-headset event)");
            return;
        }
        h1 h1Var = new h1(bluetoothDevice, z2);
        if (!h1Var.o()) {
            o7.G("M", "ignoring BTDevice with incomplete data");
            return;
        }
        StringBuilder sb = new StringBuilder();
        sb.append("BTDeviceEvent : ");
        sb.append(h1Var.c());
        sb.append(z2 ? " connected" : " disconnected");
        o7.f("M", sb.toString());
        if (z2 && (h3 = i1.h(this)) != null && h3.getState() != 12) {
            o7.f("M", "ignoring spurious connect, BT is off");
            return;
        }
        if (b2.containsKey(h1Var.a())) {
            b2.get(h1Var.a()).n();
        }
        synchronized (b2) {
            b2.put(h1Var.a(), h1Var);
        }
        E2(3, true);
    }

    public static Boolean u6(String str, String str2) {
        return Boolean.valueOf(str2.equals(str));
    }

    private void u7(boolean z2, int[] iArr) {
        Intent z22;
        Intent z23;
        TelephonyManager telephonyManager;
        if (this.W0.isEmpty()) {
            return;
        }
        Q7(false, 0L);
        if (B5() && pp.J1(3, iArr) == -1) {
            r2();
        }
        if (A5(154)) {
            I7(42, gi.e(this), false);
        }
        if (A5(7) && pp.J1(7, iArr) == -1) {
            w7(jo.k(this));
        }
        if (A5(100)) {
            M7(5, pp.O0(this.w0, "airplane_mode_on") != 0, false);
        }
        if (A5(123)) {
            M7(27, B8(this), false);
        }
        if (A5(2)) {
            M7(32, i1.h(this).getState() == 12, false);
        }
        if (A5(14)) {
            D7(false);
        }
        if (A5(16)) {
            y7(false);
        }
        if (A5(135)) {
            v7(false);
        }
        if (A5(195)) {
            B7(false);
        }
        if (A5(122)) {
            G7(26, pp.Y0(this), false);
        }
        if (A5(40) && this.p1.G0(com.joaomgcd.taskerm.util.ac.V0(this)) && (telephonyManager = (TelephonyManager) gi.d(this, "phone", "M", "rms")) != null) {
            int callState = telephonyManager.getCallState();
            if (callState == 0) {
                J7(20, "", false);
                J7(30, "", false);
            } else if (callState == 1 && (!C5(20) || TextUtils.isEmpty(n4(20, 0)))) {
                J7(20, "x", false);
            }
        }
        if (A5(107)) {
            A7(false);
        }
        if (A5(120) && pp.J1(120, iArr) == -1) {
            G7(19, -1, false);
        }
        if (A5(80) && (z23 = this.p1.z2(new IntentFilter("android.intent.action.DOCK_EVENT"))) != null) {
            A4(z23.getExtras(), false);
        }
        if (x5(110) || x5(160) || x5(161) || x5(136)) {
            H4(false);
        }
        if (A5(148)) {
            Intent z24 = this.p1.z2(new IntentFilter("com.samsung.pen.INSERT"));
            if (z24 != null) {
                M4(z24.getExtras(), false);
            }
        }
        if (A5(30) && (z22 = this.p1.z2(new IntentFilter("android.intent.action.HEADSET_PLUG"))) != null) {
            D4(z22.getExtras(), false);
        }
        if (A5(50)) {
            E4(false);
        }
        if (A5(140) || A5(141) || A5(10)) {
            J2(null, false);
        }
        F2(-1, iArr, z2);
    }

    private void u8(net.dinglisch.android.taskerm.c r11) {
        throw new UnsupportedOperationException("Method not decompiled: net.dinglisch.android.taskerm.MonitorService.u8(net.dinglisch.android.taskerm.c):void");
    }

    private void u9(int i3, boolean z2, int i4, SensorEventListener sensorEventListener, boolean z3) {
        try {
            SensorManager sensorManager = this.t0;
            if (sensorManager == null) {
                o7.G("M", "no sensor manager");
                return;
            }
            if (this.p0[i3] == null) {
                o7.f("M", "no default step sensor");
                return;
            }
            SensorEventListener sensorEventListener2 = this.o0[i3];
            if (sensorEventListener2 != null) {
                if (z3) {
                    this.p1.D0(sensorManager, sensorEventListener2);
                } else {
                    sensorManager.unregisterListener(sensorEventListener2);
                }
                this.o0[i3] = null;
                if (i3 == 1) {
                    h8(19);
                }
            }
            Handler handler = this.s0;
            if (i3 == 3 && handler != null) {
                handler.removeMessages(0);
                this.s0 = null;
            }
            int i5 = C1[i3];
            R8(i5, false);
            if (!z2) {
                a8();
                return;
            }
            this.o0[i3] = sensorEventListener;
            if (i3 == 3) {
                this.s0 = new d0(this);
            }
            if (z3 ? this.p1.i0(sensorManager, this.o0[i3], this.p0[i3], i4) : sensorManager.registerListener(this.o0[i3], this.p0[i3], i4)) {
                R8(i5, true);
                if (da(D1[i3], E1[i3], false) == 2) {
                    P1();
                }
                if (i3 == 1) {
                    this.r0 = this.q0;
                    return;
                }
                return;
            }
            o7.k("M", "no " + F1[i3] + " sensor, or couldn't enable");
            this.o0[i3] = null;
        } catch (SecurityException e3) {
            o7.G("M", "startStopSendor: " + i3 + ConstantsCommonTaskerServer.ID_SEPARATOR + e3.getMessage());
        }
    }

    private boolean v2() {
        Set<ComponentName> set = this.D;
        if (set == null) {
            set = new HashSet();
        }
        this.D = new HashSet();
        boolean z2 = false;
        if (com.joaomgcd.taskerm.util.r.h()) {
            for (ActivityManager.RunningServiceInfo runningServiceInfo : this.u0.getRunningServices(99)) {
                String packageName = runningServiceInfo.service.getPackageName();
                String className = runningServiceInfo.service.getClassName();
                if (runningServiceInfo.started) {
                    ComponentName componentName = new ComponentName(packageName, className);
                    this.D.add(componentName);
                    if (!set.contains(componentName)) {
                        o7.f("M", "new service: " + packageName + " / " + className);
                        z2 = true;
                    }
                }
            }
        } else {
            List<ComponentName> list = (List) new ff.c(this).g().f();
            for (ComponentName componentName2 : list) {
                if (!set.contains(componentName2)) {
                    o7.f("M", "new service: " + componentName2.getPackageName() + " / " + componentName2.getClassName());
                    z2 = true;
                }
            }
            this.D.addAll(list);
        }
        if (!z2) {
            for (ComponentName componentName3 : set) {
                if (!this.D.contains(componentName3)) {
                    o7.f("M", "lost service: " + componentName3);
                    return true;
                }
            }
        }
        return z2;
    }

    private void v3() {
        l7();
        o7.f("M", "query event plugins done");
        m7();
        o7.f("M", "query state plugins done");
        try {
            u7(false, null);
        } catch (Exception e3) {
            o7.l("M", "dimc/rms", e3);
        }
        o7.f("M", "recmatch done");
        C2(-1);
        o7.f("M", "checkMatchLocs: done");
        try {
            if (f1.w1(this)) {
                Q8(ip.a(this, 600000L), "doInitialMatchChecks");
                B2(this.C);
            } else {
                B2(this.B);
            }
        } catch (Exception e4) {
            o7.l("M", "dimc/cma", e4);
        }
        o7.f("M", "checkMatchApp: done");
        H2();
        o7.f("M", "checkMatchTimeDay: done");
    }

    private void v4() {
        o7.f("M", "handle BT scan end");
        J9(false);
        E2(4, true);
        j3();
        Y1();
    }

    public void v6() {
        synchronized (B1) {
            stopSelf();
            er.k(this, "M");
        }
    }

    public void v7(boolean z2) {
        M7(44, ContentResolver.getMasterSyncAutomatically(), z2);
    }

    private void v8(fn fnVar) {
        if (fnVar == null) {
            o7.G("M", "saveSettings: no task");
            return;
        }
        for (int i3 = 0; i3 < fnVar.c1(); i3++) {
            net.dinglisch.android.taskerm.c A0 = fnVar.A0(i3);
            int j3 = A0.j();
            if (z0.h(j3)) {
                x8(A0);
            } else if (z0.f(j3)) {
                u8(A0);
            }
        }
    }

    private void v9(boolean z2) {
        if (z2) {
            if (this.N == null) {
                this.N = ContentResolver.addStatusChangeListener(1, new n());
                return;
            } else {
                o7.G("M", "sync status listener already started");
                return;
            }
        }
        Object obj = this.N;
        if (obj != null) {
            ContentResolver.removeStatusChangeListener(obj);
            this.N = null;
        }
    }

    private void w2(String str, Bundle bundle, List<j2> list) {
        int i3 = 0;
        int i4 = 0;
        while (true) {
            try {
                String[] strArr = d6.d.a;
                if (i4 >= strArr.length) {
                    return;
                }
                if (str.equals(strArr[i4])) {
                    if (bundle == null) {
                        o7.k("M", str + ": no extras");
                        return;
                    }
                    j2 j2Var = new j2(446);
                    j2Var.B1(0, i4);
                    j2Var.o0(1, bundle.containsKey(ProfileManager.EXTRA_PROFILE_NAME) ? bundle.getString(ProfileManager.EXTRA_PROFILE_NAME) : "");
                    j2Var.o0(2, bundle.containsKey("message") ? bundle.getString("message") : "");
                    j2Var.o0(3, bundle.containsKey("profile") ? bundle.getString("profile") : "");
                    if (bundle.containsKey("type")) {
                        int v3 = pp.v3(bundle.getString("type"), d6.d.b);
                        if (v3 == -1) {
                            o7.G("M", str + ": unknown alarm type: " + v3);
                        } else {
                            i3 = v3;
                        }
                    } else {
                        o7.G("M", "action: no type specified");
                    }
                    j2Var.B1(4, i3);
                    list.add(j2Var);
                    return;
                }
                i4++;
            } catch (Exception e3) {
                o7.l("M", "GentleAlarm", e3);
                return;
            }
        }
    }

    private void w3(io ioVar) {
        ioVar.J1(3, 0);
    }

    public static vj.e0 w6(Runnable runnable) {
        runnable.run();
        return vj.e0.a;
    }

    public boolean w7(Object obj) {
        boolean z2;
        if (obj == null) {
            o7.f("M", "got null cell location to record");
        } else {
            String f3 = jo.f(obj);
            if (f3 != null) {
                o7.f("M", "recordCellLocation: got id: " + f3);
                if (wp.e1(17)) {
                    if (L1 == null || !L1.equals(f3)) {
                        O8(L1);
                        L1 = f3;
                        wp.F1(this, 17);
                    } else {
                        O8(L1);
                    }
                }
                M1 = f3;
                X1(f3);
                z2 = true;
                S2();
                return z2;
            }
            o7.f("M", "recordCellLocation: ignoring cell with unknown ID");
        }
        z2 = false;
        S2();
        return z2;
    }

    private net.dinglisch.android.taskerm.c w8(net.dinglisch.android.taskerm.c cVar) {
        AudioManager audioManager = (AudioManager) gi.d(this, "audio", "M", "saveSilent");
        if (audioManager == null) {
            o7.k("M", oh.g(this, 2131887712, new Object[0]));
            return null;
        }
        net.dinglisch.android.taskerm.c cVar2 = new net.dinglisch.android.taskerm.c(310);
        int ringerMode = audioManager.getRingerMode();
        cVar2.u1(0, ringerMode != 1 ? ringerMode == 0 ? 2 : 0 : 1);
        return cVar2;
    }

    public boolean x2(io ioVar, j2 j2Var, Bundle bundle) {
        gf.b i1;
        if (!ioVar.e1()) {
            o7.f("M", "check instant activation id: " + ioVar.C0() + ": not active");
            return false;
        }
        if (i7(ioVar)) {
            o7.f("M", "check instant activation id: " + ioVar.C0() + ": cooling down");
            return false;
        }
        o7.f("M", "check instant activation id: " + ioVar.C0() + ": active, not cooling down");
        if (j2Var != null && (i1 = j2Var.i1()) != null) {
            i1.h0(this, j2Var, bundle);
        }
        Bundle s1 = j2Var == null ? null : j2Var.s1(getResources());
        if (bundle == null) {
            bundle = s1 != null ? s1 : null;
        } else if (s1 != null) {
            bundle.putAll(s1);
        }
        E3(ioVar, 0, bundle);
        E3(ioVar, 1, bundle);
        RunLog.K0(this, this.A0, io.a.Instant, ioVar);
        if (ioVar.e0()) {
            this.B0.v4(false);
            F7();
            l8(true);
            ba("checkInstantActivation");
            a8();
            w3(ioVar);
        }
        return true;
    }

    public void x4(int i3) {
        o7.f("M", "handle cal alarm: " + ug.k(i3));
        E2(5, true);
        H8(i3);
    }

    public static void x6(Runnable runnable, Throwable th2) throws Exception {
        o7.g("M", "Couldn't create tasker stopped notification", th2);
        runnable.run();
    }

    public void x7(String str, float f3) {
        pp.S0(this).edit().putFloat(str, f3).commit();
    }

    private void x8(net.dinglisch.android.taskerm.c cVar) {
        int j3 = cVar.j();
        if (this.d1.containsKey(Integer.valueOf(j3))) {
            this.f1.put(Integer.valueOf(j3), Integer.valueOf(this.f1.get(Integer.valueOf(j3)).intValue() + 1));
            return;
        }
        net.dinglisch.android.taskerm.c cVar2 = new net.dinglisch.android.taskerm.c(j3);
        if (j3 != 812) {
            int t0 = cVar2.t0(0);
            if (t0 == 0) {
                int N0 = pp.N0(this.w0, j3);
                if (N0 != -1) {
                    cVar2.u1(0, N0);
                    synchronized (this.e1) {
                        this.d1.put(Integer.valueOf(j3), cVar2);
                        this.f1.put(Integer.valueOf(j3), 1);
                    }
                }
            } else if (t0 != 3) {
                o7.k("M", "saveSystemSettings: unhandled arg type: " + t0);
            } else {
                try {
                    cVar2.o1(0, J3(j3));
                    synchronized (this.e1) {
                        this.d1.put(Integer.valueOf(j3), cVar2);
                        this.f1.put(Integer.valueOf(j3), 1);
                    }
                } catch (Settings.SettingNotFoundException e3) {
                    o7.k("M", "saveSystemSettings: " + e3.toString());
                }
            }
            if (j3 == 810) {
                for (int i3 = 1; i3 < cVar.e0(); i3++) {
                    cVar2.m1(i3, cVar.C(i3));
                }
                return;
            }
            return;
        }
        int N02 = pp.N0(this.w0, j3);
        if (N02 != -1) {
            StringBuilder sb = new StringBuilder();
            sb.append("CURVAL: ");
            sb.append(N02);
            sb.append("ms = ");
            int i4 = N02 / 1000;
            sb.append(i4);
            sb.append("s");
            o7.f("M", sb.toString());
            int i5 = i4 / 3600;
            int i6 = i4 - (i5 * 3600);
            int i7 = i6 / 60;
            int i8 = i6 - (i7 * 60);
            o7.f("M", "hours: " + i5 + " mins: " + i7 + " secs: " + i8);
            cVar2.u1(0, i8);
            cVar2.u1(1, i7);
            cVar2.u1(2, i5);
            synchronized (this.e1) {
                this.d1.put(Integer.valueOf(j3), cVar2);
                this.f1.put(Integer.valueOf(j3), 1);
            }
        }
    }

    private boolean x9(int i3) {
        return y9(i3, x1[i3]);
    }

    private void y2(String str, Bundle bundle, List<j2> list) {
        int i3 = 0;
        while (true) {
            String[] strArr = d6.e.a;
            if (i3 >= strArr.length) {
                return;
            }
            if (str.equals(strArr[i3])) {
                j2 j2Var = new j2(428);
                j2Var.B1(0, i3);
                j2Var.o0(1, bundle.containsKey("org.kaloersoftware.kaloerclock.intents.EXTRA_ALARM_NAME") ? bundle.getString("org.kaloersoftware.kaloerclock.intents.EXTRA_ALARM_NAME") : "");
                list.add(j2Var);
                return;
            }
            i3++;
        }
    }

    private void y3(boolean z2) {
        mh.R(this, AssistHandler.class.getName(), true);
    }

    private void y4() {
        o7.f("M", "chron change");
        if (T6(6)) {
            int i3 = 0;
            while (true) {
                ug[] ugVarArr = this.n0;
                if (i3 >= ugVarArr.length) {
                    break;
                }
                if (ugVarArr[i3] != null) {
                    x4(i3);
                }
                i3++;
            }
        }
        if (T6(4)) {
            b5("chronChange");
        }
    }

    private boolean y5(int i3) {
        Map<Integer, List<Integer>> map = this.V0;
        return map != null && map.containsKey(Integer.valueOf(i3));
    }

    public void y6() {
        this.l0 = new f0(this);
    }

    private void y7(boolean z2) {
        boolean z3;
        if (ud.i0.a()) {
            z3 = ud.i0.f(ud.i0.c(getApplicationContext()));
        } else {
            o7.k("M", "recordDeviceIdleState: no API");
            z3 = false;
        }
        M7(47, z3, z2);
    }

    private net.dinglisch.android.taskerm.c y8(int i3, net.dinglisch.android.taskerm.c cVar) {
        AudioManager audioManager = (AudioManager) gi.d(this, "audio", "M", "saveVol");
        if (audioManager == null) {
            o7.k("M", oh.g(this, 2131887712, new Object[0]));
            return null;
        }
        net.dinglisch.android.taskerm.c cVar2 = new net.dinglisch.android.taskerm.c(cVar.j());
        cVar2.u1(0, audioManager.getStreamVolume(i3));
        cVar2.o1(1, cVar.i(1).T());
        cVar2.o1(2, cVar.i(2).T());
        return cVar2;
    }

    private boolean y9(int i3, long j3) {
        Handler handler = this.l0;
        if (handler == null) {
            return false;
        }
        if (!X9(i3)) {
            if (i3 != 0) {
                o7.f("M", "start timer: " + w1[i3] + " " + j3 + "ms");
            }
            if (!handler.sendEmptyMessageDelayed(i3, j3)) {
                o7.G("M", "timer start failed, gulp");
                return false;
            }
        } else if (i3 != 0 && i3 != 5) {
            o7.f("M", "timer already started: " + w1[i3]);
        }
        return true;
    }

    private void z2(boolean z2) {
        Cursor cursor;
        Cursor cursor2;
        String str;
        if (!gi.a(this)) {
            o7.f("M", "skipping MMS check for non-admin user (crash workaround)");
            return;
        }
        if (pp.z(this, "android.permission.READ_SMS", "McheckMMS")) {
            try {
                cursor = this.w0.query(Uri.parse("content://mms/inbox"), new String[]{"_id", "date", "sub"}, "read=0", null, "_id");
            } catch (Exception e3) {
                o7.H("M", "query MMS inbox", e3);
                cursor = null;
            }
            if (cursor == null) {
                o7.G("M", "checkMMS: null cursor");
                return;
            }
            String str2 = "content://mms/";
            while (cursor.moveToNext()) {
                int i3 = cursor.getInt(0);
                try {
                    cursor2 = this.w0.query(Uri.parse(str2 + i3 + "/addr"), new String[]{"address"}, null, null, null);
                } catch (Exception e4) {
                    o7.H("M", "query MMS detail", e4);
                    cursor2 = null;
                }
                if (cursor2 == null) {
                    o7.G("M", "no cursor getting address for MMS ID " + i3);
                    str = str2;
                } else {
                    if (cursor2.moveToNext()) {
                        long j3 = cursor.getLong(1) * 1000;
                        String string = cursor.getString(2);
                        if (string == null) {
                            string = "";
                        }
                        String str3 = string;
                        String string2 = cursor2.getString(0);
                        str = str2;
                        P7(1, string2, str3, j3);
                        if (j3 > this.x) {
                            this.x = j3;
                            if (z2) {
                                D8(this, 1, string2, str3, ExtensionsContextKt.q2(this, Integer.valueOf(i3)));
                            }
                        }
                    } else {
                        str = str2;
                        o7.f("M", "no cursor entry getting address for MMS ID " + i3);
                    }
                    cursor2.close();
                }
                str2 = str;
            }
            cursor.close();
        }
    }

    private void z3() {
        fo foVar = this.B0;
        if (foVar == null) {
            return;
        }
        mh.R(this, WebSearchHandler.class.getName(), foVar.V2());
    }

    public void z4() {
        HashSet hashSet = new HashSet();
        for (Integer num : this.B0.p2()) {
            io c3 = this.B0.c(num.intValue());
            if (c3 != null && c3.h1() && c3.a1()) {
                hashSet.add(num);
            }
        }
        S4(hashSet, null, "cooldownAlarm");
    }

    public static void z6() throws Exception {
    }

    private void z8() {
        List<Integer> copyOnWriteArrayList;
        List<Integer> list;
        for (Integer num : this.B0.p2()) {
            int intValue = num.intValue();
            io c3 = this.B0.c(intValue);
            for (int i3 = 0; i3 < c3.I0(); i3++) {
                switch (c3.V0(i3)) {
                    case 0:
                        this.R0.put(num, (f1) c3.S0(i3));
                        break;
                    case 1:
                        this.O0.add(Integer.valueOf(c3.C0()));
                        this.P0.put(num, (wo) c3.S0(i3));
                        break;
                    case 2:
                        this.Q0.put(num, (v1) c3.S0(i3));
                        this.O0.add(num);
                        break;
                    case 3:
                        this.S0.put(num, (n7) c3.S0(i3));
                        break;
                    case 4:
                    case 5:
                    case ClockContract.InstancesColumns.MISSED_STATE:
                        bn bnVar = (bn) c3.S0(i3);
                        int j3 = bnVar.j();
                        if (A5(j3)) {
                            copyOnWriteArrayList = this.W0.get(Integer.valueOf(j3));
                        } else {
                            copyOnWriteArrayList = new CopyOnWriteArrayList<>();
                            this.W0.put(Integer.valueOf(j3), copyOnWriteArrayList);
                        }
                        bnVar.h1();
                        Iterator<Integer> it = copyOnWriteArrayList.iterator();
                        while (true) {
                            if (!it.hasNext()) {
                                copyOnWriteArrayList.add(num);
                            } else if (it.next().intValue() == intValue) {
                            }
                        }
                        if (v5(j3)) {
                            for (String str : bnVar.T().a0()) {
                                if (wp.U0(str)) {
                                    this.C0.add(Integer.valueOf(wp.H0(str)));
                                }
                            }
                            break;
                        } else {
                            break;
                        }
                    case 7:
                        j2 j2Var = (j2) c3.S0(i3);
                        int j4 = j2Var.j();
                        if (y5(j4)) {
                            list = this.V0.get(Integer.valueOf(j4));
                        } else {
                            list = new CopyOnWriteArrayList<>();
                            this.V0.put(Integer.valueOf(j4), list);
                        }
                        list.add(num);
                        if (j4 == 3000) {
                            a0 a0Var = new a0(intValue, this.A0.getFloat("accMR", 3.5f), 1000000 * this.A0.getLong("acrmd", 1200L), j2Var.N(0).w(), j2Var.N(1).w());
                            if (a0Var.e) {
                                break;
                            } else {
                                this.T0.put(num, a0Var);
                                break;
                            }
                        } else if (j4 == 3001) {
                            this.U0.put(num, new e0(intValue, j2Var, this.A0.getFloat("accMax", 14.0f)));
                            break;
                        } else if (j4 == 3050) {
                            String w2 = j2Var.N(0).w();
                            if (wp.U0(w2)) {
                                this.C0.add(Integer.valueOf(wp.H0(w2)));
                                break;
                            } else {
                                break;
                            }
                        } else {
                            break;
                        }
                    default:
                        o7.k("M", "bad subcontext");
                        break;
                }
            }
        }
    }

    public void z9(long j3, boolean z2) {
        o7.f("M", "startUserAbsentAlarm: L or greater, no repeating");
        Intent intent = new Intent(this, (Class<?>) ReceiverStaticInternal.class);
        intent.setAction("net.dinglisch.android.tasker.ANOFFCHECKORUM");
        intent.putExtra("repeating", false);
        this.L0 = PendingIntent.getBroadcast(this, 0, intent, com.joaomgcd.taskerm.util.bi.m(268435456, intent));
        o7.f("M", "start user-absent updates: " + (j3 / 1000) + " secs, repeating: false");
        this.N0 = System.currentTimeMillis() + j3;
        V7("start");
    }

    public void D2(Integer num) {
        HashSet hashSet = new HashSet();
        hashSet.add(num);
        G2(hashSet, true);
    }

    public void E2(int i3, boolean z2) {
        F2(i3, null, z2);
    }

    public void F4(SensorEvent sensorEvent) {
        try {
            float f3 = sensorEvent.values[0];
            if (A5(103)) {
                if (f3 < h2) {
                    o7.f("M", "new min level " + h2 + "->" + f3);
                    h2 = f3;
                    x7("lmi", f3);
                }
                if (f3 > i2) {
                    o7.f("M", "new max level " + i2 + "->" + f3);
                    i2 = f3;
                    x7("lma", f3);
                }
                float f4 = i2;
                float f5 = h2;
                if (f4 <= f5) {
                    o7.f("M", "ignoring light sensor readig " + f3 + ", max <= min " + i2 + " < " + h2);
                } else {
                    double d3 = 0.0d;
                    double log = f5 <= 1.0f ? 0.0d : Math.log(f5);
                    double log2 = Math.log(i2);
                    if (f3 > 1.0f) {
                        d3 = Math.log(f3);
                    }
                    o7.f("M", "lmn " + log + " lmx " + log2 + " llvl " + d3);
                    int i3 = (int) (((d3 - log) / (log2 - log)) * 100.0d);
                    o7.f("M", "light: acc: " + sensorEvent.accuracy + " level " + f3 + " min " + h2 + " max " + i2 + " %" + i3);
                    G7(24, i3, true);
                }
            }
            wp.S1(this, 50, String.valueOf(f3));
        } catch (Exception e3) {
            o7.H("M", "onSensorChanged (light)", e3);
        }
    }

    public void H4(boolean z2) {
        kh[] khVarArr;
        ConnectivityManager connectivityManager = (ConnectivityManager) gi.d(this, "connectivity", "M", "hnce");
        int[] iArr = {12, 1, 39, 50};
        String[][] strArr = new String[4][];
        if (connectivityManager != null) {
            if (kh.b()) {
                khVarArr = kh.a(connectivityManager);
            } else {
                kh khVar = new kh();
                kh[] khVarArr2 = {khVar};
                khVar.b = connectivityManager.getActiveNetworkInfo();
                khVarArr2[0].a = true;
                khVarArr = khVarArr2;
            }
            for (kh khVar2 : khVarArr) {
                NetworkInfo networkInfo = khVar2.b;
                if (networkInfo != null && networkInfo.isConnected()) {
                    int type = networkInfo.getType();
                    if (type != 0) {
                        if (type == 1) {
                            o7.f("M", "wifi connection, major type: " + type);
                            WifiManager wifiManager = this.y0;
                            if (wifiManager != null) {
                                WifiInfo connectionInfo = wifiManager.getConnectionInfo();
                                if (connectionInfo == null) {
                                    o7.G("M", "no wifi connection info");
                                } else {
                                    strArr[0] = new String[]{String.valueOf(khVar2.a), connectionInfo.getSSID(), connectionInfo.getBSSID(), pp.K1(connectionInfo.getIpAddress())};
                                }
                            }
                        } else if (type == 6) {
                            o7.f("M", "wimax net connection, major type: " + type);
                            strArr[1] = new String[]{String.valueOf(khVar2.a), String.valueOf(4)};
                        } else if (type == 9) {
                            o7.f("M", "ethernet connection, major type: " + type);
                            strArr[2] = new String[]{String.valueOf(khVar2.a)};
                        } else if (type == 17) {
                            o7.f("M", "VPN connection, major type: " + type);
                            strArr[3] = new String[]{String.valueOf(khVar2.a)};
                        }
                    } else if (A5(110)) {
                        o7.f("M", "mobile net connection, major type: " + type);
                        strArr[1] = new String[]{String.valueOf(khVar2.a), String.valueOf(X3())};
                    }
                }
            }
            for (int i3 = 0; i3 < 4; i3++) {
                int i4 = iArr[i3];
                if (A5(v1[i4])) {
                    O7(i4, strArr[i3], z2);
                }
            }
        }
    }

    public void J4(int i3, j2 j2Var) {
        O5(i3, j2Var, null);
    }

    public void J7(int i3, String str, boolean z2) {
        K7(i3, str, z2, false);
    }

    public void O5(int i3, j2 j2Var, Bundle bundle) {
        List<Integer> arrayList;
        int j3 = j2Var.j();
        if (i3 != -1) {
            arrayList = new ArrayList<>();
            arrayList.add(Integer.valueOf(i3));
        } else if (y5(j3)) {
            arrayList = this.V0.get(Integer.valueOf(j3));
        } else {
            if (j3 == 201) {
                pp.e0(this, 2131891186, 2131887975, 1);
            } else if (j3 != 453 && j3 != 451 && j3 != 450 && j3 != 411 && j3 != 6 && j3 != 4 && j3 != 2 && j3 != 210 && j3 != 1000 && j3 != 208 && j3 != 134 && j3 != 3050 && j3 != 3060 && j3 != 2005 && j3 != 2010 && j3 != 413 && j3 != 463 && j3 != 7 && j3 != 461 && j3 != 464 && !gf.k.l(j3)) {
                o7.k("M", "got system event (" + j3 + ") with no relevant conIDs");
            }
            arrayList = null;
        }
        if (arrayList == null) {
            o7.f("M", "handleSystemEvent: no profiles");
            return;
        }
        for (int i4 = 0; i4 < arrayList.size(); i4++) {
            Integer num = arrayList.get(i4);
            int intValue = num.intValue();
            if (this.B0.V(intValue)) {
                io c3 = this.B0.c(intValue);
                if (c3.h1()) {
                    j2 j2Var2 = (j2) c3.T0(7);
                    Bundle M12 = com.joaomgcd.taskerm.util.b7.M1(com.joaomgcd.taskerm.util.b7.l0(this.B0, this, c3, bundle, "handleOccuredEvent"));
                    if (j2Var2 != null && j2Var2.a1(j2Var, this, this.w0, M12) && x2(c3, j2Var, M12)) {
                        g2.put(num, Long.valueOf(System.currentTimeMillis()));
                    }
                    if (j2Var2 != null) {
                        j2Var2.w0();
                    }
                }
            } else {
                o7.G("M", "handleSystemEvent: unknown profile ID " + intValue + " from event pid " + i3 + ", code" + j3);
            }
        }
    }

    public void L4(final int i3, final j2 j2Var, final Bundle bundle) {
        xg.e2.Q0(this.p1.p2().g(), new Runnable() {
            @Override
            public final void run() {
                MonitorService.this.O5(i3, j2Var, bundle);
            }
        });
    }

    public net.dinglisch.android.taskerm.j2 O4(java.lang.String r5) {
        throw new UnsupportedOperationException("Method not decompiled: net.dinglisch.android.taskerm.MonitorService.O4(java.lang.String):net.dinglisch.android.taskerm.j2");
    }

    public boolean Q1(fn fnVar, Bundle bundle) {
        boolean z2;
        String str;
        String str2;
        Class cls;
        Bundle bundle2 = bundle;
        String str3 = "action1";
        boolean z3 = false;
        if (!bundle2.containsKey("action1")) {
            o7.k("BroadcastDecode", "no valid actions found");
            return false;
        }
        int i3 = 1;
        while (bundle2.containsKey(str3)) {
            Bundle bundle3 = (Bundle) pp.w0("BroadcastDecode", bundle2, str3, Bundle.class, z3);
            String str4 = "action";
            if (bundle3 == null) {
                z2 = z3;
                str = "action";
            } else {
                if (!bundle3.containsKey("action")) {
                    boolean z4 = z3;
                    o7.k("BroadcastDecode", "no action name specified for action no " + i3);
                    return z4;
                }
                int i4 = bundle3.getInt("action");
                if (i4 >= 1000) {
                    o7.k("BroadcastDecode", "plugins barred from external calls: " + i4);
                    return z3;
                }
                if (!z0.c(i4)) {
                    o7.k("BroadcastDecode", "unknown action code: " + i4);
                    return z3;
                }
                if (z0.q(i4)) {
                    o7.k("BroadcastDecode", "deprecated action code: " + i4);
                    return z3;
                }
                if (!z0.m(i4)) {
                    o7.k("BroadcastDecode", "action barred from external calls: " + i4);
                    return z3;
                }
                String v2 = z0.v(i4);
                net.dinglisch.android.taskerm.c cVar = new net.dinglisch.android.taskerm.c(i4);
                int e02 = cVar.e0();
                String str5 = "arg:";
                if (i4 == 547) {
                    try {
                        String str6 = "arg:" + Integer.toString(5);
                        String str7 = "arg:" + Integer.toString(6);
                        String str8 = "arg:" + Integer.toString(7);
                        if (!bundle3.containsKey(str6)) {
                            String str9 = "arg:" + Integer.toString(4);
                            String str10 = "arg:" + Integer.toString(3);
                            bundle3.putBoolean(str6, bundle3.getBoolean(str9));
                            bundle3.putBoolean(str9, bundle3.getBoolean(str10));
                            bundle3.putBoolean(str10, new Boolean(false).booleanValue());
                        }
                        if (!bundle3.containsKey(str7)) {
                            bundle3.putInt(str7, 3);
                        }
                        if (!bundle3.containsKey(str8)) {
                            bundle3.putBoolean(str8, false);
                        }
                    } catch (Exception e3) {
                        o7.H("M", "addActionsFromExternalCall: failed to adapt variable set action to new format", e3);
                    }
                }
                int i5 = 1;
                while (i5 <= e02) {
                    String str11 = str5 + Integer.toString(i5);
                    if (!bundle3.containsKey(str11)) {
                        o7.k("BroadcastDecode", "missing arg no " + str11 + " for action " + v2);
                        return false;
                    }
                    Object obj = bundle3.get(str11);
                    if (obj == null) {
                        o7.k("BroadcastDecode", "null arg no " + str11 + " for action " + v2);
                        return false;
                    }
                    int i6 = i5 - 1;
                    int C = z0.C(i4, i6);
                    Bundle bundle4 = bundle3;
                    String str12 = str5;
                    if (C != 0) {
                        str2 = str4;
                        if (C != 1 && C != 2) {
                            if (C == 3) {
                                cls = Boolean.class;
                            } else if (C != 4) {
                                cls = null;
                            }
                        }
                        cls = String.class;
                    } else {
                        str2 = str4;
                        cls = Integer.class;
                    }
                    Class<?> cls2 = obj.getClass();
                    if (!cls.equals(cls2)) {
                        o7.k("BroadcastDecode", "bad arg class for arg " + i5 + " (" + cls2.getName() + ", expected " + cls.getName() + ")");
                        return false;
                    }
                    if (cls2 == String.class) {
                        String str13 = (String) obj;
                        if (str13.startsWith("app:")) {
                            if (str13.length() <= 4) {
                                o7.G("M", "app arg: empty");
                                return false;
                            }
                            String[] split = str13.substring(4).split(",");
                            cVar.k1(i6, split[0], split[1], "-");
                        } else {
                            if (str13.startsWith("icn:")) {
                                o7.k("BroadcastDecode", "unhandled arg type: icon");
                                return false;
                            }
                            cVar.o0(i6, str13);
                        }
                    } else if (cls2 == Integer.class) {
                        cVar.u1(i6, ((Integer) obj).intValue());
                    } else {
                        if (cls2 != Boolean.class) {
                            o7.k("BroadcastDecode", "action: " + i4 + " arg: " + str11 + ": bad type: " + cls2.getName());
                            return false;
                        }
                        cVar.o1(i6, ((Boolean) obj).booleanValue());
                    }
                    i5++;
                    bundle3 = bundle4;
                    str5 = str12;
                    str4 = str2;
                }
                str = str4;
                z2 = false;
                if (i5 != e02 + 1) {
                    return false;
                }
                fnVar.Z(cVar);
            }
            i3++;
            str3 = str + Integer.toString(i3);
            bundle2 = bundle;
            z3 = z2;
        }
        return true;
    }

    @Override
    public com.joaomgcd.taskerm.helper.w<?> getHelper() {
        return this.p1;
    }

    public void T1(z zVar) {
        synchronized (this.u) {
            this.u.add(zVar);
        }
    }

    public LocationListener T3(String str) {
        return new p(str);
    }

    public boolean U6(int i3) {
        return this.m0[i3];
    }

    public void Y7(int i3, String... strArr) {
        final String str;
        io c3 = this.B0.c(i3);
        j2 j2Var = (j2) c3.T0(7);
        IntentFilter p4 = p4(c3, j2Var);
        try {
            str = p4.getAction(0);
        } catch (Throwable unused) {
            str = null;
        }
        if (str == null || !com.joaomgcd.taskerm.util.b7.A0(strArr, new ik.l() {
            @Override
            public final Object invoke(Object obj) {
                Boolean u6;
                u6 = MonitorService.u6(str, (String) obj);
                return u6;
            }
        })) {
            ReceiverDynamicUser receiverDynamicUser = new ReceiverDynamicUser(j2Var.d1(), this.B0.c(i3), str);
            ExtensionsContextKt.V3(this, receiverDynamicUser, p4);
            this.a1.add(receiverDynamicUser);
        }
    }

    public int Z4(final Intent intent, int i3) {
        if (intent == null) {
            o7.f("M", "ignoring null intent");
        } else if (this.A0 == null) {
            o7.f("M", "skipping start ID " + i3 + ", no prefs -> creation failed");
        } else {
            String action = intent.getAction();
            if (action != null) {
                if (action.equals("net.dinglisch.android.tasker.SS")) {
                    fl.A0(this, intent.getDataString(), intent.getExtras());
                } else if (action.equals("net.dinglisch.android.tasker.CE")) {
                    fl.m(this, intent.getDataString(), intent);
                } else if (action.equals("net.dinglisch.android.tasker.DE")) {
                    fl.u(this, intent.getDataString(), intent);
                } else if (action.equals("net.dinglisch.android.tasker.ICOMUM")) {
                    X4(intent);
                } else if (action.equals("net.dinglisch.android.tasker.PREFUM")) {
                    x3(new Runnable() {
                        @Override
                        public final void run() {
                            MonitorService.this.P5(intent);
                        }
                    }, "handlePrefsIntent");
                } else if (intent.hasExtra("UserIntentPIDExtra")) {
                    s5(intent);
                }
            }
            if (this.g1 != null) {
                R1(intent, i3, true);
            }
        }
        o7.h("M", "handleStart: finished handling ID " + i3, true);
        if (!X9(10)) {
            er.k(this, "M");
        }
        return 1;
    }

    public void l6(Intent intent) {
        try {
            Bundle extras = intent.getExtras();
            Bundle d3 = com.joaomgcd.taskerm.util.t2.d(extras.getBundle("eventExt"));
            String string = extras.getString("eventAct");
            String string2 = extras.getString("eventDt");
            String string3 = extras.getString("eventOrigIntent");
            int i3 = extras.getInt("eventConID", -1);
            List<j2> b7 = b7(string, string2, d3, i3, string3);
            o7.f("M", "occurred event count: " + b7.size() + " with action: " + string);
            Iterator<j2> it = b7.iterator();
            while (it.hasNext()) {
                J4(i3, it.next());
            }
        } catch (Exception e3) {
            o7.l("M", "handleSystemEvent", e3);
        }
    }

    public void aa(BroadcastReceiver broadcastReceiver, String str) {
        if (broadcastReceiver == null) {
            return;
        }
        try {
            unregisterReceiver(broadcastReceiver);
        } catch (Exception e3) {
            o7.H("M", "Couldn't unregister receiver " + str, e3);
        }
    }

    java.util.List<net.dinglisch.android.taskerm.j2> b7(java.lang.String r20, java.lang.String r21, android.os.Bundle r22, int r23, java.lang.String r24) {
        throw new UnsupportedOperationException("Method not decompiled: net.dinglisch.android.taskerm.MonitorService.b7(java.lang.String, java.lang.String, android.os.Bundle, int, java.lang.String):java.util.List");
    }

    public int c4() {
        String str = this.v;
        if (str == null) {
            if (this.A0.contains("ipn")) {
                String a3 = di.a(this.A0.getInt("ipn", -1));
                r2 = a3 != null ? a3 : null;
                this.A0.edit().remove("ipn").commit();
            }
            str = r2;
            if (str == null) {
                str = this.A0.getString("cust_notification", O3(this));
                o7.f("M", "null, get default name: " + str);
            }
        }
        if (!Kid.a()) {
            str = fp.u(this, str);
        }
        return getResources().getIdentifier(str, "drawable", Kid.b(this) ? mh.B() : getPackageName());
    }

    public void c5(int i3) {
        if (i3 != 0) {
            o7.f("M", "!!! timer ding: " + w1[i3]);
        }
        switch (i3) {
            case 0:
                x3(new Runnable() {
                    @Override
                    public final void run() {
                        MonitorService.this.d5();
                    }
                }, "handleTimerAppCheck");
                break;
            case 1:
                i5();
                break;
            case 2:
                j5();
                break;
            case 3:
                o5();
                break;
            case 4:
                l5();
                break;
            case 5:
                p5();
                break;
            case ClockContract.InstancesColumns.MISSED_STATE:
                n5();
                break;
            case 7:
                x3(new Runnable() {
                    @Override
                    public final void run() {
                        MonitorService.this.q5();
                    }
                }, "handleTimerWifiTimeout");
                break;
            case 8:
                m5();
                break;
            case 9:
                h5();
                break;
            case 10:
                k5();
                break;
            case 11:
                e5();
                break;
            case 12:
                f5();
                break;
            case 13:
                x3(new Runnable() {
                    @Override
                    public final void run() {
                        MonitorService.this.g5();
                    }
                }, "handleTimerBTTimeout");
                break;
        }
    }

    @android.annotation.TargetApi(26)
    public android.app.Notification ca(boolean r17, boolean r18) {
        throw new UnsupportedOperationException("Method not decompiled: net.dinglisch.android.taskerm.MonitorService.ca(boolean, boolean):android.app.Notification");
    }

    public void d9(int i3, sn snVar, String str) {
        synchronized (this.u) {
            try {
                o7.f("M", "sig context change: " + str + ": pid: " + i3 + " cType: " + snVar.F0());
                io c3 = this.B0.c(i3);
                if (c3 != null) {
                    o7.f("M", "sig context change pid: " + c3.C0() + " cType: " + snVar.F0() + " enabled: " + c3.h1() + " active: " + snVar.K0());
                    for (Object obj : this.u.toArray()) {
                        ((z) obj).a(i3, snVar.F0(), c3.h1(), snVar.K0());
                    }
                }
            } catch (Throwable th2) {
                throw th2;
            }
        }
    }

    public synchronized List<ReceiverDynamic> f4() {
        return this.b1;
    }

    public void g8(z zVar) {
        synchronized (this.u) {
            int i3 = 0;
            while (true) {
                try {
                    if (i3 >= this.u.size()) {
                        break;
                    }
                    if (this.u.get(i3) == zVar) {
                        this.u.remove(i3);
                        break;
                    }
                    i3++;
                } catch (Throwable th2) {
                    throw th2;
                }
            }
        }
    }

    public uk.n0 getCoroutineScope() {
        return super.getCoroutineScope();
    }

    public boolean h7(int i3) {
        try {
            g7(i3).B(30L, TimeUnit.SECONDS).h();
            return true;
        } catch (RuntimeException e3) {
            Throwable cause = e3.getCause();
            if (cause == null) {
                com.joaomgcd.taskerm.util.h5.m(e3, this, "processInboxSync runtime");
            }
            if (cause instanceof InterruptedException) {
                o7.f("M", "Interrupted while processing inbox: " + cause);
            }
            if (!(cause instanceof TimeoutException)) {
                return false;
            }
            o7.f("M", "Timeout while processing inbox: " + cause);
            return false;
        } catch (Exception e4) {
            com.joaomgcd.taskerm.util.h5.m(e4, this, "processInboxSync");
            return false;
        }
    }

    @Override
    public void onConfigurationChanged(final Configuration configuration) {
        x3(new Runnable() {
            @Override
            public final void run() {
                MonitorService.this.e6(configuration);
            }
        }, "onConfigurationChanged");
    }

    @Override
    public void onCreate() {
        com.joaomgcd.taskerm.util.c0.z(this, Integer.MAX_VALUE);
        RunLog.N0(this, pp.R0(this), RunLog.i.Start);
        super.onCreate();
        this.p1.g0();
        if (!Kid.b(this) && !pp.O(this, "autobackup.xml")) {
            I4();
            RunLog.N0(this, pp.R0(this), RunLog.i.StartFail);
        } else {
            this.A0 = getSharedPreferences(d6.h, 0);
            L8(false);
            t3(new Runnable() {
                @Override
                public final void run() {
                    o7.f("M", "------------------ MONITOR ASYNC STARTUP COMPLETE -----------------");
                }
            }, "onCreate");
        }
    }

    @Override
    public void onDestroy() {
        o7.f("M", "onDestroy");
        RunLog.N0(this, pp.R0(this), RunLog.i.Stop);
        if (this.g1 != null) {
            U9();
            Iterator<io> it = this.Y0.iterator();
            while (it.hasNext()) {
                it.next().a0();
            }
            r3(this.B0, this.Y0, true, false);
        }
        f8();
        V2();
        this.u.clear();
        K9();
        k2();
        this.q1 = null;
        this.p1.h0();
        super.onDestroy();
        if (er.j("Sensor")) {
            er.k(this, "Sensor");
        }
        if (er.j("M")) {
            er.k(this, "M");
        }
        o7.f("M", "onDestroy done");
    }

    @Override
    public void onLowMemory() {
        super.onLowMemory();
        o7.G("M", "low memory reported");
    }

    @Override
    public void onStart(Intent intent, int i3) {
        Z4(intent, i3);
    }

    @Override
    public int onStartCommand(Intent intent, int i3, int i4) {
        return Z4(intent, i4);
    }

    @Override
    public void onTaskRemoved(Intent intent) {
        int g3 = pp.g();
        if (g3 < 16 || g3 >= 21) {
            return;
        }
        o7.f("M", "task removed, send dummy activity intent");
        try {
            startActivity(DummyActivity.a(this));
        } catch (Exception e3) {
            o7.l("M", "onTaskRemoved: JB workaround", e3);
        }
    }

    public void r7() {
        t3(new Runnable() {
            @Override
            public final void run() {
                MonitorService.this.s6();
            }
        }, "queryState");
    }

    public void t3(Runnable runnable, String str) {
        o7.f("M", "Doing in background after init: " + str);
        this.p1.z0(u3().u(this.p1.Q()), runnable);
    }

    public void u5(String str, Bundle bundle, ArrayList<j2> arrayList, String str2) {
        boolean equals = str.equals("net.dinglisch.android.tasker.VSETUM");
        final String string = bundle.getString("vname");
        final String str3 = null;
        String Y12 = wp.V0(string) ? wp.Y1(string) : null;
        if (string == null) {
            o7.f("M", "handleVarSetOrCleared null var name '" + str2 + "'");
            return;
        }
        j2 j2Var = new j2(equals ? 3050 : 3060);
        j2Var.o0(0, string);
        final String string2 = bundle.getString("sc");
        if (string2 != null) {
            this.p1.F(new Runnable() {
                @Override
                public final void run() {
                    MonitorService.this.T5(string2, string);
                }
            });
            return;
        }
        if (equals) {
            str3 = bundle.containsKey("vvalue") ? bundle.getString("vvalue") : wp.B0(this, string);
            j2Var.o0(1, str3);
        }
        arrayList.add(j2Var);
        HashSet hashSet = new HashSet();
        if (this.B0 != null) {
            for (int i3 : an.c) {
                Integer valueOf = Integer.valueOf(i3);
                if (this.W0.containsKey(valueOf)) {
                    Iterator<Integer> it = this.W0.get(valueOf).iterator();
                    while (it.hasNext()) {
                        io c3 = this.B0.c(it.next().intValue());
                        if (c3 != null) {
                            for (int i4 = 4; i4 <= 6; i4++) {
                                if (c3.Z0(i4)) {
                                    bn bnVar = (bn) c3.T0(i4);
                                    if (bnVar.G1(string) || (Y12 != null && bnVar.G1(Y12))) {
                                        hashSet.add(valueOf);
                                        break;
                                    }
                                }
                            }
                        }
                    }
                }
            }
        }
        if (A5(143) && string.equals(wp.I0(77))) {
            L7(29, ExecuteService.K4(), false);
            hashSet.add(143);
        }
        G2(hashSet, true);
        this.p1.F(new Runnable() {
            @Override
            public final void run() {
                MonitorService.this.S5(string, str3);
            }
        });
        this.n1.s(string);
        qi.k();
        if (U2(string) || Y12 == null) {
            return;
        }
        U2(Y12);
    }

    public boolean v5(int i3) {
        if (i3 == 165) {
            return true;
        }
        eh.e<?, ?, ?, ?, ?> h3 = eh.m.h(i3);
        if (h3 == null) {
            return false;
        }
        return h3.h();
    }

    public ti.b w4(final BluetoothDevice bluetoothDevice, final int i3, final String str) {
        HelperMonitorService helperMonitorService = this.p1;
        return helperMonitorService.C(helperMonitorService.V(), new Runnable() {
            @Override
            public final void run() {
                MonitorService.this.N5(bluetoothDevice, str, i3);
            }
        });
    }

    public boolean w5(int i3) {
        fo foVar;
        Map<Integer, List<Integer>> map = this.V0;
        if (map == null || (foVar = this.B0) == null || !y5(i3)) {
            return false;
        }
        Iterator<Integer> it = map.get(Integer.valueOf(i3)).iterator();
        while (it.hasNext()) {
            io c3 = foVar.c(it.next().intValue());
            if (c3 != null && c3.h1()) {
                return true;
            }
        }
        return false;
    }

    public boolean w9(boolean z2) {
        if (!z2) {
            if (er.j("Tasker.UserAbsentWakelock")) {
                if (er.i("Tasker.UserAbsentWakelock")) {
                    this.S = true;
                }
                er.k(this, "Tasker.UserAbsentWakelock");
            }
            N9(4);
            return true;
        }
        if (!x9(4)) {
            o7.G("M", "couldn't start " + w1[4] + ", not acquiring lock");
            return false;
        }
        if (!this.A0.getBoolean("wakeForLoc", false) || (!this.s[2] && !V6())) {
            er.e(this, "Tasker.UserAbsentWakelock");
            return true;
        }
        this.R = true;
        er.b(this, "Tasker.UserAbsentWakelock");
        return true;
    }

    public void x3(Runnable runnable, String str) {
        q3(runnable, (com.joaomgcd.taskerm.util.x7) this.p1.p2().getValue(), str);
    }

    public boolean x5(int i3) {
        Map<Integer, List<Integer>> map;
        fo foVar = this.B0;
        if (foVar == null || !A5(i3) || (map = this.W0) == null) {
            return false;
        }
        Iterator<Integer> it = map.get(Integer.valueOf(i3)).iterator();
        while (it.hasNext()) {
            io c3 = foVar.c(it.next().intValue());
            if (c3 != null && c3.h1()) {
                return true;
            }
        }
        return false;
    }

    public boolean z5(Intent intent) {
        int match;
        if (intent != null && this.V0.containsKey(599)) {
            Iterator<Integer> it = this.V0.get(599).iterator();
            while (it.hasNext()) {
                io c3 = this.B0.c(it.next().intValue());
                j2 j2Var = (j2) c3.T0(7);
                if (j2Var.d1() && (match = p4(c3, j2Var).match(getContentResolver(), intent, false, "M")) != -4 && match != -3 && match != -2 && match != -1) {
                    return true;
                }
            }
        }
        return false;
    }

    public void z7(android.view.KeyEvent r6) {
        throw new UnsupportedOperationException("Method not decompiled: net.dinglisch.android.taskerm.MonitorService.z7(android.view.KeyEvent):void");
    }
}