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

Commit dc9db97e authored by Asmita Poddar's avatar Asmita Poddar Committed by Android (Google) Code Review
Browse files

Merge "Move InputDeviceSensorManager to InputManagerGlobal" into udc-dev

parents f7e7e294 4a417805
Loading
Loading
Loading
Loading
+11 −11
Original line number Diff line number Diff line
@@ -56,7 +56,7 @@ public class InputDeviceSensorManager implements InputManager.InputDeviceListene
    private static final int MSG_SENSOR_ACCURACY_CHANGED = 1;
    private static final int MSG_SENSOR_CHANGED = 2;

    private InputManager mInputManager;
    private InputManagerGlobal mGlobal;

    // sensor map from device id to sensor list
    @GuardedBy("mInputSensorLock")
@@ -70,15 +70,15 @@ public class InputDeviceSensorManager implements InputManager.InputDeviceListene
    private final HandlerThread mSensorThread;
    private final Handler mSensorHandler;

    public InputDeviceSensorManager(InputManager inputManager) {
        mInputManager = inputManager;
    public InputDeviceSensorManager(InputManagerGlobal inputManagerGlobal) {
        mGlobal = inputManagerGlobal;

        mSensorThread = new HandlerThread("SensorThread");
        mSensorThread.start();
        mSensorHandler = new Handler(mSensorThread.getLooper());

        // Register the input device listener
        mInputManager.registerInputDeviceListener(this, mSensorHandler);
        mGlobal.registerInputDeviceListener(this, mSensorHandler);
        // Initialize the sensor list
        initializeSensors();
    }
@@ -100,7 +100,7 @@ public class InputDeviceSensorManager implements InputManager.InputDeviceListene
        final InputDevice inputDevice = InputDevice.getDevice(deviceId);
        if (inputDevice != null && inputDevice.hasSensor()) {
            final InputSensorInfo[] sensorInfos =
                    mInputManager.getSensorList(deviceId);
                    mGlobal.getSensorList(deviceId);
            populateSensorsForInputDeviceLocked(deviceId, sensorInfos);
        }
    }
@@ -154,7 +154,7 @@ public class InputDeviceSensorManager implements InputManager.InputDeviceListene
    private void initializeSensors() {
        synchronized (mInputSensorLock) {
            mSensors.clear();
            int[] deviceIds = mInputManager.getInputDeviceIds();
            int[] deviceIds = mGlobal.getInputDeviceIds();
            for (int i = 0; i < deviceIds.length; i++) {
                final int deviceId = deviceIds[i];
                updateInputDeviceSensorInfoLocked(deviceId);
@@ -455,7 +455,7 @@ public class InputDeviceSensorManager implements InputManager.InputDeviceListene
                    Slog.e(TAG, "The device doesn't have the sensor:" + sensor);
                    return false;
                }
                if (!mInputManager.enableSensor(deviceId, sensor.getType(), delayUs,
                if (!mGlobal.enableSensor(deviceId, sensor.getType(), delayUs,
                        maxBatchReportLatencyUs)) {
                    Slog.e(TAG, "Can't enable the sensor:" + sensor);
                    return false;
@@ -467,7 +467,7 @@ public class InputDeviceSensorManager implements InputManager.InputDeviceListene
            // Register the InputManagerService sensor listener if not yet.
            if (mInputServiceSensorListener == null) {
                mInputServiceSensorListener = new InputSensorEventListener();
                if (!mInputManager.registerSensorListener(mInputServiceSensorListener)) {
                if (!mGlobal.registerSensorListener(mInputServiceSensorListener)) {
                    Slog.e(TAG, "Failed registering the sensor listener");
                    return false;
                }
@@ -516,7 +516,7 @@ public class InputDeviceSensorManager implements InputManager.InputDeviceListene
            }
            // If no delegation remains, unregister the listener to input service
            if (mInputServiceSensorListener != null && mInputSensorEventListeners.size() == 0) {
                mInputManager.unregisterSensorListener(mInputServiceSensorListener);
                mGlobal.unregisterSensorListener(mInputServiceSensorListener);
                mInputServiceSensorListener = null;
            }
            // For each sensor type check if it is still in use by other listeners.
@@ -539,7 +539,7 @@ public class InputDeviceSensorManager implements InputManager.InputDeviceListene
                    if (DEBUG) {
                        Slog.d(TAG, "device " + deviceId + " sensor " + sensorType + " disabled");
                    }
                    mInputManager.disableSensor(deviceId, sensorType);
                    mGlobal.disableSensor(deviceId, sensorType);
                }
            }
        }
@@ -553,7 +553,7 @@ public class InputDeviceSensorManager implements InputManager.InputDeviceListene
            }
            for (Sensor sensor : mInputSensorEventListeners.get(idx).getSensors()) {
                final int deviceId = sensor.getId();
                if (!mInputManager.flushSensor(deviceId, sensor.getType())) {
                if (!mGlobal.flushSensor(deviceId, sensor.getType())) {
                    return false;
                }
            }
+8 −36
Original line number Diff line number Diff line
@@ -103,7 +103,6 @@ public final class InputManager {
    @Nullable
    private Boolean mIsStylusPointerIconEnabled = null;

    private InputDeviceSensorManager mInputDeviceSensorManager;
    /**
     * Broadcast Action: Query available keyboard layouts.
     * <p>
@@ -1224,11 +1223,7 @@ public final class InputManager {
     * @hide
     */
    public InputSensorInfo[] getSensorList(int deviceId) {
        try {
            return mIm.getSensorList(deviceId);
        } catch (RemoteException ex) {
            throw ex.rethrowFromSystemServer();
        }
        return mGlobal.getSensorList(deviceId);
    }

    /**
@@ -1238,12 +1233,8 @@ public final class InputManager {
     */
    public boolean enableSensor(int deviceId, int sensorType, int samplingPeriodUs,
            int maxBatchReportLatencyUs) {
        try {
            return mIm.enableSensor(deviceId, sensorType, samplingPeriodUs,
        return mGlobal.enableSensor(deviceId, sensorType, samplingPeriodUs,
                maxBatchReportLatencyUs);
        } catch (RemoteException ex) {
            throw ex.rethrowFromSystemServer();
        }
    }

    /**
@@ -1252,11 +1243,7 @@ public final class InputManager {
     * @hide
     */
    public void disableSensor(int deviceId, int sensorType) {
        try {
            mIm.disableSensor(deviceId, sensorType);
        } catch (RemoteException ex) {
            throw ex.rethrowFromSystemServer();
        }
        mGlobal.disableSensor(deviceId, sensorType);
    }

    /**
@@ -1265,11 +1252,7 @@ public final class InputManager {
     * @hide
     */
    public boolean flushSensor(int deviceId, int sensorType) {
        try {
            return mIm.flushSensor(deviceId, sensorType);
        } catch (RemoteException ex) {
            throw ex.rethrowFromSystemServer();
        }
        return mGlobal.flushSensor(deviceId, sensorType);
    }

    /**
@@ -1278,11 +1261,7 @@ public final class InputManager {
     * @hide
     */
    public boolean registerSensorListener(IInputSensorEventListener listener) {
        try {
            return mIm.registerSensorListener(listener);
        } catch (RemoteException ex) {
            throw ex.rethrowFromSystemServer();
        }
        return mGlobal.registerSensorListener(listener);
    }

    /**
@@ -1291,11 +1270,7 @@ public final class InputManager {
     * @hide
     */
    public void unregisterSensorListener(IInputSensorEventListener listener) {
        try {
            mIm.unregisterSensorListener(listener);
        } catch (RemoteException ex) {
            throw ex.rethrowFromSystemServer();
        }
        mGlobal.unregisterSensorListener(listener);
    }

    /**
@@ -1504,10 +1479,7 @@ public final class InputManager {
     */
    @NonNull
    public SensorManager getInputDeviceSensorManager(int deviceId) {
        if (mInputDeviceSensorManager == null) {
            mInputDeviceSensorManager = new InputDeviceSensorManager(this);
        }
        return mInputDeviceSensorManager.getSensorManager(deviceId);
        return mGlobal.getInputDeviceSensorManager(deviceId);
    }

    /**
+82 −0
Original line number Diff line number Diff line
@@ -22,6 +22,7 @@ import android.annotation.Nullable;
import android.annotation.RequiresPermission;
import android.content.Context;
import android.hardware.BatteryState;
import android.hardware.SensorManager;
import android.hardware.input.InputManager.InputDeviceBatteryListener;
import android.hardware.input.InputManager.InputDeviceListener;
import android.hardware.input.InputManager.KeyboardBacklightListener;
@@ -82,6 +83,8 @@ public final class InputManagerGlobal {
    @GuardedBy("mKeyboardBacklightListenerLock")
    @Nullable private IKeyboardBacklightListener mKeyboardBacklightListener;

    @Nullable private InputDeviceSensorManager mInputDeviceSensorManager;

    private static InputManagerGlobal sInstance;

    private final IInputManager mIm;
@@ -821,4 +824,83 @@ public final class InputManagerGlobal {
            }
        }
    }

    /**
     * @see InputManager#getInputDeviceSensorManager(int)
     */
    @NonNull
    SensorManager getInputDeviceSensorManager(int deviceId) {
        if (mInputDeviceSensorManager == null) {
            mInputDeviceSensorManager = new InputDeviceSensorManager(this);
        }
        return mInputDeviceSensorManager.getSensorManager(deviceId);
    }

    /**
     * @see InputManager#getSensorList(int)
     */
    InputSensorInfo[] getSensorList(int deviceId) {
        try {
            return mIm.getSensorList(deviceId);
        } catch (RemoteException ex) {
            throw ex.rethrowFromSystemServer();
        }
    }

    /**
     * @see InputManager#enableSensor(int, int, int, int)
     */
    boolean enableSensor(int deviceId, int sensorType, int samplingPeriodUs,
            int maxBatchReportLatencyUs) {
        try {
            return mIm.enableSensor(deviceId, sensorType, samplingPeriodUs,
                    maxBatchReportLatencyUs);
        } catch (RemoteException ex) {
            throw ex.rethrowFromSystemServer();
        }
    }

    /**
     * @see InputManager#disableSensor(int, int)
     */
    void disableSensor(int deviceId, int sensorType) {
        try {
            mIm.disableSensor(deviceId, sensorType);
        } catch (RemoteException ex) {
            throw ex.rethrowFromSystemServer();
        }
    }

    /**
     * @see InputManager#flushSensor(int, int)
     */
    boolean flushSensor(int deviceId, int sensorType) {
        try {
            return mIm.flushSensor(deviceId, sensorType);
        } catch (RemoteException ex) {
            throw ex.rethrowFromSystemServer();
        }
    }

    /**
     * @see InputManager#registerSensorListener(IInputSensorEventListener)
     */
    boolean registerSensorListener(IInputSensorEventListener listener) {
        try {
            return mIm.registerSensorListener(listener);
        } catch (RemoteException ex) {
            throw ex.rethrowFromSystemServer();
        }
    }

    /**
     * @see InputManager#unregisterSensorListener(IInputSensorEventListener)
     */
    void unregisterSensorListener(IInputSensorEventListener listener) {
        try {
            mIm.unregisterSensorListener(listener);
        } catch (RemoteException ex) {
            throw ex.rethrowFromSystemServer();
        }
    }
}