Merge "Allow PeopleService to make blocking binder calls" into rvc-dev am: 4c0a5e276e

Change-Id: I12f93f2cb32ca2ceed7bbe2822988ee3c36554e2
This commit is contained in:
Automerger Merge Worker
2020-03-11 00:45:06 +00:00
2 changed files with 55 additions and 43 deletions

View File

@@ -21,6 +21,7 @@ import android.annotation.WorkerThread;
import android.content.Context; import android.content.Context;
import android.database.Cursor; import android.database.Cursor;
import android.net.Uri; import android.net.Uri;
import android.os.Binder;
import android.provider.Telephony.BaseMmsColumns; import android.provider.Telephony.BaseMmsColumns;
import android.provider.Telephony.Mms; import android.provider.Telephony.Mms;
import android.telephony.PhoneNumberUtils; import android.telephony.PhoneNumberUtils;
@@ -71,31 +72,36 @@ class MmsQueryHelper {
// NOTE: The field Mms.DATE is stored in seconds, not milliseconds. // NOTE: The field Mms.DATE is stored in seconds, not milliseconds.
String[] selectionArgs = new String[] { Long.toString(sinceTime / MILLIS_PER_SECONDS) }; String[] selectionArgs = new String[] { Long.toString(sinceTime / MILLIS_PER_SECONDS) };
boolean hasResults = false; boolean hasResults = false;
try (Cursor cursor = mContext.getContentResolver().query( Binder.allowBlockingForCurrentThread();
Mms.CONTENT_URI, projection, selection, selectionArgs, null)) { try {
if (cursor == null) { try (Cursor cursor = mContext.getContentResolver().query(
Slog.w(TAG, "Cursor is null when querying MMS table."); Mms.CONTENT_URI, projection, selection, selectionArgs, null)) {
return false; if (cursor == null) {
} Slog.w(TAG, "Cursor is null when querying MMS table.");
while (cursor.moveToNext()) { return false;
// ID }
int msgIdIndex = cursor.getColumnIndex(Mms._ID); while (cursor.moveToNext()) {
String msgId = cursor.getString(msgIdIndex); // ID
int msgIdIndex = cursor.getColumnIndex(Mms._ID);
String msgId = cursor.getString(msgIdIndex);
// Date // Date
int dateIndex = cursor.getColumnIndex(Mms.DATE); int dateIndex = cursor.getColumnIndex(Mms.DATE);
long date = cursor.getLong(dateIndex) * MILLIS_PER_SECONDS; long date = cursor.getLong(dateIndex) * MILLIS_PER_SECONDS;
// Message box // Message box
int msgBoxIndex = cursor.getColumnIndex(Mms.MESSAGE_BOX); int msgBoxIndex = cursor.getColumnIndex(Mms.MESSAGE_BOX);
int msgBox = cursor.getInt(msgBoxIndex); int msgBox = cursor.getInt(msgBoxIndex);
mLastMessageTimestamp = Math.max(mLastMessageTimestamp, date); mLastMessageTimestamp = Math.max(mLastMessageTimestamp, date);
String address = getMmsAddress(msgId, msgBox); String address = getMmsAddress(msgId, msgBox);
if (address != null && addEvent(address, date, msgBox)) { if (address != null && addEvent(address, date, msgBox)) {
hasResults = true; hasResults = true;
}
} }
} }
} finally {
Binder.defaultBlockingForCurrentThread();
} }
return hasResults; return hasResults;
} }

View File

@@ -19,6 +19,7 @@ package com.android.server.people.data;
import android.annotation.WorkerThread; import android.annotation.WorkerThread;
import android.content.Context; import android.content.Context;
import android.database.Cursor; import android.database.Cursor;
import android.os.Binder;
import android.provider.Telephony.Sms; import android.provider.Telephony.Sms;
import android.provider.Telephony.TextBasedSmsColumns; import android.provider.Telephony.TextBasedSmsColumns;
import android.telephony.PhoneNumberUtils; import android.telephony.PhoneNumberUtils;
@@ -65,35 +66,40 @@ class SmsQueryHelper {
String selection = Sms.DATE + " > ?"; String selection = Sms.DATE + " > ?";
String[] selectionArgs = new String[] { Long.toString(sinceTime) }; String[] selectionArgs = new String[] { Long.toString(sinceTime) };
boolean hasResults = false; boolean hasResults = false;
try (Cursor cursor = mContext.getContentResolver().query( Binder.allowBlockingForCurrentThread();
Sms.CONTENT_URI, projection, selection, selectionArgs, null)) { try {
if (cursor == null) { try (Cursor cursor = mContext.getContentResolver().query(
Slog.w(TAG, "Cursor is null when querying SMS table."); Sms.CONTENT_URI, projection, selection, selectionArgs, null)) {
return false; if (cursor == null) {
} Slog.w(TAG, "Cursor is null when querying SMS table.");
while (cursor.moveToNext()) { return false;
// ID }
int msgIdIndex = cursor.getColumnIndex(Sms._ID); while (cursor.moveToNext()) {
String msgId = cursor.getString(msgIdIndex); // ID
int msgIdIndex = cursor.getColumnIndex(Sms._ID);
String msgId = cursor.getString(msgIdIndex);
// Date // Date
int dateIndex = cursor.getColumnIndex(Sms.DATE); int dateIndex = cursor.getColumnIndex(Sms.DATE);
long date = cursor.getLong(dateIndex); long date = cursor.getLong(dateIndex);
// Type // Type
int typeIndex = cursor.getColumnIndex(Sms.TYPE); int typeIndex = cursor.getColumnIndex(Sms.TYPE);
int type = cursor.getInt(typeIndex); int type = cursor.getInt(typeIndex);
// Address // Address
int addressIndex = cursor.getColumnIndex(Sms.ADDRESS); int addressIndex = cursor.getColumnIndex(Sms.ADDRESS);
String address = PhoneNumberUtils.formatNumberToE164( String address = PhoneNumberUtils.formatNumberToE164(
cursor.getString(addressIndex), mCurrentCountryIso); cursor.getString(addressIndex), mCurrentCountryIso);
mLastMessageTimestamp = Math.max(mLastMessageTimestamp, date); mLastMessageTimestamp = Math.max(mLastMessageTimestamp, date);
if (address != null && addEvent(address, date, type)) { if (address != null && addEvent(address, date, type)) {
hasResults = true; hasResults = true;
}
} }
} }
} finally {
Binder.defaultBlockingForCurrentThread();
} }
return hasResults; return hasResults;
} }