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.support.annotation.Nullable; 21 import android.text.TextUtils; 22 import com.android.contacts.common.ContactsUtils.UserType; 23 import com.android.contacts.common.util.UriUtils; 24 import com.android.dialer.logging.ContactSource; 25 26 /** Information for a contact as needed by the Call Log. */ 27 public class ContactInfo { 28 29 public static final ContactInfo EMPTY = new ContactInfo(); 30 public Uri lookupUri; 31 /** 32 * Contact lookup key. Note this may be a lookup key for a corp contact, in which case "lookup by 33 * lookup key" doesn't work on the personal profile. 34 */ 35 public String lookupKey; 36 37 public String name; 38 public String nameAlternative; 39 public int type; 40 public String label; 41 public String number; 42 public String formattedNumber; 43 public String geoDescription; 44 /* 45 * ContactInfo.normalizedNumber is a column value returned by PhoneLookup query. By definition, 46 * it's E164 representation. 47 * http://developer.android.com/reference/android/provider/ContactsContract.PhoneLookupColumns. 48 * html#NORMALIZED_NUMBER. 49 * 50 * The fallback value, when PhoneLookup fails or else, should be either null or 51 * PhoneNumberUtils.formatNumberToE164. 52 */ 53 public String normalizedNumber; 54 /** The photo for the contact, if available. */ 55 public long photoId; 56 /** The high-res photo for the contact, if available. */ 57 public Uri photoUri; 58 59 public boolean isBadData; 60 public String objectId; 61 public @UserType long userType; 62 public @Nullable ContactSource.Type sourceType = ContactSource.Type.UNKNOWN_SOURCE_TYPE; 63 /** 64 * True if local contact exists. This is only used for Cequint Caller ID so it won't overwrite 65 * photo if local contact exists. 66 */ 67 public boolean contactExists; 68 69 /** @see android.provider.ContactsContract.CommonDataKinds.Phone#CARRIER_PRESENCE */ 70 public int carrierPresence; 71 72 @Override hashCode()73 public int hashCode() { 74 // Uses only name and contactUri to determine hashcode. 75 // This should be sufficient to have a reasonable distribution of hash codes. 76 // Moreover, there should be no two people with the same lookupUri. 77 final int prime = 31; 78 int result = 1; 79 result = prime * result + ((lookupUri == null) ? 0 : lookupUri.hashCode()); 80 result = prime * result + ((name == null) ? 0 : name.hashCode()); 81 return result; 82 } 83 84 @Override equals(Object obj)85 public boolean equals(Object obj) { 86 if (this == obj) { 87 return true; 88 } 89 if (obj == null) { 90 return false; 91 } 92 if (getClass() != obj.getClass()) { 93 return false; 94 } 95 ContactInfo other = (ContactInfo) obj; 96 if (!UriUtils.areEqual(lookupUri, other.lookupUri)) { 97 return false; 98 } 99 if (!TextUtils.equals(name, other.name)) { 100 return false; 101 } 102 if (!TextUtils.equals(nameAlternative, other.nameAlternative)) { 103 return false; 104 } 105 if (type != other.type) { 106 return false; 107 } 108 if (!TextUtils.equals(label, other.label)) { 109 return false; 110 } 111 if (!TextUtils.equals(number, other.number)) { 112 return false; 113 } 114 if (!TextUtils.equals(formattedNumber, other.formattedNumber)) { 115 return false; 116 } 117 if (!TextUtils.equals(normalizedNumber, other.normalizedNumber)) { 118 return false; 119 } 120 if (photoId != other.photoId) { 121 return false; 122 } 123 if (!UriUtils.areEqual(photoUri, other.photoUri)) { 124 return false; 125 } 126 if (!TextUtils.equals(objectId, other.objectId)) { 127 return false; 128 } 129 if (userType != other.userType) { 130 return false; 131 } 132 if (carrierPresence != other.carrierPresence) { 133 return false; 134 } 135 if (!TextUtils.equals(geoDescription, other.geoDescription)) { 136 return false; 137 } 138 return true; 139 } 140 141 @Override toString()142 public String toString() { 143 return "ContactInfo{" 144 + "lookupUri=" 145 + lookupUri 146 + ", name='" 147 + name 148 + '\'' 149 + ", nameAlternative='" 150 + nameAlternative 151 + '\'' 152 + ", type=" 153 + type 154 + ", label='" 155 + label 156 + '\'' 157 + ", number='" 158 + number 159 + '\'' 160 + ", formattedNumber='" 161 + formattedNumber 162 + '\'' 163 + ", normalizedNumber='" 164 + normalizedNumber 165 + '\'' 166 + ", photoId=" 167 + photoId 168 + ", photoUri=" 169 + photoUri 170 + ", objectId='" 171 + objectId 172 + '\'' 173 + ", userType=" 174 + userType 175 + ", carrierPresence=" 176 + carrierPresence 177 + ", geoDescription=" 178 + geoDescription 179 + '}'; 180 } 181 } 182