Migrate About phone
Add the skeleton of About phone
Bug: 373001670
Test: atest MyDeviceInfoScreenTest
Flag: com.android.settings.flags.catalyst_my_device_info_pref_screen
Change-Id: I7799fa5fb82f9dd96959f1419108d15e7e4f7bb9
diff --git a/aconfig/catalyst/about_phone.aconfig b/aconfig/catalyst/about_phone.aconfig
index 5403b65..8ecde46 100644
--- a/aconfig/catalyst/about_phone.aconfig
+++ b/aconfig/catalyst/about_phone.aconfig
@@ -15,3 +15,9 @@
bug: "323791114"
}
+flag {
+ name: "catalyst_my_device_info_pref_screen"
+ namespace: "android_settings"
+ description: "Flag for About phone"
+ bug: "323791114"
+}
diff --git a/src/com/android/settings/deviceinfo/aboutphone/MyDeviceInfoFragment.java b/src/com/android/settings/deviceinfo/aboutphone/MyDeviceInfoFragment.java
index 50b6097..e209d85 100644
--- a/src/com/android/settings/deviceinfo/aboutphone/MyDeviceInfoFragment.java
+++ b/src/com/android/settings/deviceinfo/aboutphone/MyDeviceInfoFragment.java
@@ -25,6 +25,9 @@
import android.os.UserManager;
import android.view.View;
+import androidx.annotation.NonNull;
+import androidx.annotation.Nullable;
+
import com.android.settings.R;
import com.android.settings.Utils;
import com.android.settings.dashboard.DashboardFragment;
@@ -211,6 +214,11 @@
controller.updateDeviceName(confirm);
}
+ @Override
+ public @Nullable String getPreferenceScreenBindingKey(@NonNull Context context) {
+ return MyDeviceInfoScreen.KEY;
+ }
+
/**
* For Search.
*/
diff --git a/src/com/android/settings/deviceinfo/aboutphone/MyDeviceInfoScreen.kt b/src/com/android/settings/deviceinfo/aboutphone/MyDeviceInfoScreen.kt
new file mode 100644
index 0000000..254a91e
--- /dev/null
+++ b/src/com/android/settings/deviceinfo/aboutphone/MyDeviceInfoScreen.kt
@@ -0,0 +1,62 @@
+/*
+ * 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.aboutphone
+
+import android.content.Context
+import android.os.Build
+import android.provider.Settings
+import com.android.settings.R
+import com.android.settings.flags.Flags
+import com.android.settingslib.metadata.PreferenceIconProvider
+import com.android.settingslib.metadata.PreferenceSummaryProvider
+import com.android.settingslib.metadata.ProvidePreferenceScreen
+import com.android.settingslib.metadata.preferenceHierarchy
+import com.android.settingslib.preference.PreferenceScreenCreator
+
+@ProvidePreferenceScreen
+class MyDeviceInfoScreen :
+ PreferenceScreenCreator, PreferenceSummaryProvider, PreferenceIconProvider {
+ override val key: String
+ get() = KEY
+
+ override val title: Int
+ get() = R.string.about_settings
+
+ override fun getSummary(context: Context): CharSequence? {
+ return Settings.Global.getString(context.contentResolver, Settings.Global.DEVICE_NAME)
+ ?: Build.MODEL
+ }
+
+ override fun getIcon(context: Context): Int {
+ return when (Flags.homepageRevamp()) {
+ true -> R.drawable.ic_settings_about_device_filled
+ false -> R.drawable.ic_settings_about_device
+ }
+ }
+
+ override fun isFlagEnabled(context: Context) = Flags.catalystMyDeviceInfoPrefScreen()
+
+ override fun fragmentClass() = MyDeviceInfoFragment::class.java
+
+ override fun getPreferenceHierarchy(context: Context) = preferenceHierarchy(this) {}
+
+ override fun hasCompleteHierarchy() = false
+
+ companion object {
+ const val KEY = "my_device_info_pref_screen"
+ }
+}
diff --git a/tests/robotests/src/com/android/settings/deviceinfo/aboutphone/MyDeviceInfoScreenTest.kt b/tests/robotests/src/com/android/settings/deviceinfo/aboutphone/MyDeviceInfoScreenTest.kt
new file mode 100644
index 0000000..14479d7
--- /dev/null
+++ b/tests/robotests/src/com/android/settings/deviceinfo/aboutphone/MyDeviceInfoScreenTest.kt
@@ -0,0 +1,58 @@
+/*
+ * 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.aboutphone
+
+import android.content.Context
+import android.os.Build
+import android.provider.Settings.Global
+import com.android.settings.flags.Flags
+import com.android.settingslib.preference.CatalystScreenTestCase
+import com.google.common.truth.Truth.assertThat
+import org.junit.Before
+import org.junit.Test
+import org.robolectric.RuntimeEnvironment
+
+class MyDeviceInfoScreenTest : CatalystScreenTestCase() {
+ private lateinit var context: Context
+
+ override val preferenceScreenCreator = MyDeviceInfoScreen()
+ override val flagName: String
+ get() = Flags.FLAG_CATALYST_MY_DEVICE_INFO_PREF_SCREEN
+
+ override fun migration() {}
+
+ @Before
+ fun setup() {
+ context = RuntimeEnvironment.getApplication()
+ }
+
+ @Test
+ fun key() {
+ assertThat(preferenceScreenCreator.key).isEqualTo(MyDeviceInfoScreen.KEY)
+ }
+
+ @Test
+ fun getSummary_deviceNameNotSet_shouldReturnDeviceModel() {
+ assertThat(preferenceScreenCreator.getSummary(context)?.toString()).isEqualTo(Build.MODEL)
+ }
+
+ @Test
+ fun getSummary_deviceNameSet_shouldReturnDeviceName() {
+ Global.putString(context.contentResolver, Global.DEVICE_NAME, "Test")
+ assertThat(preferenceScreenCreator.getSummary(context)?.toString()).isEqualTo("Test")
+ }
+}