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
This commit is contained in:
@@ -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.
|
||||
|
||||
Reference in New Issue
Block a user