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

Commit 360e6d3b authored by Aleksander Morgado's avatar Aleksander Morgado
Browse files

Use isMobileDataCapable/isVoiceCapable helpers in deviceinfo/imei

Disabling telephony support may be done either with the
config_show_sim_info config option, or based on whether
TelephonyManager reports data capabilities. The isMobileDataCapable()
helper method ensures both ways are supported.

Additionally, the logic is also updated to explicitly check for voice
support, so that disabling this telephony element happens only when
both mobile data and voice are unsupported.

The unit tests are updated to consider both no-data and no-voice
cases, by mocking both Resources and TelephonyManager.

Bug: 395714454
Test: mm && atest ImeiInfoPreferenceControllerTest
Flag: EXEMPT bugfix
Change-Id: Iabba6885b5d0e0ecca7138cd85fdc86296b9e333
parent 4de0dcd0
Loading
Loading
Loading
Loading
+4 −5
Original line number Diff line number Diff line
@@ -32,10 +32,9 @@ import androidx.preference.PreferenceCategory;
import androidx.preference.PreferenceScreen;

import com.android.settings.R;
import com.android.settings.Utils;
import com.android.settings.core.BasePreferenceController;
import com.android.settings.deviceinfo.simstatus.SlotSimStatus;
import com.android.settings.network.SubscriptionUtil;
import com.android.settingslib.Utils;

/**
 * Controller that manages preference for single and multi sim devices.
@@ -81,12 +80,12 @@ public class ImeiInfoPreferenceController extends BasePreferenceController {
    @Override
    public void displayPreference(PreferenceScreen screen) {
        super.displayPreference(screen);
        if ((!SubscriptionUtil.isSimHardwareVisible(mContext)) || (mSlotSimStatus == null)) {
        if (!isAvailable() || (mSlotSimStatus == null)) {
            return;
        }
        mTelephonyManager = mContext.getSystemService(TelephonyManager.class);
        Preference preference = screen.findPreference(DEFAULT_KEY);
        if (!isAvailable() || preference == null || !preference.isVisible()) {
        if (preference == null || !preference.isVisible()) {
            return;
        }
        PreferenceCategory category = screen.findPreference(KEY_PREFERENCE_CATEGORY);
@@ -132,7 +131,7 @@ public class ImeiInfoPreferenceController extends BasePreferenceController {

    @Override
    public int getAvailabilityStatus() {
        if (!SubscriptionUtil.isSimHardwareVisible(mContext) || Utils.isWifiOnly(mContext)) {
        if (!Utils.isMobileDataCapable(mContext) && !Utils.isVoiceCapable(mContext)) {
            return UNSUPPORTED_ON_DEVICE;
        }
        if (!mContext.getSystemService(UserManager.class).isAdminUser()) {
+25 −3
Original line number Diff line number Diff line
@@ -98,6 +98,7 @@ public class ImeiInfoPreferenceControllerTest {
        // Availability defaults
        when(mResources.getBoolean(R.bool.config_show_sim_info)).thenReturn(true);
        when(mTelephonyManager.isDataCapable()).thenReturn(true);
        when(mTelephonyManager.isDeviceVoiceCapable()).thenReturn(true);
        when(mUserManager.isAdminUser()).thenReturn(true);

        when(mScreen.getContext()).thenReturn(mContext);
@@ -233,7 +234,7 @@ public class ImeiInfoPreferenceControllerTest {
    }

    @Test
    public void getAvailabilityStatus_showSimInfo_telephonyDataCapable_userAdmindisplayed() {
    public void getAvailabilityStatus_default() {
        setupPhoneCount(1, PHONE_TYPE_GSM, PHONE_TYPE_NONE);

        // Use defaults
@@ -242,7 +243,7 @@ public class ImeiInfoPreferenceControllerTest {
    }

    @Test
    public void getAvailabilityStatus_notShowSimInfo_telephonyDataCapable_userAdmin_notDisplayed() {
    public void getAvailabilityStatus_notShowSimInfo_notDisplayed() {
        setupPhoneCount(1, PHONE_TYPE_GSM, PHONE_TYPE_NONE);

        when(mResources.getBoolean(R.bool.config_show_sim_info)).thenReturn(false);
@@ -251,9 +252,30 @@ public class ImeiInfoPreferenceControllerTest {
    }

    @Test
    public void getAvailabilityStatus_showSimInfo_notTelephonyDataCapable_userAdmin_notDisplayed() {
    public void getAvailabilityStatus_voiceCapable_notDataCapable_displayed() {
        setupPhoneCount(1, PHONE_TYPE_GSM, PHONE_TYPE_NONE);

        when(mTelephonyManager.isDeviceVoiceCapable()).thenReturn(true);
        when(mTelephonyManager.isDataCapable()).thenReturn(false);
        assertThat(mController.getAvailabilityStatus()).isEqualTo(
                BasePreferenceController.AVAILABLE);
    }

    @Test
    public void getAvailabilityStatus_notVoiceCapable_dataCapable_displayed() {
        setupPhoneCount(1, PHONE_TYPE_GSM, PHONE_TYPE_NONE);

        when(mTelephonyManager.isDeviceVoiceCapable()).thenReturn(false);
        when(mTelephonyManager.isDataCapable()).thenReturn(true);
        assertThat(mController.getAvailabilityStatus()).isEqualTo(
                BasePreferenceController.AVAILABLE);
    }

    @Test
    public void getAvailabilityStatus_notVoiceCapable_notDataCapable_notDisplayed() {
        setupPhoneCount(1, PHONE_TYPE_GSM, PHONE_TYPE_NONE);

        when(mTelephonyManager.isDeviceVoiceCapable()).thenReturn(false);
        when(mTelephonyManager.isDataCapable()).thenReturn(false);
        assertThat(mController.getAvailabilityStatus()).isEqualTo(
                BasePreferenceController.UNSUPPORTED_ON_DEVICE);