analysis: full official-app reverse artifacts (jadx sources, ghidra libcxsdk decomp, authoritative protocol conclusions) + docs
This commit is contained in:
@@ -0,0 +1,315 @@
|
||||
package cn.com.magnity.magnitycx.upgrade;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.app.AlertDialog;
|
||||
import android.app.ProgressDialog;
|
||||
import android.content.Context;
|
||||
import android.content.DialogInterface;
|
||||
import android.content.Intent;
|
||||
import android.content.pm.PackageInfo;
|
||||
import android.content.pm.PackageManager;
|
||||
import android.content.res.Configuration;
|
||||
import android.net.Uri;
|
||||
import android.os.Build;
|
||||
import android.os.Bundle;
|
||||
import android.os.Environment;
|
||||
import android.os.Handler;
|
||||
import android.os.Message;
|
||||
import android.support.v4.content.FileProvider;
|
||||
import cn.com.magnity.magnitycx.MagApplication;
|
||||
import cn.com.magnity.magnitycx.MainActivity;
|
||||
import cn.com.magnity.magnitycx.R;
|
||||
import cn.com.magnity.magnitycx.log.Logging;
|
||||
import java.io.File;
|
||||
import java.util.Locale;
|
||||
import org.apache.log4j.Priority;
|
||||
import org.json.JSONArray;
|
||||
import org.json.JSONObject;
|
||||
|
||||
/* loaded from: classes.dex */
|
||||
public class CheckVersionTask implements Runnable {
|
||||
private static final int CHECK_ERROR = -1;
|
||||
private static final int CHECK_OK = 0;
|
||||
private static final String UPGRADEINFO_DESC = "description";
|
||||
private static final String UPGRADEINFO_FORCE = "forceUpgrade";
|
||||
private static final String UPGRADEINFO_URL = "url";
|
||||
private static final String UPGRADEINFO_VERSIONCODE = "versionCode";
|
||||
private static final String UPGRADEINFO_VERSIONNAME = "versionName";
|
||||
public static final int UPGRADE_BEGIN = 1;
|
||||
private static final int UPGRADE_ERROR = -2;
|
||||
public static final int UPGRADE_FINISHED = 3;
|
||||
public static final int UPGRADE_RECEIVED_SIZE = 2;
|
||||
private Context ctx_;
|
||||
private boolean isForceUpgrade_;
|
||||
private int localVersion_;
|
||||
Handler handler_ = new Handler() { // from class: cn.com.magnity.magnitycx.upgrade.CheckVersionTask.1
|
||||
@Override // android.os.Handler
|
||||
public void handleMessage(Message msg) {
|
||||
super.handleMessage(msg);
|
||||
switch (msg.what) {
|
||||
case -2:
|
||||
if (CheckVersionTask.this.progressDialog_ != null) {
|
||||
CheckVersionTask.this.progressDialog_.dismiss();
|
||||
CheckVersionTask.this.progressDialog_ = null;
|
||||
}
|
||||
AlertDialog.Builder builder = new AlertDialog.Builder(CheckVersionTask.this.ctx_);
|
||||
builder.setTitle(R.string.upgradeError);
|
||||
builder.setPositiveButton(R.string.labelOK, new DialogInterface.OnClickListener() { // from class: cn.com.magnity.magnitycx.upgrade.CheckVersionTask.1.1
|
||||
@Override // android.content.DialogInterface.OnClickListener
|
||||
public void onClick(DialogInterface dialog, int which) {
|
||||
CheckVersionTask.this.unlockScreen();
|
||||
}
|
||||
});
|
||||
AlertDialog dialog = builder.create();
|
||||
dialog.setCanceledOnTouchOutside(false);
|
||||
dialog.show();
|
||||
break;
|
||||
case -1:
|
||||
CheckVersionTask.this.unlockScreen();
|
||||
break;
|
||||
case 0:
|
||||
CheckVersionTask.this.lockScreen();
|
||||
Bundle bundle = msg.getData();
|
||||
CheckVersionTask.this.isForceUpgrade_ = bundle.getBoolean(CheckVersionTask.UPGRADEINFO_FORCE);
|
||||
CheckVersionTask.this.showUpgradeDialog(bundle.getString(CheckVersionTask.UPGRADEINFO_DESC), bundle.getString(CheckVersionTask.UPGRADEINFO_URL), bundle.getString(CheckVersionTask.UPGRADEINFO_VERSIONNAME), bundle.getInt(CheckVersionTask.UPGRADEINFO_VERSIONCODE), CheckVersionTask.this.isForceUpgrade_);
|
||||
break;
|
||||
case 1:
|
||||
CheckVersionTask.this.progressDialog_ = new ProgressDialog(CheckVersionTask.this.ctx_);
|
||||
CheckVersionTask.this.progressDialog_.setOnCancelListener(new DialogInterface.OnCancelListener() { // from class: cn.com.magnity.magnitycx.upgrade.CheckVersionTask.1.2
|
||||
@Override // android.content.DialogInterface.OnCancelListener
|
||||
public void onCancel(DialogInterface dialog2) {
|
||||
CheckVersionTask.this.stopDownloadApk();
|
||||
CheckVersionTask.this.unlockScreen();
|
||||
if (CheckVersionTask.this.isForceUpgrade_ && (CheckVersionTask.this.ctx_ instanceof MainActivity)) {
|
||||
((MainActivity) CheckVersionTask.this.ctx_).onBackPressed();
|
||||
}
|
||||
}
|
||||
});
|
||||
CheckVersionTask.this.progressDialog_.setProgressStyle(1);
|
||||
CheckVersionTask.this.progressDialog_.setMessage(CheckVersionTask.this.ctx_.getResources().getString(R.string.upgrading));
|
||||
CheckVersionTask.this.progressDialog_.setProgressNumberFormat("%1d KB/%2d KB");
|
||||
CheckVersionTask.this.progressDialog_.setProgress(0);
|
||||
CheckVersionTask.this.progressDialog_.setMax(msg.arg1 / 1000);
|
||||
CheckVersionTask.this.progressDialog_.setCanceledOnTouchOutside(false);
|
||||
CheckVersionTask.this.progressDialog_.show();
|
||||
break;
|
||||
case 2:
|
||||
if (CheckVersionTask.this.progressDialog_ != null) {
|
||||
CheckVersionTask.this.progressDialog_.setProgress(msg.arg1 / 1000);
|
||||
break;
|
||||
}
|
||||
break;
|
||||
case 3:
|
||||
if (CheckVersionTask.this.progressDialog_ != null) {
|
||||
CheckVersionTask.this.progressDialog_.dismiss();
|
||||
CheckVersionTask.this.progressDialog_ = null;
|
||||
}
|
||||
CheckVersionTask.this.unlockScreen();
|
||||
if (msg.obj != null && (msg.obj instanceof File)) {
|
||||
CheckVersionTask.this.installApk((File) msg.obj);
|
||||
break;
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
};
|
||||
private ProgressDialog progressDialog_ = null;
|
||||
private Thread threadUpgrading_ = null;
|
||||
|
||||
public CheckVersionTask(Context ctx, int localVersion) {
|
||||
this.ctx_ = ctx;
|
||||
this.localVersion_ = localVersion;
|
||||
}
|
||||
|
||||
public void stopDownload() {
|
||||
stopDownloadApk();
|
||||
}
|
||||
|
||||
public UpgradeInfo parseVersionInfo(String str) throws Exception {
|
||||
UpgradeInfo info = null;
|
||||
JSONObject object = new JSONObject(str);
|
||||
if (object != null && object.length() >= 1) {
|
||||
String productType = this.ctx_.getString(R.string.upgradeID);
|
||||
if (object.has(productType)) {
|
||||
JSONArray array = object.getJSONArray(productType);
|
||||
if (array.length() > 0) {
|
||||
JSONObject obj = array.getJSONObject(array.length() - 1);
|
||||
info = new UpgradeInfo();
|
||||
if (obj.has("verName")) {
|
||||
info.setVersionName(obj.getString("verName"));
|
||||
}
|
||||
if (obj.has("verCode")) {
|
||||
info.setVersionCode(obj.getInt("verCode"));
|
||||
}
|
||||
if (obj.has("apkUrl")) {
|
||||
info.setApkUrl(obj.getString("apkUrl"));
|
||||
}
|
||||
try {
|
||||
Configuration config = this.ctx_.getResources().getConfiguration();
|
||||
if (!config.locale.getLanguage().equals(Locale.CHINA.getLanguage()) || !config.locale.getCountry().equals(Locale.CHINA.getCountry())) {
|
||||
if (obj.has("description-en")) {
|
||||
info.setDescription(obj.getString("description-en"));
|
||||
}
|
||||
} else if (obj.has(UPGRADEINFO_DESC)) {
|
||||
info.setDescription(obj.getString(UPGRADEINFO_DESC));
|
||||
}
|
||||
} catch (Exception e) {
|
||||
}
|
||||
if (obj.has(UPGRADEINFO_FORCE)) {
|
||||
info.setForceUpgrade(obj.getBoolean(UPGRADEINFO_FORCE));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return info;
|
||||
}
|
||||
|
||||
/* JADX INFO: Access modifiers changed from: private */
|
||||
public void lockScreen() {
|
||||
if (this.ctx_ instanceof Activity) {
|
||||
((Activity) this.ctx_).setRequestedOrientation(14);
|
||||
}
|
||||
}
|
||||
|
||||
/* JADX INFO: Access modifiers changed from: private */
|
||||
public void unlockScreen() {
|
||||
if (this.ctx_ instanceof Activity) {
|
||||
((Activity) this.ctx_).setRequestedOrientation(10);
|
||||
}
|
||||
}
|
||||
|
||||
@Override // java.lang.Runnable
|
||||
public void run() {
|
||||
String path = this.ctx_.getResources().getString(R.string.remote_url);
|
||||
try {
|
||||
String str = HttpHelper.GetRemoteVersionInfo(path, 10000, Priority.INFO_INT);
|
||||
UpgradeInfo upgradeInfo = parseVersionInfo(str);
|
||||
if (upgradeInfo == null) {
|
||||
Logging.info("Parse version info fail.");
|
||||
this.handler_.sendEmptyMessage(-1);
|
||||
} else if (upgradeInfo.getVersionCode() > this.localVersion_) {
|
||||
Logging.info("New app version is detected(" + upgradeInfo.getVersionCode() + ")");
|
||||
Message msg = new Message();
|
||||
msg.what = 0;
|
||||
Bundle bundle = new Bundle();
|
||||
bundle.putBoolean(UPGRADEINFO_FORCE, upgradeInfo.isForceUpgrade());
|
||||
bundle.putString(UPGRADEINFO_DESC, upgradeInfo.getDescription());
|
||||
bundle.putString(UPGRADEINFO_URL, upgradeInfo.getApkUrl());
|
||||
bundle.putString(UPGRADEINFO_VERSIONNAME, upgradeInfo.getVersionName());
|
||||
bundle.putInt(UPGRADEINFO_VERSIONCODE, upgradeInfo.getVersionCode());
|
||||
msg.setData(bundle);
|
||||
this.handler_.sendMessage(msg);
|
||||
}
|
||||
} catch (Exception ex) {
|
||||
this.handler_.sendEmptyMessage(-1);
|
||||
Logging.error("Check upgrade error(" + ex.getMessage() + ")");
|
||||
}
|
||||
}
|
||||
|
||||
/* JADX INFO: Access modifiers changed from: private */
|
||||
public void showUpgradeDialog(String description, final String url, final String versionName, final int versionCode, boolean isForceUpgrade) {
|
||||
AlertDialog.Builder builer = new AlertDialog.Builder(this.ctx_);
|
||||
builer.setTitle(this.ctx_.getResources().getString(R.string.upgrade) + "(V" + versionName + ")");
|
||||
builer.setMessage(description);
|
||||
builer.setPositiveButton(R.string.labelOK, new DialogInterface.OnClickListener() { // from class: cn.com.magnity.magnitycx.upgrade.CheckVersionTask.2
|
||||
@Override // android.content.DialogInterface.OnClickListener
|
||||
public void onClick(DialogInterface dialog, int which) {
|
||||
String path = MagApplication.magParameter.otherDir + File.separator + "MAG-Cx." + versionName + ".apk";
|
||||
File file = new File(path);
|
||||
if (file.exists()) {
|
||||
PackageManager pm = CheckVersionTask.this.ctx_.getPackageManager();
|
||||
PackageInfo packInfo = pm.getPackageArchiveInfo(path, 1);
|
||||
if (packInfo == null || packInfo.versionCode != versionCode) {
|
||||
CheckVersionTask.this.startDownloadApk(url, versionName);
|
||||
return;
|
||||
} else {
|
||||
CheckVersionTask.this.installApk(file);
|
||||
return;
|
||||
}
|
||||
}
|
||||
CheckVersionTask.this.startDownloadApk(url, versionName);
|
||||
}
|
||||
});
|
||||
if (!isForceUpgrade) {
|
||||
builer.setNegativeButton(R.string.labelCancel, new DialogInterface.OnClickListener() { // from class: cn.com.magnity.magnitycx.upgrade.CheckVersionTask.3
|
||||
@Override // android.content.DialogInterface.OnClickListener
|
||||
public void onClick(DialogInterface dialog, int which) {
|
||||
CheckVersionTask.this.unlockScreen();
|
||||
}
|
||||
});
|
||||
} else {
|
||||
builer.setOnCancelListener(new DialogInterface.OnCancelListener() { // from class: cn.com.magnity.magnitycx.upgrade.CheckVersionTask.4
|
||||
@Override // android.content.DialogInterface.OnCancelListener
|
||||
public void onCancel(DialogInterface dialog) {
|
||||
if (CheckVersionTask.this.ctx_ instanceof MainActivity) {
|
||||
((MainActivity) CheckVersionTask.this.ctx_).onBackPressed();
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
AlertDialog dialog = builer.create();
|
||||
dialog.setCanceledOnTouchOutside(false);
|
||||
dialog.show();
|
||||
}
|
||||
|
||||
/* JADX INFO: Access modifiers changed from: private */
|
||||
public void startDownloadApk(final String url, final String version) {
|
||||
HttpHelper.isCancelled = false;
|
||||
this.threadUpgrading_ = new Thread() { // from class: cn.com.magnity.magnitycx.upgrade.CheckVersionTask.5
|
||||
@Override // java.lang.Thread, java.lang.Runnable
|
||||
public void run() {
|
||||
try {
|
||||
File file = HttpHelper.getRemoteApk(url, version, 10000, 30000, CheckVersionTask.this.handler_);
|
||||
if (file == null) {
|
||||
CheckVersionTask.this.handler_.sendEmptyMessage(-2);
|
||||
} else {
|
||||
CheckVersionTask.this.handler_.sendMessage(CheckVersionTask.this.handler_.obtainMessage(3, file));
|
||||
}
|
||||
} catch (Exception ex) {
|
||||
Logging.error("Upgrading error(" + ex.getMessage() + ")");
|
||||
CheckVersionTask.this.handler_.sendEmptyMessage(-2);
|
||||
}
|
||||
}
|
||||
};
|
||||
this.threadUpgrading_.start();
|
||||
}
|
||||
|
||||
/* JADX INFO: Access modifiers changed from: private */
|
||||
public void stopDownloadApk() {
|
||||
HttpHelper.isCancelled = true;
|
||||
try {
|
||||
this.threadUpgrading_.join(500L);
|
||||
this.threadUpgrading_ = null;
|
||||
} catch (Exception e) {
|
||||
this.threadUpgrading_ = null;
|
||||
}
|
||||
}
|
||||
|
||||
private File getOthersStoragePath(Context context) {
|
||||
File file;
|
||||
String state = Environment.getExternalStorageState();
|
||||
if ("mounted".equals(state) && (file = new File(Environment.getExternalStorageDirectory(), "magnity/Cx/others")) != null) {
|
||||
if (!file.exists()) {
|
||||
file.mkdirs();
|
||||
return file;
|
||||
}
|
||||
return file;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
/* JADX INFO: Access modifiers changed from: private */
|
||||
public void installApk(File file) {
|
||||
Intent installIntent = new Intent("android.intent.action.VIEW");
|
||||
installIntent.setFlags(268435456);
|
||||
File usedFile = new File(getOthersStoragePath(this.ctx_), file.getName());
|
||||
if (Build.VERSION.SDK_INT >= 24) {
|
||||
installIntent.setFlags(1);
|
||||
Uri contentUri = FileProvider.getUriForFile(this.ctx_, "cn.com.magnity.magnitycx.fileprovider", usedFile);
|
||||
installIntent.setDataAndType(contentUri, "application/vnd.android.package-archive");
|
||||
} else {
|
||||
installIntent.setDataAndType(Uri.fromFile(usedFile), "application/vnd.android.package-archive");
|
||||
}
|
||||
this.ctx_.startActivity(installIntent);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,224 @@
|
||||
package cn.com.magnity.magnitycx.upgrade;
|
||||
|
||||
import android.os.Handler;
|
||||
import cn.com.magnity.magnitycx.MagApplication;
|
||||
import cn.com.magnity.magnitycx.log.Logging;
|
||||
import java.io.BufferedInputStream;
|
||||
import java.io.BufferedReader;
|
||||
import java.io.File;
|
||||
import java.io.FileOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.io.InputStreamReader;
|
||||
import java.net.HttpURLConnection;
|
||||
import java.net.URL;
|
||||
|
||||
/* loaded from: classes.dex */
|
||||
public class HttpHelper {
|
||||
public static volatile boolean isCancelled;
|
||||
|
||||
public static String GetRemoteVersionInfo(String path, int connTimeout, int readTimeout) throws Exception {
|
||||
String str;
|
||||
BufferedReader br = null;
|
||||
InputStream is = null;
|
||||
try {
|
||||
URL url = new URL(path);
|
||||
HttpURLConnection conn = (HttpURLConnection) url.openConnection();
|
||||
conn.setConnectTimeout(connTimeout);
|
||||
conn.setReadTimeout(readTimeout);
|
||||
conn.setRequestMethod("GET");
|
||||
conn.setRequestProperty("Accept-Language", "zh-CN");
|
||||
conn.setRequestProperty("Charset", "UTF-8");
|
||||
conn.setRequestProperty("Connextion", "Keep-Alive");
|
||||
int code = conn.getResponseCode();
|
||||
if (code == 302) {
|
||||
URL url2 = new URL(conn.getHeaderField("Location"));
|
||||
conn = (HttpURLConnection) url2.openConnection();
|
||||
conn.setConnectTimeout(connTimeout);
|
||||
conn.setReadTimeout(readTimeout);
|
||||
conn.setRequestMethod("GET");
|
||||
conn.setRequestProperty("Accept-Language", "zh-CN");
|
||||
conn.setRequestProperty("Charset", "UTF-8");
|
||||
conn.setRequestProperty("Connextion", "Keep-Alive");
|
||||
code = conn.getResponseCode();
|
||||
}
|
||||
if (code == 200) {
|
||||
is = conn.getInputStream();
|
||||
BufferedReader br2 = new BufferedReader(new InputStreamReader(is));
|
||||
try {
|
||||
StringBuffer stringBuffer = new StringBuffer("");
|
||||
String newLine = System.getProperty("line.separator");
|
||||
while (true) {
|
||||
String line = br2.readLine();
|
||||
if (line == null) {
|
||||
break;
|
||||
}
|
||||
stringBuffer.append(line + newLine);
|
||||
}
|
||||
if (stringBuffer.length() > 0) {
|
||||
stringBuffer.deleteCharAt(stringBuffer.length() - 1);
|
||||
}
|
||||
br2.close();
|
||||
is.close();
|
||||
str = stringBuffer.toString();
|
||||
if (br2 != null) {
|
||||
try {
|
||||
br2.close();
|
||||
} catch (IOException e) {
|
||||
Logging.error("Fail to get remote info because of io error.");
|
||||
}
|
||||
}
|
||||
if (is != null) {
|
||||
is.close();
|
||||
}
|
||||
} catch (Throwable th) {
|
||||
th = th;
|
||||
br = br2;
|
||||
if (br != null) {
|
||||
try {
|
||||
br.close();
|
||||
} catch (IOException e2) {
|
||||
Logging.error("Fail to get remote info because of io error.");
|
||||
throw th;
|
||||
}
|
||||
}
|
||||
if (is != null) {
|
||||
is.close();
|
||||
}
|
||||
throw th;
|
||||
}
|
||||
} else {
|
||||
Logging.error("Get error respond(" + code + ")");
|
||||
str = "";
|
||||
if (0 != 0) {
|
||||
try {
|
||||
br.close();
|
||||
} catch (IOException e3) {
|
||||
Logging.error("Fail to get remote info because of io error.");
|
||||
}
|
||||
}
|
||||
if (0 != 0) {
|
||||
is.close();
|
||||
}
|
||||
}
|
||||
return str;
|
||||
} catch (Throwable th2) {
|
||||
th = th2;
|
||||
}
|
||||
}
|
||||
|
||||
public static File getRemoteApk(String path, String version, int connTimeout, int readTimeout, Handler handler) throws Exception {
|
||||
File file;
|
||||
FileOutputStream fos;
|
||||
int total;
|
||||
int len;
|
||||
FileOutputStream fos2 = null;
|
||||
BufferedInputStream bis = null;
|
||||
InputStream is = null;
|
||||
try {
|
||||
URL url = new URL(path);
|
||||
HttpURLConnection conn = (HttpURLConnection) url.openConnection();
|
||||
conn.setConnectTimeout(connTimeout);
|
||||
conn.setReadTimeout(readTimeout);
|
||||
conn.setRequestMethod("GET");
|
||||
conn.setRequestProperty("Accept-Language", "zh-CN");
|
||||
conn.setRequestProperty("Charset", "UTF-8");
|
||||
conn.setRequestProperty("Connextion", "Keep-Alive");
|
||||
int code = conn.getResponseCode();
|
||||
if (code == 302) {
|
||||
URL url2 = new URL(conn.getHeaderField("Location"));
|
||||
conn = (HttpURLConnection) url2.openConnection();
|
||||
conn.setConnectTimeout(connTimeout);
|
||||
conn.setReadTimeout(readTimeout);
|
||||
conn.setRequestProperty("Accept-Encoding", "identity");
|
||||
conn.setRequestMethod("GET");
|
||||
conn.setRequestProperty("Accept-Language", "zh-CN");
|
||||
conn.setRequestProperty("Charset", "UTF-8");
|
||||
conn.setRequestProperty("Connextion", "Keep-Alive");
|
||||
code = conn.getResponseCode();
|
||||
}
|
||||
if (code == 200) {
|
||||
int size = conn.getContentLength();
|
||||
handler.sendMessage(handler.obtainMessage(1, size, 0));
|
||||
is = conn.getInputStream();
|
||||
BufferedInputStream bis2 = new BufferedInputStream(is);
|
||||
try {
|
||||
file = new File(MagApplication.magParameter.otherDir, "MAG-Cx." + version + ".apk");
|
||||
if (file.exists()) {
|
||||
file.delete();
|
||||
}
|
||||
fos = new FileOutputStream(file);
|
||||
total = 0;
|
||||
} catch (Throwable th) {
|
||||
th = th;
|
||||
bis = bis2;
|
||||
}
|
||||
try {
|
||||
byte[] buf = new byte[1024];
|
||||
while (!isCancelled && (len = bis2.read(buf)) != -1) {
|
||||
fos.write(buf, 0, len);
|
||||
total += len;
|
||||
handler.sendMessage(handler.obtainMessage(2, total, 0));
|
||||
}
|
||||
fos.close();
|
||||
bis2.close();
|
||||
is.close();
|
||||
if (total != size) {
|
||||
file = null;
|
||||
}
|
||||
if (fos != null) {
|
||||
try {
|
||||
fos.close();
|
||||
} catch (IOException e) {
|
||||
Logging.error("Fail to get remote file because of io error.");
|
||||
}
|
||||
}
|
||||
if (bis2 != null) {
|
||||
bis2.close();
|
||||
}
|
||||
if (is != null) {
|
||||
is.close();
|
||||
}
|
||||
} catch (Throwable th2) {
|
||||
th = th2;
|
||||
bis = bis2;
|
||||
fos2 = fos;
|
||||
if (fos2 != null) {
|
||||
try {
|
||||
fos2.close();
|
||||
} catch (IOException e2) {
|
||||
Logging.error("Fail to get remote file because of io error.");
|
||||
throw th;
|
||||
}
|
||||
}
|
||||
if (bis != null) {
|
||||
bis.close();
|
||||
}
|
||||
if (is != null) {
|
||||
is.close();
|
||||
}
|
||||
throw th;
|
||||
}
|
||||
} else {
|
||||
Logging.error("Get error respond(" + code + ")");
|
||||
file = null;
|
||||
if (0 != 0) {
|
||||
try {
|
||||
fos2.close();
|
||||
} catch (IOException e3) {
|
||||
Logging.error("Fail to get remote file because of io error.");
|
||||
}
|
||||
}
|
||||
if (0 != 0) {
|
||||
bis.close();
|
||||
}
|
||||
if (0 != 0) {
|
||||
is.close();
|
||||
}
|
||||
}
|
||||
return file;
|
||||
} catch (Throwable th3) {
|
||||
th = th3;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,50 @@
|
||||
package cn.com.magnity.magnitycx.upgrade;
|
||||
|
||||
/* loaded from: classes.dex */
|
||||
public class UpgradeInfo {
|
||||
private String apkUrl_;
|
||||
private String description_;
|
||||
private boolean isForceUpgrade_;
|
||||
private int versionCode_;
|
||||
private String versionName_;
|
||||
|
||||
public void setVersionName(String name) {
|
||||
this.versionName_ = name;
|
||||
}
|
||||
|
||||
public String getVersionName() {
|
||||
return this.versionName_;
|
||||
}
|
||||
|
||||
public void setVersionCode(int code) {
|
||||
this.versionCode_ = code;
|
||||
}
|
||||
|
||||
public int getVersionCode() {
|
||||
return this.versionCode_;
|
||||
}
|
||||
|
||||
public void setDescription(String description) {
|
||||
this.description_ = description;
|
||||
}
|
||||
|
||||
public String getDescription() {
|
||||
return this.description_;
|
||||
}
|
||||
|
||||
public void setApkUrl(String url) {
|
||||
this.apkUrl_ = url;
|
||||
}
|
||||
|
||||
public String getApkUrl() {
|
||||
return this.apkUrl_;
|
||||
}
|
||||
|
||||
public void setForceUpgrade(boolean b) {
|
||||
this.isForceUpgrade_ = b;
|
||||
}
|
||||
|
||||
public boolean isForceUpgrade() {
|
||||
return this.isForceUpgrade_;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,67 @@
|
||||
package cn.com.magnity.magnitycx.upgrade;
|
||||
|
||||
import android.content.Context;
|
||||
import android.content.pm.PackageInfo;
|
||||
import android.content.pm.PackageManager;
|
||||
import android.net.ConnectivityManager;
|
||||
import android.net.NetworkInfo;
|
||||
import cn.com.magnity.magnitycx.log.Logging;
|
||||
|
||||
/* loaded from: classes.dex */
|
||||
public class UpgradeManager {
|
||||
private Context ctx_;
|
||||
private CheckVersionTask task_;
|
||||
private Thread thread_;
|
||||
|
||||
public UpgradeManager(Context ctx) {
|
||||
this.ctx_ = ctx;
|
||||
}
|
||||
|
||||
public boolean start() {
|
||||
if (!checkNetWorkStatus(this.ctx_)) {
|
||||
return false;
|
||||
}
|
||||
this.task_ = new CheckVersionTask(this.ctx_, getLocalVersionCode(this.ctx_));
|
||||
this.thread_ = new Thread(this.task_);
|
||||
this.thread_.start();
|
||||
return true;
|
||||
}
|
||||
|
||||
public void stop() {
|
||||
if (this.task_ != null) {
|
||||
this.task_.stopDownload();
|
||||
try {
|
||||
this.thread_.join(500L);
|
||||
} catch (InterruptedException e) {
|
||||
}
|
||||
this.thread_ = null;
|
||||
this.task_ = null;
|
||||
}
|
||||
}
|
||||
|
||||
private int getLocalVersionCode(Context ctx) {
|
||||
PackageManager packageManager = ctx.getPackageManager();
|
||||
try {
|
||||
PackageInfo packInfo = packageManager.getPackageInfo(ctx.getPackageName(), 0);
|
||||
return packInfo.versionCode;
|
||||
} catch (PackageManager.NameNotFoundException ex) {
|
||||
Logging.warn("Fail to get packet name(" + ex.getMessage() + ")");
|
||||
return 100;
|
||||
}
|
||||
}
|
||||
|
||||
public static boolean checkNetWorkStatus(Context context) {
|
||||
try {
|
||||
ConnectivityManager cm = (ConnectivityManager) context.getSystemService("connectivity");
|
||||
NetworkInfo netinfo = cm.getActiveNetworkInfo();
|
||||
if (netinfo != null) {
|
||||
if (netinfo.isConnected()) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
} catch (Exception e) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user