what-the-bank/sources/com/huawei/hms/support/hwid/tools/HuaweiIdAuthTool.java

336 lines
14 KiB
Java
Raw Permalink Normal View History

2024-07-27 18:17:47 +07:00
package com.huawei.hms.support.hwid.tools;
import android.accounts.Account;
import android.app.Activity;
import android.content.Context;
import android.os.Bundle;
import android.text.TextUtils;
import com.huawei.hms.adapter.AvailableAdapter;
import com.huawei.hms.common.ApiException;
import com.huawei.hms.hwid.aa;
import com.huawei.hms.hwid.as;
import com.huawei.hms.hwid.r;
import com.huawei.hms.hwid.t;
import com.huawei.hms.hwid.x;
import com.huawei.hms.support.api.entity.auth.Scope;
import com.huawei.hms.support.api.entity.common.CommonNaming;
import com.huawei.hms.support.feature.result.CommonConstant;
import com.huawei.hms.support.hianalytics.HiAnalyticsClient;
import com.huawei.hms.support.hwid.common.HuaweiIdAuthException;
import com.huawei.hms.support.hwid.request.HuaweiIdAuthParams;
import com.huawei.hms.support.hwid.request.HuaweiIdAuthParamsHelper;
import com.huawei.hms.support.hwid.service.HuaweiIdAuthServiceImpl;
import com.huawei.hms.utils.HMSPackageManager;
import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.TimeUnit;
import o.HiE;
import o.IHX;
import o.LRb;
import org.json.JSONException;
import org.json.JSONObject;
/* loaded from: classes2.dex */
public class HuaweiIdAuthTool {
protected static final String TAG = "[HUAWEIIDSDK]HuaweiIdAuthTool";
private HuaweiIdAuthTool() {
}
/* JADX INFO: Access modifiers changed from: package-private */
/* loaded from: classes2.dex */
public static class a {
private int a;
private a() {
}
void a(int i) {
this.a = i;
}
int a() {
return this.a;
}
}
public static void deleteAuthInfo(Context context, String str) throws HuaweiIdAuthException {
a(context, str);
}
public static void deleteAuthInfo(Activity activity, String str) throws HuaweiIdAuthException {
a(activity, str);
}
private static void a(HiE<Void> hiE) throws HuaweiIdAuthException {
CountDownLatch countDownLatch = new CountDownLatch(1);
a aVar = new a();
hiE.e(new IHX<Void>(countDownLatch, aVar) { // from class: com.huawei.hms.support.hwid.tools.HuaweiIdAuthTool.2
final CountDownLatch a;
final a b;
{
this.a = countDownLatch;
this.b = aVar;
}
@Override // o.IHX
/* renamed from: a, reason: merged with bridge method [inline-methods] */
public void onSuccess(Void r3) {
as.b(HuaweiIdAuthTool.TAG, "deleteAuthInfo Success.", true);
this.a.countDown();
this.b.a(0);
}
}).e(new LRb(hiE, countDownLatch, aVar) { // from class: com.huawei.hms.support.hwid.tools.HuaweiIdAuthTool.1
final HiE a;
final CountDownLatch b;
final a c;
{
this.a = hiE;
this.b = countDownLatch;
this.c = aVar;
}
@Override // o.LRb
public void onFailure(Exception exc) {
int statusCode = ((ApiException) this.a.e()).getStatusCode();
as.b(HuaweiIdAuthTool.TAG, "deleteAuthInfo fail: ".concat(String.valueOf(statusCode)), true);
this.b.countDown();
this.c.a(statusCode);
}
});
try {
} catch (InterruptedException unused) {
aVar.a(8);
}
if (!countDownLatch.await(10L, TimeUnit.SECONDS)) {
throw new HuaweiIdAuthException("connection timeout[907135004 ].");
}
if (aVar.a() != 0) {
if (aVar.a() == 8) {
throw new HuaweiIdAuthException("unknown interruption[8].");
}
if (aVar.a() == 2010) {
as.c(TAG, "invalid arguments[907135000].", true);
}
}
as.b(TAG, "deleteAuthInfo return[success]", true);
}
private static void a(Context context, String str) throws HuaweiIdAuthException {
boolean z;
r.a();
x.a();
if (context == null) {
throw new HuaweiIdAuthException("Context or Activity is null.");
}
if (context instanceof Activity) {
z = true;
} else {
a(context);
z = false;
}
if (TextUtils.isEmpty(str)) {
as.b(TAG, "accessToken is null or empty.", true);
return;
}
JSONObject jSONObject = new JSONObject();
try {
jSONObject.put(CommonConstant.KEY_ACCESS_TOKEN, str);
HuaweiIdAuthServiceImpl huaweiIdAuthServiceImpl = new HuaweiIdAuthServiceImpl(context, (HuaweiIdAuthParams) null, 60900100);
if (z) {
huaweiIdAuthServiceImpl = new HuaweiIdAuthServiceImpl((Activity) context, (HuaweiIdAuthParams) null, 60900100);
}
a((HiE<Void>) huaweiIdAuthServiceImpl.doWrite(new aa(CommonNaming.signout, jSONObject.toString(), HiAnalyticsClient.reportEntry(context, CommonNaming.signout, 60900100))));
} catch (JSONException unused) {
throw new HuaweiIdAuthException("json error.");
}
}
public static String requestUnionId(Context context, String str) throws HuaweiIdAuthException {
ArrayList arrayList = new ArrayList();
arrayList.add(new Scope("openid"));
return a(context, b(context, str), arrayList, new Bundle(), "requestUnionId").c();
}
public static String requestUnionId(Activity activity, String str) throws HuaweiIdAuthException {
ArrayList arrayList = new ArrayList();
arrayList.add(new Scope("openid"));
return a(activity, b(activity, str), arrayList, new Bundle(), "requestUnionId").c();
}
@Deprecated
public static String requestAccessToken(Context context, String str, List<Scope> list, Bundle bundle) throws HuaweiIdAuthException {
return requestAccessToken(context, b(context, str), list, bundle);
}
@Deprecated
public static String requestAccessToken(Activity activity, String str, List<Scope> list, Bundle bundle) throws HuaweiIdAuthException {
return requestAccessToken(activity, b(activity, str), list, bundle);
}
@Deprecated
public static String requestAccessToken(Context context, String str, List<Scope> list) throws HuaweiIdAuthException {
return requestAccessToken(context, b(context, str), list, new Bundle());
}
@Deprecated
public static String requestAccessToken(Activity activity, String str, List<Scope> list) throws HuaweiIdAuthException {
return requestAccessToken(activity, b(activity, str), list, new Bundle());
}
public static String requestAccessToken(Context context, Account account, List<Scope> list) throws HuaweiIdAuthException {
return requestAccessToken(context, account, list, new Bundle());
}
public static String requestAccessToken(Activity activity, Account account, List<Scope> list) throws HuaweiIdAuthException {
return requestAccessToken(activity, account, list, new Bundle());
}
public static String requestAccessToken(Context context, Account account, List<Scope> list, Bundle bundle) throws HuaweiIdAuthException {
return a(context, account, list, bundle, "requestAccessToken").b();
}
public static String requestAccessToken(Activity activity, Account account, List<Scope> list, Bundle bundle) throws HuaweiIdAuthException {
return a(activity, account, list, bundle, "requestAccessToken").b();
}
private static t a(Context context, Account account, List<Scope> list, Bundle bundle, String str) throws HuaweiIdAuthException {
boolean z;
HuaweiIdAuthServiceImpl huaweiIdAuthServiceImpl;
r.a();
if (context == null) {
throw new HuaweiIdAuthException("Context or Activity is null.");
}
if (context instanceof Activity) {
z = true;
} else {
a(context);
z = false;
}
a(context, account, list, bundle);
HuaweiIdAuthParams createParams = new HuaweiIdAuthParamsHelper().setAccessToken().setScopeList(list).createParams();
String str2 = account == null ? "" : account.name;
if (z) {
huaweiIdAuthServiceImpl = new HuaweiIdAuthServiceImpl((Activity) context, createParams, str2, 60900100);
} else {
huaweiIdAuthServiceImpl = new HuaweiIdAuthServiceImpl(context, createParams, str2, 60900100);
}
return a(huaweiIdAuthServiceImpl, str);
}
private static void a(Context context) throws HuaweiIdAuthException {
int isHuaweiMobileServicesAvailable = new AvailableAdapter(40000300).isHuaweiMobileServicesAvailable(context);
as.b(TAG, "checkDependentHMSVersion result is: ".concat(String.valueOf(isHuaweiMobileServicesAvailable)), true);
if (1 == isHuaweiMobileServicesAvailable) {
throw new HuaweiIdAuthException("hms apk is not exist[2013]");
}
if (2 == isHuaweiMobileServicesAvailable) {
throw new HuaweiIdAuthException("hms apk version is low[2013]");
}
}
private static void a(Context context, Account account, List<Scope> list, Bundle bundle) throws HuaweiIdAuthException {
String hMSPackageName = HMSPackageManager.getInstance(context).getHMSPackageName();
as.b(TAG, "get package name of hms is ".concat(String.valueOf(hMSPackageName)), true);
String str = (account == null || hMSPackageName.equals(account.type)) ? null : "Account type is not supported.";
if (!TextUtils.isEmpty(str)) {
throw new HuaweiIdAuthException(str);
}
}
/* JADX WARN: Removed duplicated region for block: B:7:0x0069 A[RETURN] */
/* JADX WARN: Removed duplicated region for block: B:9:0x006a */
/*
Code decompiled incorrectly, please refer to instructions dump.
To view partially-correct add '--show-bad-code' argument
*/
private static com.huawei.hms.hwid.t a(com.huawei.hms.support.hwid.service.HuaweiIdAuthService r6, java.lang.String r7) throws com.huawei.hms.support.hwid.common.HuaweiIdAuthException {
/*
java.lang.String r0 = "start countDownLatch innerSignIn:"
java.lang.String r1 = java.lang.String.valueOf(r7)
java.lang.String r0 = r0.concat(r1)
java.lang.String r1 = "[HUAWEIIDSDK]HuaweiIdAuthTool"
r2 = 1
com.huawei.hms.hwid.as.b(r1, r0, r2)
com.huawei.hms.hwid.t r0 = new com.huawei.hms.hwid.t
r0.<init>()
java.util.concurrent.CountDownLatch r3 = new java.util.concurrent.CountDownLatch
r3.<init>(r2)
o.HiE r6 = r6.silentSignIn()
com.huawei.hms.support.hwid.tools.HuaweiIdAuthTool$3 r4 = new com.huawei.hms.support.hwid.tools.HuaweiIdAuthTool$3
r4.<init>(r0, r3)
r6.e(r4)
com.huawei.hms.support.hwid.tools.HuaweiIdAuthTool$4 r4 = new com.huawei.hms.support.hwid.tools.HuaweiIdAuthTool$4
r4.<init>(r0, r3)
r6.e(r4)
java.util.concurrent.TimeUnit r6 = java.util.concurrent.TimeUnit.SECONDS // Catch: java.lang.InterruptedException -> L41
r4 = 10
boolean r6 = r3.await(r4, r6) // Catch: java.lang.InterruptedException -> L41
if (r6 == 0) goto L39
goto L4c
L39:
com.huawei.hms.support.hwid.common.HuaweiIdAuthException r3 = new com.huawei.hms.support.hwid.common.HuaweiIdAuthException // Catch: java.lang.InterruptedException -> L42
java.lang.String r4 = "connection timeout[907135004 ]."
r3.<init>(r4) // Catch: java.lang.InterruptedException -> L42
throw r3 // Catch: java.lang.InterruptedException -> L42
L41:
r6 = 0
L42:
java.lang.String r3 = "innerSignIn InterruptedException."
com.huawei.hms.hwid.as.d(r1, r3, r2)
r3 = 8
r0.a(r3)
L4c:
java.lang.StringBuilder r3 = new java.lang.StringBuilder
r3.<init>()
r3.append(r7)
java.lang.String r4 = " end countDownLatch awaitValue:"
r3.append(r4)
r3.append(r6)
java.lang.String r6 = r3.toString()
com.huawei.hms.hwid.as.b(r1, r6, r2)
int r6 = r0.a()
if (r6 != 0) goto L6a
return r0
L6a:
java.lang.StringBuilder r0 = new java.lang.StringBuilder
r0.<init>()
r0.append(r7)
java.lang.String r3 = " fail, error code is:"
r0.append(r3)
r0.append(r6)
java.lang.String r0 = r0.toString()
com.huawei.hms.hwid.as.d(r1, r0, r2)
com.huawei.hms.support.hwid.common.HuaweiIdAuthException r0 = new com.huawei.hms.support.hwid.common.HuaweiIdAuthException
java.lang.StringBuilder r1 = new java.lang.StringBuilder
r1.<init>()
r1.append(r7)
java.lang.String r7 = " error["
r1.append(r7)
r1.append(r6)
java.lang.String r6 = "]"
r1.append(r6)
java.lang.String r6 = r1.toString()
r0.<init>(r6)
throw r0
*/
throw new UnsupportedOperationException("Method not decompiled: com.huawei.hms.support.hwid.tools.HuaweiIdAuthTool.a(com.huawei.hms.support.hwid.service.HuaweiIdAuthService, java.lang.String):com.huawei.hms.hwid.t");
}
private static Account b(Context context, String str) throws HuaweiIdAuthException {
if (context == null) {
as.b(TAG, "context is null", true);
throw new HuaweiIdAuthException("context is null");
}
String hMSPackageName = HMSPackageManager.getInstance(context).getHMSPackageName();
as.b(TAG, "get package name of hms is ".concat(String.valueOf(hMSPackageName)), true);
if (TextUtils.isEmpty(str) || TextUtils.isEmpty(hMSPackageName)) {
return null;
}
return new Account(str, hMSPackageName);
}
}