1 /* 2 * Copyright (C) 2011 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.net.Uri; 20 import android.os.Build.VERSION; 21 import android.os.Build.VERSION_CODES; 22 import android.provider.ContactsContract; 23 import android.provider.ContactsContract.CommonDataKinds.Phone; 24 import android.provider.ContactsContract.Contacts; 25 import android.provider.ContactsContract.PhoneLookup; 26 27 /** The queries to look up the {@link ContactInfo} for a given number in the Call Log. */ 28 final class PhoneQuery { 29 30 public static final int PERSON_ID = 0; 31 public static final int NAME = 1; 32 public static final int PHONE_TYPE = 2; 33 public static final int LABEL = 3; 34 public static final int MATCHED_NUMBER = 4; 35 public static final int NORMALIZED_NUMBER = 5; 36 public static final int PHOTO_ID = 6; 37 public static final int LOOKUP_KEY = 7; 38 public static final int PHOTO_URI = 8; 39 /** Projection to look up a contact's DISPLAY_NAME_ALTERNATIVE */ 40 public static final String[] DISPLAY_NAME_ALTERNATIVE_PROJECTION = 41 new String[] { 42 Contacts.DISPLAY_NAME_ALTERNATIVE, 43 }; 44 45 public static final int NAME_ALTERNATIVE = 0; 46 47 public static final String[] ADDITIONAL_CONTACT_INFO_PROJECTION = 48 new String[] {Phone.DISPLAY_NAME_ALTERNATIVE, Phone.CARRIER_PRESENCE}; 49 public static final int ADDITIONAL_CONTACT_INFO_DISPLAY_NAME_ALTERNATIVE = 0; 50 public static final int ADDITIONAL_CONTACT_INFO_CARRIER_PRESENCE = 1; 51 52 /** 53 * Projection to look up the ContactInfo. Does not include DISPLAY_NAME_ALTERNATIVE as that column 54 * isn't available in ContactsCommon.PhoneLookup. We should always use this projection starting 55 * from NYC onward. 56 */ 57 private static final String[] PHONE_LOOKUP_PROJECTION = 58 new String[] { 59 PhoneLookup.CONTACT_ID, 60 PhoneLookup.DISPLAY_NAME, 61 PhoneLookup.TYPE, 62 PhoneLookup.LABEL, 63 PhoneLookup.NUMBER, 64 PhoneLookup.NORMALIZED_NUMBER, 65 PhoneLookup.PHOTO_ID, 66 PhoneLookup.LOOKUP_KEY, 67 PhoneLookup.PHOTO_URI 68 }; 69 /** 70 * Similar to {@link PHONE_LOOKUP_PROJECTION}. In pre-N, contact id is stored in {@link 71 * PhoneLookup#_ID} in non-sip query. 72 */ 73 private static final String[] BACKWARD_COMPATIBLE_NON_SIP_PHONE_LOOKUP_PROJECTION = 74 new String[] { 75 PhoneLookup._ID, 76 PhoneLookup.DISPLAY_NAME, 77 PhoneLookup.TYPE, 78 PhoneLookup.LABEL, 79 PhoneLookup.NUMBER, 80 PhoneLookup.NORMALIZED_NUMBER, 81 PhoneLookup.PHOTO_ID, 82 PhoneLookup.LOOKUP_KEY, 83 PhoneLookup.PHOTO_URI 84 }; 85 getPhoneLookupProjection(Uri phoneLookupUri)86 public static String[] getPhoneLookupProjection(Uri phoneLookupUri) { 87 if (VERSION.SDK_INT >= VERSION_CODES.N) { 88 return PHONE_LOOKUP_PROJECTION; 89 } 90 // Pre-N 91 boolean isSip = 92 phoneLookupUri.getBooleanQueryParameter( 93 ContactsContract.PhoneLookup.QUERY_PARAMETER_SIP_ADDRESS, false); 94 return (isSip) ? PHONE_LOOKUP_PROJECTION : BACKWARD_COMPATIBLE_NON_SIP_PHONE_LOOKUP_PROJECTION; 95 } 96 } 97