Skip to content

Commit 451dbe2

Browse files
committed
Feat: Improve Android detecting logic
Signed-off-by: imknown <imknown@qq.com>
1 parent 3d4271a commit 451dbe2

5 files changed

Lines changed: 35 additions & 37 deletions

File tree

app/src/main/java/net/imknown/android/forefrontinfo/ui/common/AndroidVersionExt.kt

Lines changed: 3 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,9 @@ import net.imknown.android.forefrontinfo.ui.home.model.Lld
1212
import java.util.Locale
1313
import kotlin.reflect.KClass
1414

15-
private const val CODENAME_RELEASE = "REL"
15+
const val CODENAME_NONE = ""
16+
const val CODENAME_CANARY = "CANARY"
17+
const val CODENAME_RELEASE = "REL"
1618

1719
/** See: [Build.VERSION_CODES_FULL].SDK_INT_MULTIPLIER */
1820
private const val SDK_INT_MULTIPLIER = 1_00000
@@ -122,21 +124,6 @@ fun isLatestPreviewAndroid(lld: Lld) = isPreviewAndroid()
122124
fun isSupportedByUpstreamAndroid(lld: Lld) = isStableAndroid()
123125
&& Build.VERSION.SDK_INT >= lld.android.support.api.toInt()
124126

125-
/** [Build.VERSION.RELEASE_OR_CODENAME]: Android 11+ */
126-
fun getAndroidDessertPreview(): String {
127-
val codename = Build.VERSION.CODENAME
128-
val suffix = if (isAtLeastAndroid13()) {
129-
if (codename != CODENAME_RELEASE && codename != Build.VERSION.RELEASE_OR_PREVIEW_DISPLAY) {
130-
", " + Build.VERSION.RELEASE_OR_PREVIEW_DISPLAY
131-
} else {
132-
""
133-
}
134-
} else {
135-
""
136-
}
137-
return "$codename$suffix"
138-
}
139-
140127
fun Context.isGoEdition() = isAtLeastAndroid8p1() && isLowRamDevice()
141128

142129
private fun Context.isLowRamDevice() = ContextCompat.getSystemService(

app/src/main/java/net/imknown/android/forefrontinfo/ui/home/model/Lld.kt

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,8 @@ package net.imknown.android.forefrontinfo.ui.home.model
33
import androidx.annotation.Keep
44
import kotlinx.serialization.EncodeDefault
55
import kotlinx.serialization.Serializable
6+
import net.imknown.android.forefrontinfo.ui.common.CODENAME_NONE
67

7-
const val CODENAME_NONE = ""
8-
const val CODENAME_CANARY = "CANARY"
98
const val EXTENSION_NONE = 0
109
const val SCHEME_VERSION = 1
1110

app/src/main/java/net/imknown/android/forefrontinfo/ui/home/repository/HomeRepository.kt

Lines changed: 17 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ import net.imknown.android.forefrontinfo.base.extension.formatToLocalZonedDateti
1919
import net.imknown.android.forefrontinfo.base.extension.fullMessage
2020
import net.imknown.android.forefrontinfo.ui.base.list.MyModel
2121
import net.imknown.android.forefrontinfo.ui.base.list.toColoredMyModel
22-
import net.imknown.android.forefrontinfo.ui.common.getAndroidDessertPreview
22+
import net.imknown.android.forefrontinfo.ui.common.CODENAME_CANARY
2323
import net.imknown.android.forefrontinfo.ui.common.getBooleanProperty
2424
import net.imknown.android.forefrontinfo.ui.common.getSdkExtension
2525
import net.imknown.android.forefrontinfo.ui.common.getShellResult
@@ -35,7 +35,7 @@ import net.imknown.android.forefrontinfo.ui.common.isAtLeastAndroid9
3535
import net.imknown.android.forefrontinfo.ui.common.isGoEdition
3636
import net.imknown.android.forefrontinfo.ui.common.isLatestPreviewAndroid
3737
import net.imknown.android.forefrontinfo.ui.common.isLatestStableAndroid
38-
import net.imknown.android.forefrontinfo.ui.common.isStableAndroid
38+
import net.imknown.android.forefrontinfo.ui.common.isPreviewAndroid
3939
import net.imknown.android.forefrontinfo.ui.common.isSupportedByUpstreamAndroid
4040
import net.imknown.android.forefrontinfo.ui.common.lastestApiFullAndDessert
4141
import net.imknown.android.forefrontinfo.ui.common.sdkFull
@@ -85,28 +85,27 @@ class HomeRepository(
8585
val android = lldAndroid.known.find {
8686
it.apiFull == sdkFull
8787
}
88-
var myVersionAndDessert = if (android != null) {
89-
val version = android.version + if (isStableAndroid()) {
90-
""
91-
} else {
88+
89+
fun String.toStableOrPreview(): String {
90+
var versionTemp = this
91+
if (isPreviewAndroid()) {
9292
val preview = MyApplication.getMyString(R.string.android_info_preview)
93-
" $preview"
93+
versionTemp += " $preview"
94+
95+
if (Build.VERSION.CODENAME == CODENAME_CANARY) {
96+
versionTemp += " $CODENAME_CANARY"
97+
}
9498
}
99+
return versionTemp
100+
}
101+
var myVersionAndDessert = if (android != null) {
102+
val version = android.version.toStableOrPreview()
95103
val dessert = android.name
96104
"$version, $dessert"
97105
} else {
98-
val version = Build.VERSION.RELEASE + if (isStableAndroid()) {
99-
""
100-
} else {
101-
val preview = MyApplication.getMyString(R.string.android_info_preview)
102-
" $preview"
103-
}
104-
val dessert = if (isStableAndroid()) {
105-
lastestApiFullAndDessert?.dessert
106+
val version = Build.VERSION.RELEASE.toStableOrPreview()
107+
val dessert = lastestApiFullAndDessert?.dessert
106108
?: MyApplication.getMyString(androidR.string.unknownName)
107-
} else {
108-
getAndroidDessertPreview()
109-
}
110109
"$version, $dessert"
111110
}
112111
if (MyApplication.instance.isGoEdition()) {

app/src/main/java/net/imknown/android/forefrontinfo/ui/others/datasource/RomDataSource.kt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@ class RomDataSource {
1818
fun getTags(): String = Build.TAGS
1919
fun getIncremental(): String = Build.VERSION.INCREMENTAL
2020
fun getCodename(): String = Build.VERSION.CODENAME
21+
@RequiresApi(Build.VERSION_CODES.TIRAMISU)
22+
fun getReleaseOrPreviewDisplay(): String = Build.VERSION.RELEASE_OR_PREVIEW_DISPLAY
2123
@RequiresApi(Build.VERSION_CODES.M)
2224
fun getPreviewSdkInt(): Int = Build.VERSION.PREVIEW_SDK_INT
2325

app/src/main/java/net/imknown/android/forefrontinfo/ui/others/repository/OthersRepository.kt

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@ import net.imknown.android.forefrontinfo.base.MyApplication
99
import net.imknown.android.forefrontinfo.base.extension.formatToLocalZonedDatetimeString
1010
import net.imknown.android.forefrontinfo.ui.base.list.MyModel
1111
import net.imknown.android.forefrontinfo.ui.base.list.toTranslatedDetailMyModel
12+
import net.imknown.android.forefrontinfo.ui.common.isAtLeastAndroid13
13+
import net.imknown.android.forefrontinfo.ui.common.isPreviewAndroid
1214
import net.imknown.android.forefrontinfo.ui.others.datasource.ArchitectureDataSource
1315
import net.imknown.android.forefrontinfo.ui.others.datasource.BasicDataSource
1416
import net.imknown.android.forefrontinfo.ui.others.datasource.FingerprintDataSource
@@ -126,7 +128,16 @@ class OthersRepository(
126128
fun getType() = toTranslatedDetailMyModel(MyApplication.getMyString(R.string.build_type), romDataSource.getType())
127129
fun getTags() = toTranslatedDetailMyModel(MyApplication.getMyString(R.string.build_tags), romDataSource.getTags())
128130
fun getIncremental() = toTranslatedDetailMyModel(MyApplication.getMyString(R.string.build_incremental), romDataSource.getIncremental())
129-
fun getCodename() = toTranslatedDetailMyModel(MyApplication.getMyString(R.string.build_codename), romDataSource.getCodename())
131+
fun getCodename(): MyModel {
132+
var detail = romDataSource.getCodename()
133+
if (isPreviewAndroid() && isAtLeastAndroid13()) {
134+
val previewDisplay = romDataSource.getReleaseOrPreviewDisplay()
135+
if (detail != previewDisplay) {
136+
detail += " ($previewDisplay)"
137+
}
138+
}
139+
return toTranslatedDetailMyModel(MyApplication.getMyString(R.string.build_codename), detail)
140+
}
130141
@RequiresApi(Build.VERSION_CODES.M)
131142
fun getPreviewSdkInt() = toTranslatedDetailMyModel(MyApplication.getMyString(R.string.build_preview_sdk_int), romDataSource.getPreviewSdkInt().toString())
132143

0 commit comments

Comments
 (0)