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

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

psc: Introduce ContentProviderConnectionInternal interface

Abstract ContentProviderConnection by moving its public API
to the new ContentProviderConnectionInternal interface in the
psc (ProcessStateController) package.

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

Change-Id: I048353f6660f0f43bfe8e95eb2d8ce6b1a02837f
parent 326e1ea4
Loading
Loading
Loading
Loading
+9 −15
Original line number Diff line number Diff line
@@ -20,6 +20,7 @@ import static com.android.server.am.ActivityManagerDebugConfig.DEBUG_PROVIDER;
import static com.android.server.am.ActivityManagerDebugConfig.TAG_AM;

import android.annotation.UserIdInt;
import android.content.ComponentName;
import android.os.Binder;
import android.os.SystemClock;
import android.util.Slog;
@@ -28,13 +29,13 @@ import android.util.TimeUtils;
import com.android.internal.annotations.GuardedBy;
import com.android.internal.app.procstats.AssociationState;
import com.android.internal.app.procstats.ProcessStats;
import com.android.server.am.psc.ProcessRecordInternal;
import com.android.server.am.psc.ContentProviderConnectionInternal;

/**
 * Represents a link between a content provider and client.
 */
public final class ContentProviderConnection extends Binder implements
        OomAdjusterImpl.Connection {
        ContentProviderConnectionInternal {
    public final ContentProviderRecord provider;
    public final ProcessRecord client;
    public final String clientPackage;
@@ -74,19 +75,6 @@ public final class ContentProviderConnection extends Binder implements
        createTime = SystemClock.elapsedRealtime();
    }

    @Override
    public void computeHostOomAdjLSP(OomAdjuster oomAdjuster, ProcessRecordInternal host,
            ProcessRecordInternal client, long now, ProcessRecordInternal topApp, boolean doingAll,
            int oomAdjReason, int cachedAdj) {
        oomAdjuster.computeProviderHostOomAdjLSP(this, host, client, false);
    }

    @Override
    public boolean canAffectCapabilities() {
        return false;
    }


    public void startAssociationIfNeeded() {
        // If we don't already have an active association, create one...  but only if this
        // is an association between two different processes.
@@ -116,6 +104,7 @@ public final class ContentProviderConnection extends Binder implements
    /**
     * Track the given proc state change.
     */
    @Override
    public void trackProcState(int procState, int seq) {
        if (association == null) {
            return; // early exit to optimize on oomadj cycles
@@ -127,6 +116,11 @@ public final class ContentProviderConnection extends Binder implements
        }
    }

    @Override
    public ComponentName getProviderName() {
        return provider.name;
    }

    public void stopAssociation() {
        if (association == null) {
            return; // early exit to optimize on oomadj cycles
+2 −1
Original line number Diff line number Diff line
@@ -149,6 +149,7 @@ import com.android.internal.annotations.VisibleForTesting;
import com.android.server.ServiceThread;
import com.android.server.am.psc.ActiveUidsInternal;
import com.android.server.am.psc.ConnectionRecordInternal;
import com.android.server.am.psc.ContentProviderConnectionInternal;
import com.android.server.am.psc.PlatformCompatCache;
import com.android.server.am.psc.PlatformCompatCache.CachedCompatChangeId;
import com.android.server.am.psc.ProcessRecordInternal;
@@ -1997,7 +1998,7 @@ public abstract class OomAdjuster {
     * Computes the impact on {@code app} the provider connections from {@code client} has.
     */
    @GuardedBy({"mService", "mProcLock"})
    public abstract boolean computeProviderHostOomAdjLSP(ContentProviderConnection conn,
    public abstract boolean computeProviderHostOomAdjLSP(ContentProviderConnectionInternal conn,
            ProcessRecordInternal app, ProcessRecordInternal client, boolean dryRun);

    protected int getDefaultCapability(ProcessRecordInternal app, int procState) {
+3 −2
Original line number Diff line number Diff line
@@ -106,6 +106,7 @@ import com.android.internal.annotations.VisibleForTesting;
import com.android.server.ServiceThread;
import com.android.server.am.psc.ActiveUidsInternal;
import com.android.server.am.psc.ConnectionRecordInternal;
import com.android.server.am.psc.ContentProviderConnectionInternal;
import com.android.server.am.psc.ProcessRecordInternal;
import com.android.server.am.psc.UidRecordInternal;
import com.android.server.wm.ActivityServiceConnectionsHolder;
@@ -2301,7 +2302,7 @@ public class OomAdjusterImpl extends OomAdjuster {

    @GuardedBy({"mService", "mProcLock"})
    @Override
    public boolean computeProviderHostOomAdjLSP(ContentProviderConnection conn,
    public boolean computeProviderHostOomAdjLSP(ContentProviderConnectionInternal conn,
            ProcessRecordInternal app, ProcessRecordInternal client, boolean dryRun) {
        if (app.isPendingFinishAttach()) {
            // We've set the attaching process state in the computeInitialOomAdjLSP. Skip it here.
@@ -2410,7 +2411,7 @@ public class OomAdjusterImpl extends OomAdjuster {
            app.setAdjTypeCode(ActivityManager.RunningAppProcessInfo.REASON_PROVIDER_IN_USE);
            app.setAdjSource(client);
            app.setAdjSourceProcState(clientProcState);
            app.setAdjTarget(conn.provider.name);
            app.setAdjTarget(conn.getProviderName());
            if (reportDebugMsgs) {
                reportOomAdjMessageLocked(TAG_OOM_ADJ, "Raise to " + adjType
                        + ": " + app + ", due to " + client
+46 −0
Original line number Diff line number Diff line
/*
 * Copyright (C) 2025 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package com.android.server.am.psc;

import android.content.ComponentName;

import com.android.server.am.OomAdjuster;
import com.android.server.am.OomAdjusterImpl;

/**
 * An interface encapsulating common internal properties for a link between a content provider and
 * client.
 */
public interface ContentProviderConnectionInternal extends OomAdjusterImpl.Connection {
    /** Track the given proc state change. */
    void trackProcState(int procState, int seq);

    /** Returns the {@link ComponentName} of the content provider in this connection. */
    ComponentName getProviderName();

    @Override
    default void computeHostOomAdjLSP(OomAdjuster oomAdjuster, ProcessRecordInternal host,
            ProcessRecordInternal client, long now, ProcessRecordInternal topApp, boolean doingAll,
            int oomAdjReason, int cachedAdj) {
        oomAdjuster.computeProviderHostOomAdjLSP(this, host, client, false);
    }

    @Override
    default boolean canAffectCapabilities() {
        return false;
    }
}