68 lines
2.0 KiB
Java
68 lines
2.0 KiB
Java
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;
|
|
}
|
|
}
|
|
}
|