| 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 | |
| Evan Charlton | 0e094d9 | 2014-11-08 15:49:16 -0800 | [diff] [blame] | 19 | import android.annotation.SystemApi; |
| 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 | 48d8442e | 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 | * |
| Brian Attwell | 48d8442e | 2014-12-19 11:37:16 -0800 | [diff] [blame] | 37 | * See {@link PhoneAccount}, {@link TelecomManager}. |
| Ihab Awad | 542e0ea | 2014-05-16 10:22:16 -0700 | [diff] [blame] | 38 | */ |
| Evan Charlton | 6eb262c | 2014-07-19 18:18:19 -0700 | [diff] [blame] | 39 | public class PhoneAccountHandle implements Parcelable { |
| Evan Charlton | 134dd68 | 2014-11-25 14:12:57 -0800 | [diff] [blame] | 40 | private final ComponentName mComponentName; |
| 41 | private final String mId; |
| 42 | private final UserHandle mUserHandle; |
| Ihab Awad | c35ad02 | 2014-06-12 16:29:42 -0700 | [diff] [blame] | 43 | |
| Evan Charlton | 6eb262c | 2014-07-19 18:18:19 -0700 | [diff] [blame] | 44 | public PhoneAccountHandle( |
| Ihab Awad | c35ad02 | 2014-06-12 16:29:42 -0700 | [diff] [blame] | 45 | ComponentName componentName, |
| Ihab Awad | 94cf4bf | 2014-07-17 11:21:19 -0700 | [diff] [blame] | 46 | String id) { |
| Evan Charlton | 134dd68 | 2014-11-25 14:12:57 -0800 | [diff] [blame] | 47 | this(componentName, id, Process.myUserHandle()); |
| 48 | } |
| 49 | |
| 50 | /** @hide */ |
| Brian Attwell | 48d8442e | 2014-12-19 11:37:16 -0800 | [diff] [blame] | 51 | @SystemApi |
| Evan Charlton | 134dd68 | 2014-11-25 14:12:57 -0800 | [diff] [blame] | 52 | public PhoneAccountHandle( |
| 53 | ComponentName componentName, |
| 54 | String id, |
| 55 | UserHandle userHandle) { |
| Ihab Awad | c35ad02 | 2014-06-12 16:29:42 -0700 | [diff] [blame] | 56 | mComponentName = componentName; |
| 57 | mId = id; |
| Evan Charlton | 134dd68 | 2014-11-25 14:12:57 -0800 | [diff] [blame] | 58 | mUserHandle = userHandle; |
| Ihab Awad | c35ad02 | 2014-06-12 16:29:42 -0700 | [diff] [blame] | 59 | } |
| 60 | |
| 61 | /** |
| Brian Attwell | 48d8442e | 2014-12-19 11:37:16 -0800 | [diff] [blame] | 62 | * The {@code ComponentName} of the connection service which is responsible for making phone |
| 63 | * calls using this {@code PhoneAccountHandle}. |
| Ihab Awad | c35ad02 | 2014-06-12 16:29:42 -0700 | [diff] [blame] | 64 | * |
| 65 | * @return A suitable {@code ComponentName}. |
| 66 | */ |
| 67 | public ComponentName getComponentName() { |
| 68 | return mComponentName; |
| 69 | } |
| 70 | |
| 71 | /** |
| Ihab Awad | b19a0bc | 2014-08-07 19:46:01 -0700 | [diff] [blame] | 72 | * A string that uniquely distinguishes this particular {@code PhoneAccountHandle} from all the |
| Brian Attwell | 48d8442e | 2014-12-19 11:37:16 -0800 | [diff] [blame] | 73 | * others supported by the connection service that created it. |
| Ihab Awad | b19a0bc | 2014-08-07 19:46:01 -0700 | [diff] [blame] | 74 | * <p> |
| Brian Attwell | 48d8442e | 2014-12-19 11:37:16 -0800 | [diff] [blame] | 75 | * 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] | 76 | * their users' relationship with their service, across many Android devices. For example, a |
| 77 | * good set of identifiers might be the email addresses with which with users registered for |
| 78 | * their accounts with a particular service. Depending on how a service chooses to operate, |
| 79 | * a bad set of identifiers might be an increasing series of integers |
| 80 | * ({@code 0}, {@code 1}, {@code 2}, ...) that are generated locally on each phone and could |
| 81 | * 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] | 82 | * |
| Santos Cordon | b7bb8c4 | 2015-02-10 03:38:31 -0800 | [diff] [blame^] | 83 | * Important: A non-unique identifier could cause non-deterministic call-log backup/restore |
| 84 | * behavior. |
| 85 | * |
| Ihab Awad | b19a0bc | 2014-08-07 19:46:01 -0700 | [diff] [blame] | 86 | * @return A service-specific unique identifier for this {@code PhoneAccountHandle}. |
| Ihab Awad | c35ad02 | 2014-06-12 16:29:42 -0700 | [diff] [blame] | 87 | */ |
| 88 | public String getId() { |
| 89 | return mId; |
| 90 | } |
| 91 | |
| Evan Charlton | 134dd68 | 2014-11-25 14:12:57 -0800 | [diff] [blame] | 92 | /** |
| 93 | * @return the {@link UserHandle} to use when connecting to this PhoneAccount. |
| 94 | * @hide |
| 95 | */ |
| Brian Attwell | 48d8442e | 2014-12-19 11:37:16 -0800 | [diff] [blame] | 96 | @SystemApi |
| Evan Charlton | 134dd68 | 2014-11-25 14:12:57 -0800 | [diff] [blame] | 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 | |
| Evan Charlton | 6eb262c | 2014-07-19 18:18:19 -0700 | [diff] [blame] | 144 | public static final Creator<PhoneAccountHandle> CREATOR = new Creator<PhoneAccountHandle>() { |
| Ihab Awad | 807fe0a | 2014-07-09 12:30:52 -0700 | [diff] [blame] | 145 | @Override |
| Evan Charlton | 6eb262c | 2014-07-19 18:18:19 -0700 | [diff] [blame] | 146 | public PhoneAccountHandle createFromParcel(Parcel in) { |
| 147 | return new PhoneAccountHandle(in); |
| Ihab Awad | 542e0ea | 2014-05-16 10:22:16 -0700 | [diff] [blame] | 148 | } |
| 149 | |
| Ihab Awad | 807fe0a | 2014-07-09 12:30:52 -0700 | [diff] [blame] | 150 | @Override |
| Evan Charlton | 6eb262c | 2014-07-19 18:18:19 -0700 | [diff] [blame] | 151 | public PhoneAccountHandle[] newArray(int size) { |
| 152 | return new PhoneAccountHandle[size]; |
| Ihab Awad | 542e0ea | 2014-05-16 10:22:16 -0700 | [diff] [blame] | 153 | } |
| 154 | }; |
| 155 | |
| Evan Charlton | 6eb262c | 2014-07-19 18:18:19 -0700 | [diff] [blame] | 156 | private PhoneAccountHandle(Parcel in) { |
| Evan Charlton | 134dd68 | 2014-11-25 14:12:57 -0800 | [diff] [blame] | 157 | this(ComponentName.CREATOR.createFromParcel(in), |
| 158 | in.readString(), |
| 159 | UserHandle.CREATOR.createFromParcel(in)); |
| Ihab Awad | c35ad02 | 2014-06-12 16:29:42 -0700 | [diff] [blame] | 160 | } |
| Ihab Awad | 542e0ea | 2014-05-16 10:22:16 -0700 | [diff] [blame] | 161 | } |