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