diff options
| author | 2022-12-08 17:21:37 +0100 | |
|---|---|---|
| committer | 2022-12-08 17:21:37 +0100 | |
| commit | 1b3486ad445e4085a64b557a743cfe2d4fd9db3f (patch) | |
| tree | d994bec0267a87e130350d01bfe9d3fe854cc26b | |
| parent | 91824e804fd84a5d1ed0a1093e98058368de856c (diff) | |
Create VDM on demand in SystemSensorManager.
It is not necessary until there's a non-default device association
with the context and this reduces the system memory requirements.
Test: atest VirtualSensorTest
Bug: 260943917
Change-Id: I15ae520a88bfce6e23e7c3400962233dd223fe90
| -rw-r--r-- | core/java/android/hardware/SystemSensorManager.java | 20 |
1 files changed, 14 insertions, 6 deletions
diff --git a/core/java/android/hardware/SystemSensorManager.java b/core/java/android/hardware/SystemSensorManager.java index 18118f5bfe29..161b1b71121e 100644 --- a/core/java/android/hardware/SystemSensorManager.java +++ b/core/java/android/hardware/SystemSensorManager.java @@ -135,7 +135,7 @@ public class SystemSensorManager extends SensorManager { private final boolean mIsPackageDebuggable; private final Context mContext; private final long mNativeInstance; - private final VirtualDeviceManager mVdm; + private VirtualDeviceManager mVdm; private Optional<Boolean> mHasHighSamplingRateSensorsPermission = Optional.empty(); @@ -154,7 +154,6 @@ public class SystemSensorManager extends SensorManager { mContext = context; mNativeInstance = nativeCreate(context.getOpPackageName()); mIsPackageDebuggable = (0 != (appInfo.flags & ApplicationInfo.FLAG_DEBUGGABLE)); - mVdm = mContext.getSystemService(VirtualDeviceManager.class); // initialize the sensor list for (int index = 0;; ++index) { @@ -170,8 +169,7 @@ public class SystemSensorManager extends SensorManager { @Override public List<Sensor> getSensorList(int type) { final int deviceId = mContext.getDeviceId(); - if (deviceId == DEFAULT_DEVICE_ID || mVdm == null - || mVdm.getDevicePolicy(deviceId, POLICY_TYPE_SENSORS) == DEVICE_POLICY_DEFAULT) { + if (isDeviceSensorPolicyDefault(deviceId)) { return super.getSensorList(type); } @@ -207,8 +205,7 @@ public class SystemSensorManager extends SensorManager { @Override protected List<Sensor> getFullSensorList() { final int deviceId = mContext.getDeviceId(); - if (deviceId == DEFAULT_DEVICE_ID || mVdm == null - || mVdm.getDevicePolicy(deviceId, POLICY_TYPE_SENSORS) == DEVICE_POLICY_DEFAULT) { + if (isDeviceSensorPolicyDefault(deviceId)) { return mFullSensorsList; } @@ -1136,6 +1133,17 @@ public class SystemSensorManager extends SensorManager { parameter.type, parameter.floatValues, parameter.intValues) == 0; } + private boolean isDeviceSensorPolicyDefault(int deviceId) { + if (deviceId == DEFAULT_DEVICE_ID) { + return true; + } + if (mVdm == null) { + mVdm = mContext.getSystemService(VirtualDeviceManager.class); + } + return mVdm == null + || mVdm.getDevicePolicy(deviceId, POLICY_TYPE_SENSORS) == DEVICE_POLICY_DEFAULT; + } + /** * Checks if a sensor should be capped according to HIGH_SAMPLING_RATE_SENSORS * permission. |