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

Commit 46edabde authored by Varun Shah's avatar Varun Shah
Browse files

Don't hold AMS lock while calling into USS.

Bug: 177610601
Test: atest android.app.usage.UsageStatsTest
Test: atest android.app.usage.cts.UsageStatsTest
Test: atest UsageStatsDatabaseTest
Change-Id: I0c95e48db2ffc44a12c7000ccd15fd5cfa00ff08
parent a6480854
Loading
Loading
Loading
Loading
+15 −24
Original line number Diff line number Diff line
@@ -2533,11 +2533,8 @@ public class ActivityManagerService extends IActivityManager.Stub
            Slog.d(TAG_SWITCH, "updateActivityUsageStats: comp="
                    + activity + " hash=" + appToken.hashCode() + " event=" + event);
        }
        synchronized (this) {
        if (mUsageStatsService != null) {
                mUsageStatsService.reportEvent(activity, userId, event, appToken.hashCode(),
                        taskRoot);
            }
            mUsageStatsService.reportEvent(activity, userId, event, appToken.hashCode(), taskRoot);
        }
        if (mContentCaptureService != null && (event == Event.ACTIVITY_PAUSED
                || event == Event.ACTIVITY_RESUMED || event == Event.ACTIVITY_STOPPED
@@ -2557,12 +2554,10 @@ public class ActivityManagerService extends IActivityManager.Stub
            Slog.d(TAG_SWITCH, "updateActivityUsageStats: package="
                    + packageName + " event=" + event);
        }
        synchronized (this) {
        if (mUsageStatsService != null) {
            mUsageStatsService.reportEvent(packageName, userId, event);
        }
    }
    }
    /**
     * Update Usages on this foreground service's usage.
@@ -2575,14 +2570,12 @@ public class ActivityManagerService extends IActivityManager.Stub
            Slog.d(TAG_SWITCH, "updateForegroundServiceUsageStats: comp="
                    + service + " started=" + started);
        }
        synchronized (this) {
        if (mUsageStatsService != null) {
            mUsageStatsService.reportEvent(service, userId,
                    started ? UsageEvents.Event.FOREGROUND_SERVICE_START
                            : UsageEvents.Event.FOREGROUND_SERVICE_STOP, 0, null);
        }
    }
    }
    CompatibilityInfo compatibilityInfoForPackage(ApplicationInfo ai) {
        return mAtmInternal.compatibilityInfoForPackage(ai);
@@ -6098,7 +6091,7 @@ public class ActivityManagerService extends IActivityManager.Stub
        return pfd;
    }
    void reportGlobalUsageEventLocked(int event) {
    void reportGlobalUsageEvent(int event) {
        final int currentUserId = mUserController.getCurrentUserId();
        mUsageStatsService.reportEvent(Event.DEVICE_EVENT_PACKAGE_NAME, currentUserId, event);
        int[] profiles = mUserController.getCurrentProfileIds();
@@ -6112,8 +6105,8 @@ public class ActivityManagerService extends IActivityManager.Stub
        }
    }
    void reportCurWakefulnessUsageEventLocked() {
        reportGlobalUsageEventLocked(mWakefulness == PowerManagerInternal.WAKEFULNESS_AWAKE
    void reportCurWakefulnessUsageEvent() {
        reportGlobalUsageEvent(mWakefulness == PowerManagerInternal.WAKEFULNESS_AWAKE
                ? UsageEvents.Event.SCREEN_INTERACTIVE
                : UsageEvents.Event.SCREEN_NON_INTERACTIVE);
    }
@@ -6127,7 +6120,7 @@ public class ActivityManagerService extends IActivityManager.Stub
            if (wasAwake != isAwake) {
                // Also update state in a special way for running foreground services UI.
                mServices.updateScreenStateLocked(isAwake);
                reportCurWakefulnessUsageEventLocked();
                reportCurWakefulnessUsageEvent();
                mActivityTaskManager.onScreenAwakeChanged(isAwake);
                mOomAdjProfiler.onWakefulnessChanged(wakefulness);
            }
@@ -16506,12 +16499,10 @@ public class ActivityManagerService extends IActivityManager.Stub
        }
        public void reportCurKeyguardUsageEvent(boolean keyguardShowing) {
            synchronized(ActivityManagerService.this) {
                ActivityManagerService.this.reportGlobalUsageEventLocked(keyguardShowing
            ActivityManagerService.this.reportGlobalUsageEvent(keyguardShowing
                    ? UsageEvents.Event.KEYGUARD_SHOWN
                    : UsageEvents.Event.KEYGUARD_HIDDEN);
        }
        }
        @Override
        public void monitor() {
+2 −6
Original line number Diff line number Diff line
@@ -3042,15 +3042,11 @@ class UserController implements Handler.Callback {
        }

        void reportGlobalUsageEventLocked(int event) {
            synchronized (mService) {
                mService.reportGlobalUsageEventLocked(event);
            }
            mService.reportGlobalUsageEvent(event);
        }

        void reportCurWakefulnessUsageEvent() {
            synchronized (mService) {
                mService.reportCurWakefulnessUsageEventLocked();
            }
            mService.reportCurWakefulnessUsageEvent();
        }

        void taskSupervisorRemoveUser(@UserIdInt int userId) {