blob: 768188b81c4986eb2bfc8023071d779717f89de3 [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/**
Ihab Awadb19a0bc2014-08-07 19:46:01 -070026 * The unique identifier for a {@link PhoneAccount}.
Ihab Awad542e0ea2014-05-16 10:22:16 -070027 */
Evan Charlton6eb262c2014-07-19 18:18:19 -070028public class PhoneAccountHandle implements Parcelable {
Ihab Awad807fe0a2014-07-09 12:30:52 -070029 private ComponentName mComponentName;
30 private String mId;
Ihab Awadc35ad022014-06-12 16:29:42 -070031
Evan Charlton6eb262c2014-07-19 18:18:19 -070032 public PhoneAccountHandle(
Ihab Awadc35ad022014-06-12 16:29:42 -070033 ComponentName componentName,
Ihab Awad94cf4bf2014-07-17 11:21:19 -070034 String id) {
Ihab Awadc35ad022014-06-12 16:29:42 -070035 mComponentName = componentName;
36 mId = id;
Ihab Awadc35ad022014-06-12 16:29:42 -070037 }
38
39 /**
Tyler Gunnef9f6f92014-09-12 22:16:17 -070040 * The {@code ComponentName} of the {@link android.telecom.ConnectionService} which is
Evan Charlton6eb262c2014-07-19 18:18:19 -070041 * responsible for making phone calls using this {@code PhoneAccountHandle}.
Ihab Awadc35ad022014-06-12 16:29:42 -070042 *
43 * @return A suitable {@code ComponentName}.
44 */
45 public ComponentName getComponentName() {
46 return mComponentName;
47 }
48
49 /**
Ihab Awadb19a0bc2014-08-07 19:46:01 -070050 * A string that uniquely distinguishes this particular {@code PhoneAccountHandle} from all the
51 * others supported by the {@link ConnectionService} that created it.
52 * <p>
53 * A {@code ConnectionService} must select identifiers that are stable for the lifetime of
54 * their users' relationship with their service, across many Android devices. For example, a
55 * good set of identifiers might be the email addresses with which with users registered for
56 * their accounts with a particular service. Depending on how a service chooses to operate,
57 * a bad set of identifiers might be an increasing series of integers
58 * ({@code 0}, {@code 1}, {@code 2}, ...) that are generated locally on each phone and could
59 * collide with values generated on other phones or after a data wipe of a given phone.
Ihab Awadc35ad022014-06-12 16:29:42 -070060 *
Ihab Awadb19a0bc2014-08-07 19:46:01 -070061 * @return A service-specific unique identifier for this {@code PhoneAccountHandle}.
Ihab Awadc35ad022014-06-12 16:29:42 -070062 */
63 public String getId() {
64 return mId;
65 }
66
Ihab Awad807fe0a2014-07-09 12:30:52 -070067 @Override
68 public int hashCode() {
Ihab Awad94cf4bf2014-07-17 11:21:19 -070069 return Objects.hashCode(mComponentName) + Objects.hashCode(mId);
Ihab Awadc35ad022014-06-12 16:29:42 -070070 }
71
Santos Cordon98b27032014-07-14 03:32:56 -070072 @Override
73 public String toString() {
Tyler Gunn76c01a52014-09-30 14:47:51 -070074 // Note: Log.pii called for mId as it can contain personally identifying phone account
75 // information such as SIP account IDs.
Santos Cordon98b27032014-07-14 03:32:56 -070076 return new StringBuilder().append(mComponentName)
77 .append(", ")
Tyler Gunn76c01a52014-09-30 14:47:51 -070078 .append(Log.pii(mId))
Santos Cordon98b27032014-07-14 03:32:56 -070079 .toString();
80 }
81
Ihab Awad94cf4bf2014-07-17 11:21:19 -070082 @Override
83 public boolean equals(Object other) {
Santos Cordon98b27032014-07-14 03:32:56 -070084 return other != null &&
Evan Charlton6eb262c2014-07-19 18:18:19 -070085 other instanceof PhoneAccountHandle &&
86 Objects.equals(((PhoneAccountHandle) other).getComponentName(),
87 getComponentName()) &&
88 Objects.equals(((PhoneAccountHandle) other).getId(), getId());
Santos Cordon98b27032014-07-14 03:32:56 -070089 }
90
Ihab Awaddcaa5d62014-07-08 10:33:46 -070091 //
Ihab Awad807fe0a2014-07-09 12:30:52 -070092 // Parcelable implementation.
93 //
Ihab Awad542e0ea2014-05-16 10:22:16 -070094
Sailesh Nepale7ef59a2014-07-08 21:48:22 -070095 @Override
Ihab Awad542e0ea2014-05-16 10:22:16 -070096 public int describeContents() {
97 return 0;
98 }
99
Sailesh Nepale7ef59a2014-07-08 21:48:22 -0700100 @Override
Ihab Awadc35ad022014-06-12 16:29:42 -0700101 public void writeToParcel(Parcel out, int flags) {
102 out.writeParcelable(mComponentName, flags);
103 out.writeString(mId);
Ihab Awadc35ad022014-06-12 16:29:42 -0700104 }
Ihab Awad542e0ea2014-05-16 10:22:16 -0700105
Evan Charlton6eb262c2014-07-19 18:18:19 -0700106 public static final Creator<PhoneAccountHandle> CREATOR = new Creator<PhoneAccountHandle>() {
Ihab Awad807fe0a2014-07-09 12:30:52 -0700107 @Override
Evan Charlton6eb262c2014-07-19 18:18:19 -0700108 public PhoneAccountHandle createFromParcel(Parcel in) {
109 return new PhoneAccountHandle(in);
Ihab Awad542e0ea2014-05-16 10:22:16 -0700110 }
111
Ihab Awad807fe0a2014-07-09 12:30:52 -0700112 @Override
Evan Charlton6eb262c2014-07-19 18:18:19 -0700113 public PhoneAccountHandle[] newArray(int size) {
114 return new PhoneAccountHandle[size];
Ihab Awad542e0ea2014-05-16 10:22:16 -0700115 }
116 };
117
Evan Charlton6eb262c2014-07-19 18:18:19 -0700118 private PhoneAccountHandle(Parcel in) {
Ihab Awadc35ad022014-06-12 16:29:42 -0700119 mComponentName = in.readParcelable(getClass().getClassLoader());
120 mId = in.readString();
Ihab Awadc35ad022014-06-12 16:29:42 -0700121 }
Ihab Awad542e0ea2014-05-16 10:22:16 -0700122}