Merge "Improved autofill logging and dumping." into pi-dev

This commit is contained in:
Felipe Leme
2018-03-23 05:48:26 +00:00
committed by Android (Google) Code Review
8 changed files with 192 additions and 78 deletions

View File

@@ -149,24 +149,33 @@ public final class Dataset implements Parcelable {
public String toString() {
if (!sDebug) return super.toString();
final StringBuilder builder = new StringBuilder("Dataset[id=");
final StringBuilder builder = new StringBuilder("Dataset[");
if (mId == null) {
builder.append("null");
builder.append("noId");
} else {
// Cannot disclose id because it could contain PII.
builder.append(mId.length()).append("_chars");
builder.append("id=").append(mId.length()).append("_chars");
}
if (mFieldIds != null) {
builder.append(", fieldIds=").append(mFieldIds);
}
if (mFieldValues != null) {
builder.append(", fieldValues=").append(mFieldValues);
}
if (mFieldPresentations != null) {
builder.append(", fieldPresentations=").append(mFieldPresentations.size());
return builder
.append(", fieldIds=").append(mFieldIds)
.append(", fieldValues=").append(mFieldValues)
.append(", fieldPresentations=")
.append(mFieldPresentations == null ? 0 : mFieldPresentations.size())
.append(", fieldFilters=")
.append(mFieldFilters == null ? 0 : mFieldFilters.size())
.append(", hasPresentation=").append(mPresentation != null)
.append(", hasAuthentication=").append(mAuthentication != null)
.append(']').toString();
}
if (mFieldFilters != null) {
builder.append(", fieldFilters=").append(mFieldFilters.size());
}
if (mPresentation != null) {
builder.append(", hasPresentation");
}
if (mAuthentication != null) {
builder.append(", hasAuthentication");
}
return builder.append(']').toString();
}
/**

View File

@@ -557,23 +557,40 @@ public final class FillResponse implements Parcelable {
if (!sDebug) return super.toString();
// TODO: create a dump() method instead
return new StringBuilder(
"FillResponse : [mRequestId=" + mRequestId)
.append(", datasets=").append(mDatasets == null ? "N/A" : mDatasets.getList())
.append(", saveInfo=").append(mSaveInfo)
.append(", clientState=").append(mClientState != null)
.append(", hasPresentation=").append(mPresentation != null)
.append(", hasHeader=").append(mHeader != null)
.append(", hasFooter=").append(mFooter != null)
.append(", hasAuthentication=").append(mAuthentication != null)
.append(", authenticationIds=").append(Arrays.toString(mAuthenticationIds))
.append(", ignoredIds=").append(Arrays.toString(mIgnoredIds))
.append(", disableDuration=").append(mDisableDuration)
.append(", flags=").append(mFlags)
.append(", fieldClassificationIds=")
.append(Arrays.toString(mFieldClassificationIds))
.append("]")
.toString();
final StringBuilder builder = new StringBuilder(
"FillResponse : [mRequestId=" + mRequestId);
if (mDatasets != null) {
builder.append(", datasets=").append(mDatasets.getList());
}
if (mSaveInfo != null) {
builder.append(", saveInfo=").append(mSaveInfo);
}
if (mClientState != null) {
builder.append(", hasClientState");
}
if (mPresentation != null) {
builder.append(", hasPresentation");
}
if (mHeader != null) {
builder.append(", hasHeader");
}
if (mFooter != null) {
builder.append(", hasFooter");
}
if (mAuthentication != null) {
builder.append(", hasAuthentication");
}
if (mAuthenticationIds != null) {
builder.append(", authenticationIds=").append(Arrays.toString(mAuthenticationIds));
}
builder.append(", disableDuration=").append(mDisableDuration);
if (mFlags != 0) {
builder.append(", flags=").append(mFlags);
}
if (mFieldClassificationIds != null) {
builder.append(Arrays.toString(mFieldClassificationIds));
}
return builder.append("]").toString();
}
/////////////////////////////////////

View File

@@ -689,22 +689,37 @@ public final class SaveInfo implements Parcelable {
public String toString() {
if (!sDebug) return super.toString();
return new StringBuilder("SaveInfo: [type=")
final StringBuilder builder = new StringBuilder("SaveInfo: [type=")
.append(DebugUtils.flagsToString(SaveInfo.class, "SAVE_DATA_TYPE_", mType))
.append(", requiredIds=").append(Arrays.toString(mRequiredIds))
.append(", optionalIds=").append(Arrays.toString(mOptionalIds))
.append(", description=").append(mDescription)
.append(DebugUtils.flagsToString(SaveInfo.class, "NEGATIVE_BUTTON_STYLE_",
mNegativeButtonStyle))
.append(", flags=").append(mFlags)
.append(", customDescription=").append(mCustomDescription)
.append(", validator=").append(mValidator)
.append(", sanitizerKeys=")
.append(mSanitizerKeys == null ? "N/A:" : mSanitizerKeys.length)
.append(", sanitizerValues=")
.append(mSanitizerValues == null ? "N/A:" : mSanitizerValues.length)
.append(", triggerId=").append(mTriggerId)
.append("]").toString();
.append(", style=").append(DebugUtils.flagsToString(SaveInfo.class,
"NEGATIVE_BUTTON_STYLE_", mNegativeButtonStyle));
if (mOptionalIds != null) {
builder.append(", optionalIds=").append(Arrays.toString(mOptionalIds));
}
if (mDescription != null) {
builder.append(", description=").append(mDescription);
}
if (mFlags != 0) {
builder.append(", flags=").append(mFlags);
}
if (mCustomDescription != null) {
builder.append(", customDescription=").append(mCustomDescription);
}
if (mValidator != null) {
builder.append(", validator=").append(mValidator);
}
if (mSanitizerKeys != null) {
builder.append(", sanitizerKeys=").append(mSanitizerKeys.length);
}
if (mSanitizerValues != null) {
builder.append(", sanitizerValues=").append(mSanitizerValues.length);
}
if (mTriggerId != null) {
builder.append(", triggerId=").append(mTriggerId);
}
return builder.append("]").toString();
}
/////////////////////////////////////

View File

@@ -2882,9 +2882,8 @@ public interface WindowManager extends ViewManager {
/**
* @hide
*/
public String toString(String prefix) {
StringBuilder sb = new StringBuilder(256);
sb.append("{(");
public void dumpDimensions(StringBuilder sb) {
sb.append('(');
sb.append(x);
sb.append(',');
sb.append(y);
@@ -2895,6 +2894,15 @@ public interface WindowManager extends ViewManager {
sb.append((height == MATCH_PARENT ? "fill" : (height == WRAP_CONTENT
? "wrap" : String.valueOf(height))));
sb.append(")");
}
/**
* @hide
*/
public String toString(String prefix) {
StringBuilder sb = new StringBuilder(256);
sb.append('{');
dumpDimensions(sb);
if (horizontalMargin != 0) {
sb.append(" hm=");
sb.append(horizontalMargin);

View File

@@ -80,6 +80,7 @@ import com.android.internal.util.Preconditions;
import com.android.server.FgThread;
import com.android.server.LocalServices;
import com.android.server.SystemService;
import com.android.server.autofill.AutofillManagerService.PackageCompatState;
import com.android.server.autofill.ui.AutoFillUI;
import java.io.FileDescriptor;
@@ -651,7 +652,7 @@ public final class AutofillManagerService extends SystemService {
/**
* Compatibility mode metadata per package.
*/
private static final class PackageCompatState {
static final class PackageCompatState {
private final long maxVersionCode;
private final String[] urlBarResourceIds;
@@ -662,8 +663,8 @@ public final class AutofillManagerService extends SystemService {
@Override
public String toString() {
return "PackageCompatState: [maxVersionCode=" + maxVersionCode
+ ", urlBarResourceIds=" + Arrays.toString(urlBarResourceIds) + "]";
return "maxVersionCode=" + maxVersionCode
+ ", urlBarResourceIds=" + Arrays.toString(urlBarResourceIds);
}
}
@@ -752,6 +753,25 @@ public final class AutofillManagerService extends SystemService {
}
}
}
private void dump(String prefix, PrintWriter pw) {
if (mUserSpecs == null) {
pw.println("N/A");
return;
}
pw.println();
final String prefix2 = prefix + " ";
for (int i = 0; i < mUserSpecs.size(); i++) {
final int user = mUserSpecs.keyAt(i);
pw.print(prefix); pw.print("User: "); pw.println(user);
final ArrayMap<String,PackageCompatState> perUser = mUserSpecs.get(i);
for (int j = 0; j < perUser.size(); j++) {
final String packageName = perUser.keyAt(j);
final PackageCompatState state = perUser.valueAt(j);
pw.print(prefix2); pw.print(packageName); pw.print(": "); pw.println(state);
}
}
}
}
final class AutoFillManagerServiceStub extends IAutoFillManager.Stub {
@@ -1117,6 +1137,7 @@ public final class AutofillManagerService extends SystemService {
boolean oldDebug = sDebug;
final String prefix = " ";
final String prefix2 = " ";
try {
synchronized (mLock) {
oldDebug = sDebug;
@@ -1141,8 +1162,8 @@ public final class AutofillManagerService extends SystemService {
}
mUi.dump(pw);
pw.print("Autofill Compat State: ");
pw.println(mAutofillCompatState.mUserSpecs);
pw.print(prefix); pw.print("from settings: ");
mAutofillCompatState.dump(prefix2, pw);
pw.print(prefix2); pw.print("from settings: ");
pw.println(getWhitelistedCompatModePackagesFromSettings());
}
if (showHistory) {

View File

@@ -26,6 +26,7 @@ import android.service.autofill.Dataset;
import android.util.ArrayMap;
import android.util.ArraySet;
import android.util.Slog;
import android.view.WindowManager;
import android.view.autofill.AutofillId;
import android.view.autofill.AutofillValue;
@@ -106,6 +107,13 @@ public final class Helper {
return array;
}
@NonNull
public static String paramsToString(@NonNull WindowManager.LayoutParams params) {
final StringBuilder builder = new StringBuilder(25);
params.dumpDimensions(builder);
return builder.toString();
}
@NonNull
static ArrayMap<AutofillId, AutofillValue> getFields(@NonNull Dataset dataset) {
final ArrayList<AutofillId> ids = dataset.getFieldIds();
@@ -128,7 +136,7 @@ public final class Helper {
return log;
}
public static void printlnRedactedText(@NonNull PrintWriter pw, @Nullable String text) {
public static void printlnRedactedText(@NonNull PrintWriter pw, @Nullable CharSequence text) {
if (text == null) {
pw.println("null");
} else {
@@ -173,6 +181,7 @@ public final class Helper {
* @param structure Assist structure
* @param urlBarIds list of ids; only the first id found will be sanitized.
*/
@Nullable
public static void sanitizeUrlBar(@NonNull AssistStructure structure,
@NonNull String[] urlBarIds) {
final ViewNode urlBarNode = findViewNode(structure, (node) -> {

View File

@@ -206,29 +206,51 @@ final class ViewState {
@Override
public String toString() {
return "ViewState: [id=" + id + ", datasetId=" + mDatasetId
+ ", currentValue=" + mCurrentValue
+ ", autofilledValue=" + mAutofilledValue
+ ", bounds=" + mVirtualBounds + ", state=" + getStateAsString() + "]";
final StringBuilder builder = new StringBuilder("ViewState: [id=").append(id);
if (mDatasetId != null) {
builder.append("datasetId:" ).append(mDatasetId);
}
builder.append("state:" ).append(getStateAsString());
if (mCurrentValue != null) {
builder.append("currentValue:" ).append(mCurrentValue);
}
if (mAutofilledValue != null) {
builder.append("autofilledValue:" ).append(mAutofilledValue);
}
if (mSanitizedValue != null) {
builder.append("sanitizedValue:" ).append(mSanitizedValue);
}
if (mVirtualBounds != null) {
builder.append("virtualBounds:" ).append(mVirtualBounds);
}
return builder.toString();
}
void dump(String prefix, PrintWriter pw) {
pw.print(prefix); pw.print("id:" ); pw.println(this.id);
pw.print(prefix); pw.print("datasetId:" ); pw.println(this.mDatasetId);
pw.print(prefix); pw.print("id:" ); pw.println(id);
if (mDatasetId != null) {
pw.print(prefix); pw.print("datasetId:" ); pw.println(mDatasetId);
}
pw.print(prefix); pw.print("state:" ); pw.println(getStateAsString());
pw.print(prefix); pw.print("response:");
if (mResponse == null) {
pw.println("N/A");
} else {
if (mResponse != null) {
pw.print(prefix); pw.print("response:");
if (sVerbose) {
pw.println(mResponse);
} else {
pw.println(mResponse.getRequestId());
pw.print("id=");pw.println(mResponse.getRequestId());
}
}
pw.print(prefix); pw.print("currentValue:" ); pw.println(mCurrentValue);
pw.print(prefix); pw.print("autofilledValue:" ); pw.println(mAutofilledValue);
pw.print(prefix); pw.print("sanitizedValue:" ); pw.println(mSanitizedValue);
pw.print(prefix); pw.print("virtualBounds:" ); pw.println(mVirtualBounds);
if (mCurrentValue != null) {
pw.print(prefix); pw.print("currentValue:" ); pw.println(mCurrentValue);
}
if (mAutofilledValue != null) {
pw.print(prefix); pw.print("autofilledValue:" ); pw.println(mAutofilledValue);
}
if (mSanitizedValue != null) {
pw.print(prefix); pw.print("sanitizedValue:" ); pw.println(mSanitizedValue);
}
if (mVirtualBounds != null) {
pw.print(prefix); pw.print("virtualBounds:" ); pw.println(mVirtualBounds);
}
}
}

View File

@@ -15,6 +15,7 @@
*/
package com.android.server.autofill.ui;
import static com.android.server.autofill.Helper.paramsToString;
import static com.android.server.autofill.Helper.sDebug;
import static com.android.server.autofill.Helper.sVerbose;
@@ -37,7 +38,6 @@ import android.util.Slog;
import android.util.TypedValue;
import android.view.KeyEvent;
import android.view.LayoutInflater;
import android.view.MotionEvent;
import android.view.View;
import android.view.View.MeasureSpec;
import android.view.ViewGroup;
@@ -568,12 +568,24 @@ final class FillUi {
@Override
public String toString() {
return "ViewItem: [dataset=" + (dataset == null ? "null" : dataset.getId())
+ ", value=" + (value == null ? "null" : value.length() + "_chars")
+ ", filterable=" + filterable
+ ", filter=" + (filter == null ? "null" : filter.pattern().length() + "_chars")
+ ", view=" + view.getAutofillId()
+ "]";
final StringBuilder builder = new StringBuilder("ViewItem:[view=")
.append(view.getAutofillId());
final String datasetId = dataset == null ? null : dataset.getId();
if (datasetId != null) {
builder.append(", dataset=").append(datasetId);
}
if (value != null) {
// Cannot print value because it could contain PII
builder.append(", value=").append(value.length()).append("_chars");
}
if (filterable) {
builder.append(", filterable");
}
if (filter != null) {
// Filter should not have PII, but it could be a huge regexp
builder.append(", filter=").append(filter.pattern().length()).append("_chars");
}
return builder.append(']').toString();
}
}
@@ -583,8 +595,7 @@ final class FillUi {
boolean fitsSystemWindows, int layoutDirection) {
if (sVerbose) {
Slog.v(TAG, "AutofillWindowPresenter.show(): fit=" + fitsSystemWindows
+ ", epicenter="+ transitionEpicenter + ", dir=" + layoutDirection
+ ", params=" + p);
+ ", params=" + paramsToString(p));
}
UiThread.getHandler().post(() -> mWindow.show(p));
}
@@ -616,7 +627,9 @@ final class FillUi {
* Shows the window.
*/
public void show(WindowManager.LayoutParams params) {
if (sVerbose) Slog.v(TAG, "show(): showing=" + mShowing + ", params="+ params);
if (sVerbose) {
Slog.v(TAG, "show(): showing=" + mShowing + ", params=" + paramsToString(params));
}
try {
// Okay here is a bit of voodoo - we want to show the window as system
// controlled one so it covers app windows - adjust the params accordingly.