Merge "Remove "Device Controls" from Settings" into sc-dev

This commit is contained in:
Matt Pietal
2021-04-21 11:31:33 +00:00
committed by Android (Google) Code Review
16 changed files with 19 additions and 469 deletions

View File

@@ -3688,17 +3688,6 @@
android:value="com.android.settings.gestures.PowerMenuSettings" />
</activity>
<activity android:name="Settings$DeviceControlsSettingsActivity"
android:exported="true"
android:label="@string/device_controls_sentence">
<intent-filter>
<action android:name="android.settings.ACTION_DEVICE_CONTROLS_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.DeviceControlsSettings" />
</activity>
<activity
android:name="Settings$GestureNavigationSettingsActivity"
android:label="@string/gesture_settings_activity_title"

View File

@@ -12863,9 +12863,6 @@
<!-- Developer settings: text for the bug report handler selection toast shown if an invalid bug report handler was chosen. [CHAR LIMIT=NONE] -->
<string name="select_invalid_bug_report_handler_toast_text">This choice is no longer valid. Try again.</string>
<!-- Device controls name sentence case [CHAR LIMIT=40] -->
<string name="device_controls_sentence">Device controls</string>
<!-- Device controls name lower case [CHAR LIMIT=40] -->
<string name="quick_controls_lower">device controls</string>
@@ -12884,12 +12881,6 @@
<!-- Power menu setting option cards and passes [CHAR LIMIT=NONE] -->
<string name="power_menu_cards_passes">Show cards &amp; passes</string>
<!-- Power menu setting option device controls [CHAR LIMIT=NONE] -->
<string name="power_menu_device_controls">Show device controls</string>
<!-- Power menu setting option cards, passes, device controls [CHAR LIMIT=NONE] -->
<string name="power_menu_cards_passes_device_controls">Show cards, passes, and device controls</string>
<!-- Power menu setting lock screen category name [CHAR LIMIT=40] -->
<string name="power_menu_lock_screen_category">Lock screen</string>

View File

@@ -1,36 +0,0 @@
<?xml version="1.0" encoding="utf-8"?>
<!--
~ 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.
-->
<PreferenceScreen
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:title="@string/device_controls_sentence">
<com.android.settings.widget.VideoPreference
android:key="device_controls_video"
app:animation="@raw/gesture_device_controls"
app:controller="com.android.settings.widget.VideoPreferenceController"/>
<SwitchPreference
android:key="gesture_device_controls_switch"
android:title="@string/device_controls_setting_toggle"
android:summary="@string/device_controls_setting_subtitle"
app:keywords="@string/keywords_device_controls"
app:controller="com.android.settings.gestures.DeviceControlsPreferenceController"
app:allowDividerAbove="true" />
</PreferenceScreen>

View File

@@ -33,12 +33,6 @@
android:fragment="com.android.settings.gestures.GlobalActionsPanelSettings"
settings:controller="com.android.settings.gestures.GlobalActionsPanelPreferenceController" />
<Preference
android:key="gesture_device_controls_summary"
android:title="@string/device_controls_sentence"
android:fragment="com.android.settings.gestures.DeviceControlsSettings"
settings:controller="com.android.settings.gestures.DeviceControlsPreferenceController" />
<PreferenceCategory
android:title="@string/power_menu_lock_screen_category" >

View File

@@ -93,7 +93,6 @@ import com.android.settings.fuelgauge.PowerUsageSummary;
import com.android.settings.fuelgauge.batterysaver.BatterySaverScheduleSettings;
import com.android.settings.fuelgauge.batterysaver.BatterySaverSettings;
import com.android.settings.gestures.AssistGestureSettings;
import com.android.settings.gestures.DeviceControlsSettings;
import com.android.settings.gestures.DoubleTapPowerSettings;
import com.android.settings.gestures.DoubleTapScreenSettings;
import com.android.settings.gestures.DoubleTwistGestureSettings;
@@ -306,7 +305,6 @@ public class SettingsGateway {
MobileNetworkListFragment.class.getName(),
PowerMenuSettings.class.getName(),
GlobalActionsPanelSettings.class.getName(),
DeviceControlsSettings.class.getName(),
DarkModeSettingsFragment.class.getName(),
BugReportHandlerPicker.class.getName(),
GestureNavigationSettingsFragment.class.getName(),

View File

@@ -1,72 +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 android.content.Context;
import android.content.pm.PackageManager;
import android.provider.Settings;
import android.text.TextUtils;
import com.android.internal.annotations.VisibleForTesting;
public class DeviceControlsPreferenceController extends GesturePreferenceController {
private static final String PREF_KEY_VIDEO = "device_controls_video";
@VisibleForTesting
protected static final String ENABLED_SETTING = Settings.Secure.CONTROLS_ENABLED;
@VisibleForTesting
protected static final String TOGGLE_KEY = "gesture_device_controls_switch";
public DeviceControlsPreferenceController(Context context, String key) {
super(context, key);
}
@Override
public int getAvailabilityStatus() {
boolean available = mContext.getPackageManager().hasSystemFeature(
PackageManager.FEATURE_CONTROLS);
return available ? AVAILABLE : CONDITIONALLY_UNAVAILABLE;
}
@Override
public boolean setChecked(boolean isChecked) {
return Settings.Secure.putInt(mContext.getContentResolver(), ENABLED_SETTING,
isChecked ? 1 : 0);
}
@Override
protected String getVideoPrefKey() {
return PREF_KEY_VIDEO;
}
@Override
public boolean isSliceable() {
return TextUtils.equals(getPreferenceKey(), TOGGLE_KEY);
}
@Override
public boolean isPublicSlice() {
return true;
}
@Override
public boolean isChecked() {
int enabled = Settings.Secure.getInt(mContext.getContentResolver(), ENABLED_SETTING, 1);
return enabled == 1;
}
}

View File

@@ -1,48 +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 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 DeviceControlsSettings extends DashboardFragment {
private static final String TAG = "QuickControlsSettings";
@Override
public int getMetricsCategory() {
return SettingsEnums.DEVICE_CONTROLS_SETTINGS;
}
@Override
protected String getLogTag() {
return TAG;
}
@Override
protected int getPreferenceScreenResId() {
return R.xml.device_controls_settings;
}
public static final BaseSearchIndexProvider SEARCH_INDEX_DATA_PROVIDER =
new BaseSearchIndexProvider(R.xml.device_controls_settings);
}

View File

@@ -17,7 +17,6 @@
package com.android.settings.gestures;
import android.content.Context;
import android.content.pm.PackageManager;
import android.provider.Settings;
import com.android.settings.R;
@@ -26,7 +25,6 @@ import com.android.settings.core.BasePreferenceController;
public class PowerMenuPreferenceController extends BasePreferenceController {
private static final String KEY = "gesture_power_menu_summary";
private static final String CONTROLS_ENABLED_SETTING = Settings.Secure.CONTROLS_ENABLED;
private static final String CARDS_ENABLED_SETTING =
Settings.Secure.GLOBAL_ACTIONS_PANEL_ENABLED;
private static final String CARDS_AVAILABLE_SETTING =
@@ -38,17 +36,10 @@ public class PowerMenuPreferenceController extends BasePreferenceController {
@Override
public CharSequence getSummary() {
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 (controlsVisible) {
return mContext.getText(R.string.power_menu_device_controls);
} else if (cardsVisible) {
if (cardsVisible) {
return mContext.getText(R.string.power_menu_cards_passes);
} else {
return mContext.getText(R.string.power_menu_none);
@@ -57,14 +48,10 @@ public class PowerMenuPreferenceController extends BasePreferenceController {
@Override
public int getAvailabilityStatus() {
return isCardsAvailable() || isControlsAvailable() || isAssistInvocationAvailable()
return isCardsAvailable() || isAssistInvocationAvailable()
? 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;

View File

@@ -35,7 +35,6 @@ public class PowerMenuPrivacyPreferenceController extends TogglePreferenceContro
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 CONTROLS_ENABLED_KEY = Settings.Secure.CONTROLS_ENABLED;
public PowerMenuPrivacyPreferenceController(Context context,
@@ -94,8 +93,7 @@ public class PowerMenuPrivacyPreferenceController extends TogglePreferenceContro
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;
boolean controlsEnabled = Settings.Secure.getInt(resolver, CONTROLS_ENABLED_KEY, 1) != 0;
return (cardsAvailable && cardsEnabled) || (isControlsAvailable() && controlsEnabled);
return (cardsAvailable && cardsEnabled) || isControlsAvailable();
}
private boolean isSecure() {

View File

@@ -1,102 +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.content.Context;
import android.content.pm.PackageManager;
import android.provider.Settings;
import com.android.settings.core.BasePreferenceController;
import org.junit.Before;
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 =
DeviceControlsPreferenceController.ENABLED_SETTING;
@Before
public void setUp() {
mContext = RuntimeEnvironment.application;
mShadowPackageManager = Shadows.shadowOf(mContext.getPackageManager());
mController = new DeviceControlsPreferenceController(mContext, KEY_GESTURE_PANEL);
}
@Test
public void testIsChecked_panelEnabled() {
Settings.Secure.putInt(
mContext.getContentResolver(), ENABLED_SETTING, 1);
assertThat(mController.isChecked()).isTrue();
}
@Test
public void testIsChecked_panelDisabled() {
Settings.Secure.putInt(
mContext.getContentResolver(), ENABLED_SETTING, 0);
assertThat(mController.isChecked()).isFalse();
}
@Test
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 =
new DeviceControlsPreferenceController(mContext,
DeviceControlsPreferenceController.TOGGLE_KEY);
assertThat(controller.isSliceable()).isTrue();
}
@Test
public void isSliceable_incorrectKey() {
final DeviceControlsPreferenceController controller =
new DeviceControlsPreferenceController(mContext, "bad_key");
assertThat(controller.isSliceable()).isFalse();
}
@Test
public void isPublicSlice_returnTrue() {
assertThat(mController.isPublicSlice()).isTrue();
}
}

View File

@@ -1,50 +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.provider.SearchIndexableResource;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.robolectric.RobolectricTestRunner;
import org.robolectric.RuntimeEnvironment;
import java.util.List;
@RunWith(RobolectricTestRunner.class)
public class DeviceControlsSettingsTest {
private DeviceControlsSettings mSettings;
@Before
public void setUp() {
mSettings = new DeviceControlsSettings();
}
@Test
public void testSearchIndexProvider_shouldIndexResource() {
final List<SearchIndexableResource> indexRes =
DeviceControlsSettings.SEARCH_INDEX_DATA_PROVIDER.getXmlResourcesToIndex(
RuntimeEnvironment.application, true /* enabled */);
assertThat(indexRes).isNotNull();
assertThat(indexRes.get(0).xmlResId).isEqualTo(mSettings.getPreferenceScreenResId());
}
}

View File

@@ -21,7 +21,6 @@ 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;
@@ -31,8 +30,6 @@ 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;
@@ -41,53 +38,32 @@ import java.util.Collection;
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}")
name = "cards available={0}, cards enabled={1}")
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}
// 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 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;
@@ -96,15 +72,12 @@ public class PowerMenuPreferenceControllerSummaryTest {
@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);

View File

@@ -23,7 +23,6 @@ import static org.mockito.Mockito.spy;
import static org.mockito.Mockito.when;
import android.content.Context;
import android.content.pm.PackageManager;
import android.content.res.Resources;
import android.provider.Settings;
@@ -34,19 +33,14 @@ 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 PowerMenuPreferenceControllerTest {
private Context mContext;
private Resources mResources;
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;
@@ -59,14 +53,12 @@ public class PowerMenuPreferenceControllerTest {
com.android.internal.R.bool.config_longPressOnPowerForAssistantSettingAvailable))
.thenReturn(true);
when(mContext.getResources()).thenReturn(mResources);
mShadowPackageManager = Shadows.shadowOf(mContext.getPackageManager());
mController = new PowerMenuPreferenceController(mContext, KEY_GESTURE_POWER_MENU);
}
@Test
public void getAvailabilityStatus_allAvailable_available() {
Settings.Secure.putInt(mContext.getContentResolver(), CARDS_AVAILABLE, 1);
mShadowPackageManager.setSystemFeature(CONTROLS_FEATURE, true);
when(mResources.getBoolean(
com.android.internal.R.bool.config_longPressOnPowerForAssistantSettingAvailable))
.thenReturn(true);
@@ -78,7 +70,6 @@ public class PowerMenuPreferenceControllerTest {
@Test
public void getAvailabilityStatus_onlyCardsAvailable_available() {
Settings.Secure.putInt(mContext.getContentResolver(), CARDS_AVAILABLE, 1);
mShadowPackageManager.setSystemFeature(CONTROLS_FEATURE, false);
when(mResources.getBoolean(
com.android.internal.R.bool.config_longPressOnPowerForAssistantSettingAvailable))
.thenReturn(false);
@@ -87,46 +78,9 @@ public class PowerMenuPreferenceControllerTest {
BasePreferenceController.AVAILABLE);
}
@Test
public void getAvailabilityStatus_onlyControlsAvailable_available() {
Settings.Secure.putInt(mContext.getContentResolver(), CARDS_AVAILABLE, 0);
mShadowPackageManager.setSystemFeature(CONTROLS_FEATURE, true);
when(mResources.getBoolean(
com.android.internal.R.bool.config_longPressOnPowerForAssistantSettingAvailable))
.thenReturn(false);
assertThat(mController.getAvailabilityStatus()).isEqualTo(
BasePreferenceController.AVAILABLE);
}
@Test
public void getAvailabilityStatus_controlsAndCardsAvailable_available() {
Settings.Secure.putInt(mContext.getContentResolver(), CARDS_AVAILABLE, 1);
mShadowPackageManager.setSystemFeature(CONTROLS_FEATURE, true);
when(mResources.getBoolean(
com.android.internal.R.bool.config_longPressOnPowerForAssistantSettingAvailable))
.thenReturn(false);
assertThat(mController.getAvailabilityStatus()).isEqualTo(
BasePreferenceController.AVAILABLE);
}
@Test
public void getAvailabilityStatus_controlsAndAssistAvailable_available() {
Settings.Secure.putInt(mContext.getContentResolver(), CARDS_AVAILABLE, 0);
mShadowPackageManager.setSystemFeature(CONTROLS_FEATURE, true);
when(mResources.getBoolean(
com.android.internal.R.bool.config_longPressOnPowerForAssistantSettingAvailable))
.thenReturn(true);
assertThat(mController.getAvailabilityStatus()).isEqualTo(
BasePreferenceController.AVAILABLE);
}
@Test
public void getAvailabilityStatus_cardsAndAssistAvailable_available() {
Settings.Secure.putInt(mContext.getContentResolver(), CARDS_AVAILABLE, 1);
mShadowPackageManager.setSystemFeature(CONTROLS_FEATURE, false);
when(mResources.getBoolean(
com.android.internal.R.bool.config_longPressOnPowerForAssistantSettingAvailable))
.thenReturn(true);
@@ -138,7 +92,6 @@ public class PowerMenuPreferenceControllerTest {
@Test
public void getAvailabilityStatus_onlyAssistAvailable_available() {
Settings.Secure.putInt(mContext.getContentResolver(), CARDS_AVAILABLE, 0);
mShadowPackageManager.setSystemFeature(CONTROLS_FEATURE, false);
when(mResources.getBoolean(
com.android.internal.R.bool.config_longPressOnPowerForAssistantSettingAvailable))
.thenReturn(true);
@@ -150,7 +103,6 @@ public class PowerMenuPreferenceControllerTest {
@Test
public void getAvailabilityStatus_allUnavailable_unavailable() {
Settings.Secure.putInt(mContext.getContentResolver(), CARDS_AVAILABLE, 0);
mShadowPackageManager.setSystemFeature(CONTROLS_FEATURE, false);
when(mResources.getBoolean(
com.android.internal.R.bool.config_longPressOnPowerForAssistantSettingAvailable))
.thenReturn(false);

View File

@@ -46,32 +46,23 @@ 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}")
name = "ctrls available={0} cards available={1}, cards enabled={2}")
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}
// 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}
});
}
@@ -83,19 +74,16 @@ public class PowerMenuPrivacyPreferenceControllerAvailabilityTest {
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;
@@ -120,7 +108,6 @@ public class PowerMenuPrivacyPreferenceControllerAvailabilityTest {
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);

View File

@@ -54,7 +54,6 @@ public class PowerMenuPrivacyPreferenceControllerTest {
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 CONTROLS_ENABLED_KEY = Settings.Secure.CONTROLS_ENABLED;
private Context mContext;
private ContentResolver mContentResolver;
@@ -171,18 +170,8 @@ public class PowerMenuPrivacyPreferenceControllerTest {
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);
assertThat(mController.getAvailabilityStatus()).isEqualTo(
BasePreferenceController.DISABLED_DEPENDENT_SETTING);
}
@Test
public void getAvailabilityStatus_controlsDeletedSecure_retursAvailable() {
Settings.Secure.putString(mContentResolver, CONTROLS_ENABLED_KEY, null);
mShadowPackageManager.setSystemFeature(PackageManager.FEATURE_CONTROLS, true);
assertThat(mController.getAvailabilityStatus()).isEqualTo(
BasePreferenceController.AVAILABLE);
}
}