Add <autofill-service> that declares AutoFillService metadata.
The initial version of <autofill-service> may contain a settingsActivity attribute. Test: Manual verification Change-Id: I63a67aa4b7110fbf21d0b01ee53add712bfb0364
This commit is contained in:
@@ -61,6 +61,19 @@ public abstract class AutoFillService extends Service {
|
||||
@SdkConstant(SdkConstant.SdkConstantType.SERVICE_ACTION)
|
||||
public static final String SERVICE_INTERFACE = "android.service.autofill.AutoFillService";
|
||||
|
||||
/**
|
||||
* Name under which a AutoFillService component publishes information about itself.
|
||||
* This meta-data should reference an XML resource containing a
|
||||
* <code><{@link
|
||||
* android.R.styleable#AutoFillService autofill-service}></code> tag.
|
||||
* This is a a sample XML file configuring an AutoFillService:
|
||||
* <pre> <autofill-service
|
||||
* android:settingsActivity="foo.bar.SettingsActivity"
|
||||
* . . .
|
||||
* /></pre>
|
||||
*/
|
||||
public static final String SERVICE_META_DATA = "android.autofill";
|
||||
|
||||
// Internal bundle keys.
|
||||
/** @hide */ public static final String KEY_CALLBACK = "callback";
|
||||
/** @hide */ public static final String KEY_SAVABLE_IDS = "savable_ids";
|
||||
|
||||
@@ -16,20 +16,34 @@
|
||||
package android.service.autofill;
|
||||
|
||||
import android.Manifest;
|
||||
import android.annotation.Nullable;
|
||||
import android.app.AppGlobals;
|
||||
import android.content.ComponentName;
|
||||
import android.content.pm.PackageManager;
|
||||
import android.content.pm.ServiceInfo;
|
||||
import android.content.res.Resources;
|
||||
import android.content.res.TypedArray;
|
||||
import android.content.res.XmlResourceParser;
|
||||
import android.os.RemoteException;
|
||||
import android.util.AttributeSet;
|
||||
import android.util.Log;
|
||||
import android.util.Xml;
|
||||
import org.xmlpull.v1.XmlPullParser;
|
||||
import org.xmlpull.v1.XmlPullParserException;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
/** @hide */
|
||||
public final class AutoFillServiceInfo {
|
||||
static final String TAG = "AutoFillServiceInfo";
|
||||
|
||||
private static ServiceInfo getServiceInfoOrThrow(ComponentName comp, int userHandle)
|
||||
throws PackageManager.NameNotFoundException {
|
||||
try {
|
||||
final ServiceInfo si =
|
||||
AppGlobals.getPackageManager().getServiceInfo(comp, 0, userHandle);
|
||||
ServiceInfo si = AppGlobals.getPackageManager().getServiceInfo(
|
||||
comp,
|
||||
PackageManager.GET_META_DATA,
|
||||
userHandle);
|
||||
if (si != null) {
|
||||
return si;
|
||||
}
|
||||
@@ -38,11 +52,21 @@ public final class AutoFillServiceInfo {
|
||||
throw new PackageManager.NameNotFoundException(comp.toString());
|
||||
}
|
||||
|
||||
@Nullable
|
||||
private String mParseError;
|
||||
|
||||
@Nullable
|
||||
private ServiceInfo mServiceInfo;
|
||||
@Nullable
|
||||
private String mSettingsActivity;
|
||||
|
||||
private AutoFillServiceInfo(ServiceInfo si) {
|
||||
public AutoFillServiceInfo(PackageManager pm, ComponentName comp, int userHandle)
|
||||
throws PackageManager.NameNotFoundException {
|
||||
this(pm, getServiceInfoOrThrow(comp, userHandle));
|
||||
}
|
||||
|
||||
public AutoFillServiceInfo(PackageManager pm, ServiceInfo si)
|
||||
throws PackageManager.NameNotFoundException{
|
||||
if (si == null) {
|
||||
mParseError = "Service not available";
|
||||
return;
|
||||
@@ -53,19 +77,57 @@ public final class AutoFillServiceInfo {
|
||||
return;
|
||||
}
|
||||
|
||||
XmlResourceParser parser = null;
|
||||
try {
|
||||
parser = si.loadXmlMetaData(pm, AutoFillService.SERVICE_META_DATA);
|
||||
if (parser == null) {
|
||||
mParseError = "No " + AutoFillService.SERVICE_META_DATA
|
||||
+ " meta-data for " + si.packageName;
|
||||
return;
|
||||
}
|
||||
|
||||
Resources res = pm.getResourcesForApplication(si.applicationInfo);
|
||||
|
||||
AttributeSet attrs = Xml.asAttributeSet(parser);
|
||||
|
||||
int type;
|
||||
while ((type=parser.next()) != XmlPullParser.END_DOCUMENT
|
||||
&& type != XmlPullParser.START_TAG) {
|
||||
}
|
||||
|
||||
String nodeName = parser.getName();
|
||||
if (!"autofill-service".equals(nodeName)) {
|
||||
mParseError = "Meta-data does not start with autofill-service tag";
|
||||
return;
|
||||
}
|
||||
|
||||
TypedArray array = res.obtainAttributes(attrs,
|
||||
com.android.internal.R.styleable.AutoFillService);
|
||||
mSettingsActivity = array.getString(
|
||||
com.android.internal.R.styleable.AutoFillService_settingsActivity);
|
||||
array.recycle();
|
||||
} catch (XmlPullParserException | IOException | PackageManager.NameNotFoundException e) {
|
||||
mParseError = "Error parsing auto fill service meta-data: " + e;
|
||||
Log.w(TAG, "error parsing auto fill service meta-data", e);
|
||||
return;
|
||||
} finally {
|
||||
if (parser != null) parser.close();
|
||||
}
|
||||
mServiceInfo = si;
|
||||
}
|
||||
|
||||
public AutoFillServiceInfo(ComponentName comp, int userHandle)
|
||||
throws PackageManager.NameNotFoundException {
|
||||
this(getServiceInfoOrThrow(comp, userHandle));
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public String getParseError() {
|
||||
return mParseError;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public ServiceInfo getServiceInfo() {
|
||||
return mServiceInfo;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public String getSettingsActivity() {
|
||||
return mSettingsActivity;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user