package com.huawei.hms.api; import android.app.Activity; import android.app.AlertDialog; import android.app.Dialog; import android.app.Fragment; import android.app.PendingIntent; import android.content.Context; import android.content.DialogInterface; import android.content.Intent; import android.content.IntentSender; import android.os.Bundle; import android.text.TextUtils; import com.google.android.gms.internal.common.zzd; import com.huawei.hms.activity.BridgeActivity; import com.huawei.hms.activity.EnableServiceActivity; import com.huawei.hms.activity.ForegroundIntentBuilder; import com.huawei.hms.activity.internal.BusResponseCallback; import com.huawei.hms.activity.internal.BusResponseResult; import com.huawei.hms.adapter.AvailableUtil; import com.huawei.hms.adapter.internal.CommonCode; import com.huawei.hms.adapter.ui.UpdateAdapter; import com.huawei.hms.api.Api; import com.huawei.hms.common.ErrorDialogFragment; import com.huawei.hms.common.HuaweiApi; import com.huawei.hms.common.api.AvailabilityException; import com.huawei.hms.common.api.HuaweiApiCallable; import com.huawei.hms.common.internal.ConnectionErrorMessages; import com.huawei.hms.common.internal.DialogRedirect; import com.huawei.hms.common.internal.Preconditions; import com.huawei.hms.support.log.HMSLog; import com.huawei.hms.update.note.AppSpoofResolution; import com.huawei.hms.update.note.DoNothingResolution; import com.huawei.hms.update.note.NotInstalledHmsResolution; import com.huawei.hms.update.ui.UpdateBean; import com.huawei.hms.utils.Checker; import com.huawei.hms.utils.HMSPackageManager; import com.huawei.hms.utils.PackageManagerHelper; import com.huawei.hms.utils.ResourceLoaderUtil; import com.huawei.hms.utils.UIUtil; import com.huawei.hms.utils.Util; import o.HiE; import o.nNj; /* JADX INFO: Access modifiers changed from: package-private */ /* loaded from: classes2.dex */ public final class HuaweiApiAvailabilityImpl extends HuaweiApiAvailability { private static final HuaweiApiAvailabilityImpl a = new HuaweiApiAvailabilityImpl(); /* loaded from: classes2.dex */ class a implements BusResponseCallback { final nNj[] a; final HuaweiApiAvailabilityImpl b; a(HuaweiApiAvailabilityImpl huaweiApiAvailabilityImpl, nNj[] nnjArr) { this.b = huaweiApiAvailabilityImpl; this.a = nnjArr; } @Override // com.huawei.hms.activity.internal.BusResponseCallback public BusResponseResult innerError(Activity activity, int i, String str) { StringBuilder sb = new StringBuilder("Test foreground bus error: resultCode "); sb.append(i); sb.append(", errMessage"); sb.append(str); HMSLog.e("HuaweiApiAvailabilityImpl", sb.toString()); this.a[0].c(new AvailabilityException()); return null; } @Override // com.huawei.hms.activity.internal.BusResponseCallback public BusResponseResult succeedReturn(Activity activity, int i, Intent intent) { StringBuilder sb = new StringBuilder("Test foreground bus success: resultCode "); sb.append(i); sb.append(", data"); sb.append(intent); HMSLog.i("HuaweiApiAvailabilityImpl", sb.toString()); return null; } } private HuaweiApiAvailabilityImpl() { } private static Intent a(Activity activity, String str) { return BridgeActivity.getIntentStartBridgeActivity(activity, str); } @Override // com.huawei.hms.api.HuaweiApiAvailability public final HiE checkApiAccessible(HuaweiApi huaweiApi, HuaweiApi... huaweiApiArr) { HiE hiE = new nNj().b; if (huaweiApi != null) { try { a(huaweiApi); } catch (AvailabilityException e) { StringBuilder sb = new StringBuilder("checkApi has AvailabilityException "); sb.append(e.getMessage()); HMSLog.i("HuaweiApiAvailabilityImpl", sb.toString()); } } if (huaweiApiArr != null) { for (HuaweiApi huaweiApi2 : huaweiApiArr) { a(huaweiApi2); } } return hiE; } @Override // com.huawei.hms.api.HuaweiApiAvailability public final PendingIntent getErrPendingIntent(Context context, ConnectionResult connectionResult) { Preconditions.checkNotNull(context); Preconditions.checkNotNull(connectionResult); return getResolveErrorPendingIntent(context, connectionResult.getErrorCode()); } @Override // com.huawei.hms.api.HuaweiApiAvailability public final Dialog getErrorDialog(Activity activity, int i, int i2) { Checker.checkNonNull(activity, "activity must not be null."); HMSLog.i("HuaweiApiAvailabilityImpl", "Enter getErrorDialog, errorCode: ".concat(String.valueOf(i))); return getErrorDialog(activity, i, i2, null); } @Override // com.huawei.hms.api.HuaweiApiAvailability public final String getErrorString(int i) { HMSLog.i("HuaweiApiAvailabilityImpl", "Enter getErrorString, errorCode: ".concat(String.valueOf(i))); return ConnectionResult.getErrorString(i); } @Override // com.huawei.hms.api.HuaweiApiAvailability public final HiE getHuaweiServicesReady(Activity activity) { Preconditions.checkNotNull(activity); nNj nnj = new nNj(); nNj[] nnjArr = {nnj}; HiE hiE = nnj.b; int isHuaweiMobileServicesAvailable = isHuaweiMobileServicesAvailable(activity.getApplicationContext(), 30000000); Intent resolveErrorIntent = getResolveErrorIntent(activity, isHuaweiMobileServicesAvailable); Intent intentStartBridgeActivity = BridgeActivity.getIntentStartBridgeActivity(activity, ResolutionDelegate.class.getName()); if (resolveErrorIntent != null) { ForegroundIntentBuilder.registerResponseCallback(ResolutionDelegate.CALLBACK_METHOD, new a(this, nnjArr)); Bundle bundle = new Bundle(); bundle.putParcelable(CommonCode.MapKey.HAS_RESOLUTION, resolveErrorIntent); intentStartBridgeActivity.putExtras(bundle); activity.startActivity(intentStartBridgeActivity); } else if (isHuaweiMobileServicesAvailable == 3) { Intent intent = new Intent(); intent.setClass(activity, EnableServiceActivity.class); activity.startActivity(intent); } else if (isHuaweiMobileServicesAvailable == 0) { HMSLog.i("HuaweiApiAvailabilityImpl", "The HMS service is available."); } else { HMSLog.e("HuaweiApiAvailabilityImpl", "Framework can not solve the availability problem."); nnjArr[0].c(new AvailabilityException()); } return hiE; } @Override // com.huawei.hms.api.HuaweiApiAvailability public final Intent getResolveErrorIntent(Activity activity, int i) { HMSLog.i("HuaweiApiAvailabilityImpl", "Enter getResolveErrorIntent, errorCode: ".concat(String.valueOf(i))); if (activity == null) { return null; } if (i == 1 || i == 2) { if (Util.isAvailableLibExist(activity) && AvailableUtil.isInstallerLibExist(activity)) { return (Intent) UpdateAdapter.invokeMethod("com.huawei.hms.update.manager.UpdateManager", "getStartUpdateIntent", new Object[]{activity, a(activity.getApplicationContext())}); } return a(activity, NotInstalledHmsResolution.class.getName()); } if (i != 6) { if (i == 9 && Util.isAvailableLibExist(activity)) { return a(activity, AppSpoofResolution.class.getName()); } return null; } return a(activity, BindingFailedResolution.class.getName()); } @Override // com.huawei.hms.api.HuaweiApiAvailability public final PendingIntent getResolveErrorPendingIntent(Activity activity, int i) { HMSLog.i("HuaweiApiAvailabilityImpl", "Enter getResolveErrorPendingIntent, errorCode: ".concat(String.valueOf(i))); Intent resolveErrorIntent = getResolveErrorIntent(activity, i); if (resolveErrorIntent != null) { return PendingIntent.getActivity(activity, 0, resolveErrorIntent, zzd.zza); } return null; } @Override // com.huawei.hms.api.HuaweiApiAvailability public final int isHuaweiMobileNoticeAvailable(Context context) { Checker.checkNonNull(context, "context must not be null."); PackageManagerHelper packageManagerHelper = new PackageManagerHelper(context); String hMSPackageNameForMultiService = HMSPackageManager.getInstance(context).getHMSPackageNameForMultiService(); if (TextUtils.isEmpty(hMSPackageNameForMultiService)) { HMSLog.w("HuaweiApiAvailabilityImpl", "hmsPackageName is empty, Service is invalid."); return 1; } if (!PackageManagerHelper.PackageStates.NOT_INSTALLED.equals(packageManagerHelper.getPackageStates(hMSPackageNameForMultiService))) { return HMSPackageManager.getInstance(context).isApkUpdateNecessary(20600000) ? 2 : 0; } HMSLog.w("HuaweiApiAvailabilityImpl", "hmsPackageName is not installed, Service is invalid."); return 1; } @Override // com.huawei.hms.api.HuaweiApiAvailability public final int isHuaweiMobileServicesAvailable(Context context) { Checker.checkNonNull(context, "context must not be null."); return HuaweiMobileServicesUtil.isHuaweiMobileServicesAvailable(context, HuaweiApiAvailability.getServicesVersionCode()); } @Override // com.huawei.hms.api.HuaweiApiAvailability public final boolean isUserResolvableError(int i) { return isUserResolvableError(i, null); } @Override // com.huawei.hms.api.HuaweiApiAvailability public final boolean isUserResolvableError(int i, PendingIntent pendingIntent) { if (i == 0) { return false; } return pendingIntent != null || i == 1 || i == 2 || i == 6 || i == 9; } @Override // com.huawei.hms.api.HuaweiApiAvailability public final void popupErrNotification(Context context, ConnectionResult connectionResult) { Preconditions.checkNotNull(context); Preconditions.checkNotNull(connectionResult); showErrorNotification(context, connectionResult.getErrorCode()); } @Override // com.huawei.hms.api.HuaweiApiAvailability public final void resolveError(Activity activity, int i, int i2) { resolveError(activity, i, i2, null); } @Override // com.huawei.hms.api.HuaweiApiAvailability public final boolean showErrorDialogFragment(Activity activity, int i, int i2) { return showErrorDialogFragment(activity, i, i2, null); } @Override // com.huawei.hms.api.HuaweiApiAvailability public final void showErrorNotification(Context context, int i) { Checker.checkNonNull(context, "context must not be null."); HMSLog.i("HuaweiApiAvailabilityImpl", "Enter showErrorNotification, errorCode: ".concat(String.valueOf(i))); if (!(context instanceof Activity)) { HMSLog.i("HuaweiApiAvailabilityImpl", "context not instanceof Activity"); return; } Dialog errorDialog = getErrorDialog((Activity) context, i, 0); if (errorDialog == null) { HMSLog.i("HuaweiApiAvailabilityImpl", "showErrorNotification errorDialog can not be null"); } else { errorDialog.show(); } } private static Intent a(Context context, String str) { return BridgeActivity.getIntentStartBridgeActivity(context, str); } @Override // com.huawei.hms.api.HuaweiApiAvailability public final void resolveError(Activity activity, int i, int i2, PendingIntent pendingIntent) { Checker.checkNonNull(activity, "activity must not be null."); if (pendingIntent != null) { HMSLog.i("HuaweiApiAvailabilityImpl", "Enter resolveError, param pendingIntent is not null. and.errorCode: ".concat(String.valueOf(i))); } else { HMSLog.i("HuaweiApiAvailabilityImpl", "Enter resolveError, param pendingIntent is null. get pendingIntent from error code.and.errorCode: ".concat(String.valueOf(i))); pendingIntent = getResolveErrorPendingIntent(activity, i); } if (pendingIntent != null) { HMSLog.i("HuaweiApiAvailabilityImpl", "In resolveError, start pendingIntent.errorCode: ".concat(String.valueOf(i))); try { activity.startIntentSenderForResult(pendingIntent.getIntentSender(), i2, null, 0, 0, 0); } catch (IntentSender.SendIntentException unused) { HMSLog.e("HuaweiApiAvailabilityImpl", "Enter resolveError, start pendingIntent failed.errorCode: ".concat(String.valueOf(i))); } } } @Override // com.huawei.hms.api.HuaweiApiAvailability public final boolean showErrorDialogFragment(Activity activity, int i, int i2, DialogInterface.OnCancelListener onCancelListener) { Dialog errorDialog = getErrorDialog(activity, i, i2, onCancelListener); if (errorDialog == null) { return false; } a(activity, errorDialog, HuaweiMobileServicesUtil.HMS_ERROR_DIALOG, onCancelListener); return true; } private UpdateBean a(Context context) { UpdateBean updateBean = new UpdateBean(); updateBean.setHmsOrApkUpgrade(true); updateBean.setClientPackageName(HMSPackageManager.getInstance(context).getHMSPackageName()); if (TextUtils.isEmpty(updateBean.getClientPackageName())) { updateBean.setClientPackageName("com.huawei.hwid"); } updateBean.setClientVersionCode(HuaweiApiAvailability.getServicesVersionCode()); updateBean.setClientAppId("C10132067"); if (ResourceLoaderUtil.getmContext() == null) { ResourceLoaderUtil.setmContext(context); } try { updateBean.setClientAppName(ResourceLoaderUtil.getString("hms_update_title")); } catch (Exception e) { StringBuilder sb = new StringBuilder("getString has Exception:"); sb.append(e.getMessage()); HMSLog.e("HuaweiApiAvailabilityImpl", sb.toString()); } return updateBean; } @Override // com.huawei.hms.api.HuaweiApiAvailability public final Dialog getErrorDialog(Activity activity, int i, int i2, DialogInterface.OnCancelListener onCancelListener) { Checker.checkNonNull(activity, "activity must not be null."); HMSLog.i("HuaweiApiAvailabilityImpl", "Enter getErrorDialog, errorCode: ".concat(String.valueOf(i))); return a(activity, i, DialogRedirect.getInstance(activity, a(activity, i), i2), onCancelListener); } @Override // com.huawei.hms.api.HuaweiApiAvailability public final PendingIntent getErrPendingIntent(Context context, int i, int i2) { StringBuilder sb = new StringBuilder("Enter getResolveErrorPendingIntent, errorCode: "); sb.append(i); sb.append(" requestCode: "); sb.append(i2); HMSLog.i("HuaweiApiAvailabilityImpl", sb.toString()); Intent resolveErrorIntent = getResolveErrorIntent(context, i); if (resolveErrorIntent != null) { return PendingIntent.getActivity(context, i2, resolveErrorIntent, zzd.zza); } return null; } @Override // com.huawei.hms.api.HuaweiApiAvailability public final int isHuaweiMobileServicesAvailable(Context context, int i) { Checker.checkNonNull(context, "context must not be null."); return HuaweiMobileServicesUtil.isHuaweiMobileServicesAvailable(context, i); } public final PendingIntent getResolveErrorPendingIntent(Context context, int i) { HMSLog.i("HuaweiApiAvailabilityImpl", "Enter getResolveErrorPendingIntent, errorCode: ".concat(String.valueOf(i))); Intent resolveErrorIntent = getResolveErrorIntent(context, i); if (resolveErrorIntent != null) { return PendingIntent.getActivity(context, 0, resolveErrorIntent, zzd.zza); } return null; } @Override // com.huawei.hms.api.HuaweiApiAvailability public final boolean showErrorDialogFragment(Activity activity, int i, Fragment fragment, int i2, DialogInterface.OnCancelListener onCancelListener) { return showErrorDialogFragment(activity, i, i2, onCancelListener); } @Override // com.huawei.hms.api.HuaweiApiAvailability public final HiE checkApiAccessible(HuaweiApiCallable huaweiApiCallable, HuaweiApiCallable... huaweiApiCallableArr) { HiE hiE = new nNj().b; if (huaweiApiCallable != null) { try { a(huaweiApiCallable); } catch (AvailabilityException e) { StringBuilder sb = new StringBuilder("HuaweiApiCallable checkApi has AvailabilityException "); sb.append(e.getMessage()); HMSLog.i("HuaweiApiAvailabilityImpl", sb.toString()); } } if (huaweiApiCallableArr != null) { for (HuaweiApiCallable huaweiApiCallable2 : huaweiApiCallableArr) { a(huaweiApiCallable2); } } return hiE; } private Intent a(Activity activity, int i) { HMSLog.i("HuaweiApiAvailabilityImpl", "getErrorResolutionIntent, errorCode: ".concat(String.valueOf(i))); if (i == 1 || i == 2) { if (Util.isAvailableLibExist(activity) && AvailableUtil.isInstallerLibExist(activity)) { return (Intent) UpdateAdapter.invokeMethod("com.huawei.hms.update.manager.UpdateManager", "startUpdateIntent", new Object[]{activity}); } return BridgeActivity.getIntentStartBridgeActivity(activity, DoNothingResolution.class.getName()); } if (i != 6) { if (i == 9 && Util.isAvailableLibExist(activity)) { return BridgeActivity.getIntentStartBridgeActivity(activity, AppSpoofResolution.class.getName()); } return null; } return BridgeActivity.getIntentStartBridgeActivity(activity, BindingFailedResolution.class.getName()); } public final Intent getResolveErrorIntent(Context context, int i) { HMSLog.i("HuaweiApiAvailabilityImpl", "Enter getResolveErrorIntent, errorCode: ".concat(String.valueOf(i))); if (i == 1 || i == 2) { if (Util.isAvailableLibExist(context) && AvailableUtil.isInstallerLibExist(context)) { return (Intent) UpdateAdapter.invokeMethod("com.huawei.hms.update.manager.UpdateManager", "getStartUpdateIntent", new Object[]{context, a(context.getApplicationContext())}); } return a(context, NotInstalledHmsResolution.class.getName()); } if (i != 6) { if (i == 9 && Util.isAvailableLibExist(context)) { return a(context, AppSpoofResolution.class.getName()); } return null; } return a(context, BindingFailedResolution.class.getName()); } private static Dialog a(Activity activity, int i, DialogRedirect dialogRedirect, DialogInterface.OnCancelListener onCancelListener) { if (i == 0) { return null; } AlertDialog.Builder builder = new AlertDialog.Builder(activity, UIUtil.getDialogThemeId(activity)); builder.setMessage(ConnectionErrorMessages.getErrorMessage(activity, i)); if (onCancelListener != null) { builder.setOnCancelListener(onCancelListener); } builder.setPositiveButton(ConnectionErrorMessages.getErrorDialogButtonMessage(activity, i), dialogRedirect); if (Util.isAvailableLibExist(activity) && AvailableUtil.isInstallerLibExist(activity)) { String errorTitle = ConnectionErrorMessages.getErrorTitle(activity, i); if (errorTitle != null) { builder.setTitle(errorTitle); } } else { String errorTitle2 = ConnectionErrorMessages.getErrorTitle(activity, i); if (errorTitle2 != null) { builder.setTitle(errorTitle2); } } return builder.create(); } private static void a(Activity activity, Dialog dialog, String str, DialogInterface.OnCancelListener onCancelListener) { Checker.checkNonNull(activity, "activity must not be null."); ErrorDialogFragment.newInstance(dialog, onCancelListener).show(activity.getFragmentManager(), str); } private void a(Object obj) throws AvailabilityException { ConnectionResult connectionResult; AvailabilityException availabilityException = new AvailabilityException(); if (obj instanceof HuaweiApi) { connectionResult = availabilityException.getConnectionResult((HuaweiApi) obj); } else { connectionResult = availabilityException.getConnectionResult((HuaweiApiCallable) obj); } if (connectionResult.getErrorCode() == 0) { return; } StringBuilder sb = new StringBuilder("The service is unavailable: "); sb.append(availabilityException.getMessage()); HMSLog.i("HuaweiApiAvailabilityImpl", sb.toString()); throw availabilityException; } public static HuaweiApiAvailabilityImpl getInstance() { return a; } }