Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 62969344 authored by Owen Lin's avatar Owen Lin
Browse files

Add maskDebugInfo to display info for debugging build only.

bug: 5335366

Change-Id: I5b6de536bb8e9439b61eb3778fbb1801c8e898c8
parent 338d029f
Loading
Loading
Loading
Loading
+15 −0
Original line number Diff line number Diff line
@@ -42,6 +42,11 @@ public class Utils {

    private static long[] sCrcTable = new long[256];

    private static final boolean IS_DEBUG_BUILD =
            Build.TYPE.equals("eng") || Build.TYPE.equals("userdebug");

    private static final String MASK_STRING = "********************************";

    // Throws AssertionError if the input is false.
    public static void assertTrue(boolean cond) {
        if (!cond) {
@@ -402,4 +407,14 @@ public class Utils {
            if (parcel != null) parcel.recycle();
        }
    }

    // Mask information for debugging only. It returns <code>info.toString()</code> directly
    // for debugging build (i.e., 'eng' and 'userdebug') and returns a mask ("****")
    // in release build to protect the information (e.g. for privacy issue).
    public static String maskDebugInfo(Object info) {
        if (info == null) return null;
        String s = info.toString();
        int length = Math.min(s.length(), MASK_STRING.length());
        return IS_DEBUG_BUILD ? s : MASK_STRING.substring(0, length);
    }
}