blob: 2360cec5bde84c24637724633d1b3505e867c382 [file] [log] [blame]
Kenny Root15a4d2f2010-03-11 18:20:12 -08001/*
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 Quintana97889762009-06-15 12:29:24 -070017package android.accounts;
18
Mathew Inwood1fde99a2018-08-06 16:43:30 +010019import android.annotation.UnsupportedAppUsage;
Mathew Inwood31755f92018-12-20 13:53:36 +000020import android.os.Build;
Fred Quintana97889762009-06-15 12:29:24 -070021import android.os.Parcelable;
22import android.os.Parcel;
23
Fred Quintana756b7352009-10-21 13:43:10 -070024/**
25 * A {@link Parcelable} value type that contains information about an account authenticator.
26 */
Fred Quintana97889762009-06-15 12:29:24 -070027public class AuthenticatorDescription implements Parcelable {
Fred Quintana756b7352009-10-21 13:43:10 -070028 /** The string that uniquely identifies an authenticator */
Fred Quintana97889762009-06-15 12:29:24 -070029 final public String type;
Fred Quintana756b7352009-10-21 13:43:10 -070030
31 /** A resource id of a label for the authenticator that is suitable for displaying */
Fred Quintana97889762009-06-15 12:29:24 -070032 final public int labelId;
Fred Quintana756b7352009-10-21 13:43:10 -070033
34 /** A resource id of a icon for the authenticator */
35 final public int iconId;
36
37 /** A resource id of a smaller icon for the authenticator */
38 final public int smallIconId;
39
40 /**
41 * A resource id for a hierarchy of PreferenceScreen to be added to the settings page for the
42 * account. See {@link AbstractAccountAuthenticator} for an example.
43 */
Jim Miller70e1ad72009-09-09 22:45:47 -070044 final public int accountPreferencesId;
Fred Quintana756b7352009-10-21 13:43:10 -070045
46 /** The package name that can be used to lookup the resources from above. */
Fred Quintana97889762009-06-15 12:29:24 -070047 final public String packageName;
48
Costin Manolachea40c6302010-12-13 14:50:45 -080049 /** Authenticator handles its own token caching and permission screen */
50 final public boolean customTokens;
51
Fred Quintana756b7352009-10-21 13:43:10 -070052 /** A constructor for a full AuthenticatorDescription */
53 public AuthenticatorDescription(String type, String packageName, int labelId, int iconId,
Costin Manolachea40c6302010-12-13 14:50:45 -080054 int smallIconId, int prefId, boolean customTokens) {
Fred Quintanac298a852009-08-27 18:28:17 -070055 if (type == null) throw new IllegalArgumentException("type cannot be null");
56 if (packageName == null) throw new IllegalArgumentException("packageName cannot be null");
Fred Quintana97889762009-06-15 12:29:24 -070057 this.type = type;
58 this.packageName = packageName;
59 this.labelId = labelId;
60 this.iconId = iconId;
Jim Miller70e1ad72009-09-09 22:45:47 -070061 this.smallIconId = smallIconId;
62 this.accountPreferencesId = prefId;
Costin Manolachea40c6302010-12-13 14:50:45 -080063 this.customTokens = customTokens;
64 }
65
66 public AuthenticatorDescription(String type, String packageName, int labelId, int iconId,
67 int smallIconId, int prefId) {
68 this(type, packageName, labelId, iconId, smallIconId, prefId, false);
Fred Quintana97889762009-06-15 12:29:24 -070069 }
70
Fred Quintana756b7352009-10-21 13:43:10 -070071 /**
72 * A factory method for creating an AuthenticatorDescription that can be used as a key
73 * to identify the authenticator by its type.
74 */
75
Fred Quintana97889762009-06-15 12:29:24 -070076 public static AuthenticatorDescription newKey(String type) {
Fred Quintanac298a852009-08-27 18:28:17 -070077 if (type == null) throw new IllegalArgumentException("type cannot be null");
Fred Quintana97889762009-06-15 12:29:24 -070078 return new AuthenticatorDescription(type);
79 }
80
Mathew Inwood31755f92018-12-20 13:53:36 +000081 @UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.P, trackingBug = 115609023)
Fred Quintana97889762009-06-15 12:29:24 -070082 private AuthenticatorDescription(String type) {
83 this.type = type;
84 this.packageName = null;
85 this.labelId = 0;
86 this.iconId = 0;
Jim Miller70e1ad72009-09-09 22:45:47 -070087 this.smallIconId = 0;
88 this.accountPreferencesId = 0;
Costin Manolachea40c6302010-12-13 14:50:45 -080089 this.customTokens = false;
Fred Quintana97889762009-06-15 12:29:24 -070090 }
91
Mathew Inwood31755f92018-12-20 13:53:36 +000092 @UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.P, trackingBug = 115609023)
Fred Quintana97889762009-06-15 12:29:24 -070093 private AuthenticatorDescription(Parcel source) {
94 this.type = source.readString();
95 this.packageName = source.readString();
96 this.labelId = source.readInt();
97 this.iconId = source.readInt();
Jim Miller70e1ad72009-09-09 22:45:47 -070098 this.smallIconId = source.readInt();
99 this.accountPreferencesId = source.readInt();
Costin Manolachea40c6302010-12-13 14:50:45 -0800100 this.customTokens = source.readByte() == 1;
Fred Quintana97889762009-06-15 12:29:24 -0700101 }
102
Fred Quintana756b7352009-10-21 13:43:10 -0700103 /** @inheritDoc */
Fred Quintana97889762009-06-15 12:29:24 -0700104 public int describeContents() {
105 return 0;
106 }
107
Fred Quintana756b7352009-10-21 13:43:10 -0700108 /** Returns the hashcode of the type only. */
Fred Quintana97889762009-06-15 12:29:24 -0700109 public int hashCode() {
110 return type.hashCode();
111 }
112
Fred Quintana756b7352009-10-21 13:43:10 -0700113 /** Compares the type only, suitable for key comparisons. */
Fred Quintana97889762009-06-15 12:29:24 -0700114 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
Fred Quintana5ebbb4a2009-11-09 15:42:20 -0800121 public String toString() {
122 return "AuthenticatorDescription {type=" + type + "}";
123 }
124
Kenny Rootec8f9b62010-03-01 15:01:51 -0800125 /** @inheritDoc */
Fred Quintana97889762009-06-15 12:29:24 -0700126 public void writeToParcel(Parcel dest, int flags) {
127 dest.writeString(type);
128 dest.writeString(packageName);
129 dest.writeInt(labelId);
130 dest.writeInt(iconId);
Jim Miller70e1ad72009-09-09 22:45:47 -0700131 dest.writeInt(smallIconId);
132 dest.writeInt(accountPreferencesId);
Costin Manolachea40c6302010-12-13 14:50:45 -0800133 dest.writeByte((byte) (customTokens ? 1 : 0));
Fred Quintana97889762009-06-15 12:29:24 -0700134 }
135
Fred Quintana756b7352009-10-21 13:43:10 -0700136 /** Used to create the object from a parcel. */
Fred Quintana97889762009-06-15 12:29:24 -0700137 public static final Creator<AuthenticatorDescription> CREATOR =
138 new Creator<AuthenticatorDescription>() {
Fred Quintana756b7352009-10-21 13:43:10 -0700139 /** @inheritDoc */
Fred Quintana97889762009-06-15 12:29:24 -0700140 public AuthenticatorDescription createFromParcel(Parcel source) {
141 return new AuthenticatorDescription(source);
142 }
143
Fred Quintana756b7352009-10-21 13:43:10 -0700144 /** @inheritDoc */
Fred Quintana97889762009-06-15 12:29:24 -0700145 public AuthenticatorDescription[] newArray(int size) {
146 return new AuthenticatorDescription[size];
147 }
148 };
149}