blob: 279804e6aa303d9ce8dc100a28cdd62b1e043fb5 [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;
Ihab Awad542e0ea2014-05-16 10:22:16 -070022import android.os.Parcel;
23import android.os.Parcelable;
Evan Charlton134dd682014-11-25 14:12:57 -080024import android.os.Process;
25import android.os.UserHandle;
Ihab Awadc35ad022014-06-12 16:29:42 -070026
Ihab Awaddcaa5d62014-07-08 10:33:46 -070027import java.util.Objects;
Ihab Awad542e0ea2014-05-16 10:22:16 -070028
29/**
Santos Cordond9e614f2014-10-28 13:10:36 -070030 * The unique identifier for a {@link PhoneAccount}. A {@code PhoneAccountHandle} is made of two
31 * parts:
32 * <ul>
Brian Attwellad147f42014-12-19 11:37:16 -080033 * <li>The component name of the associated connection service.</li>
Santos Cordond9e614f2014-10-28 13:10:36 -070034 * <li>A string identifier that is unique across {@code PhoneAccountHandle}s with the same
35 * component name.</li>
36 * </ul>
37 *
Brad Ebinger428cec92016-03-15 14:23:44 -070038 * Note: This Class requires a non-null {@link ComponentName} and {@link UserHandle} to operate
39 * properly. Passing in invalid parameters will generate a log warning.
40 *
Brian Attwellad147f42014-12-19 11:37:16 -080041 * See {@link PhoneAccount}, {@link TelecomManager}.
Ihab Awad542e0ea2014-05-16 10:22:16 -070042 */
Yorke Lee400470f2015-05-12 13:31:25 -070043public final class PhoneAccountHandle implements Parcelable {
Mathew Inwoode5bfa3e2018-08-01 11:26:20 +010044 @UnsupportedAppUsage
Evan Charlton134dd682014-11-25 14:12:57 -080045 private final ComponentName mComponentName;
Mathew Inwoode5bfa3e2018-08-01 11:26:20 +010046 @UnsupportedAppUsage
Evan Charlton134dd682014-11-25 14:12:57 -080047 private final String mId;
48 private final UserHandle mUserHandle;
Ihab Awadc35ad022014-06-12 16:29:42 -070049
Evan Charlton6eb262c2014-07-19 18:18:19 -070050 public PhoneAccountHandle(
Brad Ebinger428cec92016-03-15 14:23:44 -070051 @NonNull ComponentName componentName,
52 @NonNull String id) {
Evan Charlton134dd682014-11-25 14:12:57 -080053 this(componentName, id, Process.myUserHandle());
54 }
55
Evan Charlton134dd682014-11-25 14:12:57 -080056 public PhoneAccountHandle(
Brad Ebinger428cec92016-03-15 14:23:44 -070057 @NonNull ComponentName componentName,
58 @NonNull String id,
59 @NonNull UserHandle userHandle) {
60 checkParameters(componentName, userHandle);
Ihab Awadc35ad022014-06-12 16:29:42 -070061 mComponentName = componentName;
62 mId = id;
Evan Charlton134dd682014-11-25 14:12:57 -080063 mUserHandle = userHandle;
Ihab Awadc35ad022014-06-12 16:29:42 -070064 }
65
66 /**
Brian Attwellad147f42014-12-19 11:37:16 -080067 * The {@code ComponentName} of the connection service which is responsible for making phone
68 * calls using this {@code PhoneAccountHandle}.
Ihab Awadc35ad022014-06-12 16:29:42 -070069 *
70 * @return A suitable {@code ComponentName}.
71 */
72 public ComponentName getComponentName() {
73 return mComponentName;
74 }
75
76 /**
Ihab Awadb19a0bc2014-08-07 19:46:01 -070077 * A string that uniquely distinguishes this particular {@code PhoneAccountHandle} from all the
Brian Attwellad147f42014-12-19 11:37:16 -080078 * others supported by the connection service that created it.
Ihab Awadb19a0bc2014-08-07 19:46:01 -070079 * <p>
Brian Attwellad147f42014-12-19 11:37:16 -080080 * A connection service must select identifiers that are stable for the lifetime of
Ihab Awadb19a0bc2014-08-07 19:46:01 -070081 * their users' relationship with their service, across many Android devices. For example, a
82 * good set of identifiers might be the email addresses with which with users registered for
83 * their accounts with a particular service. Depending on how a service chooses to operate,
84 * a bad set of identifiers might be an increasing series of integers
85 * ({@code 0}, {@code 1}, {@code 2}, ...) that are generated locally on each phone and could
86 * collide with values generated on other phones or after a data wipe of a given phone.
Ihab Awadc35ad022014-06-12 16:29:42 -070087 *
Santos Cordon8b338d42015-02-10 03:38:31 -080088 * Important: A non-unique identifier could cause non-deterministic call-log backup/restore
89 * behavior.
90 *
Ihab Awadb19a0bc2014-08-07 19:46:01 -070091 * @return A service-specific unique identifier for this {@code PhoneAccountHandle}.
Ihab Awadc35ad022014-06-12 16:29:42 -070092 */
93 public String getId() {
94 return mId;
95 }
96
Evan Charlton134dd682014-11-25 14:12:57 -080097 /**
98 * @return the {@link UserHandle} to use when connecting to this PhoneAccount.
Evan Charlton134dd682014-11-25 14:12:57 -080099 */
100 public UserHandle getUserHandle() {
101 return mUserHandle;
102 }
103
Ihab Awad807fe0a2014-07-09 12:30:52 -0700104 @Override
105 public int hashCode() {
Evan Charlton134dd682014-11-25 14:12:57 -0800106 return Objects.hash(mComponentName, mId, mUserHandle);
Ihab Awadc35ad022014-06-12 16:29:42 -0700107 }
108
Santos Cordon98b27032014-07-14 03:32:56 -0700109 @Override
110 public String toString() {
Tyler Gunn76c01a52014-09-30 14:47:51 -0700111 // Note: Log.pii called for mId as it can contain personally identifying phone account
112 // information such as SIP account IDs.
Santos Cordon98b27032014-07-14 03:32:56 -0700113 return new StringBuilder().append(mComponentName)
114 .append(", ")
Tyler Gunn76c01a52014-09-30 14:47:51 -0700115 .append(Log.pii(mId))
Evan Charlton134dd682014-11-25 14:12:57 -0800116 .append(", ")
117 .append(mUserHandle)
Santos Cordon98b27032014-07-14 03:32:56 -0700118 .toString();
119 }
120
Ihab Awad94cf4bf2014-07-17 11:21:19 -0700121 @Override
122 public boolean equals(Object other) {
Santos Cordon98b27032014-07-14 03:32:56 -0700123 return other != null &&
Evan Charlton6eb262c2014-07-19 18:18:19 -0700124 other instanceof PhoneAccountHandle &&
125 Objects.equals(((PhoneAccountHandle) other).getComponentName(),
126 getComponentName()) &&
Evan Charlton134dd682014-11-25 14:12:57 -0800127 Objects.equals(((PhoneAccountHandle) other).getId(), getId()) &&
128 Objects.equals(((PhoneAccountHandle) other).getUserHandle(), getUserHandle());
Santos Cordon98b27032014-07-14 03:32:56 -0700129 }
130
Ihab Awaddcaa5d62014-07-08 10:33:46 -0700131 //
Ihab Awad807fe0a2014-07-09 12:30:52 -0700132 // Parcelable implementation.
133 //
Ihab Awad542e0ea2014-05-16 10:22:16 -0700134
Sailesh Nepale7ef59a2014-07-08 21:48:22 -0700135 @Override
Ihab Awad542e0ea2014-05-16 10:22:16 -0700136 public int describeContents() {
137 return 0;
138 }
139
Sailesh Nepale7ef59a2014-07-08 21:48:22 -0700140 @Override
Ihab Awadc35ad022014-06-12 16:29:42 -0700141 public void writeToParcel(Parcel out, int flags) {
Evan Charlton134dd682014-11-25 14:12:57 -0800142 mComponentName.writeToParcel(out, flags);
Ihab Awadc35ad022014-06-12 16:29:42 -0700143 out.writeString(mId);
Evan Charlton134dd682014-11-25 14:12:57 -0800144 mUserHandle.writeToParcel(out, flags);
Ihab Awadc35ad022014-06-12 16:29:42 -0700145 }
Ihab Awad542e0ea2014-05-16 10:22:16 -0700146
Brad Ebinger428cec92016-03-15 14:23:44 -0700147 private void checkParameters(ComponentName componentName, UserHandle userHandle) {
148 if(componentName == null) {
149 android.util.Log.w("PhoneAccountHandle", new Exception("PhoneAccountHandle has " +
150 "been created with null ComponentName!"));
151 }
152 if(userHandle == null) {
153 android.util.Log.w("PhoneAccountHandle", new Exception("PhoneAccountHandle has " +
154 "been created with null UserHandle!"));
155 }
156 }
157
Evan Charlton6eb262c2014-07-19 18:18:19 -0700158 public static final Creator<PhoneAccountHandle> CREATOR = new Creator<PhoneAccountHandle>() {
Ihab Awad807fe0a2014-07-09 12:30:52 -0700159 @Override
Evan Charlton6eb262c2014-07-19 18:18:19 -0700160 public PhoneAccountHandle createFromParcel(Parcel in) {
161 return new PhoneAccountHandle(in);
Ihab Awad542e0ea2014-05-16 10:22:16 -0700162 }
163
Ihab Awad807fe0a2014-07-09 12:30:52 -0700164 @Override
Evan Charlton6eb262c2014-07-19 18:18:19 -0700165 public PhoneAccountHandle[] newArray(int size) {
166 return new PhoneAccountHandle[size];
Ihab Awad542e0ea2014-05-16 10:22:16 -0700167 }
168 };
169
Mathew Inwoode5bfa3e2018-08-01 11:26:20 +0100170 @UnsupportedAppUsage
Evan Charlton6eb262c2014-07-19 18:18:19 -0700171 private PhoneAccountHandle(Parcel in) {
Evan Charlton134dd682014-11-25 14:12:57 -0800172 this(ComponentName.CREATOR.createFromParcel(in),
173 in.readString(),
174 UserHandle.CREATOR.createFromParcel(in));
Ihab Awadc35ad022014-06-12 16:29:42 -0700175 }
Ihab Awad542e0ea2014-05-16 10:22:16 -0700176}