blob: a96cfb7d7cab30e0ade1e702064aa61177f6bce2 [file] [log] [blame]
Wenyi Wang1fc3ef42016-01-14 18:21:40 -08001/*
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
17package com.android.contacts.callblocking;
18
19import android.net.Uri;
20import android.text.TextUtils;
21import android.util.Log;
22
23import com.android.contacts.common.ContactsUtils.UserType;
24import com.android.contacts.common.util.UriUtils;
25
26import com.google.common.base.Objects;
27
28/**
29 * Information for a contact as needed by blocked numbers.
30 */
31final public class ContactInfo {
32 public Uri lookupUri;
33
34 /**
35 * Contact lookup key. Note this may be a lookup key for a corp contact, in which case
36 * "lookup by lookup key" doesn't work on the personal profile.
37 */
38 public String lookupKey;
39 public String name;
40 public String nameAlternative;
41 public int type;
42 public String label;
43 public String number;
44 public String formattedNumber;
45 public String normalizedNumber;
46 /** The photo for the contact, if available. */
47 public long photoId;
48 /** The high-res photo for the contact, if available. */
49 public Uri photoUri;
50 public boolean isBadData;
51 public String objectId;
52 public @UserType long userType;
53
54 public static ContactInfo EMPTY = new ContactInfo();
55
56 public int sourceType = 0;
57
58 @Override
59 public int hashCode() {
60 // Uses only name and contactUri to determine hashcode.
61 // This should be sufficient to have a reasonable distribution of hash codes.
62 // Moreover, there should be no two people with the same lookupUri.
63 return Objects.hashCode(lookupUri, name);
64 }
65
66 @Override
67 public boolean equals(Object obj) {
68 if (Objects.equal(this, obj)) return true;
69 if (obj == null) return false;
70 if (obj instanceof ContactInfo) {
71 ContactInfo other = (ContactInfo) obj;
72 return Objects.equal(lookupUri, other.lookupUri)
73 && TextUtils.equals(name, other.name)
74 && TextUtils.equals(nameAlternative, other.nameAlternative)
75 && Objects.equal(type, other.type)
76 && TextUtils.equals(label, other.label)
77 && TextUtils.equals(number, other.number)
78 && TextUtils.equals(formattedNumber, other.formattedNumber)
79 && TextUtils.equals(normalizedNumber, other.normalizedNumber)
80 && Objects.equal(photoId, other.photoId)
81 && Objects.equal(photoUri, other.photoUri)
82 && TextUtils.equals(objectId, other.objectId)
83 && Objects.equal(userType, other.userType);
84 }
85 return false;
86 }
87
88 @Override
89 public String toString() {
90 return Objects.toStringHelper(this).add("lookupUri", lookupUri).add("name", name)
91 .add("nameAlternative", nameAlternative)
92 .add("type", type).add("label", label)
93 .add("number", number).add("formattedNumber",formattedNumber)
94 .add("normalizedNumber", normalizedNumber).add("photoId", photoId)
95 .add("photoUri", photoUri).add("objectId", objectId).toString();
96 }
97}