blob: 4600b724e3ef89122a96f96dab579068786087d6 [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
Evan Charlton0e094d92014-11-08 15:49:16 -080019import android.annotation.SystemApi;
Ihab Awadc35ad022014-06-12 16:29:42 -070020import android.content.ComponentName;
Ihab Awad542e0ea2014-05-16 10:22:16 -070021import android.os.Parcel;
22import android.os.Parcelable;
Evan Charlton134dd682014-11-25 14:12:57 -080023import android.os.Process;
24import android.os.UserHandle;
Ihab Awadc35ad022014-06-12 16:29:42 -070025
Ihab Awaddcaa5d62014-07-08 10:33:46 -070026import java.util.Objects;
Ihab Awad542e0ea2014-05-16 10:22:16 -070027
28/**
Santos Cordond9e614f2014-10-28 13:10:36 -070029 * The unique identifier for a {@link PhoneAccount}. A {@code PhoneAccountHandle} is made of two
30 * parts:
31 * <ul>
Brian Attwell48d8442e2014-12-19 11:37:16 -080032 * <li>The component name of the associated connection service.</li>
Santos Cordond9e614f2014-10-28 13:10:36 -070033 * <li>A string identifier that is unique across {@code PhoneAccountHandle}s with the same
34 * component name.</li>
35 * </ul>
36 *
Brian Attwell48d8442e2014-12-19 11:37:16 -080037 * See {@link PhoneAccount}, {@link TelecomManager}.
Ihab Awad542e0ea2014-05-16 10:22:16 -070038 */
Evan Charlton6eb262c2014-07-19 18:18:19 -070039public class PhoneAccountHandle implements Parcelable {
Evan Charlton134dd682014-11-25 14:12:57 -080040 private final ComponentName mComponentName;
41 private final String mId;
42 private final UserHandle mUserHandle;
Ihab Awadc35ad022014-06-12 16:29:42 -070043
Evan Charlton6eb262c2014-07-19 18:18:19 -070044 public PhoneAccountHandle(
Ihab Awadc35ad022014-06-12 16:29:42 -070045 ComponentName componentName,
Ihab Awad94cf4bf2014-07-17 11:21:19 -070046 String id) {
Evan Charlton134dd682014-11-25 14:12:57 -080047 this(componentName, id, Process.myUserHandle());
48 }
49
50 /** @hide */
Brian Attwell48d8442e2014-12-19 11:37:16 -080051 @SystemApi
Evan Charlton134dd682014-11-25 14:12:57 -080052 public PhoneAccountHandle(
53 ComponentName componentName,
54 String id,
55 UserHandle userHandle) {
Ihab Awadc35ad022014-06-12 16:29:42 -070056 mComponentName = componentName;
57 mId = id;
Evan Charlton134dd682014-11-25 14:12:57 -080058 mUserHandle = userHandle;
Ihab Awadc35ad022014-06-12 16:29:42 -070059 }
60
61 /**
Brian Attwell48d8442e2014-12-19 11:37:16 -080062 * The {@code ComponentName} of the connection service which is responsible for making phone
63 * calls using this {@code PhoneAccountHandle}.
Ihab Awadc35ad022014-06-12 16:29:42 -070064 *
65 * @return A suitable {@code ComponentName}.
66 */
67 public ComponentName getComponentName() {
68 return mComponentName;
69 }
70
71 /**
Ihab Awadb19a0bc2014-08-07 19:46:01 -070072 * A string that uniquely distinguishes this particular {@code PhoneAccountHandle} from all the
Brian Attwell48d8442e2014-12-19 11:37:16 -080073 * others supported by the connection service that created it.
Ihab Awadb19a0bc2014-08-07 19:46:01 -070074 * <p>
Brian Attwell48d8442e2014-12-19 11:37:16 -080075 * A connection service must select identifiers that are stable for the lifetime of
Ihab Awadb19a0bc2014-08-07 19:46:01 -070076 * their users' relationship with their service, across many Android devices. For example, a
77 * good set of identifiers might be the email addresses with which with users registered for
78 * their accounts with a particular service. Depending on how a service chooses to operate,
79 * a bad set of identifiers might be an increasing series of integers
80 * ({@code 0}, {@code 1}, {@code 2}, ...) that are generated locally on each phone and could
81 * collide with values generated on other phones or after a data wipe of a given phone.
Ihab Awadc35ad022014-06-12 16:29:42 -070082 *
Santos Cordonb7bb8c42015-02-10 03:38:31 -080083 * Important: A non-unique identifier could cause non-deterministic call-log backup/restore
84 * behavior.
85 *
Ihab Awadb19a0bc2014-08-07 19:46:01 -070086 * @return A service-specific unique identifier for this {@code PhoneAccountHandle}.
Ihab Awadc35ad022014-06-12 16:29:42 -070087 */
88 public String getId() {
89 return mId;
90 }
91
Evan Charlton134dd682014-11-25 14:12:57 -080092 /**
93 * @return the {@link UserHandle} to use when connecting to this PhoneAccount.
94 * @hide
95 */
Brian Attwell48d8442e2014-12-19 11:37:16 -080096 @SystemApi
Evan Charlton134dd682014-11-25 14:12:57 -080097 public UserHandle getUserHandle() {
98 return mUserHandle;
99 }
100
Ihab Awad807fe0a2014-07-09 12:30:52 -0700101 @Override
102 public int hashCode() {
Evan Charlton134dd682014-11-25 14:12:57 -0800103 return Objects.hash(mComponentName, mId, mUserHandle);
Ihab Awadc35ad022014-06-12 16:29:42 -0700104 }
105
Santos Cordon98b27032014-07-14 03:32:56 -0700106 @Override
107 public String toString() {
Tyler Gunn76c01a52014-09-30 14:47:51 -0700108 // Note: Log.pii called for mId as it can contain personally identifying phone account
109 // information such as SIP account IDs.
Santos Cordon98b27032014-07-14 03:32:56 -0700110 return new StringBuilder().append(mComponentName)
111 .append(", ")
Tyler Gunn76c01a52014-09-30 14:47:51 -0700112 .append(Log.pii(mId))
Evan Charlton134dd682014-11-25 14:12:57 -0800113 .append(", ")
114 .append(mUserHandle)
Santos Cordon98b27032014-07-14 03:32:56 -0700115 .toString();
116 }
117
Ihab Awad94cf4bf2014-07-17 11:21:19 -0700118 @Override
119 public boolean equals(Object other) {
Santos Cordon98b27032014-07-14 03:32:56 -0700120 return other != null &&
Evan Charlton6eb262c2014-07-19 18:18:19 -0700121 other instanceof PhoneAccountHandle &&
122 Objects.equals(((PhoneAccountHandle) other).getComponentName(),
123 getComponentName()) &&
Evan Charlton134dd682014-11-25 14:12:57 -0800124 Objects.equals(((PhoneAccountHandle) other).getId(), getId()) &&
125 Objects.equals(((PhoneAccountHandle) other).getUserHandle(), getUserHandle());
Santos Cordon98b27032014-07-14 03:32:56 -0700126 }
127
Ihab Awaddcaa5d62014-07-08 10:33:46 -0700128 //
Ihab Awad807fe0a2014-07-09 12:30:52 -0700129 // Parcelable implementation.
130 //
Ihab Awad542e0ea2014-05-16 10:22:16 -0700131
Sailesh Nepale7ef59a2014-07-08 21:48:22 -0700132 @Override
Ihab Awad542e0ea2014-05-16 10:22:16 -0700133 public int describeContents() {
134 return 0;
135 }
136
Sailesh Nepale7ef59a2014-07-08 21:48:22 -0700137 @Override
Ihab Awadc35ad022014-06-12 16:29:42 -0700138 public void writeToParcel(Parcel out, int flags) {
Evan Charlton134dd682014-11-25 14:12:57 -0800139 mComponentName.writeToParcel(out, flags);
Ihab Awadc35ad022014-06-12 16:29:42 -0700140 out.writeString(mId);
Evan Charlton134dd682014-11-25 14:12:57 -0800141 mUserHandle.writeToParcel(out, flags);
Ihab Awadc35ad022014-06-12 16:29:42 -0700142 }
Ihab Awad542e0ea2014-05-16 10:22:16 -0700143
Evan Charlton6eb262c2014-07-19 18:18:19 -0700144 public static final Creator<PhoneAccountHandle> CREATOR = new Creator<PhoneAccountHandle>() {
Ihab Awad807fe0a2014-07-09 12:30:52 -0700145 @Override
Evan Charlton6eb262c2014-07-19 18:18:19 -0700146 public PhoneAccountHandle createFromParcel(Parcel in) {
147 return new PhoneAccountHandle(in);
Ihab Awad542e0ea2014-05-16 10:22:16 -0700148 }
149
Ihab Awad807fe0a2014-07-09 12:30:52 -0700150 @Override
Evan Charlton6eb262c2014-07-19 18:18:19 -0700151 public PhoneAccountHandle[] newArray(int size) {
152 return new PhoneAccountHandle[size];
Ihab Awad542e0ea2014-05-16 10:22:16 -0700153 }
154 };
155
Evan Charlton6eb262c2014-07-19 18:18:19 -0700156 private PhoneAccountHandle(Parcel in) {
Evan Charlton134dd682014-11-25 14:12:57 -0800157 this(ComponentName.CREATOR.createFromParcel(in),
158 in.readString(),
159 UserHandle.CREATOR.createFromParcel(in));
Ihab Awadc35ad022014-06-12 16:29:42 -0700160 }
Ihab Awad542e0ea2014-05-16 10:22:16 -0700161}