Loading services/core/java/com/android/server/am/ActiveServices.java +14 −0 Original line number Diff line number Diff line Loading @@ -190,6 +190,7 @@ import java.util.Comparator; import java.util.List; import java.util.Objects; import java.util.Set; import java.util.concurrent.atomic.AtomicReference; import java.util.function.Predicate; public final class ActiveServices { Loading Loading @@ -220,6 +221,11 @@ public final class ActiveServices { | ServiceInfo.FOREGROUND_SERVICE_TYPE_CONNECTED_DEVICE | ServiceInfo.FOREGROUND_SERVICE_TYPE_MEDIA_PROJECTION; // Keep track of number of foreground services and number of apps that have foreground // services in the device. This field is made to be directly accessed without holding AMS lock. static final AtomicReference<Pair<Integer, Integer>> sNumForegroundServices = new AtomicReference(new Pair<>(0, 0)); // Foreground service is stopped for unknown reason. static final int FGS_STOP_REASON_UNKNOWN = 0; // Foreground service is stopped by app calling Service.stopForeground(). Loading Loading @@ -454,6 +460,7 @@ public final class ActiveServices { final ArrayList<ServiceRecord> mStartingBackground = new ArrayList<>(); final ArrayMap<String, ActiveForegroundApp> mActiveForegroundApps = new ArrayMap<>(); boolean mActiveForegroundAppsChanged; static final int MSG_BG_START_TIMEOUT = 1; Loading Loading @@ -2025,6 +2032,7 @@ public final class ActiveServices { logFGSStateChangeLocked(r, FrameworkStatsLog.FOREGROUND_SERVICE_STATE_CHANGED__STATE__ENTER, 0, FGS_STOP_REASON_UNKNOWN); updateNumForegroundServicesLocked(); } // Even if the service is already a FGS, we need to update the notification, // so we need to call it again. Loading Loading @@ -2116,6 +2124,7 @@ public final class ActiveServices { mAm.updateLruProcessLocked(r.app, false, null); updateServiceForegroundLocked(r.app.mServices, true); } updateNumForegroundServicesLocked(); } } } Loading Loading @@ -4784,6 +4793,7 @@ public final class ActiveServices { } smap.ensureNotStartingBackgroundLocked(r); updateNumForegroundServicesLocked(); } private void dropFgsNotificationStateLocked(ServiceRecord r) { Loading Loading @@ -6975,6 +6985,10 @@ public final class ActiveServices { fgsStopReasonToString(fgsStopReason)); } private void updateNumForegroundServicesLocked() { sNumForegroundServices.set(mAm.mProcessList.getNumForegroundServices()); } boolean canAllowWhileInUsePermissionInFgsLocked(int callingPid, int callingUid, String callingPackage) { return shouldAllowFgsWhileInUsePermissionLocked(callingPackage, callingPid, callingUid, Loading services/core/java/com/android/server/am/ProcessList.java +7 −5 Original line number Diff line number Diff line Loading @@ -814,12 +814,14 @@ public final class ProcessList { < LmkdStatsReporter.KILL_OCCURRED_MSG_SIZE) { return false; } Pair<Integer, Integer> temp = getNumForegroundServices(); final int totalForegroundServices = temp.first; final int procsWithForegroundServices = temp.second; // Note: directly access // ActiveServices.sNumForegroundServices, do not try to // hold AMS lock here, otherwise it is a potential deadlock. Pair<Integer, Integer> foregroundServices = ActiveServices.sNumForegroundServices.get(); LmkdStatsReporter.logKillOccurred(inputData, totalForegroundServices, procsWithForegroundServices); foregroundServices.first, foregroundServices.second); return true; case LMK_STATE_CHANGED: if (receivedLen Loading Loading
services/core/java/com/android/server/am/ActiveServices.java +14 −0 Original line number Diff line number Diff line Loading @@ -190,6 +190,7 @@ import java.util.Comparator; import java.util.List; import java.util.Objects; import java.util.Set; import java.util.concurrent.atomic.AtomicReference; import java.util.function.Predicate; public final class ActiveServices { Loading Loading @@ -220,6 +221,11 @@ public final class ActiveServices { | ServiceInfo.FOREGROUND_SERVICE_TYPE_CONNECTED_DEVICE | ServiceInfo.FOREGROUND_SERVICE_TYPE_MEDIA_PROJECTION; // Keep track of number of foreground services and number of apps that have foreground // services in the device. This field is made to be directly accessed without holding AMS lock. static final AtomicReference<Pair<Integer, Integer>> sNumForegroundServices = new AtomicReference(new Pair<>(0, 0)); // Foreground service is stopped for unknown reason. static final int FGS_STOP_REASON_UNKNOWN = 0; // Foreground service is stopped by app calling Service.stopForeground(). Loading Loading @@ -454,6 +460,7 @@ public final class ActiveServices { final ArrayList<ServiceRecord> mStartingBackground = new ArrayList<>(); final ArrayMap<String, ActiveForegroundApp> mActiveForegroundApps = new ArrayMap<>(); boolean mActiveForegroundAppsChanged; static final int MSG_BG_START_TIMEOUT = 1; Loading Loading @@ -2025,6 +2032,7 @@ public final class ActiveServices { logFGSStateChangeLocked(r, FrameworkStatsLog.FOREGROUND_SERVICE_STATE_CHANGED__STATE__ENTER, 0, FGS_STOP_REASON_UNKNOWN); updateNumForegroundServicesLocked(); } // Even if the service is already a FGS, we need to update the notification, // so we need to call it again. Loading Loading @@ -2116,6 +2124,7 @@ public final class ActiveServices { mAm.updateLruProcessLocked(r.app, false, null); updateServiceForegroundLocked(r.app.mServices, true); } updateNumForegroundServicesLocked(); } } } Loading Loading @@ -4784,6 +4793,7 @@ public final class ActiveServices { } smap.ensureNotStartingBackgroundLocked(r); updateNumForegroundServicesLocked(); } private void dropFgsNotificationStateLocked(ServiceRecord r) { Loading Loading @@ -6975,6 +6985,10 @@ public final class ActiveServices { fgsStopReasonToString(fgsStopReason)); } private void updateNumForegroundServicesLocked() { sNumForegroundServices.set(mAm.mProcessList.getNumForegroundServices()); } boolean canAllowWhileInUsePermissionInFgsLocked(int callingPid, int callingUid, String callingPackage) { return shouldAllowFgsWhileInUsePermissionLocked(callingPackage, callingPid, callingUid, Loading
services/core/java/com/android/server/am/ProcessList.java +7 −5 Original line number Diff line number Diff line Loading @@ -814,12 +814,14 @@ public final class ProcessList { < LmkdStatsReporter.KILL_OCCURRED_MSG_SIZE) { return false; } Pair<Integer, Integer> temp = getNumForegroundServices(); final int totalForegroundServices = temp.first; final int procsWithForegroundServices = temp.second; // Note: directly access // ActiveServices.sNumForegroundServices, do not try to // hold AMS lock here, otherwise it is a potential deadlock. Pair<Integer, Integer> foregroundServices = ActiveServices.sNumForegroundServices.get(); LmkdStatsReporter.logKillOccurred(inputData, totalForegroundServices, procsWithForegroundServices); foregroundServices.first, foregroundServices.second); return true; case LMK_STATE_CHANGED: if (receivedLen Loading