| 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 | |
| Tyler Gunn | 711d876fd | 2014-09-19 11:17:02 -0700 | [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; |
| Ihab Awad | c35ad02 | 2014-06-12 16:29:42 -0700 | [diff] [blame] | 23 | |
| Ihab Awad | dcaa5d6 | 2014-07-08 10:33:46 -0700 | [diff] [blame] | 24 | import java.util.Objects; |
| Ihab Awad | 542e0ea | 2014-05-16 10:22:16 -0700 | [diff] [blame] | 25 | |
| 26 | /** |
| Ihab Awad | b19a0bc | 2014-08-07 19:46:01 -0700 | [diff] [blame] | 27 | * The unique identifier for a {@link PhoneAccount}. |
| Tyler Gunn | 711d876fd | 2014-09-19 11:17:02 -0700 | [diff] [blame] | 28 | * @hide |
| Ihab Awad | 542e0ea | 2014-05-16 10:22:16 -0700 | [diff] [blame] | 29 | */ |
| Tyler Gunn | 711d876fd | 2014-09-19 11:17:02 -0700 | [diff] [blame] | 30 | @SystemApi |
| Evan Charlton | 6eb262c | 2014-07-19 18:18:19 -0700 | [diff] [blame] | 31 | public class PhoneAccountHandle implements Parcelable { |
| Ihab Awad | 807fe0a | 2014-07-09 12:30:52 -0700 | [diff] [blame] | 32 | private ComponentName mComponentName; |
| 33 | private String mId; |
| Ihab Awad | c35ad02 | 2014-06-12 16:29:42 -0700 | [diff] [blame] | 34 | |
| Evan Charlton | 6eb262c | 2014-07-19 18:18:19 -0700 | [diff] [blame] | 35 | public PhoneAccountHandle( |
| Ihab Awad | c35ad02 | 2014-06-12 16:29:42 -0700 | [diff] [blame] | 36 | ComponentName componentName, |
| Ihab Awad | 94cf4bf | 2014-07-17 11:21:19 -0700 | [diff] [blame] | 37 | String id) { |
| Ihab Awad | c35ad02 | 2014-06-12 16:29:42 -0700 | [diff] [blame] | 38 | mComponentName = componentName; |
| 39 | mId = id; |
| Ihab Awad | c35ad02 | 2014-06-12 16:29:42 -0700 | [diff] [blame] | 40 | } |
| 41 | |
| 42 | /** |
| Tyler Gunn | ef9f6f9 | 2014-09-12 22:16:17 -0700 | [diff] [blame] | 43 | * The {@code ComponentName} of the {@link android.telecom.ConnectionService} which is |
| Evan Charlton | 6eb262c | 2014-07-19 18:18:19 -0700 | [diff] [blame] | 44 | * responsible for making phone calls using this {@code PhoneAccountHandle}. |
| Ihab Awad | c35ad02 | 2014-06-12 16:29:42 -0700 | [diff] [blame] | 45 | * |
| 46 | * @return A suitable {@code ComponentName}. |
| 47 | */ |
| 48 | public ComponentName getComponentName() { |
| 49 | return mComponentName; |
| 50 | } |
| 51 | |
| 52 | /** |
| Ihab Awad | b19a0bc | 2014-08-07 19:46:01 -0700 | [diff] [blame] | 53 | * A string that uniquely distinguishes this particular {@code PhoneAccountHandle} from all the |
| 54 | * others supported by the {@link ConnectionService} that created it. |
| 55 | * <p> |
| 56 | * A {@code ConnectionService} must select identifiers that are stable for the lifetime of |
| 57 | * their users' relationship with their service, across many Android devices. For example, a |
| 58 | * good set of identifiers might be the email addresses with which with users registered for |
| 59 | * their accounts with a particular service. Depending on how a service chooses to operate, |
| 60 | * a bad set of identifiers might be an increasing series of integers |
| 61 | * ({@code 0}, {@code 1}, {@code 2}, ...) that are generated locally on each phone and could |
| 62 | * 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] | 63 | * |
| Ihab Awad | b19a0bc | 2014-08-07 19:46:01 -0700 | [diff] [blame] | 64 | * @return A service-specific unique identifier for this {@code PhoneAccountHandle}. |
| Ihab Awad | c35ad02 | 2014-06-12 16:29:42 -0700 | [diff] [blame] | 65 | */ |
| 66 | public String getId() { |
| 67 | return mId; |
| 68 | } |
| 69 | |
| Ihab Awad | 807fe0a | 2014-07-09 12:30:52 -0700 | [diff] [blame] | 70 | @Override |
| 71 | public int hashCode() { |
| Ihab Awad | 94cf4bf | 2014-07-17 11:21:19 -0700 | [diff] [blame] | 72 | return Objects.hashCode(mComponentName) + Objects.hashCode(mId); |
| Ihab Awad | c35ad02 | 2014-06-12 16:29:42 -0700 | [diff] [blame] | 73 | } |
| 74 | |
| Santos Cordon | 98b2703 | 2014-07-14 03:32:56 -0700 | [diff] [blame] | 75 | @Override |
| 76 | public String toString() { |
| 77 | return new StringBuilder().append(mComponentName) |
| 78 | .append(", ") |
| 79 | .append(mId) |
| Santos Cordon | 98b2703 | 2014-07-14 03:32:56 -0700 | [diff] [blame] | 80 | .toString(); |
| 81 | } |
| 82 | |
| Ihab Awad | 94cf4bf | 2014-07-17 11:21:19 -0700 | [diff] [blame] | 83 | @Override |
| 84 | public boolean equals(Object other) { |
| Santos Cordon | 98b2703 | 2014-07-14 03:32:56 -0700 | [diff] [blame] | 85 | return other != null && |
| Evan Charlton | 6eb262c | 2014-07-19 18:18:19 -0700 | [diff] [blame] | 86 | other instanceof PhoneAccountHandle && |
| 87 | Objects.equals(((PhoneAccountHandle) other).getComponentName(), |
| 88 | getComponentName()) && |
| 89 | Objects.equals(((PhoneAccountHandle) other).getId(), getId()); |
| Santos Cordon | 98b2703 | 2014-07-14 03:32:56 -0700 | [diff] [blame] | 90 | } |
| 91 | |
| Ihab Awad | dcaa5d6 | 2014-07-08 10:33:46 -0700 | [diff] [blame] | 92 | // |
| Ihab Awad | 807fe0a | 2014-07-09 12:30:52 -0700 | [diff] [blame] | 93 | // Parcelable implementation. |
| 94 | // |
| Ihab Awad | 542e0ea | 2014-05-16 10:22:16 -0700 | [diff] [blame] | 95 | |
| Sailesh Nepal | e7ef59a | 2014-07-08 21:48:22 -0700 | [diff] [blame] | 96 | @Override |
| Ihab Awad | 542e0ea | 2014-05-16 10:22:16 -0700 | [diff] [blame] | 97 | public int describeContents() { |
| 98 | return 0; |
| 99 | } |
| 100 | |
| Sailesh Nepal | e7ef59a | 2014-07-08 21:48:22 -0700 | [diff] [blame] | 101 | @Override |
| Ihab Awad | c35ad02 | 2014-06-12 16:29:42 -0700 | [diff] [blame] | 102 | public void writeToParcel(Parcel out, int flags) { |
| 103 | out.writeParcelable(mComponentName, flags); |
| 104 | out.writeString(mId); |
| Ihab Awad | c35ad02 | 2014-06-12 16:29:42 -0700 | [diff] [blame] | 105 | } |
| Ihab Awad | 542e0ea | 2014-05-16 10:22:16 -0700 | [diff] [blame] | 106 | |
| Evan Charlton | 6eb262c | 2014-07-19 18:18:19 -0700 | [diff] [blame] | 107 | public static final Creator<PhoneAccountHandle> CREATOR = new Creator<PhoneAccountHandle>() { |
| Ihab Awad | 807fe0a | 2014-07-09 12:30:52 -0700 | [diff] [blame] | 108 | @Override |
| Evan Charlton | 6eb262c | 2014-07-19 18:18:19 -0700 | [diff] [blame] | 109 | public PhoneAccountHandle createFromParcel(Parcel in) { |
| 110 | return new PhoneAccountHandle(in); |
| Ihab Awad | 542e0ea | 2014-05-16 10:22:16 -0700 | [diff] [blame] | 111 | } |
| 112 | |
| Ihab Awad | 807fe0a | 2014-07-09 12:30:52 -0700 | [diff] [blame] | 113 | @Override |
| Evan Charlton | 6eb262c | 2014-07-19 18:18:19 -0700 | [diff] [blame] | 114 | public PhoneAccountHandle[] newArray(int size) { |
| 115 | return new PhoneAccountHandle[size]; |
| Ihab Awad | 542e0ea | 2014-05-16 10:22:16 -0700 | [diff] [blame] | 116 | } |
| 117 | }; |
| 118 | |
| Evan Charlton | 6eb262c | 2014-07-19 18:18:19 -0700 | [diff] [blame] | 119 | private PhoneAccountHandle(Parcel in) { |
| Ihab Awad | c35ad02 | 2014-06-12 16:29:42 -0700 | [diff] [blame] | 120 | mComponentName = in.readParcelable(getClass().getClassLoader()); |
| 121 | mId = in.readString(); |
| Ihab Awad | c35ad02 | 2014-06-12 16:29:42 -0700 | [diff] [blame] | 122 | } |
| Ihab Awad | 542e0ea | 2014-05-16 10:22:16 -0700 | [diff] [blame] | 123 | } |