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

Commit 350ba4a4 authored by Youhan Wang's avatar Youhan Wang Committed by Android (Google) Code Review
Browse files

Merge "TelephonyMonitor: Replace boolean decision with multiple status." into oc-dev

parents c439202d c426fe6c
Loading
Loading
Loading
Loading
+20 −3
Original line number Diff line number Diff line
@@ -23,15 +23,27 @@ import android.support.v7.preference.Preference;
import android.support.v7.preference.PreferenceScreen;
import android.widget.Toast;

import com.android.internal.annotations.VisibleForTesting;
import com.android.settings.core.PreferenceController;
import com.android.settings.R;

public class TelephonyMonitorPreferenceController extends PreferenceController {

    private static final String KEY_TELEPHONY_MONITOR_SWITCH = "telephony_monitor_switch";
    @VisibleForTesting
    static final String BUILD_TYPE = "ro.build.type";
    @VisibleForTesting
    static final String PROPERTY_TELEPHONY_MONITOR = "persist.radio.enable_tel_mon";

    @VisibleForTesting
    static final String ENABLED_STATUS = "enabled";
    @VisibleForTesting
    static final String DISABLED_STATUS = "disabled";
    @VisibleForTesting
    static final String USER_ENABLED_STATUS = "user_enabled";
    @VisibleForTesting
    static final String USER_DISABLED_STATUS = "user_disabled";

    private SwitchPreference mPreference;

    public TelephonyMonitorPreferenceController(Context context) {
@@ -43,7 +55,7 @@ public class TelephonyMonitorPreferenceController extends PreferenceController {
        super.displayPreference(screen);
        if (isAvailable()) {
            mPreference = (SwitchPreference) screen.findPreference(KEY_TELEPHONY_MONITOR_SWITCH);
            mPreference.setChecked(SystemProperties.getBoolean(PROPERTY_TELEPHONY_MONITOR, false));
            mPreference.setChecked(isTelephonyMonitorEnabled());
        }
    }

@@ -69,7 +81,7 @@ public class TelephonyMonitorPreferenceController extends PreferenceController {
        if (KEY_TELEPHONY_MONITOR_SWITCH.equals(preference.getKey())) {
            final SwitchPreference switchPreference = (SwitchPreference) preference;
            SystemProperties.set(PROPERTY_TELEPHONY_MONITOR,
                    switchPreference.isChecked() ? "true" : "false");
                    switchPreference.isChecked() ? USER_ENABLED_STATUS : USER_DISABLED_STATUS);
            Toast.makeText(mContext, R.string.telephony_monitor_toast,
                    Toast.LENGTH_LONG).show();
            return true;
@@ -87,9 +99,14 @@ public class TelephonyMonitorPreferenceController extends PreferenceController {
        if (!isAvailable()) {
            return false;
        }
        final boolean enabled = SystemProperties.getBoolean(PROPERTY_TELEPHONY_MONITOR, false);
        final boolean enabled = isTelephonyMonitorEnabled();
        mPreference.setChecked(enabled);
        return enabled;
    }

    private boolean isTelephonyMonitorEnabled() {
        final String tmStatus = SystemProperties.get(PROPERTY_TELEPHONY_MONITOR, DISABLED_STATUS);
        return ENABLED_STATUS.equals(tmStatus) || USER_ENABLED_STATUS.equals(tmStatus);
    }

}
+44 −6
Original line number Diff line number Diff line
@@ -134,7 +134,24 @@ public class TelephonyMonitorPreferenceControllerTest {
        when(mContext.getResources().getBoolean(R.bool.config_show_telephony_monitor))
                .thenReturn(true);
        SettingsShadowSystemProperties.set(
                TelephonyMonitorPreferenceController.PROPERTY_TELEPHONY_MONITOR, "true");
                TelephonyMonitorPreferenceController.PROPERTY_TELEPHONY_MONITOR,
                TelephonyMonitorPreferenceController.ENABLED_STATUS);
        SettingsShadowSystemProperties.set(
                TelephonyMonitorPreferenceController.BUILD_TYPE, "userdebug");

        mController.displayPreference(mScreen);

        verify(mPreference).setChecked(true);
    }

    @Config(shadows = {SettingsShadowSystemProperties.class})
    @Test
    public void displayPreference_telephonyMonitorUserEnabled_shouldCheckedPreference() {
        when(mContext.getResources().getBoolean(R.bool.config_show_telephony_monitor))
                .thenReturn(true);
        SettingsShadowSystemProperties.set(
                TelephonyMonitorPreferenceController.PROPERTY_TELEPHONY_MONITOR,
                TelephonyMonitorPreferenceController.USER_ENABLED_STATUS);
        SettingsShadowSystemProperties.set(
                TelephonyMonitorPreferenceController.BUILD_TYPE, "userdebug");

@@ -149,7 +166,24 @@ public class TelephonyMonitorPreferenceControllerTest {
        when(mContext.getResources().getBoolean(R.bool.config_show_telephony_monitor))
                .thenReturn(true);
        SettingsShadowSystemProperties.set(
                TelephonyMonitorPreferenceController.PROPERTY_TELEPHONY_MONITOR, "false");
                TelephonyMonitorPreferenceController.PROPERTY_TELEPHONY_MONITOR,
                TelephonyMonitorPreferenceController.DISABLED_STATUS);
        SettingsShadowSystemProperties.set(
                TelephonyMonitorPreferenceController.BUILD_TYPE, "userdebug");

        mController.displayPreference(mScreen);

        verify(mPreference).setChecked(false);
    }

    @Config(shadows = {SettingsShadowSystemProperties.class})
    @Test
    public void displayPreference_telephonyMonitorUserDisabled_shouldUncheckedPreference() {
        when(mContext.getResources().getBoolean(R.bool.config_show_telephony_monitor))
                .thenReturn(true);
        SettingsShadowSystemProperties.set(
                TelephonyMonitorPreferenceController.PROPERTY_TELEPHONY_MONITOR,
                TelephonyMonitorPreferenceController.USER_DISABLED_STATUS);
        SettingsShadowSystemProperties.set(
                TelephonyMonitorPreferenceController.BUILD_TYPE, "userdebug");

@@ -168,8 +202,10 @@ public class TelephonyMonitorPreferenceControllerTest {

        mController.handlePreferenceTreeClick(mPreference);

        assertThat(SystemProperties.getBoolean(
                TelephonyMonitorPreferenceController.PROPERTY_TELEPHONY_MONITOR, false)).isTrue();
        assertThat(TelephonyMonitorPreferenceController.USER_ENABLED_STATUS.equals(
                SystemProperties.get(
                        TelephonyMonitorPreferenceController.PROPERTY_TELEPHONY_MONITOR,
                        TelephonyMonitorPreferenceController.DISABLED_STATUS))).isTrue();
    }

    @Config(shadows = {SettingsShadowSystemProperties.class})
@@ -182,8 +218,10 @@ public class TelephonyMonitorPreferenceControllerTest {

        mController.handlePreferenceTreeClick(mPreference);

        assertThat(SystemProperties.getBoolean(
                TelephonyMonitorPreferenceController.PROPERTY_TELEPHONY_MONITOR, false)).isFalse();
        assertThat(TelephonyMonitorPreferenceController.USER_DISABLED_STATUS.equals(
                SystemProperties.get(
                        TelephonyMonitorPreferenceController.PROPERTY_TELEPHONY_MONITOR,
                        TelephonyMonitorPreferenceController.DISABLED_STATUS))).isTrue();
    }

}