Merge "Migrate About phone" into main
This commit is contained in:
@@ -15,3 +15,9 @@ flag {
|
||||
bug: "323791114"
|
||||
}
|
||||
|
||||
flag {
|
||||
name: "catalyst_my_device_info_pref_screen"
|
||||
namespace: "android_settings"
|
||||
description: "Flag for About phone"
|
||||
bug: "323791114"
|
||||
}
|
||||
|
@@ -25,6 +25,9 @@ import android.os.Bundle;
|
||||
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 @@ public class MyDeviceInfoFragment extends DashboardFragment
|
||||
controller.updateDeviceName(confirm);
|
||||
}
|
||||
|
||||
@Override
|
||||
public @Nullable String getPreferenceScreenBindingKey(@NonNull Context context) {
|
||||
return MyDeviceInfoScreen.KEY;
|
||||
}
|
||||
|
||||
/**
|
||||
* For Search.
|
||||
*/
|
||||
|
@@ -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"
|
||||
}
|
||||
}
|
@@ -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")
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user