diff --git a/res/values/strings.xml b/res/values/strings.xml
index 812ff86e20e..f027e91a65c 100644
--- a/res/values/strings.xml
+++ b/res/values/strings.xml
@@ -12056,6 +12056,9 @@
Show controls when locked
+
+ Show cards when locked
+
Hide cards and controls when locked
diff --git a/src/com/android/settings/gestures/DeviceControlsPreferenceController.java b/src/com/android/settings/gestures/DeviceControlsPreferenceController.java
index e588e86354d..0e0c04bddbd 100644
--- a/src/com/android/settings/gestures/DeviceControlsPreferenceController.java
+++ b/src/com/android/settings/gestures/DeviceControlsPreferenceController.java
@@ -17,6 +17,7 @@
package com.android.settings.gestures;
import android.content.Context;
+import android.content.pm.PackageManager;
import android.provider.Settings;
import android.text.TextUtils;
@@ -37,7 +38,9 @@ public class DeviceControlsPreferenceController extends GesturePreferenceControl
@Override
public int getAvailabilityStatus() {
- return AVAILABLE;
+ boolean available = mContext.getPackageManager().hasSystemFeature(
+ PackageManager.FEATURE_CONTROLS);
+ return available ? AVAILABLE : CONDITIONALLY_UNAVAILABLE;
}
@Override
diff --git a/src/com/android/settings/gestures/PowerMenuPreferenceController.java b/src/com/android/settings/gestures/PowerMenuPreferenceController.java
index e65d140dbdb..6ef583b7037 100644
--- a/src/com/android/settings/gestures/PowerMenuPreferenceController.java
+++ b/src/com/android/settings/gestures/PowerMenuPreferenceController.java
@@ -17,6 +17,7 @@
package com.android.settings.gestures;
import android.content.Context;
+import android.content.pm.PackageManager;
import android.provider.Settings;
import com.android.settings.R;
@@ -37,15 +38,15 @@ public class PowerMenuPreferenceController extends BasePreferenceController {
@Override
public CharSequence getSummary() {
- boolean controlsEnabled = Settings.Secure.getInt(mContext.getContentResolver(),
- CONTROLS_ENABLED_SETTING, 1) == 1;
- boolean cardsEnabled = Settings.Secure.getInt(mContext.getContentResolver(),
- CARDS_ENABLED_SETTING, 0) == 1;
- boolean cardsVisible = cardsEnabled && Settings.Secure.getInt(mContext.getContentResolver(),
- CARDS_AVAILABLE_SETTING, 0) == 1;
- if (controlsEnabled && cardsVisible) {
+ boolean controlsVisible = isControlsAvailable()
+ && Settings.Secure.getInt(mContext.getContentResolver(),
+ CONTROLS_ENABLED_SETTING, 1) == 1;
+ boolean cardsVisible = isCardsAvailable()
+ && Settings.Secure.getInt(mContext.getContentResolver(),
+ CARDS_ENABLED_SETTING, 0) == 1;
+ if (controlsVisible && cardsVisible) {
return mContext.getText(R.string.power_menu_cards_passes_device_controls);
- } else if (controlsEnabled) {
+ } else if (controlsVisible) {
return mContext.getText(R.string.power_menu_device_controls);
} else if (cardsVisible) {
return mContext.getText(R.string.power_menu_cards_passes);
@@ -56,6 +57,15 @@ public class PowerMenuPreferenceController extends BasePreferenceController {
@Override
public int getAvailabilityStatus() {
- return AVAILABLE;
+ return isCardsAvailable() || isControlsAvailable() ? AVAILABLE : CONDITIONALLY_UNAVAILABLE;
+ }
+
+ private boolean isControlsAvailable() {
+ return mContext.getPackageManager().hasSystemFeature(PackageManager.FEATURE_CONTROLS);
+ }
+
+ private boolean isCardsAvailable() {
+ return Settings.Secure.getInt(mContext.getContentResolver(),
+ CARDS_AVAILABLE_SETTING, 0) == 1;
}
}
diff --git a/src/com/android/settings/gestures/PowerMenuPrivacyPreferenceController.java b/src/com/android/settings/gestures/PowerMenuPrivacyPreferenceController.java
index ec88ddc01cf..0cd71ee8657 100644
--- a/src/com/android/settings/gestures/PowerMenuPrivacyPreferenceController.java
+++ b/src/com/android/settings/gestures/PowerMenuPrivacyPreferenceController.java
@@ -18,6 +18,7 @@ package com.android.settings.gestures;
import android.content.ContentResolver;
import android.content.Context;
+import android.content.pm.PackageManager;
import android.os.UserHandle;
import android.provider.Settings;
@@ -57,13 +58,20 @@ public class PowerMenuPrivacyPreferenceController extends TogglePreferenceContro
public CharSequence getSummary() {
boolean cardsAvailable = Settings.Secure.getInt(mContext.getContentResolver(),
CARDS_AVAILABLE_KEY, 0) != 0;
+ boolean controlsAvailable = isControlsAvailable();
final int res;
if (!isSecure()) {
res = R.string.power_menu_privacy_not_secure;
- } else if (cardsAvailable) {
+ } else if (cardsAvailable && controlsAvailable) {
res = R.string.power_menu_privacy_show;
- } else {
+ } else if (!cardsAvailable && controlsAvailable) {
res = R.string.power_menu_privacy_show_controls;
+ } else if (cardsAvailable) {
+ res = R.string.power_menu_privacy_show_cards;
+ } else {
+ // In this case, neither cards nor controls are available. This preference should not
+ // be accessible as the power menu setting is not accessible
+ return "";
}
return mContext.getText(res);
}
@@ -87,7 +95,7 @@ public class PowerMenuPrivacyPreferenceController extends TogglePreferenceContro
boolean cardsAvailable = Settings.Secure.getInt(resolver, CARDS_AVAILABLE_KEY, 0) != 0;
boolean cardsEnabled = Settings.Secure.getInt(resolver, CARDS_ENABLED_KEY, 0) != 0;
boolean controlsEnabled = Settings.Secure.getInt(resolver, CONTROLS_ENABLED_KEY, 1) != 0;
- return (cardsAvailable && cardsEnabled) || controlsEnabled;
+ return (cardsAvailable && cardsEnabled) || (isControlsAvailable() && controlsEnabled);
}
private boolean isSecure() {
@@ -97,4 +105,8 @@ public class PowerMenuPrivacyPreferenceController extends TogglePreferenceContro
int userId = UserHandle.myUserId();
return utils.isSecure(userId);
}
+
+ private boolean isControlsAvailable() {
+ return mContext.getPackageManager().hasSystemFeature(PackageManager.FEATURE_CONTROLS);
+ }
}
diff --git a/tests/robotests/src/com/android/settings/gestures/DeviceControlsPreferenceControllerTest.java b/tests/robotests/src/com/android/settings/gestures/DeviceControlsPreferenceControllerTest.java
index c31971a991b..432a68d0a8b 100644
--- a/tests/robotests/src/com/android/settings/gestures/DeviceControlsPreferenceControllerTest.java
+++ b/tests/robotests/src/com/android/settings/gestures/DeviceControlsPreferenceControllerTest.java
@@ -19,6 +19,7 @@ package com.android.settings.gestures;
import static com.google.common.truth.Truth.assertThat;
import android.content.Context;
+import android.content.pm.PackageManager;
import android.provider.Settings;
import com.android.settings.core.BasePreferenceController;
@@ -28,12 +29,15 @@ import org.junit.Test;
import org.junit.runner.RunWith;
import org.robolectric.RobolectricTestRunner;
import org.robolectric.RuntimeEnvironment;
+import org.robolectric.Shadows;
+import org.robolectric.shadows.ShadowPackageManager;
@RunWith(RobolectricTestRunner.class)
public class DeviceControlsPreferenceControllerTest {
private Context mContext;
private DeviceControlsPreferenceController mController;
+ private ShadowPackageManager mShadowPackageManager;
private static final String KEY_GESTURE_PANEL = "gesture_device_controls";
private static final String ENABLED_SETTING =
@@ -42,6 +46,7 @@ public class DeviceControlsPreferenceControllerTest {
@Before
public void setUp() {
mContext = RuntimeEnvironment.application;
+ mShadowPackageManager = Shadows.shadowOf(mContext.getPackageManager());
mController = new DeviceControlsPreferenceController(mContext, KEY_GESTURE_PANEL);
}
@@ -60,11 +65,21 @@ public class DeviceControlsPreferenceControllerTest {
}
@Test
- public void getAvailabilityStatus_panelAvailable() {
+ public void getAvailabilityStatus_hasSystemFeature_panelAvailable() {
+ mShadowPackageManager.setSystemFeature(PackageManager.FEATURE_CONTROLS, true);
+
assertThat(mController.getAvailabilityStatus())
.isEqualTo(BasePreferenceController.AVAILABLE);
}
+ @Test
+ public void getAvailabilityStatus_hasntSystemFeature_panelUnsupported() {
+ mShadowPackageManager.setSystemFeature(PackageManager.FEATURE_CONTROLS, false);
+
+ assertThat(mController.getAvailabilityStatus())
+ .isEqualTo(BasePreferenceController.CONDITIONALLY_UNAVAILABLE);
+ }
+
@Test
public void isSliceable_correctKey() {
final DeviceControlsPreferenceController controller =
diff --git a/tests/robotests/src/com/android/settings/gestures/PowerMenuPreferenceControllerSummaryTest.java b/tests/robotests/src/com/android/settings/gestures/PowerMenuPreferenceControllerSummaryTest.java
new file mode 100644
index 00000000000..7fa248c7c93
--- /dev/null
+++ b/tests/robotests/src/com/android/settings/gestures/PowerMenuPreferenceControllerSummaryTest.java
@@ -0,0 +1,113 @@
+/*
+ * Copyright (C) 2020 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.gestures;
+
+import static com.google.common.truth.Truth.assertThat;
+
+import android.annotation.StringRes;
+import android.content.ContentResolver;
+import android.content.Context;
+import android.content.pm.PackageManager;
+import android.provider.Settings;
+
+import com.android.settings.R;
+
+import org.junit.Before;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.robolectric.ParameterizedRobolectricTestRunner;
+import org.robolectric.RuntimeEnvironment;
+import org.robolectric.Shadows;
+import org.robolectric.shadows.ShadowPackageManager;
+
+import java.util.Arrays;
+import java.util.Collection;
+
+@RunWith(ParameterizedRobolectricTestRunner.class)
+public class PowerMenuPreferenceControllerSummaryTest {
+
+ private static final String KEY_GESTURE_POWER_MENU = "gesture_power_menu";
+ private static final String CONTROLS_ENABLED = Settings.Secure.CONTROLS_ENABLED;
+ private static final String CONTROLS_FEATURE = PackageManager.FEATURE_CONTROLS;
+ private static final String CARDS_ENABLED = Settings.Secure.GLOBAL_ACTIONS_PANEL_ENABLED;
+ private static final String CARDS_AVAILABLE = Settings.Secure.GLOBAL_ACTIONS_PANEL_AVAILABLE;
+
+ @ParameterizedRobolectricTestRunner.Parameters(
+ name = "ctrls available={0}, ctrls enabled={1}, cards available={2}, cards enabled={3}")
+ public static Collection data() {
+ return Arrays.asList(new Object[][]{
+ // controls available, controls enabled, cards available, cards enabled, summary
+ {false, false, false, false, R.string.power_menu_none},
+ {false, false, false, true, R.string.power_menu_none},
+ {false, false, true, false, R.string.power_menu_none},
+ {false, false, true, true, R.string.power_menu_cards_passes},
+ {false, true, false, false, R.string.power_menu_none},
+ {false, true, false, true, R.string.power_menu_none},
+ {false, true, true, false, R.string.power_menu_none},
+ {false, true, true, true, R.string.power_menu_cards_passes},
+ {true, false, false, false, R.string.power_menu_none},
+ {true, false, false, true, R.string.power_menu_none},
+ {true, false, true, false, R.string.power_menu_none},
+ {true, false, true, true, R.string.power_menu_cards_passes},
+ {true, true, false, false, R.string.power_menu_device_controls},
+ {true, true, false, true, R.string.power_menu_device_controls},
+ {true, true, true, false, R.string.power_menu_device_controls},
+ {true, true, true, true, R.string.power_menu_cards_passes_device_controls}
+ });
+ }
+
+ private Context mContext;
+ private PowerMenuPreferenceController mController;
+ private ShadowPackageManager mShadowPackageManager;
+
+ private boolean mControlsAvailable;
+ private boolean mControlsEnabled;
+ private boolean mCardsAvailable;
+ private boolean mCardsEnabled;
+ private @StringRes int mSummaryRes;
+
+ public PowerMenuPreferenceControllerSummaryTest(
+ boolean controlsAvailable,
+ boolean controlsEnabled,
+ boolean cardsAvailable,
+ boolean cardsEnabled,
+ @StringRes int summaryRes) {
+ mControlsAvailable = controlsAvailable;
+ mControlsEnabled = controlsEnabled;
+ mCardsAvailable = cardsAvailable;
+ mCardsEnabled = cardsEnabled;
+ mSummaryRes = summaryRes;
+ }
+
+ @Before
+ public void setUp() {
+ mContext = RuntimeEnvironment.application;
+ mShadowPackageManager = Shadows.shadowOf(mContext.getPackageManager());
+ mController = new PowerMenuPreferenceController(mContext, KEY_GESTURE_POWER_MENU);
+ }
+
+ @Test
+ public void getSummary_possiblyAvailableAndEnabled() {
+ mShadowPackageManager.setSystemFeature(CONTROLS_FEATURE, mControlsAvailable);
+ ContentResolver cr = mContext.getContentResolver();
+ Settings.Secure.putInt(cr, CONTROLS_ENABLED, mControlsEnabled ? 1 : 0);
+ Settings.Secure.putInt(cr, CARDS_AVAILABLE, mCardsAvailable ? 1 : 0);
+ Settings.Secure.putInt(cr, CARDS_ENABLED, mCardsEnabled ? 1 : 0);
+
+ assertThat(mController.getSummary()).isEqualTo(mContext.getText(mSummaryRes));
+ }
+}
diff --git a/tests/robotests/src/com/android/settings/gestures/PowerMenuPreferenceControllerTest.java b/tests/robotests/src/com/android/settings/gestures/PowerMenuPreferenceControllerTest.java
index e14293eb82a..570a68040f7 100644
--- a/tests/robotests/src/com/android/settings/gestures/PowerMenuPreferenceControllerTest.java
+++ b/tests/robotests/src/com/android/settings/gestures/PowerMenuPreferenceControllerTest.java
@@ -19,118 +19,71 @@ package com.android.settings.gestures;
import static com.google.common.truth.Truth.assertThat;
import android.content.Context;
+import android.content.pm.PackageManager;
import android.provider.Settings;
-import com.android.settings.R;
import com.android.settings.core.BasePreferenceController;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
-import org.mockito.MockitoAnnotations;
import org.robolectric.RobolectricTestRunner;
import org.robolectric.RuntimeEnvironment;
+import org.robolectric.Shadows;
+import org.robolectric.shadows.ShadowPackageManager;
@RunWith(RobolectricTestRunner.class)
public class PowerMenuPreferenceControllerTest {
private Context mContext;
private PowerMenuPreferenceController mController;
+ private ShadowPackageManager mShadowPackageManager;
private static final String KEY_GESTURE_POWER_MENU = "gesture_power_menu";
private static final String CONTROLS_ENABLED = Settings.Secure.CONTROLS_ENABLED;
+ private static final String CONTROLS_FEATURE = PackageManager.FEATURE_CONTROLS;
private static final String CARDS_ENABLED = Settings.Secure.GLOBAL_ACTIONS_PANEL_ENABLED;
private static final String CARDS_AVAILABLE = Settings.Secure.GLOBAL_ACTIONS_PANEL_AVAILABLE;
@Before
public void setUp() {
- MockitoAnnotations.initMocks(this);
mContext = RuntimeEnvironment.application;
+ mShadowPackageManager = Shadows.shadowOf(mContext.getPackageManager());
mController = new PowerMenuPreferenceController(mContext, KEY_GESTURE_POWER_MENU);
}
@Test
- public void getAvailabilityStatus_available() {
+ public void getAvailabilityStatus_bothAvailable_available() {
+ Settings.Secure.putInt(mContext.getContentResolver(), CARDS_AVAILABLE, 1);
+ mShadowPackageManager.setSystemFeature(CONTROLS_FEATURE, true);
+
assertThat(mController.getAvailabilityStatus()).isEqualTo(
BasePreferenceController.AVAILABLE);
}
@Test
- public void getSummary_allDisabled() {
- Settings.Secure.putInt(mContext.getContentResolver(), CONTROLS_ENABLED, 0);
- Settings.Secure.putInt(mContext.getContentResolver(), CARDS_ENABLED, 0);
- Settings.Secure.putInt(mContext.getContentResolver(), CARDS_AVAILABLE, 0);
-
- assertThat(mController.getSummary())
- .isEqualTo(mContext.getText(R.string.power_menu_none));
- }
-
- @Test
- public void getSummary_onlyControlsEnabled() {
- Settings.Secure.putInt(mContext.getContentResolver(), CONTROLS_ENABLED, 1);
- Settings.Secure.putInt(mContext.getContentResolver(), CARDS_ENABLED, 0);
- Settings.Secure.putInt(mContext.getContentResolver(), CARDS_AVAILABLE, 0);
-
- assertThat(mController.getSummary())
- .isEqualTo(mContext.getText(R.string.power_menu_device_controls));
- }
-
- @Test
- public void getSummary_onlyCardsEnabled_notAvailable() {
- Settings.Secure.putInt(mContext.getContentResolver(), CONTROLS_ENABLED, 0);
- Settings.Secure.putInt(mContext.getContentResolver(), CARDS_ENABLED, 1);
- Settings.Secure.putInt(mContext.getContentResolver(), CARDS_AVAILABLE, 0);
-
- assertThat(mController.getSummary())
- .isEqualTo(mContext.getText(R.string.power_menu_none));
- }
-
- @Test
- public void getSummary_cardsAvailable_notEnabled() {
- Settings.Secure.putInt(mContext.getContentResolver(), CONTROLS_ENABLED, 0);
- Settings.Secure.putInt(mContext.getContentResolver(), CARDS_ENABLED, 0);
+ public void getAvailabilityStatus_onlyCardsAvailable_available() {
Settings.Secure.putInt(mContext.getContentResolver(), CARDS_AVAILABLE, 1);
+ mShadowPackageManager.setSystemFeature(CONTROLS_FEATURE, false);
- assertThat(mController.getSummary())
- .isEqualTo(mContext.getText(R.string.power_menu_none));
+ assertThat(mController.getAvailabilityStatus()).isEqualTo(
+ BasePreferenceController.AVAILABLE);
}
@Test
- public void getSummary_allEnabled_cardsNotAvailable() {
- Settings.Secure.putInt(mContext.getContentResolver(), CONTROLS_ENABLED, 1);
- Settings.Secure.putInt(mContext.getContentResolver(), CARDS_ENABLED, 1);
+ public void getAvailabilityStatus_onlyControlsAvailable_available() {
Settings.Secure.putInt(mContext.getContentResolver(), CARDS_AVAILABLE, 0);
+ mShadowPackageManager.setSystemFeature(CONTROLS_FEATURE, true);
- assertThat(mController.getSummary())
- .isEqualTo(mContext.getText(R.string.power_menu_device_controls));
+ assertThat(mController.getAvailabilityStatus()).isEqualTo(
+ BasePreferenceController.AVAILABLE);
}
@Test
- public void getSummary_controlsEnabled_cardsDisabledAvailable() {
- Settings.Secure.putInt(mContext.getContentResolver(), CONTROLS_ENABLED, 1);
- Settings.Secure.putInt(mContext.getContentResolver(), CARDS_ENABLED, 0);
- Settings.Secure.putInt(mContext.getContentResolver(), CARDS_AVAILABLE, 1);
+ public void getAvailabilityStatus_bothUnavailable_unavailable() {
+ Settings.Secure.putInt(mContext.getContentResolver(), CARDS_AVAILABLE, 0);
+ mShadowPackageManager.setSystemFeature(CONTROLS_FEATURE, false);
- assertThat(mController.getSummary())
- .isEqualTo(mContext.getText(R.string.power_menu_device_controls));
- }
-
- @Test
- public void getSummary_controlsDisabled() {
- Settings.Secure.putInt(mContext.getContentResolver(), CONTROLS_ENABLED, 0);
- Settings.Secure.putInt(mContext.getContentResolver(), CARDS_ENABLED, 1);
- Settings.Secure.putInt(mContext.getContentResolver(), CARDS_AVAILABLE, 1);
-
- assertThat(mController.getSummary())
- .isEqualTo(mContext.getText(R.string.power_menu_cards_passes));
- }
-
- @Test
- public void getSummary_allEnabled() {
- Settings.Secure.putInt(mContext.getContentResolver(), CONTROLS_ENABLED, 1);
- Settings.Secure.putInt(mContext.getContentResolver(), CARDS_ENABLED, 1);
- Settings.Secure.putInt(mContext.getContentResolver(), CARDS_AVAILABLE, 1);
-
- assertThat(mController.getSummary())
- .isEqualTo(mContext.getText(R.string.power_menu_cards_passes_device_controls));
+ assertThat(mController.getAvailabilityStatus()).isEqualTo(
+ BasePreferenceController.CONDITIONALLY_UNAVAILABLE);
}
}
diff --git a/tests/robotests/src/com/android/settings/gestures/PowerMenuPrivacyPreferenceControllerAvailabilityTest.java b/tests/robotests/src/com/android/settings/gestures/PowerMenuPrivacyPreferenceControllerAvailabilityTest.java
new file mode 100644
index 00000000000..40b94ebe33d
--- /dev/null
+++ b/tests/robotests/src/com/android/settings/gestures/PowerMenuPrivacyPreferenceControllerAvailabilityTest.java
@@ -0,0 +1,129 @@
+/*
+ * Copyright (C) 2020 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.gestures;
+
+import static com.google.common.truth.Truth.assertThat;
+
+import static org.mockito.ArgumentMatchers.anyInt;
+import static org.mockito.Mockito.when;
+
+import android.content.ContentResolver;
+import android.content.Context;
+import android.content.pm.PackageManager;
+import android.provider.Settings;
+
+import com.android.internal.widget.LockPatternUtils;
+import com.android.settings.core.BasePreferenceController;
+import com.android.settings.testutils.FakeFeatureFactory;
+
+import org.junit.Before;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.mockito.Mock;
+import org.mockito.MockitoAnnotations;
+import org.robolectric.ParameterizedRobolectricTestRunner;
+import org.robolectric.RuntimeEnvironment;
+import org.robolectric.Shadows;
+import org.robolectric.shadows.ShadowPackageManager;
+
+import java.util.Arrays;
+import java.util.Collection;
+
+@RunWith(ParameterizedRobolectricTestRunner.class)
+public class PowerMenuPrivacyPreferenceControllerAvailabilityTest {
+
+ private static final String CONTROLS_ENABLED = Settings.Secure.CONTROLS_ENABLED;
+ private static final String CONTROLS_FEATURE = PackageManager.FEATURE_CONTROLS;
+ private static final String CARDS_ENABLED = Settings.Secure.GLOBAL_ACTIONS_PANEL_ENABLED;
+ private static final String CARDS_AVAILABLE = Settings.Secure.GLOBAL_ACTIONS_PANEL_AVAILABLE;
+
+ @ParameterizedRobolectricTestRunner.Parameters(
+ name = "ctrls available={0}, ctrls enabled={1}, cards available={2}, cards enabled={3}")
+ public static Collection data() {
+ return Arrays.asList(new Object[][]{
+ // controls available, controls enabled, cards available, cards enabled, available
+ {false, false, false, false, BasePreferenceController.DISABLED_DEPENDENT_SETTING},
+ {false, false, false, true, BasePreferenceController.DISABLED_DEPENDENT_SETTING},
+ {false, false, true, false, BasePreferenceController.DISABLED_DEPENDENT_SETTING},
+ {false, false, true, true, BasePreferenceController.AVAILABLE},
+ {false, true, false, false, BasePreferenceController.DISABLED_DEPENDENT_SETTING},
+ {false, true, false, true, BasePreferenceController.DISABLED_DEPENDENT_SETTING},
+ {false, true, true, false, BasePreferenceController.DISABLED_DEPENDENT_SETTING},
+ {false, true, true, true, BasePreferenceController.AVAILABLE},
+ {true, false, false, false, BasePreferenceController.DISABLED_DEPENDENT_SETTING},
+ {true, false, false, true, BasePreferenceController.DISABLED_DEPENDENT_SETTING},
+ {true, false, true, false, BasePreferenceController.DISABLED_DEPENDENT_SETTING},
+ {true, false, true, true, BasePreferenceController.AVAILABLE},
+ {true, true, false, false, BasePreferenceController.AVAILABLE},
+ {true, true, false, true, BasePreferenceController.AVAILABLE},
+ {true, true, true, false, BasePreferenceController.AVAILABLE},
+ {true, true, true, true, BasePreferenceController.AVAILABLE}
+ });
+ }
+
+ private Context mContext;
+ private PowerMenuPrivacyPreferenceController mController;
+ private ShadowPackageManager mShadowPackageManager;
+
+ @Mock
+ private LockPatternUtils mLockPatternUtils;
+
+ private boolean mControlsAvailable;
+ private boolean mControlsEnabled;
+ private boolean mCardsAvailable;
+ private boolean mCardsEnabled;
+ private int mAvailable;
+
+ public PowerMenuPrivacyPreferenceControllerAvailabilityTest(
+ boolean controlsAvailable,
+ boolean controlsEnabled,
+ boolean cardsAvailable,
+ boolean cardsEnabled,
+ int available) {
+ mControlsAvailable = controlsAvailable;
+ mControlsEnabled = controlsEnabled;
+ mCardsAvailable = cardsAvailable;
+ mCardsEnabled = cardsEnabled;
+ mAvailable = available;
+ }
+
+ @Before
+ public void setUp() {
+ MockitoAnnotations.initMocks(this);
+ mContext = RuntimeEnvironment.application;
+ mShadowPackageManager = Shadows.shadowOf(mContext.getPackageManager());
+ FakeFeatureFactory featureFactory = FakeFeatureFactory.setupForTest();
+
+ // For these tests we assume the device has a secure lock.
+ when(featureFactory.securityFeatureProvider.getLockPatternUtils(mContext))
+ .thenReturn(mLockPatternUtils);
+ when(mLockPatternUtils.isSecure(anyInt())).thenReturn(true);
+
+ mController = new PowerMenuPrivacyPreferenceController(mContext, "TEST_KEY");
+ }
+
+ @Test
+ public void getAvailabilityStatus_possiblyAvailableAndEnabled() {
+ mShadowPackageManager.setSystemFeature(CONTROLS_FEATURE, mControlsAvailable);
+ ContentResolver cr = mContext.getContentResolver();
+ Settings.Secure.putInt(cr, CONTROLS_ENABLED, mControlsEnabled ? 1 : 0);
+ Settings.Secure.putInt(cr, CARDS_AVAILABLE, mCardsAvailable ? 1 : 0);
+ Settings.Secure.putInt(cr, CARDS_ENABLED, mCardsEnabled ? 1 : 0);
+
+ assertThat(mController.getAvailabilityStatus()).isEqualTo(mAvailable);
+ }
+}
diff --git a/tests/robotests/src/com/android/settings/gestures/PowerMenuPrivacyPreferenceControllerTest.java b/tests/robotests/src/com/android/settings/gestures/PowerMenuPrivacyPreferenceControllerTest.java
index 32048a157d8..994a3eece31 100644
--- a/tests/robotests/src/com/android/settings/gestures/PowerMenuPrivacyPreferenceControllerTest.java
+++ b/tests/robotests/src/com/android/settings/gestures/PowerMenuPrivacyPreferenceControllerTest.java
@@ -26,6 +26,7 @@ import static org.mockito.Mockito.when;
import android.content.ContentResolver;
import android.content.Context;
+import android.content.pm.PackageManager;
import android.provider.Settings;
import androidx.preference.Preference;
@@ -42,6 +43,8 @@ import org.mockito.Mock;
import org.mockito.MockitoAnnotations;
import org.robolectric.RobolectricTestRunner;
import org.robolectric.RuntimeEnvironment;
+import org.robolectric.Shadows;
+import org.robolectric.shadows.ShadowPackageManager;
@RunWith(RobolectricTestRunner.class)
public class PowerMenuPrivacyPreferenceControllerTest {
@@ -55,6 +58,7 @@ public class PowerMenuPrivacyPreferenceControllerTest {
private Context mContext;
private ContentResolver mContentResolver;
+ private ShadowPackageManager mShadowPackageManager;
private PowerMenuPrivacyPreferenceController mController;
@Mock
@@ -66,6 +70,8 @@ public class PowerMenuPrivacyPreferenceControllerTest {
public void setUp() {
MockitoAnnotations.initMocks(this);
mContext = RuntimeEnvironment.application;
+ mShadowPackageManager = Shadows.shadowOf(mContext.getPackageManager());
+
mContentResolver = mContext.getContentResolver();
FakeFeatureFactory featureFactory = FakeFeatureFactory.setupForTest();
when(featureFactory.securityFeatureProvider.getLockPatternUtils(mContext))
@@ -119,82 +125,50 @@ public class PowerMenuPrivacyPreferenceControllerTest {
}
@Test
- public void getSummary_cardsAvailable_isPower_menu_privacy_showString() {
+ public void getSummary_cardsControlsAvailable_isPower_menu_privacy_showString() {
Settings.Secure.putInt(mContentResolver, CARDS_AVAILABLE_KEY, 1);
+ mShadowPackageManager.setSystemFeature(PackageManager.FEATURE_CONTROLS, true);
assertThat(mController.getSummary()).isEqualTo(
mContext.getText(R.string.power_menu_privacy_show));
}
@Test
- public void getSummary_cardsUnavailable_isPower_menu_privacy_show_controlsString() {
+ public void
+ getSummary_cardsUnavailableControlsAvailable_isPower_menu_privacy_show_controlsString() {
Settings.Secure.putInt(mContentResolver, CARDS_AVAILABLE_KEY, 0);
+ mShadowPackageManager.setSystemFeature(PackageManager.FEATURE_CONTROLS, true);
assertThat(mController.getSummary()).isEqualTo(
mContext.getText(R.string.power_menu_privacy_show_controls));
}
+ @Test
+ public void
+ getSummary_cardsAvailableControlsUnavailable_isPower_menu_privacy_show_cardsString() {
+ Settings.Secure.putInt(mContentResolver, CARDS_AVAILABLE_KEY, 1);
+ mShadowPackageManager.setSystemFeature(PackageManager.FEATURE_CONTROLS, false);
+
+ assertThat(mController.getSummary()).isEqualTo(
+ mContext.getText(R.string.power_menu_privacy_show_cards));
+ }
+
@Test
public void updateState_onPreferenceRefreshed_preferenceEnabledAndSummaryChanged() {
+ mShadowPackageManager.setSystemFeature(PackageManager.FEATURE_CONTROLS, true);
+ Settings.Secure.putInt(mContentResolver, CARDS_AVAILABLE_KEY, 1);
+
mController.updateState(mPreference);
verify(mPreference).setEnabled(anyBoolean());
verify(mPreference, atLeastOnce()).setSummary(mController.getSummary());
}
- @Test
- public void getAvailabilityStatus_allOff_returnsDisabled() {
- Settings.Secure.putInt(mContentResolver, CARDS_AVAILABLE_KEY, 1);
- Settings.Secure.putInt(mContentResolver, CARDS_ENABLED_KEY, 0);
- Settings.Secure.putInt(mContentResolver, CONTROLS_ENABLED_KEY, 0);
-
- assertThat(mController.getAvailabilityStatus()).isEqualTo(
- BasePreferenceController.DISABLED_DEPENDENT_SETTING);
- }
-
- @Test
- public void getAvailabilityStatus_cardsUnavailableControlsOff_returnsDisabled() {
- Settings.Secure.putInt(mContentResolver, CARDS_AVAILABLE_KEY, 0);
- Settings.Secure.putInt(mContentResolver, CONTROLS_ENABLED_KEY, 0);
-
- assertThat(mController.getAvailabilityStatus()).isEqualTo(
- BasePreferenceController.DISABLED_DEPENDENT_SETTING);
- }
-
- @Test
- public void testAvailabilityStatus_cardsOnControlsOff_returnsAvailable() {
- Settings.Secure.putInt(mContentResolver, CARDS_AVAILABLE_KEY, 1);
- Settings.Secure.putInt(mContentResolver, CARDS_ENABLED_KEY, 1);
- Settings.Secure.putInt(mContentResolver, CONTROLS_ENABLED_KEY, 0);
-
- assertThat(mController.getAvailabilityStatus()).isEqualTo(
- BasePreferenceController.AVAILABLE);
- }
-
- @Test
- public void getAvailabilityStatus_cardsOffControlsOn_returnsAvailable() {
- Settings.Secure.putInt(mContentResolver, CARDS_AVAILABLE_KEY, 1);
- Settings.Secure.putInt(mContentResolver, CARDS_ENABLED_KEY, 0);
- Settings.Secure.putInt(mContentResolver, CONTROLS_ENABLED_KEY, 1);
-
- assertThat(mController.getAvailabilityStatus()).isEqualTo(
- BasePreferenceController.AVAILABLE);
- }
-
- @Test
- public void getAvailabilityStatus_allOn_returnsAvailable() {
- Settings.Secure.putInt(mContentResolver, CARDS_AVAILABLE_KEY, 1);
- Settings.Secure.putInt(mContentResolver, CARDS_ENABLED_KEY, 1);
- Settings.Secure.putInt(mContentResolver, CONTROLS_ENABLED_KEY, 1);
-
- assertThat(mController.getAvailabilityStatus()).isEqualTo(
- BasePreferenceController.AVAILABLE);
- }
-
@Test
public void getAvailabilityStatus_allOnNotSecure_returnsDisabled() {
when(mLockPatternUtils.isSecure(anyInt())).thenReturn(false);
+ mShadowPackageManager.setSystemFeature(PackageManager.FEATURE_CONTROLS, true);
Settings.Secure.putInt(mContentResolver, CARDS_AVAILABLE_KEY, 1);
Settings.Secure.putInt(mContentResolver, CARDS_ENABLED_KEY, 1);
Settings.Secure.putInt(mContentResolver, CONTROLS_ENABLED_KEY, 1);
@@ -205,9 +179,8 @@ public class PowerMenuPrivacyPreferenceControllerTest {
@Test
public void getAvailabilityStatus_controlsDeletedSecure_retursAvailable() {
- when(mLockPatternUtils.isSecure(anyInt())).thenReturn(true);
-
Settings.Secure.putString(mContentResolver, CONTROLS_ENABLED_KEY, null);
+ mShadowPackageManager.setSystemFeature(PackageManager.FEATURE_CONTROLS, true);
assertThat(mController.getAvailabilityStatus()).isEqualTo(
BasePreferenceController.AVAILABLE);