[3.2.0][应用升级] 增加EB5设备静默升级功能
This commit is contained in:
@@ -7,6 +7,9 @@ import com.mogo.commons.constants.*
|
|||||||
import com.mogo.commons.utils.*
|
import com.mogo.commons.utils.*
|
||||||
import com.mogo.eagle.core.data.config.*
|
import com.mogo.eagle.core.data.config.*
|
||||||
import com.mogo.eagle.core.data.deva.bindingcar.*
|
import com.mogo.eagle.core.data.deva.bindingcar.*
|
||||||
|
import com.mogo.eagle.core.function.api.devatools.download.DownloadType.APK
|
||||||
|
import com.mogo.eagle.core.function.api.devatools.download.DownloadType.PATCH
|
||||||
|
import com.mogo.eagle.core.function.call.devatools.*
|
||||||
import com.mogo.eagle.core.function.call.devatools.CallerDevaToolsManager.upgradeProvider
|
import com.mogo.eagle.core.function.call.devatools.CallerDevaToolsManager.upgradeProvider
|
||||||
import com.mogo.eagle.core.function.call.hmi.CallerHmiManager.showUpgradeDialog
|
import com.mogo.eagle.core.function.call.hmi.CallerHmiManager.showUpgradeDialog
|
||||||
import com.mogo.eagle.core.function.call.patch.CallerPatchManager.addPatchInfo
|
import com.mogo.eagle.core.function.call.patch.CallerPatchManager.addPatchInfo
|
||||||
@@ -122,8 +125,13 @@ class UpgradeAppNetWorkManager private constructor() {
|
|||||||
Log.d("ApkInstaller", "走全量升级 --- 1 ----")
|
Log.d("ApkInstaller", "走全量升级 --- 1 ----")
|
||||||
provider?.recordUpgradeRecord(info.result.versionName, null, 0)
|
provider?.recordUpgradeRecord(info.result.versionName, null, 0)
|
||||||
}
|
}
|
||||||
withContext(Dispatchers.Main) {
|
if (ApkInstaller.isInstallAppStore(Utils.getApp()) && ApkInstaller.isEB5Device(Utils.getApp())) {
|
||||||
showUpgradeDialog(downloadUrl.substring(downloadUrl.lastIndexOf("/") + 1), downloadUrl, info.result.installTitle, info.result.installContent, info.result.installType)
|
Log.d("ApkInstaller", "EB5设备,直接走静默,不弹窗...")
|
||||||
|
CallerDevaToolsManager.downLoadPackage(if (isGoFullUpgrade) APK else PATCH, downloadUrl.substring(downloadUrl.lastIndexOf("/") + 1), downloadUrl)
|
||||||
|
} else {
|
||||||
|
withContext(Dispatchers.Main) {
|
||||||
|
showUpgradeDialog(downloadUrl.substring(downloadUrl.lastIndexOf("/") + 1), downloadUrl, info.result.installTitle, info.result.installContent, info.result.installType)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
deleteApkFile()
|
deleteApkFile()
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
<?xml version="1.0" encoding="utf-8"?>
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
|
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
|
xmlns:tools="http://schemas.android.com/tools"
|
||||||
package="com.mogo.eagle.core.utilcode.util">
|
package="com.mogo.eagle.core.utilcode.util">
|
||||||
|
|
||||||
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
|
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
|
||||||
@@ -38,6 +39,14 @@
|
|||||||
|
|
||||||
<receiver android:name=".NetworkUtils$NetworkChangedReceiver" />
|
<receiver android:name=".NetworkUtils$NetworkChangedReceiver" />
|
||||||
|
|
||||||
|
<receiver android:name=".FoTaSilentUpgradeReceiver"
|
||||||
|
android:exported="true"
|
||||||
|
tools:ignore="ExportedReceiver">
|
||||||
|
<intent-filter>
|
||||||
|
<action android:name="com.mogo.launcher.f.receiver.install_result" />
|
||||||
|
</intent-filter>
|
||||||
|
</receiver>
|
||||||
|
|
||||||
<activity android:name=".InstallApkSessionApi"
|
<activity android:name=".InstallApkSessionApi"
|
||||||
android:exported="true"
|
android:exported="true"
|
||||||
android:theme="@style/ActivityTranslucent"
|
android:theme="@style/ActivityTranslucent"
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
package com.mogo.eagle.core.utilcode.download;
|
package com.mogo.eagle.core.utilcode.download;
|
||||||
|
|
||||||
import android.os.Environment;
|
import com.mogo.eagle.core.utilcode.util.Utils;
|
||||||
|
import java.io.File;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Created by kun on 2016/11/10.
|
* Created by kun on 2016/11/10.
|
||||||
@@ -10,20 +11,15 @@ public class Config {
|
|||||||
/**
|
/**
|
||||||
* 文件下载地址
|
* 文件下载地址
|
||||||
*/
|
*/
|
||||||
public final static String downLoadPath = Environment.getExternalStorageDirectory().getAbsolutePath()
|
public final static String downLoadPath = new File(Utils.getApp().getExternalFilesDir(null), "downloads").getAbsolutePath();
|
||||||
+ "/downloads/";
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* OBU下载路径
|
* OBU下载路径
|
||||||
*/
|
*/
|
||||||
public final static String downLoadObuPath = Environment.getExternalStorageDirectory().getAbsolutePath()
|
public final static String downLoadObuPath = new File(Utils.getApp().getExternalFilesDir(null), "obu").getAbsolutePath();
|
||||||
+ "/obu/";
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* OBU解压路径
|
* OBU解压路径
|
||||||
*/
|
*/
|
||||||
public final static String downLoadUnzipObuPath = Environment.getExternalStorageDirectory().getAbsolutePath()
|
public final static String downLoadUnzipObuPath = new File(Utils.getApp().getExternalFilesDir(null), "obuunzip").getAbsolutePath();
|
||||||
+ "/obuunzip/";
|
|
||||||
|
|
||||||
public final static String DOWN_LOAD_TAG = "Package-DownLoad";
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
package com.mogo.eagle.core.utilcode.util
|
package com.mogo.eagle.core.utilcode.util
|
||||||
|
|
||||||
|
import android.annotation.*
|
||||||
import android.app.*
|
import android.app.*
|
||||||
import android.content.*
|
import android.content.*
|
||||||
import android.content.pm.PackageInstaller.*
|
import android.content.pm.PackageInstaller.*
|
||||||
@@ -9,6 +10,7 @@ import android.widget.*
|
|||||||
import androidx.appcompat.app.*
|
import androidx.appcompat.app.*
|
||||||
import com.mogo.eagle.core.utilcode.util.ApkInstaller.Companion.INSTALL_CODE_INVALID
|
import com.mogo.eagle.core.utilcode.util.ApkInstaller.Companion.INSTALL_CODE_INVALID
|
||||||
import java.io.*
|
import java.io.*
|
||||||
|
import java.lang.ref.WeakReference
|
||||||
|
|
||||||
|
|
||||||
class ApkInstaller {
|
class ApkInstaller {
|
||||||
@@ -34,10 +36,55 @@ class ApkInstaller {
|
|||||||
block?.invoke(INSTALL_CODE_INVALID, msg)
|
block?.invoke(INSTALL_CODE_INVALID, msg)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
val intent = Intent(context, InstallApkSessionApi::class.java)
|
Log.d("AppInstallReceiver", "-- installApp --")
|
||||||
intent.putExtra("APK_FILE_PATH", apkFile.absolutePath)
|
if (isInstallAppStore(context) && isEB5Device(context)) {
|
||||||
block?.also { InstallApkSessionApi.listener = it }
|
Log.d("AppInstallReceiver", "-- installApp -- 1 --")
|
||||||
context.startActivity(intent)
|
val intent = Intent("com.mogo.INSTALL_REQUEST")
|
||||||
|
intent.setPackage("com.mogo.appstore")
|
||||||
|
intent.addFlags(Intent.FLAG_INCLUDE_STOPPED_PACKAGES)
|
||||||
|
intent.putExtra("command", "install_apk")
|
||||||
|
intent.putExtra("is_open", false)
|
||||||
|
intent.putExtra("is_forced", false)
|
||||||
|
intent.putExtra("apk_path", apkFile.absolutePath)
|
||||||
|
intent.putExtra("apk_pkg", context.packageName)
|
||||||
|
context.sendBroadcast(intent)
|
||||||
|
FoTaSilentUpgradeReceiver.contextHolder = WeakReference(context)
|
||||||
|
FoTaSilentUpgradeReceiver.listener = block
|
||||||
|
} else {
|
||||||
|
Log.d("AppInstallReceiver", "-- installApp -- 2 --")
|
||||||
|
val intent = Intent(context, InstallApkSessionApi::class.java)
|
||||||
|
intent.putExtra("APK_FILE_PATH", apkFile.absolutePath)
|
||||||
|
block?.also { InstallApkSessionApi.listener = it }
|
||||||
|
context.startActivity(intent)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@JvmStatic
|
||||||
|
fun isInstallAppStore(ctx: Context): Boolean {
|
||||||
|
val installedPackages = ctx.packageManager.getInstalledPackages(0)
|
||||||
|
return installedPackages.find { it.packageName == "com.mogo.appstore" } != null
|
||||||
|
}
|
||||||
|
|
||||||
|
@JvmStatic
|
||||||
|
fun isEB5Device(ctx: Context): Boolean {
|
||||||
|
val sn: String = getSystemPropertyByReflect("persist.device.sn")
|
||||||
|
return sn.startsWith("ZT", true)
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun getSystemPropertyByReflect(key: String): String {
|
||||||
|
try {
|
||||||
|
@SuppressLint("PrivateApi")
|
||||||
|
val clz = Class.forName("android.os.SystemProperties")
|
||||||
|
val getMethod = clz.getMethod(
|
||||||
|
"get",
|
||||||
|
String::class.java,
|
||||||
|
String::class.java
|
||||||
|
)
|
||||||
|
return getMethod.invoke(clz, key, "2") as String
|
||||||
|
} catch (e: Exception) {
|
||||||
|
e.printStackTrace()
|
||||||
|
}
|
||||||
|
return ""
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -164,3 +211,32 @@ class InstallApkSessionApi: AppCompatActivity() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
class FoTaSilentUpgradeReceiver: BroadcastReceiver() {
|
||||||
|
|
||||||
|
companion object {
|
||||||
|
|
||||||
|
@Volatile
|
||||||
|
var contextHolder: WeakReference<Context>? = null
|
||||||
|
|
||||||
|
@Volatile
|
||||||
|
var listener: ((Int, String) -> Unit)? = null
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun onReceive(context: Context?, intent: Intent?) {
|
||||||
|
try {
|
||||||
|
Log.d("AppInstallReceiver", "-- onReceive: --- 1 ---")
|
||||||
|
val i = intent ?: return
|
||||||
|
Log.d("AppInstallReceiver", "-- onReceive: --- 2 ---")
|
||||||
|
if (i.hasExtra("code") && i.hasExtra("msg")) {
|
||||||
|
val code = i.getIntExtra("code", -1)
|
||||||
|
val msg = i.getStringExtra("msg") ?: "未知异常"
|
||||||
|
Log.d("AppInstallReceiver", "-- onReceive: --- 3 ---:[code: $code, msg: $msg]")
|
||||||
|
listener?.invoke(code, msg)
|
||||||
|
}
|
||||||
|
} finally {
|
||||||
|
listener = null
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user