package com.huawei.hms.api; import android.app.Activity; import android.content.Intent; import android.os.Bundle; import android.view.KeyEvent; import com.huawei.hms.activity.IBridgeActivityDelegate; import com.huawei.hms.activity.internal.BusResponseCallback; import com.huawei.hms.activity.internal.ForegroundBusResponseMgr; import com.huawei.hms.adapter.internal.CommonCode; import com.huawei.hms.support.log.HMSLog; import com.huawei.hms.utils.IntentUtil; import java.lang.ref.WeakReference; /* loaded from: classes2.dex */ public class ResolutionDelegate implements IBridgeActivityDelegate { public static final String CALLBACK_METHOD = "CALLBACK_METHOD"; private static final int REQUEST_CODE = 1002; private static final String TAG = "ResolutionDelegate"; private WeakReference mThisWeakRef; private void finishBridgeActivity() { Activity activity = getActivity(); if (activity == null || activity.isFinishing()) { return; } activity.finish(); } private BusResponseCallback getResponseCallback(String str) { return ForegroundBusResponseMgr.getInstance().get(str); } @Override // com.huawei.hms.activity.IBridgeActivityDelegate public int getRequestCode() { return 1002; } @Override // com.huawei.hms.activity.IBridgeActivityDelegate public void onBridgeActivityCreate(Activity activity) { Bundle bundle; if (activity != null && !activity.isFinishing()) { this.mThisWeakRef = new WeakReference<>(activity); try { bundle = activity.getIntent().getExtras(); } catch (Exception e) { StringBuilder sb = new StringBuilder("getExtras exception:"); sb.append(e.getMessage()); HMSLog.e(TAG, sb.toString()); bundle = null; } if (bundle != null) { activity.startActivityForResult(IntentUtil.modifyIntentBehaviorsSafe((Intent) bundle.getParcelable(CommonCode.MapKey.HAS_RESOLUTION)), 1002); return; } return; } HMSLog.e(TAG, "activity is null or finishing"); } @Override // com.huawei.hms.activity.IBridgeActivityDelegate public boolean onBridgeActivityResult(int i, int i2, Intent intent) { if (i != getRequestCode()) { return false; } BusResponseCallback responseCallback = getResponseCallback(CALLBACK_METHOD); int isHuaweiMobileServicesAvailable = HuaweiApiAvailability.getInstance().isHuaweiMobileServicesAvailable(this.mThisWeakRef.get(), 30000000); if (i2 == -1 && isHuaweiMobileServicesAvailable == 0) { HMSLog.i(TAG, "Make service available success."); } else { responseCallback.innerError(this.mThisWeakRef.get(), i2, "Make service available failed."); } finishBridgeActivity(); return true; } @Override // com.huawei.hms.activity.IBridgeActivityDelegate public void onBridgeConfigurationChanged() { } @Override // com.huawei.hms.activity.IBridgeActivityDelegate public void onKeyUp(int i, KeyEvent keyEvent) { } private Activity getActivity() { WeakReference weakReference = this.mThisWeakRef; if (weakReference == null) { return null; } return weakReference.get(); } @Override // com.huawei.hms.activity.IBridgeActivityDelegate public void onBridgeActivityDestroy() { this.mThisWeakRef = null; } }