Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 9b52815e authored by Hui Yu's avatar Hui Yu
Browse files

Add isUidActiveOrForeground() for camera/audio to use.

Currently CameraService calls isUidActive() before allowing the camera
access.

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() 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: Iffed63293dbdb466e7955fe765ad2aa23a20b3ed
parent 3dc45fbc
Loading
Loading
Loading
Loading
+1 −0
Original line number Original line Diff line number Diff line
@@ -99,6 +99,7 @@ interface IActivityManager {
    void unregisterUidObserver(in IUidObserver observer);
    void unregisterUidObserver(in IUidObserver observer);
    boolean isUidActive(int uid, String callingPackage);
    boolean isUidActive(int uid, String callingPackage);
    int getUidProcessState(int uid, in String callingPackage);
    int getUidProcessState(int uid, in String callingPackage);
    boolean isUidActiveOrForeground(int uid, String callingPackage);
    // =============== End of transactions used on native side as well ============================
    // =============== End of transactions used on native side as well ============================


    // Special low-level communication with activity manager.
    // Special low-level communication with activity manager.
+21 −0
Original line number Original line Diff line number Diff line
@@ -8779,6 +8779,27 @@ public class ActivityManagerService extends IActivityManager.Stub
        return uidRecord != null && !uidRecord.setIdle;
        return uidRecord != null && !uidRecord.setIdle;
    }
    }
    @Override
    public boolean isUidActiveOrForeground(int uid, String callingPackage) {
        if (!hasUsageStatsPermission(callingPackage)) {
            enforceCallingPermission(android.Manifest.permission.PACKAGE_USAGE_STATS,
                    "isUidActiveOrForeground");
        }
        synchronized (this) {
            final boolean isActive = isUidActiveLocked(uid);
            if (isActive) {
                return true;
            }
        }
        final boolean isForeground = mAtmInternal.isUidForeground(uid);
        if (isForeground) {
            Slog.wtf(TAG, "isUidActiveOrForeground: isUidActive false but "
                    + " isUidForeground true, uid:" + uid
                    + " callingPackage:" + callingPackage);
        }
        return isForeground;
    }
    @Override
    @Override
    public void setPersistentVrThread(int tid) {
    public void setPersistentVrThread(int tid) {
        mActivityTaskManager.setPersistentVrThread(tid);
        mActivityTaskManager.setPersistentVrThread(tid);