mirror of
https://github.com/moparisthebest/k-9
synced 2024-11-23 18:02:15 -05:00
Fix accessing the unread count using MessageProvider
Thanks to teslacoil for diagnosing the problem and coming up with a fix.
This commit is contained in:
parent
1ab04587a9
commit
58919c2912
@ -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));
|
||||
|
||||
/*
|
||||
* 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);
|
||||
|
Loading…
Reference in New Issue
Block a user