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.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;
}

View File

@@ -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;
}