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

Commit cfebc957 authored by Chih-Yu Huang's avatar Chih-Yu Huang
Browse files

am: Make forEachClientConnectionLSP use internal classes

This change migrates the OomAdjusterImpl.forEachClientConnectionLSP()
method to access psc internal record classes. This is a pure refactor to
align with internal class migration efforts and improve modularity.

Bug: 425766486
Test: m services.core
Test: atest MockingOomAdjusterTests OomAdjusterTests
Test: atest FrameworksServicesTestsRavenwood_ProcessStateController
Flag: EXEMPT pure refactor
Change-Id: I97306978082fab545b667985454486eac5dac695
parent 785cc534
Loading
Loading
Loading
Loading
+10 −0
Original line number Diff line number Diff line
@@ -150,6 +150,16 @@ final class ConnectionRecord extends ConnectionRecordInternal {
        return binding.service;
    }

    @Override
    public ProcessRecord getClient() {
        return binding.client;
    }

    @Override
    public ProcessRecord getAttributedClient() {
        return binding.attributedClient;
    }

    public String getClientProcessName() {
        return clientProcessName;
    }
+5 −0
Original line number Diff line number Diff line
@@ -120,6 +120,11 @@ public final class ContentProviderConnection extends Binder implements
        return provider;
    }

    @Override
    public ProcessRecord getClient() {
        return client;
    }

    public void stopAssociation() {
        if (association == null) {
            return; // early exit to optimize on oomadj cycles
+14 −15
Original line number Diff line number Diff line
@@ -566,7 +566,7 @@ public class OomAdjusterImpl extends OomAdjuster {
     * Connections for clients marked reachable will be ignored.
     */
    private class ComputeConnectionIgnoringReachableClientsConsumer implements
            BiConsumer<Connection, ProcessRecord> {
            BiConsumer<Connection, ProcessRecordInternal> {
        private OomAdjusterArgs mArgs = null;
        public boolean hasReachableClient = false;

@@ -576,7 +576,7 @@ public class OomAdjusterImpl extends OomAdjuster {
        }

        @Override
        public void accept(Connection conn, ProcessRecord client) {
        public void accept(Connection conn, ProcessRecordInternal client) {
            final ProcessRecordInternal host = mArgs.mApp;
            final ProcessRecordInternal topApp = mArgs.mTopApp;
            final long now = mArgs.mNow;
@@ -1085,9 +1085,9 @@ public class OomAdjusterImpl extends OomAdjuster {
     * connectionConsumer}.
     */
    @GuardedBy({"mService", "mProcLock"})
    private static void forEachClientConnectionLSP(ProcessRecord app,
            BiConsumer<Connection, ProcessRecord> connectionConsumer) {
        final ProcessServiceRecordInternal psr = app.mServices;
    private static void forEachClientConnectionLSP(ProcessRecordInternal app,
            BiConsumer<Connection, ProcessRecordInternal> connectionConsumer) {
        final ProcessServiceRecordInternal psr = app.getServices();

        for (int i = psr.numberOfRunningServices() - 1; i >= 0; i--) {
            final ServiceRecordInternal s = psr.getRunningServiceAt(i);
@@ -1095,13 +1095,12 @@ public class OomAdjusterImpl extends OomAdjuster {
                final ArrayList<? extends ConnectionRecordInternal> clist =
                        s.getConnectionAt(j);
                for (int k = clist.size() - 1; k >= 0; k--) {
                    // TODO(b/425766486): Switch to use ConnectionRecordInternal.
                    final ConnectionRecord cr = (ConnectionRecord) clist.get(k);
                    final ProcessRecord client;
                    if (app.isSdkSandbox && cr.binding.attributedClient != null) {
                        client = cr.binding.attributedClient;
                    final ConnectionRecordInternal cr = clist.get(k);
                    final ProcessRecordInternal client;
                    if (app.isSdkSandbox && cr.getAttributedClient() != null) {
                        client = cr.getAttributedClient();
                    } else {
                        client = cr.binding.client;
                        client = cr.getClient();
                    }
                    if (client == null || client == app) continue;
                    connectionConsumer.accept(cr, client);
@@ -1109,12 +1108,12 @@ public class OomAdjusterImpl extends OomAdjuster {
            }
        }

        final ProcessProviderRecord ppr = app.getProviders();
        final ProcessProviderRecordInternal ppr = app.getProviders();
        for (int i = ppr.numberOfProviders() - 1; i >= 0; i--) {
            final ContentProviderRecord cpr = ppr.getProviderAt(i);
            final ContentProviderRecordInternal cpr = ppr.getProviderAt(i);
            for (int j = cpr.numberOfConnections() - 1; j >= 0; j--) {
                final ContentProviderConnection conn = cpr.getConnectionsAt(j);
                connectionConsumer.accept(conn, conn.client);
                final ContentProviderConnectionInternal conn = cpr.getConnectionsAt(j);
                connectionConsumer.accept(conn, conn.getClient());
            }
        }
    }
+9 −0
Original line number Diff line number Diff line
@@ -43,6 +43,15 @@ public abstract class ConnectionRecordInternal implements OomAdjusterImpl.Connec
    /** Returns the service associated with this connection. */
    public abstract ServiceRecordInternal getService();

    /** Returns the client process associated with this connection. */
    public abstract ProcessRecordInternal getClient();

    /**
     * Returns the attributed client process associated with this connection, if applicable (e.g.,
     * for SDK Sandbox).
     */
    public abstract ProcessRecordInternal getAttributedClient();

    /** Tracks the current process state and sequence number for association management. */
    public abstract void trackProcState(int procState, int seq);

+3 −0
Original line number Diff line number Diff line
@@ -30,6 +30,9 @@ public interface ContentProviderConnectionInternal extends OomAdjusterImpl.Conne
    /** Returns the content provider in this connection. */
    ContentProviderRecordInternal getProvider();

    /** Returns the client process that initiated this content provider connection. */
    ProcessRecordInternal getClient();

    @Override
    default void computeHostOomAdjLSP(OomAdjuster oomAdjuster, ProcessRecordInternal host,
            ProcessRecordInternal client, long now, ProcessRecordInternal topApp, boolean doingAll,