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

Commit ff5e91f2 authored by Fabian Kozynski's avatar Fabian Kozynski
Browse files

Convert all SCREEN_OFF receivers to BroadcastDispatcher

All broadcast receivers that filter for ACTION_SCREEN_OFF have been converted
to register with BroadcastDispatcher instead of Context. In many cases
this involves other Intents being covered by BroadcastDispatcher.

Additionally, UserBroadcastDispatcher propagates the PendingResult so
the individual receivers can access it (mostly to query getSendingUser).

Test: enable logging of BroadcastQueue for ACTION_SCREEN_OFF only shows 2
receivers (user 0 and user -1)
Test: Dump of BroadcastDispatcher shows all the classes registered to it
Test: enable logging of UserBroadcastDispatcher
Test: atest PowerUITest StatusBarTest VolumeDialogControllerImplTest
        SystemUIDialogTest NavigationBarFragmentTest
Bug: 134566046

Change-Id: I0caa2a6b53f3f6b360bf2e8598dde29c45f1d4e3
parent a620de30
Loading
Loading
Loading
Loading
+7 −0
Original line number Diff line number Diff line
@@ -17,6 +17,7 @@
package com.android.systemui;

import com.android.systemui.keyguard.KeyguardViewMediator;
import com.android.systemui.power.PowerUI;

import dagger.Binds;
import dagger.Module;
@@ -33,4 +34,10 @@ public abstract class SystemUIBinder {
    @IntoMap
    @ClassKey(KeyguardViewMediator.class)
    public abstract SystemUI bindKeyguardViewMediator(KeyguardViewMediator sysui);

    /** Inject into PowerUI. */
    @Binds
    @IntoMap
    @ClassKey(PowerUI.class)
    public abstract SystemUI bindPowerUI(PowerUI sysui);
}
+5 −3
Original line number Diff line number Diff line
@@ -75,7 +75,7 @@ open class BroadcastDispatcher @Inject constructor (
     * @param filter A filter to determine what broadcasts should be dispatched to this receiver.
     *               It will only take into account actions and categories for filtering.
     * @param handler A handler to dispatch [BroadcastReceiver.onReceive]. By default, it is the
     *                main handler.
     *                main handler. Pass `null` to use the default.
     * @param user A user handle to determine which broadcast should be dispatched to this receiver.
     *             By default, it is the current user.
     */
@@ -83,10 +83,12 @@ open class BroadcastDispatcher @Inject constructor (
    fun registerReceiver(
        receiver: BroadcastReceiver,
        filter: IntentFilter,
        handler: Handler = mainHandler,
        handler: Handler? = mainHandler,
        user: UserHandle = context.user
    ) {
        this.handler.obtainMessage(MSG_ADD_RECEIVER, ReceiverData(receiver, filter, handler, user))
        this.handler
                .obtainMessage(MSG_ADD_RECEIVER,
                ReceiverData(receiver, filter, handler ?: mainHandler, user))
                .sendToTarget()
    }

+5 −3
Original line number Diff line number Diff line
@@ -34,7 +34,7 @@ import java.util.concurrent.atomic.AtomicBoolean

private const val MSG_REGISTER_RECEIVER = 0
private const val MSG_UNREGISTER_RECEIVER = 1
private const val TAG = "UniversalReceiver"
private const val TAG = "UserBroadcastDispatcher"
private const val DEBUG = false

/**
@@ -97,7 +97,7 @@ class UserBroadcastDispatcher(
    private val receiverToReceiverData = ArrayMap<BroadcastReceiver, MutableSet<ReceiverData>>()

    override fun onReceive(context: Context, intent: Intent) {
        bgHandler.post(HandleBroadcastRunnable(actionsToReceivers, context, intent))
        bgHandler.post(HandleBroadcastRunnable(actionsToReceivers, context, intent, pendingResult))
    }

    /**
@@ -160,7 +160,8 @@ class UserBroadcastDispatcher(
    private class HandleBroadcastRunnable(
        val actionsToReceivers: Map<String, Set<ReceiverData>>,
        val context: Context,
        val intent: Intent
        val intent: Intent,
        val pendingResult: PendingResult
    ) : Runnable {
        override fun run() {
            if (DEBUG) Log.w(TAG, "Dispatching $intent")
@@ -171,6 +172,7 @@ class UserBroadcastDispatcher(
                    ?.forEach {
                        it.handler.post {
                            if (DEBUG) Log.w(TAG, "Dispatching to ${it.receiver}")
                            it.receiver.pendingResult = pendingResult
                            it.receiver.onReceive(context, intent)
                        }
                    }
+2 −1
Original line number Diff line number Diff line
@@ -90,6 +90,7 @@ import com.android.systemui.Dependency;
import com.android.systemui.Interpolators;
import com.android.systemui.MultiListLayout;
import com.android.systemui.MultiListLayout.MultiListAdapter;
import com.android.systemui.broadcast.BroadcastDispatcher;
import com.android.systemui.colorextraction.SysuiColorExtractor;
import com.android.systemui.plugins.ActivityStarter;
import com.android.systemui.plugins.GlobalActions.GlobalActionsManager;
@@ -187,7 +188,7 @@ public class GlobalActionsDialog implements DialogInterface.OnDismissListener,
        filter.addAction(Intent.ACTION_CLOSE_SYSTEM_DIALOGS);
        filter.addAction(Intent.ACTION_SCREEN_OFF);
        filter.addAction(TelephonyIntents.ACTION_EMERGENCY_CALLBACK_MODE_CHANGED);
        context.registerReceiver(mBroadcastReceiver, filter);
        Dependency.get(BroadcastDispatcher.class).registerReceiver(mBroadcastReceiver, filter);

        ConnectivityManager cm = (ConnectivityManager)
                context.getSystemService(Context.CONNECTIVITY_SERVICE);
+10 −1
Original line number Diff line number Diff line
@@ -45,6 +45,7 @@ import com.android.settingslib.utils.ThreadUtils;
import com.android.systemui.Dependency;
import com.android.systemui.R;
import com.android.systemui.SystemUI;
import com.android.systemui.broadcast.BroadcastDispatcher;
import com.android.systemui.statusbar.phone.StatusBar;

import java.io.FileDescriptor;
@@ -53,6 +54,8 @@ import java.time.Duration;
import java.util.Arrays;
import java.util.concurrent.Future;

import javax.inject.Inject;

public class PowerUI extends SystemUI {

    static final String TAG = "PowerUI";
@@ -97,6 +100,12 @@ public class PowerUI extends SystemUI {

    private IThermalEventListener mSkinThermalEventListener;
    private IThermalEventListener mUsbThermalEventListener;
    private final BroadcastDispatcher mBroadcastDispatcher;

    @Inject
    public PowerUI(BroadcastDispatcher broadcastDispatcher) {
        mBroadcastDispatcher = broadcastDispatcher;
    }

    public void start() {
        mPowerManager = (PowerManager) mContext.getSystemService(Context.POWER_SERVICE);
@@ -211,7 +220,7 @@ public class PowerUI extends SystemUI {
            filter.addAction(Intent.ACTION_SCREEN_OFF);
            filter.addAction(Intent.ACTION_SCREEN_ON);
            filter.addAction(Intent.ACTION_USER_SWITCHED);
            mContext.registerReceiver(this, filter, null, mHandler);
            mBroadcastDispatcher.registerReceiver(this, filter, mHandler);
        }

        @Override
Loading