Bug 1373873 - Guard against a nullable cursor r=nechen
MozReview-Commit-ID: HlherFzKfNW
--- a/mobile/android/base/java/org/mozilla/gecko/db/BrowserDB.java
+++ b/mobile/android/base/java/org/mozilla/gecko/db/BrowserDB.java
@@ -85,19 +85,19 @@ public abstract class BrowserDB {
*/
public abstract Cursor getAllVisitedHistory(ContentResolver cr);
/**
* Can return <code>null</code>.
*/
public abstract Cursor getRecentHistory(ContentResolver cr, int limit);
- public abstract Cursor getHistoryForURL(ContentResolver cr, String uri);
public abstract Cursor getRecentHistoryBetweenTime(ContentResolver cr, int historyLimit, long start, long end);
+ @Nullable public abstract Cursor getHistoryForURL(ContentResolver cr, String uri);
public abstract long getPrePathLastVisitedTimeMilliseconds(ContentResolver cr, String prePath);
public abstract void expireHistory(ContentResolver cr, ExpirePriority priority);
public abstract void removeHistoryEntry(ContentResolver cr, String url);
public abstract void clearHistory(ContentResolver cr, boolean clearSearchHistory);
--- a/mobile/android/base/java/org/mozilla/gecko/db/LocalBrowserDB.java
+++ b/mobile/android/base/java/org/mozilla/gecko/db/LocalBrowserDB.java
@@ -804,16 +804,17 @@ public class LocalBrowserDB extends Brow
Combined.TITLE,
Combined.DATE_LAST_VISITED,
Combined.VISITS },
History.DATE_LAST_VISITED + " >= " + start + " AND " + History.DATE_LAST_VISITED + " < " + end,
null,
History.DATE_LAST_VISITED + " DESC");
}
+ @Nullable
public Cursor getHistoryForURL(ContentResolver cr, String uri) {
return cr.query(mHistoryUriWithProfile,
new String[] {
History.VISITS,
History.DATE_LAST_VISITED
},
History.URL + "= ?",
new String[] { uri },
--- a/mobile/android/base/java/org/mozilla/gecko/promotion/AddToHomeScreenPromotion.java
+++ b/mobile/android/base/java/org/mozilla/gecko/promotion/AddToHomeScreenPromotion.java
@@ -5,16 +5,17 @@
package org.mozilla.gecko.promotion;
import android.app.Activity;
import android.content.Context;
import android.database.Cursor;
import android.os.Bundle;
import android.support.annotation.CallSuper;
+import android.support.annotation.Nullable;
import android.util.Log;
import org.mozilla.gecko.switchboard.SwitchBoard;
import org.json.JSONException;
import org.json.JSONObject;
import org.mozilla.gecko.AboutPages;
import org.mozilla.gecko.BrowserApp;
@@ -208,24 +209,29 @@ public class AddToHomeScreenPromotion ex
return true;
}
protected boolean hasAcceptedOrDeclinedHomeScreenShortcut(Context context, String url) {
final UrlAnnotations urlAnnotations = BrowserDB.from(context).getUrlAnnotations();
return urlAnnotations.hasAcceptedOrDeclinedHomeScreenShortcut(context.getContentResolver(), url);
}
+ @Nullable
public static URLHistory getHistoryForURL(Context context, String url) {
final GeckoProfile profile = GeckoProfile.get(context);
final BrowserDB browserDB = BrowserDB.from(profile);
Cursor cursor = null;
try {
cursor = browserDB.getHistoryForURL(context.getContentResolver(), url);
+ if (cursor == null) {
+ return null;
+ }
+
if (cursor.moveToFirst()) {
return new URLHistory(
cursor.getInt(cursor.getColumnIndex(BrowserContract.History.VISITS)),
cursor.getLong(cursor.getColumnIndex(BrowserContract.History.DATE_LAST_VISITED)));
}
} finally {
if (cursor != null) {
cursor.close();