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

Commit 570de8d5 authored by Michael Wachenschwanz's avatar Michael Wachenschwanz
Browse files

Fix sandboxed process traversal in new OomAdjuster

When traversing the process graph, bindings to sandboxed processes by
system should be ignored and a virtual binding from the attributed
client should be used instead.

Also run assignCachedAdj on the whole lru list for partial updates. The algorithm inside currently relies on being aware of every process. See b/319163103.

Bug: 319696302
Test: atest SdkSandboxLifecycleHostTest:com.android.tests.sdksandbox.host.SdkSandboxLifecycleHostTest
Test: atest MockingOomAdjusterTests
Change-Id: Ie599ea62b9057e66a0b2e9b0b57c51c192abadfb
parent 72e885eb
Loading
Loading
Loading
Loading
+4 −10
Original line number Diff line number Diff line
@@ -722,14 +722,8 @@ public class OomAdjusterModernImpl extends OomAdjuster {
        performNewUpdateOomAdjLSP(oomAdjReason, topApp, targetProcesses, activeUids,
                fullUpdate, now, UNKNOWN_ADJ);

        if (fullUpdate) {
        // TODO: b/319163103 - optimize cache adj assignment to not require the whole lru list.
        assignCachedAdjIfNecessary(mProcessList.getLruProcessesLOSP());
        } else {
            activeProcesses.clear();
            activeProcesses.addAll(targetProcesses);
            assignCachedAdjIfNecessary(activeProcesses);
            activeProcesses.clear();
        }
        postUpdateOomAdjInnerLSP(oomAdjReason, activeUids, now, nowElapsed, oldTime);
        targetProcesses.clear();

@@ -996,11 +990,11 @@ public class OomAdjusterModernImpl extends OomAdjuster {
                            && service.mState.getMaxAdj() < FOREGROUND_APP_ADJ)
                    || (service.mState.getCurAdj() <= FOREGROUND_APP_ADJ
                            && service.mState.getCurrentSchedulingGroup() > SCHED_GROUP_BACKGROUND
                            && service.mState.getCurProcState() <= PROCESS_STATE_TOP)) {
                            && service.mState.getCurProcState() <= PROCESS_STATE_TOP)
                    || (service.isSdkSandbox && cr.binding.attributedClient != null)) {
                continue;
            }


            computeServiceHostOomAdjLSP(cr, service, app, now, topApp, fullUpdate, false, false,
                    oomAdjReason, cachedAdj, false, false);
        }
+5 −21
Original line number Diff line number Diff line
@@ -1673,10 +1673,14 @@ class ProcessRecord implements WindowProcessListener {
                final ArrayList<ConnectionRecord> clist = serviceConnections.valueAt(j);
                for (int k = clist.size() - 1; k >= 0; k--) {
                    final ConnectionRecord cr = clist.get(k);
                    if (isSdkSandbox && cr.binding.attributedClient != null) {
                        consumer.accept(cr.binding.attributedClient);
                    } else {
                        consumer.accept(cr.binding.client);
                    }
                }
            }
        }
        for (int i = mProviders.numberOfProviders() - 1; i >= 0; i--) {
            final ContentProviderRecord cpr = mProviders.getProviderAt(i);
            for (int j = cpr.connections.size() - 1; j >= 0; j--) {
@@ -1684,25 +1688,5 @@ class ProcessRecord implements WindowProcessListener {
                consumer.accept(conn.client);
            }
        }
        // If this process is a sandbox itself, also add the app on whose behalf
        // its running
        if (isSdkSandbox) {
            for (int is = mServices.numberOfRunningServices() - 1; is >= 0; is--) {
                ServiceRecord s = mServices.getRunningServiceAt(is);
                ArrayMap<IBinder, ArrayList<ConnectionRecord>> serviceConnections =
                        s.getConnections();
                for (int conni = serviceConnections.size() - 1; conni >= 0; conni--) {
                    ArrayList<ConnectionRecord> clist = serviceConnections.valueAt(conni);
                    for (int i = clist.size() - 1; i >= 0; i--) {
                        ConnectionRecord cr = clist.get(i);
                        ProcessRecord attributedApp = cr.binding.attributedClient;
                        if (attributedApp == null || attributedApp == this) {
                            continue;
                        }
                        consumer.accept(attributedApp);
                    }
                }
            }
        }
    }
}
+307 −212

File changed.

Preview size limit exceeded, changes collapsed.