fixed progourd issues.
authorTrillGates <williamtrillgates@gmail.com>
Thu, 28 Jan 2021 12:11:06 +0000 (20:11 +0800)
committerTrillGates <williamtrillgates@gmail.com>
Thu, 28 Jan 2021 12:11:06 +0000 (20:11 +0800)
app/FotaBrand8541e/release/FotaBrand8541e_V1_202101260957_release.apk [deleted file]
app/FotaBrand8541e/release/output-metadata.json [deleted file]
app/proguard-rules.pro
app/src/main/AndroidManifest.xml
app/src/main/java/com/ic/icfotaclient/presenter/OtaReceiver.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/repository/CarOtaRepository.kt
app/src/main/java/com/ic/icfotaclient/utils/Constants.kt
app/src/main/java/com/ic/icfotaclient/utils/ICOtaApiUtils.kt

diff --git a/app/FotaBrand8541e/release/FotaBrand8541e_V1_202101260957_release.apk b/app/FotaBrand8541e/release/FotaBrand8541e_V1_202101260957_release.apk
deleted file mode 100644 (file)
index 8bc451b..0000000
Binary files a/app/FotaBrand8541e/release/FotaBrand8541e_V1_202101260957_release.apk and /dev/null differ
diff --git a/app/FotaBrand8541e/release/output-metadata.json b/app/FotaBrand8541e/release/output-metadata.json
deleted file mode 100644 (file)
index d1b542f..0000000
+++ /dev/null
@@ -1,18 +0,0 @@
-{
-  "version": 2,
-  "artifactType": {
-    "type": "APK",
-    "kind": "Directory"
-  },
-  "applicationId": "com.ic.icfotaclient",
-  "variantName": "processFotaBrand8541eReleaseResources",
-  "elements": [
-    {
-      "type": "SINGLE",
-      "filters": [],
-      "versionCode": 1,
-      "versionName": "1.0",
-      "outputFile": "FotaBrand8541e_V1_202101260957_release.apk"
-    }
-  ]
-}
\ No newline at end of file
index 41f2508..4b586eb 100644 (file)
     public <init>(android.content.Context, android.util.AttributeSet, int);
 }
 
+# 抛出异常时保留代码行号
+-keepattributes SourceFile,LineNumberTable
+
+# 保留枚举类不被混淆
+-keepclassmembers enum * {
+    public static **[] values();
+    public static ** valueOf(java.lang.String);
+}
+
 ################################## 项目类 ##################################
 
 -keep class com.facebook.** { *; }
index bfc13b6..4d5a66e 100644 (file)
@@ -25,7 +25,9 @@
         android:icon="@mipmap/ic_launcher"
         android:label="@string/app_name"
         android:supportsRtl="true"
-        android:theme="@style/Theme.ICFotaClient">
+        android:theme="@style/Theme.ICFotaClient"
+        android:usesCleartextTraffic="true">
+
         <activity android:name=".view.SystemUpdateActivity">
             <intent-filter>
                 <action android:name="android.intent.action.MAIN" />
@@ -47,8 +49,7 @@
                 <action android:name="android.intent.action.BOOT_COMPLETED" />
             </intent-filter>
             <intent-filter>
-                <action android:name="android.intent.action.MEDIA_MOUNTED" />
-                <data android:scheme="file" />
+                <action android:name="android.net.conn.CONNECTIVITY_CHANGE" />
             </intent-filter>
         </receiver>
         <service
index 9a77823..a369e5c 100644 (file)
@@ -3,6 +3,7 @@ package com.ic.icfotaclient.presenter
 import android.content.BroadcastReceiver
 import android.content.Context
 import android.content.Intent
+import android.net.ConnectivityManager
 import android.util.Log
 import com.ic.icfotaclient.utils.Constants
 
@@ -30,6 +31,12 @@ class OtaReceiver : BroadcastReceiver() {
                 serviceIntent.action = Constants.CMD_ACTION_BOOT_COMPLETED
                 context?.startService(serviceIntent)
             }
+            ConnectivityManager.CONNECTIVITY_ACTION -> {
+                //去检查更新
+                val serviceIntent = Intent(context, OtaService::class.java)
+                serviceIntent.action = Constants.CMD_ACTION_NET_WORK_CONNECTED
+                context?.startService(serviceIntent)
+            }
         }
     }
 }
\ No newline at end of file
index d60a162..1c8a8d3 100644 (file)
@@ -20,7 +20,7 @@ import com.ic.icfotaclient.utils.VersionInfoUtils
  */
 class OtaService : Service(), ViewModelStoreOwner, LifecycleOwner {
 
-    companion object{
+    companion object {
         const val TAG = "OtaService"
     }
 
@@ -30,11 +30,11 @@ class OtaService : Service(), ViewModelStoreOwner, LifecycleOwner {
 
     override fun onCreate() {
         super.onCreate()
-        Log.d(TAG,"on service created...")
+        Log.d(TAG, "on service created...")
         OtaViewModelCreator.initOtaViewModelStoreOwner(this)
         //观察数据变化
         otaViewModel?.otaInfo?.observe(this, Observer {
-            Log.d(TAG,"on ota info change...$it")
+            Log.d(TAG, "on ota info change...$it")
             //更新数据
             mRemoteCallback?.onCheckResult(it)
         })
@@ -60,13 +60,13 @@ class OtaService : Service(), ViewModelStoreOwner, LifecycleOwner {
 
         override fun getImeiCode() {
             val imei = VersionInfoUtils.getIMEI()
-            Log.d(TAG,"imei == > $imei")
+            Log.d(TAG, "imei == > $imei")
             mRemoteCallback?.onImeiCodeGet(imei)
         }
 
         override fun getVersionCode() {
             val versionCode = VersionInfoUtils.getSystemVersion()
-            Log.d(TAG,"versionCode == > $versionCode")
+            Log.d(TAG, "versionCode == > $versionCode")
             mRemoteCallback?.onVersionCodeGet(versionCode)
         }
     }
@@ -75,7 +75,7 @@ class OtaService : Service(), ViewModelStoreOwner, LifecycleOwner {
     override fun onStartCommand(intent: Intent?, flags: Int, startId: Int): Int {
         //判断指令是啥
         val action = intent?.action
-        Log.d(TAG,"onStartCommand action -- > $action")
+        Log.d(TAG, "onStartCommand action -- > $action")
         if (TextUtils.isEmpty(action)) {
             return START_NOT_STICKY
         }
@@ -92,6 +92,10 @@ class OtaService : Service(), ViewModelStoreOwner, LifecycleOwner {
                 //如果已经更新了,那么通知一下服务器
                 otaViewModel?.checkHasUpdated()
             }
+            Constants.CMD_ACTION_NET_WORK_CONNECTED -> {
+                //去检查更新
+                otaViewModel?.checkHasUpdated()
+            }
         }
 
         return super.onStartCommand(intent, flags, startId)
@@ -99,7 +103,7 @@ class OtaService : Service(), ViewModelStoreOwner, LifecycleOwner {
 
     private fun checkVersion(from: VersionCheckFrom) {
         val checkNetWork = otaViewModel?.checkNetWork()
-        Log.d(TAG,"checkNetWork == > $checkNetWork")
+        Log.d(TAG, "checkNetWork == > $checkNetWork")
         if (checkNetWork == true) {
             //连接上了,那么就去检查更新
             otaViewModel?.checkUpdate(from)
index 9483500..e77de84 100644 (file)
@@ -282,6 +282,9 @@ class OtaViewModel : ViewModel() {
         return VersionInfoUtils.getSystemVersion()
     }
 
+    /**
+     * 获取IMEI号
+     */
     fun getImeiCode(): String? {
         return VersionInfoUtils.getIMEI()
     }
index e5d0552..cc29b4f 100644 (file)
@@ -11,10 +11,7 @@ import com.ic.icfotaclient.utils.CarOtaApiUtils
 import com.ic.icfotaclient.utils.VersionInfoUtils
 import com.ota.fw.IDownloadEvent
 import com.ota.fw.SysInfo
-import java.io.BufferedInputStream
-import java.io.BufferedOutputStream
-import java.io.FileInputStream
-import java.io.FileOutputStream
+import java.io.*
 
 /**
  * 科洛达的Repository
@@ -73,8 +70,14 @@ class CarOtaRepository : AbstractOtaRepository() {
         //转一下
         Log.d(TAG, "download == > ${download.file}")
         val targetFile = VersionInfoUtils.getFlashPath()
-        Log.d(OtaViewModel.TAG, "copy finished to target path == > $targetFile")
-        val fis = FileInputStream(targetFile);
+        val file = File(targetFile)
+        if (!file.parentFile.exists()) {
+            file.parentFile.mkdirs()
+        }
+        if (!file.exists()) {
+            file.createNewFile()
+        }
+        val fis = FileInputStream(download.file);
         val fos = FileOutputStream(targetFile)
         //复制到对应的目录下进行
         val bis = BufferedInputStream(fis)
@@ -88,6 +91,7 @@ class CarOtaRepository : AbstractOtaRepository() {
         }
         fis.close()
         fos.close()
+        Log.d(OtaViewModel.TAG, "copy finished to target path == > $targetFile")
         val downloadInfo = DownloadInfo(download.file.path, 0L)
         downloadInfo.path = targetFile
         return downloadInfo
index 2230469..ca6b1f1 100644 (file)
@@ -2,6 +2,7 @@ package com.ic.icfotaclient.utils
 
 object Constants {
     const val CMD_ACTION_BOOT_COMPLETED = "cmd_action_boot_completed"
+    const val CMD_ACTION_NET_WORK_CONNECTED = "cmd_action_net_work_connected"
     const val CMD_ACTION_ACTIVITY_START = "cmd_action_activity_start"
     const val OTA_URL = "https://api.ota.limios.net/conn/api/v1/"
 
index 551cb1c..1e20ae3 100644 (file)
@@ -98,6 +98,10 @@ object ICOtaApiUtils {
             val gson = Gson()
             otaInfo = gson.fromJson<ICOtaInfo>(json, ICOtaInfo::class.java)
             if (otaInfo != null) {
+                if (otaInfo!!.UptoDate) {
+                    Log.d(TAG, "no update package in ic server.")
+                    return null
+                }
                 return OtaInfo(
                     otaInfo!!.AutoUpdate,
                     otaInfo!!.description,