Update the timeout list dialog in display and security settings.

Currently, we add padlocks to all the timeout options which are
more than the timeout enforced by the admin. Instead of adding
the padlocks to the options, updated the timeout list dialog to
have a disabled by admin message as dialog footer.

Bug: 27564363
Change-Id: I66ce35e92c044ce1864d14e1fc0e83881f8f4ab0
This commit is contained in:
Sudheer Shanka
2016-03-04 16:58:34 -08:00
parent 179a57b21f
commit 900adce6ca
9 changed files with 191 additions and 123 deletions

View File

@@ -0,0 +1,36 @@
<?xml version="1.0" encoding="utf-8"?>
<!-- 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.
-->
<!-- Layout used as footer in listpreference dialog to denote that some of the options
are diabled by admin. -->
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/admin_disabled_other_options"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:paddingStart="?android:attr/dialogPreferredPadding"
android:paddingEnd="?android:attr/dialogPreferredPadding"
android:orientation="vertical">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="@string/admin_disabled_other_options" />
<TextView android:id="@+id/admin_more_details_link"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/admin_more_details"
android:textColor="?android:attr/colorAccent"
android:clickable="true"
android:background="?android:attr/selectableItemBackground" />
</LinearLayout>

View File

@@ -4677,6 +4677,10 @@
<!-- Warning when trying to add a profile owner admin after setup has completed. [CHAR LIMIT=none] -->
<string name="adding_profile_owner_warning">By proceeding, your User will be managed by your Administrator which may also be able to store associated data, in addition to your personal data.\n\nYour Administrator has the ability to monitor and manage settings, access, apps, and data associated with this User, including network activity and your device\u2019s location information.</string>
<!-- Message displayed to let the user know that some of the options are disabled by admin. [CHAR LIMIT=NONE] -->
<string name="admin_disabled_other_options">Other options are disabled by your administrator.</string>
<string name="admin_more_details">More details</string>
<!-- Name to assign to a Network Access Point that was saved without a name -->
<string name="untitled_apn">Untitled</string>

View File

@@ -47,7 +47,7 @@
settings:keywords="@string/keywords_display_wallpaper"
android:fragment="com.android.settings.WallpaperTypeSettings" />
<com.android.settings.RestrictedListPreference
<com.android.settings.TimeoutListPreference
android:key="screen_timeout"
android:title="@string/screen_timeout"
android:summary="@string/screen_timeout_summary"

View File

@@ -19,7 +19,7 @@
xmlns:settings="http://schemas.android.com/apk/res/com.android.settings"
android:title="@string/settings_label">
<com.android.settings.RestrictedListPreference
<com.android.settings.TimeoutListPreference
android:key="lock_after_timeout"
android:title="@string/lock_after_timeout"
android:summary="@string/lock_after_timeout_summary"

View File

@@ -23,7 +23,7 @@
android:key="visiblepattern"
android:title="@string/lockpattern_settings_enable_visible_pattern_title"/>
<com.android.settings.RestrictedListPreference
<com.android.settings.TimeoutListPreference
android:key="lock_after_timeout"
android:title="@string/lock_after_timeout"
android:summary="@string/lock_after_timeout_summary"

View File

@@ -19,7 +19,7 @@
xmlns:settings="http://schemas.android.com/apk/res/com.android.settings"
android:title="@string/settings_label">
<com.android.settings.RestrictedListPreference
<com.android.settings.TimeoutListPreference
android:key="lock_after_timeout"
android:title="@string/lock_after_timeout"
android:summary="@string/lock_after_timeout_summary"

View File

@@ -62,7 +62,6 @@ 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.settings.RestrictedListPreference.RestrictedItem;
import static com.android.settingslib.RestrictedLockUtils.EnforcedAdmin;
public class DisplaySettings extends SettingsPreferenceFragment implements
@@ -88,7 +87,7 @@ public class DisplaySettings extends SettingsPreferenceFragment implements
private Preference mFontSizePref;
private RestrictedListPreference mScreenTimeoutPreference;
private TimeoutListPreference mScreenTimeoutPreference;
private ListPreference mNightModePreference;
private Preference mScreenSaverPreference;
private SwitchPreference mLiftToWakePreference;
@@ -118,7 +117,7 @@ public class DisplaySettings extends SettingsPreferenceFragment implements
getPreferenceScreen().removePreference(mScreenSaverPreference);
}
mScreenTimeoutPreference = (RestrictedListPreference) findPreference(KEY_SCREEN_TIMEOUT);
mScreenTimeoutPreference = (TimeoutListPreference) findPreference(KEY_SCREEN_TIMEOUT);
mFontSizePref = findPreference(KEY_FONT_SIZE);
@@ -263,7 +262,7 @@ public class DisplaySettings extends SettingsPreferenceFragment implements
}
private void updateTimeoutPreferenceDescription(long currentTimeout) {
RestrictedListPreference preference = mScreenTimeoutPreference;
TimeoutListPreference preference = mScreenTimeoutPreference;
String summary;
if (preference.isDisabledByAdmin()) {
summary = getString(R.string.disabled_by_policy_title);
@@ -278,9 +277,6 @@ public class DisplaySettings extends SettingsPreferenceFragment implements
} else {
int best = 0;
for (int i = 0; i < values.length; i++) {
if (preference.isRestrictedForEntry(entries[i])) {
break;
}
long timeout = Long.parseLong(values[i].toString());
if (currentTimeout >= timeout) {
best = i;
@@ -292,59 +288,6 @@ public class DisplaySettings extends SettingsPreferenceFragment implements
preference.setSummary(summary);
}
private void disableUnusableTimeouts(RestrictedListPreference screenTimeoutPreference) {
final EnforcedAdmin admin = RestrictedLockUtils.checkIfMaximumTimeToLockIsSet(
getActivity());
if (admin == null) {
return; // policy not enforced
}
final DevicePolicyManager dpm = (DevicePolicyManager) getActivity().getSystemService(
Context.DEVICE_POLICY_SERVICE);
if (dpm == null) {
return;
}
final long maxTimeout = dpm.getMaximumTimeToLock(null);
final CharSequence[] entries = screenTimeoutPreference.getEntries();
final CharSequence[] values = screenTimeoutPreference.getEntryValues();
long maxTimeoutSelectable = 0;
int maxTimeoutEntryIndex = -1;
for (int i = 0; i < values.length; i++) {
long timeout = Long.parseLong(values[i].toString());
if (timeout > maxTimeout) {
break;
}
maxTimeoutSelectable = timeout;
maxTimeoutEntryIndex = i;
}
// If there are no possible options for the user, then set this preference as disabled
// by admin, otherwise remove the padlock in case it was set earlier.
if (maxTimeoutSelectable == 0) {
screenTimeoutPreference.setDisabledByAdmin(admin);
return;
} else {
screenTimeoutPreference.setDisabledByAdmin(null);
}
screenTimeoutPreference.clearRestrictedItems();
// Set all the entries after the maximum selectable timeout as disabled by admin.
for (int i = maxTimeoutEntryIndex + 1; i < values.length; i++) {
screenTimeoutPreference.addRestrictedItem(
new RestrictedItem(entries[i], values[i], admin));
}
final int userPreference = Integer.parseInt(screenTimeoutPreference.getValue());
if (userPreference <= maxTimeout) {
screenTimeoutPreference.setValue(String.valueOf(userPreference));
} else if (maxTimeoutSelectable == maxTimeout) {
screenTimeoutPreference.setValue(String.valueOf(maxTimeout));
} else {
// There will be no highlighted selection since nothing in the list matches
// maxTimeout. The user can still select anything less than maxTimeout.
// TODO: maybe append maxTimeout to the list and mark selected.
}
}
@Override
public void onResume() {
super.onResume();
@@ -354,7 +297,14 @@ public class DisplaySettings extends SettingsPreferenceFragment implements
SCREEN_OFF_TIMEOUT, FALLBACK_SCREEN_TIMEOUT_VALUE);
mScreenTimeoutPreference.setValue(String.valueOf(currentTimeout));
mScreenTimeoutPreference.setOnPreferenceChangeListener(this);
disableUnusableTimeouts(mScreenTimeoutPreference);
final DevicePolicyManager dpm = (DevicePolicyManager) getActivity().getSystemService(
Context.DEVICE_POLICY_SERVICE);
if (dpm != null) {
final EnforcedAdmin admin = RestrictedLockUtils.checkIfMaximumTimeToLockIsSet(
getActivity());
final long maxTimeout = dpm.getMaximumTimeToLock(null);
mScreenTimeoutPreference.removeUnusableTimeouts(maxTimeout, admin);
}
updateTimeoutPreferenceDescription(currentTimeout);
}

View File

@@ -55,7 +55,7 @@ import android.util.Log;
import com.android.internal.logging.MetricsProto.MetricsEvent;
import com.android.internal.widget.LockPatternUtils;
import com.android.settings.RestrictedListPreference;
import com.android.settings.TimeoutListPreference;
import com.android.settings.TrustAgentUtils.TrustAgentComponentInfo;
import com.android.settings.fingerprint.FingerprintSettings;
import com.android.settings.search.BaseSearchIndexProvider;
@@ -71,7 +71,6 @@ import java.util.List;
import static android.provider.Settings.System.SCREEN_OFF_TIMEOUT;
import static com.android.settings.RestrictedListPreference.RestrictedItem;
import static com.android.settingslib.RestrictedLockUtils.EnforcedAdmin;
/**
@@ -937,7 +936,7 @@ public class SecuritySettings extends SettingsPreferenceFragment
private static final String SWITCH_PREFERENCE_KEYS[] = { KEY_LOCK_AFTER_TIMEOUT,
KEY_VISIBLE_PATTERN, KEY_POWER_INSTANTLY_LOCKS, KEY_REQUIRE_CRED_BEFORE_STARTUP };
private RestrictedListPreference mLockAfter;
private TimeoutListPreference mLockAfter;
private SwitchPreference mVisiblePattern;
private SwitchPreference mPowerButtonInstantlyLocks;
private RestrictedPreference mOwnerInfoPref;
@@ -994,7 +993,7 @@ public class SecuritySettings extends SettingsPreferenceFragment
addPreferencesFromResource(resid);
// lock after preference
mLockAfter = (RestrictedListPreference) findPreference(KEY_LOCK_AFTER_TIMEOUT);
mLockAfter = (TimeoutListPreference) findPreference(KEY_LOCK_AFTER_TIMEOUT);
if (mLockAfter != null) {
setupLockAfterPreference();
updateLockAfterPreferenceSummary();
@@ -1065,18 +1064,17 @@ public class SecuritySettings extends SettingsPreferenceFragment
Settings.Secure.LOCK_SCREEN_LOCK_AFTER_TIMEOUT, 5000);
mLockAfter.setValue(String.valueOf(currentTimeout));
mLockAfter.setOnPreferenceChangeListener(this);
final EnforcedAdmin admin = RestrictedLockUtils.checkIfMaximumTimeToLockIsSet(
getActivity());
if (admin != null) {
final long adminTimeout = (mDPM != null ? mDPM.getMaximumTimeToLock(null) : 0);
if (mDPM != null) {
final EnforcedAdmin admin = RestrictedLockUtils.checkIfMaximumTimeToLockIsSet(
getActivity());
final long adminTimeout = mDPM.getMaximumTimeToLock(null);
final long displayTimeout = Math.max(0,
Settings.System.getInt(getContentResolver(), SCREEN_OFF_TIMEOUT, 0));
if (adminTimeout > 0) {
// This setting is a slave to display timeout when a device policy is enforced.
// As such, maxLockTimeout = adminTimeout - displayTimeout.
// If there isn't enough time, shows "immediately" setting.
disableUnusableTimeouts(Math.max(0, adminTimeout - displayTimeout), admin);
}
// This setting is a slave to display timeout when a device policy is enforced.
// As such, maxLockTimeout = adminTimeout - displayTimeout.
// If there isn't enough time, shows "immediately" setting.
final long maxTimeout = Math.max(0, adminTimeout - displayTimeout);
mLockAfter.removeUnusableTimeouts(maxTimeout, admin);
}
}
@@ -1092,9 +1090,6 @@ public class SecuritySettings extends SettingsPreferenceFragment
final CharSequence[] values = mLockAfter.getEntryValues();
int best = 0;
for (int i = 0; i < values.length; i++) {
if (mLockAfter.isRestrictedForEntry(entries[i])) {
break;
}
long timeout = Long.valueOf(values[i].toString());
if (currentTimeout >= timeout) {
best = i;
@@ -1117,47 +1112,6 @@ public class SecuritySettings extends SettingsPreferenceFragment
mLockAfter.setSummary(summary);
}
private void disableUnusableTimeouts(long maxTimeout, EnforcedAdmin admin) {
final CharSequence[] entries = mLockAfter.getEntries();
final CharSequence[] values = mLockAfter.getEntryValues();
long maxTimeoutSelectable = 0;
int maxTimeoutEntryIndex = -1;
for (int i = 0; i < values.length; i++) {
long timeout = Long.parseLong(values[i].toString());
if (timeout > maxTimeout) {
break;
}
maxTimeoutSelectable = timeout;
maxTimeoutEntryIndex = i;
}
// If there are no possible options for the user, then set this preference as
// disabled by admin, otherwise remove the padlock in case it was set earlier.
if (maxTimeoutSelectable == 0) {
mLockAfter.setDisabledByAdmin(admin);
return;
} else {
mLockAfter.setDisabledByAdmin(null);
}
mLockAfter.clearRestrictedItems();
// Set all the entries after the maximum selectable timeout as disabled by admin.
for (int i = maxTimeoutEntryIndex + 1; i < values.length; i++) {
mLockAfter.addRestrictedItem(
new RestrictedItem(entries[i], values[i], admin));
}
final int userPreference = Integer.valueOf(mLockAfter.getValue());
if (userPreference <= maxTimeout) {
mLockAfter.setValue(String.valueOf(userPreference));
} else if (maxTimeoutSelectable == maxTimeout) {
mLockAfter.setValue(String.valueOf(maxTimeout));
} else {
// There will be no highlighted selection since nothing in the list matches
// maxTimeout. The user can still select anything less than maxTimeout.
// TODO: maybe append maxTimeout to the list and mark selected.
}
}
public void updateOwnerInfo() {
if (mOwnerInfoPref != null) {
if (mLockPatternUtils.isDeviceOwnerInfoEnabled()) {

View File

@@ -0,0 +1,124 @@
/*
* 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;
import android.app.AlertDialog;
import android.app.Dialog;
import android.app.admin.DevicePolicyManager;
import android.content.Context;
import android.content.DialogInterface;
import android.util.AttributeSet;
import android.view.View;
import com.android.settingslib.RestrictedLockUtils;
import java.util.ArrayList;
import static com.android.settingslib.RestrictedLockUtils.EnforcedAdmin;
public class TimeoutListPreference extends RestrictedListPreference {
private EnforcedAdmin mAdmin;
private final CharSequence[] mInitialEntries;
private final CharSequence[] mInitialValues;
public TimeoutListPreference(Context context, AttributeSet attrs) {
super(context, attrs);
mInitialEntries = getEntries();
mInitialValues = getEntryValues();
}
@Override
protected void onPrepareDialogBuilder(AlertDialog.Builder builder,
DialogInterface.OnClickListener listener) {
super.onPrepareDialogBuilder(builder, listener);
if (mAdmin != null) {
builder.setView(R.layout.admin_disabled_other_options_footer);
} else {
builder.setView(null);
}
}
@Override
protected void onDialogCreated(Dialog dialog) {
super.onDialogCreated(dialog);
dialog.create();
if (mAdmin != null) {
View footerView = dialog.findViewById(R.id.admin_disabled_other_options);
footerView.findViewById(R.id.admin_more_details_link).setOnClickListener(
new View.OnClickListener() {
@Override
public void onClick(View view) {
RestrictedLockUtils.sendShowAdminSupportDetailsIntent(
getContext(), mAdmin);
}
});
}
}
public void removeUnusableTimeouts(long maxTimeout, EnforcedAdmin admin) {
final DevicePolicyManager dpm = (DevicePolicyManager) getContext().getSystemService(
Context.DEVICE_POLICY_SERVICE);
if (dpm == null) {
return;
}
if (admin == null && mAdmin == null && !isDisabledByAdmin()) {
return;
}
if (admin == null) {
maxTimeout = Long.MAX_VALUE;
}
ArrayList<CharSequence> revisedEntries = new ArrayList<CharSequence>();
ArrayList<CharSequence> revisedValues = new ArrayList<CharSequence>();
for (int i = 0; i < mInitialValues.length; ++i) {
long timeout = Long.parseLong(mInitialValues[i].toString());
if (timeout <= maxTimeout) {
revisedEntries.add(mInitialEntries[i]);
revisedValues.add(mInitialValues[i]);
}
}
// If there are no possible options for the user, then set this preference as disabled
// by admin, otherwise remove the padlock in case it was set earlier.
if (revisedValues.size() == 0) {
setDisabledByAdmin(admin);
return;
} else {
setDisabledByAdmin(null);
}
if (revisedEntries.size() != getEntries().length) {
final int userPreference = Integer.parseInt(getValue());
setEntries(revisedEntries.toArray(new CharSequence[0]));
setEntryValues(revisedValues.toArray(new CharSequence[0]));
mAdmin = admin;
if (userPreference <= maxTimeout) {
setValue(String.valueOf(userPreference));
} else if (revisedValues.size() > 0
&& Long.parseLong(revisedValues.get(revisedValues.size() - 1).toString())
== maxTimeout) {
// If the last one happens to be the same as the max timeout, select that
setValue(String.valueOf(maxTimeout));
} else {
// There will be no highlighted selection since nothing in the list matches
// maxTimeout. The user can still select anything less than maxTimeout.
// TODO: maybe append maxTimeout to the list and mark selected.
}
}
}
}