Handle backgrounded apps for direct sensor connections
Uses the stopAll()/recoverAll() logic to temporarily stop/enable
sensors for direct connections when an app becomes idle/active.
Bug: 74395023
Test: CTS SensorDirectReportTest and verify pass
Test: 1) Subscribe to sensor on sensorlogger
2) Put app to background and wait
3) Verify subscription is disabled once app is idle
4) Put app to foreground and verify app can receive sensor samples
Test: Verify above test while a_sns_test streaming samples
Test: Verify above test with sensor service restrict and privacy mode
Change-Id: Id1981213fc13a9012fa756b8cd35fae6f144c105
diff --git a/services/sensorservice/SensorService.h b/services/sensorservice/SensorService.h
index abd881c..3bb8421 100644
--- a/services/sensorservice/SensorService.h
+++ b/services/sensorservice/SensorService.h
@@ -339,7 +339,11 @@
// allowed to register for or call flush on sensors. Typically only cts test packages are
// allowed.
bool isWhiteListedPackage(const String8& packageName);
- bool isOperationPermitted(const String16& opPackageName);
+
+ // Returns true if a connection with the specified opPackageName has no access to sensors
+ // in the RESTRICTED mode (i.e. the service is in RESTRICTED mode, and the package is not
+ // whitelisted). mLock must be held to invoke this method.
+ bool isOperationRestrictedLocked(const String16& opPackageName);
// Reset the state of SensorService to NORMAL mode.
status_t resetToNormalMode();
@@ -358,6 +362,12 @@
// Sets whether the given UID can get sensor data
void onUidStateChanged(uid_t uid, UidState state);
+ // Returns true if a connection with the given uid and opPackageName
+ // currently has access to sensors.
+ bool hasSensorAccess(uid_t uid, const String16& opPackageName);
+ // Same as hasSensorAccess but with mLock held.
+ bool hasSensorAccessLocked(uid_t uid, const String16& opPackageName);
+
// Overrides the UID state as if it is idle
status_t handleSetUidState(Vector<String16>& args, int err);
// Clears the override for the UID state