Add isUidActiveOrForeground() for camera/audio to use.

When start/resume activity, WindowManagerService start/resume the
activity, then post a runnable to DiaplayThread and
ActivityManagerService to update UidRecord's
proc state, because the thread switch, the latency before proc
state update is undetermined.

When CameraService calls ActivityManagerService.isUidActive(), the proc
state may not have been updated and camera access is denied.

isUidActiveOrForeground() will check isUidActive() first, if false,
check isUidForeground() which is actually to check with WindowManagerService if
the uid is foreground, which is equivalent to ActivityManagerService's uid
active, just updated earlier.

Bug: 151185692, 151777097, 109950150
Test: manual test.
Change-Id: I3685e0c8d2e69ca7ff3c4de4bef4ec754c400015
gugelfrei
Hui Yu 4 years ago
parent 1939a00071
commit ffffffc422

@ -945,7 +945,7 @@ bool AudioPolicyService::UidPolicy::isUidActive(uid_t uid) {
}
}
ActivityManager am;
bool active = am.isUidActive(uid, String16("audioserver"));
bool active = am.isUidActiveOrForeground(uid, String16("audioserver"));
{
Mutex::Autolock _l(mLock);
mCachedUids.insert(std::pair<uid_t,
@ -990,7 +990,7 @@ int AudioPolicyService::UidPolicy::getUidState(uid_t uid) {
}
}
ActivityManager am;
bool active = am.isUidActive(uid, String16("audioserver"));
bool active = am.isUidActiveOrForeground(uid, String16("audioserver"));
int state = ActivityManager::PROCESS_STATE_UNKNOWN;
if (active) {
state = am.getUidProcessState(uid, String16("audioserver"));

@ -3188,7 +3188,9 @@ bool CameraService::UidPolicy::isUidActiveLocked(uid_t uid, String16 callingPack
// some polling which should happen pretty rarely anyway as the race is hard
// to hit.
active = mActiveUids.find(uid) != mActiveUids.end();
if (!active) active = am.isUidActive(uid, callingPackage);
if (!active) {
active = am.isUidActiveOrForeground(uid, callingPackage);
}
if (active) {
break;
}

Loading…
Cancel
Save