Loading services/core/java/com/android/server/am/ActivityManagerService.java +44 −1 Original line number Original line Diff line number Diff line Loading @@ -291,6 +291,7 @@ import android.util.ArrayMap; import android.util.ArraySet; import android.util.ArraySet; import android.util.DebugUtils; import android.util.DebugUtils; import android.util.EventLog; import android.util.EventLog; import android.util.IntArray; import android.util.Log; import android.util.Log; import android.util.Pair; import android.util.Pair; import android.util.PrintWriterPrinter; import android.util.PrintWriterPrinter; Loading @@ -310,6 +311,7 @@ import android.view.autofill.AutofillManagerInternal; import com.android.internal.annotations.GuardedBy; import com.android.internal.annotations.GuardedBy; import com.android.internal.annotations.VisibleForTesting; import com.android.internal.annotations.VisibleForTesting; import com.android.internal.app.IAppOpsActiveCallback; import com.android.internal.app.IAppOpsCallback; import com.android.internal.app.IAppOpsCallback; import com.android.internal.app.IAppOpsService; import com.android.internal.app.IAppOpsService; import com.android.internal.app.ProcessMap; import com.android.internal.app.ProcessMap; Loading Loading @@ -656,6 +658,14 @@ public class ActivityManagerService extends IActivityManager.Stub /** Total # of UID change events dispatched, shown in dumpsys. */ /** Total # of UID change events dispatched, shown in dumpsys. */ int mUidChangeDispatchCount; int mUidChangeDispatchCount; /** * Uids of apps with current active camera sessions. Access synchronized on * the IntArray instance itself, and no other locks must be acquired while that * one is held. */ @GuardedBy("mActiveCameraUids") final IntArray mActiveCameraUids = new IntArray(4); /** /** * Helper class which strips out priority and proto arguments then calls the dump function with * Helper class which strips out priority and proto arguments then calls the dump function with * the appropriate arguments. If priority arguments are omitted, function calls the legacy * the appropriate arguments. If priority arguments are omitted, function calls the legacy Loading Loading @@ -2053,7 +2063,10 @@ public class ActivityManagerService extends IActivityManager.Stub } } if (proc != null) { if (proc != null) { long startTime = SystemClock.currentThreadTimeMillis(); long startTime = SystemClock.currentThreadTimeMillis(); long pss = Debug.getPss(pid, tmp, null); // skip background PSS calculation of apps that are capturing // camera imagery final boolean usingCamera = isCameraActiveForUid(proc.uid); long pss = usingCamera ? 0 : Debug.getPss(pid, tmp, null); long endTime = SystemClock.currentThreadTimeMillis(); long endTime = SystemClock.currentThreadTimeMillis(); synchronized (ActivityManagerService.this) { synchronized (ActivityManagerService.this) { if (pss != 0 && proc.thread != null && proc.setProcState == procState if (pss != 0 && proc.thread != null && proc.setProcState == procState Loading @@ -2066,6 +2079,7 @@ public class ActivityManagerService extends IActivityManager.Stub ProcessList.abortNextPssTime(proc.procStateMemTracker); ProcessList.abortNextPssTime(proc.procStateMemTracker); if (DEBUG_PSS) Slog.d(TAG_PSS, "Skipped pss collection of " + pid + if (DEBUG_PSS) Slog.d(TAG_PSS, "Skipped pss collection of " + pid + ": " + (proc.thread == null ? "NO_THREAD " : "") + ": " + (proc.thread == null ? "NO_THREAD " : "") + (usingCamera ? "CAMERA " : "") + (proc.pid != pid ? "PID_CHANGED " : "") + (proc.pid != pid ? "PID_CHANGED " : "") + " initState=" + procState + " curState=" + " initState=" + procState + " curState=" + proc.setProcState + " " + proc.setProcState + " " + Loading Loading @@ -2155,6 +2169,14 @@ public class ActivityManagerService extends IActivityManager.Stub } } } } }); }); final int[] cameraOp = {AppOpsManager.OP_CAMERA}; mAppOpsService.startWatchingActive(cameraOp, new IAppOpsActiveCallback.Stub() { @Override public void opActiveChanged(int op, int uid, String packageName, boolean active) { cameraActiveChanged(uid, active); } }); } } public void setWindowManager(WindowManagerService wm) { public void setWindowManager(WindowManagerService wm) { Loading Loading @@ -18266,6 +18288,27 @@ public class ActivityManagerService extends IActivityManager.Stub } } } } final void cameraActiveChanged(@UserIdInt int uid, boolean active) { synchronized (mActiveCameraUids) { final int curIndex = mActiveCameraUids.indexOf(uid); if (active) { if (curIndex < 0) { mActiveCameraUids.add(uid); } } else { if (curIndex >= 0) { mActiveCameraUids.remove(curIndex); } } } } final boolean isCameraActiveForUid(@UserIdInt int uid) { synchronized (mActiveCameraUids) { return mActiveCameraUids.indexOf(uid) >= 0; } } @GuardedBy("this") @GuardedBy("this") final void doStopUidLocked(int uid, final UidRecord uidRec) { final void doStopUidLocked(int uid, final UidRecord uidRec) { mServices.stopInBackgroundLocked(uid); mServices.stopInBackgroundLocked(uid); Loading
services/core/java/com/android/server/am/ActivityManagerService.java +44 −1 Original line number Original line Diff line number Diff line Loading @@ -291,6 +291,7 @@ import android.util.ArrayMap; import android.util.ArraySet; import android.util.ArraySet; import android.util.DebugUtils; import android.util.DebugUtils; import android.util.EventLog; import android.util.EventLog; import android.util.IntArray; import android.util.Log; import android.util.Log; import android.util.Pair; import android.util.Pair; import android.util.PrintWriterPrinter; import android.util.PrintWriterPrinter; Loading @@ -310,6 +311,7 @@ import android.view.autofill.AutofillManagerInternal; import com.android.internal.annotations.GuardedBy; import com.android.internal.annotations.GuardedBy; import com.android.internal.annotations.VisibleForTesting; import com.android.internal.annotations.VisibleForTesting; import com.android.internal.app.IAppOpsActiveCallback; import com.android.internal.app.IAppOpsCallback; import com.android.internal.app.IAppOpsCallback; import com.android.internal.app.IAppOpsService; import com.android.internal.app.IAppOpsService; import com.android.internal.app.ProcessMap; import com.android.internal.app.ProcessMap; Loading Loading @@ -656,6 +658,14 @@ public class ActivityManagerService extends IActivityManager.Stub /** Total # of UID change events dispatched, shown in dumpsys. */ /** Total # of UID change events dispatched, shown in dumpsys. */ int mUidChangeDispatchCount; int mUidChangeDispatchCount; /** * Uids of apps with current active camera sessions. Access synchronized on * the IntArray instance itself, and no other locks must be acquired while that * one is held. */ @GuardedBy("mActiveCameraUids") final IntArray mActiveCameraUids = new IntArray(4); /** /** * Helper class which strips out priority and proto arguments then calls the dump function with * Helper class which strips out priority and proto arguments then calls the dump function with * the appropriate arguments. If priority arguments are omitted, function calls the legacy * the appropriate arguments. If priority arguments are omitted, function calls the legacy Loading Loading @@ -2053,7 +2063,10 @@ public class ActivityManagerService extends IActivityManager.Stub } } if (proc != null) { if (proc != null) { long startTime = SystemClock.currentThreadTimeMillis(); long startTime = SystemClock.currentThreadTimeMillis(); long pss = Debug.getPss(pid, tmp, null); // skip background PSS calculation of apps that are capturing // camera imagery final boolean usingCamera = isCameraActiveForUid(proc.uid); long pss = usingCamera ? 0 : Debug.getPss(pid, tmp, null); long endTime = SystemClock.currentThreadTimeMillis(); long endTime = SystemClock.currentThreadTimeMillis(); synchronized (ActivityManagerService.this) { synchronized (ActivityManagerService.this) { if (pss != 0 && proc.thread != null && proc.setProcState == procState if (pss != 0 && proc.thread != null && proc.setProcState == procState Loading @@ -2066,6 +2079,7 @@ public class ActivityManagerService extends IActivityManager.Stub ProcessList.abortNextPssTime(proc.procStateMemTracker); ProcessList.abortNextPssTime(proc.procStateMemTracker); if (DEBUG_PSS) Slog.d(TAG_PSS, "Skipped pss collection of " + pid + if (DEBUG_PSS) Slog.d(TAG_PSS, "Skipped pss collection of " + pid + ": " + (proc.thread == null ? "NO_THREAD " : "") + ": " + (proc.thread == null ? "NO_THREAD " : "") + (usingCamera ? "CAMERA " : "") + (proc.pid != pid ? "PID_CHANGED " : "") + (proc.pid != pid ? "PID_CHANGED " : "") + " initState=" + procState + " curState=" + " initState=" + procState + " curState=" + proc.setProcState + " " + proc.setProcState + " " + Loading Loading @@ -2155,6 +2169,14 @@ public class ActivityManagerService extends IActivityManager.Stub } } } } }); }); final int[] cameraOp = {AppOpsManager.OP_CAMERA}; mAppOpsService.startWatchingActive(cameraOp, new IAppOpsActiveCallback.Stub() { @Override public void opActiveChanged(int op, int uid, String packageName, boolean active) { cameraActiveChanged(uid, active); } }); } } public void setWindowManager(WindowManagerService wm) { public void setWindowManager(WindowManagerService wm) { Loading Loading @@ -18266,6 +18288,27 @@ public class ActivityManagerService extends IActivityManager.Stub } } } } final void cameraActiveChanged(@UserIdInt int uid, boolean active) { synchronized (mActiveCameraUids) { final int curIndex = mActiveCameraUids.indexOf(uid); if (active) { if (curIndex < 0) { mActiveCameraUids.add(uid); } } else { if (curIndex >= 0) { mActiveCameraUids.remove(curIndex); } } } } final boolean isCameraActiveForUid(@UserIdInt int uid) { synchronized (mActiveCameraUids) { return mActiveCameraUids.indexOf(uid) >= 0; } } @GuardedBy("this") @GuardedBy("this") final void doStopUidLocked(int uid, final UidRecord uidRec) { final void doStopUidLocked(int uid, final UidRecord uidRec) { mServices.stopInBackgroundLocked(uid); mServices.stopInBackgroundLocked(uid);