Theo kinh nghiệm làm việc của mình với AOSP 9.0.0_r35 thì không có một danh sách nào định nghĩa implicit broadcast exceptions trong AOSP source code cả bạn nhé.
Theo mặc định sẽ không được gửi đén cho các app đang ở trạng thái stop (tham khảo code trong file
ActivityManagerService.java, function
broadcastIntentLocked)
final int broadcastIntentLocked(ProcessRecord callerApp,
String callerPackage, Intent intent, String resolvedType,
IIntentReceiver resultTo, int resultCode, String resultData,
Bundle resultExtras, String[] requiredPermissions, int appOp, Bundle bOptions,
boolean ordered, boolean sticky, int callingPid, int callingUid, int userId) {
intent = new Intent(intent);
...
// By default broadcasts do not go to stopped apps.
intent.addFlags(Intent.FLAG_EXCLUDE_STOPPED_PACKAGES);
...
}
Đối với các
implicit broadcast exceptions, trong code của AOSP thì nó sẽ hardcode để sử dụng flag
Intent.FLAG_RECEIVER_INCLUDE_BACKGROUND
hoặc
Intent.FLAG_INCLUDE_STOPPED_PACKAGES
khi broadcast intent được gửi đi. Những flags được định nghĩa trong file
Intent.java như sau
/**
* If set, this intent will always match any components in packages that
* are currently stopped. This is the default behavior when
* {@link #FLAG_EXCLUDE_STOPPED_PACKAGES} is not set. If both of these
* flags are set, this one wins (it allows overriding of exclude for
* places where the framework may automatically set the exclude flag).
*/
public static final int FLAG_INCLUDE_STOPPED_PACKAGES = 0x00000020;
/**
* If set, the broadcast will always go to manifest receivers in background (cached
* or not running) apps, regardless of whether that would be done by default. By
* default they will only receive broadcasts if the broadcast has specified an
* explicit component or package name.
*
* NOTE: dumpstate uses this flag numerically, so when its value is changed
* the broadcast code there must also be changed to match.
*
* @hide
*/
public static final int FLAG_RECEIVER_INCLUDE_BACKGROUND = 0x01000000;
Vì dụ với trường hợp của ACTION_TIMEZONE_CHANGED
, nó được gửi đi trong AlarmManagerService.java như sau
Intent intent = new Intent(Intent.ACTION_TIMEZONE_CHANGED);
intent.addFlags(Intent.FLAG_RECEIVER_REPLACE_PENDING
| Intent.FLAG_RECEIVER_INCLUDE_BACKGROUND
| Intent.FLAG_RECEIVER_VISIBLE_TO_INSTANT_APPS);
intent.putExtra("time-zone", zone.getID());
getContext().sendBroadcastAsUser(intent, UserHandle.ALL);