Browse Source

修复jira问题

carlos 3 months ago
parent
commit
c1bf03b3d9

BIN
XPCommonService.apk


+ 30 - 2
app/src/main/java/com/xplora/commonservice/modules/WatchStateChangeImpl.kt

@@ -3,6 +3,8 @@ package com.xplora.commonservice.modules
 import android.content.Intent
 import android.hardware.Sensor
 import android.icu.util.Calendar
+import android.os.Handler
+import android.os.Looper
 import android.provider.Settings
 import com.xplora.commonservice.BaseApplication
 import com.xplora.commonservice.BaseApplication.Companion.globalContext
@@ -20,7 +22,6 @@ import com.xplora.commonservice.model.http.status.StatusGetRepo
 import com.xplora.commonservice.model.http.status.StatusInfoReq
 import com.xplora.commonservice.modules.ChatMsgManager.refreshMsgListBySelf
 import com.xplora.commonservice.modules.ForbiddenManager.RingerMode
-import com.xplora.commonservice.modules.NotificationManager.channelCreated
 import com.xplora.commonservice.modules.OtaManager.forceCheck
 import com.xplora.commonservice.modules.SoundManager.getRingerMode
 import com.xplora.commonservice.modules.SoundManager.setRingerMode
@@ -56,6 +57,30 @@ object WatchStateChangeImpl : WatchStateChangeObserver, NetworkStateChangeObserv
     val watchBaseInfo = WatchBaseInfo()
     var batteryNotifyLevel = -1
 
+    private var reconnectTask: Runnable? = null
+    private var reconnectHandler: Handler? = null
+    private const val RECONNECT_TIMEOUT = 10 * 1000L
+
+    private fun startReconnectTimer() {
+        Logger.d(OtaManager.TAG, "startTimeout")
+        reconnectHandler?.apply { Handler(Looper.getMainLooper()) }?.let { h ->
+            reconnectTask?.apply { Runnable { AwsIotManager.connect() } }?.let { r ->
+                h.postDelayed(r, RECONNECT_TIMEOUT)
+            }
+        }
+    }
+
+    private fun clearReconnectTimer() {
+        Logger.d(OtaManager.TAG, "clearTimeout")
+        reconnectHandler?.let { h ->
+            reconnectTask?.let { r ->
+                h.removeCallbacks(r)
+            }
+        }
+        reconnectTask = null
+        reconnectHandler = null
+    }
+
     override fun onNetConnected(networkType: NetworkType) {
         Logger.d(TAG, "onNetConnected")
         val last = watchBaseInfo.networkType
@@ -64,7 +89,9 @@ object WatchStateChangeImpl : WatchStateChangeObserver, NetworkStateChangeObserv
             Logger.d(TAG, "last == NetworkType.NETWORK_NO")
             Settings.Global.putInt(globalContext.contentResolver, "xp_weak_signal_flag", 0)
             if (watchBaseInfo.inited) {
-                AwsIotManager.connect()
+                clearReconnectTimer()
+                startReconnectTimer()
+
                 refreshMsgListBySelf()
             } else {
                 forceCheck(false)
@@ -90,6 +117,7 @@ object WatchStateChangeImpl : WatchStateChangeObserver, NetworkStateChangeObserv
         Logger.d(TAG, "onNetDisconnected")
         watchBaseInfo.networkType = NetworkType.NETWORK_NO
         Settings.Global.putInt(globalContext.contentResolver, "xp_weak_signal_flag", 1)
+        clearReconnectTimer()
         // AwsIotManager.disconnect()
     }
 

+ 8 - 6
app/src/main/java/com/xplora/commonservice/modules/callbacks/SystemInfoReceiver.kt

@@ -63,8 +63,10 @@ class SystemInfoReceiver : BroadcastReceiver() {
                     ShellUtils.writeValue(CHARGER_ENABLED_PATH, ENABLED_CHARGER)
                 }*/
                 watchBaseInfo.batteryTemp = intent.getIntExtra(BatteryManager.EXTRA_TEMPERATURE, 0)
-                val chargeStatus = intent.getIntExtra(BatteryManager.EXTRA_STATUS, -1).let {
-                    it == BatteryManager.BATTERY_STATUS_CHARGING
+                val chargeStatus = intent.getIntExtra(BatteryManager.EXTRA_STATUS, -1) == BatteryManager.BATTERY_STATUS_CHARGING
+
+                val chargeDisableStatus = intent.getIntExtra(BatteryManager.EXTRA_PLUGGED, -1).let {
+                    it == BatteryManager.BATTERY_PLUGGED_AC || it == BatteryManager.BATTERY_PLUGGED_USB
                 }
 
                 Logger.d(TAG, "on battery change level: $level")
@@ -122,11 +124,11 @@ class SystemInfoReceiver : BroadcastReceiver() {
                     }
                 }
                 // 上报充电状态变化
-                Logger.d(TAG, "chargeStatus $chargeStatus")
-                if (chargeStatus != watchBaseInfo.isCharging) {
-                    watchBaseInfo.isCharging = chargeStatus
+                Logger.d(TAG, "chargeStatus $chargeStatus -- chargeDisableStatus $chargeDisableStatus")
+                if (chargeDisableStatus != watchBaseInfo.isCharging) {
+                    watchBaseInfo.isCharging = chargeDisableStatus
                     needReport = true
-                    if (chargeStatus) {
+                    if (chargeDisableStatus) {
                         watchBaseInfo.chargingTime = System.currentTimeMillis()
                         cancelBatteryLowNotify()
                         showChargingNotify()

+ 1 - 1
app/src/main/java/com/xplora/commonservice/modules/http/TokenManager.kt

@@ -17,6 +17,7 @@ object TokenManager {
             Logger.d(TAG, "Init.execute $this")
             if (it.ckError == CkError.SUCCESS) {
                 resolveToken(it.mData as InitRepo)
+                AwsIotManager.connect()
                 return true
             } else {
                 return false
@@ -42,6 +43,5 @@ object TokenManager {
         BaseApplication.iotConfig.certUrl = initRepo.awsIotCaCert
         BaseApplication.iotConfig.cliCertUrl = initRepo.awsIotCliCert
         BaseApplication.iotConfig.cliPrivUrl = initRepo.awsIotCliPriv
-        AwsIotManager.connect()
     }
 }

+ 45 - 24
app/src/main/java/com/xplora/commonservice/modules/mqtt/AwsIotManager.kt

@@ -9,38 +9,49 @@ import com.xplora.commonservice.BaseApplication.Companion.globalContext
 import com.xplora.commonservice.BaseApplication.Companion.iotConfig
 import com.xplora.commonservice.BaseApplication.Companion.isTest
 import com.xplora.commonservice.utils.Logger
-import kotlinx.coroutines.*
+import kotlinx.coroutines.CoroutineName
+import kotlinx.coroutines.CoroutineScope
+import kotlinx.coroutines.DelicateCoroutinesApi
+import kotlinx.coroutines.Dispatchers
+import kotlinx.coroutines.cancel
+import kotlinx.coroutines.delay
+import kotlinx.coroutines.launch
 import java.security.KeyStore
 
 object AwsIotManager {
     const val TAG = "AwsIotManager"
 
     private val client: MyAWSIotMqttClient by lazy { init() }
+    var isDisconnected = false
+
+    fun onCloseCallback() {
+        isDisconnected = true
+    }
 
     private fun init(): MyAWSIotMqttClient {
-/*        var certificateFile = ""
-        var privateKeyFile = ""
-        val paths = context.assets.list("aws_iot_test")
-        for (path in paths!!) {
-            Logger.d(TAG, path)
-            if (path.equals("client.cert.development.pem")) certificateFile = path
-            else if (path.equals("client.private.development.key")) privateKeyFile = path
-        }
+        /*        var certificateFile = ""
+                var privateKeyFile = ""
+                val paths = context.assets.list("aws_iot_test")
+                for (path in paths!!) {
+                    Logger.d(TAG, path)
+                    if (path.equals("client.cert.development.pem")) certificateFile = path
+                    else if (path.equals("client.private.development.key")) privateKeyFile = path
+                }
 
-        // Alternatively, you could load key store directly from a file - see the example included in this README.
-        val pair: KeyStoreHelper.KeyStorePasswordPair =
-            KeyStoreHelper.getKeyStorePasswordPair(certificateFile, privateKeyFile)!!
-        var keyStoreFile: String? = null
-        val paths = globalContext.assets.list("aws_iot_test")
-        for (path in paths!!) {
-            if (path.equals("my.keystore")) keyStoreFile = path
-        }*/
+                // Alternatively, you could load key store directly from a file - see the example included in this README.
+                val pair: KeyStoreHelper.KeyStorePasswordPair =
+                    KeyStoreHelper.getKeyStorePasswordPair(certificateFile, privateKeyFile)!!
+                var keyStoreFile: String? = null
+                val paths = globalContext.assets.list("aws_iot_test")
+                for (path in paths!!) {
+                    if (path.equals("my.keystore")) keyStoreFile = path
+                }*/
 
         val keyStorePassword = "sikey2022"
         val keyPassword = "sikey2022"
 
         val keyStore = KeyStore.getInstance(KeyStore.getDefaultType())
-        val seyPath = if(!isTest) "my.keystore" else "test_new.keystore"
+        val seyPath = if (!isTest) "my.keystore" else "test_new.keystore"
         Logger.d(TAG, "seyPath : $seyPath")
         keyStore.load(globalContext.assets.open(seyPath), keyStorePassword.toCharArray())
 
@@ -59,8 +70,14 @@ object AwsIotManager {
         CoroutineScope(Dispatchers.IO + CoroutineName("MQTT_connect")).launch {
             try {
                 Logger.d(TAG, "connect : ${Thread.currentThread()}")
+                disconnect()
+                while (!isDisconnected) {
+                    delay(100)
+                }
+                isDisconnected = false
                 client.apply {
-                    keepAliveInterval = (if(isTest) 3  else 5) * 60 * 1000 - 15 * 1000  // iotInfo.keepAlive - 15 * 1000
+                    keepAliveInterval =
+                        (if (isTest) 3 else 5) * 60 * 1000 - 15 * 1000  // iotInfo.keepAlive - 15 * 1000
                     maxConnectionRetries = 10
                     baseRetryDelay = 5 * 1000
                     maxRetryDelay = 2 * 60 * 1000
@@ -82,18 +99,22 @@ object AwsIotManager {
         }
     }
 
+    @OptIn(DelicateCoroutinesApi::class)
     fun disconnect() {
-        Logger.d(TAG, "disconnect")
-        val scope = CoroutineScope(Dispatchers.IO + CoroutineName("MQTT_disconnect"))
-        scope.launch {
-            if (client.connectionStatus == AWSIotConnectionStatus.CONNECTED) {
+        CoroutineScope(Dispatchers.IO + CoroutineName("MQTT_disconnect")).launch {
+            Logger.d(TAG, "disconnect")
+            if (client.connectionStatus != AWSIotConnectionStatus.DISCONNECTED) {
                 try {
                     client.disconnect(10 * 1000, false)
                 } catch (e: AWSIotException) {
                     Logger.e(TAG, "AWSIotException : ${e.printStackTrace()}")
+                } finally {
+                    isDisconnected = true
                 }
+            } else {
+                isDisconnected = true
             }
-            this.cancel()
         }
+
     }
 }

+ 2 - 2
app/src/main/java/com/xplora/commonservice/modules/mqtt/MyAWSIotMqttClient.kt

@@ -4,9 +4,8 @@ import android.app.Service
 import android.content.Context
 import android.os.PowerManager
 import com.amazonaws.services.iot.client.AWSIotMqttClient
-import com.amazonaws.services.iot.client.AWSIotQos
-import com.xplora.commonservice.BaseApplication
 import com.xplora.commonservice.modules.WatchStateChangeImpl
+import com.xplora.commonservice.modules.mqtt.AwsIotManager.onCloseCallback
 import com.xplora.commonservice.utils.Logger
 import java.security.KeyStore
 import java.util.concurrent.Future
@@ -25,6 +24,7 @@ class MyAWSIotMqttClient(
     override fun onConnectionClosed() {
         super.onConnectionClosed()
         Logger.d(TAG, "onConnectionClosed: ${WatchStateChangeImpl.watchBaseInfo.networkType}")
+        onCloseCallback()
         /*        if(WatchStateChangeImpl.watchBaseInfo.networkType != NetworkType.NETWORK_NO &&
                     WatchStateChangeImpl.watchBaseInfo.networkType != NetworkType.NETWORK_UNKNOWN){
                     Logger.d(TAG, "try reconnect")

+ 77 - 0
app/src/main/res/values-zh-rCN/strings.xml

@@ -0,0 +1,77 @@
+<?xml version="1.0" encoding="utf-8"?>
+<resources>
+    <string name="app_name">观看更新</string>
+    <string name="check_summary">正在检查新更新</string>
+    <string name="ota_title">软件更新</string>
+    <string name="up_to_date">你的手表是最新的</string>
+    <string name="new_available">新软件更新可用</string>
+    <string name="power_low">新的系统更新可用,但电池需要35%以上的电量,建议连接充电器。</string>
+    <string name="update_now">立即更新</string>
+    <string name="ok">好的</string>
+    <string name="no_wifi">请连接到Wi-Fi以下载更新</string>
+    <string name="downloading">正在下载更新…</string>
+    <string name="lost_wifi">手表已失去Wi-Fi连接</string>
+    <string name="check_wifi">检查Wi-Fi</string>
+    <string name="connect_wifi">连接Wi-Fi</string>
+    <string name="ready_to_install">更新已准备好安装</string>
+    <string name="install_now">立即安装</string>
+    <string name="install_overnight">隔夜安装</string>
+    <string name="overnight_summary">更新将于今晚凌晨1点后安装,请确保手表在此期间正在充电</string>
+    <string name="battery_low">电池电量低</string>
+    <string name="charging">充电</string>
+    <string name="force_update_summary">您的手表将安装重要更新以获得更好的性能。除非它连接WiFi网络,否则它将消耗您的移动数据。</string>
+    <string name="missed_call">未接来电</string>
+    <string name="missed_call_title">电话</string>
+    <string name="package_name_system">系统</string>
+    <string name="new_msg">新消息</string>
+    <string name="package_chat">聊天</string>
+    <string name="package_name_ota">软件更新</string>
+    <string name="sos_init">正在初始化SOS…</string>
+    <string name="release_cancel">松开按钮取消</string>
+    <string name="yes">是的</string>
+    <string name="no">不</string>
+    <string name="new_ringtone">新铃声</string>
+    <string name="more">更多…</string>
+    <string name="warning_message">注:</string>
+    <string name="ringtone_download_confirm">你确定不想下载铃声吗?</string>
+    <string name="the_watch_turns_off">手表关掉了</string>
+    <string name="download_check">您想下载吗?</string>
+    <string name="download_sure">你确定吗?</string>
+    <string name="download_check_summary">要稍后下载文件,请转到通知区域或Goplay。</string>
+    <string name="new_watchface">新表盘</string>
+    <string name="cancel">取消</string>
+    <string name="check_wifi_summary">您需要Wi-Fi才能下载。\\n您想连接到Wi-Fi吗?</string>
+    <string name="downloading_notify">下载中</string>
+    <string name="new_music">新音乐</string>
+    <string name="done">完成</string>
+    <string name="failed">失败</string>
+    <string name="music_new">来自%1$s的新音乐文件</string>
+    <string name="download_check_summary_music">要稍后下载文件,请转到通知区域。</string>
+    <string name="diagnostic_tool">诊断工具</string>
+    <string name="running">正在运行…</string>
+    <string name="pending">警告…</string>
+    <string name="uploading">日志正在上传</string>
+    <string name="notify_share_log">“登录以与Xplora共享”</string>
+    <string name="need_upload_summary">创建日志后,您有24小时的时间将其上传到Xplora。</string>
+    <string name="diagnostic_tips">“自诊断工具…请打开,并按照说明操作”</string>
+    <string name="diagnostic_tips_2">自我诊断工具…请尝试重现问题</string>
+    <string name="diagnostic_running_summary">诊断工具正在运行\\n在此过程中,所有监视功能都将被阻止。</string>
+    <string name="diagnostic_share_summary">自诊断工具已完成:\\n已生成观察日志!</string>
+    <string name="upload_check_summary">您想现在上传吗?请注意,上传文件需要Wi-Fi。</string>
+    <string name="now">现在</string>
+    <string name="later">稍后</string>
+    <string name="consent_summary">您是否同意与Xplora共享此日志,以便分析问题?</string>
+    <string name="consent">同意书</string>
+    <string name="attention">注意!</string>
+    <string name="attention_24h">您有一个观察日志等待上传。它将在24小时后过期</string>
+    <string name="upload">上传</string>
+    <string name="diagnostic_no_wifi_summary">请连接到Wi-Fi与Xplora共享此日志</string>
+    <string name="congratulations_summary">“恭喜!\\n日志已与Xplora共享”</string>
+    <string name="delete_log">删除日志</string>
+    <string name="attention_delete">删除最近的日志后,您可以立即录制另一个日志</string>
+    <string name="diagnostic_running_heatup_summary">在此过程中,手表温度可能会升高。</string>
+    <string name="chat_send_fail">连接问题</string>
+    <string name="roaming_off_title">数据漫游已关闭</string>
+    <string name="roaming_off_tips">\\t你可能在国外旅行。为防止产生国际漫游费用,您的手表已关闭国际漫游。\\n\\t如果您想在国外使用手表,请转到“设置”>“连接”>“数据漫游”。</string>
+    <string name="settings">设置</string>
+</resources>

+ 77 - 0
app/src/main/res/values-zh-rTW/strings.xml

@@ -0,0 +1,77 @@
+<?xml version="1.0" encoding="utf-8"?>
+<resources>
+    <string name="app_name">觀看更新</string>
+    <string name="check_summary">正在檢查新更新</string>
+    <string name="ota_title">軟體更新</string>
+    <string name="up_to_date">你的手錶是最新的</string>
+    <string name="new_available">新軟體更新可用</string>
+    <string name="power_low">新的系統更新可用,但電池需要35%以上的電量,建議連接充電器。</string>
+    <string name="update_now">立即更新</string>
+    <string name="ok">好的</string>
+    <string name="no_wifi">請連接到Wi-Fi以下載更新</string>
+    <string name="downloading">正在下載更新…</string>
+    <string name="lost_wifi">手錶已失去Wi-Fi連接</string>
+    <string name="check_wifi">檢查Wi-Fi</string>
+    <string name="connect_wifi">連接Wi-Fi</string>
+    <string name="ready_to_install">更新已準備好安裝</string>
+    <string name="install_now">立即安裝</string>
+    <string name="install_overnight">隔夜安裝</string>
+    <string name="overnight_summary">更新將於今晚淩晨1點後安裝,請確保手錶在此期間正在充電</string>
+    <string name="battery_low">電池電量低</string>
+    <string name="charging">充電</string>
+    <string name="force_update_summary">您的手錶將安裝重要更新以獲得更好的效能。 除非它連接WiFi網絡,否則它將消耗您的移動數據。</string>
+    <string name="missed_call">未接來電</string>
+    <string name="missed_call_title">電話</string>
+    <string name="package_name_system">系統</string>
+    <string name="new_msg">新消息</string>
+    <string name="package_chat">聊天</string>
+    <string name="package_name_ota">軟體更新</string>
+    <string name="sos_init">正在初始化SOS…</string>
+    <string name="release_cancel">鬆開按鈕取消</string>
+    <string name="yes">是的</string>
+    <string name="no">不</string>
+    <string name="new_ringtone">新鈴聲</string>
+    <string name="more">更多…</string>
+    <string name="warning_message">注:</string>
+    <string name="ringtone_download_confirm">你確定不想下載鈴聲嗎?</string>
+    <string name="the_watch_turns_off">手錶關掉了</string>
+    <string name="download_check">您想下載嗎?</string>
+    <string name="download_sure">你確定嗎?</string>
+    <string name="download_check_summary">要稍後下載檔案,請轉到通知區域或Goplay。</string>
+    <string name="new_watchface">新錶盤</string>
+    <string name="cancel">取消</string>
+    <string name="check_wifi_summary">您需要Wi-Fi才能下載。 \\n您想連接到Wi-Fi嗎?</string>
+    <string name="downloading_notify">下載中</string>
+    <string name="new_music">新音樂</string>
+    <string name="done">完成</string>
+    <string name="failed">失敗</string>
+    <string name="music_new">來自%1$s的新音樂檔</string>
+    <string name="download_check_summary_music">要稍後下載檔案,請轉到通知區域。</string>
+    <string name="diagnostic_tool">診斷工具</string>
+    <string name="running">正在運行…</string>
+    <string name="pending">警告…</string>
+    <string name="uploading">日誌正在上傳</string>
+    <string name="notify_share_log">“登入以與Xplora共亯”</string>
+    <string name="need_upload_summary">創建日誌後,您有24小時的時間將其上傳到Xplora。</string>
+    <string name="diagnostic_tips">“自診斷工具…請打開,並按照說明操作”</string>
+    <string name="diagnostic_tips_2">自我診斷工具…請嘗試重現問題</string>
+    <string name="diagnostic_running_summary">診斷工具正在運行\\n在此過程中,所有監視功能都將被封锁。</string>
+    <string name="diagnostic_share_summary">自診斷工具已完成:\\n已生成觀察日誌!</string>
+    <string name="upload_check_summary">您想現在上傳嗎? 請注意,上傳文件需要Wi-Fi。</string>
+    <string name="now">現在</string>
+    <string name="later">稍後</string>
+    <string name="consent_summary">您是否同意與Xplora共亯此日誌,以便分析問題?</string>
+    <string name="consent">同意書</string>
+    <string name="attention">注意!</string>
+    <string name="attention_24h">您有一個觀察日誌等待上傳。 它將在24小時後過期</string>
+    <string name="upload">上傳</string>
+    <string name="diagnostic_no_wifi_summary">請連接到Wi-Fi與Xplora共亯此日誌</string>
+    <string name="congratulations_summary">“恭喜!\\n日誌已與Xplora共亯”</string>
+    <string name="delete_log">删除日誌</string>
+    <string name="attention_delete">删除最近的日誌後,您可以立即錄製另一個日誌</string>
+    <string name="diagnostic_running_heatup_summary">在此過程中,手錶溫度可能會升高。</string>
+    <string name="chat_send_fail">連接問題</string>
+    <string name="roaming_off_title">數據漫遊已關閉</string>
+    <string name="roaming_off_tips">\\t你可能在國外旅行。 為防止產生國際漫遊費用,您的手錶已關閉國際漫遊。 \\n\\t如果您想在國外使用手錶,請轉到“設定”>“連接”>“數據漫遊”。</string>
+    <string name="settings">設定</string>
+</resources>