Home | History | Annotate | Download | only in phonenumbercache
      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 
     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
     42   CachedContactInfo lookupCachedContactFromNumber(Context context, String number);
     43 
     44   void addContact(Context context, CachedContactInfo info);
     45 
     46   boolean isCacheUri(String uri);
     47 
     48   boolean isBusiness(ContactSource.Type sourceType);
     49 
     50   boolean canReportAsInvalid(ContactSource.Type sourceType, String objectId);
     51 
     52   boolean reportAsInvalid(Context context, CachedContactInfo cachedContactInfo);
     53 
     54   /** @return return {@link Uri} to the photo or return {@code null} when failing to add photo */
     55   @Nullable
     56   Uri addPhoto(Context context, String number, InputStream in);
     57 
     58   /**
     59    * Remove all cached phone number entries from the cache, regardless of how old they are.
     60    *
     61    * @param context Valid context
     62    */
     63   void clearAllCacheEntries(Context context);
     64 
     65   interface CachedContactInfo {
     66 
     67     @NonNull
     68     ContactInfo getContactInfo();
     69 
     70     void setSource(ContactSource.Type sourceType, String name, long directoryId);
     71 
     72     void setDirectorySource(String name, long directoryId);
     73 
     74     void setExtendedSource(String name, long directoryId);
     75 
     76     void setLookupKey(String lookupKey);
     77   }
     78 }
     79