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

Commit 477cd4f2 authored by Lucas Dupin's avatar Lucas Dupin Committed by Android (Google) Code Review
Browse files

Merge "Hook up wake-lock-screen with plugin structure"

parents a1300eb0 3d95175d
Loading
Loading
Loading
Loading
+2 −5
Original line number Diff line number Diff line
@@ -72,7 +72,8 @@ public class AmbientDisplayConfiguration {
    }

    public boolean wakeLockScreenGestureAvailable() {
        return !TextUtils.isEmpty(wakeLockScreenSensorType());
        return mContext.getResources()
                .getBoolean(R.bool.config_dozeWakeLockScreenSensorAvailable);
    }

    public boolean wakeScreenGestureEnabled(int user) {
@@ -92,10 +93,6 @@ public class AmbientDisplayConfiguration {
        return mContext.getResources().getString(R.string.config_dozeLongPressSensorType);
    }

    public String wakeLockScreenSensorType() {
        return mContext.getResources().getString(R.string.config_dozeWakeLockScreenSensorType);
    }

    public String wakeScreenSensorType() {
        return mContext.getResources().getString(R.string.config_dozeWakeScreenSensorType);
    }
+2 −2
Original line number Diff line number Diff line
@@ -2113,8 +2113,8 @@
    <!-- Type of the long press sensor. Empty if long press is not supported. -->
    <string name="config_dozeLongPressSensorType" translatable="false"></string>

    <!-- Type of sensor that wakes up the lock screen. Empty if not supported. -->
    <string name="config_dozeWakeLockScreenSensorType" translatable="false"></string>
    <!-- If the sensor that wakes up the lock screen is available or not. -->
    <bool name="config_dozeWakeLockScreenSensorAvailable">false</bool>

    <!-- Type of the wake up sensor. Empty if not supported. -->
    <string name="config_dozeWakeScreenSensorType" translatable="false"></string>
+1 −1
Original line number Diff line number Diff line
@@ -3280,7 +3280,7 @@
  <java-symbol type="array" name="config_hideWhenDisabled_packageNames" />

  <java-symbol type="string" name="config_dozeLongPressSensorType" />
  <java-symbol type="string" name="config_dozeWakeLockScreenSensorType" />
  <java-symbol type="bool" name="config_dozeWakeLockScreenSensorAvailable" />

  <java-symbol type="array" name="config_allowedGlobalInstantAppSettings" />
  <java-symbol type="array" name="config_allowedSystemInstantAppSettings" />
+7 −2
Original line number Diff line number Diff line
@@ -16,6 +16,9 @@

package com.android.systemui.plugins;

import android.hardware.Sensor;
import android.hardware.TriggerEventListener;

import com.android.systemui.plugins.annotations.ProvidesInterface;

/**
@@ -28,10 +31,12 @@ public interface SensorManagerPlugin extends Plugin {
    int VERSION = 1;

    /**
     * Registers for trigger events from the sensor. The client will receive trigger events until
     * {@link #unregisterTriggerEvent(Sensor, TriggerEventListener)} is called.
     * Registers for trigger events from the sensor. Trigger events are one-shot and need to
     * re-registered in order for them to be fired again.
     * @param sensor
     * @param listener
     * @see android.hardware.SensorManager#requestTriggerSensor(
     *     android.hardware.TriggerEventListener, android.hardware.Sensor)
     */
    void registerTriggerEvent(Sensor sensor, TriggerEventListener listener);

+50 −3
Original line number Diff line number Diff line
@@ -16,6 +16,8 @@

package com.android.systemui.doze;

import static com.android.systemui.plugins.SensorManagerPlugin.Sensor.TYPE_WAKE_LOCK_SCREEN;

import android.annotation.AnyThread;
import android.app.ActivityManager;
import android.app.AlarmManager;
@@ -39,8 +41,10 @@ import android.util.Log;
import com.android.internal.hardware.AmbientDisplayConfiguration;
import com.android.internal.logging.MetricsLogger;
import com.android.internal.logging.nano.MetricsProto;
import com.android.systemui.plugins.SensorManagerPlugin;
import com.android.systemui.statusbar.phone.DozeParameters;
import com.android.systemui.util.AlarmTimeout;
import com.android.systemui.util.AsyncSensorManager;
import com.android.systemui.util.wakelock.WakeLock;

import java.io.PrintWriter;
@@ -112,8 +116,8 @@ public class DozeSensors {
                        DozeLog.PULSE_REASON_SENSOR_LONG_PRESS,
                        true /* reports touch coordinates */,
                        true /* touchscreen */),
                new TriggerSensor(
                        findSensorWithType(config.wakeLockScreenSensorType()),
                new PluginTriggerSensor(
                        new SensorManagerPlugin.Sensor(TYPE_WAKE_LOCK_SCREEN),
                        Settings.Secure.DOZE_WAKE_LOCK_SCREEN_GESTURE,
                        true /* configured */,
                        DozeLog.PULSE_REASON_SENSOR_WAKE_LOCK_SCREEN,
@@ -375,7 +379,7 @@ public class DozeSensors {
            mHandler.post(mWakeLock.wrap(() -> {
                if (DEBUG) Log.d(TAG, "onTrigger: " + triggerEventToString(event));
                boolean sensorPerformsProxCheck = false;
                if (mSensor.getType() == Sensor.TYPE_PICK_UP_GESTURE) {
                if (mSensor != null && mSensor.getType() == Sensor.TYPE_PICK_UP_GESTURE) {
                    int subType = (int) event.values[0];
                    MetricsLogger.action(
                            mContext, MetricsProto.MetricsEvent.ACTION_AMBIENT_GESTURE,
@@ -418,6 +422,49 @@ public class DozeSensors {
        }
    }

    /**
     * A Sensor that is injected via plugin, for better ContextHub interface.
     */
    private class PluginTriggerSensor extends TriggerSensor {

        private final SensorManagerPlugin.Sensor mPluginSensor;
        private final SensorManagerPlugin.TriggerEventListener mTriggerEventListener = (event) -> {
            onTrigger(null);
        };

        PluginTriggerSensor(SensorManagerPlugin.Sensor sensor, String setting, boolean configured,
                int pulseReason, boolean reportsTouchCoordinates, boolean requiresTouchscreen) {
            super(null, setting, configured, pulseReason, reportsTouchCoordinates,
                    requiresTouchscreen);
            mPluginSensor = sensor;
        }

        @Override
        public void updateListener() {
            if (!mConfigured) return;
            AsyncSensorManager asyncSensorManager = (AsyncSensorManager) mSensorManager;
            if (mRequested && !mDisabled && enabledBySetting() && !mRegistered) {
                asyncSensorManager.requestPluginTriggerSensor(mPluginSensor, mTriggerEventListener);
                mRegistered = true;
                if (DEBUG) Log.d(TAG, "requestPluginTriggerSensor");
            } else if (mRegistered) {
                asyncSensorManager.cancelPluginTriggerSensor(mPluginSensor, mTriggerEventListener);
                mRegistered = false;
                if (DEBUG) Log.d(TAG, "cancelPluginTriggerSensor");
            }
        }

        @Override
        public String toString() {
            return new StringBuilder("{mRegistered=").append(mRegistered)
                    .append(", mRequested=").append(mRequested)
                    .append(", mDisabled=").append(mDisabled)
                    .append(", mConfigured=").append(mConfigured)
                    .append(", mSensor=").append(mPluginSensor).append("}").toString();
        }

    }

    private class WakeScreenSensor extends TriggerSensor {

        WakeScreenSensor() {