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

Commit 9b85d5fe authored by Kunal's avatar Kunal Committed by Kunal Malhotra
Browse files

FGS stop log bug fix

Updating location of log to be before type is cleared. Also restricting
logging to cases where we have a UidState.

Adding in log lines for when there is no API type (since the FGS should
have a type)

Bug: 294585409
Test: manual testing on device along with unit testing
Change-Id: I6ca2a2a47dce3e0dad26263ff21aa43e3c00a07b
parent 1f6a24b2
Loading
Loading
Loading
Loading
+3 −3
Original line number Diff line number Diff line
@@ -2501,12 +2501,12 @@ public final class ActiveServices {
                        FGS_STOP_REASON_STOP_FOREGROUND,
                        FGS_TYPE_POLICY_CHECK_UNKNOWN);

                // foregroundServiceType is used in logFGSStateChangeLocked(), so we can't clear it
                // earlier.
                r.foregroundServiceType = 0;
                synchronized (mFGSLogger) {
                    mFGSLogger.logForegroundServiceStop(r.appInfo.uid, r);
                }
                // foregroundServiceType is used in logFGSStateChangeLocked(), so we can't clear it
                // earlier.
                r.foregroundServiceType = 0;
                r.mFgsNotificationWasDeferred = false;
                signalForegroundServiceObserversLocked(r);
                resetFgsRestrictionLocked(r);
+22 −13
Original line number Diff line number Diff line
@@ -141,6 +141,10 @@ public class ForegroundServiceTypeLoggerModule {
        // grab the appropriate types
        final IntArray apiTypes =
                convertFgsTypeToApiTypes(record.foregroundServiceType);
        if (apiTypes.size() == 0) {
            Slog.w(TAG, "Foreground service start for UID: "
                    + uid + " does not have any types");
        }
        // now we need to iterate through the types
        // and insert the new record as needed
        final IntArray apiTypesFound = new IntArray();
@@ -201,6 +205,9 @@ public class ForegroundServiceTypeLoggerModule {
        // and also clean up the start calls stack by UID
        final IntArray apiTypes = convertFgsTypeToApiTypes(record.foregroundServiceType);
        final UidState uidState = mUids.get(uid);
        if (apiTypes.size() == 0) {
            Slog.w(TAG, "FGS stop call for: " + uid + " has no types!");
        }
        if (uidState == null) {
            Slog.w(TAG, "FGS stop call being logged with no start call for UID for UID "
                    + uid
@@ -460,17 +467,18 @@ public class ForegroundServiceTypeLoggerModule {
    public void logFgsApiEvent(ServiceRecord r, int fgsState,
            @FgsApiState int apiState,
            @ForegroundServiceApiType int apiType, long timestamp) {
        long apiDurationBeforeFgsStart = r.createRealTime - timestamp;
        long apiDurationAfterFgsEnd = timestamp - r.mFgsExitTime;
        long apiDurationBeforeFgsStart = 0;
        long apiDurationAfterFgsEnd = 0;
        UidState uidState = mUids.get(r.appInfo.uid);
        if (uidState != null) {
        if (uidState == null) {
            return;
        }
        if (uidState.mFirstFgsTimeStamp.contains(apiType)) {
            apiDurationBeforeFgsStart = uidState.mFirstFgsTimeStamp.get(apiType) - timestamp;
        }
        if (uidState.mLastFgsTimeStamp.contains(apiType)) {
            apiDurationAfterFgsEnd = timestamp - uidState.mLastFgsTimeStamp.get(apiType);
        }
        }
        final int[] apiTypes = new int[1];
        apiTypes[0] = apiType;
        final long[] timeStamps = new long[1];
@@ -525,11 +533,12 @@ public class ForegroundServiceTypeLoggerModule {
            @ForegroundServiceApiType int apiType, long timestamp) {
        long apiDurationAfterFgsEnd = 0;
        UidState uidState = mUids.get(uid);
        if (uidState != null) {
        if (uidState == null) {
            return;
        }
        if (uidState.mLastFgsTimeStamp.contains(apiType)) {
            apiDurationAfterFgsEnd = timestamp - uidState.mLastFgsTimeStamp.get(apiType);
        }
        }
        final int[] apiTypes = new int[1];
        apiTypes[0] = apiType;
        final long[] timeStamps = new long[1];