New approach to override timeout max value
- Revert "Allow OEM customizing max screen timeout value."
- Use separate timeout list for screen timeout and lock timeout.
This reverts commit f57f490aa6
.
Fixes: 113346164
Test: manual
Change-Id: Ifbb054c232c47455ae82e3ed817f9c1e96f694cf
This commit is contained in:
@@ -172,9 +172,6 @@
|
|||||||
<!-- ComponentName to launch a vendor-specific enrollment activity if available -->
|
<!-- ComponentName to launch a vendor-specific enrollment activity if available -->
|
||||||
<string name="config_face_enroll" translatable="false"></string>
|
<string name="config_face_enroll" translatable="false"></string>
|
||||||
|
|
||||||
<!-- Max allowed value for screen timeout, in milliseconds -->
|
|
||||||
<integer name="max_lock_after_timeout_ms">1800000</integer>
|
|
||||||
|
|
||||||
<!-- App intent -->
|
<!-- App intent -->
|
||||||
<string name="config_account_intent_uri" translatable="false"></string>
|
<string name="config_account_intent_uri" translatable="false"></string>
|
||||||
</resources>
|
</resources>
|
||||||
|
@@ -5841,6 +5841,9 @@
|
|||||||
Used in SetupWizard for XLarge screen [CHAR LIMIT=20] -->
|
Used in SetupWizard for XLarge screen [CHAR LIMIT=20] -->
|
||||||
<string name="wifi_setup_detail">Network details</string>
|
<string name="wifi_setup_detail">Network details</string>
|
||||||
|
|
||||||
|
<!-- Do not translate. This is a stub which will be removed soon. -->
|
||||||
|
<string name="time_zone_auto_stub" translatable="false">Select Time Zone</string>
|
||||||
|
|
||||||
<!-- Content description of the enabled sync icon for accessibility. [CHAR LIMIT=NONE] -->
|
<!-- Content description of the enabled sync icon for accessibility. [CHAR LIMIT=NONE] -->
|
||||||
<string name="accessibility_sync_enabled">Sync enabled</string>
|
<string name="accessibility_sync_enabled">Sync enabled</string>
|
||||||
<!-- Content description of the disabled sync icon for accessibility. [CHAR LIMIT=NONE] -->
|
<!-- Content description of the disabled sync icon for accessibility. [CHAR LIMIT=NONE] -->
|
||||||
|
@@ -58,7 +58,7 @@
|
|||||||
<com.android.settingslib.RestrictedPreference
|
<com.android.settingslib.RestrictedPreference
|
||||||
android:fragment="com.android.settings.datetime.timezone.TimeZoneSettings"
|
android:fragment="com.android.settings.datetime.timezone.TimeZoneSettings"
|
||||||
android:key="timezone"
|
android:key="timezone"
|
||||||
android:title="@string/date_time_set_timezone_title"
|
android:title="@string/date_time_set_timezone"
|
||||||
android:summary="@string/summary_placeholder"
|
android:summary="@string/summary_placeholder"
|
||||||
settings:userRestriction="no_config_date_time" />
|
settings:userRestriction="no_config_date_time" />
|
||||||
</PreferenceCategory>
|
</PreferenceCategory>
|
||||||
|
@@ -26,7 +26,6 @@ import android.util.AttributeSet;
|
|||||||
import android.util.Log;
|
import android.util.Log;
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
|
|
||||||
import androidx.annotation.VisibleForTesting;
|
|
||||||
import androidx.appcompat.app.AlertDialog.Builder;
|
import androidx.appcompat.app.AlertDialog.Builder;
|
||||||
|
|
||||||
import com.android.settings.R;
|
import com.android.settings.R;
|
||||||
@@ -34,18 +33,18 @@ import com.android.settings.RestrictedListPreference;
|
|||||||
import com.android.settingslib.RestrictedLockUtils;
|
import com.android.settingslib.RestrictedLockUtils;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
|
|
||||||
public class TimeoutListPreference extends RestrictedListPreference {
|
public class TimeoutListPreference extends RestrictedListPreference {
|
||||||
private static final String TAG = "TimeoutListPreference";
|
private static final String TAG = "TimeoutListPreference";
|
||||||
private EnforcedAdmin mAdmin;
|
private EnforcedAdmin mAdmin;
|
||||||
private CharSequence[] mInitialEntries;
|
private final CharSequence[] mInitialEntries;
|
||||||
private CharSequence[] mInitialValues;
|
private final CharSequence[] mInitialValues;
|
||||||
|
|
||||||
public TimeoutListPreference(Context context, AttributeSet attrs) {
|
public TimeoutListPreference(Context context, AttributeSet attrs) {
|
||||||
super(context, attrs);
|
super(context, attrs);
|
||||||
updateInitialValues();
|
mInitialEntries = getEntries();
|
||||||
|
mInitialValues = getEntryValues();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -66,8 +65,13 @@ public class TimeoutListPreference extends RestrictedListPreference {
|
|||||||
if (mAdmin != null) {
|
if (mAdmin != null) {
|
||||||
View footerView = dialog.findViewById(R.id.admin_disabled_other_options);
|
View footerView = dialog.findViewById(R.id.admin_disabled_other_options);
|
||||||
footerView.findViewById(R.id.admin_more_details_link).setOnClickListener(
|
footerView.findViewById(R.id.admin_more_details_link).setOnClickListener(
|
||||||
view -> RestrictedLockUtils.sendShowAdminSupportDetailsIntent(
|
new View.OnClickListener() {
|
||||||
getContext(), mAdmin));
|
@Override
|
||||||
|
public void onClick(View view) {
|
||||||
|
RestrictedLockUtils.sendShowAdminSupportDetailsIntent(
|
||||||
|
getContext(), mAdmin);
|
||||||
|
}
|
||||||
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -85,8 +89,8 @@ public class TimeoutListPreference extends RestrictedListPreference {
|
|||||||
maxTimeout = Long.MAX_VALUE;
|
maxTimeout = Long.MAX_VALUE;
|
||||||
}
|
}
|
||||||
|
|
||||||
final ArrayList<CharSequence> revisedEntries = new ArrayList<>();
|
ArrayList<CharSequence> revisedEntries = new ArrayList<CharSequence>();
|
||||||
final ArrayList<CharSequence> revisedValues = new ArrayList<>();
|
ArrayList<CharSequence> revisedValues = new ArrayList<CharSequence>();
|
||||||
for (int i = 0; i < mInitialValues.length; ++i) {
|
for (int i = 0; i < mInitialValues.length; ++i) {
|
||||||
long timeout = Long.parseLong(mInitialValues[i].toString());
|
long timeout = Long.parseLong(mInitialValues[i].toString());
|
||||||
if (timeout <= maxTimeout) {
|
if (timeout <= maxTimeout) {
|
||||||
@@ -97,7 +101,7 @@ public class TimeoutListPreference extends RestrictedListPreference {
|
|||||||
|
|
||||||
// If there are no possible options for the user, then set this preference as disabled
|
// 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.
|
// by admin, otherwise remove the padlock in case it was set earlier.
|
||||||
if (revisedValues.isEmpty()) {
|
if (revisedValues.size() == 0) {
|
||||||
setDisabledByAdmin(admin);
|
setDisabledByAdmin(admin);
|
||||||
return;
|
return;
|
||||||
} else {
|
} else {
|
||||||
@@ -124,36 +128,4 @@ public class TimeoutListPreference extends RestrictedListPreference {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@VisibleForTesting
|
|
||||||
void updateInitialValues() {
|
|
||||||
// Read default list of candidate values.
|
|
||||||
final CharSequence[] entries = getEntries();
|
|
||||||
final CharSequence[] values = getEntryValues();
|
|
||||||
// Filter out values based on config
|
|
||||||
final List<CharSequence> revisedEntries = new ArrayList<>();
|
|
||||||
final List<CharSequence> revisedValues = new ArrayList<>();
|
|
||||||
final long maxTimeout = getContext().getResources().getInteger(
|
|
||||||
R.integer.max_lock_after_timeout_ms);
|
|
||||||
if (entries == null || values == null) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
Log.d(TAG, "max timeout: " + maxTimeout);
|
|
||||||
for (int i = 0; i < values.length; ++i) {
|
|
||||||
long timeout = Long.parseLong(values[i].toString());
|
|
||||||
if (timeout <= maxTimeout) {
|
|
||||||
Log.d(TAG, "keeping timeout: " + values[i]);
|
|
||||||
revisedEntries.add(entries[i]);
|
|
||||||
revisedValues.add(values[i]);
|
|
||||||
} else {
|
|
||||||
Log.d(TAG, "Dropping timeout: " + values[i]);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Store final candidates in initial value lists.
|
|
||||||
mInitialEntries = revisedEntries.toArray(new CharSequence[0]);
|
|
||||||
setEntries(mInitialEntries);
|
|
||||||
mInitialValues = revisedValues.toArray(new CharSequence[0]);
|
|
||||||
setEntryValues(mInitialValues);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
@@ -13,6 +13,8 @@
|
|||||||
*/
|
*/
|
||||||
package com.android.settings.display;
|
package com.android.settings.display;
|
||||||
|
|
||||||
|
import static android.provider.Settings.System.SCREEN_OFF_TIMEOUT;
|
||||||
|
|
||||||
import android.app.admin.DevicePolicyManager;
|
import android.app.admin.DevicePolicyManager;
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.os.UserHandle;
|
import android.os.UserHandle;
|
||||||
@@ -58,7 +60,7 @@ public class TimeoutPreferenceController extends AbstractPreferenceController im
|
|||||||
public void updateState(Preference preference) {
|
public void updateState(Preference preference) {
|
||||||
final TimeoutListPreference timeoutListPreference = (TimeoutListPreference) preference;
|
final TimeoutListPreference timeoutListPreference = (TimeoutListPreference) preference;
|
||||||
final long currentTimeout = Settings.System.getLong(mContext.getContentResolver(),
|
final long currentTimeout = Settings.System.getLong(mContext.getContentResolver(),
|
||||||
Settings.System.SCREEN_OFF_TIMEOUT, FALLBACK_SCREEN_TIMEOUT_VALUE);
|
SCREEN_OFF_TIMEOUT, FALLBACK_SCREEN_TIMEOUT_VALUE);
|
||||||
timeoutListPreference.setValue(String.valueOf(currentTimeout));
|
timeoutListPreference.setValue(String.valueOf(currentTimeout));
|
||||||
final DevicePolicyManager dpm =
|
final DevicePolicyManager dpm =
|
||||||
(DevicePolicyManager) mContext.getSystemService(Context.DEVICE_POLICY_SERVICE);
|
(DevicePolicyManager) mContext.getSystemService(Context.DEVICE_POLICY_SERVICE);
|
||||||
@@ -84,8 +86,7 @@ public class TimeoutPreferenceController extends AbstractPreferenceController im
|
|||||||
public boolean onPreferenceChange(Preference preference, Object newValue) {
|
public boolean onPreferenceChange(Preference preference, Object newValue) {
|
||||||
try {
|
try {
|
||||||
int value = Integer.parseInt((String) newValue);
|
int value = Integer.parseInt((String) newValue);
|
||||||
Settings.System.putInt(mContext.getContentResolver(),
|
Settings.System.putInt(mContext.getContentResolver(), SCREEN_OFF_TIMEOUT, value);
|
||||||
Settings.System.SCREEN_OFF_TIMEOUT, value);
|
|
||||||
updateTimeoutPreferenceDescription((TimeoutListPreference) preference, value);
|
updateTimeoutPreferenceDescription((TimeoutListPreference) preference, value);
|
||||||
} catch (NumberFormatException e) {
|
} catch (NumberFormatException e) {
|
||||||
Log.e(TAG, "could not persist screen timeout setting", e);
|
Log.e(TAG, "could not persist screen timeout setting", e);
|
||||||
@@ -93,7 +94,7 @@ public class TimeoutPreferenceController extends AbstractPreferenceController im
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
private static CharSequence getTimeoutDescription(
|
public static CharSequence getTimeoutDescription(
|
||||||
long currentTimeout, CharSequence[] entries, CharSequence[] values) {
|
long currentTimeout, CharSequence[] entries, CharSequence[] values) {
|
||||||
if (currentTimeout < 0 || entries == null || values == null
|
if (currentTimeout < 0 || entries == null || values == null
|
||||||
|| values.length != entries.length) {
|
|| values.length != entries.length) {
|
||||||
|
@@ -88,7 +88,4 @@
|
|||||||
|
|
||||||
<!-- Email address for the homepage contextual cards feedback -->
|
<!-- Email address for the homepage contextual cards feedback -->
|
||||||
<string name="config_contextual_card_feedback_email" translatable="false">test@test.test</string>
|
<string name="config_contextual_card_feedback_email" translatable="false">test@test.test</string>
|
||||||
|
|
||||||
<!-- Max allowed value for screen timeout, in milliseconds -->
|
|
||||||
<integer name="max_lock_after_timeout_ms">1700000</integer>
|
|
||||||
</resources>
|
</resources>
|
||||||
|
@@ -17,11 +17,11 @@ package com.android.settings.display;
|
|||||||
|
|
||||||
import static com.google.common.truth.Truth.assertThat;
|
import static com.google.common.truth.Truth.assertThat;
|
||||||
|
|
||||||
|
import static org.mockito.Mockito.mock;
|
||||||
import static org.robolectric.RuntimeEnvironment.application;
|
import static org.robolectric.RuntimeEnvironment.application;
|
||||||
|
|
||||||
import android.util.AttributeSet;
|
import android.util.AttributeSet;
|
||||||
|
|
||||||
import com.android.settings.R;
|
|
||||||
import com.android.settings.testutils.shadow.ShadowUserManager;
|
import com.android.settings.testutils.shadow.ShadowUserManager;
|
||||||
import com.android.settingslib.RestrictedLockUtils;
|
import com.android.settingslib.RestrictedLockUtils;
|
||||||
|
|
||||||
@@ -69,23 +69,4 @@ public class TimeoutListPreferenceTest {
|
|||||||
// should set to largest allowed value, which is 5 minute
|
// should set to largest allowed value, which is 5 minute
|
||||||
assertThat(mPreference.getValue()).isEqualTo("300000");
|
assertThat(mPreference.getValue()).isEqualTo("300000");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
|
||||||
@Config(qualifiers = "mcc999")
|
|
||||||
public void newInstance_hasLowTimeoutConfig_shouldRemoveLongTimeouts() {
|
|
||||||
final AttributeSet attributeSet = Robolectric.buildAttributeSet().build();
|
|
||||||
final TimeoutListPreference pref = new TimeoutListPreference(application, attributeSet);
|
|
||||||
final long maxTimeout = application.getResources().getInteger(
|
|
||||||
R.integer.max_lock_after_timeout_ms);
|
|
||||||
pref.setEntries(R.array.screen_timeout_entries);
|
|
||||||
pref.setEntryValues(R.array.screen_timeout_values);
|
|
||||||
|
|
||||||
pref.updateInitialValues();
|
|
||||||
|
|
||||||
final CharSequence[] values = pref.getEntryValues();
|
|
||||||
for (CharSequence value : values) {
|
|
||||||
long timeout = Long.parseLong(value.toString());
|
|
||||||
assertThat(timeout).isAtMost(maxTimeout);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user