Loading services/core/java/com/android/server/am/BroadcastController.java +1 −1 Original line number Diff line number Diff line Loading @@ -553,7 +553,7 @@ class BroadcastController { } BroadcastFilter bf = new BroadcastFilter(filter, rl, callerPackage, callerFeatureId, receiverId, permission, callingUid, userId, instantApp, visibleToInstantApps, exported, mService.mPlatformCompat); exported, callerApp.info, mService.mPlatformCompat); if (rl.containsFilter(filter)) { Slog.w(TAG, "Receiver with filter " + filter + " already registered for pid " + rl.pid Loading services/core/java/com/android/server/am/BroadcastFilter.java +14 −6 Original line number Diff line number Diff line Loading @@ -20,6 +20,8 @@ import android.annotation.Nullable; import android.compat.annotation.ChangeId; import android.compat.annotation.EnabledSince; import android.content.IntentFilter; import android.content.pm.ApplicationInfo; import android.os.Binder; import android.os.UserHandle; import android.util.PrintWriterPrinter; import android.util.Printer; Loading Loading @@ -58,7 +60,7 @@ public final class BroadcastFilter extends IntentFilter { BroadcastFilter(IntentFilter _filter, ReceiverList _receiverList, String _packageName, String _featureId, String _receiverId, String _requiredPermission, int _owningUid, int _userId, boolean _instantApp, boolean _visibleToInstantApp, boolean _exported, PlatformCompat platformCompat) { boolean _exported, ApplicationInfo applicationInfo, PlatformCompat platformCompat) { super(_filter); receiverList = _receiverList; packageName = _packageName; Loading @@ -71,7 +73,8 @@ public final class BroadcastFilter extends IntentFilter { visibleToInstantApp = _visibleToInstantApp; exported = _exported; initialPriority = getPriority(); setPriority(calculateAdjustedPriority(owningUid, initialPriority, platformCompat)); setPriority(calculateAdjustedPriority(owningUid, initialPriority, applicationInfo, platformCompat)); } public @Nullable String getReceiverClassName() { Loading Loading @@ -125,14 +128,19 @@ public final class BroadcastFilter extends IntentFilter { @VisibleForTesting static int calculateAdjustedPriority(int owningUid, int priority, PlatformCompat platformCompat) { ApplicationInfo applicationInfo, PlatformCompat platformCompat) { if (!Flags.restrictPriorityValues()) { return priority; } if (!platformCompat.isChangeEnabledByUidInternalNoLogging( RESTRICT_PRIORITY_VALUES, owningUid)) { final long token = Binder.clearCallingIdentity(); try { if (!platformCompat.isChangeEnabledInternalNoLogging( RESTRICT_PRIORITY_VALUES, applicationInfo)) { return priority; } } finally { Binder.restoreCallingIdentity(token); } if (!UserHandle.isCore(owningUid)) { if (priority >= SYSTEM_HIGH_PRIORITY) { return SYSTEM_HIGH_PRIORITY - 1; Loading services/tests/mockingservicestests/src/com/android/server/am/BaseBroadcastQueueTest.java +3 −3 Original line number Diff line number Diff line Loading @@ -185,8 +185,8 @@ public abstract class BaseBroadcastQueueTest { doReturn(mAppStartInfoTracker).when(mProcessList).getAppStartInfoTracker(); doReturn(true).when(mPlatformCompat).isChangeEnabledByUidInternalNoLogging( eq(BroadcastFilter.RESTRICT_PRIORITY_VALUES), anyInt()); doReturn(true).when(mPlatformCompat).isChangeEnabledInternalNoLogging( eq(BroadcastFilter.RESTRICT_PRIORITY_VALUES), any(ApplicationInfo.class)); doReturn(true).when(mPlatformCompat).isChangeEnabledByUidInternalNoLogging( eq(BroadcastRecord.LIMIT_PRIORITY_SCOPE), anyInt()); } Loading Loading @@ -298,7 +298,7 @@ public abstract class BaseBroadcastQueueTest { filter.setPriority(priority); final BroadcastFilter res = new BroadcastFilter(filter, receiverList, receiverList.app.info.packageName, null, null, null, receiverList.uid, receiverList.userId, false, false, true, receiverList.userId, false, false, true, receiverList.app.info, mock(PlatformCompat.class)); receiverList.add(res); return res; Loading services/tests/mockingservicestests/src/com/android/server/am/BroadcastFilterTest.java +10 −9 Original line number Diff line number Diff line Loading @@ -20,10 +20,13 @@ import static android.content.IntentFilter.SYSTEM_LOW_PRIORITY; import static com.google.common.truth.Truth.assertWithMessage; import static org.mockito.ArgumentMatchers.any; import static org.mockito.ArgumentMatchers.anyInt; import static org.mockito.ArgumentMatchers.eq; import static org.mockito.Mockito.doReturn; import static org.mockito.Mockito.mock; import android.content.pm.ApplicationInfo; import android.os.Process; import android.platform.test.annotations.DisableFlags; import android.platform.test.annotations.EnableFlags; Loading Loading @@ -53,14 +56,14 @@ public class BroadcastFilterTest { @Before public void setUp() { MockitoAnnotations.initMocks(this); doReturn(true).when(mPlatformCompat).isChangeEnabledInternalNoLogging( eq(BroadcastFilter.RESTRICT_PRIORITY_VALUES), any(ApplicationInfo.class)); } @Test @EnableFlags(Flags.FLAG_RESTRICT_PRIORITY_VALUES) public void testCalculateAdjustedPriority() { doReturn(true).when(mPlatformCompat).isChangeEnabledByUidInternalNoLogging( eq(BroadcastFilter.RESTRICT_PRIORITY_VALUES), anyInt()); { // Pairs of {initial-priority, expected-adjusted-priority} final Pair<Integer, Integer>[] priorities = new Pair[] { Loading Loading @@ -95,8 +98,8 @@ public class BroadcastFilterTest { @Test @EnableFlags(Flags.FLAG_RESTRICT_PRIORITY_VALUES) public void testCalculateAdjustedPriority_withChangeIdDisabled() { doReturn(false).when(mPlatformCompat).isChangeEnabledByUidInternalNoLogging( eq(BroadcastFilter.RESTRICT_PRIORITY_VALUES), anyInt()); doReturn(false).when(mPlatformCompat).isChangeEnabledInternalNoLogging( eq(BroadcastFilter.RESTRICT_PRIORITY_VALUES), any(ApplicationInfo.class)); { // Pairs of {initial-priority, expected-adjusted-priority} Loading Loading @@ -132,9 +135,6 @@ public class BroadcastFilterTest { @Test @DisableFlags(Flags.FLAG_RESTRICT_PRIORITY_VALUES) public void testCalculateAdjustedPriority_withFlagDisabled() { doReturn(true).when(mPlatformCompat).isChangeEnabledByUidInternalNoLogging( eq(BroadcastFilter.RESTRICT_PRIORITY_VALUES), anyInt()); { // Pairs of {initial-priority, expected-adjusted-priority} final Pair<Integer, Integer>[] priorities = new Pair[] { Loading Loading @@ -215,6 +215,7 @@ public class BroadcastFilterTest { final String errorMsg = String.format("owner=%d; actualPriority=%d; expectedPriority=%d", owningUid, priority, expectedAdjustedPriority); assertWithMessage(errorMsg).that(BroadcastFilter.calculateAdjustedPriority( owningUid, priority, mPlatformCompat)).isEqualTo(expectedAdjustedPriority); owningUid, priority, mock(ApplicationInfo.class), mPlatformCompat)) .isEqualTo(expectedAdjustedPriority); } } Loading
services/core/java/com/android/server/am/BroadcastController.java +1 −1 Original line number Diff line number Diff line Loading @@ -553,7 +553,7 @@ class BroadcastController { } BroadcastFilter bf = new BroadcastFilter(filter, rl, callerPackage, callerFeatureId, receiverId, permission, callingUid, userId, instantApp, visibleToInstantApps, exported, mService.mPlatformCompat); exported, callerApp.info, mService.mPlatformCompat); if (rl.containsFilter(filter)) { Slog.w(TAG, "Receiver with filter " + filter + " already registered for pid " + rl.pid Loading
services/core/java/com/android/server/am/BroadcastFilter.java +14 −6 Original line number Diff line number Diff line Loading @@ -20,6 +20,8 @@ import android.annotation.Nullable; import android.compat.annotation.ChangeId; import android.compat.annotation.EnabledSince; import android.content.IntentFilter; import android.content.pm.ApplicationInfo; import android.os.Binder; import android.os.UserHandle; import android.util.PrintWriterPrinter; import android.util.Printer; Loading Loading @@ -58,7 +60,7 @@ public final class BroadcastFilter extends IntentFilter { BroadcastFilter(IntentFilter _filter, ReceiverList _receiverList, String _packageName, String _featureId, String _receiverId, String _requiredPermission, int _owningUid, int _userId, boolean _instantApp, boolean _visibleToInstantApp, boolean _exported, PlatformCompat platformCompat) { boolean _exported, ApplicationInfo applicationInfo, PlatformCompat platformCompat) { super(_filter); receiverList = _receiverList; packageName = _packageName; Loading @@ -71,7 +73,8 @@ public final class BroadcastFilter extends IntentFilter { visibleToInstantApp = _visibleToInstantApp; exported = _exported; initialPriority = getPriority(); setPriority(calculateAdjustedPriority(owningUid, initialPriority, platformCompat)); setPriority(calculateAdjustedPriority(owningUid, initialPriority, applicationInfo, platformCompat)); } public @Nullable String getReceiverClassName() { Loading Loading @@ -125,14 +128,19 @@ public final class BroadcastFilter extends IntentFilter { @VisibleForTesting static int calculateAdjustedPriority(int owningUid, int priority, PlatformCompat platformCompat) { ApplicationInfo applicationInfo, PlatformCompat platformCompat) { if (!Flags.restrictPriorityValues()) { return priority; } if (!platformCompat.isChangeEnabledByUidInternalNoLogging( RESTRICT_PRIORITY_VALUES, owningUid)) { final long token = Binder.clearCallingIdentity(); try { if (!platformCompat.isChangeEnabledInternalNoLogging( RESTRICT_PRIORITY_VALUES, applicationInfo)) { return priority; } } finally { Binder.restoreCallingIdentity(token); } if (!UserHandle.isCore(owningUid)) { if (priority >= SYSTEM_HIGH_PRIORITY) { return SYSTEM_HIGH_PRIORITY - 1; Loading
services/tests/mockingservicestests/src/com/android/server/am/BaseBroadcastQueueTest.java +3 −3 Original line number Diff line number Diff line Loading @@ -185,8 +185,8 @@ public abstract class BaseBroadcastQueueTest { doReturn(mAppStartInfoTracker).when(mProcessList).getAppStartInfoTracker(); doReturn(true).when(mPlatformCompat).isChangeEnabledByUidInternalNoLogging( eq(BroadcastFilter.RESTRICT_PRIORITY_VALUES), anyInt()); doReturn(true).when(mPlatformCompat).isChangeEnabledInternalNoLogging( eq(BroadcastFilter.RESTRICT_PRIORITY_VALUES), any(ApplicationInfo.class)); doReturn(true).when(mPlatformCompat).isChangeEnabledByUidInternalNoLogging( eq(BroadcastRecord.LIMIT_PRIORITY_SCOPE), anyInt()); } Loading Loading @@ -298,7 +298,7 @@ public abstract class BaseBroadcastQueueTest { filter.setPriority(priority); final BroadcastFilter res = new BroadcastFilter(filter, receiverList, receiverList.app.info.packageName, null, null, null, receiverList.uid, receiverList.userId, false, false, true, receiverList.userId, false, false, true, receiverList.app.info, mock(PlatformCompat.class)); receiverList.add(res); return res; Loading
services/tests/mockingservicestests/src/com/android/server/am/BroadcastFilterTest.java +10 −9 Original line number Diff line number Diff line Loading @@ -20,10 +20,13 @@ import static android.content.IntentFilter.SYSTEM_LOW_PRIORITY; import static com.google.common.truth.Truth.assertWithMessage; import static org.mockito.ArgumentMatchers.any; import static org.mockito.ArgumentMatchers.anyInt; import static org.mockito.ArgumentMatchers.eq; import static org.mockito.Mockito.doReturn; import static org.mockito.Mockito.mock; import android.content.pm.ApplicationInfo; import android.os.Process; import android.platform.test.annotations.DisableFlags; import android.platform.test.annotations.EnableFlags; Loading Loading @@ -53,14 +56,14 @@ public class BroadcastFilterTest { @Before public void setUp() { MockitoAnnotations.initMocks(this); doReturn(true).when(mPlatformCompat).isChangeEnabledInternalNoLogging( eq(BroadcastFilter.RESTRICT_PRIORITY_VALUES), any(ApplicationInfo.class)); } @Test @EnableFlags(Flags.FLAG_RESTRICT_PRIORITY_VALUES) public void testCalculateAdjustedPriority() { doReturn(true).when(mPlatformCompat).isChangeEnabledByUidInternalNoLogging( eq(BroadcastFilter.RESTRICT_PRIORITY_VALUES), anyInt()); { // Pairs of {initial-priority, expected-adjusted-priority} final Pair<Integer, Integer>[] priorities = new Pair[] { Loading Loading @@ -95,8 +98,8 @@ public class BroadcastFilterTest { @Test @EnableFlags(Flags.FLAG_RESTRICT_PRIORITY_VALUES) public void testCalculateAdjustedPriority_withChangeIdDisabled() { doReturn(false).when(mPlatformCompat).isChangeEnabledByUidInternalNoLogging( eq(BroadcastFilter.RESTRICT_PRIORITY_VALUES), anyInt()); doReturn(false).when(mPlatformCompat).isChangeEnabledInternalNoLogging( eq(BroadcastFilter.RESTRICT_PRIORITY_VALUES), any(ApplicationInfo.class)); { // Pairs of {initial-priority, expected-adjusted-priority} Loading Loading @@ -132,9 +135,6 @@ public class BroadcastFilterTest { @Test @DisableFlags(Flags.FLAG_RESTRICT_PRIORITY_VALUES) public void testCalculateAdjustedPriority_withFlagDisabled() { doReturn(true).when(mPlatformCompat).isChangeEnabledByUidInternalNoLogging( eq(BroadcastFilter.RESTRICT_PRIORITY_VALUES), anyInt()); { // Pairs of {initial-priority, expected-adjusted-priority} final Pair<Integer, Integer>[] priorities = new Pair[] { Loading Loading @@ -215,6 +215,7 @@ public class BroadcastFilterTest { final String errorMsg = String.format("owner=%d; actualPriority=%d; expectedPriority=%d", owningUid, priority, expectedAdjustedPriority); assertWithMessage(errorMsg).that(BroadcastFilter.calculateAdjustedPriority( owningUid, priority, mPlatformCompat)).isEqualTo(expectedAdjustedPriority); owningUid, priority, mock(ApplicationInfo.class), mPlatformCompat)) .isEqualTo(expectedAdjustedPriority); } }