Loading res/values/strings.xml +6 −0 Original line number Diff line number Diff line Loading @@ -5655,12 +5655,18 @@ <string name="remove_and_uninstall_device_admin">Deactivate & uninstall</string> <!-- Label for screen showing to select device admin apps --> <string name="select_device_admin_msg">Device admin apps</string> <!-- Message when there are no available device admin apps to display --> <string name="no_device_admins">No device admin apps available</string> <!-- Title for personal device admin apps on the list [CHAR_LIMIT=25] --> <string name="personal_device_admin_title">Personal</string> <!-- Title for managed device admin apps on the list [CHAR_LIMIT=25] --> <string name="managed_device_admin_title">Work</string> <!-- Title for whether to enable SMS access restriction [CHAR LIMIT=50]--> <string name="sms_access_restriction_enabled">Restrict SMS & call log access</string> <!-- Summary for whether to enable SMS access restriction [CHAR LIMIT=NONE]--> <string name="sms_access_restriction_enabled_summary">Only default phone and messaging apps have SMS & call log permissions</string> <!-- Message when there are no available trust agents to display --> <string name="no_trust_agents">No available trust agents</string> Loading res/xml/development_settings.xml +5 −0 Original line number Diff line number Diff line Loading @@ -513,6 +513,11 @@ <Preference android:key="reset_shortcut_manager_throttling" android:title="@string/reset_shortcut_manager_throttling" /> <SwitchPreference android:key="sms_access_restriction_enabled" android:title="@string/sms_access_restriction_enabled" android:summary="@string/sms_access_restriction_enabled_summary" /> </PreferenceCategory> <com.android.settings.development.autofill.AutofillPreferenceCategory Loading src/com/android/settings/development/DevelopmentSettingsDashboardFragment.java +1 −0 Original line number Diff line number Diff line Loading @@ -458,6 +458,7 @@ public class DevelopmentSettingsDashboardFragment extends RestrictedDashboardFra controllers.add(new AllowAppsOnExternalPreferenceController(context)); controllers.add(new ResizableActivityPreferenceController(context)); controllers.add(new FreeformWindowsPreferenceController(context)); controllers.add(new SmsAccessRestrictionPreferenceController(context)); controllers.add(new ShortcutManagerThrottlingPreferenceController(context)); controllers.add(new EnableGnssRawMeasFullTrackingPreferenceController(context)); controllers.add(new CbrsDataSwitchPreferenceController(context)); Loading src/com/android/settings/development/SmsAccessRestrictionPreferenceController.java 0 → 100644 +69 −0 Original line number Diff line number Diff line /* * Copyright (C) 2018 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.development; import android.content.Context; import android.provider.Settings; import com.android.settings.core.PreferenceControllerMixin; import com.android.settingslib.development.DeveloperOptionsPreferenceController; import androidx.preference.Preference; import androidx.preference.SwitchPreference; // STOPSHIP b/118694572: remove the kill switch once the feature is tested and stable public class SmsAccessRestrictionPreferenceController extends DeveloperOptionsPreferenceController implements Preference.OnPreferenceChangeListener, PreferenceControllerMixin { private static final String SMS_ACCESS_RESTRICTION_ENABLED_KEY = "sms_access_restriction_enabled"; public SmsAccessRestrictionPreferenceController(Context context) { super(context); } @Override public String getPreferenceKey() { return SMS_ACCESS_RESTRICTION_ENABLED_KEY; } @Override public boolean onPreferenceChange(Preference preference, Object newValue) { writeSetting((boolean) newValue); return true; } private void writeSetting(boolean isEnabled) { Settings.Global.putInt(mContext.getContentResolver(), Settings.Global.SMS_ACCESS_RESTRICTION_ENABLED, isEnabled ? 1 : 0); } @Override public void updateState(Preference preference) { final int mode = Settings.Global.getInt(mContext.getContentResolver(), Settings.Global.SMS_ACCESS_RESTRICTION_ENABLED, 0); ((SwitchPreference) mPreference).setChecked(mode != 0); } @Override protected void onDeveloperOptionsSwitchDisabled() { super.onDeveloperOptionsSwitchDisabled(); writeSetting(false); ((SwitchPreference) mPreference).setChecked(false); } } tests/robotests/src/com/android/settings/development/SmsAccessRestrictionPreferenceControllerTest.java 0 → 100644 +110 −0 Original line number Diff line number Diff line /* * Copyright (C) 2017 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.development; import static com.google.common.truth.Truth.assertThat; import static org.mockito.Mockito.verify; import static org.mockito.Mockito.when; import android.content.Context; import android.provider.Settings; import com.android.settings.testutils.SettingsRobolectricTestRunner; import org.junit.Before; import org.junit.Test; import org.junit.runner.RunWith; import org.mockito.Mock; import org.mockito.MockitoAnnotations; import org.robolectric.RuntimeEnvironment; import androidx.preference.PreferenceScreen; import androidx.preference.SwitchPreference; @RunWith(SettingsRobolectricTestRunner.class) public class SmsAccessRestrictionPreferenceControllerTest { @Mock private SwitchPreference mPreference; @Mock private PreferenceScreen mPreferenceScreen; private Context mContext; private SmsAccessRestrictionPreferenceController mController; @Before public void setup() { MockitoAnnotations.initMocks(this); mContext = RuntimeEnvironment.application; mController = new SmsAccessRestrictionPreferenceController(mContext); when(mPreferenceScreen.findPreference(mController.getPreferenceKey())) .thenReturn(mPreference); mController.displayPreference(mPreferenceScreen); } @Test public void onPreferenceChange_settingEnabled_enableSmsRestrictionShouldBeOn() { mController.onPreferenceChange(mPreference, true /* new value */); final int mode = Settings.Global.getInt(mContext.getContentResolver(), Settings.Global.SMS_ACCESS_RESTRICTION_ENABLED, -1 /* default */); assertThat(mode).isEqualTo(1); } @Test public void onPreferenceChange_settingDisabled_enableSmsRestrictionShouldBeOff() { mController.onPreferenceChange(mPreference, false /* new value */); final int mode = Settings.Global.getInt(mContext.getContentResolver(), Settings.Global.SMS_ACCESS_RESTRICTION_ENABLED, -1 /* default */); assertThat(mode).isEqualTo(0); } @Test public void updateState_settingDisabled_preferenceShouldNotBeChecked() { Settings.Global.putInt(mContext.getContentResolver(), Settings.Global.SMS_ACCESS_RESTRICTION_ENABLED, 0); mController.updateState(mPreference); verify(mPreference).setChecked(false); } @Test public void updateState_settingEnabled_preferenceShouldBeChecked() { Settings.Global.putInt(mContext.getContentResolver(), Settings.Global.SMS_ACCESS_RESTRICTION_ENABLED, 1); mController.updateState(mPreference); verify(mPreference).setChecked(true); } @Test public void onDeveloperOptionsSwitchDisabled_shouldDisablePreference() { mController.onDeveloperOptionsSwitchDisabled(); final int mode = Settings.Global.getInt(mContext.getContentResolver(), Settings.Global.SMS_ACCESS_RESTRICTION_ENABLED, -1 /* default */); assertThat(mode).isEqualTo(0); verify(mPreference).setChecked(false); verify(mPreference).setEnabled(false); } } Loading
res/values/strings.xml +6 −0 Original line number Diff line number Diff line Loading @@ -5655,12 +5655,18 @@ <string name="remove_and_uninstall_device_admin">Deactivate & uninstall</string> <!-- Label for screen showing to select device admin apps --> <string name="select_device_admin_msg">Device admin apps</string> <!-- Message when there are no available device admin apps to display --> <string name="no_device_admins">No device admin apps available</string> <!-- Title for personal device admin apps on the list [CHAR_LIMIT=25] --> <string name="personal_device_admin_title">Personal</string> <!-- Title for managed device admin apps on the list [CHAR_LIMIT=25] --> <string name="managed_device_admin_title">Work</string> <!-- Title for whether to enable SMS access restriction [CHAR LIMIT=50]--> <string name="sms_access_restriction_enabled">Restrict SMS & call log access</string> <!-- Summary for whether to enable SMS access restriction [CHAR LIMIT=NONE]--> <string name="sms_access_restriction_enabled_summary">Only default phone and messaging apps have SMS & call log permissions</string> <!-- Message when there are no available trust agents to display --> <string name="no_trust_agents">No available trust agents</string> Loading
res/xml/development_settings.xml +5 −0 Original line number Diff line number Diff line Loading @@ -513,6 +513,11 @@ <Preference android:key="reset_shortcut_manager_throttling" android:title="@string/reset_shortcut_manager_throttling" /> <SwitchPreference android:key="sms_access_restriction_enabled" android:title="@string/sms_access_restriction_enabled" android:summary="@string/sms_access_restriction_enabled_summary" /> </PreferenceCategory> <com.android.settings.development.autofill.AutofillPreferenceCategory Loading
src/com/android/settings/development/DevelopmentSettingsDashboardFragment.java +1 −0 Original line number Diff line number Diff line Loading @@ -458,6 +458,7 @@ public class DevelopmentSettingsDashboardFragment extends RestrictedDashboardFra controllers.add(new AllowAppsOnExternalPreferenceController(context)); controllers.add(new ResizableActivityPreferenceController(context)); controllers.add(new FreeformWindowsPreferenceController(context)); controllers.add(new SmsAccessRestrictionPreferenceController(context)); controllers.add(new ShortcutManagerThrottlingPreferenceController(context)); controllers.add(new EnableGnssRawMeasFullTrackingPreferenceController(context)); controllers.add(new CbrsDataSwitchPreferenceController(context)); Loading
src/com/android/settings/development/SmsAccessRestrictionPreferenceController.java 0 → 100644 +69 −0 Original line number Diff line number Diff line /* * Copyright (C) 2018 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.development; import android.content.Context; import android.provider.Settings; import com.android.settings.core.PreferenceControllerMixin; import com.android.settingslib.development.DeveloperOptionsPreferenceController; import androidx.preference.Preference; import androidx.preference.SwitchPreference; // STOPSHIP b/118694572: remove the kill switch once the feature is tested and stable public class SmsAccessRestrictionPreferenceController extends DeveloperOptionsPreferenceController implements Preference.OnPreferenceChangeListener, PreferenceControllerMixin { private static final String SMS_ACCESS_RESTRICTION_ENABLED_KEY = "sms_access_restriction_enabled"; public SmsAccessRestrictionPreferenceController(Context context) { super(context); } @Override public String getPreferenceKey() { return SMS_ACCESS_RESTRICTION_ENABLED_KEY; } @Override public boolean onPreferenceChange(Preference preference, Object newValue) { writeSetting((boolean) newValue); return true; } private void writeSetting(boolean isEnabled) { Settings.Global.putInt(mContext.getContentResolver(), Settings.Global.SMS_ACCESS_RESTRICTION_ENABLED, isEnabled ? 1 : 0); } @Override public void updateState(Preference preference) { final int mode = Settings.Global.getInt(mContext.getContentResolver(), Settings.Global.SMS_ACCESS_RESTRICTION_ENABLED, 0); ((SwitchPreference) mPreference).setChecked(mode != 0); } @Override protected void onDeveloperOptionsSwitchDisabled() { super.onDeveloperOptionsSwitchDisabled(); writeSetting(false); ((SwitchPreference) mPreference).setChecked(false); } }
tests/robotests/src/com/android/settings/development/SmsAccessRestrictionPreferenceControllerTest.java 0 → 100644 +110 −0 Original line number Diff line number Diff line /* * Copyright (C) 2017 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.development; import static com.google.common.truth.Truth.assertThat; import static org.mockito.Mockito.verify; import static org.mockito.Mockito.when; import android.content.Context; import android.provider.Settings; import com.android.settings.testutils.SettingsRobolectricTestRunner; import org.junit.Before; import org.junit.Test; import org.junit.runner.RunWith; import org.mockito.Mock; import org.mockito.MockitoAnnotations; import org.robolectric.RuntimeEnvironment; import androidx.preference.PreferenceScreen; import androidx.preference.SwitchPreference; @RunWith(SettingsRobolectricTestRunner.class) public class SmsAccessRestrictionPreferenceControllerTest { @Mock private SwitchPreference mPreference; @Mock private PreferenceScreen mPreferenceScreen; private Context mContext; private SmsAccessRestrictionPreferenceController mController; @Before public void setup() { MockitoAnnotations.initMocks(this); mContext = RuntimeEnvironment.application; mController = new SmsAccessRestrictionPreferenceController(mContext); when(mPreferenceScreen.findPreference(mController.getPreferenceKey())) .thenReturn(mPreference); mController.displayPreference(mPreferenceScreen); } @Test public void onPreferenceChange_settingEnabled_enableSmsRestrictionShouldBeOn() { mController.onPreferenceChange(mPreference, true /* new value */); final int mode = Settings.Global.getInt(mContext.getContentResolver(), Settings.Global.SMS_ACCESS_RESTRICTION_ENABLED, -1 /* default */); assertThat(mode).isEqualTo(1); } @Test public void onPreferenceChange_settingDisabled_enableSmsRestrictionShouldBeOff() { mController.onPreferenceChange(mPreference, false /* new value */); final int mode = Settings.Global.getInt(mContext.getContentResolver(), Settings.Global.SMS_ACCESS_RESTRICTION_ENABLED, -1 /* default */); assertThat(mode).isEqualTo(0); } @Test public void updateState_settingDisabled_preferenceShouldNotBeChecked() { Settings.Global.putInt(mContext.getContentResolver(), Settings.Global.SMS_ACCESS_RESTRICTION_ENABLED, 0); mController.updateState(mPreference); verify(mPreference).setChecked(false); } @Test public void updateState_settingEnabled_preferenceShouldBeChecked() { Settings.Global.putInt(mContext.getContentResolver(), Settings.Global.SMS_ACCESS_RESTRICTION_ENABLED, 1); mController.updateState(mPreference); verify(mPreference).setChecked(true); } @Test public void onDeveloperOptionsSwitchDisabled_shouldDisablePreference() { mController.onDeveloperOptionsSwitchDisabled(); final int mode = Settings.Global.getInt(mContext.getContentResolver(), Settings.Global.SMS_ACCESS_RESTRICTION_ENABLED, -1 /* default */); assertThat(mode).isEqualTo(0); verify(mPreference).setChecked(false); verify(mPreference).setEnabled(false); } }