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

Commit a6bd2b9c authored by Aleksander Morgado's avatar Aleksander Morgado
Browse files

Hide voice call related settings with config_show_sim_info=false

The config_show_sim_info overlay config, when set to false, allows
hiding all telephony related settings, effectively making it a way to
disable telephony altogether in the Settings application, regardless
of the actual telephony support of the device.

Certain settings are not only telephony specific, but also specific to
voice calling capabilities. These settings were not being gated by the
config_show_sim_info overlay config, and instead relied exclusively on
the voice call support reported by TelephonyManager.

All voice call related settings will now be visible only if both
conditions pass: config_show_sim_info=true and TelephonyManager
reports the device as voice capable.

A new helper isTelephonyDisabled() method is introduced to check the
value of config_show_sim_info. This duplicates the logic already
available in SubscriptionUtil.isSimHardwareVisible(), which will
eventually be removed.

NO_IFTTT=Only the relevant component visibility unit tests are updated.

Bug: 395714454
Test: mm && atest SettingsRoboTests
Flag: EXEMPT bugfix
Change-Id: Id46c001197cfb3e9ddcc6d9277010d03cbcf5b9d
parent 8aa595ae
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -739,7 +739,7 @@
    <!-- Whether to enable the app battery usage list page feature. -->
    <bool name="config_app_battery_usage_list_enabled">false</bool>

    <!-- Whether sim related information is visible to the end user. -->
    <!-- Whether telephony related information is visible to the end user. -->
    <bool name="config_show_sim_info">true</bool>

    <!-- In the case of receiving both help and progress message, display progress message. -->
+9 −0
Original line number Diff line number Diff line
@@ -214,11 +214,20 @@ public final class Utils extends com.android.settingslib.Utils {
     * Returns whether the device is voice-capable (meaning, it is also a phone).
     */
    public static boolean isVoiceCapable(Context context) {
        if (isTelephonyDisabled(context)) return false;
        final TelephonyManager telephony =
                (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE);
        return telephony != null && telephony.isVoiceCapable();
    }

    /**
     * Returns whether telephony features are completely disabled in the app, regardless
     * of the TelephonyManager reported capabilities or the PackageManager flags declared.
     */
    private static boolean isTelephonyDisabled(Context context) {
        return !context.getResources().getBoolean(R.bool.config_show_sim_info);
    }

    /**
     * Returns the WIFI IP Addresses, if any, taking into account IPv4 and IPv6 style addresses.
     * @param context the application context
+19 −2
Original line number Diff line number Diff line
@@ -24,6 +24,7 @@ import static com.google.common.truth.Truth.assertThat;
import static org.mockito.Mockito.when;

import android.content.Context;
import android.content.res.Resources;
import android.telephony.TelephonyManager;

import androidx.test.core.app.ApplicationProvider;
@@ -53,6 +54,9 @@ public class HearingDeviceCallRoutingPreferenceControllerTest {
    private final Context mContext = ApplicationProvider.getApplicationContext();
    private static final String FAKE_KEY = "fake_key";

    @Spy
    private final Resources mResources = mContext.getResources();

    @Mock
    private TelephonyManager mTelephonyManager;
    private HearingDeviceCallRoutingPreferenceController mController;
@@ -60,20 +64,33 @@ public class HearingDeviceCallRoutingPreferenceControllerTest {
    @Before
    public void setUp() {
        when(mContext.getSystemService(Context.TELEPHONY_SERVICE)).thenReturn(mTelephonyManager);
        when(mContext.getResources()).thenReturn(mResources);
        mController = new HearingDeviceCallRoutingPreferenceController(mContext, FAKE_KEY);
    }

    @Test
    public void getAvailabilityStatus_hasTelephonyCalling_available() {
    public void getAvailabilityStatus_telephonyEnabled_voiceCapable_available() {
        when(mResources.getBoolean(com.android.settings.R.bool.config_show_sim_info))
                .thenReturn(true);
        when(mTelephonyManager.isVoiceCapable()).thenReturn(true);

        assertThat(mController.getAvailabilityStatus()).isEqualTo(AVAILABLE);
    }

    @Test
    public void getAvailabilityStatus_noTelephonyCalling_unsupported() {
    public void getAvailabilityStatus_telephonyEnabled_notVoiceCapable_unsupported() {
        when(mResources.getBoolean(com.android.settings.R.bool.config_show_sim_info))
                .thenReturn(true);
        when(mTelephonyManager.isVoiceCapable()).thenReturn(false);

        assertThat(mController.getAvailabilityStatus()).isEqualTo(UNSUPPORTED_ON_DEVICE);
    }

    @Test
    public void getAvailabilityStatus_telephonyDisabled_voiceCapable_unsupported() {
        when(mResources.getBoolean(com.android.settings.R.bool.config_show_sim_info))
                .thenReturn(false);
        when(mTelephonyManager.isVoiceCapable()).thenReturn(true);

        assertThat(mController.getAvailabilityStatus()).isEqualTo(UNSUPPORTED_ON_DEVICE);
    }
+22 −0
Original line number Diff line number Diff line
@@ -21,6 +21,7 @@ import static com.google.common.truth.Truth.assertThat;
import static org.mockito.Mockito.when;

import android.content.Context;
import android.content.res.Resources;
import android.provider.Settings;
import android.telephony.TelephonyManager;

@@ -57,12 +58,16 @@ public class PowerButtonEndsCallPreferenceControllerTest {
    @Spy
    private final Context mContext = ApplicationProvider.getApplicationContext();

    @Spy
    private final Resources mResources = mContext.getResources();

    private SwitchPreference mPreference;
    private PowerButtonEndsCallPreferenceController mController;

    @Before
    public void setUp() {
        when(mContext.getSystemService(Context.TELEPHONY_SERVICE)).thenReturn(mTelephonyManager);
        when(mContext.getResources()).thenReturn(mResources);
        mPreference = new SwitchPreference(mContext);
        mController = new PowerButtonEndsCallPreferenceController(mContext, "power_button");
    }
@@ -75,6 +80,8 @@ public class PowerButtonEndsCallPreferenceControllerTest {
    @Test
    public void getAvailabilityStatus_hasPowerKeyAndVoiceCapable_shouldReturnAvailable() {
        ShadowKeyCharacterMap.setDevicehasKey(true);
        when(mResources.getBoolean(com.android.settings.R.bool.config_show_sim_info))
                .thenReturn(true);
        when(mTelephonyManager.isVoiceCapable()).thenReturn(true);

        assertThat(mController.getAvailabilityStatus())
@@ -84,15 +91,30 @@ public class PowerButtonEndsCallPreferenceControllerTest {
    @Test
    public void getAvailabilityStatus_noVoiceCapable_shouldReturnUnsupportedOnDevice() {
        ShadowKeyCharacterMap.setDevicehasKey(true);
        when(mResources.getBoolean(com.android.settings.R.bool.config_show_sim_info))
                .thenReturn(true);
        when(mTelephonyManager.isVoiceCapable()).thenReturn(false);

        assertThat(mController.getAvailabilityStatus())
                .isEqualTo(BasePreferenceController.UNSUPPORTED_ON_DEVICE);
    }

    @Test
    public void getAvailabilityStatus_telephonyDisabled_shouldReturnUnsupportedOnDevice() {
        ShadowKeyCharacterMap.setDevicehasKey(true);
        when(mResources.getBoolean(com.android.settings.R.bool.config_show_sim_info))
                .thenReturn(false);
        when(mTelephonyManager.isVoiceCapable()).thenReturn(true);

        assertThat(mController.getAvailabilityStatus())
                .isEqualTo(BasePreferenceController.UNSUPPORTED_ON_DEVICE);
    }

    @Test
    public void getAvailabilityStatus_noPowerKey_shouldReturnUnsupportedOnDevice() {
        ShadowKeyCharacterMap.setDevicehasKey(false);
        when(mResources.getBoolean(com.android.settings.R.bool.config_show_sim_info))
                .thenReturn(true);
        when(mTelephonyManager.isVoiceCapable()).thenReturn(true);

        assertThat(mController.getAvailabilityStatus())
+20 −0
Original line number Diff line number Diff line
@@ -28,6 +28,7 @@ import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;

import android.content.Context;
import android.content.res.Resources;
import android.media.AudioManager;
import android.os.Vibrator;
import android.provider.Settings;
@@ -59,6 +60,7 @@ public class VibrationRampingRingerTogglePreferenceControllerTest {

    private Lifecycle mLifecycle;
    private Context mContext;
    private Resources mResources;
    private VibrationRampingRingerTogglePreferenceController mController;
    private SwitchPreference mPreference;

@@ -67,6 +69,8 @@ public class VibrationRampingRingerTogglePreferenceControllerTest {
        MockitoAnnotations.initMocks(this);
        mLifecycle = new Lifecycle(() -> mLifecycle);
        mContext = spy(ApplicationProvider.getApplicationContext());
        mResources = spy(mContext.getResources());
        when(mContext.getResources()).thenReturn(mResources);
        when(mContext.getSystemService(Context.TELEPHONY_SERVICE)).thenReturn(mTelephonyManager);
        when(mContext.getSystemService(Context.AUDIO_SERVICE)).thenReturn(mAudioManager);
        when(mAudioManager.getRingerModeInternal()).thenReturn(AudioManager.RINGER_MODE_NORMAL);
@@ -86,14 +90,28 @@ public class VibrationRampingRingerTogglePreferenceControllerTest {

    @Test
    public void getAvailabilityStatus_notVoiceCapable_returnUnsupportedOnDevice() {
        when(mResources.getBoolean(com.android.settings.R.bool.config_show_sim_info))
                .thenReturn(true);
        when(mTelephonyManager.isVoiceCapable()).thenReturn(false);
        when(mDeviceConfigProvider.isRampingRingerEnabledOnTelephonyConfig()).thenReturn(false);

        assertThat(mController.getAvailabilityStatus()).isEqualTo(UNSUPPORTED_ON_DEVICE);
    }

    @Test
    public void getAvailabilityStatus_telephonyDisabled_returnUnsupportedOnDevice() {
        when(mResources.getBoolean(com.android.settings.R.bool.config_show_sim_info))
                .thenReturn(false);
        when(mTelephonyManager.isVoiceCapable()).thenReturn(true);
        when(mDeviceConfigProvider.isRampingRingerEnabledOnTelephonyConfig()).thenReturn(false);

        assertThat(mController.getAvailabilityStatus()).isEqualTo(UNSUPPORTED_ON_DEVICE);
    }

    @Test
    public void getAvailabilityStatus_rampingRingerEnabled_returnUnsupportedOnDevice() {
        when(mResources.getBoolean(com.android.settings.R.bool.config_show_sim_info))
                .thenReturn(true);
        when(mTelephonyManager.isVoiceCapable()).thenReturn(true);
        when(mDeviceConfigProvider.isRampingRingerEnabledOnTelephonyConfig()).thenReturn(true);

@@ -102,6 +120,8 @@ public class VibrationRampingRingerTogglePreferenceControllerTest {

    @Test
    public void getAvailabilityStatus_voiceCapableAndRampingRingerDisabled_returnAvailable() {
        when(mResources.getBoolean(com.android.settings.R.bool.config_show_sim_info))
                .thenReturn(true);
        when(mTelephonyManager.isVoiceCapable()).thenReturn(true);
        when(mDeviceConfigProvider.isRampingRingerEnabledOnTelephonyConfig()).thenReturn(false);

Loading