summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--services/sensorservice/SensorEventConnection.cpp8
-rw-r--r--services/sensorservice/SensorList.cpp6
-rw-r--r--services/sensorservice/SensorList.h2
-rw-r--r--services/sensorservice/SensorService.cpp17
-rw-r--r--services/sensorservice/SensorService.h1
5 files changed, 25 insertions, 9 deletions
diff --git a/services/sensorservice/SensorEventConnection.cpp b/services/sensorservice/SensorEventConnection.cpp
index 3cccaf9329..6810c1b781 100644
--- a/services/sensorservice/SensorEventConnection.cpp
+++ b/services/sensorservice/SensorEventConnection.cpp
@@ -161,7 +161,7 @@ bool SensorService::SensorEventConnection::addSensor(int32_t handle) {
Mutex::Autolock _l(mConnectionLock);
sp<SensorInterface> si = mService->getSensorInterfaceFromHandle(handle);
if (si == nullptr ||
- !canAccessSensor(si->getSensor(), "Tried adding", mOpPackageName) ||
+ !canAccessSensor(si->getSensor(), "Add to SensorEventConnection: ", mOpPackageName) ||
mSensorInfo.count(handle) > 0) {
return false;
}
@@ -460,8 +460,12 @@ bool SensorService::SensorEventConnection::noteOpIfRequired(const sensors_event_
mTargetSdk > 0 && mTargetSdk <= __ANDROID_API_P__) {
success = true;
} else {
+ int32_t sensorHandle = event.sensor;
+ String16 noteMsg("Sensor event (");
+ noteMsg.append(String16(mService->getSensorStringType(sensorHandle)));
+ noteMsg.append(String16(")"));
int32_t appOpMode = mService->sAppOpsManager.noteOp(iter->second, mUid,
- mOpPackageName);
+ mOpPackageName, {}, noteMsg);
success = (appOpMode == AppOpsManager::MODE_ALLOWED);
}
}
diff --git a/services/sensorservice/SensorList.cpp b/services/sensorservice/SensorList.cpp
index 0ce32cc06f..85ce0f0018 100644
--- a/services/sensorservice/SensorList.cpp
+++ b/services/sensorservice/SensorList.cpp
@@ -57,6 +57,12 @@ String8 SensorList::getName(int handle) const {
mNonSensor.getName());
}
+String8 SensorList::getStringType(int handle) const {
+ return getOne<String8>(
+ handle, [] (const Entry& e) -> String8 {return e.si->getSensor().getStringType();},
+ mNonSensor.getStringType());
+}
+
sp<SensorInterface> SensorList::getInterface(int handle) const {
return getOne<sp<SensorInterface>>(
handle, [] (const Entry& e) -> sp<SensorInterface> {return e.si;}, nullptr);
diff --git a/services/sensorservice/SensorList.h b/services/sensorservice/SensorList.h
index 8424b22ed2..617ceefd0e 100644
--- a/services/sensorservice/SensorList.h
+++ b/services/sensorservice/SensorList.h
@@ -53,6 +53,8 @@ public:
const Vector<Sensor> getVirtualSensors() const;
String8 getName(int handle) const;
+ String8 getStringType(int handle) const;
+
sp<SensorInterface> getInterface(int handle) const;
bool isNewHandle(int handle) const;
diff --git a/services/sensorservice/SensorService.cpp b/services/sensorservice/SensorService.cpp
index 29698390fb..8f25bdba4f 100644
--- a/services/sensorservice/SensorService.cpp
+++ b/services/sensorservice/SensorService.cpp
@@ -1112,6 +1112,10 @@ String8 SensorService::getSensorName(int handle) const {
return mSensors.getName(handle);
}
+String8 SensorService::getSensorStringType(int handle) const {
+ return mSensors.getStringType(handle);
+}
+
bool SensorService::isVirtualSensor(int handle) const {
sp<SensorInterface> sensor = getSensorInterfaceFromHandle(handle);
return sensor != nullptr && sensor->isVirtual();
@@ -1807,9 +1811,6 @@ bool SensorService::canAccessSensor(const Sensor& sensor, const char* operation,
}
const int32_t opCode = sensor.getRequiredAppOp();
- const int32_t appOpMode = sAppOpsManager.checkOp(opCode,
- IPCThreadState::self()->getCallingUid(), opPackageName);
- bool appOpAllowed = appOpMode == AppOpsManager::MODE_ALLOWED;
int targetSdkVersion = getTargetSdkVersion(opPackageName);
bool canAccess = false;
@@ -1822,14 +1823,16 @@ bool SensorService::canAccessSensor(const Sensor& sensor, const char* operation,
canAccess = true;
} else if (hasPermissionForSensor(sensor)) {
// Ensure that the AppOp is allowed, or that there is no necessary app op for the sensor
- if (opCode < 0 || appOpAllowed) {
+ if (opCode >= 0) {
+ const int32_t appOpMode = sAppOpsManager.checkOp(opCode,
+ IPCThreadState::self()->getCallingUid(), opPackageName);
+ canAccess = (appOpMode == AppOpsManager::MODE_ALLOWED);
+ } else {
canAccess = true;
}
}
- if (canAccess) {
- sAppOpsManager.noteOp(opCode, IPCThreadState::self()->getCallingUid(), opPackageName);
- } else {
+ if (!canAccess) {
ALOGE("%s %s a sensor (%s) without holding %s", String8(opPackageName).string(),
operation, sensor.getName().string(), sensor.getRequiredPermission().string());
}
diff --git a/services/sensorservice/SensorService.h b/services/sensorservice/SensorService.h
index 052cbfe290..50c7c2f383 100644
--- a/services/sensorservice/SensorService.h
+++ b/services/sensorservice/SensorService.h
@@ -295,6 +295,7 @@ private:
virtual status_t dump(int fd, const Vector<String16>& args);
status_t dumpProtoLocked(int fd, ConnectionSafeAutolock* connLock) const;
String8 getSensorName(int handle) const;
+ String8 getSensorStringType(int handle) const;
bool isVirtualSensor(int handle) const;
sp<SensorInterface> getSensorInterfaceFromHandle(int handle) const;
bool isWakeUpSensor(int type) const;