blob: e13df7685d6d56cd3c42680aaa774259db8d916d [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() {
74 return new StringBuilder().append(mComponentName)
75 .append(", ")
76 .append(mId)
Santos Cordon98b27032014-07-14 03:32:56 -070077 .toString();
78 }
79
Ihab Awad94cf4bf2014-07-17 11:21:19 -070080 @Override
81 public boolean equals(Object other) {
Santos Cordon98b27032014-07-14 03:32:56 -070082 return other != null &&
Evan Charlton6eb262c2014-07-19 18:18:19 -070083 other instanceof PhoneAccountHandle &&
84 Objects.equals(((PhoneAccountHandle) other).getComponentName(),
85 getComponentName()) &&
86 Objects.equals(((PhoneAccountHandle) other).getId(), getId());
Santos Cordon98b27032014-07-14 03:32:56 -070087 }
88
Ihab Awaddcaa5d62014-07-08 10:33:46 -070089 //
Ihab Awad807fe0a2014-07-09 12:30:52 -070090 // Parcelable implementation.
91 //
Ihab Awad542e0ea2014-05-16 10:22:16 -070092
Sailesh Nepale7ef59a2014-07-08 21:48:22 -070093 @Override
Ihab Awad542e0ea2014-05-16 10:22:16 -070094 public int describeContents() {
95 return 0;
96 }
97
Sailesh Nepale7ef59a2014-07-08 21:48:22 -070098 @Override
Ihab Awadc35ad022014-06-12 16:29:42 -070099 public void writeToParcel(Parcel out, int flags) {
100 out.writeParcelable(mComponentName, flags);
101 out.writeString(mId);
Ihab Awadc35ad022014-06-12 16:29:42 -0700102 }
Ihab Awad542e0ea2014-05-16 10:22:16 -0700103
Evan Charlton6eb262c2014-07-19 18:18:19 -0700104 public static final Creator<PhoneAccountHandle> CREATOR = new Creator<PhoneAccountHandle>() {
Ihab Awad807fe0a2014-07-09 12:30:52 -0700105 @Override
Evan Charlton6eb262c2014-07-19 18:18:19 -0700106 public PhoneAccountHandle createFromParcel(Parcel in) {
107 return new PhoneAccountHandle(in);
Ihab Awad542e0ea2014-05-16 10:22:16 -0700108 }
109
Ihab Awad807fe0a2014-07-09 12:30:52 -0700110 @Override
Evan Charlton6eb262c2014-07-19 18:18:19 -0700111 public PhoneAccountHandle[] newArray(int size) {
112 return new PhoneAccountHandle[size];
Ihab Awad542e0ea2014-05-16 10:22:16 -0700113 }
114 };
115
Evan Charlton6eb262c2014-07-19 18:18:19 -0700116 private PhoneAccountHandle(Parcel in) {
Ihab Awadc35ad022014-06-12 16:29:42 -0700117 mComponentName = in.readParcelable(getClass().getClassLoader());
118 mId = in.readString();
Ihab Awadc35ad022014-06-12 16:29:42 -0700119 }
Ihab Awad542e0ea2014-05-16 10:22:16 -0700120}