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

570 lines
21 KiB
Java

package com.huawei.hms.common.internal;
import android.app.Activity;
import android.app.PendingIntent;
import android.content.ComponentName;
import android.content.Context;
import android.content.Intent;
import android.os.Handler;
import android.os.IBinder;
import android.os.Message;
import com.google.android.gms.internal.common.zzd;
import com.huawei.hms.adapter.AvailableAdapter;
import com.huawei.hms.adapter.BinderAdapter;
import com.huawei.hms.adapter.InnerBinderAdapter;
import com.huawei.hms.adapter.OuterBinderAdapter;
import com.huawei.hms.api.ConnectionResult;
import com.huawei.hms.api.FailedBinderCallBack;
import com.huawei.hms.api.HuaweiApiAvailability;
import com.huawei.hms.api.IPCTransport;
import com.huawei.hms.common.HuaweiApi;
import com.huawei.hms.core.aidl.IAIDLInvoke;
import com.huawei.hms.support.api.client.AidlApiClient;
import com.huawei.hms.support.api.client.SubAppInfo;
import com.huawei.hms.support.log.HMSLog;
import com.huawei.hms.utils.HMSPackageManager;
import com.huawei.hms.utils.PackageManagerHelper;
import com.huawei.hms.utils.Util;
import java.sql.Timestamp;
import java.util.List;
import java.util.concurrent.atomic.AtomicInteger;
/* loaded from: classes2.dex */
public abstract class BaseHmsClient implements AidlApiClient {
protected static final int TIMEOUT_DISCONNECTED = 6;
private static final Object i = new Object();
private static final AtomicInteger j = new AtomicInteger(1);
private static final AtomicInteger k = new AtomicInteger(1);
private static BinderAdapter l;
private static BinderAdapter m;
private final Context a;
private String b;
private final ClientSettings c;
private volatile IAIDLInvoke d;
private final ConnectionCallbacks e;
private final OnConnectionFailedListener f;
private Handler g = null;
private HuaweiApi.RequestHandler h;
protected String sessionId;
/* JADX INFO: Access modifiers changed from: package-private */
/* renamed from: com.huawei.hms.common.internal.BaseHmsClient$1, reason: invalid class name */
/* loaded from: classes2.dex */
public class AnonymousClass1 implements BinderAdapter.BinderCallBack {
final BaseHmsClient a;
AnonymousClass1(BaseHmsClient baseHmsClient) {
this.a = baseHmsClient;
}
@Override // com.huawei.hms.adapter.BinderAdapter.BinderCallBack
public void onBinderFailed(int i) {
onBinderFailed(i, null);
}
@Override // com.huawei.hms.adapter.BinderAdapter.BinderCallBack
public void onNullBinding(ComponentName componentName) {
this.a.b(1);
this.a.a(10);
}
@Override // com.huawei.hms.adapter.BinderAdapter.BinderCallBack
public void onServiceConnected(ComponentName componentName, IBinder iBinder) {
HMSLog.i("BaseHmsClient", "Enter onServiceConnected.");
this.a.connectedInternal(iBinder);
}
@Override // com.huawei.hms.adapter.BinderAdapter.BinderCallBack
public void onServiceDisconnected(ComponentName componentName) {
HMSLog.i("BaseHmsClient", "Enter onServiceDisconnected.");
this.a.b(1);
RequestManager.getHandler().sendEmptyMessage(RequestManager.NOTIFY_CONNECT_SUSPENDED);
if (this.a.e == null || (this.a.e instanceof HuaweiApi.RequestHandler)) {
return;
}
this.a.e.onConnectionSuspended(1);
}
@Override // com.huawei.hms.adapter.BinderAdapter.BinderCallBack
public void onTimedDisconnected() {
this.a.b(6);
if (this.a.e == null || (this.a.e instanceof HuaweiApi.RequestHandler)) {
return;
}
this.a.e.onConnectionSuspended(1);
}
@Override // com.huawei.hms.adapter.BinderAdapter.BinderCallBack
public void onBinderFailed(int i, Intent intent) {
if (intent != null) {
Activity activeActivity = Util.getActiveActivity(this.a.getClientSettings().getCpActivity(), this.a.getContext());
if (activeActivity != null) {
HMSLog.i("BaseHmsClient", "onBinderFailed: SDK try to resolve and reConnect!");
long time = new Timestamp(System.currentTimeMillis()).getTime();
FailedBinderCallBack.getInstance().setCallBack(Long.valueOf(time), new FailedBinderCallBack.BinderCallBack(this) { // from class: com.huawei.hms.common.internal.BaseHmsClient.1.1
final AnonymousClass1 a;
{
this.a = this;
}
@Override // com.huawei.hms.api.FailedBinderCallBack.BinderCallBack
public void binderCallBack(int i2) {
if (i2 != 0) {
this.a.a.a(new ConnectionResult(10, (PendingIntent) null));
this.a.a.d = null;
}
}
});
intent.putExtra(FailedBinderCallBack.CALLER_ID, time);
activeActivity.startActivity(intent);
return;
}
HMSLog.i("BaseHmsClient", "onBinderFailed: return pendingIntent to kit and cp");
this.a.a(new ConnectionResult(10, PendingIntent.getActivity(this.a.a, 11, intent, zzd.zza)));
this.a.d = null;
return;
}
HMSLog.i("BaseHmsClient", "onBinderFailed: intent is null!");
this.a.a(new ConnectionResult(10, (PendingIntent) null));
this.a.d = null;
}
}
/* loaded from: classes2.dex */
public interface ConnectionCallbacks {
public static final int CAUSE_API_CLIENT_EXPIRED = 3;
public static final int CAUSE_NETWORK_LOST = 2;
public static final int CAUSE_SERVICE_DISCONNECTED = 1;
void onConnected();
void onConnectionSuspended(int i);
}
/* loaded from: classes2.dex */
public interface OnConnectionFailedListener {
void onConnectionFailed(ConnectionResult connectionResult);
}
public BaseHmsClient(Context context, ClientSettings clientSettings, OnConnectionFailedListener onConnectionFailedListener, ConnectionCallbacks connectionCallbacks) {
this.a = context;
this.c = clientSettings;
if (clientSettings != null) {
this.b = clientSettings.getAppID();
}
this.f = onConnectionFailedListener;
this.e = connectionCallbacks;
}
private BinderAdapter.BinderCallBack d() {
return new AnonymousClass1(this);
}
private void e() {
HMSLog.w("BaseHmsClient", "Failed to get service as interface, trying to unbind.");
if (this.c.isUseInnerHms()) {
BinderAdapter binderAdapter = m;
if (binderAdapter == null) {
HMSLog.w("BaseHmsClient", "mInnerBinderAdapter is null.");
return;
}
binderAdapter.unBind();
} else {
BinderAdapter binderAdapter2 = l;
if (binderAdapter2 == null) {
HMSLog.w("BaseHmsClient", "mOuterBinderAdapter is null.");
return;
}
binderAdapter2.unBind();
}
b(1);
a(10);
}
private void f() {
if (this.c.isUseInnerHms()) {
BinderAdapter binderAdapter = m;
if (binderAdapter != null) {
binderAdapter.unBind();
return;
}
return;
}
BinderAdapter binderAdapter2 = l;
if (binderAdapter2 != null) {
binderAdapter2.unBind();
}
}
protected final void checkConnected() {
if (!isConnected()) {
throw new IllegalStateException("Not connected. Call connect() and wait for onConnected() to be called.");
}
}
public void connect(int i2) {
a(i2, false);
}
public void connectedInternal(IBinder iBinder) {
this.d = IAIDLInvoke.Stub.asInterface(iBinder);
if (this.d == null) {
HMSLog.e("BaseHmsClient", "mService is null, try to unBind.");
e();
} else {
onConnecting();
}
}
protected final void connectionConnected() {
b(3);
RequestManager.getHandler().sendEmptyMessage(RequestManager.NOTIFY_CONNECT_SUCCESS);
ConnectionCallbacks connectionCallbacks = this.e;
if (connectionCallbacks == null || (connectionCallbacks instanceof HuaweiApi.RequestHandler)) {
return;
}
connectionCallbacks.onConnected();
}
public void disconnect() {
int i2 = (this.c.isUseInnerHms() ? k : j).get();
HMSLog.i("BaseHmsClient", "Enter disconnect, Connection Status: ".concat(String.valueOf(i2)));
if (i2 == 3) {
f();
b(1);
} else if (i2 == 5) {
b();
b(1);
}
}
public BinderAdapter getAdapter() {
StringBuilder sb = new StringBuilder("getAdapter:isInner:");
sb.append(this.c.isUseInnerHms());
sb.append(", mInnerBinderAdapter:");
sb.append(m);
sb.append(", mOuterBinderAdapter:");
sb.append(l);
HMSLog.i("BaseHmsClient", sb.toString());
return this.c.isUseInnerHms() ? m : l;
}
@Override // com.huawei.hms.support.api.client.AidlApiClient
public List<String> getApiNameList() {
return this.c.getApiName();
}
public int getConnectionStatus() {
return (this.c.isUseInnerHms() ? k : j).get();
}
@Override // com.huawei.hms.support.api.client.ApiClient
public String getCpID() {
return this.c.getCpID();
}
@Deprecated
public int getMinApkVersion() {
return 30000000;
}
@Override // com.huawei.hms.support.api.client.ApiClient
public String getPackageName() {
return this.c.getClientPackageName();
}
public int getRequestHmsVersionCode() {
return getMinApkVersion();
}
public String getServiceAction() {
HMSPackageManager hMSPackageManager = HMSPackageManager.getInstance(this.a);
if (this.c.isUseInnerHms()) {
return hMSPackageManager.getInnerServiceAction();
}
return hMSPackageManager.getServiceAction();
}
@Override // com.huawei.hms.support.api.client.ApiClient
public SubAppInfo getSubAppInfo() {
return this.c.getSubAppID();
}
@Override // com.huawei.hms.support.api.client.ApiClient
public String getTransportName() {
return IPCTransport.class.getName();
}
@Override // com.huawei.hms.support.api.client.ApiClient
public boolean isConnected() {
return !this.c.isUseInnerHms() ? j.get() != 3 : k.get() != 3;
}
public boolean isConnecting() {
return (this.c.isUseInnerHms() ? k : j).get() == 5;
}
public void onConnecting() {
connectionConnected();
}
/* JADX INFO: Access modifiers changed from: private */
public boolean c() {
return HMSPackageManager.getInstance(this.a).getHMSPackageStatesForMultiService() == PackageManagerHelper.PackageStates.ENABLED;
}
void b(int i2) {
if (this.c.isUseInnerHms()) {
k.set(i2);
} else {
j.set(i2);
}
}
public void connect(int i2, boolean z) {
a(i2, z);
}
/* JADX INFO: Access modifiers changed from: package-private */
public void a() {
String innerHmsPkg = this.c.getInnerHmsPkg();
String serviceAction = getServiceAction();
StringBuilder sb = new StringBuilder("enter bindCoreService, packageName is ");
sb.append(innerHmsPkg);
sb.append(", serviceAction is ");
sb.append(serviceAction);
HMSLog.i("BaseHmsClient", sb.toString());
a(innerHmsPkg, serviceAction);
}
private void b() {
synchronized (i) {
Handler handler = this.g;
if (handler != null) {
handler.removeMessages(2);
this.g = null;
}
}
}
private void a(String str, String str2) {
if (this.c.isUseInnerHms()) {
m = InnerBinderAdapter.getInstance(this.a, str2, str);
if (isConnected()) {
HMSLog.i("BaseHmsClient", "The binder is already connected.");
getAdapter().updateDelayTask();
connectedInternal(getAdapter().getServiceBinder());
return;
} else {
b(5);
m.binder(d());
return;
}
}
l = OuterBinderAdapter.getInstance(this.a, str2, str);
if (isConnected()) {
HMSLog.i("BaseHmsClient", "The binder is already connected.");
getAdapter().updateDelayTask();
connectedInternal(getAdapter().getServiceBinder());
} else {
b(5);
l.binder(d());
}
}
private void b(AvailableAdapter availableAdapter, int i2) {
HMSLog.i("BaseHmsClient", "enter HmsCore resolution");
if (!getClientSettings().isHasActivity()) {
a(new ConnectionResult(26, HuaweiApiAvailability.getInstance().getErrPendingIntent(this.a, i2, 0)));
return;
}
Activity activeActivity = Util.getActiveActivity(getClientSettings().getCpActivity(), getContext());
if (activeActivity != null) {
availableAdapter.startResolution(activeActivity, new AvailableAdapter.AvailableCallBack(this) { // from class: com.huawei.hms.common.internal.BaseHmsClient.3
final BaseHmsClient a;
{
this.a = this;
}
@Override // com.huawei.hms.adapter.AvailableAdapter.AvailableCallBack
public void onComplete(int i3) {
if (i3 == 0 && this.a.c()) {
this.a.a();
} else {
this.a.a(i3);
}
}
});
} else {
a(26);
}
}
private void a(int i2, boolean z) {
int isHuaweiMobileServicesAvailable;
HMSLog.i("BaseHmsClient", "====== HMSSDK version: 61100302 ======");
int i3 = (this.c.isUseInnerHms() ? k : j).get();
HMSLog.i("BaseHmsClient", "Enter connect, Connection Status: ".concat(String.valueOf(i3)));
if (z || !(i3 == 3 || i3 == 5)) {
if (getMinApkVersion() > i2) {
i2 = getMinApkVersion();
}
StringBuilder sb = new StringBuilder("connect minVersion:");
sb.append(i2);
sb.append(" packageName:");
sb.append(this.c.getInnerHmsPkg());
HMSLog.i("BaseHmsClient", sb.toString());
if (this.a.getPackageName().equals(this.c.getInnerHmsPkg())) {
HMSLog.i("BaseHmsClient", "service packageName is same, bind core service return");
a();
return;
}
if (Util.isAvailableLibExist(this.a)) {
AvailableAdapter availableAdapter = new AvailableAdapter(i2);
isHuaweiMobileServicesAvailable = availableAdapter.isHuaweiMobileServicesAvailable(this.a);
HMSLog.i("BaseHmsClient", "check available result: ".concat(String.valueOf(isHuaweiMobileServicesAvailable)));
if (isHuaweiMobileServicesAvailable == 0) {
a();
return;
}
if (availableAdapter.isUserResolvableError(isHuaweiMobileServicesAvailable)) {
HMSLog.i("BaseHmsClient", "bindCoreService3.0 fail, start resolution now.");
b(availableAdapter, isHuaweiMobileServicesAvailable);
return;
} else if (availableAdapter.isUserNoticeError(isHuaweiMobileServicesAvailable)) {
HMSLog.i("BaseHmsClient", "bindCoreService3.0 fail, start notice now.");
a(availableAdapter, isHuaweiMobileServicesAvailable);
return;
} else {
StringBuilder sb2 = new StringBuilder("bindCoreService3.0 fail: ");
sb2.append(isHuaweiMobileServicesAvailable);
sb2.append(" is not resolvable.");
HMSLog.i("BaseHmsClient", sb2.toString());
}
} else {
isHuaweiMobileServicesAvailable = HuaweiApiAvailability.getInstance().isHuaweiMobileServicesAvailable(this.a, i2);
HMSLog.i("BaseHmsClient", "HuaweiApiAvailability check available result: ".concat(String.valueOf(isHuaweiMobileServicesAvailable)));
if (isHuaweiMobileServicesAvailable == 0) {
a();
return;
}
}
a(isHuaweiMobileServicesAvailable);
}
}
private void a(AvailableAdapter availableAdapter, int i2) {
HMSLog.i("BaseHmsClient", "enter notice");
if (!getClientSettings().isHasActivity()) {
if (i2 == 29) {
i2 = 9;
}
a(new ConnectionResult(26, HuaweiApiAvailability.getInstance().getErrPendingIntent(this.a, i2, 0)));
} else {
Activity activeActivity = Util.getActiveActivity(getClientSettings().getCpActivity(), getContext());
if (activeActivity != null) {
availableAdapter.startNotice(activeActivity, new AvailableAdapter.AvailableCallBack(this) { // from class: com.huawei.hms.common.internal.BaseHmsClient.2
final BaseHmsClient a;
{
this.a = this;
}
@Override // com.huawei.hms.adapter.AvailableAdapter.AvailableCallBack
public void onComplete(int i3) {
this.a.a(i3);
}
});
} else {
a(26);
}
}
}
/* JADX INFO: Access modifiers changed from: private */
public void a(int i2) {
HMSLog.i("BaseHmsClient", "notifyFailed result: ".concat(String.valueOf(i2)));
Message message = new Message();
message.what = RequestManager.NOTIFY_CONNECT_FAILED;
message.obj = new ConnectionResultWrapper(this.h, new ConnectionResult(i2));
RequestManager.getHandler().sendMessage(message);
OnConnectionFailedListener onConnectionFailedListener = this.f;
if (onConnectionFailedListener == null || (onConnectionFailedListener instanceof HuaweiApi.RequestHandler)) {
return;
}
onConnectionFailedListener.onConnectionFailed(new ConnectionResult(i2));
}
/* JADX INFO: Access modifiers changed from: private */
public void a(ConnectionResult connectionResult) {
StringBuilder sb = new StringBuilder("notifyFailed result: ");
sb.append(connectionResult.getErrorCode());
HMSLog.i("BaseHmsClient", sb.toString());
Message message = new Message();
message.what = RequestManager.NOTIFY_CONNECT_FAILED;
HuaweiApi.RequestHandler requestHandler = this.h;
this.h = null;
message.obj = new ConnectionResultWrapper(requestHandler, connectionResult);
RequestManager.getHandler().sendMessage(message);
OnConnectionFailedListener onConnectionFailedListener = this.f;
if (onConnectionFailedListener == null || (onConnectionFailedListener instanceof HuaweiApi.RequestHandler)) {
return;
}
onConnectionFailedListener.onConnectionFailed(connectionResult);
}
public void setService(IAIDLInvoke iAIDLInvoke) {
this.d = iAIDLInvoke;
}
public final void setInternalRequest(HuaweiApi.RequestHandler requestHandler) {
this.h = requestHandler;
}
@Override // com.huawei.hms.support.api.client.ApiClient
public String getSessionId() {
return this.sessionId;
}
@Override // com.huawei.hms.support.api.client.AidlApiClient
public IAIDLInvoke getService() {
return this.d;
}
/* loaded from: classes2.dex */
public static final class ConnectionResultWrapper {
private HuaweiApi.RequestHandler a;
private ConnectionResult b;
public ConnectionResultWrapper(HuaweiApi.RequestHandler requestHandler, ConnectionResult connectionResult) {
this.a = requestHandler;
this.b = connectionResult;
}
public final HuaweiApi.RequestHandler getRequest() {
return this.a;
}
public final ConnectionResult getConnectionResult() {
return this.b;
}
}
@Override // com.huawei.hms.support.api.client.ApiClient
public Context getContext() {
return this.a;
}
/* JADX INFO: Access modifiers changed from: protected */
public ClientSettings getClientSettings() {
return this.c;
}
@Override // com.huawei.hms.support.api.client.ApiClient
public String getAppID() {
return this.b;
}
}