diff options
| author | TreeHugger Robot <treehugger-gerrit@google.com> | 2018-09-11 21:02:28 +0000 |
|---|---|---|
| committer | Android (Google) Code Review <android-gerrit@google.com> | 2018-09-11 21:02:28 +0000 |
| commit | 47c69efe8bf3fcf69ad19befcf09b4c8627a8c87 (patch) | |
| tree | f76cbf1abe6d4ce5f5fee6824038ef264498f5ff /core/java | |
| parent | 7f094f80d0abec0ee4c9532848241feaee4af3b6 (diff) | |
| parent | 139c2488d10da0b47cde3e6ffe881b110132fc83 (diff) | |
Merge "Obfuscate account name in account manager logs and dumpsys."
Diffstat (limited to 'core/java')
| -rw-r--r-- | core/java/android/accounts/Account.java | 37 |
1 files changed, 36 insertions, 1 deletions
diff --git a/core/java/android/accounts/Account.java b/core/java/android/accounts/Account.java index f07f5ece7bc1..d3b2238d8b69 100644 --- a/core/java/android/accounts/Account.java +++ b/core/java/android/accounts/Account.java @@ -20,13 +20,14 @@ import android.annotation.NonNull; import android.annotation.Nullable; import android.annotation.UnsupportedAppUsage; import android.content.Context; -import android.os.Parcelable; import android.os.Parcel; +import android.os.Parcelable; import android.os.RemoteException; import android.os.ServiceManager; import android.text.TextUtils; import android.util.ArraySet; import android.util.Log; + import com.android.internal.annotations.GuardedBy; import java.util.Set; @@ -45,6 +46,7 @@ public class Account implements Parcelable { public final String name; public final String type; + private String mSafeName; @UnsupportedAppUsage private final @Nullable String accessId; @@ -135,4 +137,37 @@ public class Account implements Parcelable { public String toString() { return "Account {name=" + name + ", type=" + type + "}"; } + + /** + * Return a string representation of the account that is safe to print + * to logs and other places where PII should be avoided. + * @hide + */ + public String toSafeString() { + if (mSafeName == null) { + mSafeName = toSafeName(name, 'x'); + } + return "Account {name=" + mSafeName + ", type=" + type + "}"; + } + + /** + * Given a name, replace all letter or digits with the replacement char. + * @param name The input name string. + * @param replacement the replacement character. + * @return the string after replacement. + * @hide + */ + public static String toSafeName(String name, char replacement) { + final StringBuilder builder = new StringBuilder(64); + final int len = name.length(); + for (int i = 0; i < len; i++) { + final char c = name.charAt(i); + if (Character.isLetterOrDigit(c)) { + builder.append(replacement); + } else { + builder.append(c); + } + } + return builder.toString(); + } } |
