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

Commit 04e7d1fa authored by Lei Yu's avatar Lei Yu Committed by android-build-merger
Browse files

Merge "Hook up AOD knobs to Settings.Global" into oc-mr1-dev

am: 67594c6f

Change-Id: Ifbb83939c2c2c30048fe43b2092b2afe4c3b234c
parents 8a4449f2 67594c6f
Loading
Loading
Loading
Loading
+19 −0
Original line number Diff line number Diff line
@@ -9345,6 +9345,25 @@ public final class Settings {
         */
        public static final String ANOMALY_DETECTION_CONSTANTS = "anomaly_detection_constants";

        /**
         * Always on display(AOD) specific settings
         * This is encoded as a key=value list, separated by commas. Ex:
         *
         * "prox_screen_off_delay=10000,screen_brightness_array=0:1:2:3:4"
         *
         * The following keys are supported:
         *
         * <pre>
         * screen_brightness_array         (string)
         * dimming_scrim_array             (string)
         * prox_screen_off_delay           (long)
         * prox_cooldown_trigger           (long)
         * prox_cooldown_period            (long)
         * </pre>
         * @hide
         */
        public static final String ALWAYS_ON_DISPLAY_CONSTANTS = "always_on_display_constants";

        /**
         * App standby (app idle) specific settings.
         * This is encoded as a key=value list, separated by commas. Ex:
+1 −0
Original line number Diff line number Diff line
@@ -99,6 +99,7 @@ public class SettingsBackupTest {
                    Settings.Global.ALARM_MANAGER_CONSTANTS,
                    Settings.Global.ALLOW_USER_SWITCHING_WHEN_SYSTEM_USER_LOCKED,
                    Settings.Global.ALWAYS_FINISH_ACTIVITIES,
                    Settings.Global.ALWAYS_ON_DISPLAY_CONSTANTS,
                    Settings.Global.ANIMATOR_DURATION_SCALE,
                    Settings.Global.ANOMALY_DETECTION_CONSTANTS,
                    Settings.Global.APN_DB_UPDATE_CONTENT_URL,
+122 −0
Original line number Diff line number Diff line
/*
 * Copyright (C) 2017 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.systemui.doze;

import android.content.Context;
import android.content.res.Resources;
import android.provider.Settings;
import android.text.format.DateUtils;
import android.util.KeyValueListParser;
import android.util.Log;

import com.android.systemui.R;

import java.util.Arrays;

/**
 * Class to store the policy for AOD, which comes from
 * {@link android.provider.Settings.Global}
 */
public class AlwaysOnDisplayPolicy {
    public static final String TAG = "AlwaysOnDisplayPolicy";

    static final String KEY_SCREEN_BRIGHTNESS_ARRAY = "screen_brightness_array";
    static final String KEY_DIMMING_SCRIM_ARRAY = "dimming_scrim_array";
    static final String KEY_PROX_SCREEN_OFF_DELAY_MS = "prox_screen_off_delay";
    static final String KEY_PROX_COOLDOWN_TRIGGER_MS = "prox_cooldown_trigger";
    static final String KEY_PROX_COOLDOWN_PERIOD_MS = "prox_cooldown_period";

    /**
     * Integer array to map ambient brightness type to real screen brightness.
     *
     * @see Settings.Global#ALWAYS_ON_DISPLAY_CONSTANTS
     * @see #KEY_SCREEN_BRIGHTNESS_ARRAY
     */
    public final int[] screenBrightnessArray;

    /**
     * Integer array to map ambient brightness type to dimming scrim.
     *
     * @see Settings.Global#ALWAYS_ON_DISPLAY_CONSTANTS
     * @see #KEY_DIMMING_SCRIM_ARRAY
     */
    public final int[] dimmingScrimArray;

    /**
     * Delay time(ms) from covering the prox to turning off the screen.
     *
     * @see Settings.Global#ALWAYS_ON_DISPLAY_CONSTANTS
     * @see #KEY_PROX_SCREEN_OFF_DELAY_MS
     */
    public final long proxScreenOffDelayMs;

    /**
     * The threshold time(ms) to trigger the cooldown timer, which will
     * turn off prox sensor for a period.
     *
     * @see Settings.Global#ALWAYS_ON_DISPLAY_CONSTANTS
     * @see #KEY_PROX_COOLDOWN_TRIGGER_MS
     */
    public final long proxCooldownTriggerMs;

    /**
     * The period(ms) to turning off the prox sensor if
     * {@link #KEY_PROX_COOLDOWN_TRIGGER_MS} is triggered.
     *
     * @see Settings.Global#ALWAYS_ON_DISPLAY_CONSTANTS
     * @see #KEY_PROX_COOLDOWN_PERIOD_MS
     */
    public final long proxCooldownPeriodMs;

    private final KeyValueListParser mParser;

    public AlwaysOnDisplayPolicy(Context context) {
        final Resources resources = context.getResources();
        mParser = new KeyValueListParser(',');

        final String value = Settings.Global.getString(context.getContentResolver(),
                Settings.Global.ALWAYS_ON_DISPLAY_CONSTANTS);

        try {
            mParser.setString(value);
        } catch (IllegalArgumentException e) {
            Log.e(TAG, "Bad AOD constants");
        }

        proxScreenOffDelayMs = mParser.getLong(KEY_PROX_SCREEN_OFF_DELAY_MS,
                10 * DateUtils.MINUTE_IN_MILLIS);
        proxCooldownTriggerMs = mParser.getLong(KEY_PROX_COOLDOWN_TRIGGER_MS,
                2 * DateUtils.MINUTE_IN_MILLIS);
        proxCooldownPeriodMs = mParser.getLong(KEY_PROX_COOLDOWN_PERIOD_MS,
                5 * DateUtils.MINUTE_IN_MILLIS);
        screenBrightnessArray = parseIntArray(KEY_SCREEN_BRIGHTNESS_ARRAY,
                resources.getIntArray(R.array.config_doze_brightness_sensor_to_brightness));
        dimmingScrimArray = parseIntArray(KEY_DIMMING_SCRIM_ARRAY,
                resources.getIntArray(R.array.config_doze_brightness_sensor_to_scrim_opacity));
    }

    private int[] parseIntArray(final String key, final int[] defaultArray) {
        final String value = mParser.getString(key, null);
        if (value != null) {
            return Arrays.stream(value.split(":")).map(String::trim).mapToInt(
                    Integer::parseInt).toArray();
        } else {
            return defaultArray;
        }
    }

}
+3 −2
Original line number Diff line number Diff line
@@ -59,7 +59,7 @@ public class DozeFactory {

        DozeMachine machine = new DozeMachine(wrappedService, config, wakeLock);
        machine.setParts(new DozeMachine.Part[]{
                new DozePauser(handler, machine, alarmManager),
                new DozePauser(handler, machine, alarmManager, new AlwaysOnDisplayPolicy(context)),
                new DozeFalsingManagerAdapter(FalsingManager.getInstance(context)),
                createDozeTriggers(context, sensorManager, host, alarmManager, config, params,
                        handler, wakeLock, machine),
@@ -76,7 +76,8 @@ public class DozeFactory {
            Handler handler) {
        Sensor sensor = DozeSensors.findSensorWithType(sensorManager,
                context.getString(R.string.doze_brightness_sensor_type));
        return new DozeScreenBrightness(context, service, sensorManager, sensor, host, handler);
        return new DozeScreenBrightness(context, service, sensorManager, sensor, host, handler,
                new AlwaysOnDisplayPolicy(context));
    }

    private DozeTriggers createDozeTriggers(Context context, SensorManager sensorManager,
+5 −3
Original line number Diff line number Diff line
@@ -26,20 +26,22 @@ import com.android.systemui.util.AlarmTimeout;
 */
public class DozePauser implements DozeMachine.Part {
    public static final String TAG = DozePauser.class.getSimpleName();
    private static final long TIMEOUT = 10 * 1000;
    private final AlarmTimeout mPauseTimeout;
    private final DozeMachine mMachine;
    private final long mTimeoutMs;

    public DozePauser(Handler handler, DozeMachine machine, AlarmManager alarmManager) {
    public DozePauser(Handler handler, DozeMachine machine, AlarmManager alarmManager,
            AlwaysOnDisplayPolicy policy) {
        mMachine = machine;
        mPauseTimeout = new AlarmTimeout(alarmManager, this::onTimeout, TAG, handler);
        mTimeoutMs = policy.proxScreenOffDelayMs;
    }

    @Override
    public void transitionTo(DozeMachine.State oldState, DozeMachine.State newState) {
        switch (newState) {
            case DOZE_AOD_PAUSING:
                mPauseTimeout.schedule(TIMEOUT, AlarmTimeout.MODE_IGNORE_IF_SCHEDULED);
                mPauseTimeout.schedule(mTimeoutMs, AlarmTimeout.MODE_IGNORE_IF_SCHEDULED);
                break;
            default:
                mPauseTimeout.cancel();
Loading