diff options
author | Dmitri Plotnikov <dplotnikov@google.com> | 2020-03-10 10:50:02 -0700 |
---|---|---|
committer | Dmitri Plotnikov <dplotnikov@google.com> | 2020-03-10 22:59:05 +0000 |
commit | 261d5d65fdb7eece7656dc2cd340c674cc45e1ce (patch) | |
tree | 43b31e147c5a12fd9c63b77a579d82bfb99ca127 | |
parent | 086cd7706c53b1a32b0dadd6b2b4881fc33d5bbb (diff) |
Allow PeopleService to make blocking binder calls
Bug: 149788799
Test: presubmit
Change-Id: Ia23c96ce34942e95b029240e0d087b614e19b0f4
-rw-r--r-- | services/people/java/com/android/server/people/data/MmsQueryHelper.java | 52 | ||||
-rw-r--r-- | services/people/java/com/android/server/people/data/SmsQueryHelper.java | 60 |
2 files changed, 62 insertions, 50 deletions
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 1e485c082d18..39dba9c73ba2 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); - - // 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); - - mLastMessageTimestamp = Math.max(mLastMessageTimestamp, date); - String address = getMmsAddress(msgId, msgBox); - if (address != null && addEvent(address, date, msgBox)) { - hasResults = true; + 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; + + // 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; + } } } + } 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 c38c846bf461..a5eb3a581616 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); - - // Date - int dateIndex = cursor.getColumnIndex(Sms.DATE); - long date = cursor.getLong(dateIndex); - - // 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); - - mLastMessageTimestamp = Math.max(mLastMessageTimestamp, date); - if (address != null && addEvent(address, date, type)) { - hasResults = true; + 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); + + // 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); + + mLastMessageTimestamp = Math.max(mLastMessageTimestamp, date); + if (address != null && addEvent(address, date, type)) { + hasResults = true; + } } } + } finally { + Binder.defaultBlockingForCurrentThread(); } return hasResults; } |