增加全局更新

This commit is contained in:
2022-09-06 17:15:23 +08:00
parent 5c229e46d1
commit a0723355e1
18 changed files with 399 additions and 67 deletions

View File

@@ -7,11 +7,13 @@ import android.content.ContentResolver;
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
import android.content.pm.PackageInfo;
import android.content.pm.PackageManager;
import android.content.res.Resources;
import android.media.AudioManager;
import android.net.ConnectivityManager;
import android.net.wifi.WifiManager;
import android.os.Build;
import android.os.Environment;
import android.os.Handler;
import android.provider.Settings;
@@ -51,6 +53,7 @@ import com.uiui.sn.utils.ApkUtils;
import com.uiui.sn.utils.CacheUtils;
import com.uiui.sn.utils.CmdUtil;
import com.uiui.sn.gson.GsonUtils;
import com.uiui.sn.utils.FileUtils;
import com.uiui.sn.utils.JGYUtils;
import com.uiui.sn.utils.SPUtils;
import com.uiui.sn.utils.ServiceAliveUtils;
@@ -553,8 +556,8 @@ public class MessageReceiver extends XGPushBaseReceiver {
case JIGUANG_FORCE_INSTALLAPK:
ToastUtil.debugShow("收到推送消息: 强制安装应用");
NetInterfaceManager.getInstance().getAllappPackage();
NetInterfaceManager.getInstance().getForceInstall();
// intallApk(context, extras);
NetInterfaceManager.getInstance().getOverallApp();
intallApk(context, extras);
break;
case JIGUANG_FORCE_UNINSTALLAPK:
ToastUtil.debugShow("收到推送消息: 强制卸载应用");
@@ -998,35 +1001,41 @@ public class MessageReceiver extends XGPushBaseReceiver {
}
}
//静默安装应用使用okgo断网会出现问题等待修改使用aria
synchronized private void intallApk(Context context, String jsonString) {
private void intallApk(Context context, String jsonString) {
if (TextUtils.isEmpty(jsonString)) {
return;
}
// NetInterfaceManager.getInstance().getAllAppPackageName(context);
JsonObject extra = GsonUtils.getJsonObject(jsonString);
final String packages = extra.get("package").getAsString();
String packages = extra.get("package").getAsString();
ToastUtil.debugShow("收到应用安装消息:包名" + packages);
String url = extra.get("url").getAsString();
if (TextUtils.isEmpty(url)) {
return;
}
if (Aria.download(this).taskExists(url)) {
List<DownloadEntity> entity = Aria.download(this).getDownloadEntity(url);
for (DownloadEntity downloadEntity : entity) {
Aria.download(this).load(downloadEntity.getId()).cancel(true);
}
long app_version_code = extra.get("app_version_code").getAsLong();
PackageInfo info = null;
PackageManager pm = context.getPackageManager();
try {
info = pm.getPackageInfo(packages, 0);
} catch (PackageManager.NameNotFoundException e) {
e.printStackTrace();
}
if (null != info) {
long appVersionCode;
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.P) {
appVersionCode = info.getLongVersionCode();
} else {
appVersionCode = info.versionCode;
}
if (appVersionCode < app_version_code) {
Log.e(TAG, "intallApk: " + "need to upgrade");
FileUtils.ariaDownload(context, url, extra);
} else
Log.e(TAG, "intallApk: " + "it's up to date , no need upgrade");
} else {
Log.e(TAG, "intallApk: " + "not installed , upgrade");
FileUtils.ariaDownload(context, url, extra);
}
File file = new File(Environment.getExternalStoragePublicDirectory("Download") + "/Sninfo/apk");
file.mkdirs();
Aria.download(this)
.load(url)
.setFilePath(JGYUtils.getInstance().getDownLoadPath() + packages + ".apk")
.ignoreFilePathOccupy()
.setExtendField(packages).create();
Aria.download(this).resumeAllTask();
}
synchronized private void unintallApk(Context context, String jsonString) {