package com.seewo.remote.g;

import android.app.KeyguardManager;
import android.content.Context;
import android.os.Build;
import android.os.Handler;
import android.os.Looper;
import android.text.TextUtils;
import android.util.Log;
import com.android.internal.widget.LockPatternUtils;
import com.android.internal.widget.LockscreenCredential;
import com.seewo.remote.base.App;
import java.util.ArrayList;

/* JADX INFO: compiled from: ScreenLockUtils.kt */
/* JADX INFO: loaded from: classes.dex */
public final class r {
    public static final r a = new r();
    private static LockPatternUtils b;

    static {
        new Handler(Looper.getMainLooper()).post(new Runnable() { // from class: com.seewo.remote.g.b
            @Override // java.lang.Runnable
            public final void run() {
                r.a();
            }
        });
    }

    private r() {
    }

    /* JADX INFO: Access modifiers changed from: private */
    public static final void a() {
        b = new LockPatternUtils(App.b);
    }

    private final boolean b(String str) {
        int iA = com.seewo.hiddenapi.a.a();
        LockscreenCredential lockscreenCredentialD = d(str);
        LockPatternUtils lockPatternUtils = b;
        if (lockPatternUtils != null) {
            return lockPatternUtils.checkCredential(lockscreenCredentialD, iA, new LockPatternUtils.CheckCredentialProgressCallback() { // from class: com.seewo.remote.g.a
                public final void onEarlyMatched() {
                    r.c();
                }
            });
        }
        h.x.d.k.m("lockPatternUtils");
        throw null;
    }

    /* JADX INFO: Access modifiers changed from: private */
    public static final void c() {
    }

    private final LockscreenCredential d(String str) {
        int iA = com.seewo.hiddenapi.a.a();
        LockPatternUtils lockPatternUtils = b;
        if (lockPatternUtils == null) {
            h.x.d.k.m("lockPatternUtils");
            throw null;
        }
        int credentialTypeForUser = lockPatternUtils.getCredentialTypeForUser(iA);
        LockscreenCredential lockscreenCredentialCreateNone = LockscreenCredential.createNone();
        if (credentialTypeForUser == 1) {
            byte[] bytes = str.getBytes(h.c0.d.b);
            h.x.d.k.c(bytes, "this as java.lang.String).getBytes(charset)");
            lockscreenCredentialCreateNone = LockscreenCredential.createPattern(LockPatternUtils.byteArrayToPattern(bytes));
        } else if (credentialTypeForUser == 3) {
            lockscreenCredentialCreateNone = LockscreenCredential.createPin(str);
        } else if (credentialTypeForUser == 4) {
            lockscreenCredentialCreateNone = LockscreenCredential.createPassword(str);
        }
        h.x.d.k.c(lockscreenCredentialCreateNone, "credential");
        return lockscreenCredentialCreateNone;
    }

    private final boolean e(String str) {
        for (int i2 = 0; i2 < str.length(); i2++) {
            if (!Character.isDigit(str.charAt(i2))) {
                return false;
            }
        }
        return true;
    }

    public final boolean f(Context context) {
        h.x.d.k.d(context, "context");
        Object systemService = context.getSystemService("keyguard");
        if (systemService == null) {
            throw new NullPointerException("null cannot be cast to non-null type android.app.KeyguardManager");
        }
        boolean zIsKeyguardLocked = ((KeyguardManager) systemService).isKeyguardLocked();
        Log.i("ScreenLockUtils", "isScreenLock: " + zIsKeyguardLocked);
        return zIsKeyguardLocked;
    }

    public final boolean g(Context context) {
        h.x.d.k.d(context, "context");
        try {
            if (Build.VERSION.SDK_INT >= 33) {
                int iA = com.seewo.hiddenapi.a.a();
                LockPatternUtils lockPatternUtils = b;
                if (lockPatternUtils == null) {
                    h.x.d.k.m("lockPatternUtils");
                    throw null;
                }
                Boolean bool = (Boolean) e.c.e.f.g.c.l(lockPatternUtils).c("isSecure", Integer.valueOf(iA)).g();
                h.x.d.k.c(bool, "isSecure");
                if (bool.booleanValue() || f(context)) {
                    return true;
                }
            }
        } catch (Exception e2) {
            e2.printStackTrace();
            Log.e("ScreenLockUtils", "call LockPatternUtils isSecure Error");
        }
        return false;
    }

    public final boolean j(String str, String str2) {
        h.x.d.k.d(str, "oldPassword");
        h.x.d.k.d(str2, "newPassword");
        if (TextUtils.isEmpty(str) && TextUtils.isEmpty(str2)) {
            return false;
        }
        int iA = com.seewo.hiddenapi.a.a();
        LockPatternUtils lockPatternUtils = b;
        if (lockPatternUtils == null) {
            h.x.d.k.m("lockPatternUtils");
            throw null;
        }
        int credentialTypeForUser = lockPatternUtils.getCredentialTypeForUser(iA);
        if (credentialTypeForUser == 1) {
            if (!e(str2) || !e(str)) {
                Log.w("ScreenLockUtils", "CredentialType: " + credentialTypeForUser + " password is not Numeric");
                return false;
            }
            ArrayList arrayList = new ArrayList(str2.length());
            for (int i2 = 0; i2 < str2.length(); i2++) {
                arrayList.add(Integer.valueOf(Integer.parseInt(String.valueOf(str2.charAt(i2)))));
            }
            Log.i("ScreenLockUtils", "password: " + arrayList);
            if (!n.a.a(arrayList)) {
                Log.e("ScreenLockUtils", "Pattern password Illegal");
                return false;
            }
        } else if (credentialTypeForUser == 3 && (!e(str2) || !e(str))) {
            Log.w("ScreenLockUtils", "CredentialType: " + credentialTypeForUser + " password is not Numeric");
            return false;
        }
        if (!b(str)) {
            Log.e("ScreenLockUtils", "The old password is incorrect");
            return false;
        }
        LockscreenCredential lockscreenCredentialD = d(str);
        LockscreenCredential lockscreenCredentialD2 = d(str2);
        LockPatternUtils lockPatternUtils2 = b;
        if (lockPatternUtils2 != null) {
            return lockPatternUtils2.setLockCredential(lockscreenCredentialD2, lockscreenCredentialD, iA);
        }
        h.x.d.k.m("lockPatternUtils");
        throw null;
    }
}
