Loading core/java/android/content/IntentFilter.java +22 −0 Original line number Diff line number Diff line Loading @@ -531,6 +531,28 @@ public class IntentFilter implements Parcelable { mInstantAppVisibility = o.mInstantAppVisibility; } /** {@inheritDoc} */ public String toString() { final StringBuilder sb = new StringBuilder(); sb.append("IntentFilter {"); sb.append(" pri="); sb.append(mPriority); if (countActions() > 0) { sb.append(" act="); sb.append(mActions.toString()); } if (countCategories() > 0) { sb.append(" cat="); sb.append(mCategories.toString()); } if (countDataSchemes() > 0) { sb.append(" sch="); sb.append(mDataSchemes.toString()); } sb.append(" }"); return sb.toString(); } /** * Modify priority of this filter. This only affects receiver filters. * The priority of activity filters are set in XML and cannot be changed Loading core/java/android/content/pm/RegisteredServicesCache.java +11 −0 Original line number Diff line number Diff line Loading @@ -157,11 +157,16 @@ public abstract class RegisteredServicesCache<V> { migrateIfNecessaryLocked(); final boolean isCore = UserHandle.isCore(android.os.Process.myUid()); IntentFilter intentFilter = new IntentFilter(); intentFilter.addAction(Intent.ACTION_PACKAGE_ADDED); intentFilter.addAction(Intent.ACTION_PACKAGE_CHANGED); intentFilter.addAction(Intent.ACTION_PACKAGE_REMOVED); intentFilter.addDataScheme("package"); if (isCore) { intentFilter.setPriority(IntentFilter.SYSTEM_HIGH_PRIORITY); } Handler handler = BackgroundThread.getHandler(); mContext.registerReceiverAsUser( mPackageReceiver, UserHandle.ALL, intentFilter, null, handler); Loading @@ -170,11 +175,17 @@ public abstract class RegisteredServicesCache<V> { IntentFilter sdFilter = new IntentFilter(); sdFilter.addAction(Intent.ACTION_EXTERNAL_APPLICATIONS_AVAILABLE); sdFilter.addAction(Intent.ACTION_EXTERNAL_APPLICATIONS_UNAVAILABLE); if (isCore) { sdFilter.setPriority(IntentFilter.SYSTEM_HIGH_PRIORITY); } mContext.registerReceiver(mExternalReceiver, sdFilter, null, handler); // Register for user-related events IntentFilter userFilter = new IntentFilter(); userFilter.addAction(Intent.ACTION_USER_REMOVED); if (isCore) { userFilter.setPriority(IntentFilter.SYSTEM_HIGH_PRIORITY); } mContext.registerReceiver(mUserRemovedReceiver, userFilter, null, handler); } Loading core/java/com/android/internal/content/PackageMonitor.java +40 −26 Original line number Diff line number Diff line Loading @@ -39,25 +39,10 @@ import java.util.Objects; */ public abstract class PackageMonitor extends android.content.BroadcastReceiver { static final String TAG = "PackageMonitor"; static final IntentFilter sPackageFilt = new IntentFilter(); static final IntentFilter sNonDataFilt = new IntentFilter(); static final IntentFilter sExternalFilt = new IntentFilter(); static { sPackageFilt.addAction(Intent.ACTION_PACKAGE_ADDED); sPackageFilt.addAction(Intent.ACTION_PACKAGE_REMOVED); sPackageFilt.addAction(Intent.ACTION_PACKAGE_CHANGED); sPackageFilt.addAction(Intent.ACTION_QUERY_PACKAGE_RESTART); sPackageFilt.addAction(Intent.ACTION_PACKAGE_RESTARTED); sPackageFilt.addAction(Intent.ACTION_PACKAGE_DATA_CLEARED); sPackageFilt.addDataScheme("package"); sNonDataFilt.addAction(Intent.ACTION_UID_REMOVED); sNonDataFilt.addAction(Intent.ACTION_USER_STOPPED); sNonDataFilt.addAction(Intent.ACTION_PACKAGES_SUSPENDED); sNonDataFilt.addAction(Intent.ACTION_PACKAGES_UNSUSPENDED); sExternalFilt.addAction(Intent.ACTION_EXTERNAL_APPLICATIONS_AVAILABLE); sExternalFilt.addAction(Intent.ACTION_EXTERNAL_APPLICATIONS_UNAVAILABLE); } final IntentFilter mPackageFilt; final IntentFilter mNonDataFilt; final IntentFilter mExternalFilt; final HashSet<String> mUpdatingPackages = new HashSet<String>(); Loading @@ -75,6 +60,35 @@ public abstract class PackageMonitor extends android.content.BroadcastReceiver { @UnsupportedAppUsage public PackageMonitor() { final boolean isCore = UserHandle.isCore(android.os.Process.myUid()); mPackageFilt = new IntentFilter(); mPackageFilt.addAction(Intent.ACTION_PACKAGE_ADDED); mPackageFilt.addAction(Intent.ACTION_PACKAGE_REMOVED); mPackageFilt.addAction(Intent.ACTION_PACKAGE_CHANGED); mPackageFilt.addAction(Intent.ACTION_QUERY_PACKAGE_RESTART); mPackageFilt.addAction(Intent.ACTION_PACKAGE_RESTARTED); mPackageFilt.addAction(Intent.ACTION_PACKAGE_DATA_CLEARED); mPackageFilt.addDataScheme("package"); if (isCore) { mPackageFilt.setPriority(IntentFilter.SYSTEM_HIGH_PRIORITY); } mNonDataFilt = new IntentFilter(); mNonDataFilt.addAction(Intent.ACTION_UID_REMOVED); mNonDataFilt.addAction(Intent.ACTION_USER_STOPPED); mNonDataFilt.addAction(Intent.ACTION_PACKAGES_SUSPENDED); mNonDataFilt.addAction(Intent.ACTION_PACKAGES_UNSUSPENDED); if (isCore) { mNonDataFilt.setPriority(IntentFilter.SYSTEM_HIGH_PRIORITY); } mExternalFilt = new IntentFilter(); mExternalFilt.addAction(Intent.ACTION_EXTERNAL_APPLICATIONS_AVAILABLE); mExternalFilt.addAction(Intent.ACTION_EXTERNAL_APPLICATIONS_UNAVAILABLE); if (isCore) { mExternalFilt.setPriority(IntentFilter.SYSTEM_HIGH_PRIORITY); } } @UnsupportedAppUsage Loading @@ -97,17 +111,17 @@ public abstract class PackageMonitor extends android.content.BroadcastReceiver { mRegisteredContext = context; mRegisteredHandler = Objects.requireNonNull(handler); if (user != null) { context.registerReceiverAsUser(this, user, sPackageFilt, null, mRegisteredHandler); context.registerReceiverAsUser(this, user, sNonDataFilt, null, mRegisteredHandler); context.registerReceiverAsUser(this, user, mPackageFilt, null, mRegisteredHandler); context.registerReceiverAsUser(this, user, mNonDataFilt, null, mRegisteredHandler); if (externalStorage) { context.registerReceiverAsUser(this, user, sExternalFilt, null, context.registerReceiverAsUser(this, user, mExternalFilt, null, mRegisteredHandler); } } else { context.registerReceiver(this, sPackageFilt, null, mRegisteredHandler); context.registerReceiver(this, sNonDataFilt, null, mRegisteredHandler); context.registerReceiver(this, mPackageFilt, null, mRegisteredHandler); context.registerReceiver(this, mNonDataFilt, null, mRegisteredHandler); if (externalStorage) { context.registerReceiver(this, sExternalFilt, null, mRegisteredHandler); context.registerReceiver(this, mExternalFilt, null, mRegisteredHandler); } } } Loading services/core/java/com/android/server/am/ActivityManagerService.java +34 −0 Original line number Diff line number Diff line Loading @@ -13755,6 +13755,40 @@ public class ActivityManagerService extends IActivityManager.Stub userId = mUserController.handleIncomingUser(callingPid, callingUid, userId, true, ALLOW_FULL_ONLY, "registerReceiver", callerPackage); // Warn if system internals are registering for important broadcasts // without also using a priority to ensure they process the event // before normal apps hear about it if (UserHandle.isCore(callingUid)) { final int priority = filter.getPriority(); final boolean systemPriority = (priority >= IntentFilter.SYSTEM_HIGH_PRIORITY) || (priority <= IntentFilter.SYSTEM_LOW_PRIORITY); if (!systemPriority) { final int N = filter.countActions(); for (int i = 0; i < N; i++) { // TODO: expand to additional important broadcasts over time final String action = filter.getAction(i); if (action.startsWith("android.intent.action.USER_") || action.startsWith("android.intent.action.PACKAGE_") || action.startsWith("android.intent.action.UID_") || action.startsWith("android.intent.action.EXTERNAL_")) { if (DEBUG_BROADCAST) { Slog.wtf(TAG, "System internals registering for " + filter + " with app priority; this will race with apps!", new Throwable()); } // When undefined, assume that system internals need // to hear about the event first; they can use // SYSTEM_LOW_PRIORITY if they need to hear last if (priority == 0) { filter.setPriority(IntentFilter.SYSTEM_HIGH_PRIORITY); } break; } } } } Iterator<String> actions = filter.actionsIterator(); if (actions == null) { ArrayList<String> noAction = new ArrayList<String>(1); services/core/java/com/android/server/content/SyncManager.java +1 −1 Original line number Diff line number Diff line Loading @@ -690,7 +690,7 @@ public class SyncManager { context.registerReceiver(mConnectivityIntentReceiver, intentFilter); intentFilter = new IntentFilter(Intent.ACTION_SHUTDOWN); intentFilter.setPriority(100); intentFilter.setPriority(IntentFilter.SYSTEM_HIGH_PRIORITY); context.registerReceiver(mShutdownIntentReceiver, intentFilter); intentFilter = new IntentFilter(); Loading Loading
core/java/android/content/IntentFilter.java +22 −0 Original line number Diff line number Diff line Loading @@ -531,6 +531,28 @@ public class IntentFilter implements Parcelable { mInstantAppVisibility = o.mInstantAppVisibility; } /** {@inheritDoc} */ public String toString() { final StringBuilder sb = new StringBuilder(); sb.append("IntentFilter {"); sb.append(" pri="); sb.append(mPriority); if (countActions() > 0) { sb.append(" act="); sb.append(mActions.toString()); } if (countCategories() > 0) { sb.append(" cat="); sb.append(mCategories.toString()); } if (countDataSchemes() > 0) { sb.append(" sch="); sb.append(mDataSchemes.toString()); } sb.append(" }"); return sb.toString(); } /** * Modify priority of this filter. This only affects receiver filters. * The priority of activity filters are set in XML and cannot be changed Loading
core/java/android/content/pm/RegisteredServicesCache.java +11 −0 Original line number Diff line number Diff line Loading @@ -157,11 +157,16 @@ public abstract class RegisteredServicesCache<V> { migrateIfNecessaryLocked(); final boolean isCore = UserHandle.isCore(android.os.Process.myUid()); IntentFilter intentFilter = new IntentFilter(); intentFilter.addAction(Intent.ACTION_PACKAGE_ADDED); intentFilter.addAction(Intent.ACTION_PACKAGE_CHANGED); intentFilter.addAction(Intent.ACTION_PACKAGE_REMOVED); intentFilter.addDataScheme("package"); if (isCore) { intentFilter.setPriority(IntentFilter.SYSTEM_HIGH_PRIORITY); } Handler handler = BackgroundThread.getHandler(); mContext.registerReceiverAsUser( mPackageReceiver, UserHandle.ALL, intentFilter, null, handler); Loading @@ -170,11 +175,17 @@ public abstract class RegisteredServicesCache<V> { IntentFilter sdFilter = new IntentFilter(); sdFilter.addAction(Intent.ACTION_EXTERNAL_APPLICATIONS_AVAILABLE); sdFilter.addAction(Intent.ACTION_EXTERNAL_APPLICATIONS_UNAVAILABLE); if (isCore) { sdFilter.setPriority(IntentFilter.SYSTEM_HIGH_PRIORITY); } mContext.registerReceiver(mExternalReceiver, sdFilter, null, handler); // Register for user-related events IntentFilter userFilter = new IntentFilter(); userFilter.addAction(Intent.ACTION_USER_REMOVED); if (isCore) { userFilter.setPriority(IntentFilter.SYSTEM_HIGH_PRIORITY); } mContext.registerReceiver(mUserRemovedReceiver, userFilter, null, handler); } Loading
core/java/com/android/internal/content/PackageMonitor.java +40 −26 Original line number Diff line number Diff line Loading @@ -39,25 +39,10 @@ import java.util.Objects; */ public abstract class PackageMonitor extends android.content.BroadcastReceiver { static final String TAG = "PackageMonitor"; static final IntentFilter sPackageFilt = new IntentFilter(); static final IntentFilter sNonDataFilt = new IntentFilter(); static final IntentFilter sExternalFilt = new IntentFilter(); static { sPackageFilt.addAction(Intent.ACTION_PACKAGE_ADDED); sPackageFilt.addAction(Intent.ACTION_PACKAGE_REMOVED); sPackageFilt.addAction(Intent.ACTION_PACKAGE_CHANGED); sPackageFilt.addAction(Intent.ACTION_QUERY_PACKAGE_RESTART); sPackageFilt.addAction(Intent.ACTION_PACKAGE_RESTARTED); sPackageFilt.addAction(Intent.ACTION_PACKAGE_DATA_CLEARED); sPackageFilt.addDataScheme("package"); sNonDataFilt.addAction(Intent.ACTION_UID_REMOVED); sNonDataFilt.addAction(Intent.ACTION_USER_STOPPED); sNonDataFilt.addAction(Intent.ACTION_PACKAGES_SUSPENDED); sNonDataFilt.addAction(Intent.ACTION_PACKAGES_UNSUSPENDED); sExternalFilt.addAction(Intent.ACTION_EXTERNAL_APPLICATIONS_AVAILABLE); sExternalFilt.addAction(Intent.ACTION_EXTERNAL_APPLICATIONS_UNAVAILABLE); } final IntentFilter mPackageFilt; final IntentFilter mNonDataFilt; final IntentFilter mExternalFilt; final HashSet<String> mUpdatingPackages = new HashSet<String>(); Loading @@ -75,6 +60,35 @@ public abstract class PackageMonitor extends android.content.BroadcastReceiver { @UnsupportedAppUsage public PackageMonitor() { final boolean isCore = UserHandle.isCore(android.os.Process.myUid()); mPackageFilt = new IntentFilter(); mPackageFilt.addAction(Intent.ACTION_PACKAGE_ADDED); mPackageFilt.addAction(Intent.ACTION_PACKAGE_REMOVED); mPackageFilt.addAction(Intent.ACTION_PACKAGE_CHANGED); mPackageFilt.addAction(Intent.ACTION_QUERY_PACKAGE_RESTART); mPackageFilt.addAction(Intent.ACTION_PACKAGE_RESTARTED); mPackageFilt.addAction(Intent.ACTION_PACKAGE_DATA_CLEARED); mPackageFilt.addDataScheme("package"); if (isCore) { mPackageFilt.setPriority(IntentFilter.SYSTEM_HIGH_PRIORITY); } mNonDataFilt = new IntentFilter(); mNonDataFilt.addAction(Intent.ACTION_UID_REMOVED); mNonDataFilt.addAction(Intent.ACTION_USER_STOPPED); mNonDataFilt.addAction(Intent.ACTION_PACKAGES_SUSPENDED); mNonDataFilt.addAction(Intent.ACTION_PACKAGES_UNSUSPENDED); if (isCore) { mNonDataFilt.setPriority(IntentFilter.SYSTEM_HIGH_PRIORITY); } mExternalFilt = new IntentFilter(); mExternalFilt.addAction(Intent.ACTION_EXTERNAL_APPLICATIONS_AVAILABLE); mExternalFilt.addAction(Intent.ACTION_EXTERNAL_APPLICATIONS_UNAVAILABLE); if (isCore) { mExternalFilt.setPriority(IntentFilter.SYSTEM_HIGH_PRIORITY); } } @UnsupportedAppUsage Loading @@ -97,17 +111,17 @@ public abstract class PackageMonitor extends android.content.BroadcastReceiver { mRegisteredContext = context; mRegisteredHandler = Objects.requireNonNull(handler); if (user != null) { context.registerReceiverAsUser(this, user, sPackageFilt, null, mRegisteredHandler); context.registerReceiverAsUser(this, user, sNonDataFilt, null, mRegisteredHandler); context.registerReceiverAsUser(this, user, mPackageFilt, null, mRegisteredHandler); context.registerReceiverAsUser(this, user, mNonDataFilt, null, mRegisteredHandler); if (externalStorage) { context.registerReceiverAsUser(this, user, sExternalFilt, null, context.registerReceiverAsUser(this, user, mExternalFilt, null, mRegisteredHandler); } } else { context.registerReceiver(this, sPackageFilt, null, mRegisteredHandler); context.registerReceiver(this, sNonDataFilt, null, mRegisteredHandler); context.registerReceiver(this, mPackageFilt, null, mRegisteredHandler); context.registerReceiver(this, mNonDataFilt, null, mRegisteredHandler); if (externalStorage) { context.registerReceiver(this, sExternalFilt, null, mRegisteredHandler); context.registerReceiver(this, mExternalFilt, null, mRegisteredHandler); } } } Loading
services/core/java/com/android/server/am/ActivityManagerService.java +34 −0 Original line number Diff line number Diff line Loading @@ -13755,6 +13755,40 @@ public class ActivityManagerService extends IActivityManager.Stub userId = mUserController.handleIncomingUser(callingPid, callingUid, userId, true, ALLOW_FULL_ONLY, "registerReceiver", callerPackage); // Warn if system internals are registering for important broadcasts // without also using a priority to ensure they process the event // before normal apps hear about it if (UserHandle.isCore(callingUid)) { final int priority = filter.getPriority(); final boolean systemPriority = (priority >= IntentFilter.SYSTEM_HIGH_PRIORITY) || (priority <= IntentFilter.SYSTEM_LOW_PRIORITY); if (!systemPriority) { final int N = filter.countActions(); for (int i = 0; i < N; i++) { // TODO: expand to additional important broadcasts over time final String action = filter.getAction(i); if (action.startsWith("android.intent.action.USER_") || action.startsWith("android.intent.action.PACKAGE_") || action.startsWith("android.intent.action.UID_") || action.startsWith("android.intent.action.EXTERNAL_")) { if (DEBUG_BROADCAST) { Slog.wtf(TAG, "System internals registering for " + filter + " with app priority; this will race with apps!", new Throwable()); } // When undefined, assume that system internals need // to hear about the event first; they can use // SYSTEM_LOW_PRIORITY if they need to hear last if (priority == 0) { filter.setPriority(IntentFilter.SYSTEM_HIGH_PRIORITY); } break; } } } } Iterator<String> actions = filter.actionsIterator(); if (actions == null) { ArrayList<String> noAction = new ArrayList<String>(1);
services/core/java/com/android/server/content/SyncManager.java +1 −1 Original line number Diff line number Diff line Loading @@ -690,7 +690,7 @@ public class SyncManager { context.registerReceiver(mConnectivityIntentReceiver, intentFilter); intentFilter = new IntentFilter(Intent.ACTION_SHUTDOWN); intentFilter.setPriority(100); intentFilter.setPriority(IntentFilter.SYSTEM_HIGH_PRIORITY); context.registerReceiver(mShutdownIntentReceiver, intentFilter); intentFilter = new IntentFilter(); Loading