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

Commit c634a8f4 authored by Jing Ji's avatar Jing Ji
Browse files

Avoid extra calls into updateOomAdj

finishReceiver involves multiple calls into updateOomAdj
and the last one is from the trimApplications which will do
a full oom adj update; therefore the other one could be skipped.

Also fixed a test failure int ActivityManagerPerfTests due to
background restrictions

Bug: 160908195
Test: atest ActivityManagerPerfTests
Test: atest CtsAppTestCases
Change-Id: I6a7d0a96a65cea24995337eca1b50f00dbc4edee
parent d1ec2af4
Loading
Loading
Loading
Loading
+9 −6
Original line number Diff line number Diff line
@@ -603,7 +603,7 @@ public final class BroadcastQueue {
    }

    private void deliverToRegisteredReceiverLocked(BroadcastRecord r,
            BroadcastFilter filter, boolean ordered, int index) {
            BroadcastFilter filter, boolean ordered, int index, boolean skipOomAdj) {
        boolean skip = false;
        if (!mService.validateAssociationAllowedLocked(r.callerPackage, r.callingUid,
                filter.packageName, filter.owningUid)) {
@@ -787,10 +787,12 @@ public final class BroadcastQueue {
                // are already core system stuff so don't matter for this.
                r.curApp = filter.receiverList.app;
                filter.receiverList.app.curReceivers.add(r);
                if (!skipOomAdj) {
                    mService.updateOomAdjLocked(r.curApp, true,
                            OomAdjuster.OOM_ADJ_REASON_START_RECEIVER);
                }
            }
        }
        try {
            if (DEBUG_BROADCAST_LIGHT) Slog.i(TAG_BROADCAST,
                    "Delivering to " + filter + " : " + r);
@@ -984,7 +986,8 @@ public final class BroadcastQueue {
                if (DEBUG_BROADCAST)  Slog.v(TAG_BROADCAST,
                        "Delivering non-ordered on [" + mQueueName + "] to registered "
                        + target + ": " + r);
                deliverToRegisteredReceiverLocked(r, (BroadcastFilter)target, false, i);
                deliverToRegisteredReceiverLocked(r,
                        (BroadcastFilter) target, false, i, skipOomAdj);
            }
            addBroadcastToHistoryLocked(r);
            if (DEBUG_BROADCAST_LIGHT) Slog.v(TAG_BROADCAST, "Done with parallel broadcast ["
@@ -1036,7 +1039,7 @@ public final class BroadcastQueue {
                // No more broadcasts are deliverable right now, so all done!
                mDispatcher.scheduleDeferralCheckLocked(false);
                mService.scheduleAppGcsLocked();
                if (looped) {
                if (looped && !skipOomAdj) {
                    // If we had finished the last ordered broadcast, then
                    // make sure all processes have correct oom and sched
                    // adjustments.
@@ -1282,7 +1285,7 @@ public final class BroadcastQueue {
                    "Delivering ordered ["
                    + mQueueName + "] to registered "
                    + filter + ": " + r);
            deliverToRegisteredReceiverLocked(r, filter, r.ordered, recIdx);
            deliverToRegisteredReceiverLocked(r, filter, r.ordered, recIdx, skipOomAdj);
            if (r.receiver == null || !r.ordered) {
                // The receiver has already finished, so schedule to
                // process the next one.
+16 −0
Original line number Diff line number Diff line
@@ -25,14 +25,30 @@ import androidx.test.runner.AndroidJUnit4;

import com.android.frameworks.perftests.am.util.Constants;
import com.android.frameworks.perftests.am.util.TargetPackageUtils;
import com.android.frameworks.perftests.am.util.Utils;

import org.junit.After;
import org.junit.Assert;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;

@RunWith(AndroidJUnit4.class)
@LargeTest
public class ServiceStartPerfTest extends BasePerfTest {
    private static final String STUB_PACKAGE_NAME =
            "com.android.frameworks.perftests.amteststestapp";

    @Before
    public void setUp() {
        super.setUp();
        Utils.runShellCommand("cmd deviceidle whitelist +" + STUB_PACKAGE_NAME);
    }

    @After
    public void tearDown() {
        Utils.runShellCommand("cmd deviceidle whitelist -" + STUB_PACKAGE_NAME);
    }

    /**
     * Tries to start the service with the given intent, throwing a RuntimeException with the