blob: 60917b2dc568ea5f149914f31b3dc4e7d88c0f88 [file] [log] [blame]
Ihab Awad542e0ea2014-05-16 10:22:16 -07001/*
2 * Copyright (C) 2014 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
Tyler Gunnef9f6f92014-09-12 22:16:17 -070017package android.telecom;
Ihab Awad542e0ea2014-05-16 10:22:16 -070018
Ihab Awadc35ad022014-06-12 16:29:42 -070019import android.content.ComponentName;
Ihab Awad542e0ea2014-05-16 10:22:16 -070020import android.os.Parcel;
21import android.os.Parcelable;
Evan Charlton134dd682014-11-25 14:12:57 -080022import android.os.Process;
23import android.os.UserHandle;
Ihab Awadc35ad022014-06-12 16:29:42 -070024
Ihab Awaddcaa5d62014-07-08 10:33:46 -070025import java.util.Objects;
Ihab Awad542e0ea2014-05-16 10:22:16 -070026
27/**
Santos Cordond9e614f2014-10-28 13:10:36 -070028 * The unique identifier for a {@link PhoneAccount}. A {@code PhoneAccountHandle} is made of two
29 * parts:
30 * <ul>
Brian Attwellad147f42014-12-19 11:37:16 -080031 * <li>The component name of the associated connection service.</li>
Santos Cordond9e614f2014-10-28 13:10:36 -070032 * <li>A string identifier that is unique across {@code PhoneAccountHandle}s with the same
33 * component name.</li>
34 * </ul>
35 *
Brian Attwellad147f42014-12-19 11:37:16 -080036 * See {@link PhoneAccount}, {@link TelecomManager}.
Ihab Awad542e0ea2014-05-16 10:22:16 -070037 */
Evan Charlton6eb262c2014-07-19 18:18:19 -070038public class PhoneAccountHandle implements Parcelable {
Evan Charlton134dd682014-11-25 14:12:57 -080039 private final ComponentName mComponentName;
40 private final String mId;
41 private final UserHandle mUserHandle;
Ihab Awadc35ad022014-06-12 16:29:42 -070042
Evan Charlton6eb262c2014-07-19 18:18:19 -070043 public PhoneAccountHandle(
Ihab Awadc35ad022014-06-12 16:29:42 -070044 ComponentName componentName,
Ihab Awad94cf4bf2014-07-17 11:21:19 -070045 String id) {
Evan Charlton134dd682014-11-25 14:12:57 -080046 this(componentName, id, Process.myUserHandle());
47 }
48
Evan Charlton134dd682014-11-25 14:12:57 -080049 public PhoneAccountHandle(
50 ComponentName componentName,
51 String id,
52 UserHandle userHandle) {
Ihab Awadc35ad022014-06-12 16:29:42 -070053 mComponentName = componentName;
54 mId = id;
Evan Charlton134dd682014-11-25 14:12:57 -080055 mUserHandle = userHandle;
Ihab Awadc35ad022014-06-12 16:29:42 -070056 }
57
58 /**
Brian Attwellad147f42014-12-19 11:37:16 -080059 * The {@code ComponentName} of the connection service which is responsible for making phone
60 * calls using this {@code PhoneAccountHandle}.
Ihab Awadc35ad022014-06-12 16:29:42 -070061 *
62 * @return A suitable {@code ComponentName}.
63 */
64 public ComponentName getComponentName() {
65 return mComponentName;
66 }
67
68 /**
Ihab Awadb19a0bc2014-08-07 19:46:01 -070069 * A string that uniquely distinguishes this particular {@code PhoneAccountHandle} from all the
Brian Attwellad147f42014-12-19 11:37:16 -080070 * others supported by the connection service that created it.
Ihab Awadb19a0bc2014-08-07 19:46:01 -070071 * <p>
Brian Attwellad147f42014-12-19 11:37:16 -080072 * A connection service must select identifiers that are stable for the lifetime of
Ihab Awadb19a0bc2014-08-07 19:46:01 -070073 * their users' relationship with their service, across many Android devices. For example, a
74 * good set of identifiers might be the email addresses with which with users registered for
75 * their accounts with a particular service. Depending on how a service chooses to operate,
76 * a bad set of identifiers might be an increasing series of integers
77 * ({@code 0}, {@code 1}, {@code 2}, ...) that are generated locally on each phone and could
78 * collide with values generated on other phones or after a data wipe of a given phone.
Ihab Awadc35ad022014-06-12 16:29:42 -070079 *
Santos Cordon8b338d42015-02-10 03:38:31 -080080 * Important: A non-unique identifier could cause non-deterministic call-log backup/restore
81 * behavior.
82 *
Ihab Awadb19a0bc2014-08-07 19:46:01 -070083 * @return A service-specific unique identifier for this {@code PhoneAccountHandle}.
Ihab Awadc35ad022014-06-12 16:29:42 -070084 */
85 public String getId() {
86 return mId;
87 }
88
Evan Charlton134dd682014-11-25 14:12:57 -080089 /**
90 * @return the {@link UserHandle} to use when connecting to this PhoneAccount.
Evan Charlton134dd682014-11-25 14:12:57 -080091 */
92 public UserHandle getUserHandle() {
93 return mUserHandle;
94 }
95
Ihab Awad807fe0a2014-07-09 12:30:52 -070096 @Override
97 public int hashCode() {
Evan Charlton134dd682014-11-25 14:12:57 -080098 return Objects.hash(mComponentName, mId, mUserHandle);
Ihab Awadc35ad022014-06-12 16:29:42 -070099 }
100
Santos Cordon98b27032014-07-14 03:32:56 -0700101 @Override
102 public String toString() {
Tyler Gunn76c01a52014-09-30 14:47:51 -0700103 // Note: Log.pii called for mId as it can contain personally identifying phone account
104 // information such as SIP account IDs.
Santos Cordon98b27032014-07-14 03:32:56 -0700105 return new StringBuilder().append(mComponentName)
106 .append(", ")
Tyler Gunn76c01a52014-09-30 14:47:51 -0700107 .append(Log.pii(mId))
Evan Charlton134dd682014-11-25 14:12:57 -0800108 .append(", ")
109 .append(mUserHandle)
Santos Cordon98b27032014-07-14 03:32:56 -0700110 .toString();
111 }
112
Ihab Awad94cf4bf2014-07-17 11:21:19 -0700113 @Override
114 public boolean equals(Object other) {
Santos Cordon98b27032014-07-14 03:32:56 -0700115 return other != null &&
Evan Charlton6eb262c2014-07-19 18:18:19 -0700116 other instanceof PhoneAccountHandle &&
117 Objects.equals(((PhoneAccountHandle) other).getComponentName(),
118 getComponentName()) &&
Evan Charlton134dd682014-11-25 14:12:57 -0800119 Objects.equals(((PhoneAccountHandle) other).getId(), getId()) &&
120 Objects.equals(((PhoneAccountHandle) other).getUserHandle(), getUserHandle());
Santos Cordon98b27032014-07-14 03:32:56 -0700121 }
122
Ihab Awaddcaa5d62014-07-08 10:33:46 -0700123 //
Ihab Awad807fe0a2014-07-09 12:30:52 -0700124 // Parcelable implementation.
125 //
Ihab Awad542e0ea2014-05-16 10:22:16 -0700126
Sailesh Nepale7ef59a2014-07-08 21:48:22 -0700127 @Override
Ihab Awad542e0ea2014-05-16 10:22:16 -0700128 public int describeContents() {
129 return 0;
130 }
131
Sailesh Nepale7ef59a2014-07-08 21:48:22 -0700132 @Override
Ihab Awadc35ad022014-06-12 16:29:42 -0700133 public void writeToParcel(Parcel out, int flags) {
Evan Charlton134dd682014-11-25 14:12:57 -0800134 mComponentName.writeToParcel(out, flags);
Ihab Awadc35ad022014-06-12 16:29:42 -0700135 out.writeString(mId);
Evan Charlton134dd682014-11-25 14:12:57 -0800136 mUserHandle.writeToParcel(out, flags);
Ihab Awadc35ad022014-06-12 16:29:42 -0700137 }
Ihab Awad542e0ea2014-05-16 10:22:16 -0700138
Evan Charlton6eb262c2014-07-19 18:18:19 -0700139 public static final Creator<PhoneAccountHandle> CREATOR = new Creator<PhoneAccountHandle>() {
Ihab Awad807fe0a2014-07-09 12:30:52 -0700140 @Override
Evan Charlton6eb262c2014-07-19 18:18:19 -0700141 public PhoneAccountHandle createFromParcel(Parcel in) {
142 return new PhoneAccountHandle(in);
Ihab Awad542e0ea2014-05-16 10:22:16 -0700143 }
144
Ihab Awad807fe0a2014-07-09 12:30:52 -0700145 @Override
Evan Charlton6eb262c2014-07-19 18:18:19 -0700146 public PhoneAccountHandle[] newArray(int size) {
147 return new PhoneAccountHandle[size];
Ihab Awad542e0ea2014-05-16 10:22:16 -0700148 }
149 };
150
Evan Charlton6eb262c2014-07-19 18:18:19 -0700151 private PhoneAccountHandle(Parcel in) {
Evan Charlton134dd682014-11-25 14:12:57 -0800152 this(ComponentName.CREATOR.createFromParcel(in),
153 in.readString(),
154 UserHandle.CREATOR.createFromParcel(in));
Ihab Awadc35ad022014-06-12 16:29:42 -0700155 }
Ihab Awad542e0ea2014-05-16 10:22:16 -0700156}