Loading res/values/strings.xml +3 −0 Original line number Diff line number Diff line Loading @@ -12046,6 +12046,9 @@ <!-- Power menu setting privacy show controls [CHAR LIMIT=NONE] --> <string name="power_menu_privacy_show_controls">Show controls when locked</string> <!-- Power menu setting privacy show cards [CHAR LIMIT=NONE] --> <string name="power_menu_privacy_show_cards">Show cards when locked</string> <!-- Power menu setting privacy hide all [CHAR LIMIT=NONE] --> <string name="power_menu_privacy_hide">Hide cards and controls when locked</string> src/com/android/settings/gestures/DeviceControlsPreferenceController.java +4 −1 Original line number Diff line number Diff line Loading @@ -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; Loading @@ -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 Loading src/com/android/settings/gestures/PowerMenuPreferenceController.java +19 −9 Original line number Diff line number Diff line Loading @@ -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; Loading @@ -37,15 +38,15 @@ public class PowerMenuPreferenceController extends BasePreferenceController { @Override public CharSequence getSummary() { boolean controlsEnabled = Settings.Secure.getInt(mContext.getContentResolver(), boolean controlsVisible = isControlsAvailable() && Settings.Secure.getInt(mContext.getContentResolver(), CONTROLS_ENABLED_SETTING, 1) == 1; boolean cardsEnabled = Settings.Secure.getInt(mContext.getContentResolver(), boolean cardsVisible = isCardsAvailable() && 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) { 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); Loading @@ -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; } } src/com/android/settings/gestures/PowerMenuPrivacyPreferenceController.java +15 −3 Original line number Diff line number Diff line Loading @@ -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; Loading Loading @@ -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); } Loading @@ -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() { Loading @@ -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); } } tests/robotests/src/com/android/settings/gestures/DeviceControlsPreferenceControllerTest.java +16 −1 Original line number Diff line number Diff line Loading @@ -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; Loading @@ -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 = Loading @@ -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); } Loading @@ -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 = Loading Loading
res/values/strings.xml +3 −0 Original line number Diff line number Diff line Loading @@ -12046,6 +12046,9 @@ <!-- Power menu setting privacy show controls [CHAR LIMIT=NONE] --> <string name="power_menu_privacy_show_controls">Show controls when locked</string> <!-- Power menu setting privacy show cards [CHAR LIMIT=NONE] --> <string name="power_menu_privacy_show_cards">Show cards when locked</string> <!-- Power menu setting privacy hide all [CHAR LIMIT=NONE] --> <string name="power_menu_privacy_hide">Hide cards and controls when locked</string>
src/com/android/settings/gestures/DeviceControlsPreferenceController.java +4 −1 Original line number Diff line number Diff line Loading @@ -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; Loading @@ -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 Loading
src/com/android/settings/gestures/PowerMenuPreferenceController.java +19 −9 Original line number Diff line number Diff line Loading @@ -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; Loading @@ -37,15 +38,15 @@ public class PowerMenuPreferenceController extends BasePreferenceController { @Override public CharSequence getSummary() { boolean controlsEnabled = Settings.Secure.getInt(mContext.getContentResolver(), boolean controlsVisible = isControlsAvailable() && Settings.Secure.getInt(mContext.getContentResolver(), CONTROLS_ENABLED_SETTING, 1) == 1; boolean cardsEnabled = Settings.Secure.getInt(mContext.getContentResolver(), boolean cardsVisible = isCardsAvailable() && 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) { 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); Loading @@ -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; } }
src/com/android/settings/gestures/PowerMenuPrivacyPreferenceController.java +15 −3 Original line number Diff line number Diff line Loading @@ -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; Loading Loading @@ -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); } Loading @@ -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() { Loading @@ -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); } }
tests/robotests/src/com/android/settings/gestures/DeviceControlsPreferenceControllerTest.java +16 −1 Original line number Diff line number Diff line Loading @@ -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; Loading @@ -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 = Loading @@ -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); } Loading @@ -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 = Loading