Query the uid process state in opChanged instead of relying on callbacks.
Occasionally, Android may enter a state where onUidStateChanged arrives
late or not at all until another process state change occurs. In some
situations that may mean isUidVisible is (incorrectly) false when the
app is in the foreground. Instead of relying on the onUidStateChanged
callback, query the state directly through activity manager.
The flag protecting this is only needed while data_delivery_permission_checks
is not flipped, and can be removed if that advances first.
Test: CameraPermissionTest
Bug: 378016494
Flag: com.android.internal.camera.flags.query_process_state
Change-Id: Ie609c87f27dc0610f5fe9c735e68b4e9366c510f
diff --git a/services/camera/libcameraservice/CameraService.cpp b/services/camera/libcameraservice/CameraService.cpp
index 20b78b7..df94478 100644
--- a/services/camera/libcameraservice/CameraService.cpp
+++ b/services/camera/libcameraservice/CameraService.cpp
@@ -4550,6 +4550,17 @@
return OK;
}
+int32_t CameraService::getUidProcessState(int32_t uid) {
+ const auto& activityManager = getActivityManager();
+ int32_t procState = ActivityManager::PROCESS_STATE_NONEXISTENT;
+ if (activityManager != nullptr) {
+ procState = activityManager->getUidProcessState(uid, toString16(kServiceName));
+ } else {
+ ALOGE("%s: getActivityManager returned nullptr.", __FUNCTION__);
+ }
+ return procState;
+}
+
void CameraService::BasicClient::opChanged(int32_t op, const String16&) {
ATRACE_CALL();
if (mAppOpsManager == nullptr) {
@@ -4606,12 +4617,9 @@
[&](const auto& attr) {
uid = static_cast<uid_t>(attr.uid);
});
- const auto& activityManager = getActivityManager();
- if (activityManager != nullptr) {
- procState = activityManager->getUidProcessState(uid, toString16(kServiceName));
- } else {
- ALOGD("%s: getActivityManager returned nullptr.", __FUNCTION__);
- }
+ procState = getUidProcessState(uid);
+ } else if (flags::query_process_state()) {
+ procState = getUidProcessState(getClientUid());
} else {
procState = sCameraService->mUidPolicy->getProcState(getClientUid());
}