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

Commit b1e153bc authored by Amith Yamasani's avatar Amith Yamasani
Browse files

Reduce locking duration when checking idle states

Synchronize only the methods that need to be, so that
the lock is not held for a few hundred milliseconds, blocking
other usagestats operations.

Bug: 27208519
Change-Id: I43bda0791dd8b2576a8af506bcdc67a09a5830f2
parent 0137c3da
Loading
Loading
Loading
Loading
+11 −11
Original line number Original line Diff line number Diff line
@@ -431,7 +431,6 @@ public class UsageStatsService extends SystemService implements
            List<PackageInfo> packages = mPackageManager.getInstalledPackagesAsUser(
            List<PackageInfo> packages = mPackageManager.getInstalledPackagesAsUser(
                    PackageManager.MATCH_DISABLED_COMPONENTS,
                    PackageManager.MATCH_DISABLED_COMPONENTS,
                    userId);
                    userId);
            synchronized (mLock) {
            final int packageCount = packages.size();
            final int packageCount = packages.size();
            for (int p = 0; p < packageCount; p++) {
            for (int p = 0; p < packageCount; p++) {
                final PackageInfo pi = packages.get(p);
                final PackageInfo pi = packages.get(p);
@@ -442,6 +441,7 @@ public class UsageStatsService extends SystemService implements
                mHandler.sendMessage(mHandler.obtainMessage(MSG_INFORM_LISTENERS,
                mHandler.sendMessage(mHandler.obtainMessage(MSG_INFORM_LISTENERS,
                        userId, isIdle ? 1 : 0, packageName));
                        userId, isIdle ? 1 : 0, packageName));
                if (isIdle) {
                if (isIdle) {
                    synchronized (mLock) {
                        mAppIdleHistory.setIdle(packageName, userId, elapsedRealtime);
                        mAppIdleHistory.setIdle(packageName, userId, elapsedRealtime);
                    }
                    }
                }
                }