Fix EphemeralTest#testGetSearchableInfo
The failed root cause is the PackageMonitorCallbackHelper misses handling instant cases. Add instantUserIds checking to fix the issue. Bug: 289797357 Test: atest EphemeralTest#testGetSearchableInfo Test: atest PackageMonitorCallbackHelperTest Change-Id: Ib5d4869c906cc996620b52e9c137c12a106d03f3
This commit is contained in:
@@ -2998,12 +2998,14 @@ public class PackageManagerService implements PackageSender, TestUtilityService
|
||||
// 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);
|
||||
notifyPackageMonitor(action, pkg, extras, userIds, instantUserIds);
|
||||
}
|
||||
}
|
||||
|
||||
void notifyPackageMonitor(String action, String pkg, Bundle extras, int[] userIds) {
|
||||
mPackageMonitorCallbackHelper.notifyPackageMonitor(action, pkg, extras, userIds);
|
||||
void notifyPackageMonitor(String action, String pkg, Bundle extras, int[] userIds,
|
||||
int[] instantUserIds) {
|
||||
mPackageMonitorCallbackHelper.notifyPackageMonitor(action, pkg, extras, userIds,
|
||||
instantUserIds);
|
||||
}
|
||||
|
||||
void notifyResourcesChanged(boolean mediaStatus, boolean replacing,
|
||||
@@ -4053,7 +4055,7 @@ public class PackageManagerService implements PackageSender, TestUtilityService
|
||||
packageName, dontKillApp, componentNames, packageUid, reason, userIds,
|
||||
instantUserIds, broadcastAllowList));
|
||||
mPackageMonitorCallbackHelper.notifyPackageChanged(packageName, dontKillApp, componentNames,
|
||||
packageUid, reason, userIds);
|
||||
packageUid, reason, userIds, instantUserIds);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -78,7 +78,7 @@ class PackageMonitorCallbackHelper {
|
||||
extras.putInt(Intent.EXTRA_UID, uid);
|
||||
extras.putInt(PackageInstaller.EXTRA_DATA_LOADER_TYPE, dataLoaderType);
|
||||
notifyPackageMonitor(Intent.ACTION_PACKAGE_ADDED, packageName, extras ,
|
||||
userIds /* userIds */);
|
||||
userIds /* userIds */, instantUserIds);
|
||||
}
|
||||
|
||||
public void notifyResourcesChanged(boolean mediaStatus, boolean replacing,
|
||||
@@ -91,11 +91,13 @@ class PackageMonitorCallbackHelper {
|
||||
}
|
||||
String action = mediaStatus ? Intent.ACTION_EXTERNAL_APPLICATIONS_AVAILABLE
|
||||
: Intent.ACTION_EXTERNAL_APPLICATIONS_UNAVAILABLE;
|
||||
notifyPackageMonitor(action, null /* pkg */, extras, null /* userIds */);
|
||||
notifyPackageMonitor(action, null /* pkg */, extras, null /* userIds */,
|
||||
null /* instantUserIds */);
|
||||
}
|
||||
|
||||
public void notifyPackageChanged(String packageName, boolean dontKillApp,
|
||||
ArrayList<String> componentNames, int packageUid, String reason, int[] userIds) {
|
||||
ArrayList<String> componentNames, int packageUid, String reason, int[] userIds,
|
||||
int[] instantUserIds) {
|
||||
Bundle extras = new Bundle(4);
|
||||
extras.putString(Intent.EXTRA_CHANGED_COMPONENT_NAME, componentNames.get(0));
|
||||
String[] nameList = new String[componentNames.size()];
|
||||
@@ -106,11 +108,12 @@ class PackageMonitorCallbackHelper {
|
||||
if (reason != null) {
|
||||
extras.putString(Intent.EXTRA_REASON, reason);
|
||||
}
|
||||
notifyPackageMonitor(Intent.ACTION_PACKAGE_CHANGED, packageName, extras, userIds);
|
||||
notifyPackageMonitor(Intent.ACTION_PACKAGE_CHANGED, packageName, extras, userIds,
|
||||
instantUserIds);
|
||||
}
|
||||
|
||||
public void notifyPackageMonitor(String action, String pkg, Bundle extras,
|
||||
int[] userIds) {
|
||||
int[] userIds, int[] instantUserIds) {
|
||||
if (!isAllowedCallbackAction(action)) {
|
||||
return;
|
||||
}
|
||||
@@ -122,7 +125,12 @@ class PackageMonitorCallbackHelper {
|
||||
} else {
|
||||
resolvedUserIds = userIds;
|
||||
}
|
||||
doNotifyCallbacks(action, pkg, extras, resolvedUserIds);
|
||||
|
||||
if (ArrayUtils.isEmpty(instantUserIds)) {
|
||||
doNotifyCallbacks(action, pkg, extras, resolvedUserIds);
|
||||
} else {
|
||||
doNotifyCallbacks(action, pkg, extras, instantUserIds);
|
||||
}
|
||||
} catch (RemoteException e) {
|
||||
// do nothing
|
||||
}
|
||||
|
||||
@@ -633,7 +633,8 @@ public final class SuspendPackageHelper {
|
||||
(callingUid, intentExtras) -> BroadcastHelper.filterExtrasChangedPackageList(
|
||||
mPm.snapshotComputer(), callingUid, intentExtras),
|
||||
options));
|
||||
mPm.notifyPackageMonitor(intent, null /* pkg */, extras, new int[]{userId});
|
||||
mPm.notifyPackageMonitor(intent, null /* pkg */, extras, new int[]{userId},
|
||||
null /* instantUserIds */);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -77,7 +77,8 @@ public class PackageMonitorCallbackHelperTest {
|
||||
IRemoteCallback callback = createMockPackageMonitorCallback();
|
||||
|
||||
mPackageMonitorCallbackHelper.notifyPackageMonitor(Intent.ACTION_PACKAGE_ADDED,
|
||||
FAKE_PACKAGE_NAME, createFakeBundle(), new int[]{0} /* userIds */);
|
||||
FAKE_PACKAGE_NAME, createFakeBundle(), new int[]{0} /* userIds */,
|
||||
null /* instantUserIds */);
|
||||
|
||||
verify(callback, after(WAIT_CALLBACK_CALLED_IN_MS).never()).sendResult(any());
|
||||
}
|
||||
@@ -88,14 +89,15 @@ public class PackageMonitorCallbackHelperTest {
|
||||
|
||||
mPackageMonitorCallbackHelper.registerPackageMonitorCallback(callback, 0 /* userId */);
|
||||
mPackageMonitorCallbackHelper.notifyPackageMonitor(Intent.ACTION_PACKAGE_ADDED,
|
||||
FAKE_PACKAGE_NAME, createFakeBundle(), new int[]{0});
|
||||
FAKE_PACKAGE_NAME, createFakeBundle(), new int[]{0}, null /* instantUserIds */);
|
||||
|
||||
verify(callback, after(WAIT_CALLBACK_CALLED_IN_MS).times(1)).sendResult(any());
|
||||
|
||||
reset(callback);
|
||||
mPackageMonitorCallbackHelper.unregisterPackageMonitorCallback(callback);
|
||||
mPackageMonitorCallbackHelper.notifyPackageMonitor(Intent.ACTION_PACKAGE_ADDED,
|
||||
FAKE_PACKAGE_NAME, createFakeBundle(), new int[]{0} /* userIds */);
|
||||
FAKE_PACKAGE_NAME, createFakeBundle(), new int[]{0} /* userIds */,
|
||||
null /* instantUserIds */);
|
||||
|
||||
verify(callback, after(WAIT_CALLBACK_CALLED_IN_MS).never()).sendResult(any());
|
||||
}
|
||||
@@ -106,7 +108,8 @@ public class PackageMonitorCallbackHelperTest {
|
||||
|
||||
mPackageMonitorCallbackHelper.registerPackageMonitorCallback(callback, 0 /* userId */);
|
||||
mPackageMonitorCallbackHelper.notifyPackageMonitor(Intent.ACTION_PACKAGE_ADDED,
|
||||
FAKE_PACKAGE_NAME, createFakeBundle(), new int[]{0} /* userIds */);
|
||||
FAKE_PACKAGE_NAME, createFakeBundle(), new int[]{0} /* userIds */,
|
||||
null /* instantUserIds */);
|
||||
|
||||
ArgumentCaptor<Bundle> bundleCaptor = ArgumentCaptor.forClass(Bundle.class);
|
||||
verify(callback, after(WAIT_CALLBACK_CALLED_IN_MS).times(1)).sendResult(
|
||||
@@ -128,7 +131,8 @@ public class PackageMonitorCallbackHelperTest {
|
||||
mPackageMonitorCallbackHelper.registerPackageMonitorCallback(callback, 0 /* userId */);
|
||||
// Notify for user 10
|
||||
mPackageMonitorCallbackHelper.notifyPackageMonitor(Intent.ACTION_PACKAGE_ADDED,
|
||||
FAKE_PACKAGE_NAME, createFakeBundle(), new int[]{10} /* userIds */);
|
||||
FAKE_PACKAGE_NAME, createFakeBundle(), new int[]{10} /* userIds */,
|
||||
null /* instantUserIds */);
|
||||
|
||||
verify(callback, after(WAIT_CALLBACK_CALLED_IN_MS).never()).sendResult(any());
|
||||
}
|
||||
@@ -143,7 +147,7 @@ public class PackageMonitorCallbackHelperTest {
|
||||
mPackageMonitorCallbackHelper.registerPackageMonitorCallback(callback, 0 /* userId */);
|
||||
mPackageMonitorCallbackHelper.notifyPackageChanged(FAKE_PACKAGE_NAME,
|
||||
false /* dontKillApp */, components, FAKE_PACKAGE_UID, null /* reason */,
|
||||
new int[]{0} /* userIds */);
|
||||
new int[]{0} /* userIds */, null /* instantUserIds */);
|
||||
|
||||
ArgumentCaptor<Bundle> bundleCaptor = ArgumentCaptor.forClass(Bundle.class);
|
||||
verify(callback, after(WAIT_CALLBACK_CALLED_IN_MS).times(1)).sendResult(
|
||||
|
||||
Reference in New Issue
Block a user