BroadcastDispatcher can use Executors now
registerReceiver takes an optional Executor parameter. The old registerReceiver that takes a Handler has been renamed and @Deprecated Test: SystemUITests Change-Id: I43b97f720b2b153d1019ed3cf19e1533558e380f
This commit is contained in:
@@ -42,24 +42,29 @@ Acquire the dispatcher by using `@Inject` to obtain a `BroadcastDispatcher`. The
|
||||
|
||||
```kotlin
|
||||
/**
|
||||
* Register a receiver for broadcast with the dispatcher
|
||||
*
|
||||
* @param receiver A receiver to dispatch the [Intent]
|
||||
* @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. It must
|
||||
* have at least one action.
|
||||
* @param handler A handler to dispatch [BroadcastReceiver.onReceive]. By default, it is the
|
||||
* 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.
|
||||
* @throws IllegalArgumentException if the filter has other constraints that are not actions or
|
||||
* categories or the filter has no actions.
|
||||
*/
|
||||
* Register a receiver for broadcast with the dispatcher
|
||||
*
|
||||
* @param receiver A receiver to dispatch the [Intent]
|
||||
* @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. It must
|
||||
* have at least one action.
|
||||
* @param executor An executor to dispatch [BroadcastReceiver.onReceive]. Pass null to use an
|
||||
* executor in the main thread (default).
|
||||
* @param user A user handle to determine which broadcast should be dispatched to this receiver.
|
||||
* By default, it is the current user.
|
||||
* @throws IllegalArgumentException if the filter has other constraints that are not actions or
|
||||
* categories or the filter has no actions.
|
||||
*/
|
||||
@JvmOverloads
|
||||
fun registerReceiver(BroadcastReceiver, IntentFilter, Handler? = mainHandler, UserHandle = context.user)
|
||||
fun registerReceiver(
|
||||
BroadcastReceiver,
|
||||
IntentFilter,
|
||||
Executor? = context.mainExecutor,
|
||||
UserHandle = context.user
|
||||
) {
|
||||
```
|
||||
|
||||
All subscriptions are done with the same overloaded method. As specified in the doc, in order to pass a `UserHandle` with the default `Handler`, pass `null` for the `Handler`.
|
||||
All subscriptions are done with the same overloaded method. As specified in the doc, in order to pass a `UserHandle` with the default `Executor`, pass `null` for the `Executor`.
|
||||
|
||||
In the same way as with `Context`, subscribing the same `BroadcastReceiver` for the same user using different filters will result on two subscriptions, not in replacing the filter.
|
||||
|
||||
|
||||
@@ -1638,7 +1638,7 @@ public class KeyguardUpdateMonitor implements TrustManager.TrustListener, Dumpab
|
||||
filter.addAction(TelephonyManager.ACTION_PHONE_STATE_CHANGED);
|
||||
filter.addAction(AudioManager.RINGER_MODE_CHANGED_ACTION);
|
||||
filter.addAction(DevicePolicyManager.ACTION_DEVICE_POLICY_MANAGER_STATE_CHANGED);
|
||||
broadcastDispatcher.registerReceiver(mBroadcastReceiver, filter, mHandler);
|
||||
broadcastDispatcher.registerReceiverWithHandler(mBroadcastReceiver, filter, mHandler);
|
||||
|
||||
final IntentFilter allUserFilter = new IntentFilter();
|
||||
allUserFilter.addAction(Intent.ACTION_USER_INFO_CHANGED);
|
||||
@@ -1649,8 +1649,8 @@ public class KeyguardUpdateMonitor implements TrustManager.TrustListener, Dumpab
|
||||
allUserFilter.addAction(ACTION_USER_UNLOCKED);
|
||||
allUserFilter.addAction(ACTION_USER_STOPPED);
|
||||
allUserFilter.addAction(ACTION_USER_REMOVED);
|
||||
broadcastDispatcher.registerReceiver(mBroadcastAllReceiver, allUserFilter, mHandler,
|
||||
UserHandle.ALL);
|
||||
broadcastDispatcher.registerReceiverWithHandler(mBroadcastAllReceiver, allUserFilter,
|
||||
mHandler, UserHandle.ALL);
|
||||
|
||||
mSubscriptionManager.addOnSubscriptionsChangedListener(mSubscriptionListener);
|
||||
try {
|
||||
|
||||
@@ -266,7 +266,7 @@ public class ScreenDecorations extends SystemUI implements Tunable {
|
||||
|
||||
IntentFilter filter = new IntentFilter();
|
||||
filter.addAction(Intent.ACTION_USER_SWITCHED);
|
||||
mBroadcastDispatcher.registerReceiver(mIntentReceiver, filter, mHandler);
|
||||
mBroadcastDispatcher.registerReceiverWithHandler(mIntentReceiver, filter, mHandler);
|
||||
|
||||
mOverlay.addOnLayoutChangeListener(new OnLayoutChangeListener() {
|
||||
@Override
|
||||
|
||||
@@ -20,6 +20,7 @@ import android.content.BroadcastReceiver
|
||||
import android.content.Context
|
||||
import android.content.IntentFilter
|
||||
import android.os.Handler
|
||||
import android.os.HandlerExecutor
|
||||
import android.os.Looper
|
||||
import android.os.Message
|
||||
import android.os.UserHandle
|
||||
@@ -32,13 +33,14 @@ import com.android.systemui.dagger.qualifiers.Background
|
||||
import com.android.systemui.dagger.qualifiers.Main
|
||||
import java.io.FileDescriptor
|
||||
import java.io.PrintWriter
|
||||
import java.util.concurrent.Executor
|
||||
import javax.inject.Inject
|
||||
import javax.inject.Singleton
|
||||
|
||||
data class ReceiverData(
|
||||
val receiver: BroadcastReceiver,
|
||||
val filter: IntentFilter,
|
||||
val handler: Handler,
|
||||
val executor: Executor,
|
||||
val user: UserHandle
|
||||
)
|
||||
|
||||
@@ -76,8 +78,33 @@ 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. It must
|
||||
* have at least one action.
|
||||
* @param handler A handler to dispatch [BroadcastReceiver.onReceive]. By default, it is the
|
||||
* main handler. Pass `null` to use the default.
|
||||
* @param handler A handler to dispatch [BroadcastReceiver.onReceive].
|
||||
* @param user A user handle to determine which broadcast should be dispatched to this receiver.
|
||||
* By default, it is the current user.
|
||||
* @throws IllegalArgumentException if the filter has other constraints that are not actions or
|
||||
* categories or the filter has no actions.
|
||||
*/
|
||||
@Deprecated(message = "Replacing Handler for Executor in SystemUI",
|
||||
replaceWith = ReplaceWith("registerReceiver(receiver, filter, executor, user)"))
|
||||
@JvmOverloads
|
||||
fun registerReceiverWithHandler(
|
||||
receiver: BroadcastReceiver,
|
||||
filter: IntentFilter,
|
||||
handler: Handler,
|
||||
user: UserHandle = context.user
|
||||
) {
|
||||
registerReceiver(receiver, filter, HandlerExecutor(handler), user)
|
||||
}
|
||||
|
||||
/**
|
||||
* Register a receiver for broadcast with the dispatcher
|
||||
*
|
||||
* @param receiver A receiver to dispatch the [Intent]
|
||||
* @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. It must
|
||||
* have at least one action.
|
||||
* @param executor An executor to dispatch [BroadcastReceiver.onReceive]. Pass null to use an
|
||||
* executor in the main thread (default).
|
||||
* @param user A user handle to determine which broadcast should be dispatched to this receiver.
|
||||
* By default, it is the current user.
|
||||
* @throws IllegalArgumentException if the filter has other constraints that are not actions or
|
||||
@@ -85,15 +112,15 @@ open class BroadcastDispatcher @Inject constructor (
|
||||
*/
|
||||
@JvmOverloads
|
||||
fun registerReceiver(
|
||||
receiver: BroadcastReceiver,
|
||||
filter: IntentFilter,
|
||||
handler: Handler? = mainHandler,
|
||||
user: UserHandle = context.user
|
||||
receiver: BroadcastReceiver,
|
||||
filter: IntentFilter,
|
||||
executor: Executor? = context.mainExecutor,
|
||||
user: UserHandle = context.user
|
||||
) {
|
||||
checkFilter(filter)
|
||||
this.handler
|
||||
.obtainMessage(MSG_ADD_RECEIVER,
|
||||
ReceiverData(receiver, filter, handler ?: mainHandler, user))
|
||||
ReceiverData(receiver, filter, executor ?: context.mainExecutor, user))
|
||||
.sendToTarget()
|
||||
}
|
||||
|
||||
|
||||
@@ -193,7 +193,7 @@ class UserBroadcastDispatcher(
|
||||
it.filter.hasAction(intent.action) &&
|
||||
it.filter.matchCategories(intent.categories) == null }
|
||||
?.forEach {
|
||||
it.handler.post {
|
||||
it.executor.execute {
|
||||
if (DEBUG) Log.w(TAG,
|
||||
"[$index] Dispatching ${intent.action} to ${it.receiver}")
|
||||
it.receiver.pendingResult = pendingResult
|
||||
|
||||
@@ -91,7 +91,7 @@ public class DozeScreenBrightness extends BroadcastReceiver implements DozeMachi
|
||||
if (mDebuggable) {
|
||||
IntentFilter filter = new IntentFilter();
|
||||
filter.addAction(ACTION_AOD_BRIGHTNESS);
|
||||
mBroadcastDispatcher.registerReceiver(this, filter, handler, UserHandle.ALL);
|
||||
mBroadcastDispatcher.registerReceiverWithHandler(this, filter, handler, UserHandle.ALL);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -233,7 +233,7 @@ public class PowerUI extends SystemUI implements CommandQueue.Callbacks {
|
||||
filter.addAction(Intent.ACTION_SCREEN_OFF);
|
||||
filter.addAction(Intent.ACTION_SCREEN_ON);
|
||||
filter.addAction(Intent.ACTION_USER_SWITCHED);
|
||||
mBroadcastDispatcher.registerReceiver(this, filter, mHandler);
|
||||
mBroadcastDispatcher.registerReceiverWithHandler(this, filter, mHandler);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -322,7 +322,7 @@ public class TileLifecycleManager extends BroadcastReceiver implements
|
||||
filter = new IntentFilter(Intent.ACTION_USER_UNLOCKED);
|
||||
try {
|
||||
mUserReceiverRegistered.set(true);
|
||||
mBroadcastDispatcher.registerReceiver(this, filter, mHandler, mUser);
|
||||
mBroadcastDispatcher.registerReceiverWithHandler(this, filter, mHandler, mUser);
|
||||
} catch (Exception ex) {
|
||||
mUserReceiverRegistered.set(false);
|
||||
Log.e(TAG, "Could not register unlock receiver", ex);
|
||||
|
||||
@@ -98,7 +98,8 @@ public abstract class CurrentUserTracker {
|
||||
if (!mReceiverRegistered) {
|
||||
mCurrentUserId = ActivityManager.getCurrentUser();
|
||||
IntentFilter filter = new IntentFilter(Intent.ACTION_USER_SWITCHED);
|
||||
mBroadcastDispatcher.registerReceiver(this, filter, null, UserHandle.ALL);
|
||||
mBroadcastDispatcher.registerReceiver(this, filter, null,
|
||||
UserHandle.ALL);
|
||||
mReceiverRegistered = true;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -366,8 +366,8 @@ public class NavigationBarFragment extends LifecycleFragment implements Callback
|
||||
IntentFilter filter = new IntentFilter(Intent.ACTION_SCREEN_OFF);
|
||||
filter.addAction(Intent.ACTION_SCREEN_ON);
|
||||
filter.addAction(Intent.ACTION_USER_SWITCHED);
|
||||
mBroadcastDispatcher.registerReceiver(mBroadcastReceiver, filter, Handler.getMain(),
|
||||
UserHandle.ALL);
|
||||
mBroadcastDispatcher.registerReceiverWithHandler(mBroadcastReceiver, filter,
|
||||
Handler.getMain(), UserHandle.ALL);
|
||||
notifyNavigationBarScreenOn();
|
||||
|
||||
mOverviewProxyService.addCallback(mOverviewProxyListener);
|
||||
|
||||
@@ -179,7 +179,7 @@ public class PhoneStatusBarPolicy
|
||||
filter.addAction(Intent.ACTION_MANAGED_PROFILE_AVAILABLE);
|
||||
filter.addAction(Intent.ACTION_MANAGED_PROFILE_UNAVAILABLE);
|
||||
filter.addAction(Intent.ACTION_MANAGED_PROFILE_REMOVED);
|
||||
broadcastDispatcher.registerReceiver(mIntentReceiver, filter, mHandler);
|
||||
broadcastDispatcher.registerReceiverWithHandler(mIntentReceiver, filter, mHandler);
|
||||
|
||||
// listen for user / profile change.
|
||||
try {
|
||||
|
||||
@@ -188,7 +188,7 @@ public class Clock extends TextView implements DemoMode, Tunable, CommandQueue.C
|
||||
// NOTE: This receiver could run before this method returns, as it's not dispatching
|
||||
// on the main thread and BroadcastDispatcher may not need to register with Context.
|
||||
// The receiver will return immediately if the view does not have a Handler yet.
|
||||
mBroadcastDispatcher.registerReceiver(mIntentReceiver, filter,
|
||||
mBroadcastDispatcher.registerReceiverWithHandler(mIntentReceiver, filter,
|
||||
Dependency.get(Dependency.TIME_TICK_HANDLER), UserHandle.ALL);
|
||||
Dependency.get(TunerService.class).addTunable(this, CLOCK_SECONDS,
|
||||
StatusBarIconController.ICON_BLACKLIST);
|
||||
|
||||
@@ -96,7 +96,7 @@ public class DateView extends TextView {
|
||||
filter.addAction(Intent.ACTION_TIME_CHANGED);
|
||||
filter.addAction(Intent.ACTION_TIMEZONE_CHANGED);
|
||||
filter.addAction(Intent.ACTION_LOCALE_CHANGED);
|
||||
mBroadcastDispatcher.registerReceiver(mIntentReceiver, filter,
|
||||
mBroadcastDispatcher.registerReceiverWithHandler(mIntentReceiver, filter,
|
||||
Dependency.get(Dependency.TIME_TICK_HANDLER));
|
||||
|
||||
updateClock();
|
||||
|
||||
@@ -79,7 +79,8 @@ public class LocationControllerImpl extends BroadcastReceiver implements Locatio
|
||||
IntentFilter filter = new IntentFilter();
|
||||
filter.addAction(LocationManager.HIGH_POWER_REQUEST_CHANGE_ACTION);
|
||||
filter.addAction(LocationManager.MODE_CHANGED_ACTION);
|
||||
mBroadcastDispatcher.registerReceiver(this, filter, new Handler(bgLooper), UserHandle.ALL);
|
||||
mBroadcastDispatcher.registerReceiverWithHandler(this, filter,
|
||||
new Handler(bgLooper), UserHandle.ALL);
|
||||
|
||||
mAppOpsManager = (AppOpsManager) context.getSystemService(Context.APP_OPS_SERVICE);
|
||||
mStatusBarManager
|
||||
|
||||
@@ -326,7 +326,7 @@ public class NetworkControllerImpl extends BroadcastReceiver
|
||||
filter.addAction(ConnectivityManager.INET_CONDITION_ACTION);
|
||||
filter.addAction(Intent.ACTION_AIRPLANE_MODE_CHANGED);
|
||||
filter.addAction(CarrierConfigManager.ACTION_CARRIER_CONFIG_CHANGED);
|
||||
mBroadcastDispatcher.registerReceiver(this, filter, mReceiverHandler);
|
||||
mBroadcastDispatcher.registerReceiverWithHandler(this, filter, mReceiverHandler);
|
||||
mListening = true;
|
||||
|
||||
updateMobileControllers();
|
||||
|
||||
@@ -126,7 +126,8 @@ public class SecurityControllerImpl extends CurrentUserTracker implements Securi
|
||||
IntentFilter filter = new IntentFilter();
|
||||
filter.addAction(KeyChain.ACTION_TRUST_STORE_CHANGED);
|
||||
filter.addAction(Intent.ACTION_USER_UNLOCKED);
|
||||
broadcastDispatcher.registerReceiver(mBroadcastReceiver, filter, bgHandler, UserHandle.ALL);
|
||||
broadcastDispatcher.registerReceiverWithHandler(mBroadcastReceiver, filter, bgHandler,
|
||||
UserHandle.ALL);
|
||||
|
||||
// TODO: re-register network callback on user change.
|
||||
mConnectivityManager.registerNetworkCallback(REQUEST, mNetworkCallback);
|
||||
|
||||
@@ -88,7 +88,7 @@ public class ThemeOverlayController extends SystemUI {
|
||||
final IntentFilter filter = new IntentFilter();
|
||||
filter.addAction(Intent.ACTION_USER_SWITCHED);
|
||||
filter.addAction(Intent.ACTION_MANAGED_PROFILE_ADDED);
|
||||
mBroadcastDispatcher.registerReceiver(new BroadcastReceiver() {
|
||||
mBroadcastDispatcher.registerReceiverWithHandler(new BroadcastReceiver() {
|
||||
@Override
|
||||
public void onReceive(Context context, Intent intent) {
|
||||
if (DEBUG) Log.d(TAG, "Updating overlays for user switch / profile added.");
|
||||
|
||||
@@ -1008,7 +1008,7 @@ public class VolumeDialogControllerImpl implements VolumeDialogController, Dumpa
|
||||
filter.addAction(Intent.ACTION_CONFIGURATION_CHANGED);
|
||||
filter.addAction(Intent.ACTION_SCREEN_OFF);
|
||||
filter.addAction(Intent.ACTION_CLOSE_SYSTEM_DIALOGS);
|
||||
mBroadcastDispatcher.registerReceiver(this, filter, mWorker);
|
||||
mBroadcastDispatcher.registerReceiverWithHandler(this, filter, mWorker);
|
||||
}
|
||||
|
||||
public void destroy() {
|
||||
|
||||
@@ -150,10 +150,10 @@ public class KeyguardUpdateMonitorTest extends SysuiTestCase {
|
||||
|
||||
@Test
|
||||
public void testReceiversRegistered() {
|
||||
verify(mBroadcastDispatcher, atLeastOnce()).registerReceiver(
|
||||
verify(mBroadcastDispatcher, atLeastOnce()).registerReceiverWithHandler(
|
||||
eq(mKeyguardUpdateMonitor.mBroadcastReceiver),
|
||||
any(IntentFilter.class), any(Handler.class));
|
||||
verify(mBroadcastDispatcher, atLeastOnce()).registerReceiver(
|
||||
verify(mBroadcastDispatcher, atLeastOnce()).registerReceiverWithHandler(
|
||||
eq(mKeyguardUpdateMonitor.mBroadcastAllReceiver),
|
||||
any(IntentFilter.class), any(Handler.class), eq(UserHandle.ALL));
|
||||
}
|
||||
|
||||
@@ -27,6 +27,8 @@ import android.test.suitebuilder.annotation.SmallTest
|
||||
import android.testing.AndroidTestingRunner
|
||||
import android.testing.TestableLooper
|
||||
import com.android.systemui.SysuiTestCase
|
||||
import com.android.systemui.util.concurrency.FakeExecutor
|
||||
import com.android.systemui.util.time.FakeSystemClock
|
||||
import junit.framework.Assert.assertSame
|
||||
import org.junit.Before
|
||||
import org.junit.Test
|
||||
@@ -39,6 +41,7 @@ import org.mockito.Mockito.mock
|
||||
import org.mockito.Mockito.never
|
||||
import org.mockito.Mockito.verify
|
||||
import org.mockito.MockitoAnnotations
|
||||
import java.util.concurrent.Executor
|
||||
|
||||
@RunWith(AndroidTestingRunner::class)
|
||||
@TestableLooper.RunWithLooper
|
||||
@@ -73,6 +76,8 @@ class BroadcastDispatcherTest : SysuiTestCase() {
|
||||
@Mock
|
||||
private lateinit var mockHandler: Handler
|
||||
|
||||
private lateinit var executor: Executor
|
||||
|
||||
@Captor
|
||||
private lateinit var argumentCaptor: ArgumentCaptor<ReceiverData>
|
||||
|
||||
@@ -83,6 +88,7 @@ class BroadcastDispatcherTest : SysuiTestCase() {
|
||||
fun setUp() {
|
||||
MockitoAnnotations.initMocks(this)
|
||||
testableLooper = TestableLooper.get(this)
|
||||
executor = FakeExecutor(FakeSystemClock())
|
||||
|
||||
broadcastDispatcher = TestBroadcastDispatcher(
|
||||
mockContext,
|
||||
@@ -98,8 +104,9 @@ class BroadcastDispatcherTest : SysuiTestCase() {
|
||||
|
||||
@Test
|
||||
fun testAddingReceiverToCorrectUBR() {
|
||||
broadcastDispatcher.registerReceiver(broadcastReceiver, intentFilter, mockHandler, user0)
|
||||
broadcastDispatcher.registerReceiver(
|
||||
broadcastDispatcher.registerReceiverWithHandler(broadcastReceiver, intentFilter,
|
||||
mockHandler, user0)
|
||||
broadcastDispatcher.registerReceiverWithHandler(
|
||||
broadcastReceiverOther, intentFilterOther, mockHandler, user1)
|
||||
|
||||
testableLooper.processAllMessages()
|
||||
@@ -114,10 +121,30 @@ class BroadcastDispatcherTest : SysuiTestCase() {
|
||||
assertSame(intentFilterOther, argumentCaptor.value.filter)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun testAddingReceiverToCorrectUBR_executor() {
|
||||
broadcastDispatcher.registerReceiver(broadcastReceiver, intentFilter, executor, user0)
|
||||
broadcastDispatcher.registerReceiver(
|
||||
broadcastReceiverOther, intentFilterOther, executor, user1)
|
||||
|
||||
testableLooper.processAllMessages()
|
||||
|
||||
verify(mockUBRUser0).registerReceiver(capture(argumentCaptor))
|
||||
|
||||
assertSame(broadcastReceiver, argumentCaptor.value.receiver)
|
||||
assertSame(intentFilter, argumentCaptor.value.filter)
|
||||
|
||||
verify(mockUBRUser1).registerReceiver(capture(argumentCaptor))
|
||||
assertSame(broadcastReceiverOther, argumentCaptor.value.receiver)
|
||||
assertSame(intentFilterOther, argumentCaptor.value.filter)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun testRemovingReceiversRemovesFromAllUBR() {
|
||||
broadcastDispatcher.registerReceiver(broadcastReceiver, intentFilter, mockHandler, user0)
|
||||
broadcastDispatcher.registerReceiver(broadcastReceiver, intentFilter, mockHandler, user1)
|
||||
broadcastDispatcher.registerReceiverWithHandler(broadcastReceiver, intentFilter,
|
||||
mockHandler, user0)
|
||||
broadcastDispatcher.registerReceiverWithHandler(broadcastReceiver, intentFilter,
|
||||
mockHandler, user1)
|
||||
|
||||
broadcastDispatcher.unregisterReceiver(broadcastReceiver)
|
||||
|
||||
@@ -129,8 +156,10 @@ class BroadcastDispatcherTest : SysuiTestCase() {
|
||||
|
||||
@Test
|
||||
fun testRemoveReceiverFromUser() {
|
||||
broadcastDispatcher.registerReceiver(broadcastReceiver, intentFilter, mockHandler, user0)
|
||||
broadcastDispatcher.registerReceiver(broadcastReceiver, intentFilter, mockHandler, user1)
|
||||
broadcastDispatcher.registerReceiverWithHandler(broadcastReceiver, intentFilter,
|
||||
mockHandler, user0)
|
||||
broadcastDispatcher.registerReceiverWithHandler(broadcastReceiver, intentFilter,
|
||||
mockHandler, user1)
|
||||
|
||||
broadcastDispatcher.unregisterReceiverForUser(broadcastReceiver, user0)
|
||||
|
||||
@@ -143,8 +172,8 @@ class BroadcastDispatcherTest : SysuiTestCase() {
|
||||
@Test
|
||||
fun testRegisterCurrentAsActualUser() {
|
||||
setUserMock(mockContext, user1)
|
||||
broadcastDispatcher.registerReceiver(broadcastReceiver, intentFilter, mockHandler,
|
||||
UserHandle.CURRENT)
|
||||
broadcastDispatcher.registerReceiverWithHandler(broadcastReceiver, intentFilter,
|
||||
mockHandler, UserHandle.CURRENT)
|
||||
|
||||
testableLooper.processAllMessages()
|
||||
|
||||
|
||||
@@ -26,6 +26,8 @@ import android.test.suitebuilder.annotation.SmallTest
|
||||
import android.testing.AndroidTestingRunner
|
||||
import android.testing.TestableLooper
|
||||
import com.android.systemui.SysuiTestCase
|
||||
import com.android.systemui.util.concurrency.FakeExecutor
|
||||
import com.android.systemui.util.time.FakeSystemClock
|
||||
import junit.framework.Assert.assertEquals
|
||||
import junit.framework.Assert.assertFalse
|
||||
import junit.framework.Assert.assertTrue
|
||||
@@ -69,8 +71,6 @@ class UserBroadcastDispatcherTest : SysuiTestCase() {
|
||||
@Mock
|
||||
private lateinit var mockContext: Context
|
||||
@Mock
|
||||
private lateinit var mockHandler: Handler
|
||||
@Mock
|
||||
private lateinit var mPendingResult: BroadcastReceiver.PendingResult
|
||||
|
||||
@Captor
|
||||
@@ -81,12 +81,14 @@ class UserBroadcastDispatcherTest : SysuiTestCase() {
|
||||
private lateinit var intentFilter: IntentFilter
|
||||
private lateinit var intentFilterOther: IntentFilter
|
||||
private lateinit var handler: Handler
|
||||
private lateinit var fakeExecutor: FakeExecutor
|
||||
|
||||
@Before
|
||||
fun setUp() {
|
||||
MockitoAnnotations.initMocks(this)
|
||||
testableLooper = TestableLooper.get(this)
|
||||
handler = Handler(testableLooper.looper)
|
||||
fakeExecutor = FakeExecutor(FakeSystemClock())
|
||||
|
||||
userBroadcastDispatcher = UserBroadcastDispatcher(
|
||||
mockContext, USER_ID, handler, testableLooper.looper)
|
||||
@@ -108,7 +110,7 @@ class UserBroadcastDispatcherTest : SysuiTestCase() {
|
||||
intentFilter = IntentFilter(ACTION_1)
|
||||
|
||||
userBroadcastDispatcher.registerReceiver(
|
||||
ReceiverData(broadcastReceiver, intentFilter, mockHandler, USER_HANDLE))
|
||||
ReceiverData(broadcastReceiver, intentFilter, fakeExecutor, USER_HANDLE))
|
||||
testableLooper.processAllMessages()
|
||||
|
||||
assertTrue(userBroadcastDispatcher.isRegistered())
|
||||
@@ -128,7 +130,7 @@ class UserBroadcastDispatcherTest : SysuiTestCase() {
|
||||
intentFilter = IntentFilter(ACTION_1)
|
||||
|
||||
userBroadcastDispatcher.registerReceiver(
|
||||
ReceiverData(broadcastReceiver, intentFilter, mockHandler, USER_HANDLE))
|
||||
ReceiverData(broadcastReceiver, intentFilter, fakeExecutor, USER_HANDLE))
|
||||
testableLooper.processAllMessages()
|
||||
reset(mockContext)
|
||||
|
||||
@@ -151,9 +153,9 @@ class UserBroadcastDispatcherTest : SysuiTestCase() {
|
||||
}
|
||||
|
||||
userBroadcastDispatcher.registerReceiver(
|
||||
ReceiverData(broadcastReceiver, intentFilter, mockHandler, USER_HANDLE))
|
||||
ReceiverData(broadcastReceiver, intentFilter, fakeExecutor, USER_HANDLE))
|
||||
userBroadcastDispatcher.registerReceiver(
|
||||
ReceiverData(broadcastReceiverOther, intentFilterOther, mockHandler, USER_HANDLE))
|
||||
ReceiverData(broadcastReceiverOther, intentFilterOther, fakeExecutor, USER_HANDLE))
|
||||
|
||||
testableLooper.processAllMessages()
|
||||
assertTrue(userBroadcastDispatcher.isRegistered())
|
||||
@@ -179,14 +181,15 @@ class UserBroadcastDispatcherTest : SysuiTestCase() {
|
||||
intentFilterOther = IntentFilter(ACTION_2)
|
||||
|
||||
userBroadcastDispatcher.registerReceiver(
|
||||
ReceiverData(broadcastReceiver, intentFilter, handler, USER_HANDLE))
|
||||
ReceiverData(broadcastReceiver, intentFilter, fakeExecutor, USER_HANDLE))
|
||||
userBroadcastDispatcher.registerReceiver(
|
||||
ReceiverData(broadcastReceiverOther, intentFilterOther, handler, USER_HANDLE))
|
||||
ReceiverData(broadcastReceiverOther, intentFilterOther, fakeExecutor, USER_HANDLE))
|
||||
|
||||
val intent = Intent(ACTION_2)
|
||||
|
||||
userBroadcastDispatcher.onReceive(mockContext, intent)
|
||||
testableLooper.processAllMessages()
|
||||
fakeExecutor.runAllReady()
|
||||
|
||||
verify(broadcastReceiver, never()).onReceive(any(), any())
|
||||
verify(broadcastReceiverOther).onReceive(mockContext, intent)
|
||||
@@ -198,14 +201,15 @@ class UserBroadcastDispatcherTest : SysuiTestCase() {
|
||||
intentFilterOther = IntentFilter(ACTION_2)
|
||||
|
||||
userBroadcastDispatcher.registerReceiver(
|
||||
ReceiverData(broadcastReceiver, intentFilter, handler, USER_HANDLE))
|
||||
ReceiverData(broadcastReceiver, intentFilter, fakeExecutor, USER_HANDLE))
|
||||
userBroadcastDispatcher.registerReceiver(
|
||||
ReceiverData(broadcastReceiver, intentFilterOther, handler, USER_HANDLE))
|
||||
ReceiverData(broadcastReceiver, intentFilterOther, fakeExecutor, USER_HANDLE))
|
||||
|
||||
val intent = Intent(ACTION_2)
|
||||
|
||||
userBroadcastDispatcher.onReceive(mockContext, intent)
|
||||
testableLooper.processAllMessages()
|
||||
fakeExecutor.runAllReady()
|
||||
|
||||
verify(broadcastReceiver).onReceive(mockContext, intent)
|
||||
}
|
||||
@@ -218,14 +222,15 @@ class UserBroadcastDispatcherTest : SysuiTestCase() {
|
||||
intentFilterOther.addCategory(CATEGORY_2)
|
||||
|
||||
userBroadcastDispatcher.registerReceiver(
|
||||
ReceiverData(broadcastReceiver, intentFilter, handler, USER_HANDLE))
|
||||
ReceiverData(broadcastReceiver, intentFilter, fakeExecutor, USER_HANDLE))
|
||||
userBroadcastDispatcher.registerReceiver(
|
||||
ReceiverData(broadcastReceiverOther, intentFilterOther, handler, USER_HANDLE))
|
||||
ReceiverData(broadcastReceiverOther, intentFilterOther, fakeExecutor, USER_HANDLE))
|
||||
|
||||
val intent = Intent(ACTION_1)
|
||||
|
||||
userBroadcastDispatcher.onReceive(mockContext, intent)
|
||||
testableLooper.processAllMessages()
|
||||
fakeExecutor.runAllReady()
|
||||
|
||||
verify(broadcastReceiver).onReceive(mockContext, intent)
|
||||
verify(broadcastReceiverOther).onReceive(mockContext, intent)
|
||||
@@ -235,12 +240,13 @@ class UserBroadcastDispatcherTest : SysuiTestCase() {
|
||||
fun testPendingResult() {
|
||||
intentFilter = IntentFilter(ACTION_1)
|
||||
userBroadcastDispatcher.registerReceiver(
|
||||
ReceiverData(broadcastReceiver, intentFilter, handler, USER_HANDLE))
|
||||
ReceiverData(broadcastReceiver, intentFilter, fakeExecutor, USER_HANDLE))
|
||||
|
||||
val intent = Intent(ACTION_1)
|
||||
userBroadcastDispatcher.onReceive(mockContext, intent)
|
||||
|
||||
testableLooper.processAllMessages()
|
||||
fakeExecutor.runAllReady()
|
||||
|
||||
verify(broadcastReceiver).onReceive(mockContext, intent)
|
||||
verify(broadcastReceiver).pendingResult = mPendingResult
|
||||
@@ -250,15 +256,16 @@ class UserBroadcastDispatcherTest : SysuiTestCase() {
|
||||
fun testRemoveReceiverReferences() {
|
||||
intentFilter = IntentFilter(ACTION_1)
|
||||
userBroadcastDispatcher.registerReceiver(
|
||||
ReceiverData(broadcastReceiver, intentFilter, handler, USER_HANDLE))
|
||||
ReceiverData(broadcastReceiver, intentFilter, fakeExecutor, USER_HANDLE))
|
||||
|
||||
intentFilterOther = IntentFilter(ACTION_1)
|
||||
intentFilterOther.addAction(ACTION_2)
|
||||
userBroadcastDispatcher.registerReceiver(
|
||||
ReceiverData(broadcastReceiverOther, intentFilterOther, handler, USER_HANDLE))
|
||||
ReceiverData(broadcastReceiverOther, intentFilterOther, fakeExecutor, USER_HANDLE))
|
||||
|
||||
userBroadcastDispatcher.unregisterReceiver(broadcastReceiver)
|
||||
testableLooper.processAllMessages()
|
||||
fakeExecutor.runAllReady()
|
||||
|
||||
assertFalse(userBroadcastDispatcher.isReceiverReferenceHeld(broadcastReceiver))
|
||||
}
|
||||
|
||||
@@ -110,7 +110,7 @@ public class PowerUITest extends SysuiTestCase {
|
||||
@Test
|
||||
public void testReceiverIsRegisteredToDispatcherOnStart() {
|
||||
mPowerUI.start();
|
||||
verify(mBroadcastDispatcher).registerReceiver(
|
||||
verify(mBroadcastDispatcher).registerReceiverWithHandler(
|
||||
any(BroadcastReceiver.class),
|
||||
any(IntentFilter.class),
|
||||
any(Handler.class)); //PowerUI does not call with User
|
||||
|
||||
@@ -190,7 +190,7 @@ public class NavigationBarFragmentTest extends SysuiBaseFragmentTest {
|
||||
mFragments.dispatchResume();
|
||||
processAllMessages();
|
||||
|
||||
verify(mBroadcastDispatcher).registerReceiver(
|
||||
verify(mBroadcastDispatcher).registerReceiverWithHandler(
|
||||
any(BroadcastReceiver.class),
|
||||
any(IntentFilter.class),
|
||||
any(Handler.class),
|
||||
|
||||
@@ -69,7 +69,7 @@ public class VolumeDialogControllerImplTest extends SysuiTestCase {
|
||||
|
||||
@Test
|
||||
public void testRegisteredWithDispatcher() {
|
||||
verify(mBroadcastDispatcher).registerReceiver(any(BroadcastReceiver.class),
|
||||
verify(mBroadcastDispatcher).registerReceiverWithHandler(any(BroadcastReceiver.class),
|
||||
any(IntentFilter.class),
|
||||
any(Handler.class)); // VolumeDialogControllerImpl does not call with user
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user