diff --git a/services/people/java/com/android/server/people/data/MmsQueryHelper.java b/services/people/java/com/android/server/people/data/MmsQueryHelper.java index 1e485c082d189..39dba9c73ba28 100644 --- a/services/people/java/com/android/server/people/data/MmsQueryHelper.java +++ b/services/people/java/com/android/server/people/data/MmsQueryHelper.java @@ -21,6 +21,7 @@ import android.annotation.WorkerThread; import android.content.Context; import android.database.Cursor; import android.net.Uri; +import android.os.Binder; import android.provider.Telephony.BaseMmsColumns; import android.provider.Telephony.Mms; import android.telephony.PhoneNumberUtils; @@ -71,31 +72,36 @@ class MmsQueryHelper { // NOTE: The field Mms.DATE is stored in seconds, not milliseconds. String[] selectionArgs = new String[] { Long.toString(sinceTime / MILLIS_PER_SECONDS) }; boolean hasResults = false; - try (Cursor cursor = mContext.getContentResolver().query( - Mms.CONTENT_URI, projection, selection, selectionArgs, null)) { - if (cursor == null) { - Slog.w(TAG, "Cursor is null when querying MMS table."); - return false; - } - while (cursor.moveToNext()) { - // ID - int msgIdIndex = cursor.getColumnIndex(Mms._ID); - String msgId = cursor.getString(msgIdIndex); + Binder.allowBlockingForCurrentThread(); + try { + try (Cursor cursor = mContext.getContentResolver().query( + Mms.CONTENT_URI, projection, selection, selectionArgs, null)) { + if (cursor == null) { + Slog.w(TAG, "Cursor is null when querying MMS table."); + return false; + } + while (cursor.moveToNext()) { + // ID + int msgIdIndex = cursor.getColumnIndex(Mms._ID); + String msgId = cursor.getString(msgIdIndex); - // Date - int dateIndex = cursor.getColumnIndex(Mms.DATE); - long date = cursor.getLong(dateIndex) * MILLIS_PER_SECONDS; + // Date + int dateIndex = cursor.getColumnIndex(Mms.DATE); + long date = cursor.getLong(dateIndex) * MILLIS_PER_SECONDS; - // Message box - int msgBoxIndex = cursor.getColumnIndex(Mms.MESSAGE_BOX); - int msgBox = cursor.getInt(msgBoxIndex); + // Message box + int msgBoxIndex = cursor.getColumnIndex(Mms.MESSAGE_BOX); + int msgBox = cursor.getInt(msgBoxIndex); - mLastMessageTimestamp = Math.max(mLastMessageTimestamp, date); - String address = getMmsAddress(msgId, msgBox); - if (address != null && addEvent(address, date, msgBox)) { - hasResults = true; + mLastMessageTimestamp = Math.max(mLastMessageTimestamp, date); + String address = getMmsAddress(msgId, msgBox); + if (address != null && addEvent(address, date, msgBox)) { + hasResults = true; + } } } + } finally { + Binder.defaultBlockingForCurrentThread(); } return hasResults; } diff --git a/services/people/java/com/android/server/people/data/SmsQueryHelper.java b/services/people/java/com/android/server/people/data/SmsQueryHelper.java index c38c846bf461e..a5eb3a5816160 100644 --- a/services/people/java/com/android/server/people/data/SmsQueryHelper.java +++ b/services/people/java/com/android/server/people/data/SmsQueryHelper.java @@ -19,6 +19,7 @@ package com.android.server.people.data; import android.annotation.WorkerThread; import android.content.Context; import android.database.Cursor; +import android.os.Binder; import android.provider.Telephony.Sms; import android.provider.Telephony.TextBasedSmsColumns; import android.telephony.PhoneNumberUtils; @@ -65,35 +66,40 @@ class SmsQueryHelper { String selection = Sms.DATE + " > ?"; String[] selectionArgs = new String[] { Long.toString(sinceTime) }; boolean hasResults = false; - try (Cursor cursor = mContext.getContentResolver().query( - Sms.CONTENT_URI, projection, selection, selectionArgs, null)) { - if (cursor == null) { - Slog.w(TAG, "Cursor is null when querying SMS table."); - return false; - } - while (cursor.moveToNext()) { - // ID - int msgIdIndex = cursor.getColumnIndex(Sms._ID); - String msgId = cursor.getString(msgIdIndex); + Binder.allowBlockingForCurrentThread(); + try { + try (Cursor cursor = mContext.getContentResolver().query( + Sms.CONTENT_URI, projection, selection, selectionArgs, null)) { + if (cursor == null) { + Slog.w(TAG, "Cursor is null when querying SMS table."); + return false; + } + while (cursor.moveToNext()) { + // ID + int msgIdIndex = cursor.getColumnIndex(Sms._ID); + String msgId = cursor.getString(msgIdIndex); - // Date - int dateIndex = cursor.getColumnIndex(Sms.DATE); - long date = cursor.getLong(dateIndex); + // Date + int dateIndex = cursor.getColumnIndex(Sms.DATE); + long date = cursor.getLong(dateIndex); - // Type - int typeIndex = cursor.getColumnIndex(Sms.TYPE); - int type = cursor.getInt(typeIndex); + // Type + int typeIndex = cursor.getColumnIndex(Sms.TYPE); + int type = cursor.getInt(typeIndex); - // Address - int addressIndex = cursor.getColumnIndex(Sms.ADDRESS); - String address = PhoneNumberUtils.formatNumberToE164( - cursor.getString(addressIndex), mCurrentCountryIso); + // Address + int addressIndex = cursor.getColumnIndex(Sms.ADDRESS); + String address = PhoneNumberUtils.formatNumberToE164( + cursor.getString(addressIndex), mCurrentCountryIso); - mLastMessageTimestamp = Math.max(mLastMessageTimestamp, date); - if (address != null && addEvent(address, date, type)) { - hasResults = true; + mLastMessageTimestamp = Math.max(mLastMessageTimestamp, date); + if (address != null && addEvent(address, date, type)) { + hasResults = true; + } } } + } finally { + Binder.defaultBlockingForCurrentThread(); } return hasResults; }