diff --git a/res/values/strings.xml b/res/values/strings.xml index f8198a9e1a9..fe5b6a952c1 100644 --- a/res/values/strings.xml +++ b/res/values/strings.xml @@ -971,7 +971,7 @@ Set up face unlock - Use face unlock to unlock your device, sign in to apps, and confirm payments.\n\nKeep in mind:\nLooking at the phone can unlock it when you don\u2019t intend to.\n\nYour phone can be unlocked by someone else if it\u2019s held up to your face while your eyes are open.\n\nYour phone can be unlocked by someone who looks a lot like you, say, an identical sibling. + Use face unlock to unlock your device, sign in to apps, and confirm payments.\n\nKeep in mind:\nLooking at the phone can unlock it when you don\u2019t intend to.\n\nYour phone can be unlocked by someone else if it\u2019s held up to your face, even if your eyes are closed.\n\nYour phone can be unlocked by someone who looks a lot like you, say, an identical sibling. Delete face data? diff --git a/src/com/android/settings/wifi/CellularFallbackPreferenceController.java b/src/com/android/settings/wifi/CellularFallbackPreferenceController.java index cbb8fb8e26a..01677891bb1 100644 --- a/src/com/android/settings/wifi/CellularFallbackPreferenceController.java +++ b/src/com/android/settings/wifi/CellularFallbackPreferenceController.java @@ -17,8 +17,11 @@ package com.android.settings.wifi; import android.content.Context; +import android.content.res.Resources; import android.provider.Settings; +import android.telephony.SubscriptionManager; +import com.android.internal.annotations.VisibleForTesting; import com.android.settings.core.TogglePreferenceController; /** @@ -33,7 +36,7 @@ public class CellularFallbackPreferenceController extends TogglePreferenceContro @Override public int getAvailabilityStatus() { - return !avoidBadWifiConfig() ? AVAILABLE : UNSUPPORTED_ON_DEVICE; + return avoidBadWifiConfig() ? UNSUPPORTED_ON_DEVICE : AVAILABLE; } @Override @@ -49,12 +52,28 @@ public class CellularFallbackPreferenceController extends TogglePreferenceContro } private boolean avoidBadWifiConfig() { - return mContext.getResources().getInteger( - com.android.internal.R.integer.config_networkAvoidBadWifi) == 1; + final int activeDataSubscriptionId = getActiveDataSubscriptionId(); + if (activeDataSubscriptionId == SubscriptionManager.INVALID_SUBSCRIPTION_ID) { + return true; + } + + final Resources resources = getResourcesForSubId(activeDataSubscriptionId); + return resources.getInteger(com.android.internal.R.integer.config_networkAvoidBadWifi) == 1; + } + + @VisibleForTesting + int getActiveDataSubscriptionId() { + return SubscriptionManager.getActiveDataSubscriptionId(); + } + + @VisibleForTesting + Resources getResourcesForSubId(int subscriptionId) { + return SubscriptionManager.getResourcesForSubId(mContext, subscriptionId, + false /* useRootLocale */); } private boolean avoidBadWifiCurrentSettings() { return "1".equals(Settings.Global.getString(mContext.getContentResolver(), Settings.Global.NETWORK_AVOID_BAD_WIFI)); } -} \ No newline at end of file +} diff --git a/tests/robotests/src/com/android/settings/wifi/CellularFallbackPreferenceControllerTest.java b/tests/robotests/src/com/android/settings/wifi/CellularFallbackPreferenceControllerTest.java index c5bd555fa9a..6f3230cff4f 100644 --- a/tests/robotests/src/com/android/settings/wifi/CellularFallbackPreferenceControllerTest.java +++ b/tests/robotests/src/com/android/settings/wifi/CellularFallbackPreferenceControllerTest.java @@ -18,36 +18,54 @@ package com.android.settings.wifi; import static com.google.common.truth.Truth.assertThat; +import static org.mockito.ArgumentMatchers.anyInt; +import static org.mockito.Mockito.doReturn; +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.spy; import static org.mockito.Mockito.when; import android.content.Context; +import android.content.res.Resources; +import android.telephony.SubscriptionManager; import org.junit.Before; import org.junit.Test; import org.junit.runner.RunWith; -import org.mockito.Answers; import org.mockito.Mock; import org.mockito.MockitoAnnotations; import org.robolectric.RobolectricTestRunner; +import org.robolectric.RuntimeEnvironment; @RunWith(RobolectricTestRunner.class) public class CellularFallbackPreferenceControllerTest { private static final String KEY_CELLULAR_FALLBACK = "wifi_cellular_data_fallback"; - @Mock(answer = Answers.RETURNS_DEEP_STUBS) - private Context mContext; - private CellularFallbackPreferenceController mController; @Before public void setUp() { MockitoAnnotations.initMocks(this); - mController = new CellularFallbackPreferenceController(mContext, KEY_CELLULAR_FALLBACK); + + mController = spy(new CellularFallbackPreferenceController(RuntimeEnvironment.application, + KEY_CELLULAR_FALLBACK)); + } + + @Test + public void isAvailable_invalidActiveSubscriptionId_shouldReturnFalse() { + doReturn(SubscriptionManager.INVALID_SUBSCRIPTION_ID) + .when(mController).getActiveDataSubscriptionId(); + + assertThat(mController.isAvailable()).isFalse(); } @Test public void isAvailable_avoidBadWifiConfigIsFalse_shouldReturnTrue() { - when(mContext.getResources().getInteger( + final Resources resources = mock(Resources.class); + + doReturn(SubscriptionManager.DEFAULT_SUBSCRIPTION_ID) + .when(mController).getActiveDataSubscriptionId(); + doReturn(resources).when(mController).getResourcesForSubId(anyInt()); + when(resources.getInteger( com.android.internal.R.integer.config_networkAvoidBadWifi)) .thenReturn(0); @@ -56,10 +74,15 @@ public class CellularFallbackPreferenceControllerTest { @Test public void isAvailable_avoidBadWifiConfigIsTrue_shouldReturnFalse() { - when(mContext.getResources().getInteger( + final Resources resources = mock(Resources.class); + + doReturn(SubscriptionManager.DEFAULT_SUBSCRIPTION_ID) + .when(mController).getActiveDataSubscriptionId(); + doReturn(resources).when(mController).getResourcesForSubId(anyInt()); + when(resources.getInteger( com.android.internal.R.integer.config_networkAvoidBadWifi)) .thenReturn(1); assertThat(mController.isAvailable()).isFalse(); } -} +} \ No newline at end of file