blob: 97af41afd31aabe146cd51f1d31ae09e34ac1267 [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>
32 * <li>The component name of the associated {@link ConnectionService}.</li>
33 * <li>A string identifier that is unique across {@code PhoneAccountHandle}s with the same
34 * component name.</li>
35 * </ul>
36 *
37 * See {@link PhoneAccount},
38 * {@link TelecomManager#registerPhoneAccount TelecomManager.registerPhoneAccount}.
Evan Charlton0e094d92014-11-08 15:49:16 -080039 * @hide
Ihab Awad542e0ea2014-05-16 10:22:16 -070040 */
Evan Charlton0e094d92014-11-08 15:49:16 -080041@SystemApi
Evan Charlton6eb262c2014-07-19 18:18:19 -070042public class PhoneAccountHandle implements Parcelable {
Evan Charlton134dd682014-11-25 14:12:57 -080043 private final ComponentName mComponentName;
44 private final String mId;
45 private final UserHandle mUserHandle;
Ihab Awadc35ad022014-06-12 16:29:42 -070046
Evan Charlton6eb262c2014-07-19 18:18:19 -070047 public PhoneAccountHandle(
Ihab Awadc35ad022014-06-12 16:29:42 -070048 ComponentName componentName,
Ihab Awad94cf4bf2014-07-17 11:21:19 -070049 String id) {
Evan Charlton134dd682014-11-25 14:12:57 -080050 this(componentName, id, Process.myUserHandle());
51 }
52
53 /** @hide */
54 public PhoneAccountHandle(
55 ComponentName componentName,
56 String id,
57 UserHandle userHandle) {
Ihab Awadc35ad022014-06-12 16:29:42 -070058 mComponentName = componentName;
59 mId = id;
Evan Charlton134dd682014-11-25 14:12:57 -080060 mUserHandle = userHandle;
Ihab Awadc35ad022014-06-12 16:29:42 -070061 }
62
63 /**
Tyler Gunnef9f6f92014-09-12 22:16:17 -070064 * The {@code ComponentName} of the {@link android.telecom.ConnectionService} which is
Evan Charlton6eb262c2014-07-19 18:18:19 -070065 * responsible for making phone calls using this {@code PhoneAccountHandle}.
Ihab Awadc35ad022014-06-12 16:29:42 -070066 *
67 * @return A suitable {@code ComponentName}.
68 */
69 public ComponentName getComponentName() {
70 return mComponentName;
71 }
72
73 /**
Ihab Awadb19a0bc2014-08-07 19:46:01 -070074 * A string that uniquely distinguishes this particular {@code PhoneAccountHandle} from all the
75 * others supported by the {@link ConnectionService} that created it.
76 * <p>
77 * A {@code ConnectionService} must select identifiers that are stable for the lifetime of
78 * their users' relationship with their service, across many Android devices. For example, a
79 * good set of identifiers might be the email addresses with which with users registered for
80 * their accounts with a particular service. Depending on how a service chooses to operate,
81 * a bad set of identifiers might be an increasing series of integers
82 * ({@code 0}, {@code 1}, {@code 2}, ...) that are generated locally on each phone and could
83 * collide with values generated on other phones or after a data wipe of a given phone.
Ihab Awadc35ad022014-06-12 16:29:42 -070084 *
Ihab Awadb19a0bc2014-08-07 19:46:01 -070085 * @return A service-specific unique identifier for this {@code PhoneAccountHandle}.
Ihab Awadc35ad022014-06-12 16:29:42 -070086 */
87 public String getId() {
88 return mId;
89 }
90
Evan Charlton134dd682014-11-25 14:12:57 -080091 /**
92 * @return the {@link UserHandle} to use when connecting to this PhoneAccount.
93 * @hide
94 */
95 public UserHandle getUserHandle() {
96 return mUserHandle;
97 }
98
Ihab Awad807fe0a2014-07-09 12:30:52 -070099 @Override
100 public int hashCode() {
Evan Charlton134dd682014-11-25 14:12:57 -0800101 return Objects.hash(mComponentName, mId, mUserHandle);
Ihab Awadc35ad022014-06-12 16:29:42 -0700102 }
103
Santos Cordon98b27032014-07-14 03:32:56 -0700104 @Override
105 public String toString() {
Tyler Gunn76c01a52014-09-30 14:47:51 -0700106 // Note: Log.pii called for mId as it can contain personally identifying phone account
107 // information such as SIP account IDs.
Santos Cordon98b27032014-07-14 03:32:56 -0700108 return new StringBuilder().append(mComponentName)
109 .append(", ")
Tyler Gunn76c01a52014-09-30 14:47:51 -0700110 .append(Log.pii(mId))
Evan Charlton134dd682014-11-25 14:12:57 -0800111 .append(", ")
112 .append(mUserHandle)
Santos Cordon98b27032014-07-14 03:32:56 -0700113 .toString();
114 }
115
Ihab Awad94cf4bf2014-07-17 11:21:19 -0700116 @Override
117 public boolean equals(Object other) {
Santos Cordon98b27032014-07-14 03:32:56 -0700118 return other != null &&
Evan Charlton6eb262c2014-07-19 18:18:19 -0700119 other instanceof PhoneAccountHandle &&
120 Objects.equals(((PhoneAccountHandle) other).getComponentName(),
121 getComponentName()) &&
Evan Charlton134dd682014-11-25 14:12:57 -0800122 Objects.equals(((PhoneAccountHandle) other).getId(), getId()) &&
123 Objects.equals(((PhoneAccountHandle) other).getUserHandle(), getUserHandle());
Santos Cordon98b27032014-07-14 03:32:56 -0700124 }
125
Ihab Awaddcaa5d62014-07-08 10:33:46 -0700126 //
Ihab Awad807fe0a2014-07-09 12:30:52 -0700127 // Parcelable implementation.
128 //
Ihab Awad542e0ea2014-05-16 10:22:16 -0700129
Sailesh Nepale7ef59a2014-07-08 21:48:22 -0700130 @Override
Ihab Awad542e0ea2014-05-16 10:22:16 -0700131 public int describeContents() {
132 return 0;
133 }
134
Sailesh Nepale7ef59a2014-07-08 21:48:22 -0700135 @Override
Ihab Awadc35ad022014-06-12 16:29:42 -0700136 public void writeToParcel(Parcel out, int flags) {
Evan Charlton134dd682014-11-25 14:12:57 -0800137 mComponentName.writeToParcel(out, flags);
Ihab Awadc35ad022014-06-12 16:29:42 -0700138 out.writeString(mId);
Evan Charlton134dd682014-11-25 14:12:57 -0800139 mUserHandle.writeToParcel(out, flags);
Ihab Awadc35ad022014-06-12 16:29:42 -0700140 }
Ihab Awad542e0ea2014-05-16 10:22:16 -0700141
Evan Charlton6eb262c2014-07-19 18:18:19 -0700142 public static final Creator<PhoneAccountHandle> CREATOR = new Creator<PhoneAccountHandle>() {
Ihab Awad807fe0a2014-07-09 12:30:52 -0700143 @Override
Evan Charlton6eb262c2014-07-19 18:18:19 -0700144 public PhoneAccountHandle createFromParcel(Parcel in) {
145 return new PhoneAccountHandle(in);
Ihab Awad542e0ea2014-05-16 10:22:16 -0700146 }
147
Ihab Awad807fe0a2014-07-09 12:30:52 -0700148 @Override
Evan Charlton6eb262c2014-07-19 18:18:19 -0700149 public PhoneAccountHandle[] newArray(int size) {
150 return new PhoneAccountHandle[size];
Ihab Awad542e0ea2014-05-16 10:22:16 -0700151 }
152 };
153
Evan Charlton6eb262c2014-07-19 18:18:19 -0700154 private PhoneAccountHandle(Parcel in) {
Evan Charlton134dd682014-11-25 14:12:57 -0800155 this(ComponentName.CREATOR.createFromParcel(in),
156 in.readString(),
157 UserHandle.CREATOR.createFromParcel(in));
Ihab Awadc35ad022014-06-12 16:29:42 -0700158 }
Ihab Awad542e0ea2014-05-16 10:22:16 -0700159}