Add direct reading/writing of contact phone number after PDD apporoval.
Test: Built and tested on device. Bug: 147782721 Change-Id: I496e39c447a02ebfb7bb1d3668656eada6a2a59f
This commit is contained in:
@@ -274,6 +274,10 @@ public class ConversationInfo {
|
||||
}
|
||||
protoOutputStream.write(ConversationInfoProto.SHORTCUT_FLAGS, mShortcutFlags);
|
||||
protoOutputStream.write(ConversationInfoProto.CONVERSATION_FLAGS, mConversationFlags);
|
||||
if (mContactPhoneNumber != null) {
|
||||
protoOutputStream.write(ConversationInfoProto.CONTACT_PHONE_NUMBER,
|
||||
mContactPhoneNumber);
|
||||
}
|
||||
}
|
||||
|
||||
/** Reads from {@link ProtoInputStream} and constructs a {@link ConversationInfo}. */
|
||||
@@ -315,6 +319,10 @@ public class ConversationInfo {
|
||||
builder.setConversationFlags(protoInputStream.readInt(
|
||||
ConversationInfoProto.CONVERSATION_FLAGS));
|
||||
break;
|
||||
case (int) ConversationInfoProto.CONTACT_PHONE_NUMBER:
|
||||
builder.setContactPhoneNumber(protoInputStream.readString(
|
||||
ConversationInfoProto.CONTACT_PHONE_NUMBER));
|
||||
break;
|
||||
default:
|
||||
Slog.w(TAG, "Could not read undefined field: "
|
||||
+ protoInputStream.getFieldNumber());
|
||||
|
||||
@@ -22,7 +22,6 @@ import android.annotation.Nullable;
|
||||
import android.annotation.WorkerThread;
|
||||
import android.content.LocusId;
|
||||
import android.net.Uri;
|
||||
import android.text.TextUtils;
|
||||
import android.util.ArrayMap;
|
||||
import android.util.Slog;
|
||||
import android.util.proto.ProtoInputStream;
|
||||
@@ -71,16 +70,13 @@ class ConversationStore {
|
||||
|
||||
private final ScheduledExecutorService mScheduledExecutorService;
|
||||
private final File mPackageDir;
|
||||
private final ContactsQueryHelper mHelper;
|
||||
|
||||
private ConversationInfosProtoDiskReadWriter mConversationInfosProtoDiskReadWriter;
|
||||
|
||||
ConversationStore(@NonNull File packageDir,
|
||||
@NonNull ScheduledExecutorService scheduledExecutorService,
|
||||
@NonNull ContactsQueryHelper helper) {
|
||||
@NonNull ScheduledExecutorService scheduledExecutorService) {
|
||||
mScheduledExecutorService = scheduledExecutorService;
|
||||
mPackageDir = packageDir;
|
||||
mHelper = helper;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -102,7 +98,6 @@ class ConversationStore {
|
||||
return;
|
||||
}
|
||||
for (ConversationInfo conversationInfo : conversationsOnDisk) {
|
||||
conversationInfo = restoreConversationPhoneNumber(conversationInfo);
|
||||
updateConversationsInMemory(conversationInfo);
|
||||
}
|
||||
}
|
||||
@@ -250,25 +245,6 @@ class ConversationStore {
|
||||
return mConversationInfosProtoDiskReadWriter;
|
||||
}
|
||||
|
||||
/**
|
||||
* Conversation's phone number is not saved on disk, so it has to be fetched.
|
||||
*/
|
||||
@WorkerThread
|
||||
private ConversationInfo restoreConversationPhoneNumber(
|
||||
@NonNull ConversationInfo conversationInfo) {
|
||||
if (conversationInfo.getContactUri() != null) {
|
||||
if (mHelper.query(conversationInfo.getContactUri().toString())) {
|
||||
String phoneNumber = mHelper.getPhoneNumber();
|
||||
if (!TextUtils.isEmpty(phoneNumber)) {
|
||||
conversationInfo = new ConversationInfo.Builder(
|
||||
conversationInfo).setContactPhoneNumber(
|
||||
phoneNumber).build();
|
||||
}
|
||||
}
|
||||
}
|
||||
return conversationInfo;
|
||||
}
|
||||
|
||||
/** Reads and writes {@link ConversationInfo}s on disk. */
|
||||
private static class ConversationInfosProtoDiskReadWriter extends
|
||||
AbstractProtoDiskReadWriter<List<ConversationInfo>> {
|
||||
|
||||
@@ -134,8 +134,7 @@ public class DataManager {
|
||||
public void onUserUnlocked(int userId) {
|
||||
UserData userData = mUserDataArray.get(userId);
|
||||
if (userData == null) {
|
||||
userData = new UserData(userId, mDiskReadWriterExecutor,
|
||||
mInjector.createContactsQueryHelper(mContext));
|
||||
userData = new UserData(userId, mDiskReadWriterExecutor);
|
||||
mUserDataArray.put(userId, userData);
|
||||
}
|
||||
userData.setUserUnlocked();
|
||||
|
||||
@@ -59,16 +59,14 @@ public class PackageData {
|
||||
@NonNull Predicate<String> isDefaultDialerPredicate,
|
||||
@NonNull Predicate<String> isDefaultSmsAppPredicate,
|
||||
@NonNull ScheduledExecutorService scheduledExecutorService,
|
||||
@NonNull File perUserPeopleDataDir,
|
||||
@NonNull ContactsQueryHelper helper) {
|
||||
@NonNull File perUserPeopleDataDir) {
|
||||
mPackageName = packageName;
|
||||
mUserId = userId;
|
||||
|
||||
mPackageDataDir = new File(perUserPeopleDataDir, mPackageName);
|
||||
mPackageDataDir.mkdirs();
|
||||
|
||||
mConversationStore = new ConversationStore(mPackageDataDir, scheduledExecutorService,
|
||||
helper);
|
||||
mConversationStore = new ConversationStore(mPackageDataDir, scheduledExecutorService);
|
||||
mEventStore = new EventStore(mPackageDataDir, scheduledExecutorService);
|
||||
mIsDefaultDialerPredicate = isDefaultDialerPredicate;
|
||||
mIsDefaultSmsAppPredicate = isDefaultSmsAppPredicate;
|
||||
@@ -83,8 +81,7 @@ public class PackageData {
|
||||
@NonNull Predicate<String> isDefaultDialerPredicate,
|
||||
@NonNull Predicate<String> isDefaultSmsAppPredicate,
|
||||
@NonNull ScheduledExecutorService scheduledExecutorService,
|
||||
@NonNull File perUserPeopleDataDir,
|
||||
@NonNull ContactsQueryHelper helper) {
|
||||
@NonNull File perUserPeopleDataDir) {
|
||||
Map<String, PackageData> results = new ArrayMap<>();
|
||||
File[] packageDirs = perUserPeopleDataDir.listFiles(File::isDirectory);
|
||||
if (packageDirs == null) {
|
||||
@@ -93,7 +90,7 @@ public class PackageData {
|
||||
for (File packageDir : packageDirs) {
|
||||
PackageData packageData = new PackageData(packageDir.getName(), userId,
|
||||
isDefaultDialerPredicate, isDefaultSmsAppPredicate, scheduledExecutorService,
|
||||
perUserPeopleDataDir, helper);
|
||||
perUserPeopleDataDir);
|
||||
packageData.loadFromDisk();
|
||||
results.put(packageDir.getName(), packageData);
|
||||
}
|
||||
|
||||
@@ -37,8 +37,6 @@ class UserData {
|
||||
|
||||
private final ScheduledExecutorService mScheduledExecutorService;
|
||||
|
||||
private final ContactsQueryHelper mHelper;
|
||||
|
||||
private boolean mIsUnlocked;
|
||||
|
||||
private Map<String, PackageData> mPackageDataMap = new ArrayMap<>();
|
||||
@@ -49,12 +47,10 @@ class UserData {
|
||||
@Nullable
|
||||
private String mDefaultSmsApp;
|
||||
|
||||
UserData(@UserIdInt int userId, @NonNull ScheduledExecutorService scheduledExecutorService,
|
||||
ContactsQueryHelper helper) {
|
||||
UserData(@UserIdInt int userId, @NonNull ScheduledExecutorService scheduledExecutorService) {
|
||||
mUserId = userId;
|
||||
mPerUserPeopleDataDir = new File(Environment.getDataSystemCeDirectory(mUserId), "people");
|
||||
mScheduledExecutorService = scheduledExecutorService;
|
||||
mHelper = helper;
|
||||
}
|
||||
|
||||
@UserIdInt int getUserId() {
|
||||
@@ -74,7 +70,7 @@ class UserData {
|
||||
// data from disk.
|
||||
mPerUserPeopleDataDir.mkdirs();
|
||||
mPackageDataMap.putAll(PackageData.packagesDataFromDisk(mUserId, this::isDefaultDialer,
|
||||
this::isDefaultSmsApp, mScheduledExecutorService, mPerUserPeopleDataDir, mHelper));
|
||||
this::isDefaultSmsApp, mScheduledExecutorService, mPerUserPeopleDataDir));
|
||||
}
|
||||
|
||||
void setUserStopped() {
|
||||
@@ -131,7 +127,7 @@ class UserData {
|
||||
|
||||
private PackageData createPackageData(String packageName) {
|
||||
return new PackageData(packageName, mUserId, this::isDefaultDialer, this::isDefaultSmsApp,
|
||||
mScheduledExecutorService, mPerUserPeopleDataDir, mHelper);
|
||||
mScheduledExecutorService, mPerUserPeopleDataDir);
|
||||
}
|
||||
|
||||
private boolean isDefaultDialer(String packageName) {
|
||||
|
||||
@@ -21,7 +21,6 @@ import static org.junit.Assert.assertNotNull;
|
||||
import static org.junit.Assert.assertNull;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
import android.annotation.Nullable;
|
||||
import android.content.Context;
|
||||
import android.content.LocusId;
|
||||
import android.content.pm.ShortcutInfo;
|
||||
@@ -63,7 +62,6 @@ public final class ConversationStoreTest {
|
||||
private static final String PHONE_NUMBER_3 = "+9234567890";
|
||||
|
||||
private MockScheduledExecutorService mMockScheduledExecutorService;
|
||||
private TestContactQueryHelper mTestContactQueryHelper;
|
||||
private ConversationStore mConversationStore;
|
||||
private File mFile;
|
||||
|
||||
@@ -71,7 +69,6 @@ public final class ConversationStoreTest {
|
||||
public void setUp() {
|
||||
Context ctx = InstrumentationRegistry.getContext();
|
||||
mFile = new File(ctx.getCacheDir(), "testdir");
|
||||
mTestContactQueryHelper = new TestContactQueryHelper(ctx);
|
||||
resetConversationStore();
|
||||
}
|
||||
|
||||
@@ -207,9 +204,6 @@ public final class ConversationStoreTest {
|
||||
mConversationStore.deleteConversation(SHORTCUT_ID_3);
|
||||
mMockScheduledExecutorService.fastForwardTime(3L * DateUtils.MINUTE_IN_MILLIS);
|
||||
|
||||
mTestContactQueryHelper.setQueryResult(true, true);
|
||||
mTestContactQueryHelper.setPhoneNumberResult(PHONE_NUMBER, PHONE_NUMBER_2);
|
||||
|
||||
resetConversationStore();
|
||||
ConversationInfo out1 = mConversationStore.getConversation(SHORTCUT_ID);
|
||||
ConversationInfo out2 = mConversationStore.getConversation(SHORTCUT_ID_2);
|
||||
@@ -240,9 +234,6 @@ public final class ConversationStoreTest {
|
||||
mConversationStore.addOrUpdate(in2);
|
||||
mMockScheduledExecutorService.fastForwardTime(DateUtils.MINUTE_IN_MILLIS);
|
||||
|
||||
mTestContactQueryHelper.setQueryResult(true);
|
||||
mTestContactQueryHelper.setPhoneNumberResult(PHONE_NUMBER);
|
||||
|
||||
resetConversationStore();
|
||||
ConversationInfo out1 = mConversationStore.getConversation(SHORTCUT_ID);
|
||||
ConversationInfo out2 = mConversationStore.getConversation(SHORTCUT_ID_2);
|
||||
@@ -256,10 +247,6 @@ public final class ConversationStoreTest {
|
||||
mConversationStore.addOrUpdate(in3);
|
||||
mMockScheduledExecutorService.fastForwardTime(3L * DateUtils.MINUTE_IN_MILLIS);
|
||||
|
||||
mTestContactQueryHelper.reset();
|
||||
mTestContactQueryHelper.setQueryResult(true, true, true);
|
||||
mTestContactQueryHelper.setPhoneNumberResult(PHONE_NUMBER, PHONE_NUMBER_2, PHONE_NUMBER_3);
|
||||
|
||||
resetConversationStore();
|
||||
out1 = mConversationStore.getConversation(SHORTCUT_ID);
|
||||
out2 = mConversationStore.getConversation(SHORTCUT_ID_2);
|
||||
@@ -290,9 +277,6 @@ public final class ConversationStoreTest {
|
||||
// loadConversationFromDisk gets called each time we call #resetConversationStore().
|
||||
assertEquals(2, mMockScheduledExecutorService.getExecutes().size());
|
||||
|
||||
mTestContactQueryHelper.setQueryResult(true, true);
|
||||
mTestContactQueryHelper.setPhoneNumberResult(PHONE_NUMBER, PHONE_NUMBER_2);
|
||||
|
||||
resetConversationStore();
|
||||
ConversationInfo out1 = mConversationStore.getConversation(SHORTCUT_ID);
|
||||
ConversationInfo out2 = mConversationStore.getConversation(SHORTCUT_ID_2);
|
||||
@@ -303,8 +287,7 @@ public final class ConversationStoreTest {
|
||||
private void resetConversationStore() {
|
||||
mFile.mkdir();
|
||||
mMockScheduledExecutorService = new MockScheduledExecutorService();
|
||||
mConversationStore = new ConversationStore(mFile, mMockScheduledExecutorService,
|
||||
mTestContactQueryHelper);
|
||||
mConversationStore = new ConversationStore(mFile, mMockScheduledExecutorService);
|
||||
mConversationStore.loadConversationsFromDisk();
|
||||
}
|
||||
|
||||
@@ -326,54 +309,4 @@ public final class ConversationStoreTest {
|
||||
.setBubbled(true)
|
||||
.build();
|
||||
}
|
||||
|
||||
private static class TestContactQueryHelper extends ContactsQueryHelper {
|
||||
|
||||
private int mQueryCalls;
|
||||
private boolean[] mQueryResult;
|
||||
|
||||
private int mPhoneNumberCalls;
|
||||
private String[] mPhoneNumberResult;
|
||||
|
||||
TestContactQueryHelper(Context context) {
|
||||
super(context);
|
||||
|
||||
mQueryCalls = 0;
|
||||
mPhoneNumberCalls = 0;
|
||||
}
|
||||
|
||||
private void setQueryResult(boolean... values) {
|
||||
mQueryResult = values;
|
||||
}
|
||||
|
||||
private void setPhoneNumberResult(String... values) {
|
||||
mPhoneNumberResult = values;
|
||||
}
|
||||
|
||||
private void reset() {
|
||||
mQueryCalls = 0;
|
||||
mQueryResult = null;
|
||||
mPhoneNumberCalls = 0;
|
||||
mPhoneNumberResult = null;
|
||||
}
|
||||
|
||||
@Override
|
||||
boolean query(String contactUri) {
|
||||
if (mQueryResult != null && mQueryCalls < mQueryResult.length) {
|
||||
return mQueryResult[mQueryCalls++];
|
||||
}
|
||||
mQueryCalls++;
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
@Nullable
|
||||
String getPhoneNumber() {
|
||||
if (mPhoneNumberResult != null && mPhoneNumberCalls < mPhoneNumberResult.length) {
|
||||
return mPhoneNumberResult[mPhoneNumberCalls++];
|
||||
}
|
||||
mPhoneNumberCalls++;
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -61,7 +61,7 @@ public final class PackageDataTest {
|
||||
testDir.mkdir();
|
||||
mPackageData = new PackageData(
|
||||
PACKAGE_NAME, USER_ID, pkg -> mIsDefaultDialer, pkg -> mIsDefaultSmsApp,
|
||||
new MockScheduledExecutorService(), testDir, new ContactsQueryHelper(ctx));
|
||||
new MockScheduledExecutorService(), testDir);
|
||||
ConversationInfo conversationInfo = new ConversationInfo.Builder()
|
||||
.setShortcutId(SHORTCUT_ID)
|
||||
.setLocusId(LOCUS_ID)
|
||||
|
||||
@@ -79,10 +79,9 @@ public final class UsageStatsQueryHelperTest {
|
||||
Context ctx = InstrumentationRegistry.getContext();
|
||||
File testDir = new File(ctx.getCacheDir(), "testdir");
|
||||
ScheduledExecutorService scheduledExecutorService = new MockScheduledExecutorService();
|
||||
ContactsQueryHelper helper = new ContactsQueryHelper(ctx);
|
||||
|
||||
mPackageData = new TestPackageData(PKG_NAME, USER_ID_PRIMARY, pkg -> false, pkg -> false,
|
||||
scheduledExecutorService, testDir, helper);
|
||||
scheduledExecutorService, testDir);
|
||||
mPackageData.mConversationStore.mConversationInfo = new ConversationInfo.Builder()
|
||||
.setShortcutId(SHORTCUT_ID)
|
||||
.setLocusId(LOCUS_ID_1)
|
||||
@@ -221,9 +220,8 @@ public final class UsageStatsQueryHelperTest {
|
||||
private ConversationInfo mConversationInfo;
|
||||
|
||||
TestConversationStore(File packageDir,
|
||||
ScheduledExecutorService scheduledExecutorService,
|
||||
ContactsQueryHelper helper) {
|
||||
super(packageDir, scheduledExecutorService, helper);
|
||||
ScheduledExecutorService scheduledExecutorService) {
|
||||
super(packageDir, scheduledExecutorService);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -241,12 +239,10 @@ public final class UsageStatsQueryHelperTest {
|
||||
TestPackageData(@NonNull String packageName, @UserIdInt int userId,
|
||||
@NonNull Predicate<String> isDefaultDialerPredicate,
|
||||
@NonNull Predicate<String> isDefaultSmsAppPredicate,
|
||||
@NonNull ScheduledExecutorService scheduledExecutorService, @NonNull File rootDir,
|
||||
@NonNull ContactsQueryHelper helper) {
|
||||
@NonNull ScheduledExecutorService scheduledExecutorService, @NonNull File rootDir) {
|
||||
super(packageName, userId, isDefaultDialerPredicate, isDefaultSmsAppPredicate,
|
||||
scheduledExecutorService, rootDir, helper);
|
||||
mConversationStore = new TestConversationStore(rootDir, scheduledExecutorService,
|
||||
helper);
|
||||
scheduledExecutorService, rootDir);
|
||||
mConversationStore = new TestConversationStore(rootDir, scheduledExecutorService);
|
||||
mEventStore = new TestEventStore(rootDir, scheduledExecutorService);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user