Bug 880171 - Part 1: return null if unable to retrieve storage in EnvironmentBuilder. r=nalexander

This commit is contained in:
Richard Newman 2013-06-07 10:20:58 -07:00
parent 7f89dd1fc5
commit d709778bb9

View File

@ -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 <code>null</code>.
*
* 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) {