diff --git a/mobile/android/base/background/healthreport/EnvironmentBuilder.java b/mobile/android/base/background/healthreport/EnvironmentBuilder.java index 080d8b34383..9d223d54af2 100644 --- a/mobile/android/base/background/healthreport/EnvironmentBuilder.java +++ b/mobile/android/base/background/healthreport/EnvironmentBuilder.java @@ -27,9 +27,22 @@ public class EnvironmentBuilder { return cr.acquireContentProviderClient(HealthReportConstants.HEALTH_AUTHORITY); } + /** + * Fetch the storage object associated with the provided + * {@link ContentProviderClient}. If no storage instance can be found -- + * perhaps because the {@link ContentProvider} is running in a different + * process -- returns null. + * + * If the provider is not a {@link HealthReportProvider}, throws a + * {@link ClassCastException}, because that would be disastrous. + */ public static HealthReportDatabaseStorage getStorage(ContentProviderClient cpc, String profilePath) { ContentProvider pr = cpc.getLocalContentProvider(); + if (pr == null) { + Logger.error(LOG_TAG, "Unable to retrieve local content provider. Running in a different process?"); + return null; + } try { return ((HealthReportProvider) pr).getProfileStorage(profilePath); } catch (ClassCastException ex) {