what-the-bank/sources/com/huawei/hms/api/HuaweiApiClientImpl.java

1093 lines
40 KiB
Java
Raw Normal View History

2024-07-27 18:17:47 +07:00
package com.huawei.hms.api;
import android.app.Activity;
import android.app.PendingIntent;
import android.content.ComponentName;
import android.content.Context;
import android.content.Intent;
import android.content.ServiceConnection;
import android.os.Bundle;
import android.os.Handler;
import android.os.IBinder;
import android.os.Looper;
import android.os.Message;
import android.os.RemoteException;
import android.text.TextUtils;
import com.huawei.hms.api.Api;
import com.huawei.hms.api.HuaweiApiClient;
import com.huawei.hms.common.api.ConnectionPostProcessor;
import com.huawei.hms.common.internal.AutoLifecycleFragment;
import com.huawei.hms.core.aidl.CodecLookup;
import com.huawei.hms.core.aidl.DataBuffer;
import com.huawei.hms.core.aidl.IAIDLCallback;
import com.huawei.hms.core.aidl.IAIDLInvoke;
import com.huawei.hms.core.aidl.IMessageEntity;
import com.huawei.hms.core.aidl.MessageCodec;
import com.huawei.hms.core.aidl.RequestHeader;
import com.huawei.hms.core.aidl.ResponseHeader;
import com.huawei.hms.support.api.PendingResultImpl;
import com.huawei.hms.support.api.ResolveResult;
import com.huawei.hms.support.api.client.ApiClient;
import com.huawei.hms.support.api.client.BundleResult;
import com.huawei.hms.support.api.client.InnerApiClient;
import com.huawei.hms.support.api.client.PendingResult;
import com.huawei.hms.support.api.client.ResultCallback;
import com.huawei.hms.support.api.client.Status;
import com.huawei.hms.support.api.client.SubAppInfo;
import com.huawei.hms.support.api.core.ConnectService;
import com.huawei.hms.support.api.entity.auth.PermissionInfo;
import com.huawei.hms.support.api.entity.auth.Scope;
import com.huawei.hms.support.api.entity.core.CheckConnectInfo;
import com.huawei.hms.support.api.entity.core.CommonCode;
import com.huawei.hms.support.api.entity.core.ConnectInfo;
import com.huawei.hms.support.api.entity.core.ConnectResp;
import com.huawei.hms.support.api.entity.core.DisconnectInfo;
import com.huawei.hms.support.api.entity.core.DisconnectResp;
import com.huawei.hms.support.api.entity.core.JosGetNoticeResp;
import com.huawei.hms.support.log.HMSLog;
import com.huawei.hms.utils.Checker;
import com.huawei.hms.utils.HMSPackageManager;
import com.huawei.hms.utils.PackageManagerHelper;
import com.huawei.hms.utils.UIUtil;
import com.huawei.hms.utils.Util;
import java.io.FileDescriptor;
import java.io.PrintWriter;
import java.lang.ref.WeakReference;
import java.lang.reflect.InvocationTargetException;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicInteger;
import java.util.concurrent.locks.Condition;
import java.util.concurrent.locks.ReentrantLock;
@Deprecated
/* loaded from: classes2.dex */
public class HuaweiApiClientImpl extends HuaweiApiClient implements InnerApiClient, ServiceConnection {
private static final Object A = new Object();
private static final Object B = new Object();
public static final String DEFAULT_ACCOUNT = "<<default account>>";
public static final int SIGN_IN_MODE_OPTIONAL = 2;
public static final int SIGN_IN_MODE_REQUIRED = 1;
private final Context b;
private final String c;
private String d;
private String e;
private volatile IAIDLInvoke f;
private String g;
private WeakReference<Activity> h;
private WeakReference<Activity> i;
private List<Scope> l;
private List<PermissionInfo> m;
private Map<Api<?>, Api.ApiOptions> n;
/* renamed from: o, reason: collision with root package name */
private SubAppInfo f6492o;
private final ReentrantLock s;
private final Condition t;
private ConnectionResult u;
private HuaweiApiClient.ConnectionCallbacks v;
private HuaweiApiClient.OnConnectionFailedListener w;
private Handler x;
private Handler y;
private CheckUpdatelistener z;
private int a = -1;
private boolean j = false;
private AtomicInteger k = new AtomicInteger(1);
private long p = 0;
private int q = 0;
private final Object r = new Object();
/* JADX INFO: Access modifiers changed from: package-private */
/* loaded from: classes2.dex */
public class a implements Handler.Callback {
final HuaweiApiClientImpl a;
a(HuaweiApiClientImpl huaweiApiClientImpl) {
this.a = huaweiApiClientImpl;
}
@Override // android.os.Handler.Callback
public boolean handleMessage(Message message) {
if (message == null || message.what != 2) {
return false;
}
HMSLog.e("HuaweiApiClientImpl", "In connect, bind core service time out");
if (this.a.k.get() == 5) {
this.a.c(1);
this.a.b();
}
return true;
}
}
/* JADX INFO: Access modifiers changed from: package-private */
/* loaded from: classes2.dex */
public class b implements Handler.Callback {
final HuaweiApiClientImpl a;
b(HuaweiApiClientImpl huaweiApiClientImpl) {
this.a = huaweiApiClientImpl;
}
@Override // android.os.Handler.Callback
public boolean handleMessage(Message message) {
if (message == null || message.what != 3) {
return false;
}
HMSLog.e("HuaweiApiClientImpl", "In connect, process time out");
if (this.a.k.get() == 2) {
this.a.c(1);
this.a.b();
}
return true;
}
}
/* loaded from: classes2.dex */
class c extends IAIDLCallback.Stub {
final ResultCallback a;
final HuaweiApiClientImpl b;
c(HuaweiApiClientImpl huaweiApiClientImpl, ResultCallback resultCallback) {
this.b = huaweiApiClientImpl;
this.a = resultCallback;
}
@Override // com.huawei.hms.core.aidl.IAIDLCallback
public void call(DataBuffer dataBuffer) {
if (dataBuffer != null) {
MessageCodec find = CodecLookup.find(dataBuffer.getProtocol());
ResponseHeader responseHeader = new ResponseHeader();
find.decode(dataBuffer.header, responseHeader);
BundleResult bundleResult = new BundleResult(responseHeader.getStatusCode(), dataBuffer.getBody());
HMSLog.i("HuaweiApiClientImpl", "Exit asyncRequest onResult");
this.a.onResult(bundleResult);
return;
}
HMSLog.i("HuaweiApiClientImpl", "Exit asyncRequest onResult -1");
this.a.onResult(new BundleResult(-1, null));
}
}
/* loaded from: classes2.dex */
static class d extends PendingResultImpl<Status, IMessageEntity> {
public d(ApiClient apiClient, String str, IMessageEntity iMessageEntity) {
super(apiClient, str, iMessageEntity);
}
@Override // com.huawei.hms.support.api.PendingResultImpl
/* renamed from: a, reason: merged with bridge method [inline-methods] */
public Status onComplete(IMessageEntity iMessageEntity) {
return new Status(0);
}
}
/* JADX INFO: Access modifiers changed from: package-private */
/* loaded from: classes2.dex */
public class e implements ResultCallback<ResolveResult<ConnectResp>> {
final HuaweiApiClientImpl a;
/* JADX INFO: Access modifiers changed from: package-private */
/* loaded from: classes2.dex */
public class a implements Runnable {
final ResolveResult a;
final e b;
a(e eVar, ResolveResult resolveResult) {
this.b = eVar;
this.a = resolveResult;
}
@Override // java.lang.Runnable
public void run() {
this.b.a.a((ResolveResult<ConnectResp>) this.a);
}
}
private e(HuaweiApiClientImpl huaweiApiClientImpl) {
this.a = huaweiApiClientImpl;
}
@Override // com.huawei.hms.support.api.client.ResultCallback
/* renamed from: a, reason: merged with bridge method [inline-methods] */
public void onResult(ResolveResult<ConnectResp> resolveResult) {
new Handler(Looper.getMainLooper()).post(new a(this, resolveResult));
}
/* synthetic */ e(HuaweiApiClientImpl huaweiApiClientImpl, a aVar) {
this(huaweiApiClientImpl);
}
}
/* JADX INFO: Access modifiers changed from: package-private */
/* loaded from: classes2.dex */
public class f implements ResultCallback<ResolveResult<DisconnectResp>> {
final HuaweiApiClientImpl a;
/* JADX INFO: Access modifiers changed from: package-private */
/* loaded from: classes2.dex */
public class a implements Runnable {
final ResolveResult a;
final f b;
a(f fVar, ResolveResult resolveResult) {
this.b = fVar;
this.a = resolveResult;
}
@Override // java.lang.Runnable
public void run() {
this.b.a.b((ResolveResult<DisconnectResp>) this.a);
}
}
private f(HuaweiApiClientImpl huaweiApiClientImpl) {
this.a = huaweiApiClientImpl;
}
@Override // com.huawei.hms.support.api.client.ResultCallback
/* renamed from: a, reason: merged with bridge method [inline-methods] */
public void onResult(ResolveResult<DisconnectResp> resolveResult) {
new Handler(Looper.getMainLooper()).post(new a(this, resolveResult));
}
/* synthetic */ f(HuaweiApiClientImpl huaweiApiClientImpl, a aVar) {
this(huaweiApiClientImpl);
}
}
/* JADX INFO: Access modifiers changed from: package-private */
/* loaded from: classes2.dex */
public class g implements ResultCallback<ResolveResult<JosGetNoticeResp>> {
final HuaweiApiClientImpl a;
private g(HuaweiApiClientImpl huaweiApiClientImpl) {
this.a = huaweiApiClientImpl;
}
@Override // com.huawei.hms.support.api.client.ResultCallback
/* renamed from: a, reason: merged with bridge method [inline-methods] */
public void onResult(ResolveResult<JosGetNoticeResp> resolveResult) {
JosGetNoticeResp value;
Intent noticeIntent;
if (resolveResult == null || !resolveResult.getStatus().isSuccess() || (noticeIntent = (value = resolveResult.getValue()).getNoticeIntent()) == null || value.getStatusCode() != 0) {
return;
}
HMSLog.i("HuaweiApiClientImpl", "get notice has intent.");
Activity validActivity = Util.getValidActivity((Activity) this.a.h.get(), this.a.getTopActivity());
if (validActivity != null) {
this.a.j = true;
validActivity.startActivity(noticeIntent);
} else {
HMSLog.e("HuaweiApiClientImpl", "showNotice no valid activity!");
}
}
/* synthetic */ g(HuaweiApiClientImpl huaweiApiClientImpl, a aVar) {
this(huaweiApiClientImpl);
}
}
public HuaweiApiClientImpl(Context context) {
ReentrantLock reentrantLock = new ReentrantLock();
this.s = reentrantLock;
this.t = reentrantLock.newCondition();
this.x = null;
this.y = null;
this.z = null;
this.b = context;
String appId = Util.getAppId(context);
this.c = appId;
this.d = appId;
this.e = Util.getCpId(context);
}
private DisconnectInfo d() {
ArrayList arrayList = new ArrayList();
Map<Api<?>, Api.ApiOptions> map = this.n;
if (map != null) {
Iterator<Api<?>> it = map.keySet().iterator();
while (it.hasNext()) {
arrayList.add(it.next().getApiName());
}
}
return new DisconnectInfo(this.l, arrayList);
}
private int e() {
int hmsVersion = Util.getHmsVersion(this.b);
if (hmsVersion != 0 && hmsVersion >= 20503000) {
return hmsVersion;
}
int f2 = f();
if (g()) {
if (f2 < 20503000) {
return 20503000;
}
return f2;
}
if (f2 < 20600000) {
return 20600000;
}
return f2;
}
private int f() {
Integer num;
int intValue;
Map<Api<?>, Api.ApiOptions> apiMap = getApiMap();
int i = 0;
if (apiMap == null) {
return 0;
}
Iterator<Api<?>> it = apiMap.keySet().iterator();
while (it.hasNext()) {
String apiName = it.next().getApiName();
if (!TextUtils.isEmpty(apiName) && (num = HuaweiApiAvailability.getApiMap().get(apiName)) != null && (intValue = num.intValue()) > i) {
i = intValue;
}
}
return i;
}
private void i() {
synchronized (B) {
Handler handler = this.y;
if (handler != null) {
handler.removeMessages(3);
} else {
this.y = new Handler(Looper.getMainLooper(), new b(this));
}
boolean sendEmptyMessageDelayed = this.y.sendEmptyMessageDelayed(3, 3000L);
StringBuilder sb = new StringBuilder("sendEmptyMessageDelayed for onConnectionResult 3 seconds. the result is : ");
sb.append(sendEmptyMessageDelayed);
HMSLog.d("HuaweiApiClientImpl", sb.toString());
}
}
private void j() {
HMSLog.i("HuaweiApiClientImpl", "Enter sendConnectApiServceRequest.");
ConnectService.connect(this, c()).setResultCallback(new e(this, null));
}
private void k() {
ConnectService.disconnect(this, d()).setResultCallback(new f(this, null));
}
private void l() {
HMSLog.i("HuaweiApiClientImpl", "Enter sendForceConnectApiServceRequest.");
ConnectService.forceConnect(this, c()).setResultCallback(new e(this, null));
}
private void n() {
Util.unBindServiceCatchException(this.b, this);
this.f = null;
}
public int asyncRequest(Bundle bundle, String str, int i, ResultCallback<BundleResult> resultCallback) {
HMSLog.i("HuaweiApiClientImpl", "Enter asyncRequest.");
if (resultCallback != null && str != null && bundle != null) {
if (!innerIsConnected()) {
HMSLog.e("HuaweiApiClientImpl", "client is unConnect.");
return CommonCode.ErrorCode.CLIENT_API_INVALID;
}
DataBuffer dataBuffer = new DataBuffer(str, i);
MessageCodec find = CodecLookup.find(dataBuffer.getProtocol());
dataBuffer.addBody(bundle);
RequestHeader requestHeader = new RequestHeader(getAppID(), getPackageName(), 61100302, getSessionId());
requestHeader.setApiNameList(getApiNameList());
dataBuffer.header = find.encode(requestHeader, new Bundle());
try {
getService().asyncCall(dataBuffer, new c(this, resultCallback));
return 0;
} catch (RemoteException e2) {
StringBuilder sb = new StringBuilder("remote exception:");
sb.append(e2.getMessage());
HMSLog.e("HuaweiApiClientImpl", sb.toString());
return CommonCode.ErrorCode.INTERNAL_ERROR;
}
}
HMSLog.e("HuaweiApiClientImpl", "arguments is invalid.");
return CommonCode.ErrorCode.ARGUMENTS_INVALID;
}
@Override // com.huawei.hms.api.HuaweiApiClient
public void checkUpdate(Activity activity, CheckUpdatelistener checkUpdatelistener) {
if (checkUpdatelistener == null) {
HMSLog.e("HuaweiApiClientImpl", "listener is null!");
return;
}
if (activity != null && !activity.isFinishing()) {
this.z = checkUpdatelistener;
try {
Class<?> cls = Class.forName("com.huawei.hms.update.manager.CheckUpdateLegacy");
cls.getMethod("initCheckUpdateCallBack", Object.class, Activity.class).invoke(cls.getDeclaredConstructor(new Class[0]).newInstance(new Object[0]), this, activity);
return;
} catch (ClassCastException | ClassNotFoundException | IllegalAccessException | IllegalArgumentException | InstantiationException | NoSuchMethodException | InvocationTargetException e2) {
StringBuilder sb = new StringBuilder("invoke CheckUpdateLegacy.initCheckUpdateCallBack fail. ");
sb.append(e2.getMessage());
HMSLog.e("HuaweiApiClientImpl", sb.toString());
checkUpdatelistener.onResult(-1);
return;
}
}
HMSLog.e("HuaweiApiClientImpl", "checkUpdate, activity is illegal: ".concat(String.valueOf(activity)));
checkUpdatelistener.onResult(-1);
}
@Override // com.huawei.hms.api.HuaweiApiClient
public void connect(Activity activity) {
HMSLog.i("HuaweiApiClientImpl", "====== HMSSDK version: 61100302 ======");
int i = this.k.get();
HMSLog.i("HuaweiApiClientImpl", "Enter connect, Connection Status: ".concat(String.valueOf(i)));
if (i == 3 || i == 5 || i == 2 || i == 4) {
return;
}
if (activity != null) {
this.h = new WeakReference<>(activity);
this.i = new WeakReference<>(activity);
}
this.d = TextUtils.isEmpty(this.c) ? Util.getAppId(this.b) : this.c;
int e2 = e();
HMSLog.i("HuaweiApiClientImpl", "connect minVersion:".concat(String.valueOf(e2)));
HuaweiApiAvailability.setServicesVersionCode(e2);
int isHuaweiMobileServicesAvailable = HuaweiMobileServicesUtil.isHuaweiMobileServicesAvailable(this.b, e2);
HMSLog.i("HuaweiApiClientImpl", "In connect, isHuaweiMobileServicesAvailable result: ".concat(String.valueOf(isHuaweiMobileServicesAvailable)));
this.q = HMSPackageManager.getInstance(this.b).getHmsMultiServiceVersion();
if (isHuaweiMobileServicesAvailable != 0) {
if (this.w != null) {
b(isHuaweiMobileServicesAvailable);
return;
}
return;
}
c(5);
if (this.f == null) {
a();
return;
}
c(2);
j();
i();
}
@Override // com.huawei.hms.api.HuaweiApiClient
public void connectForeground() {
HMSLog.i("HuaweiApiClientImpl", "====== HMSSDK version: 61100302 ======");
int i = this.k.get();
HMSLog.i("HuaweiApiClientImpl", "Enter forceConnect, Connection Status: ".concat(String.valueOf(i)));
if (i == 3 || i == 5 || i == 2 || i == 4) {
return;
}
this.d = TextUtils.isEmpty(this.c) ? Util.getAppId(this.b) : this.c;
l();
}
@Override // com.huawei.hms.api.HuaweiApiClient
public PendingResult<Status> discardAndReconnect() {
return new d(this, null, null);
}
@Override // com.huawei.hms.api.HuaweiApiClient
public void disconnect() {
int i = this.k.get();
HMSLog.i("HuaweiApiClientImpl", "Enter disconnect, Connection Status: ".concat(String.valueOf(i)));
if (i != 2) {
if (i == 3) {
c(4);
k();
return;
} else if (i != 5) {
return;
} else {
a(2);
}
}
c(4);
}
@Override // com.huawei.hms.support.api.client.AidlApiClient
public List<String> getApiNameList() {
ArrayList arrayList = new ArrayList();
Map<Api<?>, Api.ApiOptions> map = this.n;
if (map != null) {
Iterator<Api<?>> it = map.keySet().iterator();
while (it.hasNext()) {
arrayList.add(it.next().getApiName());
}
}
return arrayList;
}
@Override // com.huawei.hms.api.HuaweiApiClient
public ConnectionResult getConnectionResult(Api<?> api) {
if (isConnected()) {
this.u = null;
return new ConnectionResult(0, (PendingIntent) null);
}
ConnectionResult connectionResult = this.u;
return connectionResult != null ? connectionResult : new ConnectionResult(13, (PendingIntent) null);
}
@Override // com.huawei.hms.support.api.client.ApiClient
public String getPackageName() {
return this.b.getPackageName();
}
@Override // com.huawei.hms.support.api.client.ApiClient
public String getTransportName() {
return IPCTransport.class.getName();
}
@Override // com.huawei.hms.api.HuaweiApiClient
public boolean hasConnectedApi(Api<?> api) {
return isConnected();
}
@Override // com.huawei.hms.api.HuaweiApiClient
public boolean hasConnectionFailureListener(HuaweiApiClient.OnConnectionFailedListener onConnectionFailedListener) {
Checker.checkNonNull(onConnectionFailedListener, "onConnectionFailedListener should not be null");
synchronized (this.r) {
return this.w == onConnectionFailedListener;
}
}
@Override // com.huawei.hms.api.HuaweiApiClient
public boolean hasConnectionSuccessListener(HuaweiApiClient.ConnectionCallbacks connectionCallbacks) {
Checker.checkNonNull(connectionCallbacks, "connectionCallbacksListener should not be null");
synchronized (this.r) {
return this.v == connectionCallbacks;
}
}
@Override // com.huawei.hms.api.HuaweiApiClient
public ConnectionResult holdUpConnect() {
if (Looper.myLooper() != Looper.getMainLooper()) {
this.s.lock();
try {
connect((Activity) null);
while (isConnecting()) {
this.t.await();
}
if (isConnected()) {
this.u = null;
return new ConnectionResult(0, (PendingIntent) null);
}
ConnectionResult connectionResult = this.u;
return connectionResult != null ? connectionResult : new ConnectionResult(13, (PendingIntent) null);
} catch (InterruptedException unused) {
Thread.currentThread().interrupt();
return new ConnectionResult(15, (PendingIntent) null);
} finally {
this.s.unlock();
}
}
throw new IllegalStateException("blockingConnect must not be called on the UI thread");
}
@Override // com.huawei.hms.support.api.client.InnerApiClient
public boolean innerIsConnected() {
return this.k.get() == 3 || this.k.get() == 4;
}
@Override // com.huawei.hms.api.HuaweiApiClient
public boolean isConnecting() {
int i = this.k.get();
return i == 2 || i == 5;
}
@Override // com.huawei.hms.api.HuaweiApiClient
public void onPause(Activity activity) {
HMSLog.i("HuaweiApiClientImpl", "onPause");
}
public void onResult(int i) {
this.z.onResult(i);
}
@Override // com.huawei.hms.api.HuaweiApiClient
public void onResume(Activity activity) {
if (activity != null) {
HMSLog.i("HuaweiApiClientImpl", "onResume");
this.i = new WeakReference<>(activity);
}
}
@Override // android.content.ServiceConnection
public void onServiceConnected(ComponentName componentName, IBinder iBinder) {
HMSLog.i("HuaweiApiClientImpl", "HuaweiApiClientImpl Enter onServiceConnected.");
a(2);
this.f = IAIDLInvoke.Stub.asInterface(iBinder);
if (this.f == null) {
HMSLog.e("HuaweiApiClientImpl", "In onServiceConnected, mCoreService must not be null.");
n();
c(1);
if (this.w != null) {
WeakReference<Activity> weakReference = this.h;
ConnectionResult connectionResult = new ConnectionResult(10, (weakReference == null || weakReference.get() == null) ? null : HuaweiApiAvailability.getInstance().getResolveErrorPendingIntent(this.h.get(), 10));
this.w.onConnectionFailed(connectionResult);
this.u = connectionResult;
return;
}
return;
}
if (this.k.get() == 5) {
c(2);
j();
i();
} else if (this.k.get() != 3) {
n();
}
}
@Override // android.content.ServiceConnection
public void onServiceDisconnected(ComponentName componentName) {
HMSLog.i("HuaweiApiClientImpl", "Enter onServiceDisconnected.");
this.f = null;
c(1);
HuaweiApiClient.ConnectionCallbacks connectionCallbacks = this.v;
if (connectionCallbacks != null) {
connectionCallbacks.onConnectionSuspended(1);
}
}
@Override // com.huawei.hms.api.HuaweiApiClient
public void print(String str, FileDescriptor fileDescriptor, PrintWriter printWriter, String[] strArr) {
}
@Override // com.huawei.hms.api.HuaweiApiClient
public void reconnect() {
disconnect();
connect((Activity) null);
}
@Override // com.huawei.hms.api.HuaweiApiClient
public void removeConnectionFailureListener(HuaweiApiClient.OnConnectionFailedListener onConnectionFailedListener) {
Checker.checkNonNull(onConnectionFailedListener, "onConnectionFailedListener should not be null");
synchronized (this.r) {
if (this.w != onConnectionFailedListener) {
HMSLog.w("HuaweiApiClientImpl", "unregisterConnectionFailedListener: this onConnectionFailedListener has not been registered");
} else {
this.w = null;
}
}
}
@Override // com.huawei.hms.api.HuaweiApiClient
public void removeConnectionSuccessListener(HuaweiApiClient.ConnectionCallbacks connectionCallbacks) {
Checker.checkNonNull(connectionCallbacks, "connectionCallbacksListener should not be null");
synchronized (this.r) {
if (this.v != connectionCallbacks) {
HMSLog.w("HuaweiApiClientImpl", "unregisterConnectionCallback: this connectionCallbacksListener has not been registered");
} else {
this.v = null;
}
}
}
@Override // com.huawei.hms.api.HuaweiApiClient
public boolean setSubAppInfo(SubAppInfo subAppInfo) {
HMSLog.i("HuaweiApiClientImpl", "Enter setSubAppInfo");
if (subAppInfo == null) {
HMSLog.e("HuaweiApiClientImpl", "subAppInfo is null");
return false;
}
String subAppID = subAppInfo.getSubAppID();
if (TextUtils.isEmpty(subAppID)) {
HMSLog.e("HuaweiApiClientImpl", "subAppId is empty");
return false;
}
if (subAppID.equals(TextUtils.isEmpty(this.c) ? Util.getAppId(this.b) : this.c)) {
HMSLog.e("HuaweiApiClientImpl", "subAppId is host appid");
return false;
}
this.f6492o = new SubAppInfo(subAppInfo);
return true;
}
/* JADX INFO: Access modifiers changed from: private */
public void c(int i) {
this.k.set(i);
if (i == 1 || i == 3 || i == 2) {
this.s.lock();
try {
this.t.signalAll();
} finally {
this.s.unlock();
}
}
}
private boolean g() {
Map<Api<?>, Api.ApiOptions> map = this.n;
if (map == null) {
return false;
}
Iterator<Api<?>> it = map.keySet().iterator();
while (it.hasNext()) {
if (HuaweiApiAvailability.HMS_API_NAME_GAME.equals(it.next().getApiName())) {
return true;
}
}
return false;
}
private void h() {
Handler handler = this.x;
if (handler != null) {
handler.removeMessages(2);
} else {
this.x = new Handler(Looper.getMainLooper(), new a(this));
}
this.x.sendEmptyMessageDelayed(2, 5000L);
}
private void m() {
if (this.j) {
HMSLog.i("HuaweiApiClientImpl", "Connect notice has been shown.");
} else if (HuaweiApiAvailability.getInstance().isHuaweiMobileNoticeAvailable(this.b) == 0) {
ConnectService.getNotice(this, 0, "6.11.0.302").setResultCallback(new g(this, null));
}
}
@Override // com.huawei.hms.api.HuaweiApiClient
public void disableLifeCycleManagement(Activity activity) {
if (this.a >= 0) {
AutoLifecycleFragment.getInstance(activity).stopAutoManage(this.a);
return;
}
throw new IllegalStateException("disableLifeCycleManagement failed");
}
@Override // com.huawei.hms.api.HuaweiApiClient, com.huawei.hms.support.api.client.ApiClient
public boolean isConnected() {
if (this.q == 0) {
this.q = HMSPackageManager.getInstance(this.b).getHmsMultiServiceVersion();
}
if (this.q < 20504000) {
long currentTimeMillis = System.currentTimeMillis() - this.p;
if (currentTimeMillis > 0 && currentTimeMillis < 300000) {
return innerIsConnected();
}
if (!innerIsConnected()) {
return false;
}
Status status = ConnectService.checkconnect(this, new CheckConnectInfo()).awaitOnAnyThread(2000L, TimeUnit.MILLISECONDS).getStatus();
if (status.isSuccess()) {
this.p = System.currentTimeMillis();
return true;
}
int statusCode = status.getStatusCode();
HMSLog.i("HuaweiApiClientImpl", "isConnected is false, statuscode:".concat(String.valueOf(statusCode)));
if (statusCode == 907135004) {
return false;
}
n();
c(1);
this.p = System.currentTimeMillis();
return false;
}
return innerIsConnected();
}
private void b(int i) {
PendingIntent pendingIntent;
WeakReference<Activity> weakReference = this.h;
if (weakReference == null || weakReference.get() == null) {
pendingIntent = null;
} else {
pendingIntent = HuaweiApiAvailability.getInstance().getResolveErrorPendingIntent(this.h.get(), i);
HMSLog.i("HuaweiApiClientImpl", "connect 2.0 fail: ".concat(String.valueOf(i)));
}
ConnectionResult connectionResult = new ConnectionResult(i, pendingIntent);
this.w.onConnectionFailed(connectionResult);
this.u = connectionResult;
}
@Override // com.huawei.hms.api.HuaweiApiClient
public Activity getTopActivity() {
WeakReference<Activity> weakReference = this.i;
if (weakReference == null) {
return null;
}
return weakReference.get();
}
private void a() {
Intent intent = new Intent(HMSPackageManager.getInstance(this.b).getServiceAction());
HMSPackageManager.getInstance(this.b).refreshForMultiService();
try {
String hMSPackageNameForMultiService = HMSPackageManager.getInstance(this.b).getHMSPackageNameForMultiService();
if (TextUtils.isEmpty(hMSPackageNameForMultiService)) {
HMSLog.e("HuaweiApiClientImpl", "servicePackageName is empty, Service is invalid, bind core service fail.");
c(1);
b();
return;
}
intent.setPackage(hMSPackageNameForMultiService);
synchronized (A) {
if (this.b.bindService(intent, this, 1)) {
h();
return;
}
c(1);
HMSLog.e("HuaweiApiClientImpl", "In connect, bind core service fail");
b();
}
} catch (IllegalArgumentException unused) {
HMSLog.e("HuaweiApiClientImpl", "IllegalArgumentException when bindCoreService intent.setPackage");
c(1);
HMSLog.e("HuaweiApiClientImpl", "In connect, bind core service fail");
b();
}
}
private ConnectInfo c() {
String packageSignature = new PackageManagerHelper(this.b).getPackageSignature(this.b.getPackageName());
if (packageSignature == null) {
packageSignature = "";
}
SubAppInfo subAppInfo = this.f6492o;
return new ConnectInfo(getApiNameList(), this.l, packageSignature, subAppInfo == null ? null : subAppInfo.getSubAppID());
}
/* JADX INFO: Access modifiers changed from: private */
public void b() {
n();
if (this.w != null) {
int i = UIUtil.isBackground(this.b) ? 7 : 6;
WeakReference<Activity> weakReference = this.h;
ConnectionResult connectionResult = new ConnectionResult(i, (weakReference == null || weakReference.get() == null) ? null : HuaweiApiAvailability.getInstance().getResolveErrorPendingIntent(this.h.get(), i));
this.w.onConnectionFailed(connectionResult);
this.u = connectionResult;
}
}
private void c(ResolveResult<ConnectResp> resolveResult) {
if (resolveResult.getValue() != null) {
ProtocolNegotiate.getInstance().negotiate(resolveResult.getValue().protocolVersion);
}
c(3);
this.u = null;
HuaweiApiClient.ConnectionCallbacks connectionCallbacks = this.v;
if (connectionCallbacks != null) {
connectionCallbacks.onConnected();
}
if (this.h != null) {
m();
}
for (Map.Entry<Api<?>, Api.ApiOptions> entry : getApiMap().entrySet()) {
if (entry.getKey().getmConnetctPostList() != null && !entry.getKey().getmConnetctPostList().isEmpty()) {
HMSLog.i("HuaweiApiClientImpl", "Enter onConnectionResult, get the ConnetctPostList ");
for (ConnectionPostProcessor connectionPostProcessor : entry.getKey().getmConnetctPostList()) {
HMSLog.i("HuaweiApiClientImpl", "Enter onConnectionResult, processor.run");
connectionPostProcessor.run(this, this.h);
}
}
}
}
/* JADX INFO: Access modifiers changed from: private */
public void b(ResolveResult<DisconnectResp> resolveResult) {
StringBuilder sb = new StringBuilder("Enter onDisconnectionResult, disconnect from server result: ");
sb.append(resolveResult.getStatus().getStatusCode());
HMSLog.i("HuaweiApiClientImpl", sb.toString());
n();
c(1);
}
private void a(int i) {
if (i == 2) {
synchronized (A) {
Handler handler = this.x;
if (handler != null) {
handler.removeMessages(i);
this.x = null;
}
}
}
if (i == 3) {
synchronized (B) {
Handler handler2 = this.y;
if (handler2 != null) {
handler2.removeMessages(i);
this.y = null;
}
}
}
synchronized (A) {
Handler handler3 = this.x;
if (handler3 != null) {
handler3.removeMessages(2);
this.x = null;
}
}
}
@Override // com.huawei.hms.api.HuaweiApiClient
public void connect(int i) {
connect((Activity) null);
}
@Override // com.huawei.hms.api.HuaweiApiClient
public ConnectionResult holdUpConnect(long j, TimeUnit timeUnit) {
if (Looper.myLooper() != Looper.getMainLooper()) {
this.s.lock();
try {
connect((Activity) null);
long nanos = timeUnit.toNanos(j);
while (isConnecting()) {
if (nanos <= 0) {
disconnect();
return new ConnectionResult(14, (PendingIntent) null);
}
nanos = this.t.awaitNanos(nanos);
}
if (isConnected()) {
this.u = null;
return new ConnectionResult(0, (PendingIntent) null);
}
ConnectionResult connectionResult = this.u;
return connectionResult != null ? connectionResult : new ConnectionResult(13, (PendingIntent) null);
} catch (InterruptedException unused) {
Thread.currentThread().interrupt();
return new ConnectionResult(15, (PendingIntent) null);
} finally {
this.s.unlock();
}
}
throw new IllegalStateException("blockingConnect must not be called on the UI thread");
}
/* JADX INFO: Access modifiers changed from: private */
public void a(ResolveResult<ConnectResp> resolveResult) {
HMSLog.i("HuaweiApiClientImpl", "Enter onConnectionResult");
if (this.f != null && this.k.get() == 2) {
a(3);
ConnectResp value = resolveResult.getValue();
if (value != null) {
this.g = value.sessionId;
}
SubAppInfo subAppInfo = this.f6492o;
PendingIntent pendingIntent = null;
String subAppID = subAppInfo == null ? null : subAppInfo.getSubAppID();
if (!TextUtils.isEmpty(subAppID)) {
this.d = subAppID;
}
int statusCode = resolveResult.getStatus().getStatusCode();
HMSLog.i("HuaweiApiClientImpl", "Enter onConnectionResult, connect to server result: ".concat(String.valueOf(statusCode)));
if (Status.SUCCESS.equals(resolveResult.getStatus())) {
c(resolveResult);
return;
}
if (resolveResult.getStatus() != null && resolveResult.getStatus().getStatusCode() == 1001) {
n();
c(1);
HuaweiApiClient.ConnectionCallbacks connectionCallbacks = this.v;
if (connectionCallbacks != null) {
connectionCallbacks.onConnectionSuspended(3);
return;
}
return;
}
n();
c(1);
if (this.w != null) {
WeakReference<Activity> weakReference = this.h;
if (weakReference != null && weakReference.get() != null) {
pendingIntent = HuaweiApiAvailability.getInstance().getResolveErrorPendingIntent(this.h.get(), statusCode);
}
ConnectionResult connectionResult = new ConnectionResult(statusCode, pendingIntent);
this.w.onConnectionFailed(connectionResult);
this.u = connectionResult;
return;
}
return;
}
HMSLog.e("HuaweiApiClientImpl", "Invalid onConnectionResult");
}
public void setScopes(List<Scope> list) {
this.l = list;
}
public void setPermissionInfos(List<PermissionInfo> list) {
this.m = list;
}
public void setHasShowNotice(boolean z) {
this.j = z;
}
@Override // com.huawei.hms.api.HuaweiApiClient
public void setConnectionFailedListener(HuaweiApiClient.OnConnectionFailedListener onConnectionFailedListener) {
this.w = onConnectionFailedListener;
}
@Override // com.huawei.hms.api.HuaweiApiClient
public void setConnectionCallbacks(HuaweiApiClient.ConnectionCallbacks connectionCallbacks) {
this.v = connectionCallbacks;
}
/* JADX INFO: Access modifiers changed from: protected */
public void setAutoLifecycleClientId(int i) {
this.a = i;
}
public void setApiMap(Map<Api<?>, Api.ApiOptions> map) {
this.n = map;
}
public void resetListener() {
this.z = null;
}
@Override // com.huawei.hms.support.api.client.ApiClient
public final SubAppInfo getSubAppInfo() {
return this.f6492o;
}
@Override // com.huawei.hms.support.api.client.ApiClient
public String getSessionId() {
return this.g;
}
@Override // com.huawei.hms.support.api.client.AidlApiClient
public IAIDLInvoke getService() {
return this.f;
}
@Override // com.huawei.hms.api.HuaweiApiClient
public List<Scope> getScopes() {
return this.l;
}
@Override // com.huawei.hms.api.HuaweiApiClient
public List<PermissionInfo> getPermissionInfos() {
return this.m;
}
@Override // com.huawei.hms.support.api.client.ApiClient
public String getCpID() {
return this.e;
}
@Override // com.huawei.hms.support.api.client.ApiClient
public Context getContext() {
return this.b;
}
@Override // com.huawei.hms.support.api.client.ApiClient
public String getAppID() {
return this.d;
}
@Override // com.huawei.hms.api.HuaweiApiClient
public Map<Api<?>, Api.ApiOptions> getApiMap() {
return this.n;
}
}