diff --git a/res/values/strings.xml b/res/values/strings.xml index 6afffb202ee..11af027dedc 100644 --- a/res/values/strings.xml +++ b/res/values/strings.xml @@ -4837,9 +4837,9 @@ Magnify with triple-tap - Magnify with button + Magnify with shortcut - Magnify with button & triple-tap + Magnify with shortcut & triple-tap Zoom in on screen @@ -4849,7 +4849,25 @@ To zoom, quickly tap the screen 3 times.\n\n\nTo zoom temporarily, quickly tap the screen 3 times and hold down your finger on the third tap.\n\n\nYou can\'t zoom in on the keyboard and navigation bar. - When magnification is turned on, use the Accessibility button at the bottom of the screen to quickly magnify.\n\nTo zoom, tap the Accessibility button, then tap anywhere on the screen.\n\n\nTo zoom temporarily, tap the Accessibility button, then touch & hold anywhere on the screen.\n\n\nYou can’t zoom in on the keyboard or navigation bar. + When magnification is turned on, you can zoom in on your screen.\n\nTo zoom, start magnification, then tap anywhere on the screen.\n\n\nTo zoom temporarily, start magnification, then touch & hold anywhere on the screen.\n\n\nYou can’t zoom in on the keyboard or navigation bar. + + Use accessibility button to open + + Use gesture to open + + Use new accessibility gesture + + To turn this service on or off, tap the accessibility button%son the bottom of your screen.\n\nTo switch between services, touch & hold the accessibility button. + + To turn this service on or off, swipe up from the bottom of the screen with two fingers.\n\nTo switch between services, swipe up with two fingers and hold. + + To turn this service on or off, swipe up from the bottom of the screen with three fingers.\n\nTo switch between services, swipe up with three fingers and hold. + + To turn an accessibility service on or off, swipe up from the bottom of the screen with two fingers.\n\nTo switch between services, swipe up with two fingers and hold. + + To turn an accessibility service on or off, swipe up from the bottom of the screen with three fingers.\n\nTo switch between services, swipe up with three fingers and hold. + + Got it The Accessibility button is set to %1$s. To use magnification, touch & hold the Accessibility button, then select magnification. @@ -10611,11 +10629,6 @@ Track all GNSS constellations and frequencies with no duty cycling - - Allow background activity starts - - Allows all background activity starts - Always show crash dialog diff --git a/res/xml/development_settings.xml b/res/xml/development_settings.xml index 63840bbcc1f..b819dbb7d6c 100644 --- a/res/xml/development_settings.xml +++ b/res/xml/development_settings.xml @@ -507,11 +507,6 @@ android:fragment="com.android.settings.applications.appops.BackgroundCheckSummary" android:title="@string/background_check_pref" /> - - + + { // Disable the toggles until the user re-enrolls @@ -150,9 +152,15 @@ public class FaceSettings extends DashboardFragment { @Override public void onResume() { super.onResume(); - if (mToken == null) { + + if (mToken == null && !mConfirmingPassword) { + // Generate challenge in onResume instead of onCreate, since FaceSettings can be + // created while Keyguard is showing, in which case the resetLockout revokeChallenge + // will invalidate the too-early created challenge here. final long challenge = mFaceManager.generateChallenge(); ChooseLockSettingsHelper helper = new ChooseLockSettingsHelper(getActivity(), this); + + mConfirmingPassword = true; if (!helper.launchConfirmationActivity(CONFIRM_REQUEST, getString(R.string.security_settings_face_preference_title), null, null, challenge, mUserId)) { @@ -173,6 +181,7 @@ public class FaceSettings extends DashboardFragment { public void onActivityResult(int requestCode, int resultCode, Intent data) { super.onActivityResult(requestCode, resultCode, data); if (requestCode == CONFIRM_REQUEST) { + mConfirmingPassword = false; if (resultCode == RESULT_FINISHED || resultCode == RESULT_OK) { mFaceManager.setActiveUser(mUserId); // The pin/pattern/password was set. @@ -196,10 +205,18 @@ public class FaceSettings extends DashboardFragment { @Override public void onStop() { super.onStop(); - mToken = null; - final int result = mFaceManager.revokeChallenge(); - if (result < 0) { - Log.w(TAG, "revokeChallenge failed, result: " + result); + + if (!mEnrollController.isClicked() && !getActivity().isChangingConfigurations() + && !mConfirmingPassword) { + // Revoke challenge and finish + if (mToken != null) { + final int result = mFaceManager.revokeChallenge(); + if (result < 0) { + Log.w(TAG, "revokeChallenge failed, result: " + result); + } + mToken = null; + } + getActivity().finish(); } } diff --git a/src/com/android/settings/biometrics/face/FaceSettingsEnrollButtonPreferenceController.java b/src/com/android/settings/biometrics/face/FaceSettingsEnrollButtonPreferenceController.java index ec7b1948fea..a087ccc78e4 100644 --- a/src/com/android/settings/biometrics/face/FaceSettingsEnrollButtonPreferenceController.java +++ b/src/com/android/settings/biometrics/face/FaceSettingsEnrollButtonPreferenceController.java @@ -42,6 +42,7 @@ public class FaceSettingsEnrollButtonPreferenceController extends BasePreference private byte[] mToken; private SettingsActivity mActivity; private Button mButton; + private boolean mIsClicked; public FaceSettingsEnrollButtonPreferenceController(Context context) { this(context, KEY); @@ -63,6 +64,7 @@ public class FaceSettingsEnrollButtonPreferenceController extends BasePreference @Override public void onClick(View v) { + mIsClicked = true; final Intent intent = new Intent(); intent.setClassName("com.android.settings", FaceEnrollIntroduction.class.getName()); intent.putExtra(Intent.EXTRA_USER_ID, mUserId); @@ -83,6 +85,13 @@ public class FaceSettingsEnrollButtonPreferenceController extends BasePreference mToken = token; } + // Return the click state, then clear its state. + public boolean isClicked() { + final boolean wasClicked = mIsClicked; + mIsClicked = false; + return wasClicked; + } + public void setActivity(SettingsActivity activity) { mActivity = activity; } diff --git a/src/com/android/settings/development/AllowBackgroundActivityStartsPreferenceController.java b/src/com/android/settings/development/AllowBackgroundActivityStartsPreferenceController.java deleted file mode 100644 index 81efaa6d157..00000000000 --- a/src/com/android/settings/development/AllowBackgroundActivityStartsPreferenceController.java +++ /dev/null @@ -1,91 +0,0 @@ -/* - * 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.DeviceConfig; -import android.provider.Settings; - -import androidx.preference.Preference; -import androidx.preference.SwitchPreference; - -import com.android.internal.annotations.VisibleForTesting; -import com.android.settings.core.PreferenceControllerMixin; -import com.android.settingslib.development.DeveloperOptionsPreferenceController; - -public class AllowBackgroundActivityStartsPreferenceController - extends DeveloperOptionsPreferenceController - implements Preference.OnPreferenceChangeListener, PreferenceControllerMixin { - - private static final String BACKGROUND_ACTIVITY_STARTS_ENABLED_KEY - = "allow_background_activity_starts"; - - /** Key in DeviceConfig that stores the default for the preference (as a boolean). */ - @VisibleForTesting - static final String KEY_DEFAULT_BACKGROUND_ACTIVITY_STARTS_ENABLED = - "default_background_activity_starts_enabled"; - - public AllowBackgroundActivityStartsPreferenceController(Context context) { - super(context); - } - - @Override - public String getPreferenceKey() { - return BACKGROUND_ACTIVITY_STARTS_ENABLED_KEY; - } - - @Override - public boolean onPreferenceChange(Preference preference, Object newValue) { - writeSetting((boolean) newValue); - return true; - } - - @Override - public void updateState(Preference preference) { - final int mode = Settings.Global.getInt(mContext.getContentResolver(), - Settings.Global.BACKGROUND_ACTIVITY_STARTS_ENABLED, -1); - - boolean isEnabled = mode < 0 ? isDefaultEnabled() : mode != 0; - ((SwitchPreference) mPreference).setChecked(isEnabled); - } - - @Override - protected void onDeveloperOptionsSwitchDisabled() { - super.onDeveloperOptionsSwitchDisabled(); - clearSetting(); - updateState(mPreference); - } - - private void writeSetting(boolean isEnabled) { - Settings.Global.putInt(mContext.getContentResolver(), - Settings.Global.BACKGROUND_ACTIVITY_STARTS_ENABLED, isEnabled ? 1 : 0); - } - - private void clearSetting() { - Settings.Global.putInt(mContext.getContentResolver(), - Settings.Global.BACKGROUND_ACTIVITY_STARTS_ENABLED, -1); - } - - private boolean isDefaultEnabled() { - // The default in the absence of user preference is settable via DeviceConfig. - // Note that the default default is disabled. - return DeviceConfig.getBoolean( - DeviceConfig.NAMESPACE_ACTIVITY_MANAGER, - KEY_DEFAULT_BACKGROUND_ACTIVITY_STARTS_ENABLED, - /*defaultValue*/ false); - } -} diff --git a/src/com/android/settings/development/DevelopmentSettingsDashboardFragment.java b/src/com/android/settings/development/DevelopmentSettingsDashboardFragment.java index d6d89576359..b253702af36 100644 --- a/src/com/android/settings/development/DevelopmentSettingsDashboardFragment.java +++ b/src/com/android/settings/development/DevelopmentSettingsDashboardFragment.java @@ -473,7 +473,6 @@ public class DevelopmentSettingsDashboardFragment extends RestrictedDashboardFra controllers.add(new ProfileGpuRenderingPreferenceController(context)); controllers.add(new KeepActivitiesPreferenceController(context)); controllers.add(new BackgroundProcessLimitPreferenceController(context)); - controllers.add(new AllowBackgroundActivityStartsPreferenceController(context)); controllers.add(new ShowFirstCrashDialogPreferenceController(context)); controllers.add(new AppsNotRespondingPreferenceController(context)); controllers.add(new NotificationChannelWarningsPreferenceController(context)); diff --git a/src/com/android/settings/network/telephony/DataDuringCallsPreferenceController.java b/src/com/android/settings/network/telephony/DataDuringCallsPreferenceController.java new file mode 100644 index 00000000000..6f61d915b91 --- /dev/null +++ b/src/com/android/settings/network/telephony/DataDuringCallsPreferenceController.java @@ -0,0 +1,104 @@ +/* + * Copyright (C) 2019 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.network.telephony; + +import static androidx.lifecycle.Lifecycle.Event.ON_PAUSE; +import static androidx.lifecycle.Lifecycle.Event.ON_RESUME; + +import android.content.Context; +import android.telephony.SubscriptionManager; +import android.telephony.TelephonyManager; + +import androidx.lifecycle.Lifecycle; +import androidx.lifecycle.LifecycleObserver; +import androidx.lifecycle.OnLifecycleEvent; +import androidx.preference.Preference; +import androidx.preference.PreferenceScreen; +import androidx.preference.SwitchPreference; + +import com.android.settings.network.SubscriptionsChangeListener; + +public class DataDuringCallsPreferenceController extends TelephonyTogglePreferenceController + implements LifecycleObserver, + SubscriptionsChangeListener.SubscriptionsChangeListenerClient { + + private SwitchPreference mPreference; + private SubscriptionsChangeListener mChangeListener; + private TelephonyManager mManager; + + public DataDuringCallsPreferenceController(Context context, + String preferenceKey) { + super(context, preferenceKey); + mChangeListener = new SubscriptionsChangeListener(mContext, this); + } + + public void init(Lifecycle lifecycle, int subId) { + this.mSubId = subId; + mManager = mContext.getSystemService(TelephonyManager.class).createForSubscriptionId(subId); + lifecycle.addObserver(this); + } + + @OnLifecycleEvent(ON_RESUME) + public void onResume() { + mChangeListener.start(); + } + + @OnLifecycleEvent(ON_PAUSE) + public void onPause() { + mChangeListener.stop(); + } + + @Override + public void displayPreference(PreferenceScreen screen) { + super.displayPreference(screen); + mPreference = screen.findPreference(getPreferenceKey()); + } + + @Override + public boolean isChecked() { + return mManager.isDataAllowedInVoiceCall(); + } + + @Override + public boolean setChecked(boolean isChecked) { + mManager.setDataAllowedDuringVoiceCall(isChecked); + return true; + } + + @Override + public int getAvailabilityStatus(int subId) { + if (mSubId == SubscriptionManager.INVALID_SUBSCRIPTION_ID || + SubscriptionManager.getDefaultDataSubscriptionId() == mSubId) { + return CONDITIONALLY_UNAVAILABLE; + } + return AVAILABLE; + } + + @Override + public void updateState(Preference preference) { + super.updateState(preference); + preference.setVisible(isAvailable()); + } + + @Override + public void onAirplaneModeChanged(boolean airplaneModeEnabled) {} + + @Override + public void onSubscriptionsChanged() { + updateState(mPreference); + } +} diff --git a/src/com/android/settings/network/telephony/MobileNetworkSettings.java b/src/com/android/settings/network/telephony/MobileNetworkSettings.java index 838aa12f95f..aa63b747ad9 100644 --- a/src/com/android/settings/network/telephony/MobileNetworkSettings.java +++ b/src/com/android/settings/network/telephony/MobileNetworkSettings.java @@ -138,6 +138,7 @@ public class MobileNetworkSettings extends RestrictedDashboardFragment { use(CarrierSettingsVersionPreferenceController.class).init(mSubId); use(BillingCyclePreferenceController.class).init(mSubId); use(MmsMessagePreferenceController.class).init(mSubId); + use(DataDuringCallsPreferenceController.class).init(getLifecycle(), mSubId); use(DisabledSubscriptionController.class).init(getLifecycle(), mSubId); use(DeleteSimProfilePreferenceController.class).init(mSubId, this, REQUEST_CODE_DELETE_SUBSCRIPTION); diff --git a/tests/robotests/assets/grandfather_slice_controller_not_in_xml b/tests/robotests/assets/grandfather_slice_controller_not_in_xml index 328c7bc35c7..fd1cef2469c 100644 --- a/tests/robotests/assets/grandfather_slice_controller_not_in_xml +++ b/tests/robotests/assets/grandfather_slice_controller_not_in_xml @@ -4,3 +4,4 @@ com.android.settings.testutils.FakeInvalidSliderController com.android.settings.core.TogglePreferenceControllerTest$FakeToggle com.android.settings.accessibility.AccessibilitySlicePreferenceController com.android.settings.network.telephony.MmsMessagePreferenceController +com.android.settings.network.telephony.DataDuringCallsPreferenceController diff --git a/tests/robotests/src/com/android/settings/development/AllowBackgroundActivityStartsPreferenceControllerTest.java b/tests/robotests/src/com/android/settings/development/AllowBackgroundActivityStartsPreferenceControllerTest.java deleted file mode 100644 index 81658628897..00000000000 --- a/tests/robotests/src/com/android/settings/development/AllowBackgroundActivityStartsPreferenceControllerTest.java +++ /dev/null @@ -1,159 +0,0 @@ -/* - * 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 static com.android.settings.development.AllowBackgroundActivityStartsPreferenceController.KEY_DEFAULT_BACKGROUND_ACTIVITY_STARTS_ENABLED; - -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.DeviceConfig; -import android.provider.Settings; - -import androidx.preference.PreferenceScreen; -import androidx.preference.SwitchPreference; - -import com.android.settings.testutils.shadow.ShadowDeviceConfig; - -import org.junit.Before; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.mockito.Mock; -import org.mockito.MockitoAnnotations; -import org.robolectric.RobolectricTestRunner; -import org.robolectric.RuntimeEnvironment; -import org.robolectric.annotation.Config; - -@RunWith(RobolectricTestRunner.class) -@Config(shadows = {ShadowDeviceConfig.class}) -public class AllowBackgroundActivityStartsPreferenceControllerTest { - - @Mock - private SwitchPreference mPreference; - @Mock - private PreferenceScreen mPreferenceScreen; - - private Context mContext; - private AllowBackgroundActivityStartsPreferenceController mController; - - @Before - public void setup() { - MockitoAnnotations.initMocks(this); - mContext = RuntimeEnvironment.application; - mController = new AllowBackgroundActivityStartsPreferenceController(mContext); - when(mPreferenceScreen.findPreference(mController.getPreferenceKey())) - .thenReturn(mPreference); - mController.displayPreference(mPreferenceScreen); - } - - @Test - public void onPreferenceChange_settingEnabled_allowBackgroundActivityStartsShouldBeOn() { - mController.onPreferenceChange(mPreference, true /* new value */); - - assertThat(getModeFroMSettings()).isEqualTo(1); - } - - @Test - public void onPreferenceChange_settingDisabled_allowBackgroundActivityStartsShouldBeOff() { - mController.onPreferenceChange(mPreference, false /* new value */); - - assertThat(getModeFroMSettings()).isEqualTo(0); - } - - @Test - public void updateState_settingDisabled_preferenceShouldNotBeChecked() { - Settings.Global.putInt(mContext.getContentResolver(), - Settings.Global.BACKGROUND_ACTIVITY_STARTS_ENABLED, 0); - mController.updateState(mPreference); - - verify(mPreference).setChecked(false); - } - - @Test - public void updateState_settingEnabled_preferenceShouldBeChecked() { - Settings.Global.putInt(mContext.getContentResolver(), - Settings.Global.BACKGROUND_ACTIVITY_STARTS_ENABLED, 1); - mController.updateState(mPreference); - - verify(mPreference).setChecked(true); - } - - @Test - public void updateState_settingReset_defaultDisabled_preferenceShouldNotBeChecked() { - setDefault(false); - mController.updateState(mPreference); - - verify(mPreference).setChecked(false); - } - - @Test - public void updateState_settingReset_defaultEnabled_preferenceShouldBeChecked() { - setDefault(true); - mController.updateState(mPreference); - - verify(mPreference).setChecked(true); - } - - @Test - public void onDeveloperOptionsSwitchDisabled_noDefault_shouldResetPreference() { - mController.onDeveloperOptionsSwitchDisabled(); - - verify(mPreference).setChecked(false); - verify(mPreference).setEnabled(false); - - assertThat(getModeFroMSettings()).isEqualTo(-1); - } - - @Test - public void onDeveloperOptionsSwitchDisabled_defaultDisabled_shouldResetPreference() { - setDefault(false); - mController.onDeveloperOptionsSwitchDisabled(); - - verify(mPreference).setChecked(false); - verify(mPreference).setEnabled(false); - - assertThat(getModeFroMSettings()).isEqualTo(-1); - } - - @Test - public void onDeveloperOptionsSwitchDisabled_defaultEnabled_shouldResetPreference() { - setDefault(true); - mController.onDeveloperOptionsSwitchDisabled(); - - verify(mPreference).setChecked(true); - verify(mPreference).setEnabled(false); - - assertThat(getModeFroMSettings()).isEqualTo(-1); - } - - private int getModeFroMSettings() { - return Settings.Global.getInt(mContext.getContentResolver(), - Settings.Global.BACKGROUND_ACTIVITY_STARTS_ENABLED, 999 /* default */); - } - - private void setDefault(boolean defaultEnabled) { - DeviceConfig.setProperty( - DeviceConfig.NAMESPACE_ACTIVITY_MANAGER, - KEY_DEFAULT_BACKGROUND_ACTIVITY_STARTS_ENABLED, - Boolean.toString(defaultEnabled), - false /* makeDefault */); - } -} - diff --git a/tests/robotests/src/com/android/settings/network/DataDuringCallsPreferenceControllerTest.java b/tests/robotests/src/com/android/settings/network/DataDuringCallsPreferenceControllerTest.java new file mode 100644 index 00000000000..a42420cc895 --- /dev/null +++ b/tests/robotests/src/com/android/settings/network/DataDuringCallsPreferenceControllerTest.java @@ -0,0 +1,134 @@ +/* + * Copyright (C) 2019 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.network; + +import static android.telephony.SubscriptionManager.INVALID_SUBSCRIPTION_ID; + +import static com.android.settings.core.BasePreferenceController.CONDITIONALLY_UNAVAILABLE; + +import static com.google.common.truth.Truth.assertThat; + +import static org.mockito.ArgumentMatchers.anyInt; +import static org.mockito.ArgumentMatchers.eq; +import static org.mockito.Mockito.doReturn; +import static org.mockito.Mockito.spy; +import static org.mockito.Mockito.when; + +import android.content.Context; +import android.telephony.TelephonyManager; + +import androidx.lifecycle.Lifecycle; +import androidx.preference.PreferenceScreen; +import androidx.preference.SwitchPreference; + +import com.android.settings.network.telephony.DataDuringCallsPreferenceController; + +import org.junit.Before; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mockito.Mock; +import org.mockito.MockitoAnnotations; +import org.robolectric.RobolectricTestRunner; +import org.robolectric.RuntimeEnvironment; +import org.robolectric.annotation.Config; +import org.robolectric.shadows.ShadowSubscriptionManager; + +@RunWith(RobolectricTestRunner.class) +@Config(shadows = ShadowSubscriptionManager.class) +public class DataDuringCallsPreferenceControllerTest { + private static final String PREF_KEY = "pref_key"; + private static final int SUB_ID_1 = 111; + private static final int SUB_ID_2 = 222; + + @Mock + private TelephonyManager mTelephonyManager; + @Mock + private Lifecycle mLifecycle; + @Mock + private PreferenceScreen mPreferenceScreen; + + private Context mContext; + private SwitchPreference mSwitchPreference; + private DataDuringCallsPreferenceController mController; + + @Before + public void setUp() { + MockitoAnnotations.initMocks(this); + mContext = spy(RuntimeEnvironment.application); + doReturn(mTelephonyManager).when(mContext).getSystemService(eq(TelephonyManager.class)); + when(mTelephonyManager.createForSubscriptionId(anyInt())).thenReturn(mTelephonyManager); + mSwitchPreference = new SwitchPreference(mContext); + when(mPreferenceScreen.findPreference(PREF_KEY)).thenReturn(mSwitchPreference); + mController = new DataDuringCallsPreferenceController(mContext, PREF_KEY); + mController.init(mLifecycle, SUB_ID_1); + } + + @Test + public void getAvailabilityStatus_noInit_notAvailable() { + ShadowSubscriptionManager.setDefaultDataSubscriptionId(SUB_ID_1); + DataDuringCallsPreferenceController controller = + new DataDuringCallsPreferenceController(mContext, PREF_KEY); + + // note that we purposely don't call init first on the controller + assertThat(controller.getAvailabilityStatus(INVALID_SUBSCRIPTION_ID)).isEqualTo( + CONDITIONALLY_UNAVAILABLE); + } + + @Test + public void displayPreference_defaultForData_notAvailable() { + ShadowSubscriptionManager.setDefaultDataSubscriptionId(SUB_ID_1); + + mController.displayPreference(mPreferenceScreen); + + assertThat(mController.isAvailable()).isFalse(); + assertThat(mSwitchPreference.isVisible()).isFalse(); + } + + @Test + public void displayPreference_notDefaultForData_available() { + ShadowSubscriptionManager.setDefaultDataSubscriptionId(SUB_ID_2); + + mController.displayPreference(mPreferenceScreen); + + assertThat(mController.isAvailable()).isTrue(); + assertThat(mSwitchPreference.isVisible()).isTrue(); + } + + @Test + public void onSubscriptionsChanged_becomesDefaultForData_notAvailable() { + ShadowSubscriptionManager.setDefaultDataSubscriptionId(SUB_ID_2); + + mController.displayPreference(mPreferenceScreen); + ShadowSubscriptionManager.setDefaultDataSubscriptionId(SUB_ID_1); + mController.onSubscriptionsChanged(); + + assertThat(mController.isAvailable()).isFalse(); + assertThat(mSwitchPreference.isVisible()).isFalse(); + } + + @Test + public void onSubscriptionsChanged_noLongerDefaultForData_available() { + ShadowSubscriptionManager.setDefaultDataSubscriptionId(SUB_ID_1); + + mController.displayPreference(mPreferenceScreen); + ShadowSubscriptionManager.setDefaultDataSubscriptionId(SUB_ID_2); + mController.onSubscriptionsChanged(); + + assertThat(mController.isAvailable()).isTrue(); + assertThat(mSwitchPreference.isVisible()).isTrue(); + } +}