Loading libs/sensor/SensorManager.cpp +36 −34 Original line number Diff line number Diff line Loading @@ -88,11 +88,16 @@ SensorManager& SensorManager::getInstanceForPackage(const String16& packageName) SensorManager* sensorManager; auto iterator = sPackageInstances.find(packageName); const uid_t uid = IPCThreadState::self()->getCallingUid(); const int deviceId = getDeviceIdForUid(uid); // Return the cached instance if the device association of the package has not changed. if (iterator != sPackageInstances.end()) { sensorManager = iterator->second; } else { String16 opPackageName = packageName; const uid_t uid = IPCThreadState::self()->getCallingUid(); if (sensorManager->mDeviceId == deviceId) { return *sensorManager; } } // It is possible that the calling code has no access to the package name. // In this case we will get the packages for the calling UID and pick the Loading @@ -100,6 +105,7 @@ SensorManager& SensorManager::getInstanceForPackage(const String16& packageName) // runtime permissions as for legacy apps we will toggle the app op for // all packages in the UID. The caveat is that the operation may be attributed // to the wrong package and stats based on app ops may be slightly off. String16 opPackageName = packageName; if (opPackageName.size() <= 0) { sp<IBinder> binder = defaultServiceManager()->getService(String16("permission")); if (binder != nullptr) { Loading @@ -115,9 +121,6 @@ SensorManager& SensorManager::getInstanceForPackage(const String16& packageName) } } // Check if the calling UID is observed on a virtual device. If so, provide that device's // sensors by default instead of the default device's sensors. const int deviceId = getDeviceIdForUid(uid); sensorManager = new SensorManager(opPackageName, deviceId); // If we had no package name, we looked it up from the UID and the sensor Loading @@ -129,7 +132,6 @@ SensorManager& SensorManager::getInstanceForPackage(const String16& packageName) // Stash the per package sensor manager. sPackageInstances.insert(std::make_pair(opPackageName, sensorManager)); } return *sensorManager; } Loading Loading
libs/sensor/SensorManager.cpp +36 −34 Original line number Diff line number Diff line Loading @@ -88,11 +88,16 @@ SensorManager& SensorManager::getInstanceForPackage(const String16& packageName) SensorManager* sensorManager; auto iterator = sPackageInstances.find(packageName); const uid_t uid = IPCThreadState::self()->getCallingUid(); const int deviceId = getDeviceIdForUid(uid); // Return the cached instance if the device association of the package has not changed. if (iterator != sPackageInstances.end()) { sensorManager = iterator->second; } else { String16 opPackageName = packageName; const uid_t uid = IPCThreadState::self()->getCallingUid(); if (sensorManager->mDeviceId == deviceId) { return *sensorManager; } } // It is possible that the calling code has no access to the package name. // In this case we will get the packages for the calling UID and pick the Loading @@ -100,6 +105,7 @@ SensorManager& SensorManager::getInstanceForPackage(const String16& packageName) // runtime permissions as for legacy apps we will toggle the app op for // all packages in the UID. The caveat is that the operation may be attributed // to the wrong package and stats based on app ops may be slightly off. String16 opPackageName = packageName; if (opPackageName.size() <= 0) { sp<IBinder> binder = defaultServiceManager()->getService(String16("permission")); if (binder != nullptr) { Loading @@ -115,9 +121,6 @@ SensorManager& SensorManager::getInstanceForPackage(const String16& packageName) } } // Check if the calling UID is observed on a virtual device. If so, provide that device's // sensors by default instead of the default device's sensors. const int deviceId = getDeviceIdForUid(uid); sensorManager = new SensorManager(opPackageName, deviceId); // If we had no package name, we looked it up from the UID and the sensor Loading @@ -129,7 +132,6 @@ SensorManager& SensorManager::getInstanceForPackage(const String16& packageName) // Stash the per package sensor manager. sPackageInstances.insert(std::make_pair(opPackageName, sensorManager)); } return *sensorManager; } Loading