Merge "Added support to run autofill service from instant apps." into pi-dev
This commit is contained in:
committed by
Android (Google) Code Review
commit
0cd7a2e101
@@ -157,6 +157,9 @@ public final class AutofillManagerService extends SystemService {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@GuardedBy("mLock")
|
||||||
|
private boolean mAllowInstantService;
|
||||||
|
|
||||||
public AutofillManagerService(Context context) {
|
public AutofillManagerService(Context context) {
|
||||||
super(context);
|
super(context);
|
||||||
mContext = context;
|
mContext = context;
|
||||||
@@ -518,6 +521,23 @@ public final class AutofillManagerService extends SystemService {
|
|||||||
sFullScreenMode = mode;
|
sFullScreenMode = mode;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Called by Shell command.
|
||||||
|
boolean getAllowInstantService() {
|
||||||
|
mContext.enforceCallingPermission(MANAGE_AUTO_FILL, TAG);
|
||||||
|
synchronized (mLock) {
|
||||||
|
return mAllowInstantService;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Called by Shell command.
|
||||||
|
void setAllowInstantService(boolean mode) {
|
||||||
|
mContext.enforceCallingPermission(MANAGE_AUTO_FILL, TAG);
|
||||||
|
Slog.i(TAG, "setAllowInstantService(): " + mode);
|
||||||
|
synchronized (mLock) {
|
||||||
|
mAllowInstantService = mode;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private void setDebugLocked(boolean debug) {
|
private void setDebugLocked(boolean debug) {
|
||||||
com.android.server.autofill.Helper.sDebug = debug;
|
com.android.server.autofill.Helper.sDebug = debug;
|
||||||
android.view.autofill.Helper.sDebug = debug;
|
android.view.autofill.Helper.sDebug = debug;
|
||||||
@@ -866,7 +886,8 @@ public final class AutofillManagerService extends SystemService {
|
|||||||
synchronized (mLock) {
|
synchronized (mLock) {
|
||||||
final AutofillManagerServiceImpl service = getServiceForUserLocked(userId);
|
final AutofillManagerServiceImpl service = getServiceForUserLocked(userId);
|
||||||
return service.startSessionLocked(activityToken, getCallingUid(), appCallback,
|
return service.startSessionLocked(activityToken, getCallingUid(), appCallback,
|
||||||
autofillId, bounds, value, hasCallback, flags, componentName, compatMode);
|
autofillId, bounds, value, hasCallback, componentName, compatMode,
|
||||||
|
mAllowInstantService, flags);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1202,6 +1223,7 @@ public final class AutofillManagerService extends SystemService {
|
|||||||
mAutofillCompatState.dump(prefix2, pw);
|
mAutofillCompatState.dump(prefix2, pw);
|
||||||
pw.print(prefix2); pw.print("from settings: ");
|
pw.print(prefix2); pw.print("from settings: ");
|
||||||
pw.println(getWhitelistedCompatModePackagesFromSettings());
|
pw.println(getWhitelistedCompatModePackagesFromSettings());
|
||||||
|
pw.print("Allow instant service: "); pw.println(mAllowInstantService);
|
||||||
}
|
}
|
||||||
if (showHistory) {
|
if (showHistory) {
|
||||||
pw.println(); pw.println("Requests history:"); pw.println();
|
pw.println(); pw.println("Requests history:"); pw.println();
|
||||||
|
|||||||
@@ -342,7 +342,8 @@ final class AutofillManagerServiceImpl {
|
|||||||
int startSessionLocked(@NonNull IBinder activityToken, int uid,
|
int startSessionLocked(@NonNull IBinder activityToken, int uid,
|
||||||
@NonNull IBinder appCallbackToken, @NonNull AutofillId autofillId,
|
@NonNull IBinder appCallbackToken, @NonNull AutofillId autofillId,
|
||||||
@NonNull Rect virtualBounds, @Nullable AutofillValue value, boolean hasCallback,
|
@NonNull Rect virtualBounds, @Nullable AutofillValue value, boolean hasCallback,
|
||||||
int flags, @NonNull ComponentName componentName, boolean compatMode) {
|
@NonNull ComponentName componentName, boolean compatMode,
|
||||||
|
boolean bindInstantServiceAllowed, int flags) {
|
||||||
if (!isEnabledLocked()) {
|
if (!isEnabledLocked()) {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
@@ -372,7 +373,7 @@ final class AutofillManagerServiceImpl {
|
|||||||
pruneAbandonedSessionsLocked();
|
pruneAbandonedSessionsLocked();
|
||||||
|
|
||||||
final Session newSession = createSessionByTokenLocked(activityToken, uid, appCallbackToken,
|
final Session newSession = createSessionByTokenLocked(activityToken, uid, appCallbackToken,
|
||||||
hasCallback, componentName, compatMode, flags);
|
hasCallback, componentName, compatMode, bindInstantServiceAllowed, flags);
|
||||||
if (newSession == null) {
|
if (newSession == null) {
|
||||||
return NO_SESSION;
|
return NO_SESSION;
|
||||||
}
|
}
|
||||||
@@ -491,7 +492,8 @@ final class AutofillManagerServiceImpl {
|
|||||||
@GuardedBy("mLock")
|
@GuardedBy("mLock")
|
||||||
private Session createSessionByTokenLocked(@NonNull IBinder activityToken, int uid,
|
private Session createSessionByTokenLocked(@NonNull IBinder activityToken, int uid,
|
||||||
@NonNull IBinder appCallbackToken, boolean hasCallback,
|
@NonNull IBinder appCallbackToken, boolean hasCallback,
|
||||||
@NonNull ComponentName componentName, boolean compatMode, int flags) {
|
@NonNull ComponentName componentName, boolean compatMode,
|
||||||
|
boolean bindInstantServiceAllowed, int flags) {
|
||||||
// use random ids so that one app cannot know that another app creates sessions
|
// use random ids so that one app cannot know that another app creates sessions
|
||||||
int sessionId;
|
int sessionId;
|
||||||
int tries = 0;
|
int tries = 0;
|
||||||
@@ -510,7 +512,7 @@ final class AutofillManagerServiceImpl {
|
|||||||
final Session newSession = new Session(this, mUi, mContext, mHandler, mUserId, mLock,
|
final Session newSession = new Session(this, mUi, mContext, mHandler, mUserId, mLock,
|
||||||
sessionId, uid, activityToken, appCallbackToken, hasCallback, mUiLatencyHistory,
|
sessionId, uid, activityToken, appCallbackToken, hasCallback, mUiLatencyHistory,
|
||||||
mWtfHistory, mInfo.getServiceInfo().getComponentName(), componentName, compatMode,
|
mWtfHistory, mInfo.getServiceInfo().getComponentName(), componentName, compatMode,
|
||||||
flags);
|
bindInstantServiceAllowed, flags);
|
||||||
mSessions.put(newSession.id, newSession);
|
mSessions.put(newSession.id, newSession);
|
||||||
|
|
||||||
return newSession;
|
return newSession;
|
||||||
|
|||||||
@@ -86,6 +86,9 @@ public final class AutofillManagerServiceShellCommand extends ShellCommand {
|
|||||||
pw.println(" get fc_score [--algorithm ALGORITHM] value1 value2");
|
pw.println(" get fc_score [--algorithm ALGORITHM] value1 value2");
|
||||||
pw.println(" Gets the field classification score for 2 fields.");
|
pw.println(" Gets the field classification score for 2 fields.");
|
||||||
pw.println("");
|
pw.println("");
|
||||||
|
pw.println(" get bind-instant-service-allowed");
|
||||||
|
pw.println(" Gets whether binding to services provided by instant apps is allowed");
|
||||||
|
pw.println("");
|
||||||
pw.println(" set log_level [off | debug | verbose]");
|
pw.println(" set log_level [off | debug | verbose]");
|
||||||
pw.println(" Sets the Autofill log level.");
|
pw.println(" Sets the Autofill log level.");
|
||||||
pw.println("");
|
pw.println("");
|
||||||
@@ -98,6 +101,9 @@ public final class AutofillManagerServiceShellCommand extends ShellCommand {
|
|||||||
pw.println(" set full_screen_mode [true | false | default]");
|
pw.println(" set full_screen_mode [true | false | default]");
|
||||||
pw.println(" Sets the Fill UI full screen mode");
|
pw.println(" Sets the Fill UI full screen mode");
|
||||||
pw.println("");
|
pw.println("");
|
||||||
|
pw.println(" set bind-instant-service-allowed [true | false]");
|
||||||
|
pw.println(" Sets whether binding to services provided by instant apps is allowed");
|
||||||
|
pw.println("");
|
||||||
pw.println(" list sessions [--user USER_ID]");
|
pw.println(" list sessions [--user USER_ID]");
|
||||||
pw.println(" Lists all pending sessions.");
|
pw.println(" Lists all pending sessions.");
|
||||||
pw.println("");
|
pw.println("");
|
||||||
@@ -123,6 +129,8 @@ public final class AutofillManagerServiceShellCommand extends ShellCommand {
|
|||||||
return getFieldClassificationScore(pw);
|
return getFieldClassificationScore(pw);
|
||||||
case "full_screen_mode":
|
case "full_screen_mode":
|
||||||
return getFullScreenMode(pw);
|
return getFullScreenMode(pw);
|
||||||
|
case "bind-instant-service-allowed":
|
||||||
|
return getBindInstantService(pw);
|
||||||
default:
|
default:
|
||||||
pw.println("Invalid set: " + what);
|
pw.println("Invalid set: " + what);
|
||||||
return -1;
|
return -1;
|
||||||
@@ -141,6 +149,8 @@ public final class AutofillManagerServiceShellCommand extends ShellCommand {
|
|||||||
return setMaxVisibileDatasets();
|
return setMaxVisibileDatasets();
|
||||||
case "full_screen_mode":
|
case "full_screen_mode":
|
||||||
return setFullScreenMode(pw);
|
return setFullScreenMode(pw);
|
||||||
|
case "bind-instant-service-allowed":
|
||||||
|
return setBindInstantService(pw);
|
||||||
default:
|
default:
|
||||||
pw.println("Invalid set: " + what);
|
pw.println("Invalid set: " + what);
|
||||||
return -1;
|
return -1;
|
||||||
@@ -259,6 +269,30 @@ public final class AutofillManagerServiceShellCommand extends ShellCommand {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private int getBindInstantService(PrintWriter pw) {
|
||||||
|
if (mService.getAllowInstantService()) {
|
||||||
|
pw.println("true");
|
||||||
|
} else {
|
||||||
|
pw.println("false");
|
||||||
|
}
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
private int setBindInstantService(PrintWriter pw) {
|
||||||
|
final String mode = getNextArgRequired();
|
||||||
|
switch (mode.toLowerCase()) {
|
||||||
|
case "true":
|
||||||
|
mService.setAllowInstantService(true);
|
||||||
|
return 0;
|
||||||
|
case "false":
|
||||||
|
mService.setAllowInstantService(false);
|
||||||
|
return 0;
|
||||||
|
default:
|
||||||
|
pw.println("Invalid mode: " + mode);
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private int requestDestroy(PrintWriter pw) {
|
private int requestDestroy(PrintWriter pw) {
|
||||||
if (!isNextArgSessions(pw)) {
|
if (!isNextArgSessions(pw)) {
|
||||||
return -1;
|
return -1;
|
||||||
|
|||||||
@@ -15,8 +15,6 @@
|
|||||||
*/
|
*/
|
||||||
package com.android.server.autofill;
|
package com.android.server.autofill;
|
||||||
|
|
||||||
import static android.view.autofill.AutofillManager.FC_SERVICE_TIMEOUT;
|
|
||||||
|
|
||||||
import static com.android.server.autofill.Helper.sDebug;
|
import static com.android.server.autofill.Helper.sDebug;
|
||||||
import static com.android.server.autofill.Helper.sVerbose;
|
import static com.android.server.autofill.Helper.sVerbose;
|
||||||
import static android.service.autofill.AutofillFieldClassificationService.SERVICE_META_DATA_KEY_AVAILABLE_ALGORITHMS;
|
import static android.service.autofill.AutofillFieldClassificationService.SERVICE_META_DATA_KEY_AVAILABLE_ALGORITHMS;
|
||||||
@@ -52,8 +50,6 @@ import java.io.PrintWriter;
|
|||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.concurrent.CountDownLatch;
|
|
||||||
import java.util.concurrent.TimeUnit;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Strategy used to bridge the field classification algorithms provided by a service in an external
|
* Strategy used to bridge the field classification algorithms provided by a service in an external
|
||||||
|
|||||||
@@ -68,6 +68,9 @@ public final class Helper {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* When non-null, overrides whether the UI should be shown on full-screen mode.
|
* When non-null, overrides whether the UI should be shown on full-screen mode.
|
||||||
|
*
|
||||||
|
* <p>Note: access to this variable is not synchronized because it's "final" on real usage -
|
||||||
|
* it's only set by Shell cmd, for development purposes.
|
||||||
*/
|
*/
|
||||||
public static Boolean sFullScreenMode = null;
|
public static Boolean sFullScreenMode = null;
|
||||||
|
|
||||||
|
|||||||
@@ -84,6 +84,8 @@ final class RemoteFillService implements DeathRecipient {
|
|||||||
|
|
||||||
private final Handler mHandler;
|
private final Handler mHandler;
|
||||||
|
|
||||||
|
private final boolean mBindInstantServiceAllowed;
|
||||||
|
|
||||||
private IAutoFillService mAutoFillService;
|
private IAutoFillService mAutoFillService;
|
||||||
|
|
||||||
private boolean mBinding;
|
private boolean mBinding;
|
||||||
@@ -109,13 +111,14 @@ final class RemoteFillService implements DeathRecipient {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public RemoteFillService(Context context, ComponentName componentName,
|
public RemoteFillService(Context context, ComponentName componentName,
|
||||||
int userId, FillServiceCallbacks callbacks) {
|
int userId, FillServiceCallbacks callbacks, boolean bindInstantServiceAllowed) {
|
||||||
mContext = context;
|
mContext = context;
|
||||||
mCallbacks = callbacks;
|
mCallbacks = callbacks;
|
||||||
mComponentName = componentName;
|
mComponentName = componentName;
|
||||||
mIntent = new Intent(AutofillService.SERVICE_INTERFACE).setComponent(mComponentName);
|
mIntent = new Intent(AutofillService.SERVICE_INTERFACE).setComponent(mComponentName);
|
||||||
mUserId = userId;
|
mUserId = userId;
|
||||||
mHandler = new Handler(FgThread.getHandler().getLooper());
|
mHandler = new Handler(FgThread.getHandler().getLooper());
|
||||||
|
mBindInstantServiceAllowed = bindInstantServiceAllowed;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void destroy() {
|
public void destroy() {
|
||||||
@@ -207,6 +210,7 @@ final class RemoteFillService implements DeathRecipient {
|
|||||||
.append(String.valueOf(isBound())).println();
|
.append(String.valueOf(isBound())).println();
|
||||||
pw.append(prefix).append(tab).append("hasPendingRequest=")
|
pw.append(prefix).append(tab).append("hasPendingRequest=")
|
||||||
.append(String.valueOf(mPendingRequest != null)).println();
|
.append(String.valueOf(mPendingRequest != null)).println();
|
||||||
|
pw.append(prefix).append("mBindInstantServiceAllowed=").println(mBindInstantServiceAllowed);
|
||||||
pw.println();
|
pw.println();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -258,12 +262,17 @@ final class RemoteFillService implements DeathRecipient {
|
|||||||
if (sVerbose) Slog.v(LOG_TAG, "[user: " + mUserId + "] ensureBound()");
|
if (sVerbose) Slog.v(LOG_TAG, "[user: " + mUserId + "] ensureBound()");
|
||||||
mBinding = true;
|
mBinding = true;
|
||||||
|
|
||||||
boolean willBind = mContext.bindServiceAsUser(mIntent, mServiceConnection,
|
int flags = Context.BIND_AUTO_CREATE | Context.BIND_FOREGROUND_SERVICE;
|
||||||
Context.BIND_AUTO_CREATE | Context.BIND_FOREGROUND_SERVICE,
|
if (mBindInstantServiceAllowed) {
|
||||||
|
flags |= Context.BIND_ALLOW_INSTANT;
|
||||||
|
}
|
||||||
|
|
||||||
|
final boolean willBind = mContext.bindServiceAsUser(mIntent, mServiceConnection, flags,
|
||||||
new UserHandle(mUserId));
|
new UserHandle(mUserId));
|
||||||
|
|
||||||
if (!willBind) {
|
if (!willBind) {
|
||||||
if (sDebug) Slog.d(LOG_TAG, "[user: " + mUserId + "] could not bind to " + mIntent);
|
Slog.w(LOG_TAG, "[user: " + mUserId + "] could not bind to " + mIntent + " using flags "
|
||||||
|
+ flags);
|
||||||
mBinding = false;
|
mBinding = false;
|
||||||
|
|
||||||
if (!mServiceDied) {
|
if (!mServiceDied) {
|
||||||
|
|||||||
@@ -517,7 +517,7 @@ final class Session implements RemoteFillService.FillServiceCallbacks, ViewState
|
|||||||
@NonNull IBinder client, boolean hasCallback, @NonNull LocalLog uiLatencyHistory,
|
@NonNull IBinder client, boolean hasCallback, @NonNull LocalLog uiLatencyHistory,
|
||||||
@NonNull LocalLog wtfHistory,
|
@NonNull LocalLog wtfHistory,
|
||||||
@NonNull ComponentName serviceComponentName, @NonNull ComponentName componentName,
|
@NonNull ComponentName serviceComponentName, @NonNull ComponentName componentName,
|
||||||
boolean compatMode, int flags) {
|
boolean compatMode, boolean bindInstantServiceAllowed, int flags) {
|
||||||
id = sessionId;
|
id = sessionId;
|
||||||
mFlags = flags;
|
mFlags = flags;
|
||||||
this.uid = uid;
|
this.uid = uid;
|
||||||
@@ -526,7 +526,8 @@ final class Session implements RemoteFillService.FillServiceCallbacks, ViewState
|
|||||||
mLock = lock;
|
mLock = lock;
|
||||||
mUi = ui;
|
mUi = ui;
|
||||||
mHandler = handler;
|
mHandler = handler;
|
||||||
mRemoteFillService = new RemoteFillService(context, serviceComponentName, userId, this);
|
mRemoteFillService = new RemoteFillService(context, serviceComponentName, userId, this,
|
||||||
|
bindInstantServiceAllowed);
|
||||||
mActivityToken = activityToken;
|
mActivityToken = activityToken;
|
||||||
mHasCallback = hasCallback;
|
mHasCallback = hasCallback;
|
||||||
mUiLatencyHistory = uiLatencyHistory;
|
mUiLatencyHistory = uiLatencyHistory;
|
||||||
|
|||||||
@@ -18,7 +18,6 @@ package com.android.server.autofill;
|
|||||||
|
|
||||||
import static android.service.autofill.FillRequest.FLAG_MANUAL_REQUEST;
|
import static android.service.autofill.FillRequest.FLAG_MANUAL_REQUEST;
|
||||||
import static com.android.server.autofill.Helper.sDebug;
|
import static com.android.server.autofill.Helper.sDebug;
|
||||||
import static com.android.server.autofill.Helper.sVerbose;
|
|
||||||
|
|
||||||
import android.annotation.Nullable;
|
import android.annotation.Nullable;
|
||||||
import android.graphics.Rect;
|
import android.graphics.Rect;
|
||||||
|
|||||||
Reference in New Issue
Block a user