Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 69e4302d authored by Fan Zhang's avatar Fan Zhang
Browse files

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 f57f490a.

Fixes: 113346164
Test: manual

Change-Id: Ifbb054c232c47455ae82e3ed817f9c1e96f694cf
parent 3eac2faa
Loading
Loading
Loading
Loading
+0 −3
Original line number Diff line number Diff line
@@ -172,9 +172,6 @@
    <!-- 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>

    <!-- App intent -->
    <string name="config_account_intent_uri" translatable="false"></string>
</resources>
+3 −0
Original line number Diff line number Diff line
@@ -5841,6 +5841,9 @@
         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] -->
+1 −1
Original line number Diff line number Diff line
@@ -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_title"
            android:title="@string/date_time_set_timezone"
            android:summary="@string/summary_placeholder"
            settings:userRestriction="no_config_date_time" />
    </PreferenceCategory>
+15 −43
Original line number Diff line number Diff line
@@ -26,7 +26,6 @@ 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;
@@ -34,18 +33,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 CharSequence[] mInitialEntries;
    private CharSequence[] mInitialValues;
    private final CharSequence[] mInitialEntries;
    private final CharSequence[] mInitialValues;

    public TimeoutListPreference(Context context, AttributeSet attrs) {
        super(context, attrs);
        updateInitialValues();
        mInitialEntries = getEntries();
        mInitialValues = getEntryValues();
    }

    @Override
@@ -66,8 +65,13 @@ 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(
                    view -> RestrictedLockUtils.sendShowAdminSupportDetailsIntent(
                            getContext(), mAdmin));
                    new View.OnClickListener() {
                        @Override
                        public void onClick(View view) {
                            RestrictedLockUtils.sendShowAdminSupportDetailsIntent(
                                    getContext(), mAdmin);
                        }
                    });
        }
    }

@@ -85,8 +89,8 @@ public class TimeoutListPreference extends RestrictedListPreference {
            maxTimeout = Long.MAX_VALUE;
        }

        final ArrayList<CharSequence> revisedEntries = new ArrayList<>();
        final ArrayList<CharSequence> revisedValues = new ArrayList<>();
        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) {
@@ -97,7 +101,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.isEmpty()) {
        if (revisedValues.size() == 0) {
            setDisabledByAdmin(admin);
            return;
        } 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);
    }
}
+5 −4
Original line number Diff line number Diff line
@@ -13,6 +13,8 @@
 */
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;
@@ -58,7 +60,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(),
                Settings.System.SCREEN_OFF_TIMEOUT, FALLBACK_SCREEN_TIMEOUT_VALUE);
                SCREEN_OFF_TIMEOUT, FALLBACK_SCREEN_TIMEOUT_VALUE);
        timeoutListPreference.setValue(String.valueOf(currentTimeout));
        final DevicePolicyManager dpm =
                (DevicePolicyManager) mContext.getSystemService(Context.DEVICE_POLICY_SERVICE);
@@ -84,8 +86,7 @@ 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(),
                    Settings.System.SCREEN_OFF_TIMEOUT, value);
            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);
@@ -93,7 +94,7 @@ public class TimeoutPreferenceController extends AbstractPreferenceController im
        return true;
    }

    private static CharSequence getTimeoutDescription(
    public static CharSequence getTimeoutDescription(
            long currentTimeout, CharSequence[] entries, CharSequence[] values) {
        if (currentTimeout < 0 || entries == null || values == null
                || values.length != entries.length) {
Loading