package com.huawei.hms.availableupdate; import android.app.Activity; import android.content.ActivityNotFoundException; import android.content.Context; import android.content.Intent; import android.net.Uri; import android.os.Build; import android.os.Handler; import android.os.Looper; import android.text.TextUtils; import android.view.KeyEvent; import com.huawei.hms.activity.IBridgeActivityDelegate; import com.huawei.hms.adapter.sysobs.SystemManager; import com.huawei.hms.android.SystemUtils; import com.huawei.hms.support.log.HMSLog; import com.huawei.hms.update.provider.UpdateProvider; import com.huawei.hms.utils.FileUtil; import com.huawei.hms.utils.HMSPackageManager; import com.huawei.hms.utils.PackageManagerHelper; import com.huawei.hms.utils.ResourceLoaderUtil; import com.huawei.updatesdk.UpdateSdkAPI; import com.huawei.updatesdk.service.appmgr.bean.ApkUpgradeInfo; import com.huawei.updatesdk.service.otaupdate.CheckUpdateCallBack; import com.huawei.updatesdk.service.otaupdate.UpdateKey; import com.meizu.cloud.pushsdk.constants.PushConstants; import java.io.File; import java.io.Serializable; /* compiled from: UpdateWizard */ public class h0 extends p implements g { public f j; public h k; public int l = 0; /* compiled from: UpdateWizard */ public static class a implements Runnable { public final /* synthetic */ g a; public final /* synthetic */ int b; public final /* synthetic */ h c; public a(g gVar, int i, h hVar) { this.a = gVar; this.b = i; this.c = hVar; } public final void run() { this.a.a(this.b, this.c); } } /* compiled from: UpdateWizard */ public class b implements CheckUpdateCallBack { public final /* synthetic */ g a; public b(g gVar) { this.a = gVar; } @Override // com.huawei.updatesdk.service.otaupdate.CheckUpdateCallBack public void onMarketInstallInfo(Intent intent) { } @Override // com.huawei.updatesdk.service.otaupdate.CheckUpdateCallBack public void onMarketStoreError(int i) { HMSLog.e("UpdateWizard", "onMarketStoreError responseCode: " + i); } @Override // com.huawei.updatesdk.service.otaupdate.CheckUpdateCallBack public void onUpdateInfo(Intent intent) { if (intent != null) { h0.this.a((h0) intent, (Intent) this.a); } } @Override // com.huawei.updatesdk.service.otaupdate.CheckUpdateCallBack public void onUpdateStoreError(int i) { HMSLog.e("UpdateWizard", "onUpdateStoreError responseCode: " + i); } } @Override // com.huawei.hms.availableupdate.p public void b(q qVar) { HMSLog.i("UpdateWizard", "Enter onDoWork."); if (qVar instanceof a0) { qVar.b(); a(s.class); a(this); } else if (qVar instanceof x) { qVar.b(); g(); } else if (qVar instanceof w) { a(y.class); f(); } else if (qVar instanceof v) { a(y.class); f(); } else if (qVar instanceof d0) { e(); } else if (qVar instanceof e0) { e(); } else if (qVar instanceof f0) { e(); } } public final void c() { f fVar = this.j; if (fVar != null) { fVar.a(); this.j = null; } } public final void d() { Activity b2 = b(); String netType = b2 != null ? SystemUtils.getNetType(b2.getBaseContext()) : ""; HMSLog.i("UpdateWizard", "current network is " + netType); if ("WIFI".equals(netType)) { a(y.class); f(); HMSLog.i("UpdateWizard", "current network is wifi"); return; } a(v.class); HMSLog.i("UpdateWizard", "current network is not wifi"); } public final void e() { if (!a(false)) { c(8, this.f); } else { a(8, this.f); } } public final void f() { Activity b2 = b(); if (b2 == null || b2.isFinishing()) { a(e0.class); } else if (a(b2)) { c(); d dVar = new d(new e(b2)); this.j = dVar; dVar.a(this, this.k); } } public void g() { c(13, this.f); } @Override // com.huawei.hms.activity.IBridgeActivityDelegate public int getRequestCode() { return 2006; } @Override // com.huawei.hms.activity.IBridgeActivityDelegate, com.huawei.hms.availableupdate.p public void onBridgeActivityCreate(Activity activity) { super.onBridgeActivityCreate(activity); if (this.c != null) { this.f = 6; if (a(activity)) { if (!this.c.isNeedConfirm() || TextUtils.isEmpty(this.h)) { a(s.class); a(this); return; } a(a0.class); } } } @Override // com.huawei.hms.activity.IBridgeActivityDelegate, com.huawei.hms.availableupdate.p public void onBridgeActivityDestroy() { c(); super.onBridgeActivityDestroy(); } @Override // com.huawei.hms.activity.IBridgeActivityDelegate public boolean onBridgeActivityResult(int i, int i2, Intent intent) { IBridgeActivityDelegate iBridgeActivityDelegate; if (this.e && (iBridgeActivityDelegate = this.b) != null) { return iBridgeActivityDelegate.onBridgeActivityResult(i, i2, intent); } if (this.f != 6 || i != getRequestCode()) { return false; } if (a(this.g, this.i)) { c(0, this.f); return true; } e(); return true; } @Override // com.huawei.hms.activity.IBridgeActivityDelegate, com.huawei.hms.availableupdate.p public void onKeyUp(int i, KeyEvent keyEvent) { IBridgeActivityDelegate iBridgeActivityDelegate; if (this.e && (iBridgeActivityDelegate = this.b) != null) { iBridgeActivityDelegate.onKeyUp(i, keyEvent); } else if (4 == i) { HMSLog.i("UpdateWizard", "In onKeyUp, Call finish."); Activity b2 = b(); if (b2 != null && !b2.isFinishing()) { b2.setResult(0, null); b2.finish(); } } } public static Uri a(Context context, File file) { PackageManagerHelper packageManagerHelper = new PackageManagerHelper(context); String packageName = context.getPackageName(); String str = packageName + UpdateProvider.AUTHORITIES_SUFFIX; if (Build.VERSION.SDK_INT > 23 && (context.getApplicationInfo().targetSdkVersion > 23 || packageManagerHelper.hasProvider(packageName, str))) { return UpdateProvider.getUriForFile(context, str, file); } return Uri.fromFile(file); } public static void a(g gVar, int i, h hVar) { if (gVar != null) { new Handler(Looper.getMainLooper()).post(new a(gVar, i, hVar)); } } public final boolean a(Activity activity) { if (HMSPackageManager.getInstance(activity).isApkUpdateNecessary(this.c.c())) { return true; } a(); SystemManager.getInstance().notifyUpdateResult(0); return false; } @Override // com.huawei.hms.availableupdate.g public void a(int i, h hVar) { HMSLog.i("UpdateWizard", "Enter onCheckUpdate, status: " + i.a(i)); if (i != 1000) { switch (i) { case 1201: case 1202: case 1203: a(d0.class); return; default: a(d0.class); return; } } else { this.k = hVar; d(); } } @Override // com.huawei.hms.availableupdate.g public void a(int i, int i2, int i3, File file) { HMSLog.i("UpdateWizard", "Enter onDownloadPackage, status: " + i.a(i) + ", reveived: " + i2 + ", total: " + i3); if (i == 2000) { a(); if (file == null) { e(); } else if (FileUtil.verifyHash(this.k.e, file)) { a(file); } else { HMSLog.i("UpdateWizard", "Hash value mismatch for download file"); } } else if (i == 2100) { q qVar = this.d; if (qVar != null && (qVar instanceof y)) { int i4 = 0; if (i2 >= 0 && i3 > 0) { i4 = (int) ((((long) i2) * 100) / ((long) i3)); } this.l = i4; ((y) this.d).b(i4); } } else if (i != 2101) { switch (i) { case PushConstants.ON_TIME_NOTIFICATION /*{ENCODED_INT: 2201}*/: a(e0.class); return; case PushConstants.DELAY_NOTIFICATION /*{ENCODED_INT: 2202}*/: a(w.class); return; case 2203: case 2204: a(f0.class); return; default: return; } } } public final void a(File file) { Activity b2 = b(); if (b2 != null && !b2.isFinishing()) { Uri a2 = a(b2, file); if (a2 == null) { HMSLog.e("UpdateWizard", "In startInstaller, Failed to creates a Uri from a file."); e(); } else if (a(b2)) { Intent intent = new Intent("android.intent.action.VIEW"); intent.setDataAndType(a2, "application/vnd.android.package-archive"); intent.setFlags(3); intent.putExtra("android.intent.extra.NOT_UNKNOWN_SOURCE", true); try { b2.startActivityForResult(intent, getRequestCode()); } catch (ActivityNotFoundException e) { HMSLog.e("UpdateWizard", "In startInstaller, Failed to start package installer." + e.getMessage()); e(); } } } } @Override // com.huawei.hms.availableupdate.p public void a(q qVar) { HMSLog.i("UpdateWizard", "Enter onCancel."); if (qVar instanceof a0) { g(); } else if (qVar instanceof s) { c(); g(); } else if (qVar instanceof y) { c(); a(x.class); } else if (qVar instanceof x) { a(y.class); f(); } else if (qVar instanceof w) { g(); } else if (qVar instanceof v) { g(); } else { e(); } } @Override // com.huawei.hms.availableupdate.p public void a(Class<? extends q> cls) { if (a(b())) { a(); try { q qVar = (q) cls.newInstance(); if (!TextUtils.isEmpty(this.h) && (qVar instanceof a0)) { this.h = ResourceLoaderUtil.getString("hms_update_title"); ((a0) qVar).a(this.h); } if (this.l > 0 && (qVar instanceof y)) { ((y) qVar).a(this.l); } qVar.a(this); this.d = qVar; } catch (IllegalAccessException | IllegalStateException | InstantiationException e) { HMSLog.e("UpdateWizard", "In showDialog, Failed to show the dialog." + e.getMessage()); } } } public final void a(g gVar) { if (gVar != null) { Activity b2 = b(); if (b2 == null || b2.isFinishing()) { a(gVar, 1201, (h) null); } else if (a(b2)) { UpdateSdkAPI.checkTargetAppUpdate(b2, this.c.b(), new b(gVar)); } } } public final void a(Intent intent, g gVar) { try { int intExtra = intent.getIntExtra(UpdateKey.STATUS, -99); HMSLog.i("UpdateWizard", "CheckUpdateCallBack status is " + intExtra); String stringExtra = intent.getStringExtra(UpdateKey.FAIL_REASON); if (!TextUtils.isEmpty(stringExtra)) { HMSLog.e("UpdateWizard", "checkTargetAppUpdate reason is " + stringExtra); } if (intExtra == 7) { Serializable serializableExtra = intent.getSerializableExtra(UpdateKey.INFO); if (serializableExtra instanceof ApkUpgradeInfo) { ApkUpgradeInfo apkUpgradeInfo = (ApkUpgradeInfo) serializableExtra; String package_ = apkUpgradeInfo.getPackage_(); int versionCode_ = apkUpgradeInfo.getVersionCode_(); String downurl_ = apkUpgradeInfo.getDownurl_(); int size_ = apkUpgradeInfo.getSize_(); String sha256_ = apkUpgradeInfo.getSha256_(); if (TextUtils.isEmpty(package_) || !package_.equals(this.c.b())) { a(gVar, 1201, (h) null); } else if (versionCode_ < this.c.c()) { HMSLog.e("UpdateWizard", "CheckUpdateCallBack versionCode is " + versionCode_ + "bean.getClientVersionCode() is " + this.c.c()); a(gVar, 1203, (h) null); } else if (TextUtils.isEmpty(downurl_) || TextUtils.isEmpty(sha256_)) { a(gVar, 1201, (h) null); } else { a(gVar, 1000, new h(package_, versionCode_, downurl_, size_, sha256_)); } } } else if (intExtra == 3) { a(gVar, 1202, (h) null); } else { a(gVar, 1201, (h) null); } } catch (Exception e) { HMSLog.e("UpdateWizard", "intent has some error" + e.getMessage()); a(gVar, 1201, (h) null); } } }