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

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

psc: Refactor ServiceRecord host process access

Introduce `ServiceRecordInternal#getHostProcess` and
`ServiceRecordInternal#getIsolationHostProcess` to abstract how the
process hosting a service is accessed. Update `OomAdjuster` and
`OomAdjusterImpl` to use this new method instead of directly
accessing `isolationHostProc` and `app` fields.

Bug: 425766486
Test: m services.core
Test: atest MockingOomAdjusterTests OomAdjusterTests
Test: atest FrameworksServicesTestsRavenwood_ProcessStateController
Flag: EXEMPT pure refactor

Change-Id: I7bccd1ce70b8d92aac5be7c5da1e620127ede7f3
parent e7fdf6b4
Loading
Loading
Loading
Loading
+2 −1
Original line number Original line Diff line number Diff line
@@ -783,7 +783,8 @@ public abstract class OomAdjuster {
            for (int i = psr.numberOfConnections() - 1; i >= 0; i--) {
            for (int i = psr.numberOfConnections() - 1; i >= 0; i--) {
                ConnectionRecord cr = psr.getConnectionAt(i);
                ConnectionRecord cr = psr.getConnectionAt(i);
                ProcessRecord service = cr.hasFlag(ServiceInfo.FLAG_ISOLATED_PROCESS)
                ProcessRecord service = cr.hasFlag(ServiceInfo.FLAG_ISOLATED_PROCESS)
                        ? cr.binding.service.isolationHostProc : cr.binding.service.app;
                        ? cr.binding.service.getIsolationHostProcess()
                        : cr.binding.service.getHostProcess();
                if (service == null || service == pr
                if (service == null || service == pr
                        || ((service.getMaxAdj() >= ProcessList.SYSTEM_ADJ)
                        || ((service.getMaxAdj() >= ProcessList.SYSTEM_ADJ)
                                && (service.getMaxAdj() < FOREGROUND_APP_ADJ))) {
                                && (service.getMaxAdj() < FOREGROUND_APP_ADJ))) {
+3 −2
Original line number Original line Diff line number Diff line
@@ -1013,7 +1013,8 @@ public class OomAdjusterImpl extends OomAdjuster {
        for (int i = psr.numberOfConnections() - 1; i >= 0; i--) {
        for (int i = psr.numberOfConnections() - 1; i >= 0; i--) {
            ConnectionRecord cr = psr.getConnectionAt(i);
            ConnectionRecord cr = psr.getConnectionAt(i);
            ProcessRecord service = cr.hasFlag(ServiceInfo.FLAG_ISOLATED_PROCESS)
            ProcessRecord service = cr.hasFlag(ServiceInfo.FLAG_ISOLATED_PROCESS)
                    ? cr.binding.service.isolationHostProc : cr.binding.service.app;
                    ? cr.binding.service.getIsolationHostProcess()
                    : cr.binding.service.getHostProcess();
            if (service == null || service == app || isSandboxAttributedConnection(cr, service)) {
            if (service == null || service == app || isSandboxAttributedConnection(cr, service)) {
                continue;
                continue;
            }
            }
@@ -1027,7 +1028,7 @@ public class OomAdjusterImpl extends OomAdjuster {


        for (int i = psr.numberOfSdkSandboxConnections() - 1; i >= 0; i--) {
        for (int i = psr.numberOfSdkSandboxConnections() - 1; i >= 0; i--) {
            final ConnectionRecord cr = psr.getSdkSandboxConnectionAt(i);
            final ConnectionRecord cr = psr.getSdkSandboxConnectionAt(i);
            final ProcessRecord service = cr.binding.service.app;
            final ProcessRecord service = cr.binding.service.getHostProcess();
            if (service == null || service == app) {
            if (service == null || service == app) {
                continue;
                continue;
            }
            }
+10 −0
Original line number Original line Diff line number Diff line
@@ -1776,6 +1776,16 @@ final class ServiceRecord extends ServiceRecordInternal implements ComponentName
        deliveredStarts.clear();
        deliveredStarts.clear();
    }
    }


    @Override
    public ProcessRecord getHostProcess() {
        return app;
    }

    @Override
    public ProcessRecord getIsolationHostProcess() {
        return isolationHostProc;
    }

    public String toString() {
    public String toString() {
        if (stringName != null) {
        if (stringName != null) {
            return stringName;
            return stringName;
+6 −0
Original line number Original line Diff line number Diff line
@@ -100,4 +100,10 @@ public abstract class ServiceRecordInternal extends Binder {


    /** Returns the list of connections for a given index. */
    /** Returns the list of connections for a given index. */
    public abstract ArrayList<? extends ConnectionRecordInternal> getConnectionAt(int index);
    public abstract ArrayList<? extends ConnectionRecordInternal> getConnectionAt(int index);

    /** Returns the host process that hosts this service. */
    public abstract ProcessRecordInternal getHostProcess();

    /** Returns the isolation host process (e.g., for isolated or SDK sandbox processes). */
    public abstract ProcessRecordInternal getIsolationHostProcess();
}
}
+2 −0
Original line number Original line Diff line number Diff line
@@ -4553,6 +4553,8 @@ public class MockingOomAdjusterTests {
        doCallRealMethod().when(record).setLastActivity(any(long.class));
        doCallRealMethod().when(record).setLastActivity(any(long.class));
        doCallRealMethod().when(record).getForegroundServiceType();
        doCallRealMethod().when(record).getForegroundServiceType();
        doCallRealMethod().when(record).setForegroundServiceType(any(int.class));
        doCallRealMethod().when(record).setForegroundServiceType(any(int.class));
        doCallRealMethod().when(record).getHostProcess();
        doCallRealMethod().when(record).getIsolationHostProcess();


        setFieldValue(ServiceRecord.class, record, "connections",
        setFieldValue(ServiceRecord.class, record, "connections",
                new ArrayMap<IBinder, ArrayList<ConnectionRecord>>());
                new ArrayMap<IBinder, ArrayList<ConnectionRecord>>());