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

Commit 49df92e2 authored by Victor Chang's avatar Victor Chang
Browse files

Cache directory photo in app storage through CachedNumberLookupService

[cherry-pick from ag/864046]

Photo of directory contact in call log should not require internet access.
It's now cached locally.

BUG=26111304

Change-Id: I9848e6fe9487c09899fd77f21804bcb4537799a8
parent f436fb5f
Loading
Loading
Loading
Loading
+16 −0
Original line number Diff line number Diff line
@@ -41,6 +41,8 @@ import com.android.dialer.service.CachedNumberLookupService;
import com.android.dialer.service.CachedNumberLookupService.CachedContactInfo;
import com.android.dialerbind.ObjectFactory;

import java.io.IOException;
import java.io.InputStream;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Locale;
@@ -520,11 +522,25 @@ public class CallerInfoAsyncQuery {

        private void addCallerInfoIntoCache(CallerInfo ci, long directoryId) {
            if (ci.contactExists && mCachedNumberLookupService != null) {
                // 1. Cache caller info
                CachedContactInfo cachedContactInfo = CallerInfoUtils
                        .buildCachedContactInfo(mCachedNumberLookupService, ci);
                String directoryLabel = mContext.getString(R.string.directory_search_label);
                cachedContactInfo.setDirectorySource(directoryLabel, directoryId);
                mCachedNumberLookupService.addContact(mContext, cachedContactInfo);

                // 2. Cache photo
                if (ci.contactDisplayPhotoUri != null && ci.normalizedNumber != null) {
                    try (InputStream in = mContext.getContentResolver()
                            .openInputStream(ci.contactDisplayPhotoUri)) {
                        if (in != null) {
                            mCachedNumberLookupService.addPhoto(mContext, ci.normalizedNumber, in);
                        }
                    } catch (IOException e) {
                        Log.e(LOG_TAG, "failed to fetch directory contact photo", e);
                    }

                }
            }
        }