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

Commit 95f8a8a1 authored by Jeff Sharkey's avatar Jeff Sharkey
Browse files

[3/3] Factor out current BroadcastQueue implementation.

Upcoming work will look at making significant changes to the
BroadcastQueue internals, so this change factors out the current
implementation to aid A/B testing.

This surgical change is designed to be a no-op refactoring with no
actual behavior changes.

Bug: 243656033
Test: atest CtsContentTestCases:BroadcastReceiverTest
Change-Id: Id709b6b82c8f814e7ac8a8aa28bdce719a61b8c2
parent 974e0ed6
Loading
Loading
Loading
Loading
+4 −4
Original line number Diff line number Diff line
@@ -2401,13 +2401,13 @@ public class ActivityManagerService extends IActivityManager.Stub
        mEnableOffloadQueue = SystemProperties.getBoolean(
                "persist.device_config.activity_manager_native_boot.offload_queue_enabled", true);
        mFgBroadcastQueue = new BroadcastQueue(this, mHandler,
        mFgBroadcastQueue = new BroadcastQueueImpl(this, mHandler,
                "foreground", foreConstants, false);
        mBgBroadcastQueue = new BroadcastQueue(this, mHandler,
        mBgBroadcastQueue = new BroadcastQueueImpl(this, mHandler,
                "background", backConstants, true);
        mBgOffloadBroadcastQueue = new BroadcastQueue(this, mHandler,
        mBgOffloadBroadcastQueue = new BroadcastQueueImpl(this, mHandler,
                "offload_bg", offloadConstants, true);
        mFgOffloadBroadcastQueue = new BroadcastQueue(this, mHandler,
        mFgOffloadBroadcastQueue = new BroadcastQueueImpl(this, mHandler,
                "offload_fg", foreConstants, true);
        mBroadcastQueues[0] = mFgBroadcastQueue;
        mBroadcastQueues[1] = mBgBroadcastQueue;
+116 −0
Original line number Diff line number Diff line
/*
 * Copyright (C) 2012 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;

import android.content.ContentResolver;
import android.content.IIntentReceiver;
import android.content.Intent;
import android.os.Bundle;
import android.os.Handler;
import android.os.IBinder;
import android.os.RemoteException;
import android.util.proto.ProtoOutputStream;

import java.io.FileDescriptor;
import java.io.PrintWriter;
import java.util.Set;

/**
 * Queue of broadcast intents and associated bookkeeping.
 */
public abstract class BroadcastQueue {
    final ActivityManagerService mService;
    final Handler mHandler;
    final BroadcastConstants mConstants;
    final String mQueueName;

    BroadcastQueue(ActivityManagerService service, Handler handler,
            String name, BroadcastConstants constants) {
        mService = service;
        mHandler = handler;
        mQueueName = name;
        mConstants = constants;
    }

    void start(ContentResolver resolver) {
        mConstants.startObserving(mHandler, resolver);
    }

    @Override
    public String toString() {
        return mQueueName;
    }

    public abstract boolean isDelayBehindServices();

    public abstract boolean hasBroadcastsScheduled();

    public abstract BroadcastRecord getPendingBroadcastLocked();

    public abstract BroadcastRecord getActiveBroadcastLocked();

    public abstract boolean isPendingBroadcastProcessLocked(int pid);

    public abstract boolean isPendingBroadcastProcessLocked(ProcessRecord app);

    public abstract void enqueueParallelBroadcastLocked(BroadcastRecord r);

    public abstract void enqueueOrderedBroadcastLocked(BroadcastRecord r);

    public abstract BroadcastRecord replaceParallelBroadcastLocked(BroadcastRecord r);

    public abstract BroadcastRecord replaceOrderedBroadcastLocked(BroadcastRecord r);

    public abstract void updateUidReadyForBootCompletedBroadcastLocked(int uid);

    public abstract boolean sendPendingBroadcastsLocked(ProcessRecord app);

    public abstract void skipPendingBroadcastLocked(int pid);

    public abstract void skipCurrentReceiverLocked(ProcessRecord app);

    public abstract void scheduleBroadcastsLocked();

    public abstract BroadcastRecord getMatchingOrderedReceiver(IBinder receiver);

    public abstract boolean finishReceiverLocked(BroadcastRecord r, int resultCode,
            String resultData, Bundle resultExtras, boolean resultAbort, boolean waitForServices);

    public abstract void backgroundServicesFinishedLocked(int userId);

    public abstract void performReceiveLocked(ProcessRecord app, IIntentReceiver receiver,
            Intent intent, int resultCode, String data, Bundle extras,
            boolean ordered, boolean sticky, int sendingUser,
            int receiverUid, int callingUid, long dispatchDelay,
            long receiveDelay) throws RemoteException;

    public abstract void processNextBroadcastLocked(boolean fromMsg, boolean skipOomAdj);

    public abstract boolean cleanupDisabledPackageReceiversLocked(
            String packageName, Set<String> filterByClasses, int userId, boolean doit);

    public abstract boolean isIdle();

    public abstract void cancelDeferrals();

    public abstract String describeState();

    public abstract void dumpDebug(ProtoOutputStream proto, long fieldId);

    public abstract boolean dumpLocked(FileDescriptor fd, PrintWriter pw, String[] args,
            int opti, boolean dumpAll, String dumpPackage, boolean needSep);
}
+3 −19
Original line number Diff line number Diff line
@@ -104,7 +104,7 @@ import java.util.Set;
 * foreground priority, and one for normal (background-priority) broadcasts, and one to
 * offload special broadcasts that we know take a long time, such as BOOT_COMPLETED.
 */
public class BroadcastQueue {
public class BroadcastQueueImpl extends BroadcastQueue {
    private static final String TAG = "BroadcastQueue";
    private static final String TAG_MU = TAG + POSTFIX_MU;
    private static final String TAG_BROADCAST = TAG + POSTFIX_BROADCAST;
@@ -113,19 +113,6 @@ public class BroadcastQueue {
    static final int MAX_BROADCAST_SUMMARY_HISTORY
            = ActivityManager.isLowRamDeviceStatic() ? 25 : 300;

    final ActivityManagerService mService;

    /**
     * Behavioral parameters such as timeouts and deferral policy, tracking Settings
     * for runtime configurability
     */
    final BroadcastConstants mConstants;

    /**
     * Recognizable moniker for this queue
     */
    final String mQueueName;

    /**
     * If true, we can delay broadcasts while waiting services to finish in the previous
     * receiver's process.
@@ -233,14 +220,11 @@ public class BroadcastQueue {
        }
    }

    BroadcastQueue(ActivityManagerService service, Handler handler,
    BroadcastQueueImpl(ActivityManagerService service, Handler handler,
            String name, BroadcastConstants constants, boolean allowDelayBehindServices) {
        mService = service;
        super(service, handler, name, constants);
        mHandler = new BroadcastHandler(handler.getLooper());
        mQueueName = name;
        mDelayBehindServices = allowDelayBehindServices;

        mConstants = constants;
        mDispatcher = new BroadcastDispatcher(this, mConstants, mHandler, mService);
    }