1 /* 2 * Copyright (C) 2016 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17 package com.android.dialer.phonenumbercache; 18 19 import android.content.Context; 20 import android.net.Uri; 21 import android.support.annotation.NonNull; 22 import android.support.annotation.Nullable; 23 import android.support.annotation.WorkerThread; 24 import com.android.dialer.logging.ContactSource; 25 import java.io.InputStream; 26 27 public interface CachedNumberLookupService { 28 buildCachedContactInfo(ContactInfo info)29 CachedContactInfo buildCachedContactInfo(ContactInfo info); 30 31 /** 32 * Perform a lookup using the cached number lookup service to return contact information stored in 33 * the cache that corresponds to the given number. 34 * 35 * @param context Valid context 36 * @param number Phone number to lookup the cache for 37 * @return A {@link CachedContactInfo} containing the contact information if the phone number is 38 * found in the cache, {@link ContactInfo#EMPTY} if the phone number was not found in the 39 * cache, and null if there was an error when querying the cache. 40 */ 41 @WorkerThread lookupCachedContactFromNumber(Context context, String number)42 CachedContactInfo lookupCachedContactFromNumber(Context context, String number); 43 addContact(Context context, CachedContactInfo info)44 void addContact(Context context, CachedContactInfo info); 45 isBusiness(ContactSource.Type sourceType)46 boolean isBusiness(ContactSource.Type sourceType); 47 canReportAsInvalid(ContactSource.Type sourceType, String objectId)48 boolean canReportAsInvalid(ContactSource.Type sourceType, String objectId); 49 reportAsInvalid(Context context, CachedContactInfo cachedContactInfo)50 boolean reportAsInvalid(Context context, CachedContactInfo cachedContactInfo); 51 52 /** @return return {@link Uri} to the photo or return {@code null} when failing to add photo */ 53 @Nullable addPhoto(Context context, String number, InputStream in)54 Uri addPhoto(Context context, String number, InputStream in); 55 56 /** 57 * Remove all cached phone number entries from the cache, regardless of how old they are. 58 * 59 * @param context Valid context 60 */ clearAllCacheEntries(Context context)61 void clearAllCacheEntries(Context context); 62 63 interface CachedContactInfo { 64 65 @NonNull getContactInfo()66 ContactInfo getContactInfo(); 67 setSource(ContactSource.Type sourceType, String name, long directoryId)68 void setSource(ContactSource.Type sourceType, String name, long directoryId); 69 setDirectorySource(String name, long directoryId)70 void setDirectorySource(String name, long directoryId); 71 setLookupKey(String lookupKey)72 void setLookupKey(String lookupKey); 73 } 74 } 75