Add display settings dashboard to new IA.

- Added a activity-alias pointing to displaySettings as top level
  setting item.
- Refactored all preference logic in DisplaySettings into
  PreferenceControllers. During fragment onAttach it installs all
  controllers, and during onResume it updates preference state. Each
  controller listens to its own preference change event.

Bug: 31800242
Test: RunSettingsRoboTests
Change-Id: Ibc9bf200c5acce7c4ae9292340822afee27a3a28
This commit is contained in:
Fan Zhang
2016-10-06 16:33:13 -07:00
parent 36a6cb0370
commit 66b573ad5a
30 changed files with 1320 additions and 555 deletions

View File

@@ -3044,6 +3044,19 @@
android:value="com.android.settings.category.ia.homepage"/>
</activity-alias>
<activity-alias android:name="DisplayDashboardAlias"
android:targetActivity="Settings$DisplaySettingsActivity">
<intent-filter android:priority="6">
<action android:name="com.android.settings.action.SETTINGS" />
</intent-filter>
<meta-data android:name="com.android.settings.category"
android:value="com.android.settings.category.ia.homepage" />
<meta-data android:name="com.android.settings.FRAGMENT_CLASS"
android:value="com.android.settings.DisplaySettings" />
<meta-data android:name="com.android.settings.PRIMARY_PROFILE_CONTROLLED"
android:value="true" />
</activity-alias>
<activity android:name=".Settings$StorageDashboardActivity"
android:label="@string/storage_settings"
android:icon="@drawable/ic_settings_storage">

View File

@@ -35,10 +35,9 @@ import android.util.Log;
import android.widget.Toast;
import com.android.internal.logging.MetricsProto.MetricsEvent;
import com.android.settings.dashboard.DashboardFeatureProvider;
import com.android.settings.dashboard.SummaryLoader;
import com.android.settings.deviceinfo.AdditionalSystemUpdatePreferenceController;
import com.android.settings.deviceinfo.SystemUpdatePreferenceController;
import com.android.settings.overlay.FeatureFactory;
import com.android.settings.search.BaseSearchIndexProvider;
import com.android.settings.search.Index;
import com.android.settings.search.Indexable;
@@ -77,7 +76,7 @@ public class DeviceInfoSettings extends SettingsPreferenceFragment implements In
int mDevHitCountdown;
Toast mDevHitToast;
private SystemUpdatePreferenceController mSystemUpdatePreferenceController;
private DashboardFeatureProvider mDashboardFeatureProvider;
private AdditionalSystemUpdatePreferenceController mAdditionalSystemUpdatePreferenceController;
private UserManager mUm;
@@ -102,8 +101,8 @@ public class DeviceInfoSettings extends SettingsPreferenceFragment implements In
final Activity activity = getActivity();
mUm = UserManager.get(activity);
mSystemUpdatePreferenceController = new SystemUpdatePreferenceController(activity, mUm);
mDashboardFeatureProvider = FeatureFactory.getFactory(activity)
.getDashboardFeatureProvider(activity);
mAdditionalSystemUpdatePreferenceController =
new AdditionalSystemUpdatePreferenceController(activity);
addPreferencesFromResource(R.xml.device_info_settings);
@@ -159,6 +158,7 @@ public class DeviceInfoSettings extends SettingsPreferenceFragment implements In
* info.
*/
mSystemUpdatePreferenceController.displayPreference(getPreferenceScreen());
mAdditionalSystemUpdatePreferenceController.displayPreference(getPreferenceScreen());
// Remove manual entry if none present.
removePreferenceIfBoolFalse(KEY_MANUAL, R.bool.config_show_manual);
@@ -398,6 +398,8 @@ public class DeviceInfoSettings extends SettingsPreferenceFragment implements In
}
new SystemUpdatePreferenceController(context, UserManager.get(context))
.updateNonIndexableKeys(keys);
new AdditionalSystemUpdatePreferenceController(context)
.updateNonIndexableKeys(keys);
return keys;
}

View File

@@ -17,435 +17,76 @@
package com.android.settings;
import android.app.Activity;
import android.app.ActivityManager;
import android.app.UiModeManager;
import android.app.admin.DevicePolicyManager;
import android.content.ContentResolver;
import android.content.Context;
import android.content.pm.PackageManager;
import android.content.res.Configuration;
import android.content.res.Resources;
import android.hardware.Sensor;
import android.hardware.SensorManager;
import android.os.Build;
import android.os.Bundle;
import android.os.SystemProperties;
import android.os.UserHandle;
import android.os.UserManager;
import android.provider.SearchIndexableResource;
import android.provider.Settings;
import android.support.v14.preference.SwitchPreference;
import android.support.v7.preference.DropDownPreference;
import android.support.v7.preference.ListPreference;
import android.support.v7.preference.Preference;
import android.support.v7.preference.Preference.OnPreferenceChangeListener;
import android.text.TextUtils;
import android.util.Log;
import com.android.internal.app.NightDisplayController;
import com.android.internal.logging.MetricsProto.MetricsEvent;
import com.android.internal.view.RotationPolicy;
import com.android.settings.accessibility.ToggleFontSizePreferenceFragment;
import com.android.settings.core.PreferenceController;
import com.android.settings.dashboard.DashboardFragment;
import com.android.settings.dashboard.SummaryLoader;
import com.android.settings.display.AutoBrightnessPreferenceController;
import com.android.settings.display.AutoRotatePreferenceController;
import com.android.settings.display.CameraGesturePreferenceController;
import com.android.settings.display.DozePreferenceController;
import com.android.settings.display.FontSizePreferenceController;
import com.android.settings.display.LiftToWakePreferenceController;
import com.android.settings.display.NightDisplayPreferenceController;
import com.android.settings.display.NightModePreferenceController;
import com.android.settings.display.ScreenSaverPreferenceController;
import com.android.settings.display.TapToWakePreferenceController;
import com.android.settings.display.TimeoutPreferenceController;
import com.android.settings.display.VrDisplayPreferenceController;
import com.android.settings.display.WallpaperPreferenceController;
import com.android.settings.search.BaseSearchIndexProvider;
import com.android.settings.search.Indexable;
import com.android.settingslib.RestrictedLockUtils;
import com.android.settingslib.RestrictedPreference;
import com.android.settingslib.drawer.CategoryKey;
import java.util.ArrayList;
import java.util.List;
import static android.provider.Settings.Secure.CAMERA_GESTURE_DISABLED;
import static android.provider.Settings.Secure.DOUBLE_TAP_TO_WAKE;
import static android.provider.Settings.Secure.DOZE_ENABLED;
import static android.provider.Settings.Secure.WAKE_GESTURE_ENABLED;
import static android.provider.Settings.System.SCREEN_BRIGHTNESS_MODE;
import static android.provider.Settings.System.SCREEN_BRIGHTNESS_MODE_AUTOMATIC;
import static android.provider.Settings.System.SCREEN_BRIGHTNESS_MODE_MANUAL;
import static android.provider.Settings.System.SCREEN_OFF_TIMEOUT;
import static com.android.settingslib.RestrictedLockUtils.EnforcedAdmin;
public class DisplaySettings extends SettingsPreferenceFragment implements
Preference.OnPreferenceChangeListener, Indexable {
public class DisplaySettings extends DashboardFragment {
private static final String TAG = "DisplaySettings";
/** If there is no setting in the provider, use this. */
private static final int FALLBACK_SCREEN_TIMEOUT_VALUE = 30000;
private static final String KEY_SCREEN_TIMEOUT = "screen_timeout";
private static final String KEY_FONT_SIZE = "font_size";
private static final String KEY_SCREEN_SAVER = "screensaver";
private static final String KEY_LIFT_TO_WAKE = "lift_to_wake";
private static final String KEY_DOZE = "doze";
private static final String KEY_TAP_TO_WAKE = "tap_to_wake";
private static final String KEY_AUTO_BRIGHTNESS = "auto_brightness";
private static final String KEY_AUTO_ROTATE = "auto_rotate";
private static final String KEY_NIGHT_DISPLAY = "night_display";
private static final String KEY_NIGHT_MODE = "night_mode";
private static final String KEY_CAMERA_GESTURE = "camera_gesture";
private static final String KEY_WALLPAPER = "wallpaper";
private static final String KEY_VR_DISPLAY_PREF = "vr_display_pref";
private Preference mFontSizePref;
private TimeoutListPreference mScreenTimeoutPreference;
private ListPreference mNightModePreference;
private Preference mScreenSaverPreference;
private SwitchPreference mLiftToWakePreference;
private SwitchPreference mDozePreference;
private SwitchPreference mTapToWakePreference;
private SwitchPreference mAutoBrightnessPreference;
private SwitchPreference mCameraGesturePreference;
@Override
public int getMetricsCategory() {
return MetricsEvent.DISPLAY;
}
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
final Activity activity = getActivity();
final ContentResolver resolver = activity.getContentResolver();
addPreferencesFromResource(R.xml.display_settings);
mScreenSaverPreference = findPreference(KEY_SCREEN_SAVER);
if (mScreenSaverPreference != null
&& getResources().getBoolean(
com.android.internal.R.bool.config_dreamsSupported) == false) {
getPreferenceScreen().removePreference(mScreenSaverPreference);
}
mScreenTimeoutPreference = (TimeoutListPreference) findPreference(KEY_SCREEN_TIMEOUT);
mFontSizePref = findPreference(KEY_FONT_SIZE);
if (isAutomaticBrightnessAvailable(getResources())) {
mAutoBrightnessPreference = (SwitchPreference) findPreference(KEY_AUTO_BRIGHTNESS);
mAutoBrightnessPreference.setOnPreferenceChangeListener(this);
} else {
removePreference(KEY_AUTO_BRIGHTNESS);
}
if (!NightDisplayController.isAvailable(activity)) {
removePreference(KEY_NIGHT_DISPLAY);
}
if (isLiftToWakeAvailable(activity)) {
mLiftToWakePreference = (SwitchPreference) findPreference(KEY_LIFT_TO_WAKE);
mLiftToWakePreference.setOnPreferenceChangeListener(this);
} else {
removePreference(KEY_LIFT_TO_WAKE);
}
if (isDozeAvailable(activity)) {
mDozePreference = (SwitchPreference) findPreference(KEY_DOZE);
mDozePreference.setOnPreferenceChangeListener(this);
} else {
removePreference(KEY_DOZE);
}
if (isTapToWakeAvailable(getResources())) {
mTapToWakePreference = (SwitchPreference) findPreference(KEY_TAP_TO_WAKE);
mTapToWakePreference.setOnPreferenceChangeListener(this);
} else {
removePreference(KEY_TAP_TO_WAKE);
}
if (isCameraGestureAvailable(getResources())) {
mCameraGesturePreference = (SwitchPreference) findPreference(KEY_CAMERA_GESTURE);
mCameraGesturePreference.setOnPreferenceChangeListener(this);
} else {
removePreference(KEY_CAMERA_GESTURE);
}
if (RotationPolicy.isRotationLockToggleVisible(activity)) {
DropDownPreference rotatePreference =
(DropDownPreference) findPreference(KEY_AUTO_ROTATE);
int rotateLockedResourceId;
// The following block sets the string used when rotation is locked.
// If the device locks specifically to portrait or landscape (rather than current
// rotation), then we use a different string to include this information.
if (allowAllRotations(activity)) {
rotateLockedResourceId = R.string.display_auto_rotate_stay_in_current;
} else {
if (RotationPolicy.getRotationLockOrientation(activity)
== Configuration.ORIENTATION_PORTRAIT) {
rotateLockedResourceId =
R.string.display_auto_rotate_stay_in_portrait;
} else {
rotateLockedResourceId =
R.string.display_auto_rotate_stay_in_landscape;
}
}
rotatePreference.setEntries(new CharSequence[] {
activity.getString(R.string.display_auto_rotate_rotate),
activity.getString(rotateLockedResourceId),
});
rotatePreference.setEntryValues(new CharSequence[] { "0", "1" });
rotatePreference.setValueIndex(RotationPolicy.isRotationLocked(activity) ?
1 : 0);
rotatePreference.setOnPreferenceChangeListener(new OnPreferenceChangeListener() {
@Override
public boolean onPreferenceChange(Preference preference, Object newValue) {
final boolean locked = Integer.parseInt((String) newValue) != 0;
mMetricsFeatureProvider.action(getActivity(), MetricsEvent.ACTION_ROTATION_LOCK,
locked);
RotationPolicy.setRotationLock(activity, locked);
return true;
}
});
} else {
removePreference(KEY_AUTO_ROTATE);
}
if (isVrDisplayModeAvailable(activity)) {
DropDownPreference vrDisplayPref =
(DropDownPreference) findPreference(KEY_VR_DISPLAY_PREF);
vrDisplayPref.setEntries(new CharSequence[] {
activity.getString(R.string.display_vr_pref_low_persistence),
activity.getString(R.string.display_vr_pref_off),
});
vrDisplayPref.setEntryValues(new CharSequence[] { "0", "1" });
final Context c = activity;
int currentUser = ActivityManager.getCurrentUser();
int current = Settings.Secure.getIntForUser(c.getContentResolver(),
Settings.Secure.VR_DISPLAY_MODE,
/*default*/Settings.Secure.VR_DISPLAY_MODE_LOW_PERSISTENCE,
currentUser);
vrDisplayPref.setValueIndex(current);
vrDisplayPref.setOnPreferenceChangeListener(new OnPreferenceChangeListener() {
@Override
public boolean onPreferenceChange(Preference preference, Object newValue) {
int i = Integer.parseInt((String) newValue);
int u = ActivityManager.getCurrentUser();
if (!Settings.Secure.putIntForUser(c.getContentResolver(),
Settings.Secure.VR_DISPLAY_MODE,
i, u)) {
Log.e(TAG, "Could not change setting for " +
Settings.Secure.VR_DISPLAY_MODE);
}
return true;
}
});
} else {
removePreference(KEY_VR_DISPLAY_PREF);
}
mNightModePreference = (ListPreference) findPreference(KEY_NIGHT_MODE);
if (mNightModePreference != null) {
final UiModeManager uiManager = (UiModeManager) getSystemService(
Context.UI_MODE_SERVICE);
final int currentNightMode = uiManager.getNightMode();
mNightModePreference.setValue(String.valueOf(currentNightMode));
mNightModePreference.setOnPreferenceChangeListener(this);
}
}
private static boolean allowAllRotations(Context context) {
return Resources.getSystem().getBoolean(
com.android.internal.R.bool.config_allowAllRotations);
}
private static boolean isLiftToWakeAvailable(Context context) {
SensorManager sensors = (SensorManager) context.getSystemService(Context.SENSOR_SERVICE);
return sensors != null && sensors.getDefaultSensor(Sensor.TYPE_WAKE_GESTURE) != null;
}
private static boolean isDozeAvailable(Context context) {
String name = Build.IS_DEBUGGABLE ? SystemProperties.get("debug.doze.component") : null;
if (TextUtils.isEmpty(name)) {
name = context.getResources().getString(
com.android.internal.R.string.config_dozeComponent);
}
return !TextUtils.isEmpty(name);
}
private static boolean isTapToWakeAvailable(Resources res) {
return res.getBoolean(com.android.internal.R.bool.config_supportDoubleTapWake);
}
private static boolean isAutomaticBrightnessAvailable(Resources res) {
return res.getBoolean(com.android.internal.R.bool.config_automatic_brightness_available);
}
private static boolean isCameraGestureAvailable(Resources res) {
boolean configSet = res.getInteger(
com.android.internal.R.integer.config_cameraLaunchGestureSensorType) != -1;
return configSet &&
!SystemProperties.getBoolean("gesture.disable_camera_launch", false);
}
private static boolean isVrDisplayModeAvailable(Context context) {
PackageManager pm = context.getPackageManager();
return pm.hasSystemFeature(PackageManager.FEATURE_VR_MODE_HIGH_PERFORMANCE);
}
private void updateTimeoutPreferenceDescription(long currentTimeout) {
TimeoutListPreference preference = mScreenTimeoutPreference;
final CharSequence[] entries = preference.getEntries();
final CharSequence[] values = preference.getEntryValues();
String summary;
if (preference.isDisabledByAdmin()) {
summary = getString(R.string.disabled_by_policy_title);
} else {
CharSequence timeoutDescription = getTimeoutDescription(
currentTimeout, entries, values);
summary = timeoutDescription == null ? ""
: getString(R.string.screen_timeout_summary, timeoutDescription);
}
preference.setSummary(summary);
}
private static CharSequence getTimeoutDescription(
long currentTimeout, CharSequence[] entries, CharSequence[] values) {
if (currentTimeout < 0 || entries == null || values == null
|| values.length != entries.length) {
return null;
}
for (int i = 0; i < values.length; i++) {
long timeout = Long.parseLong(values[i].toString());
if (currentTimeout == timeout) {
return entries[i];
}
}
return null;
protected String getLogTag() {
return TAG;
}
@Override
public void onResume() {
super.onResume();
updateState();
final long currentTimeout = Settings.System.getLong(getActivity().getContentResolver(),
SCREEN_OFF_TIMEOUT, FALLBACK_SCREEN_TIMEOUT_VALUE);
mScreenTimeoutPreference.setValue(String.valueOf(currentTimeout));
mScreenTimeoutPreference.setOnPreferenceChangeListener(this);
final DevicePolicyManager dpm = (DevicePolicyManager) getActivity().getSystemService(
Context.DEVICE_POLICY_SERVICE);
if (dpm != null) {
final EnforcedAdmin admin = RestrictedLockUtils.checkIfMaximumTimeToLockIsSet(
getActivity());
final long maxTimeout = dpm
.getMaximumTimeToLockForUserAndProfiles(UserHandle.myUserId());
mScreenTimeoutPreference.removeUnusableTimeouts(maxTimeout, admin);
}
updateTimeoutPreferenceDescription(currentTimeout);
disablePreferenceIfManaged(KEY_WALLPAPER, UserManager.DISALLOW_SET_WALLPAPER);
}
private void updateState() {
updateFontSizeSummary();
updateScreenSaverSummary();
// Update auto brightness if it is available.
if (mAutoBrightnessPreference != null) {
int brightnessMode = Settings.System.getInt(getContentResolver(),
SCREEN_BRIGHTNESS_MODE, SCREEN_BRIGHTNESS_MODE_MANUAL);
mAutoBrightnessPreference.setChecked(brightnessMode != SCREEN_BRIGHTNESS_MODE_MANUAL);
}
// Update lift-to-wake if it is available.
if (mLiftToWakePreference != null) {
int value = Settings.Secure.getInt(getContentResolver(), WAKE_GESTURE_ENABLED, 0);
mLiftToWakePreference.setChecked(value != 0);
}
// Update tap to wake if it is available.
if (mTapToWakePreference != null) {
int value = Settings.Secure.getInt(getContentResolver(), DOUBLE_TAP_TO_WAKE, 0);
mTapToWakePreference.setChecked(value != 0);
}
// Update doze if it is available.
if (mDozePreference != null) {
int value = Settings.Secure.getInt(getContentResolver(), DOZE_ENABLED, 1);
mDozePreference.setChecked(value != 0);
}
// Update camera gesture #1 if it is available.
if (mCameraGesturePreference != null) {
int value = Settings.Secure.getInt(getContentResolver(), CAMERA_GESTURE_DISABLED, 0);
mCameraGesturePreference.setChecked(value == 0);
}
}
private void updateScreenSaverSummary() {
if (mScreenSaverPreference != null) {
mScreenSaverPreference.setSummary(
DreamSettings.getSummaryTextWithDreamName(getActivity()));
}
}
private void updateFontSizeSummary() {
final Context context = mFontSizePref.getContext();
final float currentScale = Settings.System.getFloat(context.getContentResolver(),
Settings.System.FONT_SCALE, 1.0f);
final Resources res = context.getResources();
final String[] entries = res.getStringArray(R.array.entries_font_size);
final String[] strEntryValues = res.getStringArray(R.array.entryvalues_font_size);
final int index = ToggleFontSizePreferenceFragment.fontSizeValueToIndex(currentScale,
strEntryValues);
mFontSizePref.setSummary(entries[index]);
protected String getCategoryKey() {
return CategoryKey.CATEGORY_DISPLAY;
}
@Override
public boolean onPreferenceChange(Preference preference, Object objValue) {
final String key = preference.getKey();
if (KEY_SCREEN_TIMEOUT.equals(key)) {
try {
int value = Integer.parseInt((String) objValue);
Settings.System.putInt(getContentResolver(), SCREEN_OFF_TIMEOUT, value);
updateTimeoutPreferenceDescription(value);
} catch (NumberFormatException e) {
Log.e(TAG, "could not persist screen timeout setting", e);
}
}
if (preference == mAutoBrightnessPreference) {
boolean auto = (Boolean) objValue;
Settings.System.putInt(getContentResolver(), SCREEN_BRIGHTNESS_MODE,
auto ? SCREEN_BRIGHTNESS_MODE_AUTOMATIC : SCREEN_BRIGHTNESS_MODE_MANUAL);
}
if (preference == mLiftToWakePreference) {
boolean value = (Boolean) objValue;
Settings.Secure.putInt(getContentResolver(), WAKE_GESTURE_ENABLED, value ? 1 : 0);
}
if (preference == mDozePreference) {
boolean value = (Boolean) objValue;
Settings.Secure.putInt(getContentResolver(), DOZE_ENABLED, value ? 1 : 0);
}
if (preference == mTapToWakePreference) {
boolean value = (Boolean) objValue;
Settings.Secure.putInt(getContentResolver(), DOUBLE_TAP_TO_WAKE, value ? 1 : 0);
}
if (preference == mCameraGesturePreference) {
boolean value = (Boolean) objValue;
Settings.Secure.putInt(getContentResolver(), CAMERA_GESTURE_DISABLED,
value ? 0 : 1 /* Backwards because setting is for disabling */);
}
if (preference == mNightModePreference) {
try {
final int value = Integer.parseInt((String) objValue);
final UiModeManager uiManager = (UiModeManager) getSystemService(
Context.UI_MODE_SERVICE);
uiManager.setNightMode(value);
} catch (NumberFormatException e) {
Log.e(TAG, "could not persist night mode setting", e);
}
}
return true;
protected int getPreferenceScreenResId() {
return R.xml.display_settings;
}
@Override
public boolean onPreferenceTreeClick(Preference preference) {
if (preference == mDozePreference) {
mMetricsFeatureProvider.action(getActivity(), MetricsEvent.ACTION_AMBIENT_DISPLAY);
}
return super.onPreferenceTreeClick(preference);
protected List<PreferenceController> getPreferenceControllers(Context context) {
final List<PreferenceController> controllers = new ArrayList<>();
controllers.add(new AutoBrightnessPreferenceController(context));
controllers.add(new AutoRotatePreferenceController(context));
controllers.add(new CameraGesturePreferenceController(context));
controllers.add(new DozePreferenceController(context));
controllers.add(new FontSizePreferenceController(context));
controllers.add(new LiftToWakePreferenceController(context));
controllers.add(new NightDisplayPreferenceController(context));
controllers.add(new NightModePreferenceController(context));
controllers.add(new ScreenSaverPreferenceController(context));
controllers.add(new TapToWakePreferenceController(context));
controllers.add(new TimeoutPreferenceController(context));
controllers.add(new VrDisplayPreferenceController(context));
controllers.add(new WallpaperPreferenceController(context));
return controllers;
}
@Override
@@ -453,19 +94,6 @@ public class DisplaySettings extends SettingsPreferenceFragment implements
return R.string.help_uri_display;
}
private void disablePreferenceIfManaged(String key, String restriction) {
final RestrictedPreference pref = (RestrictedPreference) findPreference(key);
if (pref != null) {
pref.setDisabledByAdmin(null);
if (RestrictedLockUtils.hasBaseUserRestriction(getActivity(), restriction,
UserHandle.myUserId())) {
pref.setEnabled(false);
} else {
pref.checkRestrictionAndSetDisabled(restriction);
}
}
}
private static class SummaryProvider implements SummaryLoader.SummaryProvider {
private final Context mContext;
private final SummaryLoader mLoader;
@@ -484,13 +112,13 @@ public class DisplaySettings extends SettingsPreferenceFragment implements
private void updateSummary() {
final long currentTimeout = Settings.System.getLong(mContext.getContentResolver(),
SCREEN_OFF_TIMEOUT, FALLBACK_SCREEN_TIMEOUT_VALUE);
SCREEN_OFF_TIMEOUT, TimeoutPreferenceController.FALLBACK_SCREEN_TIMEOUT_VALUE);
final CharSequence[] entries =
mContext.getResources().getTextArray(R.array.screen_timeout_entries);
final CharSequence[] values =
mContext.getResources().getTextArray(R.array.screen_timeout_values);
final CharSequence timeoutDescription = getTimeoutDescription(
currentTimeout, entries, values);
final CharSequence timeoutDescription = TimeoutPreferenceController
.getTimeoutDescription(currentTimeout, entries, values);
final String summary = timeoutDescription == null ? ""
: mContext.getString(R.string.display_summary, timeoutDescription);
mLoader.setSummary(this, summary);
@@ -501,7 +129,7 @@ public class DisplaySettings extends SettingsPreferenceFragment implements
= new SummaryLoader.SummaryProviderFactory() {
@Override
public SummaryLoader.SummaryProvider createSummaryProvider(Activity activity,
SummaryLoader summaryLoader) {
SummaryLoader summaryLoader) {
return new SummaryProvider(activity, summaryLoader);
}
};
@@ -511,8 +139,7 @@ public class DisplaySettings extends SettingsPreferenceFragment implements
@Override
public List<SearchIndexableResource> getXmlResourcesToIndex(Context context,
boolean enabled) {
ArrayList<SearchIndexableResource> result =
new ArrayList<SearchIndexableResource>();
ArrayList<SearchIndexableResource> result = new ArrayList<>();
SearchIndexableResource sir = new SearchIndexableResource(context);
sir.xmlResId = R.xml.display_settings;
@@ -523,35 +150,22 @@ public class DisplaySettings extends SettingsPreferenceFragment implements
@Override
public List<String> getNonIndexableKeys(Context context) {
ArrayList<String> result = new ArrayList<String>();
if (!context.getResources().getBoolean(
com.android.internal.R.bool.config_dreamsSupported)) {
result.add(KEY_SCREEN_SAVER);
}
if (!isAutomaticBrightnessAvailable(context.getResources())) {
result.add(KEY_AUTO_BRIGHTNESS);
}
if (!NightDisplayController.isAvailable(context)) {
result.add(KEY_NIGHT_DISPLAY);
}
if (!isLiftToWakeAvailable(context)) {
result.add(KEY_LIFT_TO_WAKE);
}
if (!isDozeAvailable(context)) {
result.add(KEY_DOZE);
}
if (!RotationPolicy.isRotationLockToggleVisible(context)) {
result.add(KEY_AUTO_ROTATE);
}
if (!isTapToWakeAvailable(context.getResources())) {
result.add(KEY_TAP_TO_WAKE);
}
if (!isCameraGestureAvailable(context.getResources())) {
result.add(KEY_CAMERA_GESTURE);
}
if (!isVrDisplayModeAvailable(context)) {
result.add(KEY_VR_DISPLAY_PREF);
}
ArrayList<String> result = new ArrayList<>();
new AutoBrightnessPreferenceController(context).updateNonIndexableKeys(result);
new AutoRotatePreferenceController(context).updateNonIndexableKeys(result);
new CameraGesturePreferenceController(context).updateNonIndexableKeys(result);
new DozePreferenceController(context).updateNonIndexableKeys(result);
new FontSizePreferenceController(context).updateNonIndexableKeys(result);
new LiftToWakePreferenceController(context).updateNonIndexableKeys(result);
new NightDisplayPreferenceController(context).updateNonIndexableKeys(result);
new NightModePreferenceController(context).updateNonIndexableKeys(result);
new ScreenSaverPreferenceController(context).updateNonIndexableKeys(result);
new TapToWakePreferenceController(context).updateNonIndexableKeys(result);
new TimeoutPreferenceController(context).updateNonIndexableKeys(result);
new VrDisplayPreferenceController(context).updateNonIndexableKeys(result);
new WallpaperPreferenceController(context).updateNonIndexableKeys(result);
return result;
}
};

View File

@@ -164,6 +164,7 @@ public class Settings extends SettingsActivity {
public static class SystemSettings extends SettingsActivity { /* empty */ }
// Top level categories for new IA
public static class DisplayDashboardActivity extends SettingsActivity {}
public static class StorageDashboardActivity extends SettingsActivity {}
public static class SystemDashboardActivity extends SettingsActivity {}
public static class SupportDashboardActivity extends SettingsActivity {}

View File

@@ -271,6 +271,7 @@ public class SettingsActivity extends SettingsDrawerActivity
// New IA
// Home page
"com.android.settings.Settings.BatteryDashboardAlias",
"com.android.settings.Settings.DisplayDashboardAlias",
Settings.SystemDashboardActivity.class.getName(),
Settings.SupportDashboardActivity.class.getName(),
// Home page > System

View File

@@ -35,7 +35,34 @@ public abstract class PreferenceController {
/**
* Displays preference in this controller.
*/
public abstract void displayPreference(PreferenceScreen screen);
public void displayPreference(PreferenceScreen screen) {
if (isAvailable()) {
if (this instanceof Preference.OnPreferenceChangeListener) {
final Preference preference = screen.findPreference(getPreferenceKey());
preference.setOnPreferenceChangeListener(
(Preference.OnPreferenceChangeListener) this);
}
} else {
removePreference(screen, getPreferenceKey());
}
}
/**
* Updates the current status of preference (summary, switch state, etc)
*/
public void updateState(PreferenceScreen screen) {
}
/**
* Updates non-indexable keys for search provider.
*
* Called by SearchIndexProvider#getNonIndexableKeys
*/
public void updateNonIndexableKeys(List<String> keys) {
if (!isAvailable()) {
keys.add(getPreferenceKey());
}
}
/**
* Handles preference tree click
@@ -45,13 +72,6 @@ public abstract class PreferenceController {
*/
public abstract boolean handlePreferenceTreeClick(Preference preference);
/**
* Updates non-indexable keys for search provider.
*
* Called by SearchIndexProvider#getNonIndexableKeys
*/
public abstract void updateNonIndexableKeys(List<String> keys);
/**
* Removes preference from screen.
*/
@@ -62,4 +82,14 @@ public abstract class PreferenceController {
}
}
/**
* Returns true if preference is available (should be displayed)
*/
protected abstract boolean isAvailable();
/**
* Returns the key for this preference.
*/
protected abstract String getPreferenceKey();
}

View File

@@ -55,6 +55,14 @@ public abstract class DashboardFragment extends SettingsPreferenceFragment
super.onAttach(context);
mDashboardFeatureProvider =
FeatureFactory.getFactory(context).getDashboardFeatureProvider(context);
final List<PreferenceController> controllers = getPreferenceControllers(context);
if (controllers == null) {
return;
}
for (PreferenceController controller : controllers) {
addPreferenceController(controller);
}
}
@Override
@@ -81,7 +89,10 @@ public abstract class DashboardFragment extends SettingsPreferenceFragment
if (category == null) {
return;
}
mSummaryLoader.setListening(true);
if (mSummaryLoader != null) {
// SummaryLoader can be null when there is no dynamic tiles.
mSummaryLoader.setListening(true);
}
final Activity activity = getActivity();
if (activity instanceof SettingsDrawerActivity) {
mListeningToCategoryChange = true;
@@ -102,6 +113,12 @@ public abstract class DashboardFragment extends SettingsPreferenceFragment
pref.setSummary(tile.summary);
}
@Override
public void onResume() {
super.onResume();
updatePreferenceStates();
}
@Override
public boolean onPreferenceTreeClick(Preference preference) {
Collection<PreferenceController> controllers = mPreferenceControllers.values();
@@ -117,7 +134,10 @@ public abstract class DashboardFragment extends SettingsPreferenceFragment
@Override
public void onStop() {
super.onStop();
mSummaryLoader.setListening(false);
if (mSummaryLoader != null) {
// SummaryLoader can be null when there is no dynamic tiles.
mSummaryLoader.setListening(false);
}
if (mListeningToCategoryChange) {
final Activity activity = getActivity();
if (activity instanceof SettingsDrawerActivity) {
@@ -141,12 +161,36 @@ public abstract class DashboardFragment extends SettingsPreferenceFragment
*/
protected abstract String getCategoryKey();
/**
* Get the tag string for logging.
*/
protected abstract String getLogTag();
/**
* Get the res id for static preference xml for this fragment.
*/
protected abstract int getPreferenceScreenResId();
/**
* Get a list of {@link PreferenceController} for this fragment.
*/
protected abstract List<PreferenceController> getPreferenceControllers(Context context);
/**
* Displays resource based tiles.
*/
protected abstract void displayResourceTiles();
protected abstract String getLogTag();
private void displayResourceTiles() {
final int resId = getPreferenceScreenResId();
if (resId <= 0) {
return;
}
addPreferencesFromResource(resId);
final PreferenceScreen screen = getPreferenceScreen();
Collection<PreferenceController> controllers = mPreferenceControllers.values();
for (PreferenceController controller : controllers) {
controller.displayPreference(screen);
}
}
/**
* Displays dashboard tiles as preference.
@@ -195,6 +239,17 @@ public abstract class DashboardFragment extends SettingsPreferenceFragment
}
}
/**
* Update state of each preference managed by PreferenceController.
*/
private void updatePreferenceStates() {
Collection<PreferenceController> controllers = mPreferenceControllers.values();
final PreferenceScreen screen = getPreferenceScreen();
for (PreferenceController controller : controllers) {
controller.updateState(screen);
}
}
/**
* Refresh preference items using system category dashboard items.
*/
@@ -206,6 +261,7 @@ public abstract class DashboardFragment extends SettingsPreferenceFragment
}
// Add resource based tiles.
displayResourceTiles();
// Add dashboard tiles.
displayDashboardTiles(TAG, getPreferenceScreen());
}

View File

@@ -86,7 +86,13 @@ public class SummaryLoader {
mWorker = new Worker(mWorkerThread.getLooper());
mActivity = activity;
List<Tile> tiles = mDashboardFeatureProvider.getTilesForCategory(categoryKey).tiles;
final DashboardCategory category =
mDashboardFeatureProvider.getTilesForCategory(categoryKey);
if (category == null || category.tiles == null) {
return;
}
List<Tile> tiles = category.tiles;
for (Tile tile : tiles) {
mWorker.obtainMessage(Worker.MSG_GET_PROVIDER, tile).sendToTarget();
}
@@ -258,6 +264,9 @@ public class SummaryLoader {
}
private Tile getTileFromCategory(DashboardCategory category, ComponentName component) {
if (category == null || category.tiles == null) {
return null;
}
final int tileCount = category.tiles.size();
for (int j = 0; j < tileCount; j++) {
final Tile tile = category.tiles.get(j);

View File

@@ -0,0 +1,46 @@
/*
* Copyright (C) 2016 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.deviceinfo;
import android.content.Context;
import android.support.v7.preference.Preference;
import com.android.settings.core.PreferenceController;
public class AdditionalSystemUpdatePreferenceController extends PreferenceController {
private static final String KEY_UPDATE_SETTING = "additional_system_update_settings";
public AdditionalSystemUpdatePreferenceController(Context context) {
super(context);
}
@Override
public boolean handlePreferenceTreeClick(Preference preference) {
return false;
}
@Override
protected boolean isAvailable() {
return mContext.getResources().getBoolean(
com.android.settings.R.bool.config_additional_system_update_setting_enable);
}
@Override
protected String getPreferenceKey() {
return KEY_UPDATE_SETTING;
}
}

View File

@@ -33,17 +33,8 @@ public class ManageStoragePreferenceController extends PreferenceController {
}
@Override
public void displayPreference(PreferenceScreen screen) {
if (!isAvailable()) {
removePreference(screen, KEY_MANAGE_STORAGE);
}
}
@Override
public void updateNonIndexableKeys(List<String> keys) {
if (!isAvailable()) {
keys.add(KEY_MANAGE_STORAGE);
}
protected String getPreferenceKey() {
return KEY_MANAGE_STORAGE;
}
@Override
@@ -51,10 +42,8 @@ public class ManageStoragePreferenceController extends PreferenceController {
return false;
}
/**
* Whether a preference should be available on screen.
*/
private boolean isAvailable() {
@Override
protected boolean isAvailable() {
return mContext.getResources().getBoolean(R.bool.config_storage_manager_settings_enabled);
}
}

View File

@@ -20,6 +20,7 @@ import android.content.Context;
import android.provider.SearchIndexableResource;
import com.android.settings.R;
import com.android.settings.core.PreferenceController;
import com.android.settings.dashboard.DashboardFragment;
import com.android.settings.overlay.FeatureFactory;
import com.android.settings.search.BaseSearchIndexProvider;
@@ -44,23 +45,21 @@ public class StorageDashboardFragment extends DashboardFragment {
return TAG;
}
@Override
public void onAttach(Context context) {
super.onAttach(context);
addPreferenceController(new ManageStoragePreferenceController(context));
}
@Override
protected String getCategoryKey() {
return CategoryKey.CATEGORY_STORAGE;
}
@Override
protected void displayResourceTiles() {
addPreferencesFromResource(R.xml.storage_dashboard_fragment);
protected int getPreferenceScreenResId() {
return R.xml.storage_dashboard_fragment;
}
getPreferenceController(ManageStoragePreferenceController.class)
.displayPreference(getPreferenceScreen());
@Override
protected List<PreferenceController> getPreferenceControllers(Context context) {
final List<PreferenceController> controllers = new ArrayList<>();
controllers.add(new ManageStoragePreferenceController(context));
return controllers;
}
/**

View File

@@ -25,7 +25,6 @@ import android.telephony.CarrierConfigManager;
import android.text.TextUtils;
import android.util.Log;
import com.android.settings.R;
import com.android.settings.Utils;
import com.android.settings.core.PreferenceController;
@@ -37,8 +36,7 @@ public class SystemUpdatePreferenceController extends PreferenceController {
private static final String TAG = "SysUpdatePrefContr";
static final String KEY_SYSTEM_UPDATE_SETTINGS = "system_update_settings";
static final String KEY_UPDATE_SETTING = "additional_system_update_settings";
private static final String KEY_SYSTEM_UPDATE_SETTINGS = "system_update_settings";
private final UserManager mUm;
@@ -47,30 +45,33 @@ public class SystemUpdatePreferenceController extends PreferenceController {
mUm = um;
}
@Override
protected boolean isAvailable() {
return mUm.isAdminUser();
}
@Override
protected String getPreferenceKey() {
return KEY_SYSTEM_UPDATE_SETTINGS;
}
@Override
public void displayPreference(PreferenceScreen screen) {
if (isAvailable(mContext, KEY_SYSTEM_UPDATE_SETTINGS)) {
if (isAvailable()) {
Utils.updatePreferenceToSpecificActivityOrRemove(mContext, screen,
KEY_SYSTEM_UPDATE_SETTINGS,
Utils.UPDATE_PREFERENCE_FLAG_SET_TITLE_TO_MATCHING_ACTIVITY);
} else {
removePreference(screen, KEY_SYSTEM_UPDATE_SETTINGS);
}
if (!isAvailable(mContext, KEY_UPDATE_SETTING)) {
removePreference(screen, KEY_UPDATE_SETTING);
}
}
@Override
public void updateNonIndexableKeys(List<String> keys) {
// TODO: system update needs to be fixed for non-owner user b/22760654
if (!isAvailable(mContext, KEY_SYSTEM_UPDATE_SETTINGS)) {
if (!isAvailable()) {
keys.add(KEY_SYSTEM_UPDATE_SETTINGS);
}
if (!isAvailable(mContext, KEY_UPDATE_SETTING)) {
keys.add(KEY_UPDATE_SETTING);
}
}
@Override
@@ -87,21 +88,6 @@ public class SystemUpdatePreferenceController extends PreferenceController {
return false;
}
/**
* Whether a preference should be available on screen.
*/
private boolean isAvailable(Context context, String key) {
switch (key) {
case KEY_SYSTEM_UPDATE_SETTINGS:
return mUm.isAdminUser();
case KEY_UPDATE_SETTING:
return context.getResources().getBoolean(
R.bool.config_additional_system_update_setting_enable);
default:
return false;
}
}
/**
* Trigger client initiated action (send intent) on system update
*/

View File

@@ -0,0 +1,73 @@
/*
* Copyright (C) 2016 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.provider.Settings;
import android.support.v14.preference.SwitchPreference;
import android.support.v7.preference.Preference;
import android.support.v7.preference.PreferenceScreen;
import com.android.settings.core.PreferenceController;
import static android.provider.Settings.System.SCREEN_BRIGHTNESS_MODE;
import static android.provider.Settings.System.SCREEN_BRIGHTNESS_MODE_AUTOMATIC;
import static android.provider.Settings.System.SCREEN_BRIGHTNESS_MODE_MANUAL;
public class AutoBrightnessPreferenceController extends PreferenceController implements
Preference.OnPreferenceChangeListener {
private static final String KEY_AUTO_BRIGHTNESS = "auto_brightness";
public AutoBrightnessPreferenceController(Context context) {
super(context);
}
@Override
protected boolean isAvailable() {
return mContext.getResources().getBoolean(
com.android.internal.R.bool.config_automatic_brightness_available);
}
@Override
protected String getPreferenceKey() {
return KEY_AUTO_BRIGHTNESS;
}
@Override
public boolean handlePreferenceTreeClick(Preference preference) {
return false;
}
@Override
public void updateState(PreferenceScreen screen) {
final SwitchPreference preference =
(SwitchPreference) screen.findPreference(KEY_AUTO_BRIGHTNESS);
if (preference == null) {
return;
}
int brightnessMode = Settings.System.getInt(mContext.getContentResolver(),
SCREEN_BRIGHTNESS_MODE, SCREEN_BRIGHTNESS_MODE_MANUAL);
preference.setChecked(brightnessMode != SCREEN_BRIGHTNESS_MODE_MANUAL);
}
@Override
public boolean onPreferenceChange(Preference preference, Object newValue) {
boolean auto = (Boolean) newValue;
Settings.System.putInt(mContext.getContentResolver(), SCREEN_BRIGHTNESS_MODE,
auto ? SCREEN_BRIGHTNESS_MODE_AUTOMATIC : SCREEN_BRIGHTNESS_MODE_MANUAL);
return true;
}
}

View File

@@ -0,0 +1,96 @@
/*
* Copyright (C) 2016 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.content.res.Configuration;
import android.support.v7.preference.DropDownPreference;
import android.support.v7.preference.Preference;
import android.support.v7.preference.PreferenceScreen;
import com.android.internal.logging.MetricsProto;
import com.android.internal.view.RotationPolicy;
import com.android.settings.R;
import com.android.settings.core.PreferenceController;
import com.android.settings.core.instrumentation.MetricsFeatureProvider;
import com.android.settings.overlay.FeatureFactory;
public class AutoRotatePreferenceController extends PreferenceController implements
Preference.OnPreferenceChangeListener {
private static final String KEY_AUTO_ROTATE = "auto_rotate";
private final MetricsFeatureProvider mMetricsFeatureProvider;
public AutoRotatePreferenceController(Context context) {
super(context);
mMetricsFeatureProvider = FeatureFactory.getFactory(context).getMetricsFeatureProvider();
}
@Override
protected String getPreferenceKey() {
return KEY_AUTO_ROTATE;
}
@Override
public void updateState(PreferenceScreen screen) {
final DropDownPreference rotatePreference =
(DropDownPreference) screen.findPreference(KEY_AUTO_ROTATE);
final int rotateLockedResourceId;
// The following block sets the string used when rotation is locked.
// If the device locks specifically to portrait or landscape (rather than current
// rotation), then we use a different string to include this information.
if (allowAllRotations()) {
rotateLockedResourceId = R.string.display_auto_rotate_stay_in_current;
} else {
if (RotationPolicy.getRotationLockOrientation(mContext)
== Configuration.ORIENTATION_PORTRAIT) {
rotateLockedResourceId = R.string.display_auto_rotate_stay_in_portrait;
} else {
rotateLockedResourceId = R.string.display_auto_rotate_stay_in_landscape;
}
}
rotatePreference.setEntries(new CharSequence[]{
mContext.getString(R.string.display_auto_rotate_rotate),
mContext.getString(rotateLockedResourceId),
});
rotatePreference.setEntryValues(new CharSequence[]{"0", "1"});
rotatePreference.setValueIndex(RotationPolicy.isRotationLocked(mContext) ?
1 : 0);
}
@Override
public boolean handlePreferenceTreeClick(Preference preference) {
return false;
}
@Override
protected boolean isAvailable() {
return RotationPolicy.isRotationLockToggleVisible(mContext);
}
private boolean allowAllRotations() {
return mContext.getResources().getBoolean(
com.android.internal.R.bool.config_allowAllRotations);
}
@Override
public boolean onPreferenceChange(Preference preference, Object newValue) {
final boolean locked = Integer.parseInt((String) newValue) != 0;
mMetricsFeatureProvider.action(mContext, MetricsProto.MetricsEvent.ACTION_ROTATION_LOCK,
locked);
RotationPolicy.setRotationLock(mContext, locked);
return true;
}
}

View File

@@ -0,0 +1,72 @@
/*
* Copyright (C) 2016 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.SystemProperties;
import android.provider.Settings;
import android.support.v14.preference.SwitchPreference;
import android.support.v7.preference.Preference;
import android.support.v7.preference.PreferenceScreen;
import com.android.settings.core.PreferenceController;
import static android.provider.Settings.Secure.CAMERA_GESTURE_DISABLED;
public class CameraGesturePreferenceController extends PreferenceController implements
Preference.OnPreferenceChangeListener {
private static final String KEY_CAMERA_GESTURE = "camera_gesture";
public CameraGesturePreferenceController(Context context) {
super(context);
}
@Override
protected String getPreferenceKey() {
return KEY_CAMERA_GESTURE;
}
@Override
public boolean handlePreferenceTreeClick(Preference preference) {
return false;
}
@Override
public void updateState(PreferenceScreen screen) {
final SwitchPreference preference =
(SwitchPreference) screen.findPreference(KEY_CAMERA_GESTURE);
if (preference != null) {
int value = Settings.Secure.getInt(mContext.getContentResolver(),
CAMERA_GESTURE_DISABLED, 0);
preference.setChecked(value == 0);
}
}
@Override
protected boolean isAvailable() {
boolean configSet = mContext.getResources().getInteger(
com.android.internal.R.integer.config_cameraLaunchGestureSensorType) != -1;
return configSet
&& !SystemProperties.getBoolean("gesture.disable_camera_launch", false);
}
@Override
public boolean onPreferenceChange(Preference preference, Object newValue) {
boolean value = (Boolean) newValue;
Settings.Secure.putInt(mContext.getContentResolver(), CAMERA_GESTURE_DISABLED,
value ? 0 : 1 /* Backwards because setting is for disabling */);
return true;
}
}

View File

@@ -0,0 +1,83 @@
/*
* Copyright (C) 2016 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.Build;
import android.os.SystemProperties;
import android.provider.Settings;
import android.support.v14.preference.SwitchPreference;
import android.support.v7.preference.Preference;
import android.support.v7.preference.PreferenceScreen;
import android.text.TextUtils;
import com.android.settings.core.PreferenceController;
import com.android.settings.core.instrumentation.MetricsFeatureProvider;
import com.android.settings.overlay.FeatureFactory;
import static android.provider.Settings.Secure.DOZE_ENABLED;
import static com.android.internal.logging.MetricsProto.MetricsEvent.ACTION_AMBIENT_DISPLAY;
public class DozePreferenceController extends PreferenceController implements
Preference.OnPreferenceChangeListener {
private static final String KEY_DOZE = "doze";
private final MetricsFeatureProvider mMetricsFeatureProvider;
public DozePreferenceController(Context context) {
super(context);
mMetricsFeatureProvider = FeatureFactory.getFactory(context).getMetricsFeatureProvider();
}
@Override
protected String getPreferenceKey() {
return KEY_DOZE;
}
@Override
public boolean handlePreferenceTreeClick(Preference preference) {
if (KEY_DOZE.equals(preference.getKey())) {
mMetricsFeatureProvider.action(mContext, ACTION_AMBIENT_DISPLAY);
}
return false;
}
@Override
public void updateState(PreferenceScreen screen) {
final SwitchPreference preference = (SwitchPreference) screen.findPreference(KEY_DOZE);
// Update doze if it is available.
if (preference != null) {
int value = Settings.Secure.getInt(mContext.getContentResolver(), DOZE_ENABLED, 1);
preference.setChecked(value != 0);
}
}
@Override
public boolean onPreferenceChange(Preference preference, Object newValue) {
boolean value = (Boolean) newValue;
Settings.Secure.putInt(mContext.getContentResolver(), DOZE_ENABLED, value ? 1 : 0);
return true;
}
@Override
protected boolean isAvailable() {
String name = Build.IS_DEBUGGABLE ? SystemProperties.get("debug.doze.component") : null;
if (TextUtils.isEmpty(name)) {
name = mContext.getResources().getString(
com.android.internal.R.string.config_dozeComponent);
}
return !TextUtils.isEmpty(name);
}
}

View File

@@ -0,0 +1,64 @@
/*
* Copyright (C) 2016 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.content.res.Resources;
import android.provider.Settings;
import android.support.v7.preference.Preference;
import android.support.v7.preference.PreferenceScreen;
import com.android.settings.R;
import com.android.settings.accessibility.ToggleFontSizePreferenceFragment;
import com.android.settings.core.PreferenceController;
public class FontSizePreferenceController extends PreferenceController {
private static final String KEY_FONT_SIZE = "font_size";
public FontSizePreferenceController(Context context) {
super(context);
}
@Override
protected boolean isAvailable() {
return true;
}
@Override
protected String getPreferenceKey() {
return KEY_FONT_SIZE;
}
@Override
public void updateState(PreferenceScreen screen) {
final Preference preference = screen.findPreference(KEY_FONT_SIZE);
if (preference == null) {
return;
}
final float currentScale = Settings.System.getFloat(mContext.getContentResolver(),
Settings.System.FONT_SCALE, 1.0f);
final Resources res = mContext.getResources();
final String[] entries = res.getStringArray(R.array.entries_font_size);
final String[] strEntryValues = res.getStringArray(R.array.entryvalues_font_size);
final int index = ToggleFontSizePreferenceFragment.fontSizeValueToIndex(currentScale,
strEntryValues);
preference.setSummary(entries[index]);
}
@Override
public boolean handlePreferenceTreeClick(Preference preference) {
return false;
}
}

View File

@@ -0,0 +1,70 @@
/*
* Copyright (C) 2016 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.hardware.Sensor;
import android.hardware.SensorManager;
import android.provider.Settings;
import android.support.v14.preference.SwitchPreference;
import android.support.v7.preference.Preference;
import android.support.v7.preference.PreferenceScreen;
import com.android.settings.core.PreferenceController;
import static android.provider.Settings.Secure.WAKE_GESTURE_ENABLED;
public class LiftToWakePreferenceController extends PreferenceController implements
Preference.OnPreferenceChangeListener {
private static final String KEY_LIFT_TO_WAKE = "lift_to_wake";
public LiftToWakePreferenceController(Context context) {
super(context);
}
@Override
protected boolean isAvailable() {
SensorManager sensors = (SensorManager) mContext.getSystemService(Context.SENSOR_SERVICE);
return sensors != null && sensors.getDefaultSensor(Sensor.TYPE_WAKE_GESTURE) != null;
}
@Override
protected String getPreferenceKey() {
return KEY_LIFT_TO_WAKE;
}
@Override
public boolean handlePreferenceTreeClick(Preference preference) {
return false;
}
@Override
public boolean onPreferenceChange(Preference preference, Object newValue) {
boolean value = (Boolean) newValue;
Settings.Secure.putInt(mContext.getContentResolver(), WAKE_GESTURE_ENABLED, value ? 1 : 0);
return true;
}
@Override
public void updateState(PreferenceScreen screen) {
final SwitchPreference pref = (SwitchPreference) screen.findPreference(KEY_LIFT_TO_WAKE);
// Update lift-to-wake if it is available.
if (pref != null) {
int value =
Settings.Secure.getInt(mContext.getContentResolver(), WAKE_GESTURE_ENABLED, 0);
pref.setChecked(value != 0);
}
}
}

View File

@@ -0,0 +1,44 @@
/*
* Copyright (C) 2016 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.support.v7.preference.Preference;
import com.android.internal.app.NightDisplayController;
import com.android.settings.core.PreferenceController;
public class NightDisplayPreferenceController extends PreferenceController {
private static final String KEY_NIGHT_DISPLAY = "night_display";
public NightDisplayPreferenceController(Context context) {
super(context);
}
@Override
public boolean handlePreferenceTreeClick(Preference preference) {
return false;
}
@Override
protected boolean isAvailable() {
return NightDisplayController.isAvailable(mContext);
}
@Override
protected String getPreferenceKey() {
return KEY_NIGHT_DISPLAY;
}
}

View File

@@ -0,0 +1,82 @@
/*
* Copyright (C) 2016 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.app.UiModeManager;
import android.content.Context;
import android.support.v7.preference.ListPreference;
import android.support.v7.preference.Preference;
import android.support.v7.preference.PreferenceScreen;
import android.util.Log;
import com.android.settings.core.PreferenceController;
import static android.content.Context.UI_MODE_SERVICE;
public class NightModePreferenceController extends PreferenceController
implements Preference.OnPreferenceChangeListener {
private static final String TAG = "NightModePrefContr";
private static final String KEY_NIGHT_MODE = "night_mode";
public NightModePreferenceController(Context context) {
super(context);
}
@Override
protected boolean isAvailable() {
return false;
}
@Override
protected String getPreferenceKey() {
return KEY_NIGHT_MODE;
}
@Override
public void displayPreference(PreferenceScreen screen) {
if (!isAvailable()) {
removePreference(screen, KEY_NIGHT_MODE);
return;
}
ListPreference mNightModePreference = (ListPreference) screen.findPreference(
KEY_NIGHT_MODE);
if (mNightModePreference != null) {
final UiModeManager uiManager =
(UiModeManager) mContext.getSystemService(UI_MODE_SERVICE);
final int currentNightMode = uiManager.getNightMode();
mNightModePreference.setValue(String.valueOf(currentNightMode));
mNightModePreference.setOnPreferenceChangeListener(this);
}
}
@Override
public boolean handlePreferenceTreeClick(Preference preference) {
return false;
}
@Override
public boolean onPreferenceChange(Preference preference, Object newValue) {
try {
final int value = Integer.parseInt((String) newValue);
final UiModeManager uiManager =
(UiModeManager) mContext.getSystemService(UI_MODE_SERVICE);
uiManager.setNightMode(value);
} catch (NumberFormatException e) {
Log.e(TAG, "could not persist night mode setting", e);
return false;
}
return true;
}
}

View File

@@ -0,0 +1,55 @@
/*
* Copyright (C) 2016 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.support.v7.preference.Preference;
import android.support.v7.preference.PreferenceScreen;
import com.android.settings.DreamSettings;
import com.android.settings.core.PreferenceController;
public class ScreenSaverPreferenceController extends PreferenceController {
private static final String KEY_SCREEN_SAVER = "screensaver";
public ScreenSaverPreferenceController(Context context) {
super(context);
}
@Override
protected boolean isAvailable() {
return mContext.getResources().getBoolean(
com.android.internal.R.bool.config_dreamsSupported);
}
@Override
protected String getPreferenceKey() {
return KEY_SCREEN_SAVER;
}
@Override
public boolean handlePreferenceTreeClick(Preference preference) {
return false;
}
@Override
public void updateState(PreferenceScreen screen) {
final Preference preference = screen.findPreference(KEY_SCREEN_SAVER);
if (preference != null) {
preference.setSummary(
DreamSettings.getSummaryTextWithDreamName(mContext));
}
}
}

View File

@@ -0,0 +1,67 @@
/*
* Copyright (C) 2016 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.provider.Settings;
import android.support.v14.preference.SwitchPreference;
import android.support.v7.preference.Preference;
import android.support.v7.preference.PreferenceScreen;
import com.android.settings.core.PreferenceController;
public class TapToWakePreferenceController extends PreferenceController implements
Preference.OnPreferenceChangeListener {
private static final String KEY_TAP_TO_WAKE = "tap_to_wake";
public TapToWakePreferenceController(Context context) {
super(context);
}
@Override
protected String getPreferenceKey() {
return KEY_TAP_TO_WAKE;
}
@Override
protected boolean isAvailable() {
return mContext.getResources().getBoolean(
com.android.internal.R.bool.config_supportDoubleTapWake);
}
@Override
public boolean handlePreferenceTreeClick(Preference preference) {
return false;
}
@Override
public void updateState(PreferenceScreen screen) {
final SwitchPreference preference =
(SwitchPreference) screen.findPreference(KEY_TAP_TO_WAKE);
if (preference != null) {
int value = Settings.Secure.getInt(
mContext.getContentResolver(), Settings.Secure.DOUBLE_TAP_TO_WAKE, 0);
preference.setChecked(value != 0);
}
}
@Override
public boolean onPreferenceChange(Preference preference, Object newValue) {
boolean value = (Boolean) newValue;
Settings.Secure.putInt(
mContext.getContentResolver(), Settings.Secure.DOUBLE_TAP_TO_WAKE, value ? 1 : 0);
return true;
}
}

View File

@@ -0,0 +1,127 @@
/*
* Copyright (C) 2016 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.app.admin.DevicePolicyManager;
import android.content.Context;
import android.os.UserHandle;
import android.provider.Settings;
import android.support.v7.preference.Preference;
import android.support.v7.preference.PreferenceScreen;
import android.util.Log;
import com.android.settings.R;
import com.android.settings.TimeoutListPreference;
import com.android.settings.core.PreferenceController;
import com.android.settingslib.RestrictedLockUtils;
import static android.provider.Settings.System.SCREEN_OFF_TIMEOUT;
public class TimeoutPreferenceController extends PreferenceController implements
Preference.OnPreferenceChangeListener {
private static final String TAG = "TimeoutPrefContr";
/** If there is no setting in the provider, use this. */
public static final int FALLBACK_SCREEN_TIMEOUT_VALUE = 30000;
private static final String KEY_SCREEN_TIMEOUT = "screen_timeout";
public TimeoutPreferenceController(Context context) {
super(context);
}
@Override
protected boolean isAvailable() {
return true;
}
@Override
protected String getPreferenceKey() {
return KEY_SCREEN_TIMEOUT;
}
@Override
public boolean handlePreferenceTreeClick(Preference preference) {
return false;
}
@Override
public void updateState(PreferenceScreen screen) {
final TimeoutListPreference preference =
(TimeoutListPreference) screen.findPreference(KEY_SCREEN_TIMEOUT);
if (preference == null) {
return;
}
final long currentTimeout = Settings.System.getLong(mContext.getContentResolver(),
SCREEN_OFF_TIMEOUT, FALLBACK_SCREEN_TIMEOUT_VALUE);
preference.setValue(String.valueOf(currentTimeout));
final DevicePolicyManager dpm = (DevicePolicyManager) mContext.getSystemService(
Context.DEVICE_POLICY_SERVICE);
if (dpm != null) {
final RestrictedLockUtils.EnforcedAdmin admin =
RestrictedLockUtils.checkIfMaximumTimeToLockIsSet(mContext);
final long maxTimeout =
dpm.getMaximumTimeToLockForUserAndProfiles(UserHandle.myUserId());
preference.removeUnusableTimeouts(maxTimeout, admin);
}
updateTimeoutPreferenceDescription(preference, currentTimeout);
}
@Override
public boolean onPreferenceChange(Preference preference, Object newValue) {
try {
int value = Integer.parseInt((String) newValue);
Settings.System.putInt(mContext.getContentResolver(), SCREEN_OFF_TIMEOUT, value);
updateTimeoutPreferenceDescription((TimeoutListPreference) preference, value);
} catch (NumberFormatException e) {
Log.e(TAG, "could not persist screen timeout setting", e);
}
return true;
}
public static CharSequence getTimeoutDescription(
long currentTimeout, CharSequence[] entries, CharSequence[] values) {
if (currentTimeout < 0 || entries == null || values == null
|| values.length != entries.length) {
return null;
}
for (int i = 0; i < values.length; i++) {
long timeout = Long.parseLong(values[i].toString());
if (currentTimeout == timeout) {
return entries[i];
}
}
return null;
}
private void updateTimeoutPreferenceDescription(TimeoutListPreference preference,
long currentTimeout) {
final CharSequence[] entries = preference.getEntries();
final CharSequence[] values = preference.getEntryValues();
final String summary;
if (preference.isDisabledByAdmin()) {
summary = mContext.getString(com.android.settings.R.string.disabled_by_policy_title);
} else {
final CharSequence timeoutDescription = getTimeoutDescription(
currentTimeout, entries, values);
summary = timeoutDescription == null
? ""
: mContext.getString(R.string.screen_timeout_summary, timeoutDescription);
}
preference.setSummary(summary);
}
}

View File

@@ -0,0 +1,88 @@
/*
* Copyright (C) 2016 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.app.ActivityManager;
import android.content.Context;
import android.content.pm.PackageManager;
import android.provider.Settings;
import android.support.v7.preference.DropDownPreference;
import android.support.v7.preference.Preference;
import android.support.v7.preference.PreferenceScreen;
import android.util.Log;
import com.android.settings.R;
import com.android.settings.core.PreferenceController;
public class VrDisplayPreferenceController extends PreferenceController implements
Preference.OnPreferenceChangeListener {
private static final String TAG = "VrDisplayPrefContr";
private static final String KEY_VR_DISPLAY_PREF = "vr_display_pref";
public VrDisplayPreferenceController(Context context) {
super(context);
}
@Override
protected boolean isAvailable() {
final PackageManager pm = mContext.getPackageManager();
return pm.hasSystemFeature(PackageManager.FEATURE_VR_MODE_HIGH_PERFORMANCE);
}
@Override
protected String getPreferenceKey() {
return KEY_VR_DISPLAY_PREF;
}
@Override
public void updateState(PreferenceScreen screen) {
final DropDownPreference pref =
(DropDownPreference) screen.findPreference(KEY_VR_DISPLAY_PREF);
if (pref == null) {
Log.d(TAG, "Could not find VR display preference.");
return;
}
pref.setEntries(new CharSequence[]{
mContext.getString(R.string.display_vr_pref_low_persistence),
mContext.getString(R.string.display_vr_pref_off),
});
pref.setEntryValues(new CharSequence[]{"0", "1"});
int currentUser = ActivityManager.getCurrentUser();
int current = Settings.Secure.getIntForUser(mContext.getContentResolver(),
Settings.Secure.VR_DISPLAY_MODE,
/*default*/Settings.Secure.VR_DISPLAY_MODE_LOW_PERSISTENCE,
currentUser);
pref.setValueIndex(current);
}
@Override
public boolean onPreferenceChange(Preference preference, Object newValue) {
int i = Integer.parseInt((String) newValue);
int u = ActivityManager.getCurrentUser();
if (!Settings.Secure.putIntForUser(mContext.getContentResolver(),
Settings.Secure.VR_DISPLAY_MODE,
i, u)) {
Log.e(TAG, "Could not change setting for " +
Settings.Secure.VR_DISPLAY_MODE);
}
return true;
}
@Override
public boolean handlePreferenceTreeClick(Preference preference) {
return false;
}
}

View File

@@ -0,0 +1,69 @@
/*
* Copyright (C) 2016 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.support.v7.preference.Preference;
import android.support.v7.preference.PreferenceScreen;
import com.android.settings.core.PreferenceController;
import com.android.settingslib.RestrictedLockUtils;
import com.android.settingslib.RestrictedPreference;
import static android.os.UserManager.DISALLOW_SET_WALLPAPER;
public class WallpaperPreferenceController extends PreferenceController {
private static final String KEY_WALLPAPER = "wallpaper";
public WallpaperPreferenceController(Context context) {
super(context);
}
@Override
protected boolean isAvailable() {
return true;
}
@Override
protected String getPreferenceKey() {
return KEY_WALLPAPER;
}
@Override
public void updateState(PreferenceScreen screen) {
disablePreferenceIfManaged(screen);
}
@Override
public boolean handlePreferenceTreeClick(Preference preference) {
return false;
}
private void disablePreferenceIfManaged(PreferenceScreen screen) {
final RestrictedPreference pref =
(RestrictedPreference) screen.findPreference(KEY_WALLPAPER);
final String restriction = DISALLOW_SET_WALLPAPER;
if (pref != null) {
pref.setDisabledByAdmin(null);
if (RestrictedLockUtils.hasBaseUserRestriction(mContext,
restriction, UserHandle.myUserId())) {
pref.setEnabled(false);
} else {
pref.checkRestrictionAndSetDisabled(restriction);
}
}
}
}

View File

@@ -20,7 +20,9 @@ import android.os.UserManager;
import android.provider.SearchIndexableResource;
import com.android.settings.R;
import com.android.settings.core.PreferenceController;
import com.android.settings.dashboard.DashboardFragment;
import com.android.settings.deviceinfo.AdditionalSystemUpdatePreferenceController;
import com.android.settings.deviceinfo.SystemUpdatePreferenceController;
import com.android.settings.overlay.FeatureFactory;
import com.android.settings.search.BaseSearchIndexProvider;
@@ -47,18 +49,8 @@ public class SystemDashboardFragment extends DashboardFragment {
}
@Override
public void onAttach(Context context) {
super.onAttach(context);
addPreferenceController(
new SystemUpdatePreferenceController(context, UserManager.get(context)));
}
@Override
protected void displayResourceTiles() {
addPreferencesFromResource(R.xml.system_dashboard_fragment);
getPreferenceController(SystemUpdatePreferenceController.class)
.displayPreference(getPreferenceScreen());
protected int getPreferenceScreenResId() {
return R.xml.system_dashboard_fragment;
}
@Override
@@ -66,6 +58,14 @@ public class SystemDashboardFragment extends DashboardFragment {
return CategoryKey.CATEGORY_SYSTEM;
}
@Override
protected List<PreferenceController> getPreferenceControllers(Context context) {
final List<PreferenceController> controllers = new ArrayList<>();
controllers.add(new SystemUpdatePreferenceController(context, UserManager.get(context)));
controllers.add(new AdditionalSystemUpdatePreferenceController(context));
return controllers;
}
/**
* For Search.
*/
@@ -89,10 +89,11 @@ public class SystemDashboardFragment extends DashboardFragment {
.isEnabled()) {
return null;
}
final SystemUpdatePreferenceController systemUpdatePreferenceController =
new SystemUpdatePreferenceController(context, UserManager.get(context));
final List<String> keys = new ArrayList<>();
systemUpdatePreferenceController.updateNonIndexableKeys(keys);
new SystemUpdatePreferenceController(context, UserManager.get(context))
.updateNonIndexableKeys(keys);
new AdditionalSystemUpdatePreferenceController(context)
.updateNonIndexableKeys(keys);
return keys;
}
};

View File

@@ -40,11 +40,11 @@ import android.os.RemoteException;
import android.os.UserHandle;
import android.os.UserManager;
import android.provider.Settings;
import android.provider.Settings.Global;
import android.support.v7.preference.Preference;
import android.support.v7.preference.Preference.OnPreferenceClickListener;
import android.support.v7.preference.PreferenceGroup;
import android.support.v7.preference.PreferenceScreen;
import android.provider.Settings.Global;
import android.util.Log;
import android.util.SparseArray;
import android.view.Menu;

View File

@@ -29,8 +29,6 @@ import org.mockito.MockitoAnnotations;
import org.robolectric.RobolectricTestRunner;
import org.robolectric.annotation.Config;
import java.util.List;
import static org.mockito.Matchers.any;
import static org.mockito.Mockito.never;
import static org.mockito.Mockito.verify;
@@ -39,7 +37,6 @@ import static org.mockito.Mockito.when;
@RunWith(RobolectricTestRunner.class)
@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION)
public class PreferenceControllerTest {
private static final String KEY_PREF = "test_pref";
@Mock
private Context mContext;
@@ -58,39 +55,60 @@ public class PreferenceControllerTest {
@Test
public void removeExistingPref_shouldBeRemoved() {
when(mScreen.findPreference(KEY_PREF)).thenReturn(mPreference);
when(mScreen.findPreference(TestPrefController.KEY_PREF)).thenReturn(mPreference);
mTestPrefController.removePreference(mScreen, KEY_PREF);
mTestPrefController.removePreference(mScreen, TestPrefController.KEY_PREF);
verify(mScreen).removePreference(mPreference);
}
@Test
public void removeNonExistingPref_shouldNotRemoveAnything() {
mTestPrefController.removePreference(mScreen, KEY_PREF);
mTestPrefController.removePreference(mScreen, TestPrefController.KEY_PREF);
verify(mScreen, never()).removePreference(any(Preference.class));
}
@Test
public void displayPref_ifAvailable() {
mTestPrefController.isAvailable = true;
mTestPrefController.displayPreference(mScreen);
verify(mScreen, never()).removePreference(any(Preference.class));
}
@Test
public void doNotDisplayPref_ifNotAvailable() {
when(mScreen.findPreference(TestPrefController.KEY_PREF)).thenReturn(mPreference);
mTestPrefController.isAvailable = false;
mTestPrefController.displayPreference(mScreen);
verify(mScreen).removePreference(any(Preference.class));
}
private class TestPrefController extends PreferenceController {
private static final String KEY_PREF = "test_pref";
public boolean isAvailable;
public TestPrefController(Context context) {
super(context);
}
@Override
public void displayPreference(PreferenceScreen screen) {
}
@Override
public boolean handlePreferenceTreeClick(Preference preference) {
return false;
}
@Override
public void updateNonIndexableKeys(List<String> keys) {
protected boolean isAvailable() {
return isAvailable;
}
@Override
protected String getPreferenceKey() {
return KEY_PREF;
}
}

View File

@@ -116,15 +116,20 @@ public class DashboardFragmentTest {
}
@Override
public void displayPreference(PreferenceScreen screen) {
public boolean handlePreferenceTreeClick(Preference preference) {
return false;
}
@Override
public boolean handlePreferenceTreeClick(Preference preference) {
protected boolean isAvailable() {
return false;
}
@Override
protected String getPreferenceKey() {
return null;
}
@Override
public void updateNonIndexableKeys(List<String> keys) {
@@ -157,10 +162,6 @@ public class DashboardFragmentTest {
return CategoryKey.CATEGORY_HOMEPAGE;
}
@Override
protected void displayResourceTiles() {
}
@Override
public PreferenceScreen getPreferenceScreen() {
return mScreen;
@@ -170,6 +171,16 @@ public class DashboardFragmentTest {
protected String getLogTag() {
return "TEST_FRAG";
}
@Override
protected int getPreferenceScreenResId() {
return 0;
}
@Override
protected List<PreferenceController> getPreferenceControllers(Context context) {
return null;
}
}
}

View File

@@ -37,7 +37,6 @@ import java.util.List;
import static com.google.common.truth.Truth.assertThat;
import static org.mockito.Answers.RETURNS_DEEP_STUBS;
import static org.mockito.Matchers.any;
import static org.mockito.Mockito.times;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
@@ -79,14 +78,14 @@ public class SystemUpdatePreferenceControllerTest {
mController.updateNonIndexableKeys(keys);
assertThat(keys.size()).isEqualTo(2);
assertThat(keys.size()).isEqualTo(1);
}
@Test
public void displayPrefs_nothingAvailable_shouldNotDisplay() {
mController.displayPreference(mScreen);
verify(mScreen, times(2)).removePreference(any(Preference.class));
verify(mScreen).removePreference(any(Preference.class));
}
@Test