From: TrillGates Date: Fri, 29 Jan 2021 02:39:33 +0000 (+0800) Subject: remove suspend tag X-Git-Url: http://git.snicker.com.cn/?a=commitdiff_plain;h=ee91fdd7c998be10c1fa96afb8b0895fb4df0880;p=icfotaclient.git remove suspend tag --- diff --git a/app/src/main/java/com/ic/icfotaclient/base/AbstractOtaRepository.kt b/app/src/main/java/com/ic/icfotaclient/base/AbstractOtaRepository.kt index a943fc3..5912b97 100644 --- a/app/src/main/java/com/ic/icfotaclient/base/AbstractOtaRepository.kt +++ b/app/src/main/java/com/ic/icfotaclient/base/AbstractOtaRepository.kt @@ -9,35 +9,35 @@ abstract class AbstractOtaRepository : IOtaBaseRepository { var mNextRepository: IOtaBaseRepository? = null - override suspend fun setNextRepository(nextRepository: IOtaBaseRepository) { + override fun setNextRepository(nextRepository: IOtaBaseRepository) { this.mNextRepository = nextRepository } - override suspend fun checkHasNewVersion(): OtaInfo? { + override fun checkHasNewVersion(): OtaInfo? { return mNextRepository?.checkHasNewVersion() } - override suspend fun downloadPackage(callback: IOtaRepositoryCallback): DownloadInfo? { + override fun downloadPackage(callback: IOtaRepositoryCallback): DownloadInfo? { return mNextRepository?.downloadPackage(callback) } - override suspend fun reportInstallResult(isSuccess: Boolean) { + override fun reportInstallResult(isSuccess: Boolean) { mNextRepository?.reportInstallResult(isSuccess) } - override suspend fun reportResult(versionCode: String) { + override fun reportResult(versionCode: String) { mNextRepository?.reportResult(versionCode) } - override suspend fun getPackagePath(): String? { + override fun getPackagePath(): String? { return mNextRepository?.getPackagePath() } - override suspend fun deletePackage() { + override fun deletePackage() { mNextRepository?.deletePackage() } - override suspend fun pauseDownload() { + override fun pauseDownload() { mNextRepository?.pauseDownload() } } \ No newline at end of file diff --git a/app/src/main/java/com/ic/icfotaclient/base/IOtaBaseRepository.kt b/app/src/main/java/com/ic/icfotaclient/base/IOtaBaseRepository.kt index 26a6ab9..9c92663 100644 --- a/app/src/main/java/com/ic/icfotaclient/base/IOtaBaseRepository.kt +++ b/app/src/main/java/com/ic/icfotaclient/base/IOtaBaseRepository.kt @@ -9,42 +9,42 @@ interface IOtaBaseRepository { /** * 检查是否有新的版本 */ - suspend fun checkHasNewVersion(): OtaInfo? + fun checkHasNewVersion(): OtaInfo? /** * 下载升级包 */ - suspend fun downloadPackage(callback: IOtaRepositoryCallback): DownloadInfo? + fun downloadPackage(callback: IOtaRepositoryCallback): DownloadInfo? /** * 通知升级结果 */ - suspend fun reportInstallResult(isSuccess: Boolean); + fun reportInstallResult(isSuccess: Boolean); /** * 通知更新成功,让服务器收费 */ - suspend fun reportResult(versionCode: String) + fun reportResult(versionCode: String) /** * 获取升级包的路径 */ - suspend fun getPackagePath(): String? + fun getPackagePath(): String? /** * 删除升级包 */ - suspend fun deletePackage() + fun deletePackage() /** * 设置下一级委托的Repository */ - suspend fun setNextRepository(nextRepository: IOtaBaseRepository) + fun setNextRepository(nextRepository: IOtaBaseRepository) /** * 暂停下载 */ - suspend fun pauseDownload() + fun pauseDownload() } \ No newline at end of file diff --git a/app/src/main/java/com/ic/icfotaclient/repository/CarOtaRepository.kt b/app/src/main/java/com/ic/icfotaclient/repository/CarOtaRepository.kt index cc29b4f..a63ecd3 100644 --- a/app/src/main/java/com/ic/icfotaclient/repository/CarOtaRepository.kt +++ b/app/src/main/java/com/ic/icfotaclient/repository/CarOtaRepository.kt @@ -11,7 +11,8 @@ 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.* +import java.io.FileInputStream +import java.io.FileOutputStream /** * 科洛达的Repository @@ -44,7 +45,7 @@ class CarOtaRepository : AbstractOtaRepository() { ) } - override suspend fun downloadPackage(callback: IOtaRepositoryCallback): DownloadInfo? { + override fun downloadPackage(callback: IOtaRepositoryCallback): DownloadInfo? { mCallback = callback val download = CarOtaApiUtils.mClient.download(object : IDownloadEvent { override fun onDownloading(downloaded: Long, total: Long, extra: Bundle?) { @@ -67,30 +68,27 @@ class CarOtaRepository : AbstractOtaRepository() { } }) ?: return null - //转一下 - Log.d(TAG, "download == > ${download.file}") + //复制到对应的位置 + val sourceFile = download.file val targetFile = VersionInfoUtils.getFlashPath() - 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) - val bos = BufferedOutputStream(fos) - val buf = ByteArray(1024) - var len = 0; - while (true) { - len = bis.read(buf) - if (len == -1) break; - bos.write(buf, 0, len) + Log.d(TAG, "download == > $sourceFile") + try { + val fis = FileInputStream(sourceFile) + val fos = FileOutputStream(targetFile) + val buf = ByteArray(1024) + var len: Int + var total = 0 + while (fis.read(buf).also { + len = it + } != -1) { + fos.write(buf, 0, len) + total += len + } + fis.close() + fos.close() + } catch (e: Exception) { + e.printStackTrace() } - fis.close() - fos.close() Log.d(OtaViewModel.TAG, "copy finished to target path == > $targetFile") val downloadInfo = DownloadInfo(download.file.path, 0L) downloadInfo.path = targetFile diff --git a/app/src/main/java/com/ic/icfotaclient/repository/ICOtaRepository.kt b/app/src/main/java/com/ic/icfotaclient/repository/ICOtaRepository.kt index ea4a896..af4edbb 100644 --- a/app/src/main/java/com/ic/icfotaclient/repository/ICOtaRepository.kt +++ b/app/src/main/java/com/ic/icfotaclient/repository/ICOtaRepository.kt @@ -23,7 +23,7 @@ class ICOtaRepository : AbstractOtaRepository() { /** * 检查是否有更新,英卡的服务器 */ - override suspend fun checkHasNewVersion(): OtaInfo? { + override fun checkHasNewVersion(): OtaInfo? { try { //调用一下英卡的接口 checkIcVersion = ICOtaApiUtils.checkIcVersion() @@ -38,7 +38,7 @@ class ICOtaRepository : AbstractOtaRepository() { } - override suspend fun pauseDownload() { + override fun pauseDownload() { if (checkIcVersion != null) { Toast.makeText( App.sContext, @@ -50,7 +50,7 @@ class ICOtaRepository : AbstractOtaRepository() { } - override suspend fun downloadPackage(callback: IOtaRepositoryCallback): DownloadInfo? { + override fun downloadPackage(callback: IOtaRepositoryCallback): DownloadInfo? { //下载安装包,直接当前线程调用即可 //如果这个有安装包就不需要往下去下载了。 if (checkIcVersion != null) { @@ -60,7 +60,7 @@ class ICOtaRepository : AbstractOtaRepository() { return super.downloadPackage(callback) } - override suspend fun reportResult(versionCode: String) { + override fun reportResult(versionCode: String) { if (checkIcVersion != null) { return } @@ -68,14 +68,14 @@ class ICOtaRepository : AbstractOtaRepository() { } - override suspend fun reportInstallResult(isSuccess: Boolean) { + override fun reportInstallResult(isSuccess: Boolean) { if (checkIcVersion != null) { return } super.reportInstallResult(isSuccess) } - override suspend fun deletePackage() { + override fun deletePackage() { //删除flash_root下的 val file = File(VersionInfoUtils.getFlashPath()) if (file.exists()) {