Use PackageManager.FEATURE_CONTROLS to decide availability
Using this features, some of the Preference in Power Menu Settings can change their availability and their summary. Test: Robotest Settings Fixes: 157244528 Change-Id: I704438dda181aa6347c3f168ac5ef6bd16148993
This commit is contained in:
@@ -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);
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user