From 1eeddaf502b8d5f6ef613875191ddea91cc6aa79 Mon Sep 17 00:00:00 2001 From: Anthony Restaino Date: Wed, 4 Nov 2015 23:33:45 -0500 Subject: [PATCH] Fix crash that could occur pre API 16 --- .../acr/browser/lightning/utils/Utils.java | 24 +++++++++++++++++-- 1 file changed, 22 insertions(+), 2 deletions(-) diff --git a/app/src/main/java/acr/browser/lightning/utils/Utils.java b/app/src/main/java/acr/browser/lightning/utils/Utils.java index 43bd90a..7681877 100644 --- a/app/src/main/java/acr/browser/lightning/utils/Utils.java +++ b/app/src/main/java/acr/browser/lightning/utils/Utils.java @@ -12,6 +12,7 @@ import android.content.Intent; import android.content.pm.ApplicationInfo; import android.content.pm.PackageManager; import android.content.res.Resources; +import android.database.Cursor; import android.graphics.Bitmap; import android.graphics.Canvas; import android.graphics.Color; @@ -29,6 +30,9 @@ import android.util.Log; import android.view.View; import android.webkit.URLUtil; +import com.anthonycr.grant.PermissionsManager; +import com.anthonycr.grant.PermissionsResultAction; + import java.io.Closeable; import java.io.File; import java.io.IOException; @@ -40,8 +44,6 @@ import java.util.Date; import acr.browser.lightning.R; import acr.browser.lightning.constant.Constants; import acr.browser.lightning.download.DownloadHandler; -import com.anthonycr.grant.PermissionsManager; -import com.anthonycr.grant.PermissionsResultAction; public final class Utils { @@ -274,6 +276,24 @@ public final class Utils { } } + /** + * Utility method to close cursors. Cursor did not + * implement Closeable until API 16, so using this + * method for when we want to close a cursor. + * + * @param cursor the cursor to close + */ + public static void close(Cursor cursor) { + if (cursor == null) { + return; + } + try { + cursor.close(); + } catch (Exception e) { + e.printStackTrace(); + } + } + /** * Draws the trapezoid background for the horizontal tabs on a canvas object using * the specified color.