From d12f78d6bac81590f97fc190723865ffe65e5d69 Mon Sep 17 00:00:00 2001 From: Marc Blank Date: Wed, 22 Jun 2011 10:59:06 -0700 Subject: [PATCH] Fix cursor-related errors: 1) Have CachedCursor implement CrossProcessCursor; still need to figure out how this ever worked 2) Close cursor used internally in findMailboxOfType Bug: 4869024 Change-Id: Id20d37b7b83e133aa4d5fe9293a42ae217024f01 --- .../android/emailcommon/provider/Mailbox.java | 19 +++++++++++++------ .../android/email/provider/ContentCache.java | 19 ++++++++++++++++++- 2 files changed, 31 insertions(+), 7 deletions(-) diff --git a/emailcommon/src/com/android/emailcommon/provider/Mailbox.java b/emailcommon/src/com/android/emailcommon/provider/Mailbox.java index a3d8daae9..946c0d05d 100644 --- a/emailcommon/src/com/android/emailcommon/provider/Mailbox.java +++ b/emailcommon/src/com/android/emailcommon/provider/Mailbox.java @@ -315,12 +315,19 @@ public class Mailbox extends EmailContent implements SyncColumns, MailboxColumns Uri uri = FROM_ACCOUNT_AND_TYPE_URI.buildUpon().appendPath(Long.toString(accountId)) .appendPath(Integer.toString(type)).build(); Cursor c = context.getContentResolver().query(uri, ID_PROJECTION, null, null, null); - c.moveToFirst(); - Long mailboxId = c.getLong(ID_PROJECTION_COLUMN); - if (mailboxId != null && mailboxId.intValue() != 0) { - return mailboxId; - } else { - Log.w(Logging.LOG_TAG, "========== Mailbox of type " + type + " not found in cache??"); + if (c != null) { + try { + c.moveToFirst(); + Long mailboxId = c.getLong(ID_PROJECTION_COLUMN); + if (mailboxId != null && mailboxId.intValue() != 0) { + return mailboxId; + } else { + Log.w(Logging.LOG_TAG, "========== Mailbox of type " + type + + " not found in cache"); + } + } finally { + c.close(); + } } String[] bindArguments = new String[] {Long.toString(type), Long.toString(accountId)}; return Utility.getFirstRowLong(context, Mailbox.CONTENT_URI, diff --git a/src/com/android/email/provider/ContentCache.java b/src/com/android/email/provider/ContentCache.java index 492fc8e98..11ad179a5 100644 --- a/src/com/android/email/provider/ContentCache.java +++ b/src/com/android/email/provider/ContentCache.java @@ -17,7 +17,9 @@ package com.android.email.provider; import android.content.ContentValues; +import android.database.CrossProcessCursor; import android.database.Cursor; +import android.database.CursorWindow; import android.database.CursorWrapper; import android.database.MatrixCursor; import android.net.Uri; @@ -275,7 +277,7 @@ public final class ContentCache { * Multiple CachedCursor's can use the same underlying cursor, so we override the various * moveX methods such that each CachedCursor can have its own position information */ - public static final class CachedCursor extends CursorWrapper { + public static final class CachedCursor extends CursorWrapper implements CrossProcessCursor { // The cursor we're wrapping private final Cursor mCursor; // The cache which generated this cursor @@ -381,6 +383,21 @@ public final class ContentCache { public final boolean isAfterLast() { return mPosition == 1; } + + @Override + public CursorWindow getWindow() { + return ((CrossProcessCursor)mCursor).getWindow(); + } + + @Override + public void fillWindow(int pos, CursorWindow window) { + ((CrossProcessCursor)mCursor).fillWindow(pos, window); + } + + @Override + public boolean onMove(int oldPosition, int newPosition) { + return ((CrossProcessCursor)mCursor).onMove(oldPosition, newPosition); + } } /**