Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 92b8a72d authored by Trung Lam's avatar Trung Lam
Browse files

Add direct reading/writing of contact phone number after PDD apporoval.

Test: Built and tested on device.
Bug: 147782721
Change-Id: I496e39c447a02ebfb7bb1d3668656eada6a2a59f
parent fda6d338
Loading
Loading
Loading
Loading
+8 −0
Original line number Diff line number Diff line
@@ -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());
+1 −25
Original line number Diff line number Diff line
@@ -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>> {
+1 −2
Original line number Diff line number Diff line
@@ -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();
+4 −7
Original line number Diff line number Diff line
@@ -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);
        }
+3 −7
Original line number Diff line number Diff line
@@ -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) {
Loading