blob: 570f5fdf2ffa2b12441657794e4d014c9562d8a2 [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 Attwellad147f42014-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 Attwellad147f42014-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 Attwellad147f42014-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 Attwellad147f42014-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 Attwellad147f42014-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 Attwellad147f42014-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 *
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.
91 * @hide
92 */
Brian Attwellad147f42014-12-19 11:37:16 -080093 @SystemApi
Evan Charlton134dd682014-11-25 14:12:57 -080094 public UserHandle getUserHandle() {
95 return mUserHandle;
96 }
97
Ihab Awad807fe0a2014-07-09 12:30:52 -070098 @Override
99 public int hashCode() {
Evan Charlton134dd682014-11-25 14:12:57 -0800100 return Objects.hash(mComponentName, mId, mUserHandle);
Ihab Awadc35ad022014-06-12 16:29:42 -0700101 }
102
Santos Cordon98b27032014-07-14 03:32:56 -0700103 @Override
104 public String toString() {
Tyler Gunn76c01a52014-09-30 14:47:51 -0700105 // Note: Log.pii called for mId as it can contain personally identifying phone account
106 // information such as SIP account IDs.
Santos Cordon98b27032014-07-14 03:32:56 -0700107 return new StringBuilder().append(mComponentName)
108 .append(", ")
Tyler Gunn76c01a52014-09-30 14:47:51 -0700109 .append(Log.pii(mId))
Evan Charlton134dd682014-11-25 14:12:57 -0800110 .append(", ")
111 .append(mUserHandle)
Santos Cordon98b27032014-07-14 03:32:56 -0700112 .toString();
113 }
114
Ihab Awad94cf4bf2014-07-17 11:21:19 -0700115 @Override
116 public boolean equals(Object other) {
Santos Cordon98b27032014-07-14 03:32:56 -0700117 return other != null &&
Evan Charlton6eb262c2014-07-19 18:18:19 -0700118 other instanceof PhoneAccountHandle &&
119 Objects.equals(((PhoneAccountHandle) other).getComponentName(),
120 getComponentName()) &&
Evan Charlton134dd682014-11-25 14:12:57 -0800121 Objects.equals(((PhoneAccountHandle) other).getId(), getId()) &&
122 Objects.equals(((PhoneAccountHandle) other).getUserHandle(), getUserHandle());
Santos Cordon98b27032014-07-14 03:32:56 -0700123 }
124
Ihab Awaddcaa5d62014-07-08 10:33:46 -0700125 //
Ihab Awad807fe0a2014-07-09 12:30:52 -0700126 // Parcelable implementation.
127 //
Ihab Awad542e0ea2014-05-16 10:22:16 -0700128
Sailesh Nepale7ef59a2014-07-08 21:48:22 -0700129 @Override
Ihab Awad542e0ea2014-05-16 10:22:16 -0700130 public int describeContents() {
131 return 0;
132 }
133
Sailesh Nepale7ef59a2014-07-08 21:48:22 -0700134 @Override
Ihab Awadc35ad022014-06-12 16:29:42 -0700135 public void writeToParcel(Parcel out, int flags) {
Evan Charlton134dd682014-11-25 14:12:57 -0800136 mComponentName.writeToParcel(out, flags);
Ihab Awadc35ad022014-06-12 16:29:42 -0700137 out.writeString(mId);
Evan Charlton134dd682014-11-25 14:12:57 -0800138 mUserHandle.writeToParcel(out, flags);
Ihab Awadc35ad022014-06-12 16:29:42 -0700139 }
Ihab Awad542e0ea2014-05-16 10:22:16 -0700140
Evan Charlton6eb262c2014-07-19 18:18:19 -0700141 public static final Creator<PhoneAccountHandle> CREATOR = new Creator<PhoneAccountHandle>() {
Ihab Awad807fe0a2014-07-09 12:30:52 -0700142 @Override
Evan Charlton6eb262c2014-07-19 18:18:19 -0700143 public PhoneAccountHandle createFromParcel(Parcel in) {
144 return new PhoneAccountHandle(in);
Ihab Awad542e0ea2014-05-16 10:22:16 -0700145 }
146
Ihab Awad807fe0a2014-07-09 12:30:52 -0700147 @Override
Evan Charlton6eb262c2014-07-19 18:18:19 -0700148 public PhoneAccountHandle[] newArray(int size) {
149 return new PhoneAccountHandle[size];
Ihab Awad542e0ea2014-05-16 10:22:16 -0700150 }
151 };
152
Evan Charlton6eb262c2014-07-19 18:18:19 -0700153 private PhoneAccountHandle(Parcel in) {
Evan Charlton134dd682014-11-25 14:12:57 -0800154 this(ComponentName.CREATOR.createFromParcel(in),
155 in.readString(),
156 UserHandle.CREATOR.createFromParcel(in));
Ihab Awadc35ad022014-06-12 16:29:42 -0700157 }
Ihab Awad542e0ea2014-05-16 10:22:16 -0700158}