Merge "Wallet/controls - Migrate existing settings" into sc-dev
This commit is contained in:
committed by
Android (Google) Code Review
commit
db624992ed
@@ -3684,17 +3684,6 @@
|
||||
android:value="com.android.settings.fuelgauge.batterysaver.BatterySaverScheduleSettings" />
|
||||
</activity>
|
||||
|
||||
<activity android:name="Settings$GlobalActionsPanelSettingsActivity"
|
||||
android:exported="true"
|
||||
android:label="@string/cards_passes_sentence">
|
||||
<intent-filter>
|
||||
<action android:name="com.android.settings.GLOBAL_ACTIONS_PANEL_SETTINGS" />
|
||||
<category android:name="android.intent.category.DEFAULT" />
|
||||
</intent-filter>
|
||||
<meta-data android:name="com.android.settings.FRAGMENT_CLASS"
|
||||
android:value="com.android.settings.gestures.GlobalActionsPanelSettings" />
|
||||
</activity>
|
||||
|
||||
<activity android:name="Settings$PowerMenuSettingsActivity"
|
||||
android:exported="true"
|
||||
android:label="@string/power_menu_setting_name">
|
||||
|
@@ -8079,8 +8079,7 @@
|
||||
<string name="keywords_profile_challenge">work challenge, work, profile</string>
|
||||
<string name="keywords_unification">work profile, managed profile, unify, unification, work, profile</string>
|
||||
<string name="keywords_gesture">gestures</string>
|
||||
<string name="keywords_cards_passes">cards, passes</string>
|
||||
<string name="keywords_device_controls">device controls, controls</string>
|
||||
<string name="keywords_wallet">wallet</string>
|
||||
<string name="keywords_payment_settings">pay, tap, payments</string>
|
||||
<string name="keywords_backup">backup, back up</string>
|
||||
<string name="keywords_assist_gesture_launch">gesture</string>
|
||||
@@ -12969,32 +12968,11 @@
|
||||
<!-- Power menu setting title [CHAR LIMIT=NONE] -->
|
||||
<string name="power_menu_setting_title">Power button menu</string>
|
||||
|
||||
<!-- Power menu setting option cards and passes [CHAR LIMIT=NONE] -->
|
||||
<string name="power_menu_cards_passes">Show cards & passes</string>
|
||||
|
||||
<!-- Power menu setting lock screen category name [CHAR LIMIT=40] -->
|
||||
<string name="power_menu_lock_screen_category">Lock screen</string>
|
||||
|
||||
<!-- Power menu setting option none [CHAR LIMIT=NONE] -->
|
||||
<string name="power_menu_none">Don\u2019t show any content</string>
|
||||
|
||||
<!-- Power menu setting Privacy [CHAR LIMIT=40] -->
|
||||
<string name="power_menu_privacy">Sensitive content</string>
|
||||
|
||||
<!-- Power menu setting privacy show all [CHAR LIMIT=NONE] -->
|
||||
<string name="power_menu_privacy_show">Show cards and controls when locked</string>
|
||||
|
||||
<!-- 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>
|
||||
|
||||
<!-- Power menu setting privacy no secure screen lock set [CHAR_LIMIT=NONE] -->
|
||||
<string name="power_menu_privacy_not_secure">To use, first set a screen lock</string>
|
||||
<string name="lockscreen_privacy_not_secure">To use, first set a screen lock</string>
|
||||
|
||||
<!-- Power menu setting use long press power to invoke assistant. [CHAR_LIMIT=NONE] -->
|
||||
<string name="power_menu_long_press_for_assist">Hold for Assistant</string>
|
||||
@@ -13002,17 +12980,15 @@
|
||||
<!-- Power menu setting use log press power to invoke assistant summary. [CHAR_LIMIT=NONE] -->
|
||||
<string name="power_menu_long_press_for_assist_summary">Trigger the Assistant by holding the power button</string>
|
||||
|
||||
<!-- Wallet (formerly Cards and passes) toggle name [CHAR LIMIT=60] -->
|
||||
<string name="lockscreen_privacy_wallet_setting_toggle">Show wallet</string>
|
||||
<!-- Wallet (formerly Cards and passes) summary [CHAR LIMIT=NONE] -->
|
||||
<string name="lockscreen_privacy_wallet_summary">Allow access to wallet from lock screen and quick settings</string>
|
||||
|
||||
<!-- Device controls toggle name [CHAR LIMIT=60] -->
|
||||
<string name="device_controls_setting_toggle">Show device controls</string>
|
||||
|
||||
<!-- Cards and passes toggle name [CHAR LIMIT=60] -->
|
||||
<string name="cards_passes_setting_toggle">Show cards & passes</string>
|
||||
|
||||
<!-- Device controls toggle subtitle [CHAR LIMIT=NONE] -->
|
||||
<string name="device_controls_setting_subtitle">To access controls for connected devices, hold the Power button</string>
|
||||
|
||||
<!-- Cards and passes toggle subtitle [CHAR LIMIT=NONE] -->
|
||||
<string name="cards_passes_setting_subtitle">To access things like your payment methods and boarding passes, press and hold the Power button.</string>
|
||||
<string name="lockscreen_privacy_controls_setting_toggle">Show device controls</string>
|
||||
<!-- Device controls summary [CHAR LIMIT=NONE] -->
|
||||
<string name="lockscreen_privacy_controls_summary">Access controls when locked</string>
|
||||
|
||||
<!-- Title for RTT setting. [CHAR LIMIT=NONE] -->
|
||||
<string name="rtt_settings_title"></string>
|
||||
|
@@ -1,36 +0,0 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<!--
|
||||
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.
|
||||
-->
|
||||
|
||||
<PreferenceScreen
|
||||
xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:app="http://schemas.android.com/apk/res-auto"
|
||||
android:title="@string/cards_passes_sentence">
|
||||
|
||||
<com.android.settings.widget.VideoPreference
|
||||
android:key="global_actions_panel_video"
|
||||
app:animation="@raw/gesture_global_actions_panel"
|
||||
app:controller="com.android.settings.widget.VideoPreferenceController" />
|
||||
|
||||
<SwitchPreference
|
||||
android:key="gesture_global_actions_panel_switch"
|
||||
android:title="@string/cards_passes_setting_toggle"
|
||||
android:summary="@string/cards_passes_setting_subtitle"
|
||||
app:keywords="@string/keywords_cards_passes"
|
||||
app:controller="com.android.settings.gestures.GlobalActionsPanelPreferenceController"
|
||||
app:allowDividerAbove="true" />
|
||||
|
||||
</PreferenceScreen>
|
@@ -26,19 +26,4 @@
|
||||
android:summary="@string/power_menu_long_press_for_assist_summary"
|
||||
settings:controller="com.android.settings.gestures.LongPressPowerButtonPreferenceController"
|
||||
/>
|
||||
|
||||
<Preference
|
||||
android:key="gesture_global_actions_panel_summary"
|
||||
android:title="@string/cards_passes_sentence"
|
||||
android:fragment="com.android.settings.gestures.GlobalActionsPanelSettings"
|
||||
settings:controller="com.android.settings.gestures.GlobalActionsPanelPreferenceController" />
|
||||
|
||||
<PreferenceCategory
|
||||
android:title="@string/power_menu_lock_screen_category" >
|
||||
|
||||
<SwitchPreference
|
||||
android:key="gesture_power_menu_privacy"
|
||||
android:title="@string/power_menu_privacy"
|
||||
settings:controller="com.android.settings.gestures.PowerMenuPrivacyPreferenceController" />
|
||||
</PreferenceCategory>
|
||||
</PreferenceScreen>
|
||||
|
@@ -46,11 +46,16 @@
|
||||
android:summary="@string/owner_info_settings_summary" />
|
||||
|
||||
<SwitchPreference
|
||||
android:key="security_setting_lockdown_enabled"
|
||||
android:title="@string/lockdown_settings_title"
|
||||
android:summary="@string/lockdown_settings_summary"
|
||||
settings:controller="com.android.settings.security.LockdownButtonPreferenceController" />
|
||||
android:key="lockscreen_privacy_wallet_switch"
|
||||
android:title="@string/lockscreen_privacy_wallet_setting_toggle"
|
||||
android:summary="@string/lockscreen_privacy_wallet_summary"
|
||||
settings:controller="com.android.settings.display.WalletPrivacyPreferenceController" />
|
||||
|
||||
<SwitchPreference
|
||||
android:key="lockscreen_privacy_controls_switch"
|
||||
android:title="@string/lockscreen_privacy_controls_setting_toggle"
|
||||
android:summary="@string/lockscreen_privacy_controls_summary"
|
||||
settings:controller="com.android.settings.display.ControlsPrivacyPreferenceController" />
|
||||
</PreferenceCategory>
|
||||
|
||||
<PreferenceCategory
|
||||
|
@@ -295,9 +295,7 @@ public class Settings extends SettingsActivity {
|
||||
public static class BluetoothDeviceDetailActivity extends SettingsActivity { /* empty */ }
|
||||
public static class WifiCallingDisclaimerActivity extends SettingsActivity { /* empty */ }
|
||||
public static class MobileNetworkListActivity extends SettingsActivity {}
|
||||
public static class GlobalActionsPanelSettingsActivity extends SettingsActivity {}
|
||||
public static class PowerMenuSettingsActivity extends SettingsActivity {}
|
||||
public static class DeviceControlsSettingsActivity extends SettingsActivity {}
|
||||
/**
|
||||
* Activity for BugReportHandlerPicker.
|
||||
*/
|
||||
|
@@ -99,7 +99,6 @@ import com.android.settings.gestures.DoubleTapPowerSettings;
|
||||
import com.android.settings.gestures.DoubleTapScreenSettings;
|
||||
import com.android.settings.gestures.DoubleTwistGestureSettings;
|
||||
import com.android.settings.gestures.GestureNavigationSettingsFragment;
|
||||
import com.android.settings.gestures.GlobalActionsPanelSettings;
|
||||
import com.android.settings.gestures.PickupGestureSettings;
|
||||
import com.android.settings.gestures.PowerMenuSettings;
|
||||
import com.android.settings.gestures.SwipeToNotificationSettings;
|
||||
@@ -308,7 +307,6 @@ public class SettingsGateway {
|
||||
BatterySaverScheduleSettings.class.getName(),
|
||||
MobileNetworkListFragment.class.getName(),
|
||||
PowerMenuSettings.class.getName(),
|
||||
GlobalActionsPanelSettings.class.getName(),
|
||||
DarkModeSettingsFragment.class.getName(),
|
||||
BugReportHandlerPicker.class.getName(),
|
||||
GestureNavigationSettingsFragment.class.getName(),
|
||||
|
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (C) 2020 The Android Open Source Project
|
||||
* Copyright (C) 2021 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.
|
||||
@@ -14,9 +14,8 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package com.android.settings.gestures;
|
||||
package com.android.settings.display;
|
||||
|
||||
import android.content.ContentResolver;
|
||||
import android.content.Context;
|
||||
import android.content.pm.PackageManager;
|
||||
import android.os.UserHandle;
|
||||
@@ -29,16 +28,14 @@ import com.android.settings.R;
|
||||
import com.android.settings.core.TogglePreferenceController;
|
||||
import com.android.settings.overlay.FeatureFactory;
|
||||
|
||||
public class PowerMenuPrivacyPreferenceController extends TogglePreferenceController {
|
||||
/**
|
||||
* Preference for showing/hiding sensitive device controls content while the device is locked.
|
||||
*/
|
||||
public class ControlsPrivacyPreferenceController extends TogglePreferenceController {
|
||||
|
||||
private static final String SETTING_KEY = Settings.Secure.POWER_MENU_LOCKED_SHOW_CONTENT;
|
||||
private static final String CARDS_AVAILABLE_KEY =
|
||||
Settings.Secure.GLOBAL_ACTIONS_PANEL_AVAILABLE;
|
||||
private static final String CARDS_ENABLED_KEY = Settings.Secure.GLOBAL_ACTIONS_PANEL_ENABLED;
|
||||
private static final String SETTING_KEY = "lockscreen_show_controls";
|
||||
|
||||
|
||||
public PowerMenuPrivacyPreferenceController(Context context,
|
||||
String preferenceKey) {
|
||||
public ControlsPrivacyPreferenceController(Context context, String preferenceKey) {
|
||||
super(context, preferenceKey);
|
||||
}
|
||||
|
||||
@@ -55,22 +52,12 @@ public class PowerMenuPrivacyPreferenceController extends TogglePreferenceContro
|
||||
|
||||
@Override
|
||||
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 && controlsAvailable) {
|
||||
res = R.string.power_menu_privacy_show;
|
||||
} else if (!cardsAvailable && controlsAvailable) {
|
||||
res = R.string.power_menu_privacy_show_controls;
|
||||
} else if (cardsAvailable) {
|
||||
res = R.string.power_menu_privacy_show_cards;
|
||||
res = R.string.lockscreen_privacy_not_secure;
|
||||
} 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 "";
|
||||
res = R.string.lockscreen_privacy_controls_summary;
|
||||
}
|
||||
return mContext.getText(res);
|
||||
}
|
||||
@@ -78,7 +65,6 @@ public class PowerMenuPrivacyPreferenceController extends TogglePreferenceContro
|
||||
@Override
|
||||
public int getAvailabilityStatus() {
|
||||
// hide if lockscreen isn't secure for this user
|
||||
|
||||
return isEnabled() && isSecure() ? AVAILABLE : DISABLED_DEPENDENT_SETTING;
|
||||
}
|
||||
|
||||
@@ -90,10 +76,7 @@ public class PowerMenuPrivacyPreferenceController extends TogglePreferenceContro
|
||||
}
|
||||
|
||||
private boolean isEnabled() {
|
||||
final ContentResolver resolver = mContext.getContentResolver();
|
||||
boolean cardsAvailable = Settings.Secure.getInt(resolver, CARDS_AVAILABLE_KEY, 0) != 0;
|
||||
boolean cardsEnabled = Settings.Secure.getInt(resolver, CARDS_ENABLED_KEY, 0) != 0;
|
||||
return (cardsAvailable && cardsEnabled) || isControlsAvailable();
|
||||
return isControlsAvailable();
|
||||
}
|
||||
|
||||
private boolean isSecure() {
|
@@ -0,0 +1,95 @@
|
||||
/*
|
||||
* Copyright (C) 2021 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.display;
|
||||
|
||||
import android.content.Context;
|
||||
import android.os.UserHandle;
|
||||
import android.provider.Settings;
|
||||
import android.service.quickaccesswallet.QuickAccessWalletClient;
|
||||
|
||||
import androidx.annotation.VisibleForTesting;
|
||||
import androidx.preference.Preference;
|
||||
|
||||
import com.android.internal.widget.LockPatternUtils;
|
||||
import com.android.settings.R;
|
||||
import com.android.settings.core.TogglePreferenceController;
|
||||
import com.android.settings.overlay.FeatureFactory;
|
||||
|
||||
/**
|
||||
* Preference for showing/hiding sensitive wallet content while the device is locked.
|
||||
*/
|
||||
public class WalletPrivacyPreferenceController extends TogglePreferenceController {
|
||||
|
||||
private static final String SETTING_KEY = "lockscreen_show_wallet";
|
||||
private final QuickAccessWalletClient mClient;
|
||||
|
||||
public WalletPrivacyPreferenceController(Context context, String preferenceKey) {
|
||||
super(context, preferenceKey);
|
||||
mClient = initWalletClient();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isChecked() {
|
||||
return Settings.Secure.getInt(mContext.getContentResolver(), SETTING_KEY, 0) != 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean setChecked(boolean isChecked) {
|
||||
return Settings.Secure.putInt(mContext.getContentResolver(), SETTING_KEY,
|
||||
isChecked ? 1 : 0);
|
||||
}
|
||||
|
||||
@Override
|
||||
public CharSequence getSummary() {
|
||||
final int res;
|
||||
if (!isSecure()) {
|
||||
res = R.string.lockscreen_privacy_not_secure;
|
||||
} else {
|
||||
res = R.string.lockscreen_privacy_wallet_summary;
|
||||
}
|
||||
return mContext.getText(res);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getAvailabilityStatus() {
|
||||
return isEnabled() && isSecure() ? AVAILABLE : DISABLED_DEPENDENT_SETTING;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void updateState(Preference preference) {
|
||||
super.updateState(preference);
|
||||
preference.setEnabled(getAvailabilityStatus() != DISABLED_DEPENDENT_SETTING);
|
||||
refreshSummary(preference);
|
||||
}
|
||||
|
||||
private boolean isEnabled() {
|
||||
return mClient.isWalletServiceAvailable();
|
||||
}
|
||||
|
||||
private boolean isSecure() {
|
||||
final LockPatternUtils utils = FeatureFactory.getFactory(mContext)
|
||||
.getSecurityFeatureProvider()
|
||||
.getLockPatternUtils(mContext);
|
||||
int userId = UserHandle.myUserId();
|
||||
return utils.isSecure(userId);
|
||||
}
|
||||
|
||||
@VisibleForTesting
|
||||
QuickAccessWalletClient initWalletClient() {
|
||||
return QuickAccessWalletClient.create(mContext);
|
||||
}
|
||||
}
|
@@ -1,48 +0,0 @@
|
||||
/*
|
||||
* 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.gestures;
|
||||
|
||||
import android.app.settings.SettingsEnums;
|
||||
|
||||
import com.android.settings.R;
|
||||
import com.android.settings.dashboard.DashboardFragment;
|
||||
import com.android.settings.search.BaseSearchIndexProvider;
|
||||
import com.android.settingslib.search.SearchIndexable;
|
||||
|
||||
@SearchIndexable
|
||||
public class GlobalActionsPanelSettings extends DashboardFragment {
|
||||
|
||||
private static final String TAG = "GlobalActionsPanelSettings";
|
||||
|
||||
@Override
|
||||
public int getMetricsCategory() {
|
||||
return SettingsEnums.GLOBAL_ACTIONS_PANEL_SETTINGS;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected String getLogTag() {
|
||||
return TAG;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected int getPreferenceScreenResId() {
|
||||
return R.xml.global_actions_panel_settings;
|
||||
}
|
||||
|
||||
public static final BaseSearchIndexProvider SEARCH_INDEX_DATA_PROVIDER =
|
||||
new BaseSearchIndexProvider(R.xml.global_actions_panel_settings);
|
||||
}
|
@@ -17,44 +17,24 @@
|
||||
package com.android.settings.gestures;
|
||||
|
||||
import android.content.Context;
|
||||
import android.provider.Settings;
|
||||
|
||||
import com.android.settings.R;
|
||||
import com.android.settings.core.BasePreferenceController;
|
||||
|
||||
public class PowerMenuPreferenceController extends BasePreferenceController {
|
||||
|
||||
private static final String KEY = "gesture_power_menu_summary";
|
||||
private static final String CARDS_ENABLED_SETTING =
|
||||
Settings.Secure.GLOBAL_ACTIONS_PANEL_ENABLED;
|
||||
private static final String CARDS_AVAILABLE_SETTING =
|
||||
Settings.Secure.GLOBAL_ACTIONS_PANEL_AVAILABLE;
|
||||
|
||||
public PowerMenuPreferenceController(Context context, String key) {
|
||||
super(context, key);
|
||||
}
|
||||
|
||||
@Override
|
||||
public CharSequence getSummary() {
|
||||
boolean cardsVisible = isCardsAvailable()
|
||||
&& Settings.Secure.getInt(mContext.getContentResolver(),
|
||||
CARDS_ENABLED_SETTING, 0) == 1;
|
||||
if (cardsVisible) {
|
||||
return mContext.getText(R.string.power_menu_cards_passes);
|
||||
} else {
|
||||
return mContext.getText(R.string.power_menu_none);
|
||||
}
|
||||
return mContext.getText(R.string.power_menu_long_press_for_assist);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getAvailabilityStatus() {
|
||||
return isCardsAvailable() || isAssistInvocationAvailable()
|
||||
? AVAILABLE : CONDITIONALLY_UNAVAILABLE;
|
||||
}
|
||||
|
||||
private boolean isCardsAvailable() {
|
||||
return Settings.Secure.getInt(mContext.getContentResolver(),
|
||||
CARDS_AVAILABLE_SETTING, 0) == 1;
|
||||
return isAssistInvocationAvailable() ? AVAILABLE : CONDITIONALLY_UNAVAILABLE;
|
||||
}
|
||||
|
||||
private boolean isAssistInvocationAvailable() {
|
||||
|
@@ -14,7 +14,7 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package com.android.settings.gestures;
|
||||
package com.android.settings.display;
|
||||
|
||||
import static com.google.common.truth.Truth.assertThat;
|
||||
|
||||
@@ -47,18 +47,15 @@ import org.robolectric.Shadows;
|
||||
import org.robolectric.shadows.ShadowPackageManager;
|
||||
|
||||
@RunWith(RobolectricTestRunner.class)
|
||||
public class PowerMenuPrivacyPreferenceControllerTest {
|
||||
public class ControlsPrivacyPreferenceControllerTest {
|
||||
|
||||
private static final String TEST_KEY = "test_key";
|
||||
private static final String SETTING_KEY = Settings.Secure.POWER_MENU_LOCKED_SHOW_CONTENT;
|
||||
private static final String CARDS_AVAILABLE_KEY =
|
||||
Settings.Secure.GLOBAL_ACTIONS_PANEL_AVAILABLE;
|
||||
private static final String CARDS_ENABLED_KEY = Settings.Secure.GLOBAL_ACTIONS_PANEL_ENABLED;
|
||||
private static final String SETTING_KEY = "lockscreen_show_controls";
|
||||
|
||||
private Context mContext;
|
||||
private ContentResolver mContentResolver;
|
||||
private ShadowPackageManager mShadowPackageManager;
|
||||
private PowerMenuPrivacyPreferenceController mController;
|
||||
private ControlsPrivacyPreferenceController mController;
|
||||
|
||||
@Mock
|
||||
private Preference mPreference;
|
||||
@@ -77,85 +74,63 @@ public class PowerMenuPrivacyPreferenceControllerTest {
|
||||
.thenReturn(mLockPatternUtils);
|
||||
when(mLockPatternUtils.isSecure(anyInt())).thenReturn(true);
|
||||
|
||||
mController = new PowerMenuPrivacyPreferenceController(mContext, TEST_KEY);
|
||||
mController = new ControlsPrivacyPreferenceController(mContext, TEST_KEY);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void isChecked_POWER_MENU_LOCKED_SHOW_CONTENTIs1_returnTrue() {
|
||||
public void isChecked_SettingIs1_returnTrue() {
|
||||
Settings.Secure.putInt(mContentResolver, SETTING_KEY, 1);
|
||||
|
||||
assertThat(mController.isChecked()).isTrue();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void isChecked_POWER_MENU_LOCKED_SHOW_CONTENTIs0_returnFalse() {
|
||||
public void isChecked_SettingIs0_returnFalse() {
|
||||
Settings.Secure.putInt(mContentResolver, SETTING_KEY, 0);
|
||||
|
||||
assertThat(mController.isChecked()).isFalse();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void isChecked_POWER_MENU_LOCKED_SHOW_CONTENTIsNotSet_returnFalse() {
|
||||
public void isChecked_SettingIsNotSet_returnFalse() {
|
||||
Settings.Secure.putString(mContentResolver, SETTING_KEY, null);
|
||||
|
||||
assertThat(mController.isChecked()).isFalse();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void setChecked_true_POWER_MENU_LOCKED_SHOW_CONTENTIsNot0() {
|
||||
public void setChecked_true_SettingIsNot0() {
|
||||
mController.setChecked(true);
|
||||
|
||||
assertThat(Settings.Secure.getInt(mContentResolver, SETTING_KEY, 0)).isNotEqualTo(0);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void setChecked_false_POWER_MENU_LOCKED_SHOW_CONTENTIs0() {
|
||||
public void setChecked_false_SettingIs0() {
|
||||
mController.setChecked(false);
|
||||
|
||||
assertThat(Settings.Secure.getInt(mContentResolver, SETTING_KEY, 0)).isEqualTo(0);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getSummary_notSecureLock_isPower_menu_privacy_not_secureString() {
|
||||
public void getSummary_notSecureLock_lockscreen_privacy_not_secureString() {
|
||||
when(mLockPatternUtils.isSecure(anyInt())).thenReturn(false);
|
||||
|
||||
assertThat(mController.getSummary()).isEqualTo(
|
||||
mContext.getText(R.string.power_menu_privacy_not_secure));
|
||||
mContext.getText(R.string.lockscreen_privacy_not_secure));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getSummary_cardsControlsAvailable_isPower_menu_privacy_showString() {
|
||||
Settings.Secure.putInt(mContentResolver, CARDS_AVAILABLE_KEY, 1);
|
||||
public void getSummary_ControlsAvailable_lockscreen_privacy_showString() {
|
||||
mShadowPackageManager.setSystemFeature(PackageManager.FEATURE_CONTROLS, true);
|
||||
|
||||
assertThat(mController.getSummary()).isEqualTo(
|
||||
mContext.getText(R.string.power_menu_privacy_show));
|
||||
}
|
||||
|
||||
@Test
|
||||
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));
|
||||
mContext.getText(R.string.lockscreen_privacy_controls_summary));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void updateState_onPreferenceRefreshed_preferenceEnabledAndSummaryChanged() {
|
||||
mShadowPackageManager.setSystemFeature(PackageManager.FEATURE_CONTROLS, true);
|
||||
Settings.Secure.putInt(mContentResolver, CARDS_AVAILABLE_KEY, 1);
|
||||
|
||||
mController.updateState(mPreference);
|
||||
|
||||
@@ -164,12 +139,20 @@ public class PowerMenuPrivacyPreferenceControllerTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getAvailabilityStatus_allOnNotSecure_returnsDisabled() {
|
||||
public void getAvailabilityStatus_ControlsOnNotSecure_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);
|
||||
|
||||
assertThat(mController.getAvailabilityStatus()).isEqualTo(
|
||||
BasePreferenceController.DISABLED_DEPENDENT_SETTING);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getAvailabilityStatus_ControlsOffSecure_returnsDisabled() {
|
||||
when(mLockPatternUtils.isSecure(anyInt())).thenReturn(true);
|
||||
|
||||
mShadowPackageManager.setSystemFeature(PackageManager.FEATURE_CONTROLS, false);
|
||||
|
||||
assertThat(mController.getAvailabilityStatus()).isEqualTo(
|
||||
BasePreferenceController.DISABLED_DEPENDENT_SETTING);
|
@@ -0,0 +1,151 @@
|
||||
/*
|
||||
* 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.display;
|
||||
|
||||
import static com.google.common.truth.Truth.assertThat;
|
||||
|
||||
import static org.mockito.ArgumentMatchers.anyBoolean;
|
||||
import static org.mockito.ArgumentMatchers.anyInt;
|
||||
import static org.mockito.Mockito.atLeastOnce;
|
||||
import static org.mockito.Mockito.verify;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
import android.content.ContentResolver;
|
||||
import android.content.Context;
|
||||
import android.provider.Settings;
|
||||
import android.service.quickaccesswallet.QuickAccessWalletClient;
|
||||
|
||||
import androidx.preference.Preference;
|
||||
|
||||
import com.android.internal.widget.LockPatternUtils;
|
||||
import com.android.settings.R;
|
||||
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.RobolectricTestRunner;
|
||||
import org.robolectric.RuntimeEnvironment;
|
||||
|
||||
@RunWith(RobolectricTestRunner.class)
|
||||
public class WalletPrivacyPreferenceControllerTest {
|
||||
|
||||
private static final String TEST_KEY = "test_key";
|
||||
private static final String SETTING_KEY = "lockscreen_show_wallet";
|
||||
|
||||
private Context mContext;
|
||||
private ContentResolver mContentResolver;
|
||||
private WalletPrivacyPreferenceController mController;
|
||||
|
||||
@Mock
|
||||
private Preference mPreference;
|
||||
@Mock
|
||||
private LockPatternUtils mLockPatternUtils;
|
||||
@Mock
|
||||
private QuickAccessWalletClient mClient;
|
||||
|
||||
@Before
|
||||
public void setUp() {
|
||||
MockitoAnnotations.initMocks(this);
|
||||
mContext = RuntimeEnvironment.application;
|
||||
|
||||
mContentResolver = mContext.getContentResolver();
|
||||
FakeFeatureFactory featureFactory = FakeFeatureFactory.setupForTest();
|
||||
when(featureFactory.securityFeatureProvider.getLockPatternUtils(mContext))
|
||||
.thenReturn(mLockPatternUtils);
|
||||
when(mLockPatternUtils.isSecure(anyInt())).thenReturn(true);
|
||||
|
||||
when(mClient.isWalletServiceAvailable()).thenReturn(true);
|
||||
mController = new WalletPrivacyPreferenceController(mContext, TEST_KEY) {
|
||||
@Override
|
||||
QuickAccessWalletClient initWalletClient() {
|
||||
return mClient;
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
@Test
|
||||
public void isChecked_SettingIs1_returnTrue() {
|
||||
Settings.Secure.putInt(mContentResolver, SETTING_KEY, 1);
|
||||
|
||||
assertThat(mController.isChecked()).isTrue();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void isChecked_SettingIs0_returnFalse() {
|
||||
Settings.Secure.putInt(mContentResolver, SETTING_KEY, 0);
|
||||
|
||||
assertThat(mController.isChecked()).isFalse();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void isChecked_SettingIsNotSet_returnFalse() {
|
||||
Settings.Secure.putString(mContentResolver, SETTING_KEY, null);
|
||||
|
||||
assertThat(mController.isChecked()).isFalse();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void setChecked_true_SettingIsNot0() {
|
||||
mController.setChecked(true);
|
||||
|
||||
assertThat(Settings.Secure.getInt(mContentResolver, SETTING_KEY, 0)).isNotEqualTo(0);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void setChecked_false_POWER_MENU_LOCKED_SHOW_CONTENTIs0() {
|
||||
mController.setChecked(false);
|
||||
|
||||
assertThat(Settings.Secure.getInt(mContentResolver, SETTING_KEY, 0)).isEqualTo(0);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getSummary_notSecureLock_lockscreen_privacy_not_secureString() {
|
||||
when(mLockPatternUtils.isSecure(anyInt())).thenReturn(false);
|
||||
|
||||
assertThat(mController.getSummary()).isEqualTo(
|
||||
mContext.getText(R.string.lockscreen_privacy_not_secure));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getSummary_isSecure_lockscreen_privacy_showString() {
|
||||
when(mLockPatternUtils.isSecure(anyInt())).thenReturn(true);
|
||||
|
||||
assertThat(mController.getSummary()).isEqualTo(
|
||||
mContext.getText(R.string.lockscreen_privacy_wallet_summary));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void updateState_onPreferenceRefreshed_preferenceEnabledAndSummaryChanged() {
|
||||
mController.updateState(mPreference);
|
||||
|
||||
verify(mPreference).setEnabled(anyBoolean());
|
||||
verify(mPreference, atLeastOnce()).setSummary(mController.getSummary());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getAvailabilityStatus_noService_returnsDisabled() {
|
||||
when(mClient.isWalletServiceAvailable()).thenReturn(false);
|
||||
when(mLockPatternUtils.isSecure(anyInt())).thenReturn(true);
|
||||
|
||||
assertThat(mController.getAvailabilityStatus()).isEqualTo(
|
||||
BasePreferenceController.DISABLED_DEPENDENT_SETTING);
|
||||
}
|
||||
}
|
@@ -1,86 +0,0 @@
|
||||
/*
|
||||
* 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.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 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 CARDS_ENABLED = Settings.Secure.GLOBAL_ACTIONS_PANEL_ENABLED;
|
||||
private static final String CARDS_AVAILABLE = Settings.Secure.GLOBAL_ACTIONS_PANEL_AVAILABLE;
|
||||
|
||||
@ParameterizedRobolectricTestRunner.Parameters(
|
||||
name = "cards available={0}, cards enabled={1}")
|
||||
public static Collection data() {
|
||||
return Arrays.asList(new Object[][]{
|
||||
// cards available, cards enabled, summary
|
||||
{false, false, R.string.power_menu_none},
|
||||
{false, true, R.string.power_menu_none},
|
||||
{true, false, R.string.power_menu_none},
|
||||
{true, true, R.string.power_menu_cards_passes}
|
||||
});
|
||||
}
|
||||
|
||||
private Context mContext;
|
||||
private PowerMenuPreferenceController mController;
|
||||
|
||||
private boolean mCardsAvailable;
|
||||
private boolean mCardsEnabled;
|
||||
private @StringRes int mSummaryRes;
|
||||
|
||||
public PowerMenuPreferenceControllerSummaryTest(
|
||||
boolean cardsAvailable,
|
||||
boolean cardsEnabled,
|
||||
@StringRes int summaryRes) {
|
||||
mCardsAvailable = cardsAvailable;
|
||||
mCardsEnabled = cardsEnabled;
|
||||
mSummaryRes = summaryRes;
|
||||
}
|
||||
|
||||
@Before
|
||||
public void setUp() {
|
||||
mContext = RuntimeEnvironment.application;
|
||||
mController = new PowerMenuPreferenceController(mContext, KEY_GESTURE_POWER_MENU);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getSummary_possiblyAvailableAndEnabled() {
|
||||
ContentResolver cr = mContext.getContentResolver();
|
||||
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));
|
||||
}
|
||||
}
|
@@ -24,7 +24,6 @@ import static org.mockito.Mockito.when;
|
||||
|
||||
import android.content.Context;
|
||||
import android.content.res.Resources;
|
||||
import android.provider.Settings;
|
||||
|
||||
import com.android.settings.core.BasePreferenceController;
|
||||
|
||||
@@ -41,8 +40,6 @@ public class PowerMenuPreferenceControllerTest {
|
||||
private PowerMenuPreferenceController mController;
|
||||
|
||||
private static final String KEY_GESTURE_POWER_MENU = "gesture_power_menu";
|
||||
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
|
||||
@@ -57,8 +54,7 @@ public class PowerMenuPreferenceControllerTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getAvailabilityStatus_allAvailable_available() {
|
||||
Settings.Secure.putInt(mContext.getContentResolver(), CARDS_AVAILABLE, 1);
|
||||
public void getAvailabilityStatus_assistAvailable_available() {
|
||||
when(mResources.getBoolean(
|
||||
com.android.internal.R.bool.config_longPressOnPowerForAssistantSettingAvailable))
|
||||
.thenReturn(true);
|
||||
@@ -68,41 +64,7 @@ public class PowerMenuPreferenceControllerTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getAvailabilityStatus_onlyCardsAvailable_available() {
|
||||
Settings.Secure.putInt(mContext.getContentResolver(), CARDS_AVAILABLE, 1);
|
||||
when(mResources.getBoolean(
|
||||
com.android.internal.R.bool.config_longPressOnPowerForAssistantSettingAvailable))
|
||||
.thenReturn(false);
|
||||
|
||||
assertThat(mController.getAvailabilityStatus()).isEqualTo(
|
||||
BasePreferenceController.AVAILABLE);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getAvailabilityStatus_cardsAndAssistAvailable_available() {
|
||||
Settings.Secure.putInt(mContext.getContentResolver(), CARDS_AVAILABLE, 1);
|
||||
when(mResources.getBoolean(
|
||||
com.android.internal.R.bool.config_longPressOnPowerForAssistantSettingAvailable))
|
||||
.thenReturn(true);
|
||||
|
||||
assertThat(mController.getAvailabilityStatus()).isEqualTo(
|
||||
BasePreferenceController.AVAILABLE);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getAvailabilityStatus_onlyAssistAvailable_available() {
|
||||
Settings.Secure.putInt(mContext.getContentResolver(), CARDS_AVAILABLE, 0);
|
||||
when(mResources.getBoolean(
|
||||
com.android.internal.R.bool.config_longPressOnPowerForAssistantSettingAvailable))
|
||||
.thenReturn(true);
|
||||
|
||||
assertThat(mController.getAvailabilityStatus()).isEqualTo(
|
||||
BasePreferenceController.AVAILABLE);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getAvailabilityStatus_allUnavailable_unavailable() {
|
||||
Settings.Secure.putInt(mContext.getContentResolver(), CARDS_AVAILABLE, 0);
|
||||
public void getAvailabilityStatus_assistUnavailable_unavailable() {
|
||||
when(mResources.getBoolean(
|
||||
com.android.internal.R.bool.config_longPressOnPowerForAssistantSettingAvailable))
|
||||
.thenReturn(false);
|
||||
|
@@ -1,116 +0,0 @@
|
||||
/*
|
||||
* 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_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} cards available={1}, cards enabled={2}")
|
||||
public static Collection data() {
|
||||
return Arrays.asList(new Object[][]{
|
||||
// controls available, cards available, cards enabled, available
|
||||
{false, false, false, BasePreferenceController.DISABLED_DEPENDENT_SETTING},
|
||||
{false, false, true, BasePreferenceController.DISABLED_DEPENDENT_SETTING},
|
||||
{false, true, false, BasePreferenceController.DISABLED_DEPENDENT_SETTING},
|
||||
{false, true, true, BasePreferenceController.AVAILABLE},
|
||||
{true, false, false, BasePreferenceController.AVAILABLE},
|
||||
{true, false, true, BasePreferenceController.AVAILABLE},
|
||||
{true, true, false, BasePreferenceController.AVAILABLE},
|
||||
{true, true, true, BasePreferenceController.AVAILABLE}
|
||||
});
|
||||
}
|
||||
|
||||
private Context mContext;
|
||||
private PowerMenuPrivacyPreferenceController mController;
|
||||
private ShadowPackageManager mShadowPackageManager;
|
||||
|
||||
@Mock
|
||||
private LockPatternUtils mLockPatternUtils;
|
||||
|
||||
private boolean mControlsAvailable;
|
||||
private boolean mCardsAvailable;
|
||||
private boolean mCardsEnabled;
|
||||
private int mAvailable;
|
||||
|
||||
public PowerMenuPrivacyPreferenceControllerAvailabilityTest(
|
||||
boolean controlsAvailable,
|
||||
boolean cardsAvailable,
|
||||
boolean cardsEnabled,
|
||||
int available) {
|
||||
mControlsAvailable = controlsAvailable;
|
||||
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, CARDS_AVAILABLE, mCardsAvailable ? 1 : 0);
|
||||
Settings.Secure.putInt(cr, CARDS_ENABLED, mCardsEnabled ? 1 : 0);
|
||||
|
||||
assertThat(mController.getAvailabilityStatus()).isEqualTo(mAvailable);
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user