what-the-bank/sources/com/huawei/hms/common/HuaweiApi.java

822 lines
34 KiB
Java
Raw Permalink Normal View History

2024-07-27 18:17:47 +07:00
package com.huawei.hms.common;
import android.app.Activity;
import android.content.Context;
import android.os.Looper;
import android.text.TextUtils;
import com.huawei.hms.adapter.AvailableUtil;
import com.huawei.hms.adapter.BinderAdapter;
import com.huawei.hms.api.Api;
import com.huawei.hms.api.Api.ApiOptions;
import com.huawei.hms.api.ConnectionResult;
import com.huawei.hms.common.internal.AbstractClientBuilder;
import com.huawei.hms.common.internal.AnyClient;
import com.huawei.hms.common.internal.BaseHmsClient;
import com.huawei.hms.common.internal.BindResolveClients;
import com.huawei.hms.common.internal.ClientSettings;
import com.huawei.hms.common.internal.HmsClient;
import com.huawei.hms.common.internal.RequestHeader;
import com.huawei.hms.common.internal.RequestManager;
import com.huawei.hms.common.internal.ResolveClientBean;
import com.huawei.hms.common.internal.ResponseHeader;
import com.huawei.hms.common.internal.TaskApiCall;
import com.huawei.hms.common.internal.TaskApiCallWrapper;
import com.huawei.hms.common.internal.TransactionIdCreater;
import com.huawei.hms.core.aidl.IAIDLInvoke;
import com.huawei.hms.core.aidl.IMessageEntity;
import com.huawei.hms.support.api.client.Status;
import com.huawei.hms.support.api.client.SubAppInfo;
import com.huawei.hms.support.api.entity.auth.Scope;
import com.huawei.hms.support.api.entity.core.CommonCode;
import com.huawei.hms.support.hianalytics.HiAnalyticsConstant;
import com.huawei.hms.support.hianalytics.HiAnalyticsInnerClient;
import com.huawei.hms.support.log.HMSLog;
import com.huawei.hms.utils.Checker;
import com.huawei.hms.utils.HMSBIInitializer;
import com.huawei.hms.utils.HMSPackageManager;
import com.huawei.hms.utils.Util;
import java.lang.ref.WeakReference;
import java.util.Collections;
import java.util.Iterator;
import java.util.LinkedList;
import java.util.List;
import java.util.Queue;
import java.util.concurrent.atomic.AtomicBoolean;
import o.HiE;
import o.nNj;
/* loaded from: classes2.dex */
public class HuaweiApi<TOption extends Api.ApiOptions> {
private Context a;
private TOption b;
private Context c;
private AbstractClientBuilder<?, TOption> d;
private String e;
private String f;
private SubAppInfo g;
private WeakReference<Activity> h;
private int i;
private int j = 1;
private boolean k = false;
private String l;
private boolean m;
private RequestManager n;
/* loaded from: classes2.dex */
public static class RequestHandler<OptionsT extends Api.ApiOptions> implements BaseHmsClient.ConnectionCallbacks, BaseHmsClient.OnConnectionFailedListener {
private final AnyClient b;
private final HuaweiApi<OptionsT> d;
private ResolveClientBean e;
public final Queue<TaskApiCallbackWrapper> callbackWaitQueue = new LinkedList();
private final Queue<TaskApiCallbackWrapper> a = new LinkedList();
private ConnectionResult c = null;
/* JADX INFO: Access modifiers changed from: package-private */
/* renamed from: com.huawei.hms.common.HuaweiApi$RequestHandler$2, reason: invalid class name */
/* loaded from: classes2.dex */
public class AnonymousClass2 implements AnyClient.CallBack {
final TaskApiCallbackWrapper a;
final RequestHeader b;
final RequestHandler c;
AnonymousClass2(RequestHandler requestHandler, TaskApiCallbackWrapper taskApiCallbackWrapper, RequestHeader requestHeader) {
this.c = requestHandler;
this.a = taskApiCallbackWrapper;
this.b = requestHeader;
}
@Override // com.huawei.hms.common.internal.AnyClient.CallBack
public void onCallback(IMessageEntity iMessageEntity, String str) {
AnyClient.CallBack b = this.a.b();
if (b != null) {
b.onCallback(iMessageEntity, str);
}
RequestManager.removeReqByTransId(this.b.getTransactionId());
RequestManager.getHandler().post(new Runnable(this) { // from class: com.huawei.hms.common.HuaweiApi.RequestHandler.2.1
final AnonymousClass2 a;
{
this.a = this;
}
@Override // java.lang.Runnable
public void run() {
this.a.c.a.remove(this.a.a);
}
});
}
}
RequestHandler(HuaweiApi<OptionsT> huaweiApi) {
this.d = huaweiApi;
this.b = huaweiApi.getClient(RequestManager.getHandler().getLooper(), this);
}
@Override // com.huawei.hms.common.internal.BaseHmsClient.ConnectionCallbacks
public void onConnected() {
HMSLog.i("HuaweiApi", "onConnected");
BindResolveClients.getInstance().unRegister(this.e);
this.e = null;
RequestManager.getHandler().post(new Runnable(this) { // from class: com.huawei.hms.common.HuaweiApi.RequestHandler.4
final RequestHandler a;
{
this.a = this;
}
@Override // java.lang.Runnable
public void run() {
this.a.b();
}
});
}
@Override // com.huawei.hms.common.internal.BaseHmsClient.OnConnectionFailedListener
public void onConnectionFailed(ConnectionResult connectionResult) {
HMSLog.i("HuaweiApi", "onConnectionFailed");
BindResolveClients.getInstance().unRegister(this.e);
this.e = null;
RequestManager.getHandler().post(new Runnable(this, connectionResult) { // from class: com.huawei.hms.common.HuaweiApi.RequestHandler.3
final ConnectionResult a;
final RequestHandler b;
{
this.b = this;
this.a = connectionResult;
}
@Override // java.lang.Runnable
public void run() {
this.b.b(this.a);
}
});
}
@Override // com.huawei.hms.common.internal.BaseHmsClient.ConnectionCallbacks
public void onConnectionSuspended(int i) {
HMSLog.i("HuaweiApi", "onConnectionSuspended");
BindResolveClients.getInstance().unRegister(this.e);
this.e = null;
RequestManager.getHandler().post(new Runnable(this) { // from class: com.huawei.hms.common.HuaweiApi.RequestHandler.5
final RequestHandler a;
{
this.a = this;
}
@Override // java.lang.Runnable
public void run() {
this.a.c();
}
});
}
public void postMessage(TaskApiCallbackWrapper taskApiCallbackWrapper) {
RequestManager.addToConnectedReqMap(taskApiCallbackWrapper.a().getTaskApiCall().getTransactionId(), this);
this.a.add(taskApiCallbackWrapper);
String uri = taskApiCallbackWrapper.a().getTaskApiCall().getUri();
String packageName = (((HuaweiApi) this.d).c == null ? this.d.getContext() : ((HuaweiApi) this.d).c).getPackageName();
if (((HuaweiApi) this.d).c != null) {
HuaweiApi<OptionsT> huaweiApi = this.d;
huaweiApi.b(((HuaweiApi) huaweiApi).c);
}
RequestHeader requestHeader = new RequestHeader();
requestHeader.setSrvName(uri.split("\\.")[0]);
requestHeader.setApiName(uri);
StringBuilder sb = new StringBuilder();
sb.append(this.d.getAppID());
sb.append(HiAnalyticsConstant.REPORT_VAL_SEPARATOR);
sb.append(this.d.getSubAppID());
requestHeader.setAppID(sb.toString());
requestHeader.setPkgName(packageName);
requestHeader.setSessionId(this.b.getSessionId());
TaskApiCall taskApiCall = taskApiCallbackWrapper.a().getTaskApiCall();
requestHeader.setTransactionId(a(taskApiCall.getTransactionId(), uri));
requestHeader.setParcelable(taskApiCall.getParcelable());
requestHeader.setKitSdkVersion(this.d.getKitSdkVersion());
requestHeader.setApiLevel(Math.max(this.d.getApiLevel(), taskApiCall.getApiLevel()));
this.b.post(requestHeader, taskApiCall.getRequestJson(), new AnonymousClass2(this, taskApiCallbackWrapper, requestHeader));
}
private TaskApiCallbackWrapper b(TaskApiCallWrapper taskApiCallWrapper) {
return new TaskApiCallbackWrapper(taskApiCallWrapper, new AnyClient.CallBack(this, taskApiCallWrapper) { // from class: com.huawei.hms.common.HuaweiApi.RequestHandler.1
private AtomicBoolean a = new AtomicBoolean(true);
final TaskApiCallWrapper b;
final RequestHandler c;
{
this.c = this;
this.b = taskApiCallWrapper;
}
@Override // com.huawei.hms.common.internal.AnyClient.CallBack
public void onCallback(IMessageEntity iMessageEntity, String str) {
if (!(iMessageEntity instanceof ResponseHeader)) {
HMSLog.e("HuaweiApi", "header is not instance of ResponseHeader");
return;
}
ResponseHeader responseHeader = (ResponseHeader) iMessageEntity;
if (responseHeader.getErrorCode() == 11) {
this.c.a();
HMSLog.i("HuaweiApi", "unbind service");
}
if (!TextUtils.isEmpty(responseHeader.getResolution())) {
StringBuilder sb = new StringBuilder("Response has resolution: ");
sb.append(responseHeader.getResolution());
HMSLog.e("HuaweiApi", sb.toString());
}
if (this.a.compareAndSet(true, false)) {
HiAnalyticsInnerClient.reportEntryExit(this.c.d.getContext(), responseHeader, String.valueOf(this.c.d.getKitSdkVersion()));
}
this.b.getTaskApiCall().onResponse(this.c.b, responseHeader, str, this.b.getTaskCompletionSource());
}
});
}
/* JADX INFO: Access modifiers changed from: private */
public void c() {
StringBuilder sb = new StringBuilder("wait queue size = ");
sb.append(this.callbackWaitQueue.size());
HMSLog.i("HuaweiApi", sb.toString());
StringBuilder sb2 = new StringBuilder("run queue size = ");
sb2.append(this.a.size());
HMSLog.i("HuaweiApi", sb2.toString());
Iterator<TaskApiCallbackWrapper> it = this.callbackWaitQueue.iterator();
while (it.hasNext()) {
a(it.next());
}
Iterator<TaskApiCallbackWrapper> it2 = this.a.iterator();
while (it2.hasNext()) {
a(it2.next());
}
this.callbackWaitQueue.clear();
this.a.clear();
this.c = null;
this.b.disconnect();
}
void a(TaskApiCallWrapper taskApiCallWrapper) {
HMSLog.i("HuaweiApi", "sendRequest");
TaskApiCallbackWrapper b = b(taskApiCallWrapper);
if (HMSPackageManager.getInstance(this.d.getContext()).isUpdateHmsForThirdPartyDevice()) {
this.b.disconnect();
}
int hmsVersionCode = HMSPackageManager.getInstance(((HuaweiApi) this.d).a).getHmsVersionCode();
if (hmsVersionCode < 40000000 && hmsVersionCode > 0 && this.b.isConnected() && !((HuaweiApi) this.d).m && ((BaseHmsClient) this.b).getAdapter().getServiceAction().equals("com.huawei.hms.core.aidlservice")) {
int requestHmsVersionCode = this.b.getRequestHmsVersionCode();
if (requestHmsVersionCode <= taskApiCallWrapper.getTaskApiCall().getMinApkVersion()) {
requestHmsVersionCode = taskApiCallWrapper.getTaskApiCall().getMinApkVersion();
}
if (requestHmsVersionCode > hmsVersionCode) {
this.b.disconnect();
}
}
if (this.b.isConnected()) {
HMSLog.i("HuaweiApi", "isConnected:true.");
BinderAdapter adapter = ((BaseHmsClient) this.b).getAdapter();
adapter.updateDelayTask();
((HmsClient) this.b).setService(IAIDLInvoke.Stub.asInterface(adapter.getServiceBinder()));
postMessage(b);
return;
}
HMSLog.i("HuaweiApi", "isConnected:false.");
this.callbackWaitQueue.add(b);
ConnectionResult connectionResult = this.c;
if (connectionResult != null && connectionResult.getErrorCode() != 0) {
StringBuilder sb = new StringBuilder("onConnectionFailed, ErrorCode:");
sb.append(this.c.getErrorCode());
HMSLog.i("HuaweiApi", sb.toString());
onConnectionFailed(this.c);
return;
}
RequestManager.addRequestToQueue(this);
Object obj = this.b;
if (obj instanceof BaseHmsClient) {
((BaseHmsClient) obj).setInternalRequest(this);
}
a(taskApiCallWrapper.getTaskApiCall().getMinApkVersion(), b);
}
/* JADX INFO: Access modifiers changed from: private */
public void b(ConnectionResult connectionResult) {
this.c = connectionResult;
Iterator<TaskApiCallbackWrapper> it = this.callbackWaitQueue.iterator();
boolean z = true;
while (it.hasNext()) {
TaskApiCallWrapper a = it.next().a();
StringBuilder sb = new StringBuilder("Connection Failed:");
sb.append(a(connectionResult));
sb.append("(");
sb.append(connectionResult.getErrorCode());
sb.append(")");
ResponseHeader responseHeader = new ResponseHeader(1, CommonCode.ErrorCode.CLIENT_API_INVALID, sb.toString());
responseHeader.setTransactionId(a.getTaskApiCall().getTransactionId());
HiAnalyticsInnerClient.reportEntryExit(this.d.getContext(), responseHeader, String.valueOf(this.d.getKitSdkVersion()));
if (this.c.getResolution() != null && z) {
responseHeader.setParcelable(this.c.getResolution());
if (Util.isAvailableLibExist(this.d.getContext()) && this.c.getErrorCode() == 26) {
responseHeader.setResolution(CommonCode.Resolution.HAS_RESOLUTION);
}
z = false;
}
int errorCode = this.c.getErrorCode();
if (errorCode == 30 || errorCode == 31) {
responseHeader.setErrorCode(errorCode);
}
a.getTaskApiCall().onResponse(this.b, responseHeader, null, a.getTaskCompletionSource());
}
this.callbackWaitQueue.clear();
this.a.clear();
this.c = null;
this.b.disconnect();
}
/* JADX INFO: Access modifiers changed from: private */
public void b() {
this.c = null;
this.a.clear();
Iterator<TaskApiCallbackWrapper> it = this.callbackWaitQueue.iterator();
while (it.hasNext()) {
postMessage(it.next());
}
this.callbackWaitQueue.clear();
}
private String a(String str, String str2) {
return TextUtils.isEmpty(str) ? TransactionIdCreater.getId(this.d.getAppID(), str2) : str;
}
void a(int i, TaskApiCallbackWrapper taskApiCallbackWrapper) {
synchronized (this) {
if (this.b.isConnected()) {
HMSLog.d("HuaweiApi", "client is connected");
return;
}
if (this.b.isConnecting()) {
HMSLog.d("HuaweiApi", "client is isConnecting");
return;
}
if (this.d.getActivity() != null) {
if (this.e == null) {
this.e = new ResolveClientBean(this.b, i);
}
if (BindResolveClients.getInstance().isClientRegistered(this.e)) {
HMSLog.i("HuaweiApi", "mResolveClientBean has already register, return!");
return;
}
BindResolveClients.getInstance().register(this.e);
}
this.b.connect(i);
}
}
void a() {
this.b.disconnect();
}
private void a(TaskApiCallbackWrapper taskApiCallbackWrapper) {
TaskApiCallWrapper a = taskApiCallbackWrapper.a();
ResponseHeader responseHeader = new ResponseHeader(1, CommonCode.ErrorCode.CLIENT_API_INVALID, "Connection Suspended");
responseHeader.setTransactionId(a.getTaskApiCall().getTransactionId());
a.getTaskApiCall().onResponse(this.b, responseHeader, null, a.getTaskCompletionSource());
}
/* JADX WARN: Removed duplicated region for block: B:18:0x0046 A[RETURN, SYNTHETIC] */
/*
Code decompiled incorrectly, please refer to instructions dump.
To view partially-correct add '--show-bad-code' argument
*/
private java.lang.String a(com.huawei.hms.api.ConnectionResult r5) {
/*
r4 = this;
com.huawei.hms.common.HuaweiApi<OptionsT extends com.huawei.hms.api.Api$ApiOptions> r0 = r4.d
android.content.Context r0 = r0.getContext()
boolean r0 = com.huawei.hms.utils.Util.isAvailableLibExist(r0)
r1 = 10
r2 = 8
r3 = -1
if (r0 == 0) goto L3c
int r5 = r5.getErrorCode()
if (r5 == r3) goto L4f
r0 = 3
if (r5 == r0) goto L39
if (r5 == r2) goto L4c
if (r5 == r1) goto L49
r0 = 13
if (r5 == r0) goto L36
r0 = 21
if (r5 == r0) goto L33
switch(r5) {
case 25: goto L30;
case 26: goto L2d;
case 27: goto L2a;
default: goto L29;
}
L29:
goto L46
L2a:
java.lang.String r5 = "there is already an update popup at the front desk, but it hasn't been clicked or it is not effective for a while"
goto L51
L2d:
java.lang.String r5 = "update failed, because no activity incoming, can't pop update page"
goto L51
L30:
java.lang.String r5 = "failed to get update result"
goto L51
L33:
java.lang.String r5 = "device is too old to be support"
goto L51
L36:
java.lang.String r5 = "update cancelled"
goto L51
L39:
java.lang.String r5 = "HuaWei Mobile Service is disabled"
goto L51
L3c:
int r5 = r5.getErrorCode()
if (r5 == r3) goto L4f
if (r5 == r2) goto L4c
if (r5 == r1) goto L49
L46:
java.lang.String r5 = "unknown errorReason"
goto L51
L49:
java.lang.String r5 = "application configuration error, please developer check configuration"
goto L51
L4c:
java.lang.String r5 = "internal error"
goto L51
L4f:
java.lang.String r5 = "get update result, but has other error codes"
L51:
return r5
*/
throw new UnsupportedOperationException("Method not decompiled: com.huawei.hms.common.HuaweiApi.RequestHandler.a(com.huawei.hms.api.ConnectionResult):java.lang.String");
}
public AnyClient getClient() {
return this.b;
}
}
/* JADX INFO: Access modifiers changed from: package-private */
/* loaded from: classes2.dex */
public static class a<OptionsT extends Api.ApiOptions> implements Runnable {
private final HuaweiApi<OptionsT> a;
private final TaskApiCallWrapper b;
public a(HuaweiApi<OptionsT> huaweiApi, TaskApiCallWrapper taskApiCallWrapper) {
this.a = huaweiApi;
this.b = taskApiCallWrapper;
}
/* JADX WARN: Removed duplicated region for block: B:14:0x0055 A[ADDED_TO_REGION] */
/*
Code decompiled incorrectly, please refer to instructions dump.
To view partially-correct add '--show-bad-code' argument
*/
private void a(com.huawei.hms.common.HuaweiApi.RequestHandler r8, java.lang.Throwable r9) {
/*
r7 = this;
java.lang.String r0 = "HuaweiApi"
r1 = 0
com.huawei.hms.common.internal.AnyClient r8 = r8.getClient() // Catch: java.lang.Throwable -> L38
com.huawei.hms.common.internal.ResponseHeader r2 = new com.huawei.hms.common.internal.ResponseHeader // Catch: java.lang.Throwable -> L35
java.lang.String r9 = r9.getMessage() // Catch: java.lang.Throwable -> L35
r3 = 1
r4 = 907135001(0x3611c819, float:2.1723156E-6)
r2.<init>(r3, r4, r9) // Catch: java.lang.Throwable -> L35
org.json.JSONObject r9 = new org.json.JSONObject // Catch: java.lang.Throwable -> L30
r9.<init>() // Catch: java.lang.Throwable -> L30
java.lang.String r9 = r9.toString() // Catch: java.lang.Throwable -> L30
com.huawei.hms.common.internal.TaskApiCallWrapper r3 = r7.b // Catch: java.lang.Throwable -> L2c
o.nNj r3 = r3.getTaskCompletionSource() // Catch: java.lang.Throwable -> L2c
com.huawei.hms.common.internal.TaskApiCallWrapper r4 = r7.b // Catch: java.lang.Throwable -> L2a
com.huawei.hms.common.internal.TaskApiCall r1 = r4.getTaskApiCall() // Catch: java.lang.Throwable -> L2a
goto L53
L2a:
r4 = move-exception
goto L3e
L2c:
r3 = move-exception
r4 = r3
r3 = r1
goto L3e
L30:
r9 = move-exception
r4 = r9
r9 = r1
r3 = r9
goto L3e
L35:
r9 = move-exception
r4 = r9
goto L3b
L38:
r8 = move-exception
r4 = r8
r8 = r1
L3b:
r9 = r1
r2 = r9
r3 = r2
L3e:
java.lang.StringBuilder r5 = new java.lang.StringBuilder
java.lang.String r6 = "<notifyCpException> "
r5.<init>(r6)
java.lang.String r4 = r4.getMessage()
r5.append(r4)
java.lang.String r4 = r5.toString()
com.huawei.hms.support.log.HMSLog.e(r0, r4)
L53:
if (r8 == 0) goto L61
if (r2 == 0) goto L61
if (r9 == 0) goto L61
if (r3 == 0) goto L61
if (r1 == 0) goto L61
r1.onResponse(r8, r2, r9, r3)
return
L61:
java.lang.String r8 = "<notifyCpException> isNotify is false, Can not notify CP."
com.huawei.hms.support.log.HMSLog.e(r0, r8)
return
*/
throw new UnsupportedOperationException("Method not decompiled: com.huawei.hms.common.HuaweiApi.a.a(com.huawei.hms.common.HuaweiApi$RequestHandler, java.lang.Throwable):void");
}
@Override // java.lang.Runnable
public void run() {
RequestHandler requestHandler = new RequestHandler(this.a);
try {
requestHandler.a(this.b);
} catch (Throwable th) {
a(requestHandler, th);
}
}
}
public HuaweiApi(Activity activity, Api<TOption> api, TOption toption, AbstractClientBuilder abstractClientBuilder, int i) {
Checker.checkNonNull(activity, "Null activity is not permitted.");
this.h = new WeakReference<>(activity);
a(activity, api, toption, abstractClientBuilder, i, null);
}
@Deprecated
public HiE<Boolean> disconnectService() {
nNj nnj = new nNj();
RequestManager.getInstance();
RequestManager.getHandler().post(new Runnable(this, this, nnj) { // from class: com.huawei.hms.common.HuaweiApi.1
final HuaweiApi a;
final nNj b;
final HuaweiApi c;
{
this.c = this;
this.a = this;
this.b = nnj;
}
@Override // java.lang.Runnable
public void run() {
this.c.a((HuaweiApi<?>) this.a, (nNj<Boolean>) this.b);
}
});
return nnj.b;
}
/* JADX WARN: Type inference failed for: r3v2, types: [com.huawei.hms.common.internal.AnyClient] */
public AnyClient getClient(Looper looper, RequestHandler requestHandler) {
return this.d.buildClient(this.a, getClientSetting(), requestHandler, requestHandler);
}
protected ClientSettings getClientSetting() {
ClientSettings clientSettings = new ClientSettings(this.a.getPackageName(), this.a.getClass().getName(), getScopes(), this.e, null, this.g);
if (!this.m) {
String hMSPackageNameForMultiService = HMSPackageManager.getInstance(this.a).getHMSPackageNameForMultiService();
if (TextUtils.isEmpty(hMSPackageNameForMultiService)) {
hMSPackageNameForMultiService = "com.huawei.hwid";
}
this.l = hMSPackageNameForMultiService;
StringBuilder sb = new StringBuilder("No setInnerHms, hms pkg name is ");
sb.append(this.l);
HMSLog.i("HuaweiApi", sb.toString());
}
clientSettings.setInnerHmsPkg(this.l);
clientSettings.setUseInnerHms(this.m);
WeakReference<Activity> weakReference = this.h;
if (weakReference != null) {
clientSettings.setCpActivity(weakReference.get());
}
return clientSettings;
}
protected List<Scope> getScopes() {
return Collections.emptyList();
}
public String getSubAppID() {
return this.g.getSubAppID();
}
public void setInnerHms() {
this.l = this.a.getPackageName();
this.m = true;
StringBuilder sb = new StringBuilder("<setInnerHms> init inner hms pkg info:");
sb.append(this.l);
HMSLog.i("HuaweiApi", sb.toString());
}
public void setSubAppId(String str) throws ApiException {
if (!setSubAppInfo(new SubAppInfo(str))) {
throw new ApiException(Status.FAILURE);
}
}
@Deprecated
public boolean setSubAppInfo(SubAppInfo subAppInfo) {
HMSLog.i("HuaweiApi", "Enter setSubAppInfo");
SubAppInfo subAppInfo2 = this.g;
if (subAppInfo2 != null && !TextUtils.isEmpty(subAppInfo2.getSubAppID())) {
HMSLog.e("HuaweiApi", "subAppInfo is already set");
return false;
}
if (subAppInfo == null) {
HMSLog.e("HuaweiApi", "subAppInfo is null");
return false;
}
String subAppID = subAppInfo.getSubAppID();
if (TextUtils.isEmpty(subAppID)) {
HMSLog.e("HuaweiApi", "subAppId is empty");
return false;
}
if (subAppID.equals(this.e)) {
HMSLog.e("HuaweiApi", "subAppId is host appid");
return false;
}
if (this.k) {
HMSLog.e("HuaweiApi", "Client has sent request to Huawei Mobile Services, setting subAppId is not allowed");
return false;
}
this.g = new SubAppInfo(subAppInfo);
return true;
}
/* JADX INFO: Access modifiers changed from: private */
public void b(Context context) {
String appId = Util.getAppId(context);
this.e = appId;
this.f = appId;
}
public Activity getActivity() {
WeakReference<Activity> weakReference = this.h;
if (weakReference != null) {
return weakReference.get();
}
return null;
}
public <TResult, TClient extends AnyClient> HiE<TResult> doWrite(TaskApiCall<TClient, TResult> taskApiCall) {
this.k = true;
if (taskApiCall == null) {
HMSLog.e("HuaweiApi", "in doWrite:taskApiCall is null");
nNj nnj = new nNj();
nnj.c(new ApiException(Status.FAILURE));
return nnj.b;
}
HiAnalyticsInnerClient.reportEntryClient(this.a, taskApiCall.getUri(), TextUtils.isEmpty(this.g.getSubAppID()) ? this.f : this.g.getSubAppID(), taskApiCall.getTransactionId(), String.valueOf(getKitSdkVersion()));
if (this.n == null) {
this.n = RequestManager.getInstance();
}
return a(taskApiCall);
}
private void a(Context context, Api<TOption> api, TOption toption, AbstractClientBuilder abstractClientBuilder, int i, String str) {
this.a = context.getApplicationContext();
this.b = toption;
this.d = abstractClientBuilder;
b(context);
this.g = new SubAppInfo("");
this.i = i;
if (!TextUtils.isEmpty(str)) {
if (str.equals(this.e)) {
HMSLog.e("HuaweiApi", "subAppId is host appid");
} else {
HMSLog.i("HuaweiApi", "subAppId is ".concat(String.valueOf(str)));
this.g = new SubAppInfo(str);
}
}
a(context);
if (Util.isAvailableLibExist(context)) {
AvailableUtil.asyncCheckHmsUpdateInfo(context);
}
}
public HuaweiApi(Activity activity, Api<TOption> api, TOption toption, AbstractClientBuilder abstractClientBuilder, int i, String str) {
Checker.checkNonNull(activity, "Null activity is not permitted.");
this.h = new WeakReference<>(activity);
a(activity, api, toption, abstractClientBuilder, i, str);
}
private void a(Context context) {
HMSBIInitializer.getInstance(context).initBI();
}
/* JADX INFO: Access modifiers changed from: private */
public void a(HuaweiApi<?> huaweiApi, nNj<Boolean> nnj) {
HMSLog.i("HuaweiApi", "innerDisconnect.");
try {
huaweiApi.getClient(RequestManager.getHandler().getLooper(), null).disconnect();
nnj.b(Boolean.TRUE);
} catch (Exception e) {
StringBuilder sb = new StringBuilder("disconnect the binder failed for:");
sb.append(e.getMessage());
HMSLog.w("HuaweiApi", sb.toString());
}
}
private <TResult, TClient extends AnyClient> HiE<TResult> a(TaskApiCall<TClient, TResult> taskApiCall) {
nNj nnj;
if (taskApiCall.getToken() == null) {
nnj = new nNj();
} else {
taskApiCall.getToken();
nnj = new nNj((byte) 0);
}
RequestManager.getHandler().post(new a(this, new TaskApiCallWrapper(taskApiCall, nnj)));
return nnj.b;
}
public HuaweiApi(Activity activity, Api<TOption> api, TOption toption, AbstractClientBuilder abstractClientBuilder) {
Checker.checkNonNull(activity, "Null activity is not permitted.");
this.h = new WeakReference<>(activity);
a(activity, api, toption, abstractClientBuilder, 0, null);
}
public HuaweiApi(Context context, Api<TOption> api, TOption toption, AbstractClientBuilder abstractClientBuilder, int i) {
Checker.checkNonNull(context, "Null context is not permitted.");
a(context, api, toption, abstractClientBuilder, i, null);
}
public HuaweiApi(Context context, Api<TOption> api, TOption toption, AbstractClientBuilder abstractClientBuilder, int i, String str) {
Checker.checkNonNull(context, "Null context is not permitted.");
a(context, api, toption, abstractClientBuilder, i, str);
}
public HuaweiApi(Context context, Api<TOption> api, TOption toption, AbstractClientBuilder abstractClientBuilder) {
Checker.checkNonNull(context, "Null context is not permitted.");
a(context, api, toption, abstractClientBuilder, 0, null);
}
public void setKitSdkVersion(int i) {
this.i = i;
}
public void setHostContext(Context context) {
this.c = context;
}
public void setApiLevel(int i) {
this.j = i;
}
public TOption getOption() {
return this.b;
}
public int getKitSdkVersion() {
return this.i;
}
/* loaded from: classes2.dex */
public static class TaskApiCallbackWrapper {
private final TaskApiCallWrapper a;
private final AnyClient.CallBack b;
TaskApiCallbackWrapper(TaskApiCallWrapper taskApiCallWrapper, AnyClient.CallBack callBack) {
this.a = taskApiCallWrapper;
this.b = callBack;
}
AnyClient.CallBack b() {
return this.b;
}
TaskApiCallWrapper a() {
return this.a;
}
}
public Context getContext() {
return this.a;
}
public String getAppID() {
return this.f;
}
public int getApiLevel() {
return this.j;
}
}