blob: bc4cc8ce4e83268c7cee719fd66d6d3791b0bd39 [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
Ihab Awadc35ad022014-06-12 16:29:42 -070019import android.content.ComponentName;
Ihab Awad542e0ea2014-05-16 10:22:16 -070020import android.os.Parcel;
21import android.os.Parcelable;
Ihab Awadc35ad022014-06-12 16:29:42 -070022
Ihab Awaddcaa5d62014-07-08 10:33:46 -070023import java.util.Objects;
Ihab Awad542e0ea2014-05-16 10:22:16 -070024
25/**
Santos Cordond9e614f2014-10-28 13:10:36 -070026 * The unique identifier for a {@link PhoneAccount}. A {@code PhoneAccountHandle} is made of two
27 * parts:
28 * <ul>
29 * <li>The component name of the associated {@link ConnectionService}.</li>
30 * <li>A string identifier that is unique across {@code PhoneAccountHandle}s with the same
31 * component name.</li>
32 * </ul>
33 *
34 * See {@link PhoneAccount},
35 * {@link TelecomManager#registerPhoneAccount TelecomManager.registerPhoneAccount}.
Ihab Awad542e0ea2014-05-16 10:22:16 -070036 */
Evan Charlton6eb262c2014-07-19 18:18:19 -070037public class PhoneAccountHandle implements Parcelable {
Ihab Awad807fe0a2014-07-09 12:30:52 -070038 private ComponentName mComponentName;
39 private String mId;
Ihab Awadc35ad022014-06-12 16:29:42 -070040
Evan Charlton6eb262c2014-07-19 18:18:19 -070041 public PhoneAccountHandle(
Ihab Awadc35ad022014-06-12 16:29:42 -070042 ComponentName componentName,
Ihab Awad94cf4bf2014-07-17 11:21:19 -070043 String id) {
Ihab Awadc35ad022014-06-12 16:29:42 -070044 mComponentName = componentName;
45 mId = id;
Ihab Awadc35ad022014-06-12 16:29:42 -070046 }
47
48 /**
Tyler Gunnef9f6f92014-09-12 22:16:17 -070049 * The {@code ComponentName} of the {@link android.telecom.ConnectionService} which is
Evan Charlton6eb262c2014-07-19 18:18:19 -070050 * responsible for making phone calls using this {@code PhoneAccountHandle}.
Ihab Awadc35ad022014-06-12 16:29:42 -070051 *
52 * @return A suitable {@code ComponentName}.
53 */
54 public ComponentName getComponentName() {
55 return mComponentName;
56 }
57
58 /**
Ihab Awadb19a0bc2014-08-07 19:46:01 -070059 * A string that uniquely distinguishes this particular {@code PhoneAccountHandle} from all the
60 * others supported by the {@link ConnectionService} that created it.
61 * <p>
62 * A {@code ConnectionService} must select identifiers that are stable for the lifetime of
63 * their users' relationship with their service, across many Android devices. For example, a
64 * good set of identifiers might be the email addresses with which with users registered for
65 * their accounts with a particular service. Depending on how a service chooses to operate,
66 * a bad set of identifiers might be an increasing series of integers
67 * ({@code 0}, {@code 1}, {@code 2}, ...) that are generated locally on each phone and could
68 * collide with values generated on other phones or after a data wipe of a given phone.
Ihab Awadc35ad022014-06-12 16:29:42 -070069 *
Ihab Awadb19a0bc2014-08-07 19:46:01 -070070 * @return A service-specific unique identifier for this {@code PhoneAccountHandle}.
Ihab Awadc35ad022014-06-12 16:29:42 -070071 */
72 public String getId() {
73 return mId;
74 }
75
Ihab Awad807fe0a2014-07-09 12:30:52 -070076 @Override
77 public int hashCode() {
Ihab Awad94cf4bf2014-07-17 11:21:19 -070078 return Objects.hashCode(mComponentName) + Objects.hashCode(mId);
Ihab Awadc35ad022014-06-12 16:29:42 -070079 }
80
Santos Cordon98b27032014-07-14 03:32:56 -070081 @Override
82 public String toString() {
Tyler Gunn76c01a52014-09-30 14:47:51 -070083 // Note: Log.pii called for mId as it can contain personally identifying phone account
84 // information such as SIP account IDs.
Santos Cordon98b27032014-07-14 03:32:56 -070085 return new StringBuilder().append(mComponentName)
86 .append(", ")
Tyler Gunn76c01a52014-09-30 14:47:51 -070087 .append(Log.pii(mId))
Santos Cordon98b27032014-07-14 03:32:56 -070088 .toString();
89 }
90
Ihab Awad94cf4bf2014-07-17 11:21:19 -070091 @Override
92 public boolean equals(Object other) {
Santos Cordon98b27032014-07-14 03:32:56 -070093 return other != null &&
Evan Charlton6eb262c2014-07-19 18:18:19 -070094 other instanceof PhoneAccountHandle &&
95 Objects.equals(((PhoneAccountHandle) other).getComponentName(),
96 getComponentName()) &&
97 Objects.equals(((PhoneAccountHandle) other).getId(), getId());
Santos Cordon98b27032014-07-14 03:32:56 -070098 }
99
Ihab Awaddcaa5d62014-07-08 10:33:46 -0700100 //
Ihab Awad807fe0a2014-07-09 12:30:52 -0700101 // Parcelable implementation.
102 //
Ihab Awad542e0ea2014-05-16 10:22:16 -0700103
Sailesh Nepale7ef59a2014-07-08 21:48:22 -0700104 @Override
Ihab Awad542e0ea2014-05-16 10:22:16 -0700105 public int describeContents() {
106 return 0;
107 }
108
Sailesh Nepale7ef59a2014-07-08 21:48:22 -0700109 @Override
Ihab Awadc35ad022014-06-12 16:29:42 -0700110 public void writeToParcel(Parcel out, int flags) {
111 out.writeParcelable(mComponentName, flags);
112 out.writeString(mId);
Ihab Awadc35ad022014-06-12 16:29:42 -0700113 }
Ihab Awad542e0ea2014-05-16 10:22:16 -0700114
Evan Charlton6eb262c2014-07-19 18:18:19 -0700115 public static final Creator<PhoneAccountHandle> CREATOR = new Creator<PhoneAccountHandle>() {
Ihab Awad807fe0a2014-07-09 12:30:52 -0700116 @Override
Evan Charlton6eb262c2014-07-19 18:18:19 -0700117 public PhoneAccountHandle createFromParcel(Parcel in) {
118 return new PhoneAccountHandle(in);
Ihab Awad542e0ea2014-05-16 10:22:16 -0700119 }
120
Ihab Awad807fe0a2014-07-09 12:30:52 -0700121 @Override
Evan Charlton6eb262c2014-07-19 18:18:19 -0700122 public PhoneAccountHandle[] newArray(int size) {
123 return new PhoneAccountHandle[size];
Ihab Awad542e0ea2014-05-16 10:22:16 -0700124 }
125 };
126
Evan Charlton6eb262c2014-07-19 18:18:19 -0700127 private PhoneAccountHandle(Parcel in) {
Ihab Awadc35ad022014-06-12 16:29:42 -0700128 mComponentName = in.readParcelable(getClass().getClassLoader());
129 mId = in.readString();
Ihab Awadc35ad022014-06-12 16:29:42 -0700130 }
Ihab Awad542e0ea2014-05-16 10:22:16 -0700131}