From 58919c2912941ac0a2ee8c8a927feef1596141b9 Mon Sep 17 00:00:00 2001 From: cketti Date: Sat, 2 Feb 2013 04:13:26 +0100 Subject: [PATCH] Fix accessing the unread count using MessageProvider Thanks to teslacoil for diagnosing the problem and coming up with a fix. --- src/com/fsck/k9/provider/MessageProvider.java | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/src/com/fsck/k9/provider/MessageProvider.java b/src/com/fsck/k9/provider/MessageProvider.java index 7035baa65..94442704a 100644 --- a/src/com/fsck/k9/provider/MessageProvider.java +++ b/src/com/fsck/k9/provider/MessageProvider.java @@ -13,6 +13,7 @@ import android.database.CursorWindow; import android.database.DataSetObserver; import android.database.MatrixCursor; import android.net.Uri; +import android.os.Binder; import android.os.Bundle; import android.provider.BaseColumns; import android.util.Log; @@ -460,10 +461,22 @@ public class MessageProvider extends ContentProvider { int accountId = -1; segments = uri.getPathSegments(); accountId = Integer.parseInt(segments.get(1)); - return getAccountUnread(accountId); + + /* + * This method below calls Account.getStats() which uses EmailProvider to do its work. + * For this to work we need to clear the calling identity. Otherwise accessing + * EmailProvider will fail because it's not exported so third-party apps can't access it + * directly. + */ + long identityToken = Binder.clearCallingIdentity(); + try { + return getAccountUnread(accountId); + } finally { + Binder.restoreCallingIdentity(identityToken); + } } - public Cursor getAccountUnread(int accountNumber) { + private Cursor getAccountUnread(int accountNumber) { String[] projection = new String[] { "accountName", "unread" }; MatrixCursor ret = new MatrixCursor(projection);