Skip to content

Commit

Permalink
app: Fix nullPointer caused by failure to get ultimateota link
Browse files Browse the repository at this point in the history
* For example: rothko OS2.0.5.0.VNNCNXM
  • Loading branch information
YuKongA committed Nov 18, 2024
1 parent 9a26758 commit a64b1c9
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 25 deletions.
31 changes: 24 additions & 7 deletions composeApp/src/commonMain/kotlin/misc/AppUtils.kt
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,8 @@ fun updateRomInfo(
val messageWrongResult = stringResource(Res.string.toast_wrong_info)
val messageCrashResult = stringResource(Res.string.toast_crash_info)

var noUltimateLink = false

val coroutineScope = rememberCoroutineScope()

if (updateRomInfo.value != 0) {
Expand All @@ -100,13 +102,22 @@ fun updateRomInfo(

if (recoveryRomInfo.currentRom?.bigversion != null) {

println(recoveryRomInfo.currentRom)
println(recoveryRomInfo.latestRom)
val curRomDownload = if (recoveryRomInfo.currentRom.md5 != recoveryRomInfo.latestRom?.md5) {
val romInfoCurrent = getRecoveryRomInfo("", codeNameExt, regionCode, systemVersionExt, androidVersion.value, isLogin)
val recoveryRomInfoCurrent = json.decodeFromString<RomInfoHelper.RomInfo>(romInfoCurrent)
downloadUrl(recoveryRomInfoCurrent.currentRom?.version!!, recoveryRomInfoCurrent.latestRom?.filename!!)
println(recoveryRomInfoCurrent)
if (recoveryRomInfoCurrent.currentRom != null) {
noUltimateLink = false
downloadUrl(recoveryRomInfoCurrent.currentRom.version!!, recoveryRomInfoCurrent.latestRom?.filename!!)
} else {
noUltimateLink = true
downloadUrl(recoveryRomInfo.currentRom.version!!, recoveryRomInfo.currentRom.filename!!)
}
} else downloadUrl(recoveryRomInfo.currentRom.version!!, recoveryRomInfo.latestRom?.filename!!)

handleRomInfo(recoveryRomInfo, recoveryRomInfo.currentRom, curRomInfo, curIconInfo, curRomDownload)
handleRomInfo(recoveryRomInfo, recoveryRomInfo.currentRom, curRomInfo, curIconInfo, curRomDownload, noUltimateLink)

perfSet("deviceName", deviceName.value)
perfSet("codeName", codeName.value)
Expand Down Expand Up @@ -163,13 +174,15 @@ fun updateRomInfo(
* @param romInfoData: Data used to display ROM info
* @param iconInfoData: Data used to display changelog icons
* @param officialDownload: Official download URL
* @param noUltimateLink: No ultimate download link
*/
fun handleRomInfo(
recoveryRomInfo: RomInfoHelper.RomInfo,
romInfo: RomInfoHelper.Rom?,
romInfoData: MutableState<DataHelper.RomInfoData>,
iconInfoData: MutableState<List<DataHelper.IconInfoData>>,
officialDownload: String? = null
officialDownload: String? = null,
noUltimateLink: Boolean = false
) {
if (romInfo?.bigversion != null) {
val log = StringBuilder()
Expand Down Expand Up @@ -206,10 +219,14 @@ fun handleRomInfo(
},
fileName = romInfo.filename.toString().substringBefore(".zip") + ".zip",
fileSize = romInfo.filesize.toString(),
official1Download = "https://ultimateota.d.miui.com" + (officialDownload ?: downloadUrl(romInfo.version, romInfo.filename)),
official2Download = "https://superota.d.miui.com" + (officialDownload ?: downloadUrl(romInfo.version, romInfo.filename)),
cdn1Download = "https://cdnorg.d.miui.com" + downloadUrl(romInfo.version, romInfo.filename),
cdn2Download = "https://bkt-sgp-miui-ota-update-alisgp.oss-ap-southeast-1.aliyuncs.com" + downloadUrl(romInfo.version, romInfo.filename),
official1Download = if (noUltimateLink) "" else {
"https://ultimateota.d.miui.com" + (officialDownload ?: downloadUrl(romInfo.version, romInfo.filename))
},
official2Download = if (noUltimateLink) "" else {
"https://superota.d.miui.com" + (officialDownload ?: downloadUrl(romInfo.version, romInfo.filename))
},
cdn1Download = "https://bkt-sgp-miui-ota-update-alisgp.oss-ap-southeast-1.aliyuncs.com" + downloadUrl(romInfo.version, romInfo.filename),
cdn2Download = "https://cdnorg.d.miui.com" + downloadUrl(romInfo.version, romInfo.filename),
changelog = log.toString().trimEnd()
)
}
Expand Down
38 changes: 20 additions & 18 deletions composeApp/src/commonMain/kotlin/ui/InfoCardViews.kt
Original file line number Diff line number Diff line change
Expand Up @@ -99,22 +99,24 @@ fun InfoCardViews(
fontSize = bodySmallFontSize
)

Row(
modifier = Modifier.fillMaxWidth(),
horizontalArrangement = Arrangement.Start
) {
DownloadInfoView(
modifier = Modifier.weight(1f),
"ultimateota",
romInfoState.value.official1Download,
romInfoState.value.fileName
)
DownloadInfoView(
modifier = Modifier.weight(1f),
"superota",
romInfoState.value.official2Download,
romInfoState.value.fileName
)
if (romInfoState.value.official1Download.isNotEmpty()) {
Row(
modifier = Modifier.fillMaxWidth(),
horizontalArrangement = Arrangement.Start
) {
DownloadInfoView(
modifier = Modifier.weight(1f),
"ultimateota",
romInfoState.value.official1Download,
romInfoState.value.fileName
)
DownloadInfoView(
modifier = Modifier.weight(1f),
"superota",
romInfoState.value.official2Download,
romInfoState.value.fileName
)
}
}

Row(
Expand All @@ -123,13 +125,13 @@ fun InfoCardViews(
) {
DownloadInfoView(
modifier = Modifier.weight(1f),
"cdnorg",
"aliyuncs",
romInfoState.value.cdn1Download,
romInfoState.value.fileName
)
DownloadInfoView(
modifier = Modifier.weight(1f),
"aliyuncs",
"cdnorg",
romInfoState.value.cdn2Download,
romInfoState.value.fileName
)
Expand Down

0 comments on commit a64b1c9

Please sign in to comment.