Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit d2ed7b5e authored by Sunny Shao's avatar Sunny Shao
Browse files

[Catalyst] Migrate About phone > Model > Model

NO_IFTTT=Catalyst only

Test: atest DeviceModelPreferenceTest
Bug: 407440073
Flag: com.android.settings.flags.device_state
Change-Id: Icf398e2ec7dc2498a9e3a6745edb957b8491f54f
parent a6436cad
Loading
Loading
Loading
Loading
+7 −0
Original line number Diff line number Diff line
@@ -24,6 +24,8 @@ import com.android.settings.connecteddevice.BluetoothDashboardScreen
import com.android.settings.datausage.DataSaverScreen
import com.android.settings.deviceinfo.aboutphone.MyDeviceInfoScreen
import com.android.settings.deviceinfo.firmwareversion.FirmwareVersionScreen
import com.android.settings.deviceinfo.hardwareinfo.DeviceModelPreference
import com.android.settings.deviceinfo.hardwareinfo.HardwareInfoScreen
import com.android.settings.deviceinfo.legal.LegalSettingsScreen
import com.android.settings.deviceinfo.legal.ModuleLicensesScreen
import com.android.settings.deviceinfo.storage.StoragePreferenceScreen
@@ -538,6 +540,11 @@ fun getDeviceStateItemList() =
            settingKey = ZenModeButtonPreference.KEY,
            settingScreenKey = ZenModeBedtimeScreen.KEY,
        ),
        DeviceStateItemConfig(
            enabled = true,
            settingKey = DeviceModelPreference.KEY,
            settingScreenKey = HardwareInfoScreen.KEY,
        ),
        DeviceStateItemConfig(
            enabled = true,
            settingKey = AppInfoStorageScreen.KEY,
+56 −0
Original line number Diff line number Diff line
/*
 * Copyright (C) 2025 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.hardwareinfo

import android.content.Context
import com.android.settings.R
import com.android.settings.deviceinfo.HardwareInfoPreferenceController
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 DeviceModelPreference :
    PreferenceMetadata,
    PreferenceBinding,
    PreferenceSummaryProvider,
    PreferenceAvailabilityProvider {
    override val key: String
        get() = KEY

    override val title: Int
        get() = R.string.model_info

    override fun getSummary(context: Context): CharSequence? =
        HardwareInfoPreferenceController.getDeviceModel()

    override fun isAvailable(context: Context) =
        context.resources.getBoolean(R.bool.config_show_device_model)

    override fun createWidget(context: Context) =
        super.createWidget(context).apply {
            isCopyingEnabled = true
            isSelectable = false
        }

    companion object {
        const val KEY = "hardware_info_device_model"
    }
}
// LINT.ThenChange(DeviceModelPreferenceController.java)
+2 −0
Original line number Diff line number Diff line
@@ -20,6 +20,7 @@ import android.content.Context;

import com.android.settings.deviceinfo.HardwareInfoPreferenceController;

// LINT.IfChange
public class DeviceModelPreferenceController extends HardwareInfoPreferenceController {

    public DeviceModelPreferenceController(Context context, String key) {
@@ -55,3 +56,4 @@ public class DeviceModelPreferenceController extends HardwareInfoPreferenceContr
        return true;
    }
}
// LINT.ThenChange(DeviceModelPreference.kt)
+3 −1
Original line number Diff line number Diff line
@@ -59,7 +59,9 @@ class HardwareInfoScreen :
        return super.createWidget(context).apply { isCopyingEnabled = true }
    }

    override fun getPreferenceHierarchy(context: Context) = preferenceHierarchy(context, this) {}
    override fun getPreferenceHierarchy(context: Context) = preferenceHierarchy(context, this) {
        +DeviceModelPreference()
    }

    companion object {
        const val KEY = "device_model"
+56 −0
Original line number Diff line number Diff line
/*
 * Copyright (C) 2025 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.hardwareinfo

import android.content.Context
import android.content.ContextWrapper
import android.content.res.Resources
import androidx.test.core.app.ApplicationProvider
import androidx.test.ext.junit.runners.AndroidJUnit4
import com.google.common.truth.Truth.assertThat
import org.junit.Test
import org.junit.runner.RunWith
import org.mockito.ArgumentMatchers.anyInt
import org.mockito.kotlin.doReturn
import org.mockito.kotlin.mock
import org.mockito.kotlin.stub

@RunWith(AndroidJUnit4::class)
class DeviceModelPreferenceTest {
    private val mockResources = mock<Resources>()

    private val context: Context =
        object : ContextWrapper(ApplicationProvider.getApplicationContext()) {
            override fun getResources(): Resources = mockResources
        }

    private val deviceModelPreference = DeviceModelPreference()

    @Test
    fun isAvailable_configTrue_shouldReturnTrue() {
        mockResources.stub { on { getBoolean(anyInt()) } doReturn true }

        assertThat(deviceModelPreference.isAvailable(context)).isTrue()
    }

    @Test
    fun isAvailable_configFalse_shouldReturnFalse() {
        mockResources.stub { on { getBoolean(anyInt()) } doReturn false }

        assertThat(deviceModelPreference.isAvailable(context)).isFalse()
    }
}