package d.i.c;

import android.app.ActivityManager;
import android.content.ActivityNotFoundException;
import android.content.ComponentName;
import android.content.Context;
import android.content.Intent;
import android.content.pm.ResolveInfo;
import android.content.pm.ServiceInfo;
import android.os.Build;
import android.provider.Settings;
import android.text.TextUtils;
import android.util.Log;
import d.i.f.c.c;
import d.i.f.g.d;
import f.a.n;
import f.a.w.h.b;
import java.lang.reflect.Field;
import java.util.List;
import java.util.concurrent.atomic.AtomicInteger;

/* JADX INFO: loaded from: classes.dex */
public final class a {
    public static d.i.f.g.a a;

    public static boolean A() {
        return c.c("ro.ctm.support.selinux", 0) == 1;
    }

    public static boolean B() {
        return A() && w();
    }

    public static void C(n<?> nVar, AtomicInteger atomicInteger, b bVar) {
        if (atomicInteger.getAndIncrement() == 0) {
            Throwable thB = bVar.b();
            if (thB != null) {
                nVar.a(thB);
            } else {
                nVar.onComplete();
            }
        }
    }

    public static void D(n<?> nVar, Throwable th, AtomicInteger atomicInteger, b bVar) {
        if (!bVar.a(th)) {
            f.a.y.a.C0(th);
        } else if (atomicInteger.getAndIncrement() == 0) {
            nVar.a(bVar.b());
        }
    }

    /* JADX WARN: Multi-variable type inference failed */
    public static <T> void E(n<? super T> nVar, T t, AtomicInteger atomicInteger, b bVar) {
        if (atomicInteger.get() == 0 && atomicInteger.compareAndSet(0, 1)) {
            nVar.c(t);
            if (atomicInteger.decrementAndGet() != 0) {
                Throwable thB = bVar.b();
                if (thB != null) {
                    nVar.a(thB);
                } else {
                    nVar.onComplete();
                }
            }
        }
    }

    public static int F(int i2) {
        return 1 << (32 - Integer.numberOfLeadingZeros(i2 - 1));
    }

    public static void G(Context context, String str, boolean z) {
        try {
            context.getPackageManager().setApplicationEnabledSetting(str, z ? 0 : 2, 0);
        } catch (Exception e2) {
            Log.i("ActivityUtils", str + "doesn't have label", e2);
        }
    }

    public static void H(Context context, boolean z, boolean z2) {
        Intent intent = new Intent("com.seewo.state.vs.lock.change");
        intent.putExtra("lock-type", 4);
        intent.putExtra("lock-state", z);
        intent.putExtra("showui", z2);
        context.sendBroadcast(intent);
        if (z && c.g("persist.sys.keys.child.lock", false)) {
            Intent intent2 = new Intent("com.seewo.action.CHILD_KEYPAD_LOCK_STATE");
            intent2.putExtra("KEYPAD_LOCK_STATE", false);
            intent2.putExtra("showui", false);
            context.sendBroadcast(intent2);
        }
    }

    public static boolean I(Context context, String str, String str2) {
        ComponentName componentName = new ComponentName(str, str2);
        Intent intent = new Intent("android.intent.action.MAIN");
        intent.addCategory("android.intent.category.LAUNCHER");
        intent.setComponent(componentName);
        intent.setFlags(270532608);
        try {
            context.startActivity(intent);
            return true;
        } catch (ActivityNotFoundException e2) {
            Log.d("ActivityUtils", "catch a ActivityNotFoundException when start " + str + " activity: " + str2, e2);
            return false;
        } catch (SecurityException e3) {
            Log.d("ActivityUtils", "catch a SecurityException when startActivitySafely", e3);
            return false;
        }
    }

    @Deprecated
    public static boolean J(Context context, String str) {
        Intent intentG;
        if (z(context, str) || (intentG = g(context, new Intent(str))) == null) {
            return false;
        }
        context.startService(intentG);
        return true;
    }

    @Deprecated
    public static boolean K(Context context, String str) {
        Intent intentG;
        if (!z(context, str) || (intentG = g(context, new Intent(str))) == null) {
            return false;
        }
        context.stopService(intentG);
        return true;
    }

    public static void L(Throwable th) {
        if (th instanceof VirtualMachineError) {
            throw ((VirtualMachineError) th);
        }
        if (th instanceof ThreadDeath) {
            throw ((ThreadDeath) th);
        }
        if (th instanceof LinkageError) {
            throw ((LinkageError) th);
        }
    }

    public static <T> T a(Object obj, String str, Object... objArr) {
        return (T) d.i.f.g.e.b.d(obj).b(str, objArr).f3661b;
    }

    public static d b(String str) {
        return d(new String[]{str}, true, true);
    }

    public static d c(String str, boolean z) {
        return d(new String[]{str}, z, true);
    }

    /* JADX WARN: Can't wrap try/catch for region: R(12:(9:255|84|253|85|225|86|(3:88|(2:90|264)(4:91|(1:93)|94|263)|95)|262|96)|(19:249|98|244|99|243|100|251|101|(9:247|102|(1:104)(1:265)|195|196|(1:198)(1:199)|(1:202)|203|204)|(2:105|(1:107)(0))|132|(1:134)|(1:136)|195|196|(0)(0)|(0)|203|204)(1:131)|220|132|(0)|(0)|195|196|(0)(0)|(0)|203|204) */
    /* JADX WARN: Code restructure failed: missing block: B:138:0x01f1, code lost:
    
        r0 = move-exception;
     */
    /* JADX WARN: Code restructure failed: missing block: B:139:0x01f2, code lost:
    
        android.util.Log.e("ShellCommandUtils", "close stream error", r0);
     */
    /* JADX WARN: Multi-variable type inference failed */
    /* JADX WARN: Removed duplicated region for block: B:134:0x01e7 A[Catch: IOException -> 0x01f1, TryCatch #5 {IOException -> 0x01f1, blocks: (B:132:0x01e2, B:134:0x01e7, B:136:0x01ec), top: B:220:0x01e2 }] */
    /* JADX WARN: Removed duplicated region for block: B:136:0x01ec A[Catch: IOException -> 0x01f1, TRY_LEAVE, TryCatch #5 {IOException -> 0x01f1, blocks: (B:132:0x01e2, B:134:0x01e7, B:136:0x01ec), top: B:220:0x01e2 }] */
    /* JADX WARN: Removed duplicated region for block: B:170:0x0229 A[Catch: IOException -> 0x0225, TryCatch #29 {IOException -> 0x0225, blocks: (B:166:0x0221, B:170:0x0229, B:172:0x022e), top: B:234:0x0221 }] */
    /* JADX WARN: Removed duplicated region for block: B:172:0x022e A[Catch: IOException -> 0x0225, TRY_LEAVE, TryCatch #29 {IOException -> 0x0225, blocks: (B:166:0x0221, B:170:0x0229, B:172:0x022e), top: B:234:0x0221 }] */
    /* JADX WARN: Removed duplicated region for block: B:189:0x0250 A[Catch: IOException -> 0x024c, TryCatch #27 {IOException -> 0x024c, blocks: (B:185:0x0248, B:189:0x0250, B:191:0x0255), top: B:231:0x0248 }] */
    /* JADX WARN: Removed duplicated region for block: B:191:0x0255 A[Catch: IOException -> 0x024c, TRY_LEAVE, TryCatch #27 {IOException -> 0x024c, blocks: (B:185:0x0248, B:189:0x0250, B:191:0x0255), top: B:231:0x0248 }] */
    /* JADX WARN: Removed duplicated region for block: B:195:0x025e A[PHI: r1 r13 r14 r15
      0x025e: PHI (r1v10 java.lang.StringBuilder) = 
      (r1v7 java.lang.StringBuilder)
      (r1v8 java.lang.StringBuilder)
      (r1v16 java.lang.StringBuilder)
      (r1v16 java.lang.StringBuilder)
      (r1v16 java.lang.StringBuilder)
     binds: [B:175:0x0235, B:194:0x025c, B:139:0x01f2, B:135:0x01ea, B:136:0x01ec] A[DONT_GENERATE, DONT_INLINE]
      0x025e: PHI (r13v19 int) = (r13v16 int), (r13v17 int), (r13v27 int), (r13v27 int), (r13v27 int) binds: [B:175:0x0235, B:194:0x025c, B:139:0x01f2, B:135:0x01ea, B:136:0x01ec] A[DONT_GENERATE, DONT_INLINE]
      0x025e: PHI (r14v18 ??) = (r14v15 ??), (r14v16 ??), (r14v20 ??), (r14v20 ??), (r14v20 ??) binds: [B:175:0x0235, B:194:0x025c, B:139:0x01f2, B:135:0x01ea, B:136:0x01ec] A[DONT_GENERATE, DONT_INLINE]
      0x025e: PHI (r15v14 java.lang.StringBuilder) = 
      (r15v8 java.lang.StringBuilder)
      (r15v9 java.lang.StringBuilder)
      (r15v22 java.lang.StringBuilder)
      (r15v22 java.lang.StringBuilder)
      (r15v22 java.lang.StringBuilder)
     binds: [B:175:0x0235, B:194:0x025c, B:139:0x01f2, B:135:0x01ea, B:136:0x01ec] A[DONT_GENERATE, DONT_INLINE]] */
    /* JADX WARN: Removed duplicated region for block: B:198:0x0265  */
    /* JADX WARN: Removed duplicated region for block: B:199:0x0267  */
    /* JADX WARN: Removed duplicated region for block: B:202:0x026e  */
    /* JADX WARN: Removed duplicated region for block: B:212:0x0282 A[Catch: IOException -> 0x027e, TryCatch #18 {IOException -> 0x027e, blocks: (B:208:0x027a, B:212:0x0282, B:214:0x0287), top: B:227:0x027a }] */
    /* JADX WARN: Removed duplicated region for block: B:214:0x0287 A[Catch: IOException -> 0x027e, TRY_LEAVE, TryCatch #18 {IOException -> 0x027e, blocks: (B:208:0x027a, B:212:0x0282, B:214:0x0287), top: B:227:0x027a }] */
    /* JADX WARN: Removed duplicated region for block: B:218:0x0290  */
    /* JADX WARN: Removed duplicated region for block: B:227:0x027a A[EXC_TOP_SPLITTER, SYNTHETIC] */
    /* JADX WARN: Removed duplicated region for block: B:231:0x0248 A[EXC_TOP_SPLITTER, SYNTHETIC] */
    /* JADX WARN: Removed duplicated region for block: B:234:0x0221 A[EXC_TOP_SPLITTER, SYNTHETIC] */
    /* JADX WARN: Removed duplicated region for block: B:266:? A[SYNTHETIC] */
    /* JADX WARN: Removed duplicated region for block: B:58:0x00e0  */
    /* JADX WARN: Removed duplicated region for block: B:62:0x00f6  */
    /* JADX WARN: Removed duplicated region for block: B:66:0x0102  */
    /* JADX WARN: Type inference failed for: r14v0, types: [boolean] */
    /* JADX WARN: Type inference failed for: r14v1, types: [java.lang.Process] */
    /* JADX WARN: Type inference failed for: r14v10 */
    /* JADX WARN: Type inference failed for: r14v11 */
    /* JADX WARN: Type inference failed for: r14v12 */
    /* JADX WARN: Type inference failed for: r14v13 */
    /* JADX WARN: Type inference failed for: r14v14 */
    /* JADX WARN: Type inference failed for: r14v15 */
    /* JADX WARN: Type inference failed for: r14v16 */
    /* JADX WARN: Type inference failed for: r14v18, types: [java.lang.Process] */
    /* JADX WARN: Type inference failed for: r14v2 */
    /* JADX WARN: Type inference failed for: r14v20, types: [java.lang.Process] */
    /* JADX WARN: Type inference failed for: r14v28 */
    /* JADX WARN: Type inference failed for: r14v29 */
    /* JADX WARN: Type inference failed for: r14v3 */
    /* JADX WARN: Type inference failed for: r14v30 */
    /* JADX WARN: Type inference failed for: r14v31 */
    /* JADX WARN: Type inference failed for: r14v32 */
    /* JADX WARN: Type inference failed for: r14v33 */
    /* JADX WARN: Type inference failed for: r14v4 */
    /* JADX WARN: Type inference failed for: r14v5 */
    /* JADX WARN: Type inference failed for: r14v6 */
    /* JADX WARN: Type inference failed for: r14v7 */
    /* JADX WARN: Type inference failed for: r14v8 */
    /* JADX WARN: Type inference failed for: r14v9 */
    /* JADX WARN: Type inference failed for: r2v10 */
    /* JADX WARN: Type inference failed for: r2v13 */
    /* JADX WARN: Type inference failed for: r2v14 */
    /* JADX WARN: Type inference failed for: r2v5 */
    /* JADX WARN: Type inference failed for: r2v6, types: [java.io.InputStream] */
    /* JADX WARN: Type inference failed for: r3v0, types: [java.lang.String] */
    /* JADX WARN: Type inference failed for: r3v1, types: [java.io.BufferedReader] */
    /* JADX WARN: Type inference failed for: r3v10, types: [java.io.BufferedReader] */
    /* JADX WARN: Type inference failed for: r3v11 */
    /* JADX WARN: Type inference failed for: r3v12 */
    /* JADX WARN: Type inference failed for: r3v13 */
    /* JADX WARN: Type inference failed for: r3v2 */
    /* JADX WARN: Type inference failed for: r3v3 */
    /* JADX WARN: Type inference failed for: r3v4 */
    /* JADX WARN: Type inference failed for: r3v5 */
    /* JADX WARN: Type inference failed for: r3v6, types: [java.io.BufferedReader] */
    /* JADX WARN: Type inference failed for: r3v7, types: [java.io.BufferedReader] */
    /* JADX WARN: Type inference failed for: r3v8 */
    /* JADX WARN: Type inference failed for: r3v9, types: [java.io.BufferedReader] */
    /* JADX WARN: Type inference failed for: r4v20, types: [java.lang.String] */
    /* JADX WARN: Type inference failed for: r4v21, types: [android.net.LocalSocket] */
    /* JADX WARN: Type inference failed for: r4v22 */
    /* JADX WARN: Type inference failed for: r4v23 */
    /* JADX WARN: Type inference failed for: r4v24 */
    /* JADX WARN: Type inference failed for: r4v25, types: [android.net.LocalSocket] */
    /* JADX WARN: Type inference failed for: r4v26, types: [android.net.LocalSocket] */
    /* JADX WARN: Type inference failed for: r7v13, types: [int] */
    /* JADX WARN: Type inference failed for: r7v14, types: [java.io.OutputStream] */
    /* JADX WARN: Type inference failed for: r7v15 */
    /* JADX WARN: Type inference failed for: r7v16 */
    /* JADX WARN: Type inference failed for: r7v17, types: [java.io.OutputStream] */
    /* JADX WARN: Type inference failed for: r7v18 */
    /* JADX WARN: Type inference failed for: r7v19 */
    /* JADX WARN: Type inference failed for: r7v21, types: [java.io.OutputStream] */
    /*
        Code decompiled incorrectly, please refer to instructions dump.
        To view partially-correct add '--show-bad-code' argument
    */
    public static d.i.f.g.d d(java.lang.String[] r13, boolean r14, boolean r15) throws java.lang.Throwable {
        /*
            Method dump skipped, instruction units count: 660
            To view this dump add '--comments-level debug' option
        */
        throw new UnsupportedOperationException("Method not decompiled: d.i.c.a.d(java.lang.String[], boolean, boolean):d.i.f.g.d");
    }

    public static d.i.f.g.a e() {
        d.i.f.g.a aVar = a;
        if (aVar != null) {
            return aVar;
        }
        String strF = c.f("ro.cvte.ic", "");
        if (TextUtils.isEmpty(strF)) {
            strF = c.f("ro.customer.ic", "");
        }
        if (strF.equals("MSD638")) {
            a = d.i.f.g.a.MSD638;
        } else if (strF.equals("MSD608")) {
            a = d.i.f.g.a.MSD608;
        } else if (strF.equals("MSD6369")) {
            a = d.i.f.g.a.MSD6369;
        } else if (strF.equals("MTK5508")) {
            a = d.i.f.g.a.MTK5508;
        } else if (strF.equals("3288")) {
            a = d.i.f.g.a.RK3288;
        } else if (strF.equals("510")) {
            a = d.i.f.g.a.HISI_V510;
        } else if (strF.equals("3399")) {
            a = d.i.f.g.a.RK3399;
        } else if (strF.equals("620")) {
            a = d.i.f.g.a.HISI_V620;
        } else if (strF.equals("551")) {
            a = d.i.f.g.a.HISI_V551;
        } else if (strF.equals("811")) {
            a = d.i.f.g.a.HISI_V811;
        } else if (strF.equals("MSD8386")) {
            a = d.i.f.g.a.MSD8386;
        } else if (strF.equals("972")) {
            a = d.i.f.g.a.V972;
        } else if (strF.equals("9950")) {
            a = d.i.f.g.a.MTK9950;
        } else if (strF.endsWith("982")) {
            a = d.i.f.g.a.V982;
        } else if (strF.endsWith("1516")) {
            a = d.i.f.g.a.A1516;
        } else if (strF.endsWith("3588")) {
            a = d.i.f.g.a.RK3588;
        } else if (strF.endsWith("8195")) {
            a = d.i.f.g.a.MT8195;
        } else if (strF.endsWith("9666")) {
            a = d.i.f.g.a.MT9666;
        } else {
            a = d.i.f.g.a.Other;
        }
        return a;
    }

    public static boolean f(Context context, String str, boolean z) {
        int i2 = Settings.Global.getInt(context.getContentResolver(), str, -1);
        return i2 < 0 ? z : i2 == 1;
    }

    public static Intent g(Context context, Intent intent) {
        List<ResolveInfo> listQueryIntentServices = context.getPackageManager().queryIntentServices(intent, 0);
        if (listQueryIntentServices == null || listQueryIntentServices.size() != 1) {
            Log.e("ActivityUtils", "Make sure there is one and only one component matches this action");
            return null;
        }
        ServiceInfo serviceInfo = listQueryIntentServices.get(0).serviceInfo;
        ComponentName componentName = new ComponentName(serviceInfo.packageName, serviceInfo.name);
        Intent intent2 = new Intent(intent);
        intent2.setComponent(componentName);
        return intent2;
    }

    public static String h(StringBuilder sb) {
        String[] strArrSplit = sb.toString().split("\n");
        StringBuilder sb2 = new StringBuilder("");
        for (int i2 = 0; i2 < strArrSplit.length - 1; i2++) {
            sb2.append(strArrSplit[i2]);
            sb2.append('\n');
        }
        String str = "response#" + ((Object) sb2);
        if (d.i.f.g.c.a) {
            Log.v("ShellCommandUtils", str);
        }
        return sb2.toString();
    }

    public static <T> T i(Class cls, String str) {
        Field field;
        try {
            try {
                field = (Field) d.i.f.g.e.b.a(cls.getField(str));
            } catch (NoSuchFieldException e2) {
                Class superclass = cls;
                do {
                    try {
                        field = (Field) d.i.f.g.e.b.a(superclass.getDeclaredField(str));
                    } catch (NoSuchFieldException unused) {
                        superclass = superclass.getSuperclass();
                    }
                } while (superclass != null);
                throw new d.i.f.g.e.c(e2);
            }
            field.getType();
            return (T) field.get(cls);
        } catch (Exception e3) {
            throw new d.i.f.g.e.c(e3);
        }
    }

    public static String j(Context context) {
        String strF = y() ? "com.seewo.easimark.MarkActivity" : c.f("sys.current.visible.activity", null);
        if (strF != null && !strF.isEmpty()) {
            return strF;
        }
        List<ActivityManager.RunningTaskInfo> runningTasks = ((ActivityManager) context.getSystemService("activity")).getRunningTasks(1);
        if (runningTasks == null || runningTasks.isEmpty()) {
            return null;
        }
        return runningTasks.get(0).topActivity.getClassName();
    }

    public static boolean k() {
        int i2 = d.i.f.g.b.a;
        StringBuilder sbB = d.b.a.a.a.B("is638Machine: ");
        sbB.append(m());
        sbB.append(" is510Machine: ");
        sbB.append(l());
        sbB.append(" isBitTrue: ");
        sbB.append(d.i.f.g.b.a(19));
        Log.e("HardwareUtils", sbB.toString());
        return m() || l() || d.i.f.g.b.a(19);
    }

    public static boolean l() {
        return d.i.f.g.a.HISI_V510 == e();
    }

    public static boolean m() {
        return d.i.f.g.a.MSD638 == e();
    }

    public static boolean n() {
        return d.i.f.g.a.HISI_V811 == e();
    }

    public static boolean o() {
        return d.i.f.g.a.MSD8386 == e();
    }

    public static boolean p() {
        return d.i.f.g.a.V972 == e();
    }

    public static boolean q() {
        return d.i.f.g.a.V982 == e();
    }

    public static boolean r() {
        return d.i.f.g.a.MTK9950 == e();
    }

    public static boolean s() {
        return r() && Build.VERSION.SDK_INT == 30;
    }

    public static boolean t(Context context, String str) {
        String strJ = j(context);
        if (strJ == null || strJ.isEmpty()) {
            return false;
        }
        return strJ.equals(str);
    }

    public static boolean u() {
        if (d.i.f.g.a.RK3288 == e()) {
            return true;
        }
        return d.i.f.g.a.RK3399 == e();
    }

    @Deprecated
    public static boolean v(Context context, String str) {
        if (!"".equals(str)) {
            try {
                return context.getPackageManager().getApplicationEnabledSetting(str) != 2;
            } catch (Exception e2) {
                Log.i("ActivityUtils", str + "doesn't have label", e2);
            }
        }
        return false;
    }

    public static boolean w() {
        return d.i.f.a.a.a <= 9 && !s() && Build.VERSION.SDK_INT < 33;
    }

    public static boolean x(Context context) {
        return t(context, "com.seewo.easinote.PlainActivity") || t(context, "com.seewo.easinote.PlainWhiteboardActivity") || t(context, "com.seewo.easinote.PlainPairModeActivity") || (c.h() & 1) == 1;
    }

    public static boolean y() {
        return (c.h() & 2) == 2;
    }

    public static boolean z(Context context, String str) {
        List<ActivityManager.RunningServiceInfo> runningServices = ((ActivityManager) context.getSystemService("activity")).getRunningServices(Integer.MAX_VALUE);
        for (int i2 = 0; i2 < runningServices.size(); i2++) {
            if (runningServices.get(i2).service.getClassName().equals(str)) {
                return true;
            }
        }
        return false;
    }
}
