Ihab Awad | 542e0ea | 2014-05-16 10:22:16 -0700 | [diff] [blame] | 1 | /* |
| 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 Gunn | ef9f6f9 | 2014-09-12 22:16:17 -0700 | [diff] [blame] | 17 | package android.telecom; |
Ihab Awad | 542e0ea | 2014-05-16 10:22:16 -0700 | [diff] [blame] | 18 | |
Brad Ebinger | 428cec9 | 2016-03-15 14:23:44 -0700 | [diff] [blame] | 19 | import android.annotation.NonNull; |
Ihab Awad | c35ad02 | 2014-06-12 16:29:42 -0700 | [diff] [blame] | 20 | import android.content.ComponentName; |
Ihab Awad | 542e0ea | 2014-05-16 10:22:16 -0700 | [diff] [blame] | 21 | import android.os.Parcel; |
| 22 | import android.os.Parcelable; |
Evan Charlton | 134dd68 | 2014-11-25 14:12:57 -0800 | [diff] [blame] | 23 | import android.os.Process; |
| 24 | import android.os.UserHandle; |
Ihab Awad | c35ad02 | 2014-06-12 16:29:42 -0700 | [diff] [blame] | 25 | |
Ihab Awad | dcaa5d6 | 2014-07-08 10:33:46 -0700 | [diff] [blame] | 26 | import java.util.Objects; |
Ihab Awad | 542e0ea | 2014-05-16 10:22:16 -0700 | [diff] [blame] | 27 | |
| 28 | /** |
Santos Cordon | d9e614f | 2014-10-28 13:10:36 -0700 | [diff] [blame] | 29 | * The unique identifier for a {@link PhoneAccount}. A {@code PhoneAccountHandle} is made of two |
| 30 | * parts: |
| 31 | * <ul> |
Brian Attwell | ad147f4 | 2014-12-19 11:37:16 -0800 | [diff] [blame] | 32 | * <li>The component name of the associated connection service.</li> |
Santos Cordon | d9e614f | 2014-10-28 13:10:36 -0700 | [diff] [blame] | 33 | * <li>A string identifier that is unique across {@code PhoneAccountHandle}s with the same |
| 34 | * component name.</li> |
| 35 | * </ul> |
| 36 | * |
Brad Ebinger | 428cec9 | 2016-03-15 14:23:44 -0700 | [diff] [blame] | 37 | * Note: This Class requires a non-null {@link ComponentName} and {@link UserHandle} to operate |
| 38 | * properly. Passing in invalid parameters will generate a log warning. |
| 39 | * |
Brian Attwell | ad147f4 | 2014-12-19 11:37:16 -0800 | [diff] [blame] | 40 | * See {@link PhoneAccount}, {@link TelecomManager}. |
Ihab Awad | 542e0ea | 2014-05-16 10:22:16 -0700 | [diff] [blame] | 41 | */ |
Yorke Lee | 400470f | 2015-05-12 13:31:25 -0700 | [diff] [blame] | 42 | public final class PhoneAccountHandle implements Parcelable { |
Evan Charlton | 134dd68 | 2014-11-25 14:12:57 -0800 | [diff] [blame] | 43 | private final ComponentName mComponentName; |
| 44 | private final String mId; |
| 45 | private final UserHandle mUserHandle; |
Ihab Awad | c35ad02 | 2014-06-12 16:29:42 -0700 | [diff] [blame] | 46 | |
Evan Charlton | 6eb262c | 2014-07-19 18:18:19 -0700 | [diff] [blame] | 47 | public PhoneAccountHandle( |
Brad Ebinger | 428cec9 | 2016-03-15 14:23:44 -0700 | [diff] [blame] | 48 | @NonNull ComponentName componentName, |
| 49 | @NonNull String id) { |
Evan Charlton | 134dd68 | 2014-11-25 14:12:57 -0800 | [diff] [blame] | 50 | this(componentName, id, Process.myUserHandle()); |
| 51 | } |
| 52 | |
Evan Charlton | 134dd68 | 2014-11-25 14:12:57 -0800 | [diff] [blame] | 53 | public PhoneAccountHandle( |
Brad Ebinger | 428cec9 | 2016-03-15 14:23:44 -0700 | [diff] [blame] | 54 | @NonNull ComponentName componentName, |
| 55 | @NonNull String id, |
| 56 | @NonNull UserHandle userHandle) { |
| 57 | checkParameters(componentName, userHandle); |
Ihab Awad | c35ad02 | 2014-06-12 16:29:42 -0700 | [diff] [blame] | 58 | mComponentName = componentName; |
| 59 | mId = id; |
Evan Charlton | 134dd68 | 2014-11-25 14:12:57 -0800 | [diff] [blame] | 60 | mUserHandle = userHandle; |
Ihab Awad | c35ad02 | 2014-06-12 16:29:42 -0700 | [diff] [blame] | 61 | } |
| 62 | |
| 63 | /** |
Brian Attwell | ad147f4 | 2014-12-19 11:37:16 -0800 | [diff] [blame] | 64 | * The {@code ComponentName} of the connection service which is responsible for making phone |
| 65 | * calls using this {@code PhoneAccountHandle}. |
Ihab Awad | c35ad02 | 2014-06-12 16:29:42 -0700 | [diff] [blame] | 66 | * |
| 67 | * @return A suitable {@code ComponentName}. |
| 68 | */ |
| 69 | public ComponentName getComponentName() { |
| 70 | return mComponentName; |
| 71 | } |
| 72 | |
| 73 | /** |
Ihab Awad | b19a0bc | 2014-08-07 19:46:01 -0700 | [diff] [blame] | 74 | * A string that uniquely distinguishes this particular {@code PhoneAccountHandle} from all the |
Brian Attwell | ad147f4 | 2014-12-19 11:37:16 -0800 | [diff] [blame] | 75 | * others supported by the connection service that created it. |
Ihab Awad | b19a0bc | 2014-08-07 19:46:01 -0700 | [diff] [blame] | 76 | * <p> |
Brian Attwell | ad147f4 | 2014-12-19 11:37:16 -0800 | [diff] [blame] | 77 | * A connection service must select identifiers that are stable for the lifetime of |
Ihab Awad | b19a0bc | 2014-08-07 19:46:01 -0700 | [diff] [blame] | 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 Awad | c35ad02 | 2014-06-12 16:29:42 -0700 | [diff] [blame] | 84 | * |
Santos Cordon | 8b338d4 | 2015-02-10 03:38:31 -0800 | [diff] [blame] | 85 | * Important: A non-unique identifier could cause non-deterministic call-log backup/restore |
| 86 | * behavior. |
| 87 | * |
Ihab Awad | b19a0bc | 2014-08-07 19:46:01 -0700 | [diff] [blame] | 88 | * @return A service-specific unique identifier for this {@code PhoneAccountHandle}. |
Ihab Awad | c35ad02 | 2014-06-12 16:29:42 -0700 | [diff] [blame] | 89 | */ |
| 90 | public String getId() { |
| 91 | return mId; |
| 92 | } |
| 93 | |
Evan Charlton | 134dd68 | 2014-11-25 14:12:57 -0800 | [diff] [blame] | 94 | /** |
| 95 | * @return the {@link UserHandle} to use when connecting to this PhoneAccount. |
Evan Charlton | 134dd68 | 2014-11-25 14:12:57 -0800 | [diff] [blame] | 96 | */ |
| 97 | public UserHandle getUserHandle() { |
| 98 | return mUserHandle; |
| 99 | } |
| 100 | |
Ihab Awad | 807fe0a | 2014-07-09 12:30:52 -0700 | [diff] [blame] | 101 | @Override |
| 102 | public int hashCode() { |
Evan Charlton | 134dd68 | 2014-11-25 14:12:57 -0800 | [diff] [blame] | 103 | return Objects.hash(mComponentName, mId, mUserHandle); |
Ihab Awad | c35ad02 | 2014-06-12 16:29:42 -0700 | [diff] [blame] | 104 | } |
| 105 | |
Santos Cordon | 98b2703 | 2014-07-14 03:32:56 -0700 | [diff] [blame] | 106 | @Override |
| 107 | public String toString() { |
Tyler Gunn | 76c01a5 | 2014-09-30 14:47:51 -0700 | [diff] [blame] | 108 | // Note: Log.pii called for mId as it can contain personally identifying phone account |
| 109 | // information such as SIP account IDs. |
Santos Cordon | 98b2703 | 2014-07-14 03:32:56 -0700 | [diff] [blame] | 110 | return new StringBuilder().append(mComponentName) |
| 111 | .append(", ") |
Tyler Gunn | 76c01a5 | 2014-09-30 14:47:51 -0700 | [diff] [blame] | 112 | .append(Log.pii(mId)) |
Evan Charlton | 134dd68 | 2014-11-25 14:12:57 -0800 | [diff] [blame] | 113 | .append(", ") |
| 114 | .append(mUserHandle) |
Santos Cordon | 98b2703 | 2014-07-14 03:32:56 -0700 | [diff] [blame] | 115 | .toString(); |
| 116 | } |
| 117 | |
Ihab Awad | 94cf4bf | 2014-07-17 11:21:19 -0700 | [diff] [blame] | 118 | @Override |
| 119 | public boolean equals(Object other) { |
Santos Cordon | 98b2703 | 2014-07-14 03:32:56 -0700 | [diff] [blame] | 120 | return other != null && |
Evan Charlton | 6eb262c | 2014-07-19 18:18:19 -0700 | [diff] [blame] | 121 | other instanceof PhoneAccountHandle && |
| 122 | Objects.equals(((PhoneAccountHandle) other).getComponentName(), |
| 123 | getComponentName()) && |
Evan Charlton | 134dd68 | 2014-11-25 14:12:57 -0800 | [diff] [blame] | 124 | Objects.equals(((PhoneAccountHandle) other).getId(), getId()) && |
| 125 | Objects.equals(((PhoneAccountHandle) other).getUserHandle(), getUserHandle()); |
Santos Cordon | 98b2703 | 2014-07-14 03:32:56 -0700 | [diff] [blame] | 126 | } |
| 127 | |
Ihab Awad | dcaa5d6 | 2014-07-08 10:33:46 -0700 | [diff] [blame] | 128 | // |
Ihab Awad | 807fe0a | 2014-07-09 12:30:52 -0700 | [diff] [blame] | 129 | // Parcelable implementation. |
| 130 | // |
Ihab Awad | 542e0ea | 2014-05-16 10:22:16 -0700 | [diff] [blame] | 131 | |
Sailesh Nepal | e7ef59a | 2014-07-08 21:48:22 -0700 | [diff] [blame] | 132 | @Override |
Ihab Awad | 542e0ea | 2014-05-16 10:22:16 -0700 | [diff] [blame] | 133 | public int describeContents() { |
| 134 | return 0; |
| 135 | } |
| 136 | |
Sailesh Nepal | e7ef59a | 2014-07-08 21:48:22 -0700 | [diff] [blame] | 137 | @Override |
Ihab Awad | c35ad02 | 2014-06-12 16:29:42 -0700 | [diff] [blame] | 138 | public void writeToParcel(Parcel out, int flags) { |
Evan Charlton | 134dd68 | 2014-11-25 14:12:57 -0800 | [diff] [blame] | 139 | mComponentName.writeToParcel(out, flags); |
Ihab Awad | c35ad02 | 2014-06-12 16:29:42 -0700 | [diff] [blame] | 140 | out.writeString(mId); |
Evan Charlton | 134dd68 | 2014-11-25 14:12:57 -0800 | [diff] [blame] | 141 | mUserHandle.writeToParcel(out, flags); |
Ihab Awad | c35ad02 | 2014-06-12 16:29:42 -0700 | [diff] [blame] | 142 | } |
Ihab Awad | 542e0ea | 2014-05-16 10:22:16 -0700 | [diff] [blame] | 143 | |
Brad Ebinger | 428cec9 | 2016-03-15 14:23:44 -0700 | [diff] [blame] | 144 | private void checkParameters(ComponentName componentName, UserHandle userHandle) { |
| 145 | if(componentName == null) { |
| 146 | android.util.Log.w("PhoneAccountHandle", new Exception("PhoneAccountHandle has " + |
| 147 | "been created with null ComponentName!")); |
| 148 | } |
| 149 | if(userHandle == null) { |
| 150 | android.util.Log.w("PhoneAccountHandle", new Exception("PhoneAccountHandle has " + |
| 151 | "been created with null UserHandle!")); |
| 152 | } |
| 153 | } |
| 154 | |
Evan Charlton | 6eb262c | 2014-07-19 18:18:19 -0700 | [diff] [blame] | 155 | public static final Creator<PhoneAccountHandle> CREATOR = new Creator<PhoneAccountHandle>() { |
Ihab Awad | 807fe0a | 2014-07-09 12:30:52 -0700 | [diff] [blame] | 156 | @Override |
Evan Charlton | 6eb262c | 2014-07-19 18:18:19 -0700 | [diff] [blame] | 157 | public PhoneAccountHandle createFromParcel(Parcel in) { |
| 158 | return new PhoneAccountHandle(in); |
Ihab Awad | 542e0ea | 2014-05-16 10:22:16 -0700 | [diff] [blame] | 159 | } |
| 160 | |
Ihab Awad | 807fe0a | 2014-07-09 12:30:52 -0700 | [diff] [blame] | 161 | @Override |
Evan Charlton | 6eb262c | 2014-07-19 18:18:19 -0700 | [diff] [blame] | 162 | public PhoneAccountHandle[] newArray(int size) { |
| 163 | return new PhoneAccountHandle[size]; |
Ihab Awad | 542e0ea | 2014-05-16 10:22:16 -0700 | [diff] [blame] | 164 | } |
| 165 | }; |
| 166 | |
Evan Charlton | 6eb262c | 2014-07-19 18:18:19 -0700 | [diff] [blame] | 167 | private PhoneAccountHandle(Parcel in) { |
Evan Charlton | 134dd68 | 2014-11-25 14:12:57 -0800 | [diff] [blame] | 168 | this(ComponentName.CREATOR.createFromParcel(in), |
| 169 | in.readString(), |
| 170 | UserHandle.CREATOR.createFromParcel(in)); |
Ihab Awad | c35ad02 | 2014-06-12 16:29:42 -0700 | [diff] [blame] | 171 | } |
Ihab Awad | 542e0ea | 2014-05-16 10:22:16 -0700 | [diff] [blame] | 172 | } |