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

Commit 6e8db7fa authored by Kunal Malhotra's avatar Kunal Malhotra Committed by Automerger Merge Worker
Browse files

Merge "Bug fix for properly clearing the last open call pointer" into...

Merge "Bug fix for properly clearing the last open call pointer" into udc-qpr-dev am: 8433b368 am: a5348266

Original change: https://googleplex-android-review.googlesource.com/c/platform/frameworks/base/+/24816581



Change-Id: I7395ecc3dd3417735f9080b0e94a0983a2b49ddb
Signed-off-by: default avatarAutomerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
parents 15f8a750 a5348266
Loading
Loading
Loading
Loading
+25 −18
Original line number Diff line number Diff line
@@ -220,6 +220,24 @@ public class ForegroundServiceTypeLoggerModule {
        final ArrayList<Long> timestampsFound = new ArrayList<>();
        for (int i = 0, size = apiTypes.size(); i < size; i++) {
            final int apiType = apiTypes.get(i);

            // remove the FGS record from the stack
            final ArrayMap<ComponentName, ServiceRecord> runningFgsOfType =
                    uidState.mRunningFgs.get(apiType);
            if (runningFgsOfType == null) {
                Slog.w(TAG, "Could not find appropriate running FGS for FGS stop for UID " + uid
                        + " in package " + record.packageName);
                continue;
            }

            runningFgsOfType.remove(record.getComponentName());
            if (runningFgsOfType.size() == 0) {
                // there's no more FGS running for this type, just get rid of it
                uidState.mRunningFgs.remove(apiType);
                // but we need to keep track of the timestamp in case an API stops
                uidState.mLastFgsTimeStamp.put(apiType, System.currentTimeMillis());
            }

            final int apiTypeIndex = uidState.mOpenWithFgsCount.indexOfKey(apiType);
            if (apiTypeIndex < 0) {
                Slog.w(TAG, "Logger should be tracking FGS types correctly for UID " + uid
@@ -238,22 +256,6 @@ public class ForegroundServiceTypeLoggerModule {
                // remove the last API close call
                uidState.mApiClosedCalls.remove(apiType);
            }
            // remove the FGS record from the stack
            final ArrayMap<ComponentName, ServiceRecord> runningFgsOfType =
                    uidState.mRunningFgs.get(apiType);
            if (runningFgsOfType == null) {
                Slog.w(TAG, "Could not find appropriate running FGS for FGS stop for UID " + uid
                        + " in package " + record.packageName);
                continue;
            }

            runningFgsOfType.remove(record.getComponentName());
            if (runningFgsOfType.size() == 0) {
                // there's no more FGS running for this type, just get rid of it
                uidState.mRunningFgs.remove(apiType);
                // but we need to keep track of the timestamp in case an API stops
                uidState.mLastFgsTimeStamp.put(apiType, System.currentTimeMillis());
            }
        }
        if (!apisFound.isEmpty()) {
            // time to log the call
@@ -383,9 +385,14 @@ public class ForegroundServiceTypeLoggerModule {
            // initialize if we don't contain
            uidState.mOpenedWithoutFgsCount.put(apiType, 0);
        }
        if (uidState.mOpenedWithoutFgsCount.get(apiType) != 0) {
        int apiOpenWithoutFgsCount = uidState.mOpenedWithoutFgsCount.get(apiType);
        if (apiOpenWithoutFgsCount != 0) {
            apiOpenWithoutFgsCount -= 1;
            if (apiOpenWithoutFgsCount == 0) {
                uidState.mApiOpenCalls.remove(apiType);
            }
            uidState.mOpenedWithoutFgsCount
                    .put(apiType, uidState.mOpenedWithoutFgsCount.get(apiType) - 1);
                    .put(apiType, apiOpenWithoutFgsCount);
            return System.currentTimeMillis();
        }
        // This is a part of a valid active FGS
+44 −0
Original line number Diff line number Diff line
@@ -151,6 +151,50 @@ public class FgsLoggerTest {
        resetAndVerifyZeroInteractions();
    }

    @Test
    public void testApiStartStopFgs() throws InterruptedException {
        ServiceRecord record = ServiceRecord.newEmptyInstanceForTest(null);
        record.foregroundServiceType = ServiceInfo.FOREGROUND_SERVICE_TYPE_CAMERA;

        mFgsLogger.logForegroundServiceApiEventBegin(FOREGROUND_SERVICE_API_TYPE_CAMERA,
                1, 1, "aPackageHasNoName");
        Thread.sleep(2000);

        resetAndVerifyZeroInteractions();

        mFgsLogger.logForegroundServiceApiEventEnd(FOREGROUND_SERVICE_API_TYPE_CAMERA, 1, 1);

        resetAndVerifyZeroInteractions();

        mFgsLogger.logForegroundServiceStart(1, 1, record);

        resetAndVerifyZeroInteractions();
    }

    @Test
    public void testFgsStartStopApiStartStop() throws InterruptedException {
        ServiceRecord record = ServiceRecord.newEmptyInstanceForTest(null);
        record.foregroundServiceType = ServiceInfo.FOREGROUND_SERVICE_TYPE_CAMERA;

        mFgsLogger.logForegroundServiceStart(1, 1, record);

        resetAndVerifyZeroInteractions();

        mFgsLogger.logForegroundServiceStop(1, record);

        resetAndVerifyZeroInteractions();

        mFgsLogger.logForegroundServiceApiEventBegin(FOREGROUND_SERVICE_API_TYPE_CAMERA,
                1, 1, "aPackageHasNoName");
        Thread.sleep(2000);

        resetAndVerifyZeroInteractions();

        mFgsLogger.logForegroundServiceApiEventEnd(FOREGROUND_SERVICE_API_TYPE_CAMERA, 1, 1);

        resetAndVerifyZeroInteractions();
    }

    @Test
    public void testMultipleStartStopApis() throws InterruptedException {
        ServiceRecord record = ServiceRecord.newEmptyInstanceForTest(null);