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

Commit b88fd0fd authored by François Degros's avatar François Degros
Browse files

Add redact() method

Bug: 406088962
Flag: EXEMPT used in DEBUG log messages only
Test: Manual
Change-Id: I81d8dab07cd54eb3a3ed5f13210bd0e4d3730d7e
parent 75b050df
Loading
Loading
Loading
Loading
+2 −1
Original line number Diff line number Diff line
@@ -19,6 +19,7 @@ package com.android.documentsui;
import static android.content.ContentResolver.wrap;

import static com.android.documentsui.DocumentsApplication.acquireUnstableProviderOrThrow;
import static com.android.documentsui.base.SharedMinimal.redact;

import android.content.ContentProviderClient;
import android.content.Context;
@@ -640,7 +641,7 @@ public final class Metrics {
        try {
            return DocumentsContract.getRootId(uri);
        } catch (IllegalArgumentException iae) {
            Log.w(TAG, "Invalid root Uri " + uri.toSafeString());
            Log.w(TAG, "Invalid root Uri " + redact(uri));
        }
        return null;
    }
+3 −4
Original line number Diff line number Diff line
@@ -17,6 +17,7 @@
package com.android.documentsui.base;

import static com.android.documentsui.base.SharedMinimal.DEBUG;
import static com.android.documentsui.base.SharedMinimal.redact;
import static com.android.documentsui.util.FlagUtils.isZipNgFlagEnabled;

import android.content.ContentProviderClient;
@@ -446,10 +447,8 @@ public class DocumentInfo implements Durable, Parcelable {
            final String type = resolver.getType(uri);
            if (type != null) {
                mimeTypes.add(type);
            } else {
                if (DEBUG) {
                    Log.d(TAG, "resolver.getType(uri) return null, url:" + uri.toSafeString());
                }
            } else if (DEBUG) {
                Log.d(TAG, "resolver.getType(" + redact(uri) + ") returned null");
            }
            final String[] streamTypes = resolver.getStreamTypes(uri, "*/*");
            if (streamTypes != null) {
+17 −0
Original line number Diff line number Diff line
@@ -16,6 +16,7 @@

package com.android.documentsui.base;

import android.net.Uri;
import android.os.Build;
import android.util.Log;

@@ -36,4 +37,20 @@ public final class SharedMinimal {
    private SharedMinimal() {
        throw new UnsupportedOperationException("provides static fields only");
    }

    /**
     * Gets a redacted string representation of the given object. Can be used to redact file names,
     * file paths or URIs in log messages.
     */
    public static String redact(Object o) {
        if (o == null) return "(null)";

        if (DEBUG) {
            if (o instanceof Uri) return o.toString();
            return "'" + o.toString() + "'";
        }

        if (o instanceof Uri) return ((Uri) o).toSafeString();
        return "(redacted)";
    }
}
+2 −11
Original line number Diff line number Diff line
@@ -1385,9 +1385,7 @@ public class DirectoryFragment extends Fragment implements SwipeRefreshLayout.On

    public static void showDirectory(
            FragmentManager fm, RootInfo root, DocumentInfo doc, int anim) {
        if (DEBUG) {
            Log.d(TAG, "Showing directory: " + DocumentInfo.debugString(doc));
        }
        if (DEBUG) Log.d(TAG, "Showing dir " + doc);
        create(fm, root, doc, anim);
    }

@@ -1400,14 +1398,7 @@ public class DirectoryFragment extends Fragment implements SwipeRefreshLayout.On
            RootInfo root,
            @Nullable DocumentInfo doc,
            @AnimationType int anim) {

        if (DEBUG) {
            if (doc == null) {
                Log.d(TAG, "Creating new fragment null directory");
            } else {
                Log.d(TAG, "Creating new fragment for directory: " + DocumentInfo.debugString(doc));
            }
        }
        if (DEBUG) Log.d(TAG, "Creating new fragment for dir " + doc);

        final Bundle args = new Bundle();
        args.putParcelable(Shared.EXTRA_ROOT, root);