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

Commit e4a1d0e4 authored by Beverly's avatar Beverly Committed by Beverly Tai
Browse files

Add posture support for prox sensor

Some postures don't need to register for a prox sensor

Test: manual, atest PostureDependentProximitySensorTest
Bug: 192805135
Change-Id: I5c5fbed6d3faff6ba690f67f592bb0b8082062d5
parent 2160b3d7
Loading
Loading
Loading
Loading
+5 −2
Original line number Original line Diff line number Diff line
@@ -24,6 +24,8 @@ import android.provider.Settings;
import android.text.TextUtils;
import android.text.TextUtils;
import android.util.Log;
import android.util.Log;


import java.util.Arrays;

import com.android.internal.R;
import com.android.internal.R;


/**
/**
@@ -258,10 +260,11 @@ public class AmbientDisplayConfiguration {
            String defaultValue,
            String defaultValue,
            int posture) {
            int posture) {
        String sensorType = defaultValue;
        String sensorType = defaultValue;
        if (posture < postureMapping.length) {
        if (postureMapping != null && posture < postureMapping.length) {
            sensorType = postureMapping[posture];
            sensorType = postureMapping[posture];
        } else {
        } else {
            Log.e(TAG, "Unsupported doze posture " + posture);
            Log.e(TAG, "Unsupported doze posture " + posture
                  + " postureMapping=" + Arrays.toString(postureMapping));
        }
        }


        return TextUtils.isEmpty(sensorType) ? defaultValue : sensorType;
        return TextUtils.isEmpty(sensorType) ? defaultValue : sensorType;
+21 −4
Original line number Original line Diff line number Diff line
@@ -224,15 +224,23 @@
         display brightness, suitable to listen to while the device is asleep (e.g. during
         display brightness, suitable to listen to while the device is asleep (e.g. during
         always-on display) -->
         always-on display) -->
    <string-array name="doze_brightness_sensor_name_posture_mapping" translatable="false">
    <string-array name="doze_brightness_sensor_name_posture_mapping" translatable="false">
        <item></item> <!-- UNKNOWN -->
        <!-- UNKNOWN -->
        <item></item> <!-- CLOSED -->
        <!-- CLOSED -->
        <item></item> <!-- HALF_OPENED -->
        <!-- HALF_OPENED -->
        <item></item> <!-- OPENED -->
        <!-- OPENED -->
    </string-array>
    </string-array>


    <!-- Override value to use for proximity sensor.  -->
    <!-- Override value to use for proximity sensor.  -->
    <string name="proximity_sensor_type" translatable="false"></string>
    <string name="proximity_sensor_type" translatable="false"></string>


    <!-- Sensor type per posture state to use for proximity sensor -->
    <string-array name="proximity_sensor_posture_mapping" translatable="false">
        <!-- UNKNOWN -->
        <!-- CLOSED -->
        <!-- HALF_OPENED -->
        <!-- OPENED -->
    </string-array>

    <!-- If using proximity_sensor_type, specifies a threshold value to distinguish near and
    <!-- If using proximity_sensor_type, specifies a threshold value to distinguish near and
         far break points. A sensor value less than this is considered "near". -->
         far break points. A sensor value less than this is considered "near". -->
    <item name="proximity_sensor_threshold" translatable="false" format="float" type="dimen"></item>
    <item name="proximity_sensor_threshold" translatable="false" format="float" type="dimen"></item>
@@ -246,6 +254,15 @@
    <!-- Override value to use for proximity sensor as confirmation for proximity_sensor_type. -->
    <!-- Override value to use for proximity sensor as confirmation for proximity_sensor_type. -->
    <string name="proximity_sensor_secondary_type" translatable="false"></string>
    <string name="proximity_sensor_secondary_type" translatable="false"></string>


    <!-- Sensor type per posture state to use for proximity sensor as a confirmation for
        proximity_sensor_type. -->
    <string-array name="proximity_sensor_secondary_posture_mapping" translatable="false">
        <!-- UNKNOWN -->
        <!-- CLOSED -->
        <!-- HALF_OPENED -->
        <!-- OPENED -->
    </string-array>

    <!-- If using proximity_sensor_secondary_type, specifies a threshold value to distinguish
    <!-- If using proximity_sensor_secondary_type, specifies a threshold value to distinguish
         near and far break points. A sensor value less than this is considered "near". -->
         near and far break points. A sensor value less than this is considered "near". -->
    <item name="proximity_sensor_secondary_threshold" translatable="false" format="float"
    <item name="proximity_sensor_secondary_threshold" translatable="false" format="float"
+4 −3
Original line number Original line Diff line number Diff line
@@ -37,6 +37,7 @@ import com.android.systemui.statusbar.policy.KeyguardStateController;
import com.android.systemui.util.concurrency.DelayableExecutor;
import com.android.systemui.util.concurrency.DelayableExecutor;
import com.android.systemui.util.sensors.ProximitySensor;
import com.android.systemui.util.sensors.ProximitySensor;
import com.android.systemui.util.sensors.ThresholdSensor;
import com.android.systemui.util.sensors.ThresholdSensor;
import com.android.systemui.util.sensors.ThresholdSensorEvent;
import com.android.systemui.util.time.SystemClock;
import com.android.systemui.util.time.SystemClock;


import java.util.Collections;
import java.util.Collections;
@@ -405,7 +406,7 @@ class FalsingCollectorImpl implements FalsingCollector {
        mProximitySensor.unregister(mSensorEventListener);
        mProximitySensor.unregister(mSensorEventListener);
    }
    }


    private void onProximityEvent(ThresholdSensor.ThresholdSensorEvent proximityEvent) {
    private void onProximityEvent(ThresholdSensorEvent proximityEvent) {
        // TODO: some of these classifiers might allow us to abort early, meaning we don't have to
        // TODO: some of these classifiers might allow us to abort early, meaning we don't have to
        // make these calls.
        // make these calls.
        mFalsingManager.onProximityEvent(new ProximityEventImpl(proximityEvent));
        mFalsingManager.onProximityEvent(new ProximityEventImpl(proximityEvent));
@@ -423,9 +424,9 @@ class FalsingCollectorImpl implements FalsingCollector {
    }
    }


    private static class ProximityEventImpl implements FalsingManager.ProximityEvent {
    private static class ProximityEventImpl implements FalsingManager.ProximityEvent {
        private ThresholdSensor.ThresholdSensorEvent mThresholdSensorEvent;
        private ThresholdSensorEvent mThresholdSensorEvent;


        ProximityEventImpl(ThresholdSensor.ThresholdSensorEvent thresholdSensorEvent) {
        ProximityEventImpl(ThresholdSensorEvent thresholdSensorEvent) {
            mThresholdSensorEvent = thresholdSensorEvent;
            mThresholdSensorEvent = thresholdSensorEvent;
        }
        }
        @Override
        @Override
+4 −2
Original line number Original line Diff line number Diff line
@@ -46,6 +46,7 @@ import com.android.systemui.statusbar.policy.KeyguardStateController;
import com.android.systemui.util.Assert;
import com.android.systemui.util.Assert;
import com.android.systemui.util.concurrency.DelayableExecutor;
import com.android.systemui.util.concurrency.DelayableExecutor;
import com.android.systemui.util.sensors.AsyncSensorManager;
import com.android.systemui.util.sensors.AsyncSensorManager;
import com.android.systemui.util.sensors.ProximityCheck;
import com.android.systemui.util.sensors.ProximitySensor;
import com.android.systemui.util.sensors.ProximitySensor;
import com.android.systemui.util.settings.SecureSettings;
import com.android.systemui.util.settings.SecureSettings;
import com.android.systemui.util.wakelock.WakeLock;
import com.android.systemui.util.wakelock.WakeLock;
@@ -90,7 +91,7 @@ public class DozeTriggers implements DozeMachine.Part {
    private final TriggerReceiver mBroadcastReceiver = new TriggerReceiver();
    private final TriggerReceiver mBroadcastReceiver = new TriggerReceiver();
    private final DockEventListener mDockEventListener = new DockEventListener();
    private final DockEventListener mDockEventListener = new DockEventListener();
    private final DockManager mDockManager;
    private final DockManager mDockManager;
    private final ProximitySensor.ProximityCheck mProxCheck;
    private final ProximityCheck mProxCheck;
    private final BroadcastDispatcher mBroadcastDispatcher;
    private final BroadcastDispatcher mBroadcastDispatcher;
    private final AuthController mAuthController;
    private final AuthController mAuthController;
    private final DelayableExecutor mMainExecutor;
    private final DelayableExecutor mMainExecutor;
@@ -181,7 +182,8 @@ public class DozeTriggers implements DozeMachine.Part {
            AmbientDisplayConfiguration config,
            AmbientDisplayConfiguration config,
            DozeParameters dozeParameters, AsyncSensorManager sensorManager,
            DozeParameters dozeParameters, AsyncSensorManager sensorManager,
            WakeLock wakeLock, DockManager dockManager,
            WakeLock wakeLock, DockManager dockManager,
            ProximitySensor proximitySensor, ProximitySensor.ProximityCheck proxCheck,
            ProximitySensor proximitySensor,
            ProximityCheck proxCheck,
            DozeLog dozeLog, BroadcastDispatcher broadcastDispatcher,
            DozeLog dozeLog, BroadcastDispatcher broadcastDispatcher,
            SecureSettings secureSettings, AuthController authController,
            SecureSettings secureSettings, AuthController authController,
            @Main DelayableExecutor mainExecutor,
            @Main DelayableExecutor mainExecutor,
+1 −0
Original line number Original line Diff line number Diff line
@@ -46,6 +46,7 @@ public interface DevicePostureController extends CallbackController<Callback> {
    int DEVICE_POSTURE_HALF_OPENED = 2;
    int DEVICE_POSTURE_HALF_OPENED = 2;
    int DEVICE_POSTURE_OPENED = 3;
    int DEVICE_POSTURE_OPENED = 3;
    int DEVICE_POSTURE_FLIPPED = 4;
    int DEVICE_POSTURE_FLIPPED = 4;
    int SUPPORTED_POSTURES_SIZE = DEVICE_POSTURE_FLIPPED + 1;


    /** Return the current device posture. */
    /** Return the current device posture. */
    @DevicePostureInt int getDevicePosture();
    @DevicePostureInt int getDevicePosture();
Loading