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

Commit 4540811b authored by TreeHugger Robot's avatar TreeHugger Robot Committed by Android (Google) Code Review
Browse files

Merge "AOD: Refactor always on configuration"

parents 8cfea139 28d26a82
Loading
Loading
Loading
Loading
+13 −1
Original line number Diff line number Diff line
@@ -19,6 +19,7 @@ package com.android.internal.hardware;
import com.android.internal.R;

import android.content.Context;
import android.os.Build;
import android.provider.Settings;
import android.text.TextUtils;

@@ -33,7 +34,8 @@ public class AmbientDisplayConfiguration {
    public boolean enabled(int user) {
        return pulseOnNotificationEnabled(user)
                || pulseOnPickupEnabled(user)
                || pulseOnDoubleTapEnabled(user);
                || pulseOnDoubleTapEnabled(user)
                || alwaysOnEnabled(user);
    }
    
    public boolean available() {
@@ -72,6 +74,16 @@ public class AmbientDisplayConfiguration {
        return mContext.getResources().getString(R.string.config_dozeDoubleTapSensorType);
    }

    public boolean alwaysOnEnabled(int user) {
        return boolSetting(Settings.Secure.DOZE_ALWAYS_ON, user)
                && alwaysOnAvailable();
    }

    public boolean alwaysOnAvailable() {
        // TODO: introduce config_dozeAlwaysOnAvailable. For now just debuggable builds.
        return Build.IS_DEBUGGABLE && ambientDisplayAvailable();
    }

    public String ambientDisplayComponent() {
        return mContext.getResources().getString(R.string.config_dozeComponent);
    }
+1 −1
Original line number Diff line number Diff line
@@ -53,7 +53,7 @@ public class DozeFactory {

        DozeMachine machine = new DozeMachine(
                DozeScreenStatePreventingAdapter.wrapIfNeeded(dozeService, params),
                params,
                config,
                wakeLock);
        machine.setParts(new DozeMachine.Part[]{
                createDozeTriggers(context, sensorManager, host, config, params, handler, wakeLock,
+7 −5
Original line number Diff line number Diff line
@@ -17,11 +17,12 @@
package com.android.systemui.doze;

import android.annotation.MainThread;
import android.os.UserHandle;
import android.util.Log;
import android.view.Display;

import com.android.internal.hardware.AmbientDisplayConfiguration;
import com.android.internal.util.Preconditions;
import com.android.systemui.statusbar.phone.DozeParameters;
import com.android.systemui.util.Assert;

import java.io.PrintWriter;
@@ -95,16 +96,17 @@ public class DozeMachine {

    private final Service mDozeService;
    private final DozeFactory.WakeLock mWakeLock;
    private final DozeParameters mParams;
    private final AmbientDisplayConfiguration mConfig;
    private Part[] mParts;

    private final ArrayList<State> mQueuedRequests = new ArrayList<>();
    private State mState = State.UNINITIALIZED;
    private boolean mWakeLockHeldForCurrentState = false;

    public DozeMachine(Service service, DozeParameters params, DozeFactory.WakeLock wakeLock) {
    public DozeMachine(Service service, AmbientDisplayConfiguration config,
            DozeFactory.WakeLock wakeLock) {
        mDozeService = service;
        mParams = params;
        mConfig = config;
        mWakeLock = wakeLock;
    }

@@ -267,7 +269,7 @@ public class DozeMachine {
        switch (state) {
            case INITIALIZED:
            case DOZE_PULSE_DONE:
                transitionTo(mParams.getAlwaysOn()
                transitionTo(mConfig.alwaysOnEnabled(UserHandle.USER_CURRENT)
                        ? DozeMachine.State.DOZE_AOD : DozeMachine.State.DOZE);
                break;
            default:
+6 −8
Original line number Diff line number Diff line
@@ -17,7 +17,6 @@
package com.android.systemui.statusbar.phone;

import android.content.Context;
import android.os.Build;
import android.os.SystemProperties;
import android.os.UserHandle;
import android.provider.Settings;
@@ -25,6 +24,7 @@ import android.text.TextUtils;
import android.util.MathUtils;
import android.util.SparseBooleanArray;

import com.android.internal.hardware.AmbientDisplayConfiguration;
import com.android.systemui.R;

import java.io.PrintWriter;
@@ -32,14 +32,15 @@ import java.io.PrintWriter;
public class DozeParameters {
    private static final int MAX_DURATION = 60 * 1000;
    public static final String DOZE_SENSORS_WAKE_UP_FULLY = "doze_sensors_wake_up_fully";
    public static final boolean ALWAYS_ON_AVAILABLE = Build.IS_DEBUGGABLE;

    private final Context mContext;
    private final AmbientDisplayConfiguration mAmbientDisplayConfiguration;

    private static IntInOutMatcher sPickupSubtypePerformsProxMatcher;

    public DozeParameters(Context context) {
        mContext = context;
        mAmbientDisplayConfiguration = new AmbientDisplayConfiguration(mContext);
    }

    public void dump(PrintWriter pw) {
@@ -58,8 +59,7 @@ public class DozeParameters {
        pw.print("    getPickupVibrationThreshold(): "); pw.println(getPickupVibrationThreshold());
        pw.print("    getPickupSubtypePerformsProxCheck(): ");pw.println(
                dumpPickupSubtypePerformsProxCheck());
        if (ALWAYS_ON_AVAILABLE) {
            pw.print("    getAlwaysOn(): "); pw.println(getAlwaysOn());
        if (mAmbientDisplayConfiguration.alwaysOnAvailable()) {
            pw.print("    getSensorsWakeUpFully(): "); pw.println(getSensorsWakeUpFully());
        }
    }
@@ -119,13 +119,11 @@ public class DozeParameters {
    }

    public boolean getAlwaysOn() {
        return ALWAYS_ON_AVAILABLE
                && Settings.Secure.getIntForUser(mContext.getContentResolver(),
                Settings.Secure.DOZE_ALWAYS_ON, 0, UserHandle.USER_CURRENT) != 0;
        return mAmbientDisplayConfiguration.alwaysOnEnabled(UserHandle.USER_CURRENT);
    }

    public boolean getSensorsWakeUpFully() {
        return ALWAYS_ON_AVAILABLE
        return mAmbientDisplayConfiguration.alwaysOnAvailable()
                && Settings.Secure.getIntForUser(mContext.getContentResolver(),
                DOZE_SENSORS_WAKE_UP_FULLY, 1, UserHandle.USER_CURRENT) != 0;
    }
+6 −2
Original line number Diff line number Diff line
@@ -26,11 +26,11 @@ import android.view.Menu;
import android.view.MenuInflater;
import android.view.MenuItem;

import com.android.internal.hardware.AmbientDisplayConfiguration;
import com.android.internal.logging.MetricsLogger;
import com.android.internal.logging.nano.MetricsProto.MetricsEvent;
import com.android.systemui.R;
import com.android.systemui.plugins.PluginPrefs;
import com.android.systemui.statusbar.phone.DozeParameters;

public class TunerFragment extends PreferenceFragment {

@@ -65,7 +65,7 @@ public class TunerFragment extends PreferenceFragment {
        if (!PluginPrefs.hasPlugins(getContext())) {
            getPreferenceScreen().removePreference(findPreference(KEY_PLUGINS));
        }
        if (!DozeParameters.ALWAYS_ON_AVAILABLE) {
        if (!alwaysOnAvailable()) {
            getPreferenceScreen().removePreference(findPreference(KEY_DOZE));
        }

@@ -77,6 +77,10 @@ public class TunerFragment extends PreferenceFragment {
        }
    }

    private boolean alwaysOnAvailable() {
        return new AmbientDisplayConfiguration(getContext()).alwaysOnAvailable();
    }

    @Override
    public void onResume() {
        super.onResume();
Loading