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

Commit 42f73024 authored by [D's avatar [D[1;5D
Browse files

Correctly initialize runtime sensors

For SensorManager instances associated with virtual devices with
custom sensor policy, the sensor list and mapping from handle to
sensor is only created after the first call to getSensorList()

This breaks the assumption that the sensors are static per device

Initializing the list in the constructor solves the problem

Fix: 371586534
Test: presubmit and manual with VDM demo apps
Flag: EXEMPT trivial bugfix
Change-Id: Ia4c0e19da78cd3e5e021fc4c70729a24b7347e5e
parent a9492910
Loading
Loading
Loading
Loading
+10 −5
Original line number Diff line number Diff line
@@ -16,6 +16,7 @@

package android.hardware;

import static android.companion.virtual.VirtualDeviceParams.DEVICE_POLICY_CUSTOM;
import static android.companion.virtual.VirtualDeviceParams.DEVICE_POLICY_DEFAULT;
import static android.companion.virtual.VirtualDeviceParams.DEVICE_POLICY_INVALID;
import static android.companion.virtual.VirtualDeviceParams.POLICY_TYPE_SENSORS;
@@ -161,6 +162,9 @@ public class SystemSensorManager extends SensorManager {
        mIsPackageDebuggable = (0 != (appInfo.flags & ApplicationInfo.FLAG_DEBUGGABLE));

        // initialize the sensor list
        if (getSensorPolicy(mContext.getDeviceId()) == DEVICE_POLICY_CUSTOM) {
            createRuntimeSensorListLocked(mContext.getDeviceId());
        } else {
            for (int index = 0; ; ++index) {
                Sensor sensor = new Sensor();
                if (!nativeGetDefaultDeviceSensorAtIndex(mNativeInstance, sensor, index)) break;
@@ -168,6 +172,7 @@ public class SystemSensorManager extends SensorManager {
                mHandleToSensor.put(sensor.getHandle(), sensor);
            }
        }
    }

    /** @hide */
    @Override