From: TrillGates Date: Tue, 20 Jul 2021 14:10:07 +0000 (+0800) Subject: fixed host2 download issues. X-Git-Url: http://git.snicker.com.cn/Users/apple/Desktop/static/gitweb.css?a=commitdiff_plain;h=88e4cb901f0c3ac491b68e82a8d8237ed8f2ff42;p=icfotaclient.git fixed host2 download issues. --- 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 83abc5f..e802d10 100644 --- a/app/src/main/java/com/ic/icfotaclient/utils/ICOtaApiUtils.kt +++ b/app/src/main/java/com/ic/icfotaclient/utils/ICOtaApiUtils.kt @@ -97,35 +97,49 @@ object ICOtaApiUtils { if (okHttpClient == null) { initOkHttp() } - val request: Request = Request.Builder().url(url).build() - val newCall = okHttpClient?.newCall(request) - val response = newCall?.execute() - Log.d(TAG, "execute == > $response") - //解析数据 - 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(json, ICOtaInfo::class.java) - if (otaInfo != null) { - if (otaInfo!!.UptoDate) { - Log.d(TAG, "no update package in ic server...$isBackUpHost") - if (!isBackUpHost) { - isBackUpHost = true - return getUpdateInfo(backupUrl) + try { + val request: Request = Request.Builder().url(url).build() + val newCall = okHttpClient?.newCall(request) + val response = newCall?.execute() + Log.d(TAG, "execute == > $response") + //解析数据 + 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(json, ICOtaInfo::class.java) + if (otaInfo != null) { + if (otaInfo!!.UptoDate) { + Log.d(TAG, "no update package in ic server...$isBackUpHost") + if (!isBackUpHost) { + isBackUpHost = true + return getUpdateInfo(backupUrl) + } + //备份的服务器都走完了,还是没有升级包,就直接返回null + return null + } else { + //需要升级的,返回数据 + return OtaInfo( + otaInfo!!.AutoUpdate, + otaInfo!!.description, + otaInfo!!.OtaPackageVersion, + otaInfo!!.OtaPackageLength.toLong(), + System.currentTimeMillis(), + OtaInfo.ServerInc.IN_CAR + ) } } - return OtaInfo( - otaInfo!!.AutoUpdate, - otaInfo!!.description, - otaInfo!!.OtaPackageVersion, - otaInfo!!.OtaPackageLength.toLong(), - System.currentTimeMillis(), - OtaInfo.ServerInc.IN_CAR - ) + } + } catch (e: Exception) { + e.printStackTrace() + Log.d(TAG, "exception....$e") + //如果访问自己的出错了,再访问备用的 + if (!isBackUpHost) { + isBackUpHost = true + return getUpdateInfo(backupUrl) } } Log.d(TAG, "no update info...")