得物.apk(点击下载) / HonorAccountAuthHelper.java


package com.shizhuang.duapp.libs.honor;

import android.content.Context;
import android.content.Intent;
import android.content.pm.PackageInfo;
import android.os.Build;
import androidx.activity.result.contract.ActivityResultContracts;
import androidx.fragment.app.FragmentActivity;
import b8.c;
import c8.d;
import com.hihonor.cloudservice.common.ApiException;
import com.hihonor.cloudservice.support.account.request.SignInOptions;
import com.hihonor.cloudservice.support.account.result.SignInAccountInfo;
import com.hihonor.cloudservice.support.account.service.HonorIDSignInService;
import com.hihonor.cloudservice.support.api.entity.auth.PermissionInfo;
import com.hihonor.cloudservice.support.api.entity.auth.Scope;
import com.hihonor.cloudservice.tasks.OnFailureListener;
import com.hihonor.cloudservice.tasks.OnSuccessListener;
import com.meituan.robust.ChangeQuickRedirect;
import com.meituan.robust.PatchProxy;
import com.meituan.robust.PatchProxyResult;
import ik1.k;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
import java.util.concurrent.CancellationException;
import kotlin.Result;
import kotlin.ResultKt;
import kotlin.collections.CollectionsKt__CollectionsKt;
import kotlin.coroutines.Continuation;
import kotlin.coroutines.intrinsics.IntrinsicsKt__IntrinsicsJvmKt;
import kotlin.coroutines.intrinsics.IntrinsicsKt__IntrinsicsKt;
import kotlin.coroutines.jvm.internal.DebugProbesKt;
import kotlin.text.StringsKt__StringNumberConversionsKt;
import kotlin.text.StringsKt__StringsJVMKt;
import kotlin.text.StringsKt__StringsKt;
import kotlinx.coroutines.CancellableContinuation;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;

/* compiled from: HonorAccountAuth.kt */
public final class HonorAccountAuthHelper {
    @NotNull

    /* renamed from: a  reason: collision with root package name */
    public static final HonorAccountAuthHelper f9390a = new HonorAccountAuthHelper();
    public static ChangeQuickRedirect changeQuickRedirect;

    /* compiled from: HonorAccountAuth.kt */
    public static final class a<TResult> implements OnSuccessListener<SignInAccountInfo> {
        public static ChangeQuickRedirect changeQuickRedirect;

        /* renamed from: a  reason: collision with root package name */
        public final /* synthetic */ CancellableContinuation f9391a;

        public a(CancellableContinuation cancellableContinuation) {
            this.f9391a = cancellableContinuation;
        }

        /* JADX DEBUG: Method arguments types fixed to match base method, original types: [java.lang.Object] */
        @Override // com.hihonor.cloudservice.tasks.OnSuccessListener
        public void onSuccess(SignInAccountInfo signInAccountInfo) {
            SignInAccountInfo signInAccountInfo2 = signInAccountInfo;
            if (!PatchProxy.proxy(new Object[]{signInAccountInfo2}, this, changeQuickRedirect, false, 33722, new Class[]{SignInAccountInfo.class}, Void.TYPE).isSupported && !this.f9391a.isCompleted()) {
                CancellableContinuation cancellableContinuation = this.f9391a;
                String authorizationCode = signInAccountInfo2.getAuthorizationCode();
                Result.Companion companion = Result.Companion;
                cancellableContinuation.resumeWith(Result.m822constructorimpl(authorizationCode));
            }
        }
    }

    /* compiled from: HonorAccountAuth.kt */
    public static final class b implements OnFailureListener {
        public static ChangeQuickRedirect changeQuickRedirect;

        /* renamed from: a  reason: collision with root package name */
        public final /* synthetic */ CancellableContinuation f9392a;

        public b(CancellableContinuation cancellableContinuation) {
            this.f9392a = cancellableContinuation;
        }

        @Override // com.hihonor.cloudservice.tasks.OnFailureListener
        public final void onFailure(Exception exc) {
            if (PatchProxy.proxy(new Object[]{exc}, this, changeQuickRedirect, false, 33723, new Class[]{Exception.class}, Void.TYPE).isSupported || this.f9392a.isCompleted()) {
                return;
            }
            if (exc instanceof ApiException) {
                ApiException apiException = (ApiException) exc;
                if (apiException.getStatusCode() == 31 || apiException.getStatusCode() == 30 || apiException.getStatusCode() == 55) {
                    CancellableContinuation cancellableContinuation = this.f9392a;
                    SilentSignInException silentSignInException = new SilentSignInException(exc);
                    Result.Companion companion = Result.Companion;
                    cancellableContinuation.resumeWith(Result.m822constructorimpl(ResultKt.createFailure(silentSignInException)));
                    return;
                }
                CancellableContinuation cancellableContinuation2 = this.f9392a;
                NotSupportHonorAuthException notSupportHonorAuthException = new NotSupportHonorAuthException(exc);
                Result.Companion companion2 = Result.Companion;
                cancellableContinuation2.resumeWith(Result.m822constructorimpl(ResultKt.createFailure(notSupportHonorAuthException)));
                return;
            }
            CancellableContinuation cancellableContinuation3 = this.f9392a;
            UnKnownException unKnownException = new UnKnownException(exc);
            Result.Companion companion3 = Result.Companion;
            cancellableContinuation3.resumeWith(Result.m822constructorimpl(ResultKt.createFailure(unKnownException)));
        }
    }

    public final boolean a(@NotNull Context context) {
        String str;
        List split$default;
        Integer intOrNull;
        int intValue;
        PatchProxyResult proxy = PatchProxy.proxy(new Object[]{context}, this, changeQuickRedirect, false, 33712, new Class[]{Context.class}, Boolean.TYPE);
        if (proxy.isSupported) {
            return ((Boolean) proxy.result).booleanValue();
        }
        if (!StringsKt__StringsJVMKt.equals("HONOR", Build.BRAND, true)) {
            return false;
        }
        try {
            PackageInfo packageInfo = context.getApplicationContext().getPackageManager().getPackageInfo("com.hihonor.id", 128);
            if (packageInfo != null && (str = packageInfo.versionName) != null) {
                List list = null;
                String str2 = str.length() > 0 ? str : null;
                if (str2 != null && (split$default = StringsKt__StringsKt.split$default((CharSequence) str2, new String[]{"."}, false, 0, 6, (Object) null)) != null) {
                    if (!split$default.isEmpty()) {
                        list = split$default;
                    }
                    if (list != null) {
                        Integer[] numArr = {6, 0, 2, 300};
                        int i = 0;
                        int i3 = 0;
                        while (i < 4) {
                            int i12 = i3 + 1;
                            int intValue2 = numArr[i].intValue();
                            if (CollectionsKt__CollectionsKt.getLastIndex(list) < i3 || (intOrNull = StringsKt__StringNumberConversionsKt.toIntOrNull((String) list.get(i3))) == null || (intValue = intOrNull.intValue()) > intValue2) {
                                return true;
                            }
                            if (intValue < intValue2) {
                                return false;
                            }
                            i++;
                            i3 = i12;
                        }
                    }
                }
            }
            return true;
        } catch (Throwable unused) {
            return false;
        }
    }

    /* JADX WARNING: Removed duplicated region for block: B:14:0x0036  */
    /* JADX WARNING: Removed duplicated region for block: B:8:0x0023  */
    public final /* synthetic */ Object b(FragmentActivity fragmentActivity, HonorIDSignInService honorIDSignInService, Continuation<? super String> continuation) {
        HonorAccountAuthHelper$oauthSignInByHonorId$1 honorAccountAuthHelper$oauthSignInByHonorId$1;
        int i;
        if (continuation instanceof HonorAccountAuthHelper$oauthSignInByHonorId$1) {
            honorAccountAuthHelper$oauthSignInByHonorId$1 = (HonorAccountAuthHelper$oauthSignInByHonorId$1) continuation;
            int i3 = honorAccountAuthHelper$oauthSignInByHonorId$1.label;
            if ((i3 & Integer.MIN_VALUE) != 0) {
                honorAccountAuthHelper$oauthSignInByHonorId$1.label = i3 - Integer.MIN_VALUE;
                Object obj = honorAccountAuthHelper$oauthSignInByHonorId$1.result;
                Object coroutine_suspended = IntrinsicsKt__IntrinsicsKt.getCOROUTINE_SUSPENDED();
                i = honorAccountAuthHelper$oauthSignInByHonorId$1.label;
                if (i != 0) {
                    ResultKt.throwOnFailure(obj);
                    mi.a aVar = new mi.a(fragmentActivity, new ActivityResultContracts.StartActivityForResult(), null, 4);
                    Intent signInIntent = honorIDSignInService.getSignInIntent();
                    if (signInIntent != null) {
                        HonorAccountAuthHelper$oauthSignInByHonorId$2 honorAccountAuthHelper$oauthSignInByHonorId$2 = new HonorAccountAuthHelper$oauthSignInByHonorId$2(aVar, signInIntent, null);
                        honorAccountAuthHelper$oauthSignInByHonorId$1.L$0 = honorIDSignInService;
                        honorAccountAuthHelper$oauthSignInByHonorId$1.label = 1;
                        obj = honorAccountAuthHelper$oauthSignInByHonorId$2.invoke((Continuation<? super String>) honorAccountAuthHelper$oauthSignInByHonorId$1);
                        if (obj == coroutine_suspended) {
                            return coroutine_suspended;
                        }
                    } else {
                        throw new NotSupportHonorAuthException(new Exception("Honor version too low"));
                    }
                } else if (i == 1) {
                    HonorIDSignInService honorIDSignInService2 = (HonorIDSignInService) honorAccountAuthHelper$oauthSignInByHonorId$1.L$0;
                    try {
                        ResultKt.throwOnFailure(obj);
                    } catch (CancellationException e) {
                        honorIDSignInService2.cancelAuthorization();
                        throw e;
                    }
                } else {
                    throw new IllegalStateException("call to 'resume' before 'invoke' with coroutine");
                }
                return (String) obj;
            }
        }
        honorAccountAuthHelper$oauthSignInByHonorId$1 = new HonorAccountAuthHelper$oauthSignInByHonorId$1(this, continuation);
        Object obj2 = honorAccountAuthHelper$oauthSignInByHonorId$1.result;
        Object coroutine_suspended2 = IntrinsicsKt__IntrinsicsKt.getCOROUTINE_SUSPENDED();
        i = honorAccountAuthHelper$oauthSignInByHonorId$1.label;
        if (i != 0) {
        }
        return (String) obj2;
    }

    public final Object c(HonorIDSignInService honorIDSignInService, Continuation<? super String> continuation) {
        k kVar = new k(IntrinsicsKt__IntrinsicsJvmKt.intercepted(continuation), 1);
        kVar.v();
        b8.a<SignInAccountInfo> silentSignIn = honorIDSignInService.silentSignIn();
        d dVar = (d) silentSignIn;
        dVar.d(new c8.b(c.a(), new a(kVar)));
        dVar.d(new c8.a(c.a(), new b(kVar)));
        kVar.invokeOnCancellation(new HonorAccountAuthHelper$silentSignInByHonorId$$inlined$suspendCancellableCoroutine$lambda$1(honorIDSignInService));
        Object n = kVar.n();
        if (n == IntrinsicsKt__IntrinsicsKt.getCOROUTINE_SUSPENDED()) {
            DebugProbesKt.probeCoroutineSuspended(continuation);
        }
        return n;
    }

    /* JADX WARNING: Removed duplicated region for block: B:12:0x0051  */
    /* JADX WARNING: Removed duplicated region for block: B:20:0x0073  */
    @Nullable
    public final Object d(@NotNull FragmentActivity fragmentActivity, @NotNull Continuation<? super String> continuation) {
        HonorAccountAuthHelper$startHonorAuth$1 honorAccountAuthHelper$startHonorAuth$1;
        int i;
        HonorAccountAuthHelper honorAccountAuthHelper;
        FragmentActivity fragmentActivity2;
        HonorIDSignInService honorIDSignInService;
        PatchProxyResult proxy = PatchProxy.proxy(new Object[]{fragmentActivity, continuation}, this, changeQuickRedirect, false, 33713, new Class[]{FragmentActivity.class, Continuation.class}, Object.class);
        if (proxy.isSupported) {
            return proxy.result;
        }
        if (continuation instanceof HonorAccountAuthHelper$startHonorAuth$1) {
            honorAccountAuthHelper$startHonorAuth$1 = (HonorAccountAuthHelper$startHonorAuth$1) continuation;
            int i3 = honorAccountAuthHelper$startHonorAuth$1.label;
            if ((i3 & Integer.MIN_VALUE) != 0) {
                honorAccountAuthHelper$startHonorAuth$1.label = i3 - Integer.MIN_VALUE;
                Object obj = honorAccountAuthHelper$startHonorAuth$1.result;
                Object coroutine_suspended = IntrinsicsKt__IntrinsicsKt.getCOROUTINE_SUSPENDED();
                i = honorAccountAuthHelper$startHonorAuth$1.label;
                if (i != 0) {
                    ResultKt.throwOnFailure(obj);
                    SignInOptions signInOptions = SignInOptions.DEFAULT_AUTH_REQUEST_PARAM;
                    HashSet hashSet = new HashSet();
                    HashSet hashSet2 = new HashSet();
                    hashSet.addAll(signInOptions.getRequestScopeList());
                    hashSet2.addAll(signInOptions.getPermissionInfos());
                    hashSet.add(new Scope("https://www.hihonor.com/auth/account/mobile.number"));
                    SignInOptions signInOptions2 = new SignInOptions((Set<Scope>) hashSet, (Set<PermissionInfo>) hashSet2, "220921330", "", "", false, false, false, true, true, (String) null, (String) null);
                    PatchProxyResult proxy2 = PatchProxy.proxy(new Object[]{fragmentActivity, signInOptions2}, this, changeQuickRedirect, false, 33716, new Class[]{Context.class, SignInOptions.class}, HonorIDSignInService.class);
                    if (proxy2.isSupported) {
                        honorIDSignInService = (HonorIDSignInService) proxy2.result;
                    } else {
                        honorIDSignInService = new z7.a(fragmentActivity.getApplicationContext(), signInOptions2);
                    }
                    try {
                        honorAccountAuthHelper$startHonorAuth$1.L$0 = this;
                        honorAccountAuthHelper$startHonorAuth$1.L$1 = fragmentActivity;
                        honorAccountAuthHelper$startHonorAuth$1.L$2 = honorIDSignInService;
                        honorAccountAuthHelper$startHonorAuth$1.label = 1;
                        Object c5 = c(honorIDSignInService, honorAccountAuthHelper$startHonorAuth$1);
                        if (c5 == coroutine_suspended) {
                            return coroutine_suspended;
                        }
                        obj = c5;
                    } catch (SilentSignInException unused) {
                        honorAccountAuthHelper = this;
                        fragmentActivity2 = fragmentActivity;
                        honorAccountAuthHelper$startHonorAuth$1.L$0 = null;
                        honorAccountAuthHelper$startHonorAuth$1.L$1 = null;
                        honorAccountAuthHelper$startHonorAuth$1.L$2 = null;
                        honorAccountAuthHelper$startHonorAuth$1.label = 2;
                        obj = honorAccountAuthHelper.b(fragmentActivity2, honorIDSignInService, honorAccountAuthHelper$startHonorAuth$1);
                        if (obj == coroutine_suspended) {
                            return coroutine_suspended;
                        }
                        return (String) obj;
                    }
                } else if (i == 1) {
                    HonorIDSignInService honorIDSignInService2 = (HonorIDSignInService) honorAccountAuthHelper$startHonorAuth$1.L$2;
                    fragmentActivity2 = (FragmentActivity) honorAccountAuthHelper$startHonorAuth$1.L$1;
                    honorAccountAuthHelper = (HonorAccountAuthHelper) honorAccountAuthHelper$startHonorAuth$1.L$0;
                    try {
                        ResultKt.throwOnFailure(obj);
                    } catch (SilentSignInException unused2) {
                        honorIDSignInService = honorIDSignInService2;
                    }
                } else if (i == 2) {
                    ResultKt.throwOnFailure(obj);
                    return (String) obj;
                } else {
                    throw new IllegalStateException("call to 'resume' before 'invoke' with coroutine");
                }
                return (String) obj;
            }
        }
        honorAccountAuthHelper$startHonorAuth$1 = new HonorAccountAuthHelper$startHonorAuth$1(this, continuation);
        Object obj2 = honorAccountAuthHelper$startHonorAuth$1.result;
        Object coroutine_suspended2 = IntrinsicsKt__IntrinsicsKt.getCOROUTINE_SUSPENDED();
        i = honorAccountAuthHelper$startHonorAuth$1.label;
        if (i != 0) {
        }
        return (String) obj2;
    }
}