Test for null package in isEnabledAndMatches()

Bug: 188174037

Avoid an NPE is isEnabledAndMatches() by returning false if no package
is found matching the component name.

This does not address the more general problem uncovered by the bug,
which is that a thread that has multiple calls into PM on the stack
might end up executing with different snapshots.

Test: atest
 * CtsContentTestCases
Change-Id: Ib4e929a62edf3393e0177f5d85c9b3fe1e0697d8
This commit is contained in:
Lee Shombert
2021-05-20 13:15:40 -07:00
parent f5098669d7
commit ff9a01834e

View File

@@ -26543,11 +26543,17 @@ public class PackageManagerService extends IPackageManager.Stub
}
}
// TODO(188814480) should be able to remove the NPE check when snapshot
// "recursion" is fixed.
@Override
public boolean isEnabledAndMatches(ParsedMainComponent component, int flags, int userId) {
synchronized (mLock) {
AndroidPackage pkg = getPackage(component.getPackageName());
return mSettings.isEnabledAndMatchLPr(pkg, component, flags, userId);
if (pkg == null) {
return false;
} else {
return mSettings.isEnabledAndMatchLPr(pkg, component, flags, userId);
}
}
}