工作空间 v3.6.5.2版本的 MD5 值为:58e65af156c65a63bf64ed2e64960853
以下内容为反编译后的 ClientUpgradeHelper.java 源代码,内容仅作参考
package com.uusafe.appsetting.helper;
import android.app.Activity;
import android.app.Dialog;
import android.content.Context;
import android.content.ContextWrapper;
import android.content.DialogInterface;
import android.os.Handler;
import android.os.Looper;
import android.os.Message;
import android.os.Process;
import android.text.TextUtils;
import android.view.KeyEvent;
import android.view.View;
import android.widget.ProgressBar;
import android.widget.TextView;
import androidx.core.view.GravityCompat;
import com.uusafe.base.modulesdk.module.activity.ActivityManager;
import com.uusafe.base.modulesdk.module.bean.ClientUpgradeDetailBean;
import com.uusafe.base.modulesdk.module.bean.InstallAppInfo;
import com.uusafe.base.modulesdk.module.global.CommGlobal;
import com.uusafe.base.modulesdk.module.manager.BaseModuleManager;
import com.uusafe.base.modulesdk.module.netapi.BaseApis;
import com.uusafe.commbase.bean.DownloadInfo;
import com.uusafe.commbase.event.NextDialogEvent;
import com.uusafe.commbase.global.BaseGlobal;
import com.uusafe.commbase.module.listener.DownloadListener;
import com.uusafe.data.module.presenter.clientupgrade.ClientUpgradePresenter;
import com.uusafe.download.manager.DownloadManager;
import com.uusafe.download.task.DownloadTask;
import com.uusafe.emm.android.Constants;
import com.uusafe.mbs.appsetting.R;
import com.uusafe.mcm.net.Apis;
import com.uusafe.uibase.dialog.CommonDialog;
import com.uusafe.util.PackageUtils;
import com.uusafe.utils.common.FileAccessorUtil;
import com.uusafe.utils.common.FileUtils;
import com.uusafe.utils.common.MD5Util;
import com.uusafe.utils.common.PreferenceUtils;
import com.uusafe.utils.common.StringUtils;
import com.uusafe.utils.common.UiUtils;
import com.uusafe.utils.common.ZZLog;
import java.io.File;
public class ClientUpgradeHelper {
private static ClientUpgradeHelper sInstance;
private boolean cancelable;
private CommonDialog downloadDialog;
private String fileMd5;
private String fileUrl;
private boolean forceUpgrade;
private String mClientVersion;
private CommonDialog mDialog;
private String mTargetPath;
private String mUpdateDescription;
private String msgText;
private Dialog net4gDialog;
private ProgressBar pbUpdate;
private String positiveText;
private boolean showNegative;
private boolean showTitle;
private String titleText;
private TextView tvCompleteHint;
private TextView tvPositive;
private ClientUpgradeDetailBean upgradeBean;
private View vHorizontalDivider;
public final String TAG = "ClientUpgradeHelper";
private final int STARTINSATLLDELAY = 1011;
boolean showUpDateDialog = true;
private DialogInterface.OnDismissListener onDismissListener = new DialogInterface.OnDismissListener() {
@Override
public final void onDismiss(DialogInterface dialogInterface) {
ClientUpgradeHelper.this.a(dialogInterface);
}
};
private DialogInterface.OnKeyListener onBackKeyListener = new DialogInterface.OnKeyListener() {
@Override
public boolean onKey(DialogInterface dialogInterface, int i, KeyEvent keyEvent) {
if (i == 4 && keyEvent.getRepeatCount() == 0) {
ZZLog.i("ClientUpgradeHelper", "keyCode == KeyEvent.KEYCODE_BACK", new Object[0]);
ClientUpgradeHelper clientUpgradeHelper = ClientUpgradeHelper.this;
clientUpgradeHelper.closeDialog(clientUpgradeHelper.mDialog);
ClientUpgradeHelper.this.onPause();
if (ClientUpgradeHelper.this.upgradeBean != null && ClientUpgradeHelper.this.upgradeBean.getUpdateFlag() > 0 && ClientUpgradeHelper.this.forceUpgrade) {
ZZLog.i("ClientUpgradeHelper", "keyCode exitApp", new Object[0]);
BaseGlobal.getInstance().exitApp();
} else {
ZZLog.i("ClientUpgradeHelper", "keyCode dismissAll", new Object[0]);
ClientUpgradeHelper.this.dismissAll();
org.greenrobot.eventbus.e.a().c(new NextDialogEvent());
}
}
return false;
}
};
private Handler uiHandler = new Handler(Looper.getMainLooper()) {
@Override
public void handleMessage(Message message) {
int i = message.what;
if (i == 3) {
DownloadManager.getInstance().pauseTask((String) message.obj, true);
} else if (i != 1011) {
} else {
Process.killProcess(Process.myPid());
System.exit(0);
}
}
};
private void checkApkExist() {
DownloadTask taskByDownloadUrl = DownloadManager.getInstance().getTaskByDownloadUrl(this.fileUrl, FileAccessorUtil.DOWNLOAD_PATH);
if (taskByDownloadUrl != null) {
if (taskByDownloadUrl.getDownloadInfo().status == 5) {
this.mTargetPath = taskByDownloadUrl.getDownloadInfo().getSaveFileFullPath();
if (StringUtils.areNotEmpty(this.mTargetPath) && FileUtils.exists(this.mTargetPath)) {
String fileMD5 = MD5Util.getFileMD5(new File(this.mTargetPath));
if (FileUtils.exists(this.mTargetPath) && fileMD5.equals(this.fileMd5)) {
if (this.showUpDateDialog) {
ZZLog.i("ClientUpgradeHelper", "checkApkExist showDownloadDialog=", new Object[0]);
showDownloadDialog();
return;
}
ZZLog.i("ClientUpgradeHelper", "checkApkExist startInstall=", new Object[0]);
startInstall();
org.greenrobot.eventbus.e.a().c(new NextDialogEvent());
return;
}
}
ZZLog.i("ClientUpgradeHelper", "checkApkExist onPause=", new Object[0]);
onPause();
} else if (taskByDownloadUrl.getDownloadInfo().status == 2) {
ZZLog.i("ClientUpgradeHelper", "checkApkExist showToast=", new Object[0]);
UiUtils.showToast(getActivity(), getActivity().getString(R.string.uu_mos_msg_updating));
org.greenrobot.eventbus.e.a().c(new NextDialogEvent());
return;
}
}
initNewVersion();
}
public void close(Dialog dialog) {
if (dialog != null) {
try {
if (dialog.isShowing()) {
Context baseContext = ((ContextWrapper) dialog.getContext()).getBaseContext();
if (baseContext != null && (baseContext instanceof Activity)) {
if (!((Activity) baseContext).isFinishing() && !((Activity) baseContext).isDestroyed()) {
dialog.dismiss();
}
} else {
dialog.dismiss();
}
}
} catch (Exception e2) {
e2.printStackTrace();
}
}
}
public void dismissAll() {
closeDialog(this.mDialog);
closeDialog(this.net4gDialog);
closeDialog(this.downloadDialog);
ClientUpgradePresenter.setShowMosAppUpdateDialog(true);
}
private void dismissDownloadDialog() {
ZZLog.i("ClientUpgradeHelper", "dismissDownloadDialog=", new Object[0]);
org.greenrobot.eventbus.e.a().c(new NextDialogEvent());
if (TextUtils.equals(this.tvPositive.getText().toString(), getActivity().getText(R.string.uu_mos_msg_update_install))) {
startInstall();
} else {
onPause();
ClientUpgradeDetailBean clientUpgradeDetailBean = this.upgradeBean;
if (clientUpgradeDetailBean != null && clientUpgradeDetailBean.getUpdateFlag() > 0 && this.forceUpgrade) {
BaseGlobal.getInstance().exitApp();
}
}
CommonDialog commonDialog = this.downloadDialog;
if (commonDialog != null) {
closeDialog(commonDialog);
}
}
private void doUpdate() {
ZZLog.i("ClientUpgradeHelper", "doUpdate=", new Object[0]);
showDownloadDialog();
}
public Context getActivity() {
Activity currentActivity = ActivityManager.getScreenManager().currentActivity();
return currentActivity == null ? CommGlobal.getContext() : currentActivity;
}
private String getDownloadUrlByFileId(long j) {
StringBuilder sb = new StringBuilder();
sb.append(BaseApis.getBaseUrl());
sb.append(Apis.MCM_DOWNLOAD_URL);
sb.append(j);
sb.append("&orgCode=");
Context context = CommGlobal.getContext();
BaseGlobal.getInstance();
sb.append(PreferenceUtils.getCompanyCode(context, BaseGlobal.getMosKey()));
return sb.toString();
}
public static synchronized ClientUpgradeHelper getInstance() {
ClientUpgradeHelper clientUpgradeHelper;
synchronized (ClientUpgradeHelper.class) {
if (sInstance == null) {
sInstance = new ClientUpgradeHelper();
}
clientUpgradeHelper = sInstance;
}
return clientUpgradeHelper;
}
public void handleFinishEvent() {
ZZLog.i("ClientUpgradeHelper", "showDownloadDialog handleFinishEvent mTargetPath=" + this.mTargetPath, new Object[0]);
ProgressBar progressBar = this.pbUpdate;
if (progressBar != null) {
progressBar.setVisibility(8);
}
TextView textView = this.tvPositive;
if (textView != null) {
textView.setText(getActivity().getString(R.string.uu_mos_msg_update_install));
}
View view = this.vHorizontalDivider;
if (view != null) {
view.setVisibility(0);
}
TextView textView2 = this.tvPositive;
if (textView2 != null) {
textView2.setVisibility(0);
}
TextView textView3 = this.tvCompleteHint;
if (textView3 != null) {
textView3.setVisibility(0);
}
}
private void initNewVersion() {
ZZLog.i("ClientUpgradeHelper", "initNewVersion=", new Object[0]);
StringBuilder sb = new StringBuilder();
sb.append(getActivity().getString(R.string.uu_mos_msg_new_version));
if (!TextUtils.isEmpty(this.mClientVersion)) {
sb.append(this.mClientVersion);
}
if (!this.forceUpgrade) {
sb.append(getActivity().getString(R.string.uu_mos_msg_version_update));
}
this.showTitle = true;
this.titleText = sb.toString();
this.msgText = this.mUpdateDescription;
this.showNegative = !this.forceUpgrade;
this.positiveText = getActivity().getString(R.string.uu_mos_btn_update);
showDialog(true);
}
private void initSameVersion() {
ZZLog.i("ClientUpgradeHelper", "initSameVersion=", new Object[0]);
this.cancelable = true;
this.msgText = getActivity().getString(R.string.uu_mos_msg_same_version);
this.positiveText = getActivity().getString(R.string.uu_mos_btn_same_version);
showDialog(false);
}
public void onPause() {
ZZLog.i("ClientUpgradeHelper", "onPause ====", new Object[0]);
DownloadTask taskByDownloadUrl = DownloadManager.getInstance().getTaskByDownloadUrl(this.fileUrl, FileAccessorUtil.DOWNLOAD_PATH);
if (taskByDownloadUrl != null && taskByDownloadUrl.getDownloadInfo() != null) {
if (this.uiHandler.hasMessages(3)) {
this.uiHandler.removeMessages(3);
}
taskByDownloadUrl.getDownloadInfo().setStatus(3);
if (taskByDownloadUrl.getDownloadInfo().getStatus() == 2) {
Message obtain = Message.obtain();
obtain.what = 3;
obtain.obj = this.fileUrl;
this.uiHandler.sendMessageDelayed(obtain, 300L);
return;
}
return;
}
ZZLog.i("ClientUpgradeHelper", "onPause downloadTask == null", new Object[0]);
}
private void showDownloadDialog() {
String absolutePath;
ZZLog.i("ClientUpgradeHelper", "showDownloadDialog=", new Object[0]);
closeDialog(this.mDialog);
closeDialog(this.net4gDialog);
if (this.showUpDateDialog) {
View inflate = View.inflate(getActivity(), R.layout.uu_mos_appsetting_activity_client_upgrade_download, null);
ZZLog.i("ClientUpgradeHelper", "showDownloadDialog show 11=", new Object[0]);
this.downloadDialog = new CommonDialog.Builder(getActivity()).setCancelable(false).setTitleShow(true).setTitle(getActivity().getString(R.string.uu_mos_msg_updating)).setContentView(inflate).setPositiveBtnShow(true ^ this.forceUpgrade).setPositiveText(getActivity().getString(R.string.uu_mos_dialog_cancel)).setNegativeBtnShow(false).setOnDismissListener(this.onDismissListener).setOnKeyListener(this.onBackKeyListener).create();
this.downloadDialog.show();
this.tvPositive = (TextView) this.downloadDialog.findViewById(R.id.uu_base_tv_positive);
this.vHorizontalDivider = this.downloadDialog.findViewById(R.id.uu_base_view_horizontal_divide_line_bottom);
this.pbUpdate = (ProgressBar) inflate.findViewById(R.id.pb_update);
this.tvCompleteHint = (TextView) inflate.findViewById(R.id.tv_complete_hint);
this.tvPositive.setOnClickListener(new View.OnClickListener() {
@Override
public final void onClick(View view) {
ClientUpgradeHelper.this.b(view);
}
});
} else {
UiUtils.showToast(getActivity(), getActivity().getString(R.string.uu_mos_msg_updating));
}
if (FileAccessorUtil.getDownloadClientUpGradePath() == null) {
absolutePath = BaseGlobal.getInstance().getDownloadRootPath() + "/download/";
} else {
absolutePath = FileAccessorUtil.getDownloadClientUpGradePath().getAbsolutePath();
}
String str = absolutePath;
String str2 = this.upgradeBean.getFileId() + Constants.APK_SUFFIX;
ZZLog.i("ClientUpgradeHelper", "downloadFile ===fileName=" + str2 + " savePath=" + str, new Object[0]);
DownloadManager.getInstance().downloadFile(this.fileUrl, str2, str, true, new DownloadListener(ClientUpgradeHelper.class.getName(), false) {
@Override
public void onAddTask(DownloadInfo downloadInfo) {
int fraction = (int) (downloadInfo.getFraction() * 100.0f);
ClientUpgradeHelper clientUpgradeHelper = ClientUpgradeHelper.this;
if (clientUpgradeHelper.showUpDateDialog) {
clientUpgradeHelper.pbUpdate.setProgress(fraction);
}
}
@Override
public void onError(DownloadInfo downloadInfo) {
ZZLog.i("ClientUpgradeHelper", "showDownloadDialog downloadFile onError=", new Object[0]);
UiUtils.showToast(ClientUpgradeHelper.this.getActivity(), ClientUpgradeHelper.this.getActivity().getString(R.string.uu_mos_msg_updating_err));
if (ClientUpgradeHelper.this.downloadDialog != null) {
ClientUpgradeHelper clientUpgradeHelper = ClientUpgradeHelper.this;
clientUpgradeHelper.closeDialog(clientUpgradeHelper.downloadDialog);
}
}
@Override
public void onFinish(DownloadInfo downloadInfo) {
ClientUpgradeHelper.this.mTargetPath = downloadInfo.getSaveFileFullPath();
ZZLog.i("ClientUpgradeHelper", "showDownloadDialog downloadFile onFinish mTargetPath=" + ClientUpgradeHelper.this.mTargetPath, new Object[0]);
ClientUpgradeHelper clientUpgradeHelper = ClientUpgradeHelper.this;
if (clientUpgradeHelper.showUpDateDialog) {
clientUpgradeHelper.handleFinishEvent();
} else {
clientUpgradeHelper.startInstall();
}
}
@Override
public void onPause(DownloadInfo downloadInfo) {
}
@Override
public void onProgress(DownloadInfo downloadInfo) {
int fraction = (int) (downloadInfo.getFraction() * 100.0f);
ClientUpgradeHelper clientUpgradeHelper = ClientUpgradeHelper.this;
if (clientUpgradeHelper.showUpDateDialog) {
clientUpgradeHelper.pbUpdate.setProgress(fraction);
}
}
});
}
public void startInstall() {
ZZLog.i("ClientUpgradeHelper", "startInstall ===mTargetPath=" + this.mTargetPath + " forceUpgrade=" + this.forceUpgrade, new Object[0]);
InstallAppInfo installAppInfo = new InstallAppInfo();
installAppInfo.setContext(getActivity());
installAppInfo.setApkPath(this.mTargetPath);
installAppInfo.setPackageName("");
installAppInfo.setStartInstallTime(System.currentTimeMillis());
installAppInfo.setClientUpgrade(true);
installAppInfo.setFromType(CommGlobal.OpenAppFromType.EVENT_CLIENTUPGRADGE);
if (BaseModuleManager.getInstance().getDataModule() != null) {
BaseModuleManager.getInstance().getDataModule().cacheInstallApp(CommGlobal.getPackageName(getActivity()), installAppInfo);
}
ClientUpgradeDetailBean clientUpgradeDetailBean = this.upgradeBean;
if (clientUpgradeDetailBean != null && clientUpgradeDetailBean.getUpdateFlag() > 0 && this.forceUpgrade) {
ZZLog.i("ClientUpgradeHelper", "startInstall installApk=", new Object[0]);
PackageUtils.installApk(installAppInfo);
if (this.showUpDateDialog) {
this.uiHandler.sendEmptyMessageDelayed(1011, 1000L);
}
if (this.showUpDateDialog) {
return;
}
PreferenceUtils.setUpdateVersionName(getActivity(), "3.6.5.2", CommGlobal.getMosKey());
PreferenceUtils.setUpdateVersionCode(getActivity(), 2045211033);
return;
}
ZZLog.i("ClientUpgradeHelper", "startInstall installApk 22=", new Object[0]);
PackageUtils.installApk(installAppInfo);
}
public void a(View view) {
closeDialog(this.mDialog);
CommGlobal.versionChecked = true;
org.greenrobot.eventbus.e.a().c(new NextDialogEvent());
}
public void b(View view) {
ZZLog.i("ClientUpgradeHelper", "dismissDownloadDialog=", new Object[0]);
dismissDownloadDialog();
}
public void closeDialog(final Dialog dialog) {
if (dialog == null || !dialog.isShowing()) {
return;
}
if (Looper.myLooper() == Looper.getMainLooper()) {
close(dialog);
} else {
new Handler(Looper.getMainLooper()).post(new Runnable() {
@Override
public void run() {
ClientUpgradeHelper.this.close(dialog);
}
});
}
}
public void initData(Context context, ClientUpgradeDetailBean clientUpgradeDetailBean) {
this.showUpDateDialog = true;
ZZLog.i("ClientUpgradeHelper", "initData=", new Object[0]);
if (clientUpgradeDetailBean == null) {
ZZLog.i("ClientUpgradeHelper", "initData clientUpgradeDetailBean == null=", new Object[0]);
} else if (getActivity() == null) {
ZZLog.i("ClientUpgradeHelper", "initData getActivity() == null=", new Object[0]);
} else {
this.upgradeBean = clientUpgradeDetailBean;
this.mClientVersion = this.upgradeBean.getClientVersionName();
this.mUpdateDescription = this.upgradeBean.getDescription();
this.fileUrl = this.upgradeBean.getFileUrl();
this.forceUpgrade = this.upgradeBean.getUpdateFlag() == 2;
this.fileMd5 = clientUpgradeDetailBean.getFileMd5();
if (BaseModuleManager.getInstance().getEmmModule() != null && PreferenceUtils.isMdm(getActivity()) && this.forceUpgrade) {
this.showUpDateDialog = false;
}
if (this.upgradeBean.getUpdateFlag() > 0) {
ZZLog.i("ClientUpgradeHelper", "checkApkExist=", new Object[0]);
checkApkExist();
return;
}
ZZLog.i("ClientUpgradeHelper", "initSameVersion=", new Object[0]);
initSameVersion();
}
}
public void showDialog(final boolean z) {
ZZLog.i("ClientUpgradeHelper", "showDialog isNewVersion=" + z, new Object[0]);
if (!this.showUpDateDialog) {
if (z) {
doUpdate();
}
org.greenrobot.eventbus.e.a().c(new NextDialogEvent());
return;
}
int i = 17;
ClientUpgradeDetailBean clientUpgradeDetailBean = this.upgradeBean;
if (clientUpgradeDetailBean != null && clientUpgradeDetailBean.getUpdateFlag() > 0) {
i = GravityCompat.START;
}
ZZLog.i("ClientUpgradeHelper", "showDialog mDialog.show() isNewVersion=" + z + " appInBackground=" + CommGlobal.appInBackground, new Object[0]);
this.mDialog = new CommonDialog.Builder(getActivity()).setCancelable(this.cancelable).setTitleShow(this.showTitle).setTitle(this.titleText).setMessage(this.msgText).setMessageTextColor(R.color.uu_ic_description_text_color).setMessageGravity(i).setNegativeBtnShow(this.showNegative).setNegativeText(getActivity().getString(R.string.uu_mos_btn_update_cancel)).setNegativeTextColor(R.color.uu_ic_description_text_color).setPositiveText(this.positiveText).setNegativeListener(new View.OnClickListener() {
@Override
public final void onClick(View view) {
ClientUpgradeHelper.this.a(view);
}
}).setPositiveListener(new View.OnClickListener() {
@Override
public final void onClick(View view) {
ClientUpgradeHelper.this.a(z, view);
}
}).setOnKeyListener(this.onBackKeyListener).create();
this.mDialog.show();
}
public void a(boolean z, View view) {
if (z) {
doUpdate();
}
org.greenrobot.eventbus.e.a().c(new NextDialogEvent());
}
public void a(DialogInterface dialogInterface) {
dismissAll();
}
}