add back up server ip.
authorTrillGates <williamtrillgates@gmail.com>
Tue, 13 Jul 2021 11:18:45 +0000 (19:18 +0800)
committerTrillGates <williamtrillgates@gmail.com>
Tue, 13 Jul 2021 11:18:45 +0000 (19:18 +0800)
15 files changed:
.idea/codeStyles/Project.xml
app/FotaBrand8521e/debug/Android.mk [deleted file]
app/FotaBrand8521e/debug/FotaBrand8521e_V1_202103081958_debug.apk [deleted file]
app/FotaBrand8521e/debug/output-metadata.json [deleted file]
app/FotaBrand8521e/release/FotaBrand8521e_V1_202106281712_release.apk [new file with mode: 0644]
app/FotaBrand8521e/release/output-metadata.json [moved from app/FotaBrand8541e/release/output-metadata.json with 67% similarity]
app/FotaBrand8541e/release/FotaBrand8541e_V1_202103181928_release.apk [deleted file]
app/src/main/java/com/ic/icfotaclient/bean/OtaInfo.kt
app/src/main/java/com/ic/icfotaclient/presenter/OtaService.kt
app/src/main/java/com/ic/icfotaclient/presenter/OtaViewModel.kt
app/src/main/java/com/ic/icfotaclient/utils/ICOtaApiUtils.kt
app/src/main/java/com/ic/icfotaclient/view/SystemUpdateActivity.kt
app/src/main/res/values-en/strings.xml
app/src/main/res/values-zh-rCN/strings.xml
app/src/main/res/values/strings.xml

index 208123b..3c7772a 100644 (file)
@@ -3,9 +3,18 @@
     <JetCodeStyleSettings>
       <option name="PACKAGES_TO_USE_STAR_IMPORTS">
         <value>
-          <package name="java.util" withSubpackages="false" static="false" />
-          <package name="kotlinx.android.synthetic" withSubpackages="true" static="false" />
-          <package name="io.ktor" withSubpackages="true" static="false" />
+          <package name="java.util" alias="false" withSubpackages="false" />
+          <package name="kotlinx.android.synthetic" alias="false" withSubpackages="true" />
+          <package name="io.ktor" alias="false" withSubpackages="true" />
+        </value>
+      </option>
+      <option name="PACKAGES_IMPORT_LAYOUT">
+        <value>
+          <package name="" alias="false" withSubpackages="true" />
+          <package name="java" alias="false" withSubpackages="true" />
+          <package name="javax" alias="false" withSubpackages="true" />
+          <package name="kotlin" alias="false" withSubpackages="true" />
+          <package name="" alias="true" withSubpackages="true" />
         </value>
       </option>
       <option name="CODE_STYLE_DEFAULTS" value="KOTLIN_OFFICIAL" />
diff --git a/app/FotaBrand8521e/debug/Android.mk b/app/FotaBrand8521e/debug/Android.mk
deleted file mode 100644 (file)
index 8b12add..0000000
+++ /dev/null
@@ -1,18 +0,0 @@
-LOCAL_PATH:= $(call my-dir)
-include $(CLEAR_VARS)
-
-# Module name should match apk name to be installed
-LOCAL_MODULE := ICFotaClient
-LOCAL_MODULE_TAGS := optional
-LOCAL_SRC_FILES := FotaBrand8521e_V1_202103081958_debug.apk
-LOCAL_MODULE_CLASS := APPS
-LOCAL_MODULE_SUFFIX := $(COMMON_ANDROID_PACKAGE_SUFFIX)
-
-# icfota
-LOCAL_OVERRIDES_PACKAGES := icfota
-
-LOCAL_PRIVILEGED_MODULE := true
-LOCAL_CERTIFICATE := platform
-LOCAL_DEX_PREOPT := false
-
-include $(BUILD_PREBUILT)
diff --git a/app/FotaBrand8521e/debug/FotaBrand8521e_V1_202103081958_debug.apk b/app/FotaBrand8521e/debug/FotaBrand8521e_V1_202103081958_debug.apk
deleted file mode 100644 (file)
index 97a8fa3..0000000
Binary files a/app/FotaBrand8521e/debug/FotaBrand8521e_V1_202103081958_debug.apk and /dev/null differ
diff --git a/app/FotaBrand8521e/debug/output-metadata.json b/app/FotaBrand8521e/debug/output-metadata.json
deleted file mode 100644 (file)
index 937cd6f..0000000
+++ /dev/null
@@ -1,18 +0,0 @@
-{
-  "version": 2,
-  "artifactType": {
-    "type": "APK",
-    "kind": "Directory"
-  },
-  "applicationId": "com.ic.icfotaclient",
-  "variantName": "processFotaBrand8521eDebugResources",
-  "elements": [
-    {
-      "type": "SINGLE",
-      "filters": [],
-      "versionCode": 1,
-      "versionName": "1.0",
-      "outputFile": "FotaBrand8521e_V1_202103081958_debug.apk"
-    }
-  ]
-}
\ No newline at end of file
diff --git a/app/FotaBrand8521e/release/FotaBrand8521e_V1_202106281712_release.apk b/app/FotaBrand8521e/release/FotaBrand8521e_V1_202106281712_release.apk
new file mode 100644 (file)
index 0000000..e39f4d4
Binary files /dev/null and b/app/FotaBrand8521e/release/FotaBrand8521e_V1_202106281712_release.apk differ
@@ -5,14 +5,14 @@
     "kind": "Directory"
   },
   "applicationId": "com.ic.icfotaclient",
-  "variantName": "processFotaBrand8541eReleaseResources",
+  "variantName": "processFotaBrand8521eReleaseResources",
   "elements": [
     {
       "type": "SINGLE",
       "filters": [],
       "versionCode": 1,
       "versionName": "1.0",
-      "outputFile": "FotaBrand8541e_V1_202103181928_release.apk"
+      "outputFile": "FotaBrand8521e_V1_202106281712_release.apk"
     }
   ]
 }
\ No newline at end of file
diff --git a/app/FotaBrand8541e/release/FotaBrand8541e_V1_202103181928_release.apk b/app/FotaBrand8541e/release/FotaBrand8541e_V1_202103181928_release.apk
deleted file mode 100644 (file)
index 0b41367..0000000
Binary files a/app/FotaBrand8541e/release/FotaBrand8541e_V1_202103181928_release.apk and /dev/null differ
index 067e16e..3c913e3 100644 (file)
@@ -29,8 +29,7 @@ data class OtaInfo(
         parcel.readLong(),
         parcel.readLong(),
         TODO("serverInc")
-    ) {
-    }
+    )
 
     enum class ServerInc {
         IN_CAR,
index 123811f..8681432 100644 (file)
@@ -117,7 +117,6 @@ class OtaService : Service(), ViewModelStoreOwner, LifecycleOwner {
     private fun checkRemote() {
         App.sHandler.postDelayed({
             checkVersion(VersionCheckFrom.BOOT_CHECK)
-
         }, Constants.TIME_DELAY_BOOT)
     }
 
index fcf28ac..f1d65b8 100644 (file)
@@ -445,7 +445,7 @@ class OtaViewModel : ViewModel() {
                 }
                 Log.d(TAG, "batteryPct == > $batteryPct")
                 //进行电量检查
-                if (batteryPct!! >= 50.0f) {
+                if (batteryPct!! >= 30.0f) {
                     currentActionState.postValue(UpdateActionState.UPDATING)
                     //保存一个SP值,升级完了检查,用于通知服务器更新成功了.
                     //这里后面要改成我们自己的升级,而不是apk的升级方式
index b7c4ae3..4a24cac 100644 (file)
@@ -23,11 +23,20 @@ import javax.net.ssl.X509TrustManager
 
 object ICOtaApiUtils {
 
-    val TAG = "ICOtaApiUtils"
+    private const val TAG = "ICOtaApiUtils"
+    private var isBackUpHost = false
+
+    private val backupUrl by lazy {
+        val backupUri = URI(getRemoteUriBackup())
+        Log.d(TAG, "backupUri == > $backupUri")
+        backupUri.toString()
+    }
 
     fun checkIcVersion(): OtaInfo? {
         val uri = URI(getRemoteUri())
         val url = uri.toString()
+        Log.d(TAG, "uri == > $uri")
+        isBackUpHost = false
         return getUpdateInfo(url)
     }
 
@@ -84,23 +93,30 @@ object ICOtaApiUtils {
     private fun getUpdateInfo(
         url: String?
     ): OtaInfo? {
+        Log.d(TAG, "getUpdateInfo url is $url")
         if (okHttpClient == null) {
             initOkHttp()
         }
         val request: Request = Request.Builder().url(url).build()
-
-        val execute = okHttpClient?.newCall(request)?.execute()
+        val newCall = okHttpClient?.newCall(request)
+        val response = newCall?.execute()
+        Log.d(TAG, "execute == > $response")
         //解析数据
-        if (execute != null && execute.code() == HttpURLConnection.HTTP_OK) {
-            val body = execute.body() ?: return null
+        val code = response?.code()
+        Log.d(TAG, "code == > $code")
+        if (response != null && code == HttpURLConnection.HTTP_OK) {
+            val body = response.body() ?: return null
             val json = body.string()
             Log.d(TAG, "result == > $json")
             val gson = Gson()
-            otaInfo = gson.fromJson<ICOtaInfo>(json, ICOtaInfo::class.java)
+            otaInfo = gson.fromJson(json, ICOtaInfo::class.java)
             if (otaInfo != null) {
                 if (otaInfo!!.UptoDate) {
                     Log.d(TAG, "no update package in ic server.")
-                    return null
+                    if (!isBackUpHost) {
+                        isBackUpHost = true
+                        return getUpdateInfo(backupUrl)
+                    }
                 }
                 return OtaInfo(
                     otaInfo!!.AutoUpdate,
@@ -112,9 +128,11 @@ object ICOtaApiUtils {
                 )
             }
         }
+        Log.d(TAG, "no update info...")
         return null
     }
 
+
     private fun getRemoteUri(): String? {
         var server: String = getRemoteHost()
         val productname: String? = VersionInfoUtils.getOtaProductName()
@@ -134,6 +152,32 @@ object ICOtaApiUtils {
         return actionUrl
     }
 
+    private fun getRemoteUriBackup(): String? {
+        var server: String? = getRemoteHostBackup()
+        val productname: String? = VersionInfoUtils.getOtaProductName()
+        val pkgversion: String? = VersionInfoUtils.getSystemVersion()
+        val imei: String? = VersionInfoUtils.getIMEI()
+        //为了兼容之前的只设置ip和端口的设置方式
+        var actionUrl =
+            "$server/ota.jsp?product=$productname&pkgver=$pkgversion&imei=$imei"
+        if (server != null) {
+            if (server.contains("/")) { //此时说明不是ip地址,而是个url
+                actionUrl = "$server?product=$productname&pkgver=$pkgversion&imei=$imei"
+            }
+        }
+        if (!actionUrl.startsWith("http://") && !actionUrl.startsWith("https://")) {
+            actionUrl = "http://$actionUrl"
+        }
+        return actionUrl
+    }
+
+    private fun getRemoteHostBackup(): String? {
+        var remoteHost: String? = SysPropUtils.get("persist.sys.ota.host2", null)
+        if (remoteHost == null || remoteHost.isEmpty() || remoteHost == "unknown") {
+            remoteHost = "server-git:8089"
+        }
+        return remoteHost
+    }
 
     private fun getRemoteHost(): String {
         var remoteHost: String? =
index 265e091..446d52e 100644 (file)
@@ -22,7 +22,8 @@ class SystemUpdateActivity : AppCompatActivity() {
         val currentActionState = OtaViewModelCreator.getOtaViewModel(null)?.currentActionState
         val tipsWifiConnect = OtaViewModelCreator.getOtaViewModel(null)?.isTipsWifiConnect
         if (checkNetWork != true ||
-            currentActionState?.value == UpdateActionState.LAST_VERSION
+            currentActionState?.value == UpdateActionState.LAST_VERSION ||
+            currentActionState?.value == UpdateActionState.BATTERY_LEVEL_NOT_ENOUGH
             || tipsWifiConnect?.value == true
         ) {
             super.onBackPressed()
index f30329a..fe58ba6 100644 (file)
@@ -9,7 +9,7 @@
     <string name="check_has_update_text">Check has update</string>
     <string name="update_text">Update</string>
     <string name="no_network_text">Unable to reach the server</string>
-    <string name="battery_level_tips_text">Please make the power is above 50%</string>
+    <string name="battery_level_tips_text">Please make the power is above 30%</string>
     <string name="error_tips_text">Error , please try again</string>
     <string name="verify_package_text">Checking</string>
     <string name="inject_update_seed_text">Inject upgrade seeds</string>
index c7471b3..3d8da48 100644 (file)
@@ -9,7 +9,7 @@
     <string name="check_has_update_text">检查是否有更新</string>
     <string name="update_text">马上升级</string>
     <string name="no_network_text">无法触及到服务器</string>
-    <string name="battery_level_tips_text">请确保电量50%以上</string>
+    <string name="battery_level_tips_text">请确保电量30%以上</string>
     <string name="error_tips_text">资源准备失败,请重启尝试</string>
     <string name="verify_package_text">正在校验升级包</string>
     <string name="inject_update_seed_text">注入升级种子</string>
index f30329a..fe58ba6 100644 (file)
@@ -9,7 +9,7 @@
     <string name="check_has_update_text">Check has update</string>
     <string name="update_text">Update</string>
     <string name="no_network_text">Unable to reach the server</string>
-    <string name="battery_level_tips_text">Please make the power is above 50%</string>
+    <string name="battery_level_tips_text">Please make the power is above 30%</string>
     <string name="error_tips_text">Error , please try again</string>
     <string name="verify_package_text">Checking</string>
     <string name="inject_update_seed_text">Inject upgrade seeds</string>