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

Commit c5bd860b authored by Sudheer Shanka's avatar Sudheer Shanka
Browse files

Inject the BroadcastQueue created in the test into AMS.

Bug: 314181833
Test: atest services/tests/mockingservicestests/src/com/android/server/am/BroadcastQueueTest.java
Change-Id: Icadfb72ed2b1efc6f3f2d6240b970d5537e392d9
parent 8628cbbf
Loading
Loading
Loading
Loading
+42 −32
Original line number Diff line number Diff line
@@ -2486,7 +2486,7 @@ public class ActivityManagerService extends IActivityManager.Stub
        mUseFifoUiScheduling = false;
        mEnableOffloadQueue = false;
        mEnableModernQueue = false;
        mBroadcastQueues = new BroadcastQueue[0];
        mBroadcastQueues = injector.getBroadcastQueues(this);
        mComponentAliasResolver = new ComponentAliasResolver(this);
    }
@@ -2527,40 +2527,12 @@ public class ActivityManagerService extends IActivityManager.Stub
                ? new OomAdjusterModernImpl(this, mProcessList, activeUids)
                : new OomAdjuster(this, mProcessList, activeUids);
        // Broadcast policy parameters
        final BroadcastConstants foreConstants = new BroadcastConstants(
                Settings.Global.BROADCAST_FG_CONSTANTS);
        foreConstants.TIMEOUT = BROADCAST_FG_TIMEOUT;
        final BroadcastConstants backConstants = new BroadcastConstants(
                Settings.Global.BROADCAST_BG_CONSTANTS);
        backConstants.TIMEOUT = BROADCAST_BG_TIMEOUT;
        final BroadcastConstants offloadConstants = new BroadcastConstants(
                Settings.Global.BROADCAST_OFFLOAD_CONSTANTS);
        offloadConstants.TIMEOUT = BROADCAST_BG_TIMEOUT;
        // by default, no "slow" policy in this queue
        offloadConstants.SLOW_TIME = Integer.MAX_VALUE;
        mEnableOffloadQueue = SystemProperties.getBoolean(
                "persist.device_config.activity_manager_native_boot.offload_queue_enabled", true);
        mEnableModernQueue = foreConstants.MODERN_QUEUE_ENABLED;
        mEnableModernQueue = new BroadcastConstants(
                Settings.Global.BROADCAST_FG_CONSTANTS).MODERN_QUEUE_ENABLED;
        if (mEnableModernQueue) {
            mBroadcastQueues = new BroadcastQueue[1];
            mBroadcastQueues[0] = new BroadcastQueueModernImpl(this, mHandler,
                    foreConstants, backConstants);
        } else {
            mBroadcastQueues = new BroadcastQueue[4];
            mBroadcastQueues[BROADCAST_QUEUE_FG] = new BroadcastQueueImpl(this, mHandler,
                    "foreground", foreConstants, false, ProcessList.SCHED_GROUP_DEFAULT);
            mBroadcastQueues[BROADCAST_QUEUE_BG] = new BroadcastQueueImpl(this, mHandler,
                    "background", backConstants, true, ProcessList.SCHED_GROUP_BACKGROUND);
            mBroadcastQueues[BROADCAST_QUEUE_BG_OFFLOAD] = new BroadcastQueueImpl(this, mHandler,
                    "offload_bg", offloadConstants, true, ProcessList.SCHED_GROUP_BACKGROUND);
            mBroadcastQueues[BROADCAST_QUEUE_FG_OFFLOAD] = new BroadcastQueueImpl(this, mHandler,
                    "offload_fg", foreConstants, true, ProcessList.SCHED_GROUP_BACKGROUND);
        }
        mBroadcastQueues = mInjector.getBroadcastQueues(this);
        mServices = new ActiveServices(this);
        mCpHelper = new ContentProviderHelper(this, true);
@@ -20060,6 +20032,44 @@ public class ActivityManagerService extends IActivityManager.Stub
            }
            return mNmi != null;
        }
        public BroadcastQueue[] getBroadcastQueues(ActivityManagerService service) {
            // Broadcast policy parameters
            final BroadcastConstants foreConstants = new BroadcastConstants(
                    Settings.Global.BROADCAST_FG_CONSTANTS);
            foreConstants.TIMEOUT = BROADCAST_FG_TIMEOUT;
            final BroadcastConstants backConstants = new BroadcastConstants(
                    Settings.Global.BROADCAST_BG_CONSTANTS);
            backConstants.TIMEOUT = BROADCAST_BG_TIMEOUT;
            final BroadcastConstants offloadConstants = new BroadcastConstants(
                    Settings.Global.BROADCAST_OFFLOAD_CONSTANTS);
            offloadConstants.TIMEOUT = BROADCAST_BG_TIMEOUT;
            // by default, no "slow" policy in this queue
            offloadConstants.SLOW_TIME = Integer.MAX_VALUE;
            final BroadcastQueue[] broadcastQueues;
            final Handler handler = service.mHandler;
            if (service.mEnableModernQueue) {
                broadcastQueues = new BroadcastQueue[1];
                broadcastQueues[0] = new BroadcastQueueModernImpl(service, handler,
                        foreConstants, backConstants);
            } else {
                broadcastQueues = new BroadcastQueue[4];
                broadcastQueues[BROADCAST_QUEUE_FG] = new BroadcastQueueImpl(service, handler,
                        "foreground", foreConstants, false, ProcessList.SCHED_GROUP_DEFAULT);
                broadcastQueues[BROADCAST_QUEUE_BG] = new BroadcastQueueImpl(service, handler,
                        "background", backConstants, true, ProcessList.SCHED_GROUP_BACKGROUND);
                broadcastQueues[BROADCAST_QUEUE_BG_OFFLOAD] = new BroadcastQueueImpl(service,
                        handler, "offload_bg", offloadConstants, true,
                        ProcessList.SCHED_GROUP_BACKGROUND);
                broadcastQueues[BROADCAST_QUEUE_FG_OFFLOAD] = new BroadcastQueueImpl(service,
                        handler, "offload_fg", foreConstants, true,
                        ProcessList.SCHED_GROUP_BACKGROUND);
            }
            return broadcastQueues;
        }
    }
    @Override
+10 −1
Original line number Diff line number Diff line
@@ -93,6 +93,8 @@ public abstract class BaseBroadcastQueueTest {
            .spyStatic(ProcessList.class)
            .build();

    final BroadcastQueue[] mBroadcastQueues = new BroadcastQueue[1];

    @Mock
    AppOpsService mAppOpsService;
    @Mock
@@ -162,8 +164,10 @@ public abstract class BaseBroadcastQueueTest {
    }

    public void tearDown() throws Exception {
        if (mHandlerThread != null) {
            mHandlerThread.quit();
        }
    }

    static int getUidForPackage(@NonNull String packageName) {
        switch (packageName) {
@@ -202,6 +206,11 @@ public abstract class BaseBroadcastQueueTest {
        public ProcessList getProcessList(ActivityManagerService service) {
            return mProcessList;
        }

        @Override
        public BroadcastQueue[] getBroadcastQueues(ActivityManagerService service) {
            return mBroadcastQueues;
        }
    }

    abstract String getTag();
+1 −0
Original line number Diff line number Diff line
@@ -126,6 +126,7 @@ public final class BroadcastQueueModernImplTest extends BaseBroadcastQueueTest {

        mImpl = new BroadcastQueueModernImpl(mAms, mHandlerThread.getThreadHandler(),
            mConstants, mConstants, mSkipPolicy, emptyHistory);
        mBroadcastQueues[0] = mImpl;

        doReturn(1L).when(mQueue1).getRunnableAt();
        doReturn(2L).when(mQueue2).getRunnableAt();
+1 −0
Original line number Diff line number Diff line
@@ -255,6 +255,7 @@ public class BroadcastQueueTest extends BaseBroadcastQueueTest {
        } else {
            throw new UnsupportedOperationException();
        }
        mBroadcastQueues[0] = mQueue;

        mQueue.start(mContext.getContentResolver());
    }