Loading services/core/java/com/android/server/pm/PackageMonitorCallbackHelper.java +21 −12 Original line number Diff line number Diff line Loading @@ -48,6 +48,7 @@ import java.util.function.BiFunction; class PackageMonitorCallbackHelper { private static final boolean DEBUG = false; private static final String TAG = "PackageMonitorCallbackHelper"; @NonNull private final Object mLock = new Object(); Loading Loading @@ -243,25 +244,33 @@ class PackageMonitorCallbackHelper { return; } int registerUid = registerUser.getUid(); if (allowUids != null && registerUid != Process.SYSTEM_UID && !ArrayUtils.contains(allowUids, registerUid)) { if (DEBUG) { Slog.w(TAG, "Skip invoke PackageMonitorCallback for " + intent.getAction() + ", uid " + registerUid); } return; } Intent newIntent = intent; 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 (filteredExtras == null) { // caller is unable to access this intent if (DEBUG) { Slog.w("PackageMonitorCallbackHelper", Slog.w(TAG, "Skip invoke PackageMonitorCallback for " + intent.getAction() + ", uid " + registerUid); + " because null filteredExtras"); } return; } invokeCallback(callback, intent); newIntent = new Intent(newIntent); newIntent.replaceExtras(filteredExtras); } } invokeCallback(callback, newIntent); })); } Loading services/tests/mockingservicestests/src/com/android/server/pm/PackageMonitorCallbackHelperTest.java +14 −0 Original line number Diff line number Diff line Loading @@ -107,6 +107,20 @@ public class PackageMonitorCallbackHelperTest { verify(callback, after(WAIT_CALLBACK_CALLED_IN_MS).never()).sendResult(any()); } @Test public void testPackageMonitorCallback_SuspendNoAccessCallbackNotCalled() throws Exception { BiFunction<Integer, Bundle, Bundle> filterExtras = (callingUid, intentExtras) -> null; 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); verify(callback, after(WAIT_CALLBACK_CALLED_IN_MS).never()).sendResult(any()); } @Test public void testPackageMonitorCallback_SuspendCallbackCalled() throws Exception { Bundle result = new Bundle(); Loading Loading
services/core/java/com/android/server/pm/PackageMonitorCallbackHelper.java +21 −12 Original line number Diff line number Diff line Loading @@ -48,6 +48,7 @@ import java.util.function.BiFunction; class PackageMonitorCallbackHelper { private static final boolean DEBUG = false; private static final String TAG = "PackageMonitorCallbackHelper"; @NonNull private final Object mLock = new Object(); Loading Loading @@ -243,25 +244,33 @@ class PackageMonitorCallbackHelper { return; } int registerUid = registerUser.getUid(); if (allowUids != null && registerUid != Process.SYSTEM_UID && !ArrayUtils.contains(allowUids, registerUid)) { if (DEBUG) { Slog.w(TAG, "Skip invoke PackageMonitorCallback for " + intent.getAction() + ", uid " + registerUid); } return; } Intent newIntent = intent; 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 (filteredExtras == null) { // caller is unable to access this intent if (DEBUG) { Slog.w("PackageMonitorCallbackHelper", Slog.w(TAG, "Skip invoke PackageMonitorCallback for " + intent.getAction() + ", uid " + registerUid); + " because null filteredExtras"); } return; } invokeCallback(callback, intent); newIntent = new Intent(newIntent); newIntent.replaceExtras(filteredExtras); } } invokeCallback(callback, newIntent); })); } Loading
services/tests/mockingservicestests/src/com/android/server/pm/PackageMonitorCallbackHelperTest.java +14 −0 Original line number Diff line number Diff line Loading @@ -107,6 +107,20 @@ public class PackageMonitorCallbackHelperTest { verify(callback, after(WAIT_CALLBACK_CALLED_IN_MS).never()).sendResult(any()); } @Test public void testPackageMonitorCallback_SuspendNoAccessCallbackNotCalled() throws Exception { BiFunction<Integer, Bundle, Bundle> filterExtras = (callingUid, intentExtras) -> null; 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); verify(callback, after(WAIT_CALLBACK_CALLED_IN_MS).never()).sendResult(any()); } @Test public void testPackageMonitorCallback_SuspendCallbackCalled() throws Exception { Bundle result = new Bundle(); Loading