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