From: TrillGates Date: Tue, 20 Jul 2021 13:55:40 +0000 (+0800) Subject: fixed null point exception. X-Git-Url: http://git.snicker.com.cn/Users/apple/Desktop/static/gitweb.css?a=commitdiff_plain;h=c090d4e33085eace370712876e828f078250446f;p=icfotaclient.git fixed null point exception. --- diff --git a/app/FotaBrand8521e/release/FotaBrand8521e_V1_202107131922_release.apk b/app/FotaBrand8521e/release/FotaBrand8521e_V1_202107131922_release.apk deleted file mode 100644 index 6cf22a3..0000000 Binary files a/app/FotaBrand8521e/release/FotaBrand8521e_V1_202107131922_release.apk and /dev/null differ diff --git a/app/FotaBrand8521e/release/output-metadata.json b/app/FotaBrand8521e/release/output-metadata.json deleted file mode 100644 index e00d28e..0000000 --- a/app/FotaBrand8521e/release/output-metadata.json +++ /dev/null @@ -1,18 +0,0 @@ -{ - "version": 2, - "artifactType": { - "type": "APK", - "kind": "Directory" - }, - "applicationId": "com.ic.icfotaclient", - "variantName": "processFotaBrand8521eReleaseResources", - "elements": [ - { - "type": "SINGLE", - "filters": [], - "versionCode": 1, - "versionName": "1.0", - "outputFile": "FotaBrand8521e_V1_202107141910_release.apk" - } - ] -} \ No newline at end of file diff --git a/app/src/main/java/com/ic/icfotaclient/presenter/OtaService.kt b/app/src/main/java/com/ic/icfotaclient/presenter/OtaService.kt index 8681432..fb3d620 100644 --- a/app/src/main/java/com/ic/icfotaclient/presenter/OtaService.kt +++ b/app/src/main/java/com/ic/icfotaclient/presenter/OtaService.kt @@ -80,7 +80,6 @@ class OtaService : Service(), ViewModelStoreOwner, LifecycleOwner { } } - private var hasCheck = false override fun onStartCommand(intent: Intent?, flags: Int, startId: Int): Int { @@ -114,6 +113,8 @@ class OtaService : Service(), ViewModelStoreOwner, LifecycleOwner { return super.onStartCommand(intent, flags, startId) } + + private fun checkRemote() { App.sHandler.postDelayed({ checkVersion(VersionCheckFrom.BOOT_CHECK) @@ -121,11 +122,6 @@ class OtaService : Service(), ViewModelStoreOwner, LifecycleOwner { } private fun doCheck() { - if (hasCheck) { - Log.d(TAG, "has checked..") - return - } - hasCheck = true checkRemote() OtaViewModelCreator.getOtaViewModel(object : OtaViewModelCreator.OnViewModelInitListener { override fun onViewModelInit(otaViewModel: OtaViewModel?) { @@ -151,6 +147,7 @@ class OtaService : Service(), ViewModelStoreOwner, LifecycleOwner { }) } + private fun checkVersion(from: VersionCheckFrom) { //连接上了,那么就去检查更新 otaViewModel?.checkUpdate(from) diff --git a/app/src/main/java/com/ic/icfotaclient/presenter/OtaViewModel.kt b/app/src/main/java/com/ic/icfotaclient/presenter/OtaViewModel.kt index e1be691..646e51f 100644 --- a/app/src/main/java/com/ic/icfotaclient/presenter/OtaViewModel.kt +++ b/app/src/main/java/com/ic/icfotaclient/presenter/OtaViewModel.kt @@ -16,7 +16,6 @@ import android.widget.Button import android.widget.TextView import android.widget.Toast import androidx.lifecycle.MutableLiveData -import androidx.lifecycle.Transformations import androidx.lifecycle.ViewModel import androidx.lifecycle.viewModelScope import com.ic.icfotaclient.App @@ -56,12 +55,6 @@ class OtaViewModel : ViewModel() { //升级数据 val otaInfo = MutableLiveData() - val testObserver = Transformations.switchMap(otaInfo) { otaInfo -> - val mutableLiveData = MutableLiveData() - mutableLiveData.value = otaInfo?.versionCode - mutableLiveData - } - //下载进度,百分比 val downloadProgress = MutableLiveData() @@ -98,8 +91,15 @@ class OtaViewModel : ViewModel() { return result } + private var hasCheck = false + //检查更新,需要在子线程种完成 fun checkUpdate(from: VersionCheckFrom) { + if (hasCheck) { + Log.d(TAG, "has checked..") + return + } + hasCheck = true if (currentActionState.value == UpdateActionState.CHECKING) { Log.d(TAG, "checking....") return @@ -203,6 +203,8 @@ class OtaViewModel : ViewModel() { private fun checkRemote(from: VersionCheckFrom) { if (!checkNetWork()) { currentActionState.postValue(UpdateActionState.NO_NETWORK) + //reset has check. + hasCheck = false Log.d(TAG, "no network...") return } @@ -222,34 +224,32 @@ class OtaViewModel : ViewModel() { checkHasNewVersion } //结果 - Log.d(TAG, "check result ==> $result") - otaInfo.postValue(result) + Log.d(TAG, "check result ==> $result ... ${Thread.currentThread().name}") + otaInfo.value = result //如果不为null,弹出一个系统级的dialog,也就是在任何地方都可以弹出的 - currentActionState.postValue( - if (result == null) { - //createNewVersionDialog( "无描述") - //已经是最新版本了 - UpdateActionState.LAST_VERSION + currentActionState.value = if (result == null) { + //createNewVersionDialog( "无描述") + //已经是最新版本了 + UpdateActionState.LAST_VERSION + } else { + //保存一下是哪家的平台,后面用于判断是否需要上报结果 + SPUtil.getSharePreference().edit() + .putString(SPUtil.KEY_SERVER_INC, result.serverInc.toString()) + .apply() + //如果是强制升级的,不等通知用户结果了直接升级 + if (result.isForce) { + Log.d(TAG, "force download data...") + //直接调用下载 + downloadPackage() } else { - //保存一下是哪家的平台,后面用于判断是否需要上报结果 - SPUtil.getSharePreference().edit() - .putString(SPUtil.KEY_SERVER_INC, result.serverInc.toString()) - .apply() - //如果是强制升级的,不等通知用户结果了直接升级 - if (result.isForce) { - Log.d(TAG, "force download data...") - //直接调用下载 - downloadPackage() - } else { - //不是UI来的,可以创建一个弹窗,否则不弹窗,非强制升级 - if (from != VersionCheckFrom.UI_CHECK) { - createNewVersionDialog(result.updateDesc ?: "无描述") - } + //不是UI来的,可以创建一个弹窗,否则不弹窗,非强制升级 + if (from != VersionCheckFrom.UI_CHECK) { + createNewVersionDialog(result.updateDesc ?: "无描述") } - //有新版本 - UpdateActionState.NEW_VERSION } - ) + //有新版本 + UpdateActionState.NEW_VERSION + } } catch (e: Exception) { Log.e(TAG, e.toString()) } @@ -286,6 +286,7 @@ class OtaViewModel : ViewModel() { } //判断size是否大于100M,如果大于100M的话那么就提示连接wifi进行下载 try { + Log.d(TAG, "otaInfo == > ${otaInfo.value}") if (otaInfo.value?.packageSize!! > 100000000L && !wifiConnected) { isTipsWifiConnect.postValue(true) //提示用户连接wifi下载 diff --git a/app/src/main/java/com/ic/icfotaclient/utils/ICOtaApiUtils.kt b/app/src/main/java/com/ic/icfotaclient/utils/ICOtaApiUtils.kt index 4a24cac..83abc5f 100644 --- a/app/src/main/java/com/ic/icfotaclient/utils/ICOtaApiUtils.kt +++ b/app/src/main/java/com/ic/icfotaclient/utils/ICOtaApiUtils.kt @@ -112,7 +112,7 @@ object ICOtaApiUtils { otaInfo = gson.fromJson(json, ICOtaInfo::class.java) if (otaInfo != null) { if (otaInfo!!.UptoDate) { - Log.d(TAG, "no update package in ic server.") + Log.d(TAG, "no update package in ic server...$isBackUpHost") if (!isBackUpHost) { isBackUpHost = true return getUpdateInfo(backupUrl) @@ -176,6 +176,7 @@ object ICOtaApiUtils { if (remoteHost == null || remoteHost.isEmpty() || remoteHost == "unknown") { remoteHost = "server-git:8089" } + Log.d(TAG, "remoteHost2 == > $remoteHost") return remoteHost }