add icon and label to the authenticator description
This commit is contained in:
134
api/current.xml
134
api/current.xml
@@ -16468,7 +16468,7 @@
|
||||
</exception>
|
||||
</method>
|
||||
<method name="blockingGetAuthenticatorTypes"
|
||||
return="java.lang.String[]"
|
||||
return="android.accounts.AuthenticatorDescription[]"
|
||||
abstract="false"
|
||||
native="false"
|
||||
synchronized="false"
|
||||
@@ -16808,7 +16808,7 @@
|
||||
</parameter>
|
||||
</method>
|
||||
<method name="getAuthenticatorTypes"
|
||||
return="android.accounts.Future1<java.lang.String[]>"
|
||||
return="android.accounts.Future1<android.accounts.AuthenticatorDescription[]>"
|
||||
abstract="false"
|
||||
native="false"
|
||||
synchronized="false"
|
||||
@@ -16817,7 +16817,7 @@
|
||||
deprecated="not deprecated"
|
||||
visibility="public"
|
||||
>
|
||||
<parameter name="callback" type="android.accounts.Future1Callback<java.lang.String[]>">
|
||||
<parameter name="callback" type="android.accounts.Future1Callback<android.accounts.AuthenticatorDescription[]>">
|
||||
</parameter>
|
||||
<parameter name="handler" type="android.os.Handler">
|
||||
</parameter>
|
||||
@@ -17011,6 +17011,122 @@
|
||||
</parameter>
|
||||
</method>
|
||||
</class>
|
||||
<class name="AuthenticatorDescription"
|
||||
extends="java.lang.Object"
|
||||
abstract="false"
|
||||
static="false"
|
||||
final="false"
|
||||
deprecated="not deprecated"
|
||||
visibility="public"
|
||||
>
|
||||
<implements name="android.os.Parcelable">
|
||||
</implements>
|
||||
<constructor name="AuthenticatorDescription"
|
||||
type="android.accounts.AuthenticatorDescription"
|
||||
static="false"
|
||||
final="false"
|
||||
deprecated="not deprecated"
|
||||
visibility="public"
|
||||
>
|
||||
<parameter name="type" type="java.lang.String">
|
||||
</parameter>
|
||||
<parameter name="packageName" type="java.lang.String">
|
||||
</parameter>
|
||||
<parameter name="labelId" type="int">
|
||||
</parameter>
|
||||
<parameter name="iconId" type="int">
|
||||
</parameter>
|
||||
</constructor>
|
||||
<method name="describeContents"
|
||||
return="int"
|
||||
abstract="false"
|
||||
native="false"
|
||||
synchronized="false"
|
||||
static="false"
|
||||
final="false"
|
||||
deprecated="not deprecated"
|
||||
visibility="public"
|
||||
>
|
||||
</method>
|
||||
<method name="newKey"
|
||||
return="android.accounts.AuthenticatorDescription"
|
||||
abstract="false"
|
||||
native="false"
|
||||
synchronized="false"
|
||||
static="true"
|
||||
final="false"
|
||||
deprecated="not deprecated"
|
||||
visibility="public"
|
||||
>
|
||||
<parameter name="type" type="java.lang.String">
|
||||
</parameter>
|
||||
</method>
|
||||
<method name="writeToParcel"
|
||||
return="void"
|
||||
abstract="false"
|
||||
native="false"
|
||||
synchronized="false"
|
||||
static="false"
|
||||
final="false"
|
||||
deprecated="not deprecated"
|
||||
visibility="public"
|
||||
>
|
||||
<parameter name="dest" type="android.os.Parcel">
|
||||
</parameter>
|
||||
<parameter name="flags" type="int">
|
||||
</parameter>
|
||||
</method>
|
||||
<field name="CREATOR"
|
||||
type="android.os.Parcelable.Creator"
|
||||
transient="false"
|
||||
volatile="false"
|
||||
static="true"
|
||||
final="true"
|
||||
deprecated="not deprecated"
|
||||
visibility="public"
|
||||
>
|
||||
</field>
|
||||
<field name="iconId"
|
||||
type="int"
|
||||
transient="false"
|
||||
volatile="false"
|
||||
static="false"
|
||||
final="true"
|
||||
deprecated="not deprecated"
|
||||
visibility="public"
|
||||
>
|
||||
</field>
|
||||
<field name="labelId"
|
||||
type="int"
|
||||
transient="false"
|
||||
volatile="false"
|
||||
static="false"
|
||||
final="true"
|
||||
deprecated="not deprecated"
|
||||
visibility="public"
|
||||
>
|
||||
</field>
|
||||
<field name="packageName"
|
||||
type="java.lang.String"
|
||||
transient="false"
|
||||
volatile="false"
|
||||
static="false"
|
||||
final="true"
|
||||
deprecated="not deprecated"
|
||||
visibility="public"
|
||||
>
|
||||
</field>
|
||||
<field name="type"
|
||||
type="java.lang.String"
|
||||
transient="false"
|
||||
volatile="false"
|
||||
static="false"
|
||||
final="true"
|
||||
deprecated="not deprecated"
|
||||
visibility="public"
|
||||
>
|
||||
</field>
|
||||
</class>
|
||||
<class name="AuthenticatorException"
|
||||
extends="java.lang.Exception"
|
||||
abstract="false"
|
||||
@@ -285738,7 +285854,11 @@
|
||||
deprecated="not deprecated"
|
||||
visibility="public"
|
||||
>
|
||||
<parameter name="val" type="int">
|
||||
<parameter name="buf" type="byte[]">
|
||||
</parameter>
|
||||
<parameter name="off" type="int">
|
||||
</parameter>
|
||||
<parameter name="nbytes" type="int">
|
||||
</parameter>
|
||||
</method>
|
||||
<method name="update"
|
||||
@@ -285751,11 +285871,7 @@
|
||||
deprecated="not deprecated"
|
||||
visibility="public"
|
||||
>
|
||||
<parameter name="buf" type="byte[]">
|
||||
</parameter>
|
||||
<parameter name="off" type="int">
|
||||
</parameter>
|
||||
<parameter name="nbytes" type="int">
|
||||
<parameter name="val" type="int">
|
||||
</parameter>
|
||||
</method>
|
||||
</interface>
|
||||
|
||||
@@ -17,31 +17,10 @@
|
||||
package android.accounts;
|
||||
|
||||
import android.content.pm.PackageManager;
|
||||
import android.content.pm.ResolveInfo;
|
||||
import android.content.pm.ServiceInfo;
|
||||
import android.content.pm.RegisteredServicesCache;
|
||||
import android.content.res.XmlResourceParser;
|
||||
import android.content.res.TypedArray;
|
||||
import android.content.BroadcastReceiver;
|
||||
import android.content.ComponentName;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.content.IntentFilter;
|
||||
import android.util.Log;
|
||||
import android.util.AttributeSet;
|
||||
import android.util.Xml;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.FileDescriptor;
|
||||
import java.io.PrintWriter;
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import com.google.android.collect.Maps;
|
||||
import org.xmlpull.v1.XmlPullParserException;
|
||||
import org.xmlpull.v1.XmlPullParser;
|
||||
|
||||
/**
|
||||
* A cache of services that export the {@link IAccountAuthenticator} interface. This cache
|
||||
@@ -50,7 +29,8 @@ import org.xmlpull.v1.XmlPullParser;
|
||||
* are made available via the {@link RegisteredServicesCache#getServiceInfo} method.
|
||||
* @hide
|
||||
*/
|
||||
/* package private */ class AccountAuthenticatorCache extends RegisteredServicesCache<String> {
|
||||
/* package private */ class AccountAuthenticatorCache
|
||||
extends RegisteredServicesCache<AuthenticatorDescription> {
|
||||
private static final String TAG = "Account";
|
||||
|
||||
private static final String SERVICE_INTERFACE = "android.accounts.AccountAuthenticator";
|
||||
@@ -61,11 +41,17 @@ import org.xmlpull.v1.XmlPullParser;
|
||||
super(context, SERVICE_INTERFACE, SERVICE_META_DATA, ATTRIBUTES_NAME);
|
||||
}
|
||||
|
||||
public String parseServiceAttributes(AttributeSet attrs) {
|
||||
public AuthenticatorDescription parseServiceAttributes(String packageName, AttributeSet attrs) {
|
||||
TypedArray sa = mContext.getResources().obtainAttributes(attrs,
|
||||
com.android.internal.R.styleable.AccountAuthenticator);
|
||||
try {
|
||||
return sa.getString(com.android.internal.R.styleable.AccountAuthenticator_accountType);
|
||||
final String accountType =
|
||||
sa.getString(com.android.internal.R.styleable.AccountAuthenticator_accountType);
|
||||
final int labelId = sa.getResourceId(
|
||||
com.android.internal.R.styleable.AccountAuthenticator_label, 0);
|
||||
final int iconId = sa.getResourceId(
|
||||
com.android.internal.R.styleable.AccountAuthenticator_icon, 0);
|
||||
return new AuthenticatorDescription(accountType, packageName, labelId, iconId);
|
||||
} finally {
|
||||
sa.recycle();
|
||||
}
|
||||
|
||||
@@ -118,7 +118,7 @@ public class AccountManager {
|
||||
});
|
||||
}
|
||||
|
||||
public String[] blockingGetAuthenticatorTypes() {
|
||||
public AuthenticatorDescription[] blockingGetAuthenticatorTypes() {
|
||||
ensureNotOnMainThread();
|
||||
try {
|
||||
return mService.getAuthenticatorTypes();
|
||||
@@ -128,10 +128,10 @@ public class AccountManager {
|
||||
}
|
||||
}
|
||||
|
||||
public Future1<String[]> getAuthenticatorTypes(Future1Callback<String[]> callback,
|
||||
Handler handler) {
|
||||
return startAsFuture(callback, handler, new Callable<String[]>() {
|
||||
public String[] call() throws Exception {
|
||||
public Future1<AuthenticatorDescription[]> getAuthenticatorTypes(
|
||||
Future1Callback<AuthenticatorDescription[]> callback, Handler handler) {
|
||||
return startAsFuture(callback, handler, new Callable<AuthenticatorDescription[]>() {
|
||||
public AuthenticatorDescription[] call() throws Exception {
|
||||
return blockingGetAuthenticatorTypes();
|
||||
}
|
||||
});
|
||||
|
||||
@@ -215,14 +215,15 @@ public class AccountManagerService extends IAccountManager.Stub {
|
||||
}
|
||||
}
|
||||
|
||||
public String[] getAuthenticatorTypes() {
|
||||
public AuthenticatorDescription[] getAuthenticatorTypes() {
|
||||
long identityToken = clearCallingIdentity();
|
||||
try {
|
||||
Collection<AccountAuthenticatorCache.ServiceInfo<String>> authenticatorCollection =
|
||||
mAuthenticatorCache.getAllServices();
|
||||
String[] types = new String[authenticatorCollection.size()];
|
||||
Collection<AccountAuthenticatorCache.ServiceInfo<AuthenticatorDescription>>
|
||||
authenticatorCollection = mAuthenticatorCache.getAllServices();
|
||||
AuthenticatorDescription[] types =
|
||||
new AuthenticatorDescription[authenticatorCollection.size()];
|
||||
int i = 0;
|
||||
for (AccountAuthenticatorCache.ServiceInfo<String> authenticator
|
||||
for (AccountAuthenticatorCache.ServiceInfo<AuthenticatorDescription> authenticator
|
||||
: authenticatorCollection) {
|
||||
types[i] = authenticator.type;
|
||||
i++;
|
||||
|
||||
@@ -95,8 +95,9 @@ public class AuthenticatorBindHelper {
|
||||
|
||||
// otherwise find the component name for the authenticator and initiate a bind
|
||||
// if no authenticator or the bind fails then return false, otherwise return true
|
||||
AccountAuthenticatorCache.ServiceInfo authenticatorInfo =
|
||||
mAuthenticatorCache.getServiceInfo(authenticatorType);
|
||||
AccountAuthenticatorCache.ServiceInfo<AuthenticatorDescription> authenticatorInfo =
|
||||
mAuthenticatorCache.getServiceInfo(
|
||||
AuthenticatorDescription.newKey(authenticatorType));
|
||||
if (authenticatorInfo == null) {
|
||||
if (Log.isLoggable(TAG, Log.VERBOSE)) {
|
||||
Log.v(TAG, "there is no authenticator for " + authenticatorType
|
||||
|
||||
19
core/java/android/accounts/AuthenticatorDescription.aidl
Normal file
19
core/java/android/accounts/AuthenticatorDescription.aidl
Normal file
@@ -0,0 +1,19 @@
|
||||
/*
|
||||
* Copyright (C) 2009 The Android Open Source Project
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package android.accounts;
|
||||
|
||||
parcelable AuthenticatorDescription;
|
||||
69
core/java/android/accounts/AuthenticatorDescription.java
Normal file
69
core/java/android/accounts/AuthenticatorDescription.java
Normal file
@@ -0,0 +1,69 @@
|
||||
package android.accounts;
|
||||
|
||||
import android.os.Parcelable;
|
||||
import android.os.Parcel;
|
||||
|
||||
public class AuthenticatorDescription implements Parcelable {
|
||||
final public String type;
|
||||
final public int labelId;
|
||||
final public int iconId;
|
||||
final public String packageName;
|
||||
|
||||
public AuthenticatorDescription(String type, String packageName, int labelId, int iconId) {
|
||||
this.type = type;
|
||||
this.packageName = packageName;
|
||||
this.labelId = labelId;
|
||||
this.iconId = iconId;
|
||||
}
|
||||
|
||||
public static AuthenticatorDescription newKey(String type) {
|
||||
return new AuthenticatorDescription(type);
|
||||
}
|
||||
|
||||
private AuthenticatorDescription(String type) {
|
||||
this.type = type;
|
||||
this.packageName = null;
|
||||
this.labelId = 0;
|
||||
this.iconId = 0;
|
||||
}
|
||||
|
||||
private AuthenticatorDescription(Parcel source) {
|
||||
this.type = source.readString();
|
||||
this.packageName = source.readString();
|
||||
this.labelId = source.readInt();
|
||||
this.iconId = source.readInt();
|
||||
}
|
||||
|
||||
public int describeContents() {
|
||||
return 0;
|
||||
}
|
||||
|
||||
public int hashCode() {
|
||||
return type.hashCode();
|
||||
}
|
||||
|
||||
public boolean equals(Object o) {
|
||||
if (o == this) return true;
|
||||
if (!(o instanceof AuthenticatorDescription)) return false;
|
||||
final AuthenticatorDescription other = (AuthenticatorDescription) o;
|
||||
return type.equals(other.type);
|
||||
}
|
||||
|
||||
public void writeToParcel(Parcel dest, int flags) {
|
||||
dest.writeString(type);
|
||||
dest.writeString(packageName);
|
||||
dest.writeInt(labelId);
|
||||
dest.writeInt(iconId);
|
||||
}
|
||||
|
||||
public static final Creator<AuthenticatorDescription> CREATOR =
|
||||
new Creator<AuthenticatorDescription>() {
|
||||
public AuthenticatorDescription createFromParcel(Parcel source) {
|
||||
return new AuthenticatorDescription(source);
|
||||
}
|
||||
|
||||
public AuthenticatorDescription[] newArray(int size) {
|
||||
return new AuthenticatorDescription[size];
|
||||
}
|
||||
};
|
||||
}
|
||||
@@ -18,6 +18,7 @@ package android.accounts;
|
||||
|
||||
import android.accounts.IAccountManagerResponse;
|
||||
import android.accounts.Account;
|
||||
import android.accounts.AuthenticatorDescription;
|
||||
import android.os.Bundle;
|
||||
|
||||
/**
|
||||
@@ -27,7 +28,7 @@ import android.os.Bundle;
|
||||
interface IAccountManager {
|
||||
String getPassword(in Account account);
|
||||
String getUserData(in Account account, String key);
|
||||
String[] getAuthenticatorTypes();
|
||||
AuthenticatorDescription[] getAuthenticatorTypes();
|
||||
Account[] getAccounts();
|
||||
Account[] getAccountsByType(String accountType);
|
||||
boolean addAccount(in Account account, String password, in Bundle extras);
|
||||
|
||||
@@ -16,32 +16,10 @@
|
||||
|
||||
package android.content;
|
||||
|
||||
import android.content.pm.PackageManager;
|
||||
import android.content.pm.ResolveInfo;
|
||||
import android.content.pm.ServiceInfo;
|
||||
import android.content.pm.RegisteredServicesCache;
|
||||
import android.content.res.XmlResourceParser;
|
||||
import android.content.res.TypedArray;
|
||||
import android.content.BroadcastReceiver;
|
||||
import android.content.ComponentName;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.content.IntentFilter;
|
||||
import android.util.Log;
|
||||
import android.util.AttributeSet;
|
||||
import android.util.Xml;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.FileDescriptor;
|
||||
import java.io.PrintWriter;
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import com.google.android.collect.Maps;
|
||||
import org.xmlpull.v1.XmlPullParserException;
|
||||
import org.xmlpull.v1.XmlPullParser;
|
||||
|
||||
/**
|
||||
* A cache of services that export the {@link android.content.ISyncAdapter} interface.
|
||||
@@ -58,7 +36,7 @@ import org.xmlpull.v1.XmlPullParser;
|
||||
super(context, SERVICE_INTERFACE, SERVICE_META_DATA, ATTRIBUTES_NAME);
|
||||
}
|
||||
|
||||
public SyncAdapterType parseServiceAttributes(AttributeSet attrs) {
|
||||
public SyncAdapterType parseServiceAttributes(String packageName, AttributeSet attrs) {
|
||||
TypedArray sa = mContext.getResources().obtainAttributes(attrs,
|
||||
com.android.internal.R.styleable.SyncAdapter);
|
||||
try {
|
||||
|
||||
@@ -1642,7 +1642,7 @@ class SyncManager implements OnAccountsUpdatedListener {
|
||||
// connect to the sync adapter
|
||||
SyncAdapterType syncAdapterType = new SyncAdapterType(syncOperation.authority,
|
||||
syncOperation.account.mType);
|
||||
RegisteredServicesCache.ServiceInfo syncAdapterInfo =
|
||||
RegisteredServicesCache.ServiceInfo<SyncAdapterType> syncAdapterInfo =
|
||||
mSyncAdapters.getServiceInfo(syncAdapterType);
|
||||
if (syncAdapterInfo == null) {
|
||||
if (Config.LOGD) {
|
||||
|
||||
@@ -130,7 +130,7 @@ public abstract class RegisteredServicesCache<V> {
|
||||
* @param type the account type of the authenticator
|
||||
* @return the AuthenticatorInfo that matches the account type or null if none is present
|
||||
*/
|
||||
public ServiceInfo getServiceInfo(V type) {
|
||||
public ServiceInfo<V> getServiceInfo(V type) {
|
||||
if (mServices == null) {
|
||||
maybeRegisterForPackageChanges();
|
||||
mServices = generateServicesMap();
|
||||
@@ -219,7 +219,7 @@ public abstract class RegisteredServicesCache<V> {
|
||||
"Meta-data does not start with " + mAttributesName + " tag");
|
||||
}
|
||||
|
||||
V v = parseServiceAttributes(attrs);
|
||||
V v = parseServiceAttributes(si.packageName, attrs);
|
||||
if (v == null) {
|
||||
return null;
|
||||
}
|
||||
@@ -229,5 +229,5 @@ public abstract class RegisteredServicesCache<V> {
|
||||
}
|
||||
}
|
||||
|
||||
public abstract V parseServiceAttributes(AttributeSet attrs);
|
||||
public abstract V parseServiceAttributes(String packageName, AttributeSet attrs);
|
||||
}
|
||||
|
||||
@@ -3297,6 +3297,10 @@
|
||||
<declare-styleable name="AccountAuthenticator">
|
||||
<!-- the account type this authenticator handles. -->
|
||||
<attr name="accountType" format="string"/>
|
||||
<!-- the user-visible name of the authenticator. -->
|
||||
<attr name="label"/>
|
||||
<!-- the icon of the authenticator. -->
|
||||
<attr name="icon"/>
|
||||
</declare-styleable>
|
||||
|
||||
<!-- =============================== -->
|
||||
|
||||
Reference in New Issue
Block a user