blob: 5dedb045566ca060fdc0307dbf7fdcff6aa54811 [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
Brad Ebinger428cec92016-03-15 14:23:44 -070019import android.annotation.NonNull;
Mathew Inwoode5bfa3e2018-08-01 11:26:20 +010020import android.annotation.UnsupportedAppUsage;
Ihab Awadc35ad022014-06-12 16:29:42 -070021import android.content.ComponentName;
Mathew Inwood8c854f82018-09-14 12:35:36 +010022import android.os.Build;
Ihab Awad542e0ea2014-05-16 10:22:16 -070023import android.os.Parcel;
24import android.os.Parcelable;
Evan Charlton134dd682014-11-25 14:12:57 -080025import android.os.Process;
26import android.os.UserHandle;
Ihab Awadc35ad022014-06-12 16:29:42 -070027
Ihab Awaddcaa5d62014-07-08 10:33:46 -070028import java.util.Objects;
Ihab Awad542e0ea2014-05-16 10:22:16 -070029
30/**
Santos Cordond9e614f2014-10-28 13:10:36 -070031 * The unique identifier for a {@link PhoneAccount}. A {@code PhoneAccountHandle} is made of two
32 * parts:
33 * <ul>
Brian Attwellad147f42014-12-19 11:37:16 -080034 * <li>The component name of the associated connection service.</li>
Santos Cordond9e614f2014-10-28 13:10:36 -070035 * <li>A string identifier that is unique across {@code PhoneAccountHandle}s with the same
36 * component name.</li>
37 * </ul>
38 *
Brad Ebinger428cec92016-03-15 14:23:44 -070039 * Note: This Class requires a non-null {@link ComponentName} and {@link UserHandle} to operate
40 * properly. Passing in invalid parameters will generate a log warning.
41 *
Brian Attwellad147f42014-12-19 11:37:16 -080042 * See {@link PhoneAccount}, {@link TelecomManager}.
Ihab Awad542e0ea2014-05-16 10:22:16 -070043 */
Yorke Lee400470f2015-05-12 13:31:25 -070044public final class PhoneAccountHandle implements Parcelable {
Mathew Inwoode5bfa3e2018-08-01 11:26:20 +010045 @UnsupportedAppUsage
Evan Charlton134dd682014-11-25 14:12:57 -080046 private final ComponentName mComponentName;
Mathew Inwood8c854f82018-09-14 12:35:36 +010047 @UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.P, trackingBug = 115609023)
Evan Charlton134dd682014-11-25 14:12:57 -080048 private final String mId;
49 private final UserHandle mUserHandle;
Ihab Awadc35ad022014-06-12 16:29:42 -070050
Evan Charlton6eb262c2014-07-19 18:18:19 -070051 public PhoneAccountHandle(
Brad Ebinger428cec92016-03-15 14:23:44 -070052 @NonNull ComponentName componentName,
53 @NonNull String id) {
Evan Charlton134dd682014-11-25 14:12:57 -080054 this(componentName, id, Process.myUserHandle());
55 }
56
Evan Charlton134dd682014-11-25 14:12:57 -080057 public PhoneAccountHandle(
Brad Ebinger428cec92016-03-15 14:23:44 -070058 @NonNull ComponentName componentName,
59 @NonNull String id,
60 @NonNull UserHandle userHandle) {
61 checkParameters(componentName, userHandle);
Ihab Awadc35ad022014-06-12 16:29:42 -070062 mComponentName = componentName;
63 mId = id;
Evan Charlton134dd682014-11-25 14:12:57 -080064 mUserHandle = userHandle;
Ihab Awadc35ad022014-06-12 16:29:42 -070065 }
66
67 /**
Brian Attwellad147f42014-12-19 11:37:16 -080068 * The {@code ComponentName} of the connection service which is responsible for making phone
69 * calls using this {@code PhoneAccountHandle}.
Ihab Awadc35ad022014-06-12 16:29:42 -070070 *
71 * @return A suitable {@code ComponentName}.
72 */
73 public ComponentName getComponentName() {
74 return mComponentName;
75 }
76
77 /**
Ihab Awadb19a0bc2014-08-07 19:46:01 -070078 * A string that uniquely distinguishes this particular {@code PhoneAccountHandle} from all the
Brian Attwellad147f42014-12-19 11:37:16 -080079 * others supported by the connection service that created it.
Ihab Awadb19a0bc2014-08-07 19:46:01 -070080 * <p>
Brian Attwellad147f42014-12-19 11:37:16 -080081 * A connection service must select identifiers that are stable for the lifetime of
Ihab Awadb19a0bc2014-08-07 19:46:01 -070082 * their users' relationship with their service, across many Android devices. For example, a
83 * good set of identifiers might be the email addresses with which with users registered for
84 * their accounts with a particular service. Depending on how a service chooses to operate,
85 * a bad set of identifiers might be an increasing series of integers
86 * ({@code 0}, {@code 1}, {@code 2}, ...) that are generated locally on each phone and could
87 * collide with values generated on other phones or after a data wipe of a given phone.
Ihab Awadc35ad022014-06-12 16:29:42 -070088 *
Santos Cordon8b338d42015-02-10 03:38:31 -080089 * Important: A non-unique identifier could cause non-deterministic call-log backup/restore
90 * behavior.
91 *
Ihab Awadb19a0bc2014-08-07 19:46:01 -070092 * @return A service-specific unique identifier for this {@code PhoneAccountHandle}.
Ihab Awadc35ad022014-06-12 16:29:42 -070093 */
94 public String getId() {
95 return mId;
96 }
97
Evan Charlton134dd682014-11-25 14:12:57 -080098 /**
99 * @return the {@link UserHandle} to use when connecting to this PhoneAccount.
Evan Charlton134dd682014-11-25 14:12:57 -0800100 */
101 public UserHandle getUserHandle() {
102 return mUserHandle;
103 }
104
Ihab Awad807fe0a2014-07-09 12:30:52 -0700105 @Override
106 public int hashCode() {
Evan Charlton134dd682014-11-25 14:12:57 -0800107 return Objects.hash(mComponentName, mId, mUserHandle);
Ihab Awadc35ad022014-06-12 16:29:42 -0700108 }
109
Santos Cordon98b27032014-07-14 03:32:56 -0700110 @Override
111 public String toString() {
Tyler Gunn76c01a52014-09-30 14:47:51 -0700112 // Note: Log.pii called for mId as it can contain personally identifying phone account
113 // information such as SIP account IDs.
Santos Cordon98b27032014-07-14 03:32:56 -0700114 return new StringBuilder().append(mComponentName)
115 .append(", ")
Tyler Gunn76c01a52014-09-30 14:47:51 -0700116 .append(Log.pii(mId))
Evan Charlton134dd682014-11-25 14:12:57 -0800117 .append(", ")
118 .append(mUserHandle)
Santos Cordon98b27032014-07-14 03:32:56 -0700119 .toString();
120 }
121
Ihab Awad94cf4bf2014-07-17 11:21:19 -0700122 @Override
123 public boolean equals(Object other) {
Santos Cordon98b27032014-07-14 03:32:56 -0700124 return other != null &&
Evan Charlton6eb262c2014-07-19 18:18:19 -0700125 other instanceof PhoneAccountHandle &&
126 Objects.equals(((PhoneAccountHandle) other).getComponentName(),
127 getComponentName()) &&
Evan Charlton134dd682014-11-25 14:12:57 -0800128 Objects.equals(((PhoneAccountHandle) other).getId(), getId()) &&
129 Objects.equals(((PhoneAccountHandle) other).getUserHandle(), getUserHandle());
Santos Cordon98b27032014-07-14 03:32:56 -0700130 }
131
Ihab Awaddcaa5d62014-07-08 10:33:46 -0700132 //
Ihab Awad807fe0a2014-07-09 12:30:52 -0700133 // Parcelable implementation.
134 //
Ihab Awad542e0ea2014-05-16 10:22:16 -0700135
Sailesh Nepale7ef59a2014-07-08 21:48:22 -0700136 @Override
Ihab Awad542e0ea2014-05-16 10:22:16 -0700137 public int describeContents() {
138 return 0;
139 }
140
Sailesh Nepale7ef59a2014-07-08 21:48:22 -0700141 @Override
Ihab Awadc35ad022014-06-12 16:29:42 -0700142 public void writeToParcel(Parcel out, int flags) {
Evan Charlton134dd682014-11-25 14:12:57 -0800143 mComponentName.writeToParcel(out, flags);
Ihab Awadc35ad022014-06-12 16:29:42 -0700144 out.writeString(mId);
Evan Charlton134dd682014-11-25 14:12:57 -0800145 mUserHandle.writeToParcel(out, flags);
Ihab Awadc35ad022014-06-12 16:29:42 -0700146 }
Ihab Awad542e0ea2014-05-16 10:22:16 -0700147
Brad Ebinger428cec92016-03-15 14:23:44 -0700148 private void checkParameters(ComponentName componentName, UserHandle userHandle) {
149 if(componentName == null) {
150 android.util.Log.w("PhoneAccountHandle", new Exception("PhoneAccountHandle has " +
151 "been created with null ComponentName!"));
152 }
153 if(userHandle == null) {
154 android.util.Log.w("PhoneAccountHandle", new Exception("PhoneAccountHandle has " +
155 "been created with null UserHandle!"));
156 }
157 }
158
Evan Charlton6eb262c2014-07-19 18:18:19 -0700159 public static final Creator<PhoneAccountHandle> CREATOR = new Creator<PhoneAccountHandle>() {
Ihab Awad807fe0a2014-07-09 12:30:52 -0700160 @Override
Evan Charlton6eb262c2014-07-19 18:18:19 -0700161 public PhoneAccountHandle createFromParcel(Parcel in) {
162 return new PhoneAccountHandle(in);
Ihab Awad542e0ea2014-05-16 10:22:16 -0700163 }
164
Ihab Awad807fe0a2014-07-09 12:30:52 -0700165 @Override
Evan Charlton6eb262c2014-07-19 18:18:19 -0700166 public PhoneAccountHandle[] newArray(int size) {
167 return new PhoneAccountHandle[size];
Ihab Awad542e0ea2014-05-16 10:22:16 -0700168 }
169 };
170
Mathew Inwood31755f92018-12-20 13:53:36 +0000171 @UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.P, trackingBug = 115609023)
Evan Charlton6eb262c2014-07-19 18:18:19 -0700172 private PhoneAccountHandle(Parcel in) {
Evan Charlton134dd682014-11-25 14:12:57 -0800173 this(ComponentName.CREATOR.createFromParcel(in),
174 in.readString(),
175 UserHandle.CREATOR.createFromParcel(in));
Ihab Awadc35ad022014-06-12 16:29:42 -0700176 }
Ihab Awad542e0ea2014-05-16 10:22:16 -0700177}