Merge changes from topic "catalyst-firmware-version" into main
* changes: Migrate "Build number" preference Migrate "Kernel version" preference Migrate "Baseband version" preference
This commit is contained in:
@@ -0,0 +1,57 @@
|
||||
/*
|
||||
* Copyright (C) 2024 The Android Open Source Project
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package com.android.settings.deviceinfo.firmwareversion
|
||||
|
||||
import android.content.Context
|
||||
import android.os.SystemProperties
|
||||
import androidx.preference.Preference
|
||||
import com.android.settings.R
|
||||
import com.android.settings.Utils
|
||||
import com.android.settingslib.metadata.PreferenceAvailabilityProvider
|
||||
import com.android.settingslib.metadata.PreferenceMetadata
|
||||
import com.android.settingslib.metadata.PreferenceSummaryProvider
|
||||
import com.android.settingslib.preference.PreferenceBinding
|
||||
|
||||
// LINT.IfChange
|
||||
class BasebandVersionPreference :
|
||||
PreferenceMetadata,
|
||||
PreferenceSummaryProvider,
|
||||
PreferenceAvailabilityProvider,
|
||||
PreferenceBinding {
|
||||
|
||||
override val key: String
|
||||
get() = "base_band"
|
||||
|
||||
override val title: Int
|
||||
get() = R.string.baseband_version
|
||||
|
||||
override fun getSummary(context: Context): CharSequence? =
|
||||
SystemProperties.get(BASEBAND_PROPERTY, context.getString(R.string.device_info_default))
|
||||
|
||||
override fun isAvailable(context: Context) = !Utils.isWifiOnly(context)
|
||||
|
||||
override fun bind(preference: Preference, metadata: PreferenceMetadata) {
|
||||
super.bind(preference, metadata)
|
||||
preference.isSelectable = false
|
||||
preference.isCopyingEnabled = true
|
||||
}
|
||||
|
||||
companion object {
|
||||
const val BASEBAND_PROPERTY: String = "gsm.version.baseband"
|
||||
}
|
||||
}
|
||||
// LINT.ThenChange(BasebandVersionPreferenceController.java)
|
@@ -25,6 +25,7 @@ import com.android.settings.R;
|
||||
import com.android.settings.Utils;
|
||||
import com.android.settings.core.BasePreferenceController;
|
||||
|
||||
// LINT.IfChange
|
||||
public class BasebandVersionPreferenceController extends BasePreferenceController {
|
||||
|
||||
@VisibleForTesting
|
||||
@@ -45,3 +46,4 @@ public class BasebandVersionPreferenceController extends BasePreferenceControlle
|
||||
mContext.getString(R.string.device_info_default));
|
||||
}
|
||||
}
|
||||
// LINT.ThenChange(BasebandVersionPreference.kt)
|
||||
|
@@ -50,9 +50,9 @@ class FirmwareVersionScreen : PreferenceScreenCreator, PreferenceSummaryProvider
|
||||
+PreferenceWidget("os_firmware_version", R.string.firmware_version)
|
||||
+PreferenceWidget("security_key", R.string.security_patch)
|
||||
+PreferenceWidget("module_version", R.string.module_version)
|
||||
+PreferenceWidget("base_band", R.string.baseband_version)
|
||||
+PreferenceWidget("kernel_version", R.string.kernel_version)
|
||||
+PreferenceWidget("os_build_number", R.string.build_number)
|
||||
+BasebandVersionPreference()
|
||||
+KernelVersionPreference()
|
||||
+SimpleBuildNumberPreference()
|
||||
}
|
||||
|
||||
private class PreferenceWidget(override val key: String, override val title: Int) :
|
||||
|
@@ -0,0 +1,45 @@
|
||||
/*
|
||||
* Copyright (C) 2024 The Android Open Source Project
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package com.android.settings.deviceinfo.firmwareversion
|
||||
|
||||
import android.content.Context
|
||||
import androidx.preference.Preference
|
||||
import com.android.settings.R
|
||||
import com.android.settingslib.DeviceInfoUtils
|
||||
import com.android.settingslib.metadata.PreferenceMetadata
|
||||
import com.android.settingslib.metadata.PreferenceSummaryProvider
|
||||
import com.android.settingslib.preference.PreferenceBinding
|
||||
|
||||
// LINT.IfChange
|
||||
class KernelVersionPreference : PreferenceMetadata, PreferenceSummaryProvider, PreferenceBinding {
|
||||
|
||||
override val key: String
|
||||
get() = "kernel_version"
|
||||
|
||||
override val title: Int
|
||||
get() = R.string.kernel_version
|
||||
|
||||
override fun getSummary(context: Context): CharSequence? =
|
||||
DeviceInfoUtils.getFormattedKernelVersion(context)
|
||||
|
||||
override fun bind(preference: Preference, metadata: PreferenceMetadata) {
|
||||
super.bind(preference, metadata)
|
||||
preference.isSelectable = false
|
||||
preference.isCopyingEnabled = true
|
||||
}
|
||||
}
|
||||
// LINT.ThenChange(KernelVersionPreferenceController.java)
|
@@ -21,6 +21,7 @@ import android.content.Context;
|
||||
import com.android.settings.core.BasePreferenceController;
|
||||
import com.android.settingslib.DeviceInfoUtils;
|
||||
|
||||
// LINT.IfChange
|
||||
public class KernelVersionPreferenceController extends BasePreferenceController {
|
||||
|
||||
public KernelVersionPreferenceController(Context context, String preferenceKey) {
|
||||
@@ -37,3 +38,4 @@ public class KernelVersionPreferenceController extends BasePreferenceController
|
||||
return DeviceInfoUtils.getFormattedKernelVersion(mContext);
|
||||
}
|
||||
}
|
||||
// LINT.ThenChange(KernelVersionPreference.kt)
|
||||
|
@@ -0,0 +1,52 @@
|
||||
/*
|
||||
* Copyright (C) 2024 The Android Open Source Project
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package com.android.settings.deviceinfo.firmwareversion
|
||||
|
||||
import android.content.Context
|
||||
import android.os.Build
|
||||
import android.text.BidiFormatter
|
||||
import android.view.View.LAYOUT_DIRECTION_RTL
|
||||
import androidx.preference.Preference
|
||||
import com.android.settings.R
|
||||
import com.android.settingslib.metadata.PreferenceMetadata
|
||||
import com.android.settingslib.metadata.PreferenceSummaryProvider
|
||||
import com.android.settingslib.preference.PreferenceBinding
|
||||
|
||||
// LINT.IfChange
|
||||
class SimpleBuildNumberPreference :
|
||||
PreferenceMetadata, PreferenceSummaryProvider, PreferenceBinding {
|
||||
|
||||
override val key: String
|
||||
get() = "os_build_number"
|
||||
|
||||
override val title: Int
|
||||
get() = R.string.build_number
|
||||
|
||||
override fun isIndexable(context: Context) = false
|
||||
|
||||
override fun getSummary(context: Context): CharSequence? {
|
||||
val isRtl = context.resources.configuration.layoutDirection == LAYOUT_DIRECTION_RTL
|
||||
return BidiFormatter.getInstance(isRtl).unicodeWrap(Build.DISPLAY)
|
||||
}
|
||||
|
||||
override fun bind(preference: Preference, metadata: PreferenceMetadata) {
|
||||
super.bind(preference, metadata)
|
||||
preference.isSelectable = false
|
||||
preference.isCopyingEnabled = true
|
||||
}
|
||||
}
|
||||
// LINT.ThenChange(SimpleBuildNumberPreferenceController.java)
|
@@ -22,6 +22,7 @@ import android.text.BidiFormatter;
|
||||
|
||||
import com.android.settings.core.BasePreferenceController;
|
||||
|
||||
// LINT.IfChange
|
||||
public class SimpleBuildNumberPreferenceController extends BasePreferenceController {
|
||||
|
||||
public SimpleBuildNumberPreferenceController(Context context,
|
||||
@@ -39,3 +40,4 @@ public class SimpleBuildNumberPreferenceController extends BasePreferenceControl
|
||||
return BidiFormatter.getInstance().unicodeWrap(Build.DISPLAY);
|
||||
}
|
||||
}
|
||||
// LINT.ThenChange(SimpleBuildNumberPreference.kt)
|
||||
|
@@ -69,6 +69,9 @@ android_robolectric_test {
|
||||
"com_android_server_accessibility_flags_lib",
|
||||
"flag-junit",
|
||||
"flag-junit-base",
|
||||
"kotlin-test",
|
||||
"mockito-robolectric-prebuilt", // mockito deps order matters!
|
||||
"mockito-kotlin2",
|
||||
"notification_flags_lib",
|
||||
"platform-test-annotations",
|
||||
"testables",
|
||||
|
@@ -38,6 +38,7 @@ import org.robolectric.RuntimeEnvironment;
|
||||
|
||||
import java.util.Arrays;
|
||||
|
||||
// LINT.IfChange
|
||||
@RunWith(RobolectricTestRunner.class)
|
||||
public class BasebandVersionPreferenceControllerTest {
|
||||
@Mock
|
||||
@@ -68,3 +69,4 @@ public class BasebandVersionPreferenceControllerTest {
|
||||
assertThat(mController.getAvailabilityStatus()).isEqualTo(AVAILABLE);
|
||||
}
|
||||
}
|
||||
// LINT.ThenChange(BasebandVersionPreferenceTest.kt)
|
||||
|
@@ -0,0 +1,60 @@
|
||||
/*
|
||||
* Copyright (C) 2024 The Android Open Source Project
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package com.android.settings.deviceinfo.firmwareversion
|
||||
|
||||
import android.content.Context
|
||||
import android.content.ContextWrapper
|
||||
import android.sysprop.TelephonyProperties
|
||||
import android.telephony.TelephonyManager
|
||||
import androidx.test.core.app.ApplicationProvider
|
||||
import com.google.common.truth.Truth.assertThat
|
||||
import org.junit.Test
|
||||
import org.junit.runner.RunWith
|
||||
import org.mockito.kotlin.doReturn
|
||||
import org.mockito.kotlin.mock
|
||||
import org.robolectric.RobolectricTestRunner
|
||||
|
||||
// LINT.IfChange
|
||||
@RunWith(RobolectricTestRunner::class)
|
||||
class BasebandVersionPreferenceTest {
|
||||
private lateinit var telephonyManager: TelephonyManager
|
||||
|
||||
private val context: Context =
|
||||
object : ContextWrapper(ApplicationProvider.getApplicationContext()) {
|
||||
override fun getSystemService(name: String): Any? =
|
||||
when {
|
||||
name == getSystemServiceName(TelephonyManager::class.java) -> telephonyManager
|
||||
else -> super.getSystemService(name)
|
||||
}
|
||||
}
|
||||
|
||||
private val basebandVersionPreference = BasebandVersionPreference()
|
||||
|
||||
@Test
|
||||
fun isAvailable_wifiOnly_unavailable() {
|
||||
telephonyManager = mock { on { isDataCapable } doReturn false }
|
||||
assertThat(basebandVersionPreference.isAvailable(context)).isFalse()
|
||||
}
|
||||
|
||||
@Test
|
||||
fun isAvailable_hasMobile_available() {
|
||||
TelephonyProperties.baseband_version(listOf("test"))
|
||||
telephonyManager = mock { on { isDataCapable } doReturn true }
|
||||
assertThat(basebandVersionPreference.isAvailable(context)).isTrue()
|
||||
}
|
||||
}
|
||||
// LINT.ThenChange(BasebandVersionPreferenceControllerTest.java)
|
@@ -29,6 +29,7 @@ import org.mockito.MockitoAnnotations;
|
||||
import org.robolectric.RobolectricTestRunner;
|
||||
import org.robolectric.RuntimeEnvironment;
|
||||
|
||||
// LINT.IfChange
|
||||
@RunWith(RobolectricTestRunner.class)
|
||||
public class KernelVersionPreferenceControllerTest {
|
||||
|
||||
@@ -49,3 +50,4 @@ public class KernelVersionPreferenceControllerTest {
|
||||
DeviceInfoUtils.getFormattedKernelVersion(mContext));
|
||||
}
|
||||
}
|
||||
// LINT.ThenChange(KernelVersionPreferenceTest.kt)
|
||||
|
@@ -0,0 +1,40 @@
|
||||
/*
|
||||
* Copyright (C) 2024 The Android Open Source Project
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package com.android.settings.deviceinfo.firmwareversion
|
||||
|
||||
import android.content.Context
|
||||
import androidx.test.core.app.ApplicationProvider
|
||||
import com.android.settingslib.DeviceInfoUtils
|
||||
import com.google.common.truth.Truth.assertThat
|
||||
import org.junit.Test
|
||||
import org.junit.runner.RunWith
|
||||
import org.robolectric.RobolectricTestRunner
|
||||
|
||||
// LINT.IfChange
|
||||
@RunWith(RobolectricTestRunner::class)
|
||||
class KernelVersionPreferenceTest {
|
||||
private val context: Context = ApplicationProvider.getApplicationContext()
|
||||
|
||||
private val kernelVersionPreference = KernelVersionPreference()
|
||||
|
||||
@Test
|
||||
fun getSummary() {
|
||||
assertThat(kernelVersionPreference.getSummary(context))
|
||||
.isEqualTo(DeviceInfoUtils.getFormattedKernelVersion(context))
|
||||
}
|
||||
}
|
||||
// LINT.ThenChange(KernelVersionPreferenceControllerTest.java)
|
@@ -29,6 +29,7 @@ import org.mockito.MockitoAnnotations;
|
||||
import org.robolectric.RobolectricTestRunner;
|
||||
import org.robolectric.RuntimeEnvironment;
|
||||
|
||||
// LINT.IfChange
|
||||
@RunWith(RobolectricTestRunner.class)
|
||||
public class SimpleBuildNumberPreferenceControllerTest {
|
||||
|
||||
@@ -48,3 +49,4 @@ public class SimpleBuildNumberPreferenceControllerTest {
|
||||
assertThat(mController.getAvailabilityStatus()).isEqualTo(AVAILABLE_UNSEARCHABLE);
|
||||
}
|
||||
}
|
||||
// LINT.ThenChange(SimpleBuildNumberPreferenceTest.kt)
|
||||
|
@@ -0,0 +1,55 @@
|
||||
/*
|
||||
* Copyright (C) 2024 The Android Open Source Project
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package com.android.settings.deviceinfo.firmwareversion
|
||||
|
||||
import android.content.Context
|
||||
import android.os.Build
|
||||
import android.text.BidiFormatter
|
||||
import androidx.test.core.app.ApplicationProvider
|
||||
import com.google.common.truth.Truth.assertThat
|
||||
import java.util.Locale
|
||||
import org.junit.Test
|
||||
import org.junit.runner.RunWith
|
||||
import org.robolectric.RobolectricTestRunner
|
||||
|
||||
// LINT.IfChange
|
||||
@RunWith(RobolectricTestRunner::class)
|
||||
class SimpleBuildNumberPreferenceTest {
|
||||
private val context: Context = ApplicationProvider.getApplicationContext()
|
||||
|
||||
private val simpleBuildNumberPreference = SimpleBuildNumberPreference()
|
||||
|
||||
@Test
|
||||
fun isIndexable() {
|
||||
assertThat(simpleBuildNumberPreference.isIndexable(context)).isFalse()
|
||||
}
|
||||
|
||||
@Test
|
||||
fun getSummary_ltr() {
|
||||
context.resources.configuration.setLayoutDirection(Locale.ENGLISH)
|
||||
assertThat(simpleBuildNumberPreference.getSummary(context))
|
||||
.isEqualTo(BidiFormatter.getInstance(false).unicodeWrap(Build.DISPLAY))
|
||||
}
|
||||
|
||||
@Test
|
||||
fun getSummary_rtl() {
|
||||
context.resources.configuration.setLayoutDirection(Locale("ar"))
|
||||
assertThat(simpleBuildNumberPreference.getSummary(context))
|
||||
.isEqualTo(BidiFormatter.getInstance(true).unicodeWrap(Build.DISPLAY))
|
||||
}
|
||||
}
|
||||
// LINT.ThenChange(SimpleBuildNumberPreferenceControllerTest.java)
|
Reference in New Issue
Block a user