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

Commit a9403c6f authored by Jing Ji's avatar Jing Ji
Browse files

Update the PlatformCompat cache in OomAdjuster when gets notified

...instead of reading from PlatformCompat when it hits an obsoleted
cache at critical code path in oomAdjUpdate.

The cache will also be refreshed when the ApplicationInfo is updated.

Bug: 192316054
Test: atest FrameworksServicesTests:OomAdjusterTests
Test: atest ActivityManagerPerfTests:OomAdjPerfTest
Change-Id: I4d826a84770fa3b83752b11851d261e41acc2c16
parent 3c299e99
Loading
Loading
Loading
Loading
+40 −12
Original line number Diff line number Diff line
@@ -256,7 +256,7 @@ public class OomAdjuster {
    @GuardedBy("mService")
    private boolean mPendingFullOomAdjUpdate = false;

    private final PlatformCompatCache mPlatformCompatCache;
    final PlatformCompatCache mPlatformCompatCache;

    /** Overrideable by a test */
    @VisibleForTesting
@@ -309,6 +309,12 @@ public class OomAdjuster {
            }
        }

        void onApplicationInfoChanged(ApplicationInfo app) {
            for (int i = mCaches.size() - 1; i >= 0; i--) {
                mCaches.valueAt(i).onApplicationInfoChanged(app);
            }
        }

        static class CacheItem implements CompatChange.ChangeListener {
            private final PlatformCompat mPlatformCompat;
            private final long mChangeId;
@@ -328,22 +334,14 @@ public class OomAdjuster {
                    final int index = mCache.indexOfKey(app.packageName);
                    Pair<Boolean, WeakReference<ApplicationInfo>> p;
                    if (index < 0) {
                        p = new Pair<>(mPlatformCompat.isChangeEnabledInternalNoLogging(mChangeId,
                                                                                        app),
                                new WeakReference<>(app));
                        mCache.put(app.packageName, p);
                        return p.first;
                        return fetchLocked(app, index);
                    }
                    p = mCache.valueAt(index);
                    if (p.second.get() == app) {
                        return p.first;
                    }
                    // Cache is invalid, regenerate it
                    p = new Pair<>(mPlatformCompat.isChangeEnabledInternalNoLogging(mChangeId,
                                                                                    app),
                            new WeakReference<>(app));
                    mCache.setValueAt(index, p);
                    return p.first;
                    return fetchLocked(app, index);
                }
            }

@@ -353,10 +351,40 @@ public class OomAdjuster {
                }
            }

            @GuardedBy("mLock")
            boolean fetchLocked(ApplicationInfo app, int index) {
                final Pair<Boolean, WeakReference<ApplicationInfo>> p = new Pair<>(
                        mPlatformCompat.isChangeEnabledInternalNoLogging(mChangeId, app),
                        new WeakReference<>(app));
                if (index >= 0) {
                    mCache.setValueAt(index, p);
                } else {
                    mCache.put(app.packageName, p);
                }
                return p.first;
            }

            void onApplicationInfoChanged(ApplicationInfo app) {
                synchronized (mLock) {
                    final int index = mCache.indexOfKey(app.packageName);
                    if (index >= 0) {
                        fetchLocked(app, index);
                    }
                }
            }

            @Override
            public void onCompatChange(String packageName) {
                synchronized (mLock) {
                    mCache.remove(packageName);
                    final int index = mCache.indexOfKey(packageName);
                    if (index >= 0) {
                        final ApplicationInfo app = mCache.valueAt(index).second.get();
                        if (app != null) {
                            fetchLocked(app, index);
                        } else {
                            mCache.removeAt(index);
                        }
                    }
                }
            }
        }
+2 −0
Original line number Diff line number Diff line
@@ -4710,6 +4710,8 @@ public final class ProcessList {
                        if (ai != null) {
                            if (ai.packageName.equals(app.info.packageName)) {
                                app.info = ai;
                                mService.mOomAdjuster.mPlatformCompatCache
                                        .onApplicationInfoChanged(ai);
                            }
                            app.getThread().scheduleApplicationInfoChanged(ai);
                            targetProcesses.add(app.getWindowProcessController());