Commit e4ddfe60 authored by Yusuf Ozuysal's avatar Yusuf Ozuysal Committed by Commit Bot

Speculative null check for getAssetStatements

We are getting an NPE on stable for getAssetStatements and it is not
entirely clear from where from the crash stack. The metadata being null
here seems to be the most likely culprit. Adding a null check for that
as a bandaid fix.

BUG=787831
TBR=mariakhomenko@chromium.org

Change-Id: Ie538e4dda791de27d87c2359671037fa75fcc12b
Reviewed-on: https://chromium-review.googlesource.com/802089
Commit-Queue: Yusuf Ozuysal <yusufo@chromium.org>
Reviewed-by: default avatarMatt Giuca <mgiuca@chromium.org>
Cr-Commit-Position: refs/heads/master@{#520805}
parent a0f64459
......@@ -250,6 +250,10 @@ public class InstalledAppProviderImpl implements InstalledAppProvider {
// Get the <meta-data> from this app's manifest.
// Throws NameNotFoundException if the application is not installed.
ApplicationInfo appInfo = pm.getApplicationInfo(packageName, PackageManager.GET_META_DATA);
if (appInfo == null || appInfo.metaData == null) {
return new JSONArray();
}
int identifier = appInfo.metaData.getInt(ASSET_STATEMENTS_KEY);
if (identifier == 0) {
return new JSONArray();
......
......@@ -438,6 +438,19 @@ public class InstalledAppProviderTest {
verifyInstalledApps(manifestRelatedApps, expectedInstalledRelatedApps);
}
/** One related Android app; Android app is not mutually related (has no asset_statements). */
@Test
@Feature({"InstalledApp"})
public void testOneRelatedAppNoAssetStatementsNullMetadata() {
RelatedApplication manifestRelatedApps[] = new RelatedApplication[] {
createRelatedApplication(PLATFORM_ANDROID, PACKAGE_NAME_1, null)};
FakeResources resources = new FakeResources(0x4321, null);
setMetaDataAndResourcesForTest(PACKAGE_NAME_1, null, resources);
RelatedApplication[] expectedInstalledRelatedApps = new RelatedApplication[] {};
verifyInstalledApps(manifestRelatedApps, expectedInstalledRelatedApps);
}
/**
* One related Android app; Android app is related to other origins.
*
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment