Loading services/core/java/com/android/server/pm/BroadcastHelper.java +10 −6 Original line number Diff line number Diff line Loading @@ -827,7 +827,8 @@ public final class BroadcastHelper { // action. When the targetPkg is set, it sends the broadcast to specific app, e.g. // installer app or null for registered apps. The callback only need to send back to the // registered apps so we check the null condition here. notifyPackageMonitor(action, pkg, extras, userIds, instantUserIds, broadcastAllowList); notifyPackageMonitor(action, pkg, extras, userIds, instantUserIds, broadcastAllowList, null /* filterExtras */); } } Loading Loading @@ -975,14 +976,16 @@ public final class BroadcastHelper { final Bundle options = new BroadcastOptions() .setDeferralPolicy(BroadcastOptions.DEFERRAL_POLICY_UNTIL_ACTIVE) .toBundle(); BiFunction<Integer, Bundle, Bundle> filterExtrasForReceiver = (callingUid, intentExtras) -> BroadcastHelper.filterExtrasChangedPackageList( snapshot, callingUid, intentExtras); mHandler.post(() -> sendPackageBroadcast(intent, null /* pkg */, extras, flags, null /* targetPkg */, null /* finishedReceiver */, new int[]{userId}, null /* instantUserIds */, null /* broadcastAllowList */, (callingUid, intentExtras) -> BroadcastHelper.filterExtrasChangedPackageList( snapshot, callingUid, intentExtras), filterExtrasForReceiver, options)); notifyPackageMonitor(intent, null /* pkg */, extras, new int[]{userId}, null /* instantUserIds */, null /* broadcastAllowList */); null /* instantUserIds */, null /* broadcastAllowList */, filterExtrasForReceiver); } void sendMyPackageSuspendedOrUnsuspended(@NonNull Computer snapshot, Loading Loading @@ -1068,9 +1071,10 @@ public final class BroadcastHelper { @Nullable Bundle extras, @NonNull int[] userIds, @NonNull int[] instantUserIds, @Nullable SparseArray<int[]> broadcastAllowList) { @Nullable SparseArray<int[]> broadcastAllowList, @Nullable BiFunction<Integer, Bundle, Bundle> filterExtras) { mPackageMonitorCallbackHelper.notifyPackageMonitor(action, pkg, extras, userIds, instantUserIds, broadcastAllowList, mHandler); instantUserIds, broadcastAllowList, mHandler, filterExtras); } private void notifyResourcesChanged(boolean mediaStatus, Loading services/core/java/com/android/server/pm/PackageManagerService.java +2 −2 Original line number Diff line number Diff line Loading @@ -4626,7 +4626,7 @@ public class PackageManagerService implements PackageSender, TestUtilityService }); mPackageMonitorCallbackHelper.notifyPackageMonitor(Intent.ACTION_PACKAGE_UNSTOPPED, packageName, extras, userIds, null /* instantUserIds */, broadcastAllowList, mHandler); broadcastAllowList, mHandler, null /* filterExtras */); } } } Loading Loading @@ -7076,7 +7076,7 @@ public class PackageManagerService implements PackageSender, TestUtilityService } mPackageMonitorCallbackHelper.notifyPackageMonitor(Intent.ACTION_PACKAGE_RESTARTED, packageName, extras, userIds, null /* instantUserIds */, broadcastAllowList, mHandler); broadcastAllowList, mHandler, null /* filterExtras */); } @Override Loading services/core/java/com/android/server/pm/PackageMonitorCallbackHelper.java +27 −11 Original line number Diff line number Diff line Loading @@ -41,6 +41,7 @@ import com.android.internal.annotations.GuardedBy; import com.android.internal.util.ArrayUtils; import java.util.ArrayList; import java.util.function.BiFunction; /** Helper class to handle PackageMonitorCallback and notify the registered client. This is mainly * used by PackageMonitor to improve the broadcast latency. */ Loading Loading @@ -106,7 +107,8 @@ class PackageMonitorCallbackHelper { } extras.putInt(PackageInstaller.EXTRA_DATA_LOADER_TYPE, dataLoaderType); notifyPackageMonitor(Intent.ACTION_PACKAGE_ADDED, packageName, extras, userIds /* userIds */, instantUserIds, broadcastAllowList, handler); userIds /* userIds */, instantUserIds, broadcastAllowList, handler, null /* filterExtras */); } public void notifyResourcesChanged(boolean mediaStatus, boolean replacing, Loading @@ -120,7 +122,8 @@ class PackageMonitorCallbackHelper { String action = mediaStatus ? Intent.ACTION_EXTERNAL_APPLICATIONS_AVAILABLE : Intent.ACTION_EXTERNAL_APPLICATIONS_UNAVAILABLE; notifyPackageMonitor(action, null /* pkg */, extras, null /* userIds */, null /* instantUserIds */, null /* broadcastAllowList */, handler); null /* instantUserIds */, null /* broadcastAllowList */, handler, null /* filterExtras */); } public void notifyPackageChanged(String packageName, boolean dontKillApp, Loading @@ -137,12 +140,12 @@ class PackageMonitorCallbackHelper { extras.putString(Intent.EXTRA_REASON, reason); } notifyPackageMonitor(Intent.ACTION_PACKAGE_CHANGED, packageName, extras, userIds, instantUserIds, broadcastAllowList, handler); instantUserIds, broadcastAllowList, handler, null /* filterExtras */); } public void notifyPackageMonitor(String action, String pkg, Bundle extras, int[] userIds, int[] instantUserIds, SparseArray<int[]> broadcastAllowList, Handler handler) { Handler handler, BiFunction<Integer, Bundle, Bundle> filterExtras) { if (!isAllowedCallbackAction(action)) { return; } Loading @@ -160,10 +163,11 @@ class PackageMonitorCallbackHelper { if (ArrayUtils.isEmpty(instantUserIds)) { doNotifyCallbacksByAction( action, pkg, extras, resolvedUserIds, broadcastAllowList, handler); action, pkg, extras, resolvedUserIds, broadcastAllowList, handler, filterExtras); } else { doNotifyCallbacksByAction(action, pkg, extras, instantUserIds, broadcastAllowList, handler); handler, filterExtras); } } catch (RemoteException e) { // do nothing Loading Loading @@ -199,11 +203,13 @@ class PackageMonitorCallbackHelper { synchronized (mLock) { callbacks = mCallbacks; } doNotifyCallbacks(callbacks, intent, userId, broadcastAllowList, handler); doNotifyCallbacks(callbacks, intent, userId, broadcastAllowList, handler, null /* filterExtrasFunction */); } private void doNotifyCallbacksByAction(String action, String pkg, Bundle extras, int[] userIds, SparseArray<int[]> broadcastAllowList, Handler handler) { SparseArray<int[]> broadcastAllowList, Handler handler, BiFunction<Integer, Bundle, Bundle> filterExtrasFunction) { RemoteCallbackList<IRemoteCallback> callbacks; synchronized (mLock) { callbacks = mCallbacks; Loading @@ -223,12 +229,13 @@ class PackageMonitorCallbackHelper { final int[] allowUids = broadcastAllowList != null ? broadcastAllowList.get(userId) : null; doNotifyCallbacks(callbacks, intent, userId, allowUids, handler); doNotifyCallbacks(callbacks, intent, userId, allowUids, handler, filterExtrasFunction); } } private void doNotifyCallbacks(RemoteCallbackList<IRemoteCallback> callbacks, Intent intent, int userId, int[] allowUids, Handler handler) { Intent intent, int userId, int[] allowUids, Handler handler, BiFunction<Integer, Bundle, Bundle> filterExtrasFunction) { handler.post(() -> callbacks.broadcast((callback, user) -> { RegisterUser registerUser = (RegisterUser) user; if ((registerUser.getUserId() != UserHandle.USER_ALL) && (registerUser.getUserId() Loading @@ -236,6 +243,15 @@ class PackageMonitorCallbackHelper { return; } int registerUid = registerUser.getUid(); if (filterExtrasFunction != null) { final Bundle extras = intent.getExtras(); if (extras != null) { final Bundle filteredExtras = filterExtrasFunction.apply(registerUid, extras); if (filteredExtras != null) { intent.replaceExtras(filteredExtras); } } } if (allowUids != null && registerUid != Process.SYSTEM_UID && !ArrayUtils.contains(allowUids, registerUid)) { if (DEBUG) { Loading services/tests/mockingservicestests/src/com/android/server/pm/PackageMonitorCallbackHelperTest.java +43 −9 Original line number Diff line number Diff line Loading @@ -44,6 +44,7 @@ import org.junit.runners.JUnit4; import org.mockito.ArgumentCaptor; import java.util.ArrayList; import java.util.function.BiFunction; /** * A unit test for PackageMonitorCallbackHelper implementation. Loading Loading @@ -78,7 +79,8 @@ public class PackageMonitorCallbackHelperTest { mPackageMonitorCallbackHelper.notifyPackageMonitor(Intent.ACTION_PACKAGE_ADDED, FAKE_PACKAGE_NAME, createFakeBundle(), new int[]{0} /* userIds */, null /* instantUserIds */, null /* broadcastAllowList */, mHandler); null /* instantUserIds */, null /* broadcastAllowList */, mHandler, null /* filterExtras */); verify(callback, after(WAIT_CALLBACK_CALLED_IN_MS).never()).sendResult(any()); } Loading @@ -91,7 +93,7 @@ public class PackageMonitorCallbackHelperTest { Binder.getCallingUid()); mPackageMonitorCallbackHelper.notifyPackageMonitor(Intent.ACTION_PACKAGE_ADDED, FAKE_PACKAGE_NAME, createFakeBundle(), new int[]{0}, null /* instantUserIds */, null /* broadcastAllowList */, mHandler); null /* broadcastAllowList */, mHandler, null /* filterExtras */); verify(callback, after(WAIT_CALLBACK_CALLED_IN_MS).times(1)).sendResult(any()); Loading @@ -99,11 +101,40 @@ public class PackageMonitorCallbackHelperTest { mPackageMonitorCallbackHelper.unregisterPackageMonitorCallback(callback); mPackageMonitorCallbackHelper.notifyPackageMonitor(Intent.ACTION_PACKAGE_ADDED, FAKE_PACKAGE_NAME, createFakeBundle(), new int[]{0} /* userIds */, null /* instantUserIds */, null /* broadcastAllowList */, mHandler); null /* instantUserIds */, null /* broadcastAllowList */, mHandler, null /* filterExtras */); verify(callback, after(WAIT_CALLBACK_CALLED_IN_MS).never()).sendResult(any()); } @Test public void testPackageMonitorCallback_SuspendCallbackCalled() throws Exception { Bundle result = new Bundle(); result.putInt(Intent.EXTRA_UID, FAKE_PACKAGE_UID); result.putStringArray(Intent.EXTRA_CHANGED_PACKAGE_LIST, new String[]{FAKE_PACKAGE_NAME}); BiFunction<Integer, Bundle, Bundle> filterExtras = (callingUid, intentExtras) -> result; IRemoteCallback callback = createMockPackageMonitorCallback(); mPackageMonitorCallbackHelper.registerPackageMonitorCallback(callback, 0 /* userId */, Binder.getCallingUid()); mPackageMonitorCallbackHelper.notifyPackageMonitor(Intent.ACTION_PACKAGES_SUSPENDED, FAKE_PACKAGE_NAME, createFakeBundle(), new int[]{0}, null /* instantUserIds */, null /* broadcastAllowList */, mHandler, filterExtras); ArgumentCaptor<Bundle> bundleCaptor = ArgumentCaptor.forClass(Bundle.class); verify(callback, after(WAIT_CALLBACK_CALLED_IN_MS).times(1)).sendResult( bundleCaptor.capture()); Bundle bundle = bundleCaptor.getValue(); Intent intent = bundle.getParcelable( PackageManager.EXTRA_PACKAGE_MONITOR_CALLBACK_RESULT, Intent.class); assertThat(intent).isNotNull(); assertThat(intent.getAction()).isEqualTo(Intent.ACTION_PACKAGES_SUSPENDED); String[] pkgList = intent.getStringArrayExtra(Intent.EXTRA_CHANGED_PACKAGE_LIST); assertThat(pkgList).isNotNull(); assertThat(pkgList.length).isEqualTo(1); assertThat(pkgList[0]).isEqualTo(FAKE_PACKAGE_NAME); } @Test public void testRegisterPackageMonitorCallback_callbackCalled() throws Exception { IRemoteCallback callback = createMockPackageMonitorCallback(); Loading @@ -112,7 +143,8 @@ public class PackageMonitorCallbackHelperTest { Binder.getCallingUid()); mPackageMonitorCallbackHelper.notifyPackageMonitor(Intent.ACTION_PACKAGE_ADDED, FAKE_PACKAGE_NAME, createFakeBundle(), new int[]{0} /* userIds */, null /* instantUserIds */, null /* broadcastAllowList */, mHandler); null /* instantUserIds */, null /* broadcastAllowList */, mHandler, null /* filterExtras */); ArgumentCaptor<Bundle> bundleCaptor = ArgumentCaptor.forClass(Bundle.class); verify(callback, after(WAIT_CALLBACK_CALLED_IN_MS).times(1)).sendResult( Loading @@ -136,7 +168,8 @@ public class PackageMonitorCallbackHelperTest { // Notify for user 10 mPackageMonitorCallbackHelper.notifyPackageMonitor(Intent.ACTION_PACKAGE_ADDED, FAKE_PACKAGE_NAME, createFakeBundle(), new int[]{10} /* userIds */, null /* instantUserIds */, null /* broadcastAllowList */, mHandler); null /* instantUserIds */, null /* broadcastAllowList */, mHandler, null /* filterExtras */); verify(callback, after(WAIT_CALLBACK_CALLED_IN_MS).never()).sendResult(any()); } Loading Loading @@ -239,7 +272,8 @@ public class PackageMonitorCallbackHelperTest { mPackageMonitorCallbackHelper.onUserRemoved(10); mPackageMonitorCallbackHelper.notifyPackageMonitor(Intent.ACTION_PACKAGE_ADDED, FAKE_PACKAGE_NAME, createFakeBundle(), new int[]{10} /* userIds */, null /* instantUserIds */, null /* broadcastAllowList */, mHandler); null /* instantUserIds */, null /* broadcastAllowList */, mHandler, null /* filterExtras */); verify(callback, after(WAIT_CALLBACK_CALLED_IN_MS).never()).sendResult(any()); } Loading @@ -255,7 +289,7 @@ public class PackageMonitorCallbackHelperTest { Binder.getCallingUid()); mPackageMonitorCallbackHelper.notifyPackageMonitor(Intent.ACTION_PACKAGE_ADDED, FAKE_PACKAGE_NAME, createFakeBundle(), new int[]{0} /* userIds */, null /* instantUserIds */, broadcastAllowList, mHandler); null /* instantUserIds */, broadcastAllowList, mHandler, null /* filterExtras */); verify(callback, after(WAIT_CALLBACK_CALLED_IN_MS).times(1)).sendResult(any()); } Loading @@ -271,7 +305,7 @@ public class PackageMonitorCallbackHelperTest { Binder.getCallingUid()); mPackageMonitorCallbackHelper.notifyPackageMonitor(Intent.ACTION_PACKAGE_ADDED, FAKE_PACKAGE_NAME, createFakeBundle(), new int[]{0} /* userIds */, null /* instantUserIds */, broadcastAllowList, mHandler); null /* instantUserIds */, broadcastAllowList, mHandler, null /* filterExtras */); verify(callback, after(WAIT_CALLBACK_CALLED_IN_MS).never()).sendResult(any()); } Loading @@ -287,7 +321,7 @@ public class PackageMonitorCallbackHelperTest { Process.SYSTEM_UID); mPackageMonitorCallbackHelper.notifyPackageMonitor(Intent.ACTION_PACKAGE_ADDED, FAKE_PACKAGE_NAME, createFakeBundle(), new int[]{0} /* userIds */, null /* instantUserIds */, broadcastAllowList, mHandler); null /* instantUserIds */, broadcastAllowList, mHandler, null /* filterExtras */); verify(callback, after(WAIT_CALLBACK_CALLED_IN_MS).times(1)).sendResult(any()); } Loading Loading
services/core/java/com/android/server/pm/BroadcastHelper.java +10 −6 Original line number Diff line number Diff line Loading @@ -827,7 +827,8 @@ public final class BroadcastHelper { // action. When the targetPkg is set, it sends the broadcast to specific app, e.g. // installer app or null for registered apps. The callback only need to send back to the // registered apps so we check the null condition here. notifyPackageMonitor(action, pkg, extras, userIds, instantUserIds, broadcastAllowList); notifyPackageMonitor(action, pkg, extras, userIds, instantUserIds, broadcastAllowList, null /* filterExtras */); } } Loading Loading @@ -975,14 +976,16 @@ public final class BroadcastHelper { final Bundle options = new BroadcastOptions() .setDeferralPolicy(BroadcastOptions.DEFERRAL_POLICY_UNTIL_ACTIVE) .toBundle(); BiFunction<Integer, Bundle, Bundle> filterExtrasForReceiver = (callingUid, intentExtras) -> BroadcastHelper.filterExtrasChangedPackageList( snapshot, callingUid, intentExtras); mHandler.post(() -> sendPackageBroadcast(intent, null /* pkg */, extras, flags, null /* targetPkg */, null /* finishedReceiver */, new int[]{userId}, null /* instantUserIds */, null /* broadcastAllowList */, (callingUid, intentExtras) -> BroadcastHelper.filterExtrasChangedPackageList( snapshot, callingUid, intentExtras), filterExtrasForReceiver, options)); notifyPackageMonitor(intent, null /* pkg */, extras, new int[]{userId}, null /* instantUserIds */, null /* broadcastAllowList */); null /* instantUserIds */, null /* broadcastAllowList */, filterExtrasForReceiver); } void sendMyPackageSuspendedOrUnsuspended(@NonNull Computer snapshot, Loading Loading @@ -1068,9 +1071,10 @@ public final class BroadcastHelper { @Nullable Bundle extras, @NonNull int[] userIds, @NonNull int[] instantUserIds, @Nullable SparseArray<int[]> broadcastAllowList) { @Nullable SparseArray<int[]> broadcastAllowList, @Nullable BiFunction<Integer, Bundle, Bundle> filterExtras) { mPackageMonitorCallbackHelper.notifyPackageMonitor(action, pkg, extras, userIds, instantUserIds, broadcastAllowList, mHandler); instantUserIds, broadcastAllowList, mHandler, filterExtras); } private void notifyResourcesChanged(boolean mediaStatus, Loading
services/core/java/com/android/server/pm/PackageManagerService.java +2 −2 Original line number Diff line number Diff line Loading @@ -4626,7 +4626,7 @@ public class PackageManagerService implements PackageSender, TestUtilityService }); mPackageMonitorCallbackHelper.notifyPackageMonitor(Intent.ACTION_PACKAGE_UNSTOPPED, packageName, extras, userIds, null /* instantUserIds */, broadcastAllowList, mHandler); broadcastAllowList, mHandler, null /* filterExtras */); } } } Loading Loading @@ -7076,7 +7076,7 @@ public class PackageManagerService implements PackageSender, TestUtilityService } mPackageMonitorCallbackHelper.notifyPackageMonitor(Intent.ACTION_PACKAGE_RESTARTED, packageName, extras, userIds, null /* instantUserIds */, broadcastAllowList, mHandler); broadcastAllowList, mHandler, null /* filterExtras */); } @Override Loading
services/core/java/com/android/server/pm/PackageMonitorCallbackHelper.java +27 −11 Original line number Diff line number Diff line Loading @@ -41,6 +41,7 @@ import com.android.internal.annotations.GuardedBy; import com.android.internal.util.ArrayUtils; import java.util.ArrayList; import java.util.function.BiFunction; /** Helper class to handle PackageMonitorCallback and notify the registered client. This is mainly * used by PackageMonitor to improve the broadcast latency. */ Loading Loading @@ -106,7 +107,8 @@ class PackageMonitorCallbackHelper { } extras.putInt(PackageInstaller.EXTRA_DATA_LOADER_TYPE, dataLoaderType); notifyPackageMonitor(Intent.ACTION_PACKAGE_ADDED, packageName, extras, userIds /* userIds */, instantUserIds, broadcastAllowList, handler); userIds /* userIds */, instantUserIds, broadcastAllowList, handler, null /* filterExtras */); } public void notifyResourcesChanged(boolean mediaStatus, boolean replacing, Loading @@ -120,7 +122,8 @@ class PackageMonitorCallbackHelper { String action = mediaStatus ? Intent.ACTION_EXTERNAL_APPLICATIONS_AVAILABLE : Intent.ACTION_EXTERNAL_APPLICATIONS_UNAVAILABLE; notifyPackageMonitor(action, null /* pkg */, extras, null /* userIds */, null /* instantUserIds */, null /* broadcastAllowList */, handler); null /* instantUserIds */, null /* broadcastAllowList */, handler, null /* filterExtras */); } public void notifyPackageChanged(String packageName, boolean dontKillApp, Loading @@ -137,12 +140,12 @@ class PackageMonitorCallbackHelper { extras.putString(Intent.EXTRA_REASON, reason); } notifyPackageMonitor(Intent.ACTION_PACKAGE_CHANGED, packageName, extras, userIds, instantUserIds, broadcastAllowList, handler); instantUserIds, broadcastAllowList, handler, null /* filterExtras */); } public void notifyPackageMonitor(String action, String pkg, Bundle extras, int[] userIds, int[] instantUserIds, SparseArray<int[]> broadcastAllowList, Handler handler) { Handler handler, BiFunction<Integer, Bundle, Bundle> filterExtras) { if (!isAllowedCallbackAction(action)) { return; } Loading @@ -160,10 +163,11 @@ class PackageMonitorCallbackHelper { if (ArrayUtils.isEmpty(instantUserIds)) { doNotifyCallbacksByAction( action, pkg, extras, resolvedUserIds, broadcastAllowList, handler); action, pkg, extras, resolvedUserIds, broadcastAllowList, handler, filterExtras); } else { doNotifyCallbacksByAction(action, pkg, extras, instantUserIds, broadcastAllowList, handler); handler, filterExtras); } } catch (RemoteException e) { // do nothing Loading Loading @@ -199,11 +203,13 @@ class PackageMonitorCallbackHelper { synchronized (mLock) { callbacks = mCallbacks; } doNotifyCallbacks(callbacks, intent, userId, broadcastAllowList, handler); doNotifyCallbacks(callbacks, intent, userId, broadcastAllowList, handler, null /* filterExtrasFunction */); } private void doNotifyCallbacksByAction(String action, String pkg, Bundle extras, int[] userIds, SparseArray<int[]> broadcastAllowList, Handler handler) { SparseArray<int[]> broadcastAllowList, Handler handler, BiFunction<Integer, Bundle, Bundle> filterExtrasFunction) { RemoteCallbackList<IRemoteCallback> callbacks; synchronized (mLock) { callbacks = mCallbacks; Loading @@ -223,12 +229,13 @@ class PackageMonitorCallbackHelper { final int[] allowUids = broadcastAllowList != null ? broadcastAllowList.get(userId) : null; doNotifyCallbacks(callbacks, intent, userId, allowUids, handler); doNotifyCallbacks(callbacks, intent, userId, allowUids, handler, filterExtrasFunction); } } private void doNotifyCallbacks(RemoteCallbackList<IRemoteCallback> callbacks, Intent intent, int userId, int[] allowUids, Handler handler) { Intent intent, int userId, int[] allowUids, Handler handler, BiFunction<Integer, Bundle, Bundle> filterExtrasFunction) { handler.post(() -> callbacks.broadcast((callback, user) -> { RegisterUser registerUser = (RegisterUser) user; if ((registerUser.getUserId() != UserHandle.USER_ALL) && (registerUser.getUserId() Loading @@ -236,6 +243,15 @@ class PackageMonitorCallbackHelper { return; } int registerUid = registerUser.getUid(); if (filterExtrasFunction != null) { final Bundle extras = intent.getExtras(); if (extras != null) { final Bundle filteredExtras = filterExtrasFunction.apply(registerUid, extras); if (filteredExtras != null) { intent.replaceExtras(filteredExtras); } } } if (allowUids != null && registerUid != Process.SYSTEM_UID && !ArrayUtils.contains(allowUids, registerUid)) { if (DEBUG) { Loading
services/tests/mockingservicestests/src/com/android/server/pm/PackageMonitorCallbackHelperTest.java +43 −9 Original line number Diff line number Diff line Loading @@ -44,6 +44,7 @@ import org.junit.runners.JUnit4; import org.mockito.ArgumentCaptor; import java.util.ArrayList; import java.util.function.BiFunction; /** * A unit test for PackageMonitorCallbackHelper implementation. Loading Loading @@ -78,7 +79,8 @@ public class PackageMonitorCallbackHelperTest { mPackageMonitorCallbackHelper.notifyPackageMonitor(Intent.ACTION_PACKAGE_ADDED, FAKE_PACKAGE_NAME, createFakeBundle(), new int[]{0} /* userIds */, null /* instantUserIds */, null /* broadcastAllowList */, mHandler); null /* instantUserIds */, null /* broadcastAllowList */, mHandler, null /* filterExtras */); verify(callback, after(WAIT_CALLBACK_CALLED_IN_MS).never()).sendResult(any()); } Loading @@ -91,7 +93,7 @@ public class PackageMonitorCallbackHelperTest { Binder.getCallingUid()); mPackageMonitorCallbackHelper.notifyPackageMonitor(Intent.ACTION_PACKAGE_ADDED, FAKE_PACKAGE_NAME, createFakeBundle(), new int[]{0}, null /* instantUserIds */, null /* broadcastAllowList */, mHandler); null /* broadcastAllowList */, mHandler, null /* filterExtras */); verify(callback, after(WAIT_CALLBACK_CALLED_IN_MS).times(1)).sendResult(any()); Loading @@ -99,11 +101,40 @@ public class PackageMonitorCallbackHelperTest { mPackageMonitorCallbackHelper.unregisterPackageMonitorCallback(callback); mPackageMonitorCallbackHelper.notifyPackageMonitor(Intent.ACTION_PACKAGE_ADDED, FAKE_PACKAGE_NAME, createFakeBundle(), new int[]{0} /* userIds */, null /* instantUserIds */, null /* broadcastAllowList */, mHandler); null /* instantUserIds */, null /* broadcastAllowList */, mHandler, null /* filterExtras */); verify(callback, after(WAIT_CALLBACK_CALLED_IN_MS).never()).sendResult(any()); } @Test public void testPackageMonitorCallback_SuspendCallbackCalled() throws Exception { Bundle result = new Bundle(); result.putInt(Intent.EXTRA_UID, FAKE_PACKAGE_UID); result.putStringArray(Intent.EXTRA_CHANGED_PACKAGE_LIST, new String[]{FAKE_PACKAGE_NAME}); BiFunction<Integer, Bundle, Bundle> filterExtras = (callingUid, intentExtras) -> result; IRemoteCallback callback = createMockPackageMonitorCallback(); mPackageMonitorCallbackHelper.registerPackageMonitorCallback(callback, 0 /* userId */, Binder.getCallingUid()); mPackageMonitorCallbackHelper.notifyPackageMonitor(Intent.ACTION_PACKAGES_SUSPENDED, FAKE_PACKAGE_NAME, createFakeBundle(), new int[]{0}, null /* instantUserIds */, null /* broadcastAllowList */, mHandler, filterExtras); ArgumentCaptor<Bundle> bundleCaptor = ArgumentCaptor.forClass(Bundle.class); verify(callback, after(WAIT_CALLBACK_CALLED_IN_MS).times(1)).sendResult( bundleCaptor.capture()); Bundle bundle = bundleCaptor.getValue(); Intent intent = bundle.getParcelable( PackageManager.EXTRA_PACKAGE_MONITOR_CALLBACK_RESULT, Intent.class); assertThat(intent).isNotNull(); assertThat(intent.getAction()).isEqualTo(Intent.ACTION_PACKAGES_SUSPENDED); String[] pkgList = intent.getStringArrayExtra(Intent.EXTRA_CHANGED_PACKAGE_LIST); assertThat(pkgList).isNotNull(); assertThat(pkgList.length).isEqualTo(1); assertThat(pkgList[0]).isEqualTo(FAKE_PACKAGE_NAME); } @Test public void testRegisterPackageMonitorCallback_callbackCalled() throws Exception { IRemoteCallback callback = createMockPackageMonitorCallback(); Loading @@ -112,7 +143,8 @@ public class PackageMonitorCallbackHelperTest { Binder.getCallingUid()); mPackageMonitorCallbackHelper.notifyPackageMonitor(Intent.ACTION_PACKAGE_ADDED, FAKE_PACKAGE_NAME, createFakeBundle(), new int[]{0} /* userIds */, null /* instantUserIds */, null /* broadcastAllowList */, mHandler); null /* instantUserIds */, null /* broadcastAllowList */, mHandler, null /* filterExtras */); ArgumentCaptor<Bundle> bundleCaptor = ArgumentCaptor.forClass(Bundle.class); verify(callback, after(WAIT_CALLBACK_CALLED_IN_MS).times(1)).sendResult( Loading @@ -136,7 +168,8 @@ public class PackageMonitorCallbackHelperTest { // Notify for user 10 mPackageMonitorCallbackHelper.notifyPackageMonitor(Intent.ACTION_PACKAGE_ADDED, FAKE_PACKAGE_NAME, createFakeBundle(), new int[]{10} /* userIds */, null /* instantUserIds */, null /* broadcastAllowList */, mHandler); null /* instantUserIds */, null /* broadcastAllowList */, mHandler, null /* filterExtras */); verify(callback, after(WAIT_CALLBACK_CALLED_IN_MS).never()).sendResult(any()); } Loading Loading @@ -239,7 +272,8 @@ public class PackageMonitorCallbackHelperTest { mPackageMonitorCallbackHelper.onUserRemoved(10); mPackageMonitorCallbackHelper.notifyPackageMonitor(Intent.ACTION_PACKAGE_ADDED, FAKE_PACKAGE_NAME, createFakeBundle(), new int[]{10} /* userIds */, null /* instantUserIds */, null /* broadcastAllowList */, mHandler); null /* instantUserIds */, null /* broadcastAllowList */, mHandler, null /* filterExtras */); verify(callback, after(WAIT_CALLBACK_CALLED_IN_MS).never()).sendResult(any()); } Loading @@ -255,7 +289,7 @@ public class PackageMonitorCallbackHelperTest { Binder.getCallingUid()); mPackageMonitorCallbackHelper.notifyPackageMonitor(Intent.ACTION_PACKAGE_ADDED, FAKE_PACKAGE_NAME, createFakeBundle(), new int[]{0} /* userIds */, null /* instantUserIds */, broadcastAllowList, mHandler); null /* instantUserIds */, broadcastAllowList, mHandler, null /* filterExtras */); verify(callback, after(WAIT_CALLBACK_CALLED_IN_MS).times(1)).sendResult(any()); } Loading @@ -271,7 +305,7 @@ public class PackageMonitorCallbackHelperTest { Binder.getCallingUid()); mPackageMonitorCallbackHelper.notifyPackageMonitor(Intent.ACTION_PACKAGE_ADDED, FAKE_PACKAGE_NAME, createFakeBundle(), new int[]{0} /* userIds */, null /* instantUserIds */, broadcastAllowList, mHandler); null /* instantUserIds */, broadcastAllowList, mHandler, null /* filterExtras */); verify(callback, after(WAIT_CALLBACK_CALLED_IN_MS).never()).sendResult(any()); } Loading @@ -287,7 +321,7 @@ public class PackageMonitorCallbackHelperTest { Process.SYSTEM_UID); mPackageMonitorCallbackHelper.notifyPackageMonitor(Intent.ACTION_PACKAGE_ADDED, FAKE_PACKAGE_NAME, createFakeBundle(), new int[]{0} /* userIds */, null /* instantUserIds */, broadcastAllowList, mHandler); null /* instantUserIds */, broadcastAllowList, mHandler, null /* filterExtras */); verify(callback, after(WAIT_CALLBACK_CALLED_IN_MS).times(1)).sendResult(any()); } Loading