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

@@ -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);
}
}
}
}