1/* 2 * Copyright (C) 2009 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 17package android.accounts; 18 19import android.os.Parcelable; 20import android.os.Parcel; 21 22/** 23 * A {@link Parcelable} value type that contains information about an account authenticator. 24 */ 25public class AuthenticatorDescription implements Parcelable { 26 /** The string that uniquely identifies an authenticator */ 27 final public String type; 28 29 /** A resource id of a label for the authenticator that is suitable for displaying */ 30 final public int labelId; 31 32 /** A resource id of a icon for the authenticator */ 33 final public int iconId; 34 35 /** A resource id of a smaller icon for the authenticator */ 36 final public int smallIconId; 37 38 /** 39 * A resource id for a hierarchy of PreferenceScreen to be added to the settings page for the 40 * account. See {@link AbstractAccountAuthenticator} for an example. 41 */ 42 final public int accountPreferencesId; 43 44 /** The package name that can be used to lookup the resources from above. */ 45 final public String packageName; 46 47 /** Authenticator handles its own token caching and permission screen 48 * @hide 49 */ 50 final public boolean customTokens; 51 52 /** A constructor for a full AuthenticatorDescription 53 * @hide 54 */ 55 public AuthenticatorDescription(String type, String packageName, int labelId, int iconId, 56 int smallIconId, int prefId, boolean customTokens) { 57 if (type == null) throw new IllegalArgumentException("type cannot be null"); 58 if (packageName == null) throw new IllegalArgumentException("packageName cannot be null"); 59 this.type = type; 60 this.packageName = packageName; 61 this.labelId = labelId; 62 this.iconId = iconId; 63 this.smallIconId = smallIconId; 64 this.accountPreferencesId = prefId; 65 this.customTokens = customTokens; 66 } 67 68 public AuthenticatorDescription(String type, String packageName, int labelId, int iconId, 69 int smallIconId, int prefId) { 70 this(type, packageName, labelId, iconId, smallIconId, prefId, false); 71 } 72 73 /** 74 * A factory method for creating an AuthenticatorDescription that can be used as a key 75 * to identify the authenticator by its type. 76 */ 77 78 public static AuthenticatorDescription newKey(String type) { 79 if (type == null) throw new IllegalArgumentException("type cannot be null"); 80 return new AuthenticatorDescription(type); 81 } 82 83 private AuthenticatorDescription(String type) { 84 this.type = type; 85 this.packageName = null; 86 this.labelId = 0; 87 this.iconId = 0; 88 this.smallIconId = 0; 89 this.accountPreferencesId = 0; 90 this.customTokens = false; 91 } 92 93 private AuthenticatorDescription(Parcel source) { 94 this.type = source.readString(); 95 this.packageName = source.readString(); 96 this.labelId = source.readInt(); 97 this.iconId = source.readInt(); 98 this.smallIconId = source.readInt(); 99 this.accountPreferencesId = source.readInt(); 100 this.customTokens = source.readByte() == 1; 101 } 102 103 /** @inheritDoc */ 104 public int describeContents() { 105 return 0; 106 } 107 108 /** Returns the hashcode of the type only. */ 109 public int hashCode() { 110 return type.hashCode(); 111 } 112 113 /** Compares the type only, suitable for key comparisons. */ 114 public boolean equals(Object o) { 115 if (o == this) return true; 116 if (!(o instanceof AuthenticatorDescription)) return false; 117 final AuthenticatorDescription other = (AuthenticatorDescription) o; 118 return type.equals(other.type); 119 } 120 121 public String toString() { 122 return "AuthenticatorDescription {type=" + type + "}"; 123 } 124 125 /** @inheritDoc */ 126 public void writeToParcel(Parcel dest, int flags) { 127 dest.writeString(type); 128 dest.writeString(packageName); 129 dest.writeInt(labelId); 130 dest.writeInt(iconId); 131 dest.writeInt(smallIconId); 132 dest.writeInt(accountPreferencesId); 133 dest.writeByte((byte) (customTokens ? 1 : 0)); 134 } 135 136 /** Used to create the object from a parcel. */ 137 public static final Creator<AuthenticatorDescription> CREATOR = 138 new Creator<AuthenticatorDescription>() { 139 /** @inheritDoc */ 140 public AuthenticatorDescription createFromParcel(Parcel source) { 141 return new AuthenticatorDescription(source); 142 } 143 144 /** @inheritDoc */ 145 public AuthenticatorDescription[] newArray(int size) { 146 return new AuthenticatorDescription[size]; 147 } 148 }; 149} 150