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 | |
Ihab Awad | c35ad02 | 2014-06-12 16:29:42 -0700 | [diff] [blame] | 19 | import android.content.ComponentName; |
Ihab Awad | 542e0ea | 2014-05-16 10:22:16 -0700 | [diff] [blame] | 20 | import android.os.Parcel; |
| 21 | import android.os.Parcelable; |
Ihab Awad | c35ad02 | 2014-06-12 16:29:42 -0700 | [diff] [blame] | 22 | |
Ihab Awad | dcaa5d6 | 2014-07-08 10:33:46 -0700 | [diff] [blame] | 23 | import java.util.Objects; |
Ihab Awad | 542e0ea | 2014-05-16 10:22:16 -0700 | [diff] [blame] | 24 | |
| 25 | /** |
Ihab Awad | b19a0bc | 2014-08-07 19:46:01 -0700 | [diff] [blame] | 26 | * The unique identifier for a {@link PhoneAccount}. |
Ihab Awad | 542e0ea | 2014-05-16 10:22:16 -0700 | [diff] [blame] | 27 | */ |
Evan Charlton | 6eb262c | 2014-07-19 18:18:19 -0700 | [diff] [blame] | 28 | public class PhoneAccountHandle implements Parcelable { |
Ihab Awad | 807fe0a | 2014-07-09 12:30:52 -0700 | [diff] [blame] | 29 | private ComponentName mComponentName; |
| 30 | private String mId; |
Ihab Awad | c35ad02 | 2014-06-12 16:29:42 -0700 | [diff] [blame] | 31 | |
Evan Charlton | 6eb262c | 2014-07-19 18:18:19 -0700 | [diff] [blame] | 32 | public PhoneAccountHandle( |
Ihab Awad | c35ad02 | 2014-06-12 16:29:42 -0700 | [diff] [blame] | 33 | ComponentName componentName, |
Ihab Awad | 94cf4bf | 2014-07-17 11:21:19 -0700 | [diff] [blame] | 34 | String id) { |
Ihab Awad | c35ad02 | 2014-06-12 16:29:42 -0700 | [diff] [blame] | 35 | mComponentName = componentName; |
| 36 | mId = id; |
Ihab Awad | c35ad02 | 2014-06-12 16:29:42 -0700 | [diff] [blame] | 37 | } |
| 38 | |
| 39 | /** |
Tyler Gunn | ef9f6f9 | 2014-09-12 22:16:17 -0700 | [diff] [blame] | 40 | * The {@code ComponentName} of the {@link android.telecom.ConnectionService} which is |
Evan Charlton | 6eb262c | 2014-07-19 18:18:19 -0700 | [diff] [blame] | 41 | * responsible for making phone calls using this {@code PhoneAccountHandle}. |
Ihab Awad | c35ad02 | 2014-06-12 16:29:42 -0700 | [diff] [blame] | 42 | * |
| 43 | * @return A suitable {@code ComponentName}. |
| 44 | */ |
| 45 | public ComponentName getComponentName() { |
| 46 | return mComponentName; |
| 47 | } |
| 48 | |
| 49 | /** |
Ihab Awad | b19a0bc | 2014-08-07 19:46:01 -0700 | [diff] [blame] | 50 | * 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 Awad | c35ad02 | 2014-06-12 16:29:42 -0700 | [diff] [blame] | 60 | * |
Ihab Awad | b19a0bc | 2014-08-07 19:46:01 -0700 | [diff] [blame] | 61 | * @return A service-specific unique identifier for this {@code PhoneAccountHandle}. |
Ihab Awad | c35ad02 | 2014-06-12 16:29:42 -0700 | [diff] [blame] | 62 | */ |
| 63 | public String getId() { |
| 64 | return mId; |
| 65 | } |
| 66 | |
Ihab Awad | 807fe0a | 2014-07-09 12:30:52 -0700 | [diff] [blame] | 67 | @Override |
| 68 | public int hashCode() { |
Ihab Awad | 94cf4bf | 2014-07-17 11:21:19 -0700 | [diff] [blame] | 69 | return Objects.hashCode(mComponentName) + Objects.hashCode(mId); |
Ihab Awad | c35ad02 | 2014-06-12 16:29:42 -0700 | [diff] [blame] | 70 | } |
| 71 | |
Santos Cordon | 98b2703 | 2014-07-14 03:32:56 -0700 | [diff] [blame] | 72 | @Override |
| 73 | public String toString() { |
Tyler Gunn | 76c01a5 | 2014-09-30 14:47:51 -0700 | [diff] [blame^] | 74 | // Note: Log.pii called for mId as it can contain personally identifying phone account |
| 75 | // information such as SIP account IDs. |
Santos Cordon | 98b2703 | 2014-07-14 03:32:56 -0700 | [diff] [blame] | 76 | return new StringBuilder().append(mComponentName) |
| 77 | .append(", ") |
Tyler Gunn | 76c01a5 | 2014-09-30 14:47:51 -0700 | [diff] [blame^] | 78 | .append(Log.pii(mId)) |
Santos Cordon | 98b2703 | 2014-07-14 03:32:56 -0700 | [diff] [blame] | 79 | .toString(); |
| 80 | } |
| 81 | |
Ihab Awad | 94cf4bf | 2014-07-17 11:21:19 -0700 | [diff] [blame] | 82 | @Override |
| 83 | public boolean equals(Object other) { |
Santos Cordon | 98b2703 | 2014-07-14 03:32:56 -0700 | [diff] [blame] | 84 | return other != null && |
Evan Charlton | 6eb262c | 2014-07-19 18:18:19 -0700 | [diff] [blame] | 85 | other instanceof PhoneAccountHandle && |
| 86 | Objects.equals(((PhoneAccountHandle) other).getComponentName(), |
| 87 | getComponentName()) && |
| 88 | Objects.equals(((PhoneAccountHandle) other).getId(), getId()); |
Santos Cordon | 98b2703 | 2014-07-14 03:32:56 -0700 | [diff] [blame] | 89 | } |
| 90 | |
Ihab Awad | dcaa5d6 | 2014-07-08 10:33:46 -0700 | [diff] [blame] | 91 | // |
Ihab Awad | 807fe0a | 2014-07-09 12:30:52 -0700 | [diff] [blame] | 92 | // Parcelable implementation. |
| 93 | // |
Ihab Awad | 542e0ea | 2014-05-16 10:22:16 -0700 | [diff] [blame] | 94 | |
Sailesh Nepal | e7ef59a | 2014-07-08 21:48:22 -0700 | [diff] [blame] | 95 | @Override |
Ihab Awad | 542e0ea | 2014-05-16 10:22:16 -0700 | [diff] [blame] | 96 | public int describeContents() { |
| 97 | return 0; |
| 98 | } |
| 99 | |
Sailesh Nepal | e7ef59a | 2014-07-08 21:48:22 -0700 | [diff] [blame] | 100 | @Override |
Ihab Awad | c35ad02 | 2014-06-12 16:29:42 -0700 | [diff] [blame] | 101 | public void writeToParcel(Parcel out, int flags) { |
| 102 | out.writeParcelable(mComponentName, flags); |
| 103 | out.writeString(mId); |
Ihab Awad | c35ad02 | 2014-06-12 16:29:42 -0700 | [diff] [blame] | 104 | } |
Ihab Awad | 542e0ea | 2014-05-16 10:22:16 -0700 | [diff] [blame] | 105 | |
Evan Charlton | 6eb262c | 2014-07-19 18:18:19 -0700 | [diff] [blame] | 106 | public static final Creator<PhoneAccountHandle> CREATOR = new Creator<PhoneAccountHandle>() { |
Ihab Awad | 807fe0a | 2014-07-09 12:30:52 -0700 | [diff] [blame] | 107 | @Override |
Evan Charlton | 6eb262c | 2014-07-19 18:18:19 -0700 | [diff] [blame] | 108 | public PhoneAccountHandle createFromParcel(Parcel in) { |
| 109 | return new PhoneAccountHandle(in); |
Ihab Awad | 542e0ea | 2014-05-16 10:22:16 -0700 | [diff] [blame] | 110 | } |
| 111 | |
Ihab Awad | 807fe0a | 2014-07-09 12:30:52 -0700 | [diff] [blame] | 112 | @Override |
Evan Charlton | 6eb262c | 2014-07-19 18:18:19 -0700 | [diff] [blame] | 113 | public PhoneAccountHandle[] newArray(int size) { |
| 114 | return new PhoneAccountHandle[size]; |
Ihab Awad | 542e0ea | 2014-05-16 10:22:16 -0700 | [diff] [blame] | 115 | } |
| 116 | }; |
| 117 | |
Evan Charlton | 6eb262c | 2014-07-19 18:18:19 -0700 | [diff] [blame] | 118 | private PhoneAccountHandle(Parcel in) { |
Ihab Awad | c35ad02 | 2014-06-12 16:29:42 -0700 | [diff] [blame] | 119 | mComponentName = in.readParcelable(getClass().getClassLoader()); |
| 120 | mId = in.readString(); |
Ihab Awad | c35ad02 | 2014-06-12 16:29:42 -0700 | [diff] [blame] | 121 | } |
Ihab Awad | 542e0ea | 2014-05-16 10:22:16 -0700 | [diff] [blame] | 122 | } |