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

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

am: Move OomAdjuster.initSettings() logic to ActivityManagerService

This CL moves OomAdjuster's initialization logic into
ActivityManagerService.setupServicePrewarmingOnUserSwitch(). This
includes transferring the ACTION_USER_SWITCHED receiver registration.

Bug: 441408003
Test: m services.core
Test: atest MockingOomAdjusterTests OomAdjusterTests
Test: atest FrameworksServicesTestsRavenwood_ProcessStateController
Flag: EXEMPT PURE_REFACTOR

Change-Id: I1d642980d8cbed145ab1b1b23eff1f466f65c84d
parent 3d7ad161
Loading
Loading
Loading
Loading
+19 −0
Original line number Diff line number Diff line
@@ -19516,6 +19516,25 @@ public class ActivityManagerService extends IActivityManager.Stub
        processesToUnfreeze.clear();
    }
    /**
     * Sets up a broadcast receiver to handle user switch events, which triggers prewarming of
     * services.
     */
    void setupServicePrewarmingOnUserSwitch() {
        if (!mConstants.KEEP_WARMING_SERVICES.isEmpty()) {
            final IntentFilter filter = new IntentFilter(Intent.ACTION_USER_SWITCHED);
            final BroadcastReceiver receiver = new BroadcastReceiver() {
                @Override
                public void onReceive(Context context, Intent intent) {
                    synchronized (ActivityManagerService.this) {
                        mOomAdjuster.prewarmServicesIfNecessary();
                    }
                }
            };
            mContext.registerReceiverForAllUsers(receiver, filter, null, mHandler);
        }
    }
    /**
     * Resets the state of the {@link com.android.server.am.AppErrors} instance.
     * This is intended for testing within the CTS only and is protected by
+1 −1
Original line number Diff line number Diff line
@@ -1381,7 +1381,7 @@ public class ContentProviderHelper {
        new DevelopmentSettingsObserver(); // init to observe developer settings enable/disable
        SettingsToPropertiesMapper.start(mService.mContext.getContentResolver());
        mService.getCachedAppOptimizer().init();
        mService.mOomAdjuster.initSettings();
        mService.setupServicePrewarmingOnUserSwitch();

        // Now that the settings provider is published we can consider sending in a rescue party.
        CrashRecoveryAdaptor.rescuePartyOnSettingsProviderPublished(mService.mContext);
+1 −19
Original line number Diff line number Diff line
@@ -123,11 +123,8 @@ import android.app.ActivityManager;
import android.app.ActivityManagerInternal.OomAdjReason;
import android.app.ApplicationExitInfo;
import android.app.usage.UsageEvents;
import android.content.BroadcastReceiver;
import android.content.ComponentName;
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
import android.content.pm.ApplicationInfo;
import android.content.pm.ServiceInfo;
import android.net.NetworkPolicyManager;
@@ -548,26 +545,11 @@ public abstract class OomAdjuster {
                group, app));
    }

    void initSettings() {
        if (mService.mConstants.KEEP_WARMING_SERVICES.size() > 0) {
            final IntentFilter filter = new IntentFilter(Intent.ACTION_USER_SWITCHED);
            mService.mContext.registerReceiverForAllUsers(new BroadcastReceiver() {
                @Override
                public void onReceive(Context context, Intent intent) {
                    synchronized (mService) {
                        handleUserSwitchedLocked();
                    }
                }
            }, filter, null, mService.mHandler);
        }
    }

    /**
     * Update the keep-warming service flags upon user switches
     */
    @VisibleForTesting
    @GuardedBy("mService")
    void handleUserSwitchedLocked() {
    public void prewarmServicesIfNecessary() {
        mProcessList.forEachLruProcessesLOSP(false,
                this::updateKeepWarmIfNecessaryForProcessLocked);
    }
+1 −1
Original line number Diff line number Diff line
@@ -3716,7 +3716,7 @@ public class MockingOomAdjusterTests {
        assertThatProcess(app2).notHasImplicitCpuTimeCapability();

        doReturn(userOther).when(mService.mUserController).getCurrentUserId();
        mService.mOomAdjuster.handleUserSwitchedLocked();
        mService.mOomAdjuster.prewarmServicesIfNecessary();

        updateOomAdj();
        assertProcStates(app, PROCESS_STATE_SERVICE, cachedAdj1,