Merge "Improved Autofill logging." into oc-dev

This commit is contained in:
TreeHugger Robot
2017-04-28 15:50:26 +00:00
committed by Android (Google) Code Review
20 changed files with 282 additions and 229 deletions

View File

@@ -16,7 +16,7 @@
package android.service.autofill;
import static android.view.autofill.Helper.DEBUG;
import static android.view.autofill.Helper.sDebug;
import android.annotation.NonNull;
import android.annotation.Nullable;
@@ -24,7 +24,6 @@ import android.content.IntentSender;
import android.os.Parcel;
import android.os.Parcelable;
import android.view.autofill.AutofillId;
import android.view.autofill.AutofillManager;
import android.view.autofill.AutofillValue;
import android.widget.RemoteViews;
import com.android.internal.util.Preconditions;
@@ -90,7 +89,7 @@ public final class Dataset implements Parcelable {
@Override
public String toString() {
if (!DEBUG) return super.toString();
if (!sDebug) return super.toString();
return new StringBuilder("Dataset " + mId + " [")
.append("fieldIds=").append(mFieldIds)

View File

@@ -16,7 +16,7 @@
package android.service.autofill;
import static android.view.autofill.Helper.DEBUG;
import static android.view.autofill.Helper.sDebug;
import android.annotation.NonNull;
import android.app.assist.AssistStructure;
@@ -74,7 +74,7 @@ public final class FillContext implements Parcelable {
@Override
public String toString() {
if (!DEBUG) return super.toString();
if (!sDebug) return super.toString();
return "FillContext [reqId=" + mRequestId + "]";
}

View File

@@ -17,7 +17,7 @@
package android.service.autofill;
import static android.service.autofill.FillRequest.INVALID_REQUEST_ID;
import static android.view.autofill.Helper.DEBUG;
import static android.view.autofill.Helper.sDebug;
import android.annotation.NonNull;
import android.annotation.Nullable;
@@ -394,7 +394,7 @@ public final class FillResponse implements Parcelable {
/////////////////////////////////////
@Override
public String toString() {
if (!DEBUG) return super.toString();
if (!sDebug) return super.toString();
return new StringBuilder(
"FillResponse : [mRequestId=" + mRequestId)

View File

@@ -16,7 +16,7 @@
package android.service.autofill;
import static android.view.autofill.Helper.DEBUG;
import static android.view.autofill.Helper.sDebug;
import android.annotation.IntDef;
import android.annotation.NonNull;
@@ -387,7 +387,7 @@ public final class SaveInfo implements Parcelable {
/////////////////////////////////////
@Override
public String toString() {
if (!DEBUG) return super.toString();
if (!sDebug) return super.toString();
return new StringBuilder("SaveInfo: [type=")
.append(DebugUtils.flagsToString(SaveInfo.class, "SAVE_DATA_TYPE_", mType))

View File

@@ -15,8 +15,6 @@
*/
package android.view.autofill;
import static android.view.autofill.Helper.DEBUG;
import android.os.Parcel;
import android.os.Parcelable;
import android.view.View;
@@ -92,11 +90,9 @@ public final class AutofillId implements Parcelable {
@Override
public String toString() {
if (!DEBUG) return super.toString();
final StringBuilder builder = new StringBuilder().append(mViewId);
if (mVirtual) {
builder.append(":").append(mVirtualId);
builder.append(':').append(mVirtualId);
}
return builder.toString();
}

View File

@@ -16,8 +16,8 @@
package android.view.autofill;
import static android.view.autofill.Helper.DEBUG;
import static android.view.autofill.Helper.VERBOSE;
import static android.view.autofill.Helper.sDebug;
import static android.view.autofill.Helper.sVerbose;
import android.annotation.IntDef;
import android.annotation.NonNull;
@@ -112,6 +112,11 @@ public final class AutofillManager {
/** @hide */ public static final int ACTION_VIEW_EXITED = 3;
/** @hide */ public static final int ACTION_VALUE_CHANGED = 4;
/** @hide */ public static final int FLAG_ADD_CLIENT_ENABLED = 0x1;
/** @hide */ public static final int FLAG_ADD_CLIENT_DEBUG = 0x2;
/** @hide */ public static final int FLAG_ADD_CLIENT_VERBOSE = 0x4;
private final MetricsLogger mMetricsLogger = new MetricsLogger();
/**
@@ -238,7 +243,7 @@ public final class AutofillManager {
Log.w(TAG, "Session " + mSessionId + " could not be restored");
mSessionId = NO_SESSION;
} else {
if (DEBUG) {
if (sDebug) {
Log.d(TAG, "session " + mSessionId + " was restored");
}
@@ -689,7 +694,7 @@ public final class AutofillManager {
// set the EXTRA_AUTHENTICATION_RESULT extra, but it could cause weird results if the
// service set the extra and returned RESULT_CANCELED...
if (DEBUG) Log.d(TAG, "onAuthenticationResult(): d=" + data);
if (sDebug) Log.d(TAG, "onAuthenticationResult(): d=" + data);
synchronized (mLock) {
if (mSessionId == NO_SESSION || data == null) {
@@ -716,8 +721,8 @@ public final class AutofillManager {
private void startSessionLocked(@NonNull AutofillId id, @NonNull IBinder windowToken,
@NonNull Rect bounds, @NonNull AutofillValue value, int flags) {
if (DEBUG) {
Log.d(TAG, "startSessionLocked(): id=" + id + ", bounds=" + bounds + ", value=" + value
if (sVerbose) {
Log.v(TAG, "startSessionLocked(): id=" + id + ", bounds=" + bounds + ", value=" + value
+ ", flags=" + flags);
}
@@ -735,9 +740,7 @@ public final class AutofillManager {
}
private void finishSessionLocked() {
if (DEBUG) {
Log.d(TAG, "finishSessionLocked()");
}
if (sVerbose) Log.v(TAG, "finishSessionLocked()");
try {
mService.finishSession(mSessionId, mContext.getUserId());
@@ -750,9 +753,7 @@ public final class AutofillManager {
}
private void cancelSessionLocked() {
if (DEBUG) {
Log.d(TAG, "cancelSessionLocked()");
}
if (sVerbose) Log.v(TAG, "cancelSessionLocked()");
try {
mService.cancelSession(mSessionId, mContext.getUserId());
@@ -770,11 +771,9 @@ public final class AutofillManager {
private void updateSessionLocked(AutofillId id, Rect bounds, AutofillValue value, int action,
int flags) {
if (DEBUG) {
if (VERBOSE || action != ACTION_VIEW_EXITED) {
Log.d(TAG, "updateSessionLocked(): id=" + id + ", bounds=" + bounds
+ ", value=" + value + ", action=" + action + ", flags=" + flags);
}
if (sVerbose && action != ACTION_VIEW_EXITED) {
Log.v(TAG, "updateSessionLocked(): id=" + id + ", bounds=" + bounds
+ ", value=" + value + ", action=" + action + ", flags=" + flags);
}
try {
@@ -793,7 +792,10 @@ public final class AutofillManager {
if (mServiceClient == null) {
mServiceClient = new AutofillManagerClient(this);
try {
mEnabled = mService.addClient(mServiceClient, mContext.getUserId());
final int flags = mService.addClient(mServiceClient, mContext.getUserId());
mEnabled = (flags & FLAG_ADD_CLIENT_ENABLED) != 0;
sDebug = (flags & FLAG_ADD_CLIENT_DEBUG) != 0;
sVerbose = (flags & FLAG_ADD_CLIENT_VERBOSE) != 0;
} catch (RemoteException e) {
throw e.rethrowFromSystemServer();
}
@@ -1175,8 +1177,8 @@ public final class AutofillManager {
}
}
if (DEBUG) {
Log.d(TAG, "TrackedViews(trackedIds=" + trackedIds + "): "
if (sVerbose) {
Log.v(TAG, "TrackedViews(trackedIds=" + trackedIds + "): "
+ " mVisibleTrackedIds=" + mVisibleTrackedIds
+ " mInvisibleTrackedIds=" + mInvisibleTrackedIds);
}
@@ -1196,7 +1198,7 @@ public final class AutofillManager {
AutofillId id = getAutofillId(view);
AutofillClient client = getClientLocked();
if (DEBUG) {
if (sDebug) {
Log.d(TAG, "notifyViewVisibilityChange(): id=" + id + " isVisible="
+ isVisible);
}
@@ -1237,8 +1239,8 @@ public final class AutofillManager {
if (client.getViewVisibility(id.getViewId())) {
updatedVisibleTrackedIds = addToSet(updatedVisibleTrackedIds, id);
if (DEBUG) {
Log.i(TAG, "onVisibleForAutofill() " + id + " became visible");
if (sDebug) {
Log.d(TAG, "onVisibleForAutofill() " + id + " became visible");
}
} else {
updatedInvisibleTrackedIds = addToSet(updatedInvisibleTrackedIds, id);
@@ -1253,8 +1255,8 @@ public final class AutofillManager {
} else {
updatedInvisibleTrackedIds = addToSet(updatedInvisibleTrackedIds, id);
if (DEBUG) {
Log.i(TAG, "onVisibleForAutofill() " + id + " became invisible");
if (sDebug) {
Log.d(TAG, "onVisibleForAutofill() " + id + " became invisible");
}
}
}

View File

@@ -20,8 +20,7 @@ import static android.view.View.AUTOFILL_TYPE_DATE;
import static android.view.View.AUTOFILL_TYPE_LIST;
import static android.view.View.AUTOFILL_TYPE_TEXT;
import static android.view.View.AUTOFILL_TYPE_TOGGLE;
import static android.view.autofill.Helper.DEBUG;
import static android.view.autofill.Helper.VERBOSE;
import static android.view.autofill.Helper.sDebug;
import android.annotation.NonNull;
import android.annotation.Nullable;
@@ -171,12 +170,17 @@ public final class AutofillValue implements Parcelable {
@Override
public String toString() {
if (!DEBUG) return super.toString();
if (!sDebug) return super.toString();
final String sanitizedValue = isText() && !VERBOSE
? ((CharSequence) mValue).length() + "_chars" : mValue.toString();
return "[type=" + mType + ", value=" + sanitizedValue + "]";
final StringBuilder string = new StringBuilder()
.append("[type=").append(mType)
.append(", value=");
if (isText()) {
string.append(((CharSequence) mValue).length()).append("_chars");
} else {
string.append(mValue);
}
return string.append(']').toString();
}
/////////////////////////////////////

View File

@@ -25,15 +25,16 @@ import java.util.Set;
/** @hide */
public final class Helper {
// TODO(b/36141126): set to false and remove guard from places that should always be on
public static final boolean DEBUG = true;
public static final boolean VERBOSE = false;
// Debug-level flags are defined when service is bound.
public static boolean sDebug = false;
public static boolean sVerbose = false;
public static final String REDACTED = "[REDACTED]";
static StringBuilder append(StringBuilder builder, Bundle bundle) {
if (bundle == null) {
if (bundle == null || !sDebug) {
builder.append("N/A");
} else if (!VERBOSE) {
} else if (!sVerbose) {
builder.append(REDACTED);
} else {
final Set<String> keySet = bundle.keySet();

View File

@@ -30,7 +30,8 @@ import android.view.autofill.IAutoFillManagerClient;
* {@hide}
*/
interface IAutoFillManager {
boolean addClient(in IAutoFillManagerClient client, int userId);
// Returns flags: FLAG_ADD_CLIENT_ENABLED | FLAG_ADD_CLIENT_DEBUG | FLAG_ADD_CLIENT_VERBOSE
int addClient(in IAutoFillManagerClient client, int userId);
int startSession(IBinder activityToken, IBinder windowToken, in IBinder appCallback,
in AutofillId autoFillId, in Rect bounds, in AutofillValue value, int userId,
boolean hasCallback, int flags, String packageName);

View File

@@ -19,14 +19,13 @@ package com.android.server.autofill;
import static android.Manifest.permission.MANAGE_AUTO_FILL;
import static android.content.Context.AUTOFILL_MANAGER_SERVICE;
import static com.android.server.autofill.Helper.DEBUG;
import static com.android.server.autofill.Helper.VERBOSE;
import static com.android.server.autofill.Helper.sDebug;
import static com.android.server.autofill.Helper.sVerbose;
import static com.android.server.autofill.Helper.bundleToString;
import android.annotation.NonNull;
import android.annotation.Nullable;
import android.app.ActivityManager;
import android.app.ActivityManagerInternal;
import android.content.BroadcastReceiver;
import android.content.ComponentName;
import android.content.ContentResolver;
@@ -39,6 +38,7 @@ import android.database.ContentObserver;
import android.graphics.Rect;
import android.net.Uri;
import android.os.Binder;
import android.os.Build;
import android.os.Bundle;
import android.os.Handler;
import android.os.IBinder;
@@ -50,13 +50,12 @@ import android.os.UserManager;
import android.os.UserManagerInternal;
import android.provider.Settings;
import android.service.autofill.FillEventHistory;
import android.text.TextUtils;
import android.util.LocalLog;
import android.util.Log;
import android.util.Slog;
import android.util.SparseArray;
import android.util.SparseBooleanArray;
import android.view.autofill.AutofillId;
import android.view.autofill.AutofillManager;
import android.view.autofill.AutofillValue;
import android.view.autofill.IAutoFillManager;
import android.view.autofill.IAutoFillManagerClient;
@@ -118,10 +117,6 @@ public final class AutofillManagerService extends SystemService {
@Override
public void onReceive(Context context, Intent intent) {
if (Intent.ACTION_CLOSE_SYSTEM_DIALOGS.equals(intent.getAction())) {
final String reason = intent.getStringExtra("reason");
if (VERBOSE) {
Slog.v(TAG, "close system dialogs: " + reason);
}
mUi.hideAll();
}
}
@@ -132,6 +127,10 @@ public final class AutofillManagerService extends SystemService {
mContext = context;
mUi = new AutoFillUI(mContext);
final boolean debug = Build.IS_DEBUGGABLE;
Slog.i(TAG, "Setting debug to " + debug);
setDebugLocked(debug);
final IntentFilter filter = new IntentFilter();
filter.addAction(Intent.ACTION_CLOSE_SYSTEM_DIALOGS);
mContext.registerReceiver(mBroadcastReceiver, filter, null, FgThread.getHandler());
@@ -154,7 +153,7 @@ public final class AutofillManagerService extends SystemService {
final boolean disabledBefore = mDisabledUsers.get(userId);
if (disabledBefore == disabledNow) {
// Nothing changed, do nothing.
if (DEBUG) {
if (sDebug) {
Slog.d(TAG, "Restriction not changed for user " + userId + ": "
+ bundleToString(newRestrictions));
return;
@@ -368,6 +367,42 @@ public final class AutofillManagerService extends SystemService {
}
}
// Called by Shell command.
void setLogLevel(int level) {
Slog.i(TAG, "setLogLevel(): " + level);
boolean debug = false;
boolean verbose = false;
if (level == AutofillManager.FLAG_ADD_CLIENT_VERBOSE) {
debug = verbose = true;
} else if (level == AutofillManager.FLAG_ADD_CLIENT_DEBUG) {
debug = true;
}
synchronized (mLock) {
setDebugLocked(debug);
setVerboseLocked(verbose);
}
}
// Called by Shell command.
int getLogLevel() {
synchronized (mLock) {
if (sVerbose) return AutofillManager.FLAG_ADD_CLIENT_VERBOSE;
if (sDebug) return AutofillManager.FLAG_ADD_CLIENT_DEBUG;
return 0;
}
}
private void setDebugLocked(boolean debug) {
com.android.server.autofill.Helper.sDebug = debug;
android.view.autofill.Helper.sDebug = debug;
}
private void setVerboseLocked(boolean verbose) {
com.android.server.autofill.Helper.sVerbose = verbose;
android.view.autofill.Helper.sVerbose = verbose;
}
/**
* Removes a cached service for a given user.
*/
@@ -399,24 +434,21 @@ public final class AutofillManagerService extends SystemService {
}
}
private IBinder getTopActivityForUser() {
final List<IBinder> topActivities = LocalServices
.getService(ActivityManagerInternal.class).getTopVisibleActivities();
if (VERBOSE) {
Slog.v(TAG, "Top activities (" + topActivities.size() + "): " + topActivities);
}
if (topActivities.isEmpty()) {
Slog.w(TAG, "Could not get top activity");
return null;
}
return topActivities.get(0);
}
final class AutoFillManagerServiceStub extends IAutoFillManager.Stub {
@Override
public boolean addClient(IAutoFillManagerClient client, int userId) {
public int addClient(IAutoFillManagerClient client, int userId) {
synchronized (mLock) {
return getServiceForUserLocked(userId).addClientLocked(client);
int flags = 0;
if (getServiceForUserLocked(userId).addClientLocked(client)) {
flags |= AutofillManager.FLAG_ADD_CLIENT_ENABLED;
}
if (sDebug) {
flags |= AutofillManager.FLAG_ADD_CLIENT_DEBUG;
}
if (sVerbose) {
flags |= AutofillManager.FLAG_ADD_CLIENT_VERBOSE;
}
return flags;
}
}
@@ -568,24 +600,38 @@ public final class AutofillManagerService extends SystemService {
@Override
public void dump(FileDescriptor fd, PrintWriter pw, String[] args) {
if (!DumpUtils.checkDumpPermission(mContext, TAG, pw)) return;
synchronized (mLock) {
pw.print("Disabled users: "); pw.println(mDisabledUsers);
final int size = mServicesCache.size();
pw.print("Cached services: ");
if (size == 0) {
pw.println("none");
} else {
pw.println(size);
for (int i = 0; i < size; i++) {
pw.print("\nService at index "); pw.println(i);
final AutofillManagerServiceImpl impl = mServicesCache.valueAt(i);
impl.dumpLocked(" ", pw);
boolean oldDebug = sDebug;
boolean oldVerbose = sVerbose;
try {
synchronized (mLock) {
oldDebug = sDebug;
oldVerbose = sVerbose;
setDebugLocked(true);
setVerboseLocked(true);
pw.print("Debug mode: "); pw.println(oldDebug);
pw.print("Verbose mode: "); pw.println(oldVerbose);
pw.print("Disabled users: "); pw.println(mDisabledUsers);
final int size = mServicesCache.size();
pw.print("Cached services: ");
if (size == 0) {
pw.println("none");
} else {
pw.println(size);
for (int i = 0; i < size; i++) {
pw.print("\nService at index "); pw.println(i);
final AutofillManagerServiceImpl impl = mServicesCache.valueAt(i);
impl.dumpLocked(" ", pw);
}
}
mUi.dump(pw);
}
mUi.dump(pw);
pw.println("Requests history:");
mRequestsHistory.reverseDump(fd, pw, args);
} finally {
setDebugLocked(oldDebug);
setVerboseLocked(oldVerbose);
}
pw.println("Requests history:");
mRequestsHistory.reverseDump(fd, pw, args);
}
@Override

View File

@@ -19,8 +19,7 @@ package com.android.server.autofill;
import static android.view.autofill.AutofillManager.ACTION_START_SESSION;
import static android.view.autofill.AutofillManager.NO_SESSION;
import static com.android.server.autofill.Helper.DEBUG;
import static com.android.server.autofill.Helper.VERBOSE;
import static com.android.server.autofill.Helper.sVerbose;
import android.annotation.NonNull;
import android.annotation.Nullable;
@@ -48,12 +47,9 @@ import android.service.autofill.FillResponse;
import android.service.autofill.IAutoFillService;
import android.text.TextUtils;
import android.util.LocalLog;
import android.util.Log;
import android.util.PrintWriterPrinter;
import android.util.Slog;
import android.util.SparseArray;
import android.view.autofill.AutofillId;
import android.view.autofill.AutofillManager;
import android.view.autofill.AutofillValue;
import android.view.autofill.IAutoFillManagerClient;
@@ -288,14 +284,15 @@ final class AutofillManagerServiceImpl {
final Session session = mSessions.get(sessionId);
if (session == null || uid != session.uid) {
Slog.w(TAG, "finishSessionLocked(): no session for " + sessionId + "(" + uid + ")");
if (sVerbose) {
Slog.v(TAG, "finishSessionLocked(): no session for " + sessionId + "(" + uid + ")");
}
return;
}
final boolean finished = session.showSaveLocked();
if (DEBUG) {
Log.d(TAG, "finishSessionLocked(): session finished on save? " + finished);
}
if (sVerbose) Slog.v(TAG, "finishSessionLocked(): session finished on save? " + finished);
if (finished) {
session.removeSelfLocked();
}
@@ -342,7 +339,7 @@ final class AutofillManagerServiceImpl {
do {
tries++;
if (tries > MAX_SESSION_ID_CREATE_TRIES) {
Log.w(TAG, "Cannot create session in " + MAX_SESSION_ID_CREATE_TRIES + " tries");
Slog.w(TAG, "Cannot create session in " + MAX_SESSION_ID_CREATE_TRIES + " tries");
return null;
}
@@ -399,7 +396,7 @@ final class AutofillManagerServiceImpl {
AutofillValue value, int action, int flags) {
final Session session = mSessions.get(sessionId);
if (session == null || session.uid != uid) {
if (VERBOSE) {
if (sVerbose) {
Slog.v(TAG, "updateSessionLocked(): session gone for " + sessionId + "(" + uid
+ ")");
}
@@ -426,9 +423,7 @@ final class AutofillManagerServiceImpl {
}
void destroyLocked() {
if (VERBOSE) {
Slog.v(TAG, "destroyLocked()");
}
if (sVerbose) Slog.v(TAG, "destroyLocked()");
final int numSessions = mSessions.size();
for (int i = 0; i < numSessions; i++) {
@@ -519,12 +514,6 @@ final class AutofillManagerServiceImpl {
pw.println(mContext.getString(R.string.config_defaultAutofillService));
pw.print(prefix); pw.print("Disabled: "); pw.println(mDisabled);
if (VERBOSE && mInfo != null) {
// ServiceInfo dump is too noisy and redundant (it can be obtained through other dumps)
pw.print(prefix); pw.println("ServiceInfo:");
mInfo.getServiceInfo().dump(new PrintWriterPrinter(pw), prefix + prefix);
}
final int size = mSessions.size();
if (size == 0) {
pw.print(prefix); pw.println("No sessions");

View File

@@ -18,10 +18,10 @@ package com.android.server.autofill;
import static com.android.server.autofill.AutofillManagerService.RECEIVER_BUNDLE_EXTRA_SESSIONS;
import android.app.ActivityManager;
import android.os.Bundle;
import android.os.ShellCommand;
import android.os.UserHandle;
import android.view.autofill.AutofillManager;
import com.android.internal.os.IResultReceiver;
@@ -51,6 +51,10 @@ public final class AutofillManagerServiceShellCommand extends ShellCommand {
return requestDestroy(pw);
case "reset":
return requestReset();
case "get":
return requestGet(pw);
case "set":
return requestSet(pw);
default:
return handleDefaultCommands(cmd);
}
@@ -63,6 +67,12 @@ public final class AutofillManagerServiceShellCommand extends ShellCommand {
pw.println(" help");
pw.println(" Prints this help text.");
pw.println("");
pw.println(" get log_level ");
pw.println(" Gets the Autofill log level (off | debug | verbose).");
pw.println("");
pw.println(" set log_level [off | debug | verbose]");
pw.println(" Sets the Autofill log level.");
pw.println("");
pw.println(" list sessions [--user USER_ID]");
pw.println(" List all pending sessions.");
pw.println("");
@@ -75,6 +85,48 @@ public final class AutofillManagerServiceShellCommand extends ShellCommand {
}
}
private int requestGet(PrintWriter pw) {
if (!isNextArgLogLevel(pw, "get")) {
return -1;
}
final int logLevel = mService.getLogLevel();
switch (logLevel) {
case AutofillManager.FLAG_ADD_CLIENT_VERBOSE:
pw.println("verbose");
return 0;
case AutofillManager.FLAG_ADD_CLIENT_DEBUG:
pw.println("debug");
return 0;
case 0:
pw.println("off");
return 0;
default:
pw.println("unknow (" + logLevel + ")");
return 0;
}
}
private int requestSet(PrintWriter pw) {
if (!isNextArgLogLevel(pw, "set")) {
return -1;
}
final String logLevel = getNextArg();
switch (logLevel.toLowerCase()) {
case "verbose":
mService.setLogLevel(AutofillManager.FLAG_ADD_CLIENT_VERBOSE);
return 0;
case "debug":
mService.setLogLevel(AutofillManager.FLAG_ADD_CLIENT_DEBUG);
return 0;
case "off":
mService.setLogLevel(0);
return 0;
default:
pw.println("Invalid level: " + logLevel);
return -1;
}
}
private int requestDestroy(PrintWriter pw) {
if (!isNextArgSessions(pw)) {
return -1;
@@ -121,6 +173,15 @@ public final class AutofillManagerServiceShellCommand extends ShellCommand {
return true;
}
private boolean isNextArgLogLevel(PrintWriter pw, String cmd) {
final String type = getNextArgRequired();
if (!type.equals("log_level")) {
pw.println("Error: invalid " + cmd + " type: " + type);
return false;
}
return true;
}
private int requestSessionCommon(PrintWriter pw, CountDownLatch latch,
Runnable command) {
command.run();
@@ -144,13 +205,6 @@ public final class AutofillManagerServiceShellCommand extends ShellCommand {
return 0;
}
private int getUserIdFromArgsOrCurrentUser() {
if ("--user".equals(getNextArg())) {
return UserHandle.parseUserArg(getNextArgRequired());
}
return ActivityManager.getCurrentUser();
}
private int getUserIdFromArgsOrAllUsers() {
if ("--user".equals(getNextArg())) {
return UserHandle.parseUserArg(getNextArgRequired());

View File

@@ -17,7 +17,6 @@
package com.android.server.autofill;
import android.annotation.NonNull;
import android.annotation.Nullable;
import android.app.assist.AssistStructure;
import android.app.assist.AssistStructure.ViewNode;
import android.os.Bundle;
@@ -27,14 +26,22 @@ import java.util.Arrays;
import java.util.Objects;
import java.util.Set;
final class Helper {
public final class Helper {
// TODO(b/36141126): set to false and remove guard from places that should always be on
static final boolean DEBUG = true;
static final boolean VERBOSE = false;
/**
* Defines a logging flag that can be dynamically changed at runtime using
* {@code cmd autofill debug [on|off]}.
*/
public static boolean sDebug = false;
/**
* Defines a logging flag that can be dynamically changed at runtime using
* {@code cmd autofill verbose [on|off]}.
*/
public static boolean sVerbose = false;
static void append(StringBuilder builder, Bundle bundle) {
if (bundle == null || !DEBUG) {
if (bundle == null || !sVerbose) {
builder.append("null");
return;
}

View File

@@ -18,7 +18,8 @@ package com.android.server.autofill;
import static android.service.autofill.FillRequest.INVALID_REQUEST_ID;
import static com.android.server.autofill.Helper.DEBUG;
import static com.android.server.autofill.Helper.sDebug;
import static com.android.server.autofill.Helper.sVerbose;
import android.annotation.NonNull;
import android.annotation.Nullable;
@@ -219,9 +220,7 @@ final class RemoteFillService implements DeathRecipient {
mPendingRequest = pendingRequest;
ensureBound();
} else {
if (DEBUG) {
Slog.d(LOG_TAG, "[user: " + mUserId + "] handlePendingRequest()");
}
if (sVerbose) Slog.v(LOG_TAG, "[user: " + mUserId + "] handlePendingRequest()");
pendingRequest.run();
if (pendingRequest.isFinal()) {
mCompleted = true;
@@ -237,9 +236,7 @@ final class RemoteFillService implements DeathRecipient {
if (isBound() || mBinding) {
return;
}
if (DEBUG) {
Slog.d(LOG_TAG, "[user: " + mUserId + "] ensureBound()");
}
if (sVerbose) Slog.v(LOG_TAG, "[user: " + mUserId + "] ensureBound()");
mBinding = true;
boolean willBind = mContext.bindServiceAsUser(mIntent, mServiceConnection,
@@ -247,9 +244,7 @@ final class RemoteFillService implements DeathRecipient {
new UserHandle(mUserId));
if (!willBind) {
if (DEBUG) {
Slog.d(LOG_TAG, "[user: " + mUserId + "] could not bind to " + mIntent);
}
if (sDebug) Slog.d(LOG_TAG, "[user: " + mUserId + "] could not bind to " + mIntent);
mBinding = false;
if (!mServiceDied) {
@@ -262,9 +257,7 @@ final class RemoteFillService implements DeathRecipient {
if (!isBound() && !mBinding) {
return;
}
if (DEBUG) {
Slog.d(LOG_TAG, "[user: " + mUserId + "] ensureUnbound()");
}
if (sVerbose) Slog.v(LOG_TAG, "[user: " + mUserId + "] ensureUnbound()");
mBinding = false;
if (isBound()) {
try {

View File

@@ -25,8 +25,8 @@ import static android.view.autofill.AutofillManager.ACTION_VALUE_CHANGED;
import static android.view.autofill.AutofillManager.ACTION_VIEW_ENTERED;
import static android.view.autofill.AutofillManager.ACTION_VIEW_EXITED;
import static com.android.server.autofill.Helper.DEBUG;
import static com.android.server.autofill.Helper.VERBOSE;
import static com.android.server.autofill.Helper.sDebug;
import static com.android.server.autofill.Helper.sVerbose;
import static com.android.server.autofill.Helper.findViewNodeById;
import android.annotation.NonNull;
@@ -193,8 +193,8 @@ final class Session implements RemoteFillService.FillServiceCallbacks, ViewState
final int requestId = receiverExtras.getInt(EXTRA_REQUEST_ID);
if (DEBUG) {
Slog.d(TAG, "New structure for requestId " + requestId + ": " + structure);
if (sVerbose) {
Slog.v(TAG, "New structure for requestId " + requestId + ": " + structure);
}
final FillRequest request;
@@ -245,9 +245,7 @@ final class Session implements RemoteFillService.FillServiceCallbacks, ViewState
final ViewNode node = findViewNodeById(structure, viewState.id);
if (node == null) {
if (DEBUG) {
Slog.w(TAG, "fillStructureWithAllowedValues(): no node for " + viewState.id);
}
Slog.w(TAG, "fillStructureWithAllowedValues(): no node for " + viewState.id);
continue;
}
@@ -296,8 +294,8 @@ final class Session implements RemoteFillService.FillServiceCallbacks, ViewState
requestId = sIdCounter.getAndIncrement();
} while (requestId == INVALID_REQUEST_ID);
if (DEBUG) {
Slog.d(TAG, "Requesting structure for requestId=" + requestId + ", flags=" + flags);
if (sVerbose) {
Slog.v(TAG, "Requesting structure for requestId=" + requestId + ", flags=" + flags);
}
// If the focus changes very quickly before the first request is returned each focus change
@@ -613,7 +611,7 @@ final class Session implements RemoteFillService.FillServiceCallbacks, ViewState
Slog.e(TAG, "Error requesting to show fill UI", e);
}
} else {
if (DEBUG) {
if (sDebug) {
Slog.d(TAG, "Do not show full UI on " + id + " as it is not the current view ("
+ mCurrentViewId + ") anymore");
}
@@ -724,23 +722,23 @@ final class Session implements RemoteFillService.FillServiceCallbacks, ViewState
if (mResponses == null) {
// Happens when the activity / session was finished before the service replied, or
// when the service cannot autofill it (and returned a null response).
if (DEBUG) {
Slog.d(TAG, "showSaveLocked(): no responses on session");
if (sVerbose) {
Slog.v(TAG, "showSaveLocked(): no responses on session");
}
return true;
}
final int lastResponseIdx = getLastResponseIndex();
if (lastResponseIdx < 0) {
Slog.d(TAG, "showSaveLocked(): mResponses=" + mResponses
Slog.w(TAG, "showSaveLocked(): did not get last response. mResponses=" + mResponses
+ ", mViewStates=" + mViewStates);
return true;
}
final FillResponse response = mResponses.valueAt(lastResponseIdx);
final SaveInfo saveInfo = response.getSaveInfo();
if (DEBUG) {
Slog.d(TAG, "showSaveLocked(): mResponses=" + mResponses + ", mContexts=" + mContexts
if (sVerbose) {
Slog.v(TAG, "showSaveLocked(): mResponses=" + mResponses + ", mContexts=" + mContexts
+ ", mViewStates=" + mViewStates);
}
@@ -775,7 +773,7 @@ final class Session implements RemoteFillService.FillServiceCallbacks, ViewState
final AutofillValue currentValue = viewState.getCurrentValue();
if (currentValue == null || currentValue.isEmpty()) {
if (DEBUG) {
if (sDebug) {
Slog.d(TAG, "showSaveLocked(): empty value for required " + id );
}
allRequiredAreNotEmpty = false;
@@ -784,7 +782,7 @@ final class Session implements RemoteFillService.FillServiceCallbacks, ViewState
final AutofillValue filledValue = viewState.getAutofilledValue();
if (!currentValue.equals(filledValue)) {
if (DEBUG) {
if (sDebug) {
Slog.d(TAG, "showSaveLocked(): found a change on required " + id + ": "
+ filledValue + " => " + currentValue);
}
@@ -807,7 +805,7 @@ final class Session implements RemoteFillService.FillServiceCallbacks, ViewState
final AutofillValue currentValue = viewState.getCurrentValue();
final AutofillValue filledValue = viewState.getAutofilledValue();
if (currentValue != null && !currentValue.equals(filledValue)) {
if (DEBUG) {
if (sDebug) {
Slog.d(TAG, "finishSessionLocked(): found a change on optional "
+ id + ": " + filledValue + " => " + currentValue);
}
@@ -824,7 +822,7 @@ final class Session implements RemoteFillService.FillServiceCallbacks, ViewState
}
}
// Nothing changed...
if (DEBUG) {
if (sDebug) {
Slog.d(TAG, "showSaveLocked(): with no changes, comes no responsibilities."
+ "allRequiredAreNotNull=" + allRequiredAreNotEmpty
+ ", atLeastOneChanged=" + atLeastOneChanged);
@@ -842,25 +840,19 @@ final class Session implements RemoteFillService.FillServiceCallbacks, ViewState
return;
}
if (DEBUG) {
Slog.d(TAG, "callSaveLocked(): mViewStates=" + mViewStates);
}
if (sVerbose) Slog.v(TAG, "callSaveLocked(): mViewStates=" + mViewStates);
int numContexts = mContexts.size();
final int numContexts = mContexts.size();
for (int i = 0; i < numContexts; i++) {
FillContext context = mContexts.get(i);
final FillContext context = mContexts.get(i);
if (VERBOSE) {
Slog.v(TAG, "callSaveLocked(): updating " + context);
}
if (sVerbose) Slog.v(TAG, "callSaveLocked(): updating " + context);
for (Entry<AutofillId, ViewState> entry : mViewStates.entrySet()) {
final AutofillValue value = entry.getValue().getCurrentValue();
if (value == null) {
if (VERBOSE) {
Slog.v(TAG, "callSaveLocked(): skipping " + entry.getKey());
}
if (sVerbose) Slog.v(TAG, "callSaveLocked(): skipping " + entry.getKey());
continue;
}
final AutofillId id = entry.getKey();
@@ -869,9 +861,7 @@ final class Session implements RemoteFillService.FillServiceCallbacks, ViewState
Slog.w(TAG, "callSaveLocked(): did not find node with id " + id);
continue;
}
if (VERBOSE) {
Slog.v(TAG, "callSaveLocked(): updating " + id + " to " + value);
}
if (sVerbose) Slog.v(TAG, "callSaveLocked(): updating " + id + " to " + value);
node.updateAutofillValue(value);
}
@@ -879,7 +869,7 @@ final class Session implements RemoteFillService.FillServiceCallbacks, ViewState
// Sanitize structure before it's sent to service.
context.getStructure().sanitizeForParceling(false);
if (VERBOSE) {
if (sVerbose) {
Slog.v(TAG, "Dumping structure of " + context + " before calling service.save()");
context.getStructure().dump();
}
@@ -949,14 +939,14 @@ final class Session implements RemoteFillService.FillServiceCallbacks, ViewState
if (viewState == null) {
if (action == ACTION_START_SESSION || action == ACTION_VALUE_CHANGED
|| action == ACTION_VIEW_ENTERED) {
if (DEBUG) {
Slog.d(TAG,
if (sVerbose) {
Slog.v(TAG,
"Creating viewState for " + id + " on " + getActionAsString(action));
}
viewState = new ViewState(this, id, value, this, ViewState.STATE_INITIAL);
mViewStates.put(id, viewState);
} else {
if (VERBOSE) Slog.v(TAG, "Ignored " + getActionAsString(action) + " for " + id);
if (sVerbose) Slog.v(TAG, "Ignored " + getActionAsString(action) + " for " + id);
return;
}
}
@@ -997,7 +987,7 @@ final class Session implements RemoteFillService.FillServiceCallbacks, ViewState
if (mResponseWaitingAuth != null) {
viewState.setState(ViewState.STATE_WAITING_RESPONSE_AUTH);
} else {
if (DEBUG) {
if (sDebug) {
Slog.d(TAG, "Starting partition for view id " + viewState.id);
}
viewState.setState(ViewState.STATE_STARTED_PARTITION);
@@ -1106,8 +1096,8 @@ final class Session implements RemoteFillService.FillServiceCallbacks, ViewState
}
private void processResponseLocked(@NonNull FillResponse response) {
if (DEBUG) {
Slog.d(TAG, "processResponseLocked(mCurrentViewId=" + mCurrentViewId + "):" + response);
if (sVerbose) {
Slog.v(TAG, "processResponseLocked(mCurrentViewId=" + mCurrentViewId + "):" + response);
}
if (mResponses == null) {
@@ -1196,8 +1186,8 @@ final class Session implements RemoteFillService.FillServiceCallbacks, ViewState
viewState.setState(state);
} else {
viewState = new ViewState(this, id, null, this, state);
if (DEBUG) { // TODO(b/33197203): change to VERBOSE once stable
Slog.d(TAG, "Adding autofillable view with id " + id + " and state " + state);
if (sVerbose) {
Slog.v(TAG, "Adding autofillable view with id " + id + " and state " + state);
}
mViewStates.put(id, viewState);
}
@@ -1301,7 +1291,7 @@ final class Session implements RemoteFillService.FillServiceCallbacks, ViewState
FillContext context = mContexts.get(i);
pw.print(prefix2); pw.print(context);
if (VERBOSE) {
if (sVerbose) {
pw.println(context.getStructure() + " (look at logcat)");
// TODO: add method on AssistStructure to dump on pw
@@ -1326,9 +1316,7 @@ final class Session implements RemoteFillService.FillServiceCallbacks, ViewState
return;
}
try {
if (DEBUG) {
Slog.d(TAG, "autoFillApp(): the buck is on the app: " + dataset);
}
if (sDebug) Slog.d(TAG, "autoFillApp(): the buck is on the app: " + dataset);
mClient.autofill(id, mWindowToken, dataset.getFieldIds(),
dataset.getFieldValues());
setViewStatesLocked(null, dataset, ViewState.STATE_AUTOFILLED);
@@ -1363,9 +1351,7 @@ final class Session implements RemoteFillService.FillServiceCallbacks, ViewState
}
void removeSelfLocked() {
if (VERBOSE) {
Slog.v(TAG, "removeSelfLocked()");
}
if (sVerbose) Slog.v(TAG, "removeSelfLocked()");
if (mDestroyed) {
Slog.w(TAG, "Call to Session#removeSelfLocked() rejected - session: "
+ id + " destroyed");

View File

@@ -16,7 +16,7 @@
package com.android.server.autofill;
import static com.android.server.autofill.Helper.DEBUG;
import static com.android.server.autofill.Helper.sDebug;
import android.annotation.Nullable;
import android.graphics.Rect;
@@ -172,9 +172,7 @@ final class ViewState {
*/
void maybeCallOnFillReady() {
if ((mState & (STATE_AUTOFILLED | STATE_WAITING_DATASET_AUTH)) != 0) {
if (DEBUG) {
Slog.d(TAG, "Ignoring UI for " + id + " on " + getStateAsString());
}
if (sDebug) Slog.d(TAG, "Ignoring UI for " + id + " on " + getStateAsString());
return;
}
// First try the current response associated with this View.

View File

@@ -15,7 +15,7 @@
*/
package com.android.server.autofill.ui;
import static com.android.server.autofill.ui.Helper.DEBUG;
import static com.android.server.autofill.Helper.sDebug;
import android.annotation.NonNull;
import android.annotation.Nullable;
@@ -47,7 +47,7 @@ import java.io.PrintWriter;
* managing saving of user edits.
*/
public final class AutoFillUI {
private static final String TAG = "AutoFillUI";
private static final String TAG = "AutofillUI";
private final Handler mHandler = UiThread.getHandler();
private final @NonNull Context mContext;
@@ -139,7 +139,7 @@ public final class AutoFillUI {
*/
public void showFillUi(@NonNull AutofillId focusedId, @NonNull FillResponse response,
@Nullable String filterText, @NonNull String packageName) {
if (DEBUG) {
if (sDebug) {
Slog.d(TAG, "showFillUi(): id=" + focusedId + ", filter=" + filterText);
}
final LogMaker log = (new LogMaker(MetricsProto.MetricsEvent.AUTOFILL_FILL_UI))

View File

@@ -15,6 +15,8 @@
*/
package com.android.server.autofill.ui;
import static com.android.server.autofill.Helper.sDebug;
import android.annotation.NonNull;
import android.annotation.Nullable;
import android.app.PendingIntent;
@@ -341,7 +343,7 @@ final class FillUi {
mWm.updateViewLayout(mContentView, params);
}
} catch (WindowManager.BadTokenException e) {
Slog.i(TAG, "Filed with with token " + params.token + " gone.");
if (sDebug) Slog.d(TAG, "Filed with with token " + params.token + " gone.");
mCallback.onDestroy();
}
}

View File

@@ -1,26 +0,0 @@
/*
* Copyright (C) 2017 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 com.android.server.autofill.ui;
final class Helper {
static final boolean DEBUG = true; // TODO(b/33197203): set to false when stable
static final boolean VERBOSE = false;
private Helper() {
throw new UnsupportedOperationException("contains static members only");
}
}

View File

@@ -16,7 +16,7 @@
package com.android.server.autofill.ui;
import static com.android.server.autofill.ui.Helper.DEBUG;
import static com.android.server.autofill.Helper.sDebug;
import android.annotation.NonNull;
import android.app.Dialog;
@@ -42,7 +42,7 @@ import com.android.server.UiThread;
*/
final class SaveUi {
private static final String TAG = "SaveUi";
private static final String TAG = "AutofillSaveUi";
public interface OnSaveListener {
void onSave();
@@ -61,7 +61,7 @@ final class SaveUi {
@Override
public void onSave() {
if (DEBUG) Slog.d(TAG, "onSave(): " + mDone);
if (sDebug) Slog.d(TAG, "onSave(): " + mDone);
if (mDone) {
return;
}
@@ -71,7 +71,7 @@ final class SaveUi {
@Override
public void onCancel(IntentSender listener) {
if (DEBUG) Slog.d(TAG, "onCancel(): " + mDone);
if (sDebug) Slog.d(TAG, "onCancel(): " + mDone);
if (mDone) {
return;
}
@@ -81,7 +81,7 @@ final class SaveUi {
@Override
public void onDestroy() {
if (DEBUG) Slog.d(TAG, "onDestroy(): " + mDone);
if (sDebug) Slog.d(TAG, "onDestroy(): " + mDone);
if (mDone) {
return;
}
@@ -154,8 +154,9 @@ final class SaveUi {
subTitleView.setVisibility(View.VISIBLE);
}
if (DEBUG) {
Slog.d(TAG, "Title: " + title + " SubTitle: " + subTitle);
Slog.i(TAG, "Showing save dialog: " + title);
if (sDebug) {
Slog.d(TAG, "SubTitle: " + subTitle);
}
final TextView noButton = view.findViewById(R.id.autofill_save_no);