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 17 package android.telecom; 18 19 import android.annotation.SystemApi; 20 import android.content.ComponentName; 21 import android.os.Parcel; 22 import android.os.Parcelable; 23 24 import java.util.Objects; 25 26 /** 27 * The unique identifier for a {@link PhoneAccount}. 28 * @hide 29 */ 30 @SystemApi 31 public class PhoneAccountHandle implements Parcelable { 32 private ComponentName mComponentName; 33 private String mId; 34 PhoneAccountHandle( ComponentName componentName, String id)35 public PhoneAccountHandle( 36 ComponentName componentName, 37 String id) { 38 mComponentName = componentName; 39 mId = id; 40 } 41 42 /** 43 * The {@code ComponentName} of the {@link android.telecom.ConnectionService} which is 44 * responsible for making phone calls using this {@code PhoneAccountHandle}. 45 * 46 * @return A suitable {@code ComponentName}. 47 */ getComponentName()48 public ComponentName getComponentName() { 49 return mComponentName; 50 } 51 52 /** 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. 63 * 64 * @return A service-specific unique identifier for this {@code PhoneAccountHandle}. 65 */ getId()66 public String getId() { 67 return mId; 68 } 69 70 @Override hashCode()71 public int hashCode() { 72 return Objects.hashCode(mComponentName) + Objects.hashCode(mId); 73 } 74 75 @Override toString()76 public String toString() { 77 return new StringBuilder().append(mComponentName) 78 .append(", ") 79 .append(mId) 80 .toString(); 81 } 82 83 @Override equals(Object other)84 public boolean equals(Object other) { 85 return other != null && 86 other instanceof PhoneAccountHandle && 87 Objects.equals(((PhoneAccountHandle) other).getComponentName(), 88 getComponentName()) && 89 Objects.equals(((PhoneAccountHandle) other).getId(), getId()); 90 } 91 92 // 93 // Parcelable implementation. 94 // 95 96 @Override describeContents()97 public int describeContents() { 98 return 0; 99 } 100 101 @Override writeToParcel(Parcel out, int flags)102 public void writeToParcel(Parcel out, int flags) { 103 out.writeParcelable(mComponentName, flags); 104 out.writeString(mId); 105 } 106 107 public static final Creator<PhoneAccountHandle> CREATOR = new Creator<PhoneAccountHandle>() { 108 @Override 109 public PhoneAccountHandle createFromParcel(Parcel in) { 110 return new PhoneAccountHandle(in); 111 } 112 113 @Override 114 public PhoneAccountHandle[] newArray(int size) { 115 return new PhoneAccountHandle[size]; 116 } 117 }; 118 PhoneAccountHandle(Parcel in)119 private PhoneAccountHandle(Parcel in) { 120 mComponentName = in.readParcelable(getClass().getClassLoader()); 121 mId = in.readString(); 122 } 123 } 124