Allow OEM customizing max screen timeout value.
Side fix - update string for select timezone. Change-Id: Id61128b7dfcc27da8ed07225af3b6bec4e93b512 Fixes: 113346164 Fixes: 121986474 Test: robotest
This commit is contained in:
@@ -171,4 +171,7 @@
|
||||
|
||||
<!-- ComponentName to launch a vendor-specific enrollment activity if available -->
|
||||
<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>
|
||||
</resources>
|
||||
|
@@ -5828,9 +5828,6 @@
|
||||
Used in SetupWizard for XLarge screen [CHAR LIMIT=20] -->
|
||||
<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] -->
|
||||
<string name="accessibility_sync_enabled">Sync enabled</string>
|
||||
<!-- Content description of the disabled sync icon for accessibility. [CHAR LIMIT=NONE] -->
|
||||
|
@@ -58,7 +58,7 @@
|
||||
<com.android.settingslib.RestrictedPreference
|
||||
android:fragment="com.android.settings.datetime.timezone.TimeZoneSettings"
|
||||
android:key="timezone"
|
||||
android:title="@string/date_time_set_timezone"
|
||||
android:title="@string/date_time_set_timezone_title"
|
||||
android:summary="@string/summary_placeholder"
|
||||
settings:userRestriction="no_config_date_time" />
|
||||
</PreferenceCategory>
|
||||
|
@@ -26,6 +26,7 @@ import android.util.AttributeSet;
|
||||
import android.util.Log;
|
||||
import android.view.View;
|
||||
|
||||
import androidx.annotation.VisibleForTesting;
|
||||
import androidx.appcompat.app.AlertDialog.Builder;
|
||||
|
||||
import com.android.settings.R;
|
||||
@@ -33,18 +34,18 @@ import com.android.settings.RestrictedListPreference;
|
||||
import com.android.settingslib.RestrictedLockUtils;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
|
||||
public class TimeoutListPreference extends RestrictedListPreference {
|
||||
private static final String TAG = "TimeoutListPreference";
|
||||
private EnforcedAdmin mAdmin;
|
||||
private final CharSequence[] mInitialEntries;
|
||||
private final CharSequence[] mInitialValues;
|
||||
private CharSequence[] mInitialEntries;
|
||||
private CharSequence[] mInitialValues;
|
||||
|
||||
public TimeoutListPreference(Context context, AttributeSet attrs) {
|
||||
super(context, attrs);
|
||||
mInitialEntries = getEntries();
|
||||
mInitialValues = getEntryValues();
|
||||
updateInitialValues();
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -65,13 +66,8 @@ public class TimeoutListPreference extends RestrictedListPreference {
|
||||
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);
|
||||
}
|
||||
});
|
||||
view -> RestrictedLockUtils.sendShowAdminSupportDetailsIntent(
|
||||
getContext(), mAdmin));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -89,8 +85,8 @@ public class TimeoutListPreference extends RestrictedListPreference {
|
||||
maxTimeout = Long.MAX_VALUE;
|
||||
}
|
||||
|
||||
ArrayList<CharSequence> revisedEntries = new ArrayList<CharSequence>();
|
||||
ArrayList<CharSequence> revisedValues = new ArrayList<CharSequence>();
|
||||
final ArrayList<CharSequence> revisedEntries = new ArrayList<>();
|
||||
final ArrayList<CharSequence> revisedValues = new ArrayList<>();
|
||||
for (int i = 0; i < mInitialValues.length; ++i) {
|
||||
long timeout = Long.parseLong(mInitialValues[i].toString());
|
||||
if (timeout <= maxTimeout) {
|
||||
@@ -101,7 +97,7 @@ public class TimeoutListPreference extends RestrictedListPreference {
|
||||
|
||||
// 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) {
|
||||
if (revisedValues.isEmpty()) {
|
||||
setDisabledByAdmin(admin);
|
||||
return;
|
||||
} else {
|
||||
@@ -128,4 +124,36 @@ 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,8 +13,6 @@
|
||||
*/
|
||||
package com.android.settings.display;
|
||||
|
||||
import static android.provider.Settings.System.SCREEN_OFF_TIMEOUT;
|
||||
|
||||
import android.app.admin.DevicePolicyManager;
|
||||
import android.content.Context;
|
||||
import android.os.UserHandle;
|
||||
@@ -60,7 +58,7 @@ public class TimeoutPreferenceController extends AbstractPreferenceController im
|
||||
public void updateState(Preference preference) {
|
||||
final TimeoutListPreference timeoutListPreference = (TimeoutListPreference) preference;
|
||||
final long currentTimeout = Settings.System.getLong(mContext.getContentResolver(),
|
||||
SCREEN_OFF_TIMEOUT, FALLBACK_SCREEN_TIMEOUT_VALUE);
|
||||
Settings.System.SCREEN_OFF_TIMEOUT, FALLBACK_SCREEN_TIMEOUT_VALUE);
|
||||
timeoutListPreference.setValue(String.valueOf(currentTimeout));
|
||||
final DevicePolicyManager dpm =
|
||||
(DevicePolicyManager) mContext.getSystemService(Context.DEVICE_POLICY_SERVICE);
|
||||
@@ -86,7 +84,8 @@ public class TimeoutPreferenceController extends AbstractPreferenceController im
|
||||
public boolean onPreferenceChange(Preference preference, Object newValue) {
|
||||
try {
|
||||
int value = Integer.parseInt((String) newValue);
|
||||
Settings.System.putInt(mContext.getContentResolver(), SCREEN_OFF_TIMEOUT, value);
|
||||
Settings.System.putInt(mContext.getContentResolver(),
|
||||
Settings.System.SCREEN_OFF_TIMEOUT, value);
|
||||
updateTimeoutPreferenceDescription((TimeoutListPreference) preference, value);
|
||||
} catch (NumberFormatException e) {
|
||||
Log.e(TAG, "could not persist screen timeout setting", e);
|
||||
@@ -94,7 +93,7 @@ public class TimeoutPreferenceController extends AbstractPreferenceController im
|
||||
return true;
|
||||
}
|
||||
|
||||
public static CharSequence getTimeoutDescription(
|
||||
private static CharSequence getTimeoutDescription(
|
||||
long currentTimeout, CharSequence[] entries, CharSequence[] values) {
|
||||
if (currentTimeout < 0 || entries == null || values == null
|
||||
|| values.length != entries.length) {
|
||||
|
@@ -88,4 +88,7 @@
|
||||
|
||||
<!-- Email address for the homepage contextual cards feedback -->
|
||||
<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>
|
||||
|
@@ -17,11 +17,11 @@ package com.android.settings.display;
|
||||
|
||||
import static com.google.common.truth.Truth.assertThat;
|
||||
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.robolectric.RuntimeEnvironment.application;
|
||||
|
||||
import android.util.AttributeSet;
|
||||
|
||||
import com.android.settings.R;
|
||||
import com.android.settings.testutils.shadow.ShadowUserManager;
|
||||
import com.android.settingslib.RestrictedLockUtils;
|
||||
|
||||
@@ -69,4 +69,23 @@ public class TimeoutListPreferenceTest {
|
||||
// should set to largest allowed value, which is 5 minute
|
||||
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