Override registerReceiver methods in test Context to accept flags
The BroadcastInterceptingContext allows a broadcast Intent to be intercepted in the local process and sent directly to the receiver's onReceive method. This commit updates this class to also override the registerReceiver methods that accept the flags parameter to ensure broadcasts can be sent to receivers registering with flags during tests. Bug: 234659204 Test: atest com.android.networkstack.tethering.EntitlementManagerTest Change-Id: I9366ed1a3eb5f370b93e72981abac535f675a2bb
This commit is contained in:
@@ -147,12 +147,39 @@ public class BroadcastInterceptingContext extends ContextWrapper {
|
||||
|
||||
@Override
|
||||
public Intent registerReceiver(BroadcastReceiver receiver, IntentFilter filter) {
|
||||
return registerReceiver(receiver, filter, null, null);
|
||||
return registerReceiver(receiver, filter, null, null, 0);
|
||||
}
|
||||
|
||||
/**
|
||||
* Registers the specified {@code receiver} to listen for broadcasts that match the {@code
|
||||
* filter} in the current process.
|
||||
*
|
||||
* <p>Since this method only listens for broadcasts in the current process, the provided {@code
|
||||
* flags} are ignored; this method is primarily intended to allow receivers that register with
|
||||
* flags to register in the current process during tests.
|
||||
*/
|
||||
@Override
|
||||
public Intent registerReceiver(BroadcastReceiver receiver, IntentFilter filter, int flags) {
|
||||
return registerReceiver(receiver, filter, null, null, flags);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Intent registerReceiver(BroadcastReceiver receiver, IntentFilter filter,
|
||||
String broadcastPermission, Handler scheduler) {
|
||||
return registerReceiver(receiver, filter, broadcastPermission, scheduler, 0);
|
||||
}
|
||||
|
||||
/**
|
||||
* Registers the specified {@code receiver} to listen for broadcasts that match the {@code
|
||||
* filter} to run in the context of the specified {@code scheduler} in the current process.
|
||||
*
|
||||
* <p>Since this method only listens for broadcasts in the current process, the provided {@code
|
||||
* flags} are ignored; this method is primarily intended to allow receivers that register with
|
||||
* flags to register in the current process during tests.
|
||||
*/
|
||||
@Override
|
||||
public Intent registerReceiver(BroadcastReceiver receiver, IntentFilter filter,
|
||||
String broadcastPermission, Handler scheduler, int flags) {
|
||||
synchronized (mInterceptors) {
|
||||
mInterceptors.add(new BroadcastInterceptor(receiver, filter, scheduler));
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user