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

Commit 559bbfe9 authored by Steve McKay's avatar Steve McKay
Browse files

Show raw metadata in debug view.

Test: Ran local tests only. Added visibility coverage of debug view.
Change-Id: Ic99dadf27485b886ace7065416a87779ea7103d0
parent a1299dd5
Loading
Loading
Loading
Loading
+3 −0
Original line number Diff line number Diff line
@@ -26,6 +26,9 @@
         This section is only visible to developers or people running debug builds. [CHAR LIMIT=48] -->
    <string name="inspector_debug_section">Debug info (dev only)</string>

    <!-- Title of inspector's debug info metadata sub-section. [CHAR LIMIT=48] -->
    <string name="inspector_debug_metadata_section">Raw metadata: <xliff:g id="metadataType" example="EXIF">%1$s</xliff:g></string>

    <!-- Title of inspector's media details info section. Shows information related to camera, dimensions, and authors. -->
    <string name="inspector_metadata_section">Media details</string>

+30 −2
Original line number Diff line number Diff line
@@ -19,6 +19,8 @@ import android.annotation.StringRes;
import android.content.Context;
import android.content.res.Resources;
import android.os.AsyncTask;
import android.os.Bundle;
import android.provider.DocumentsContract;
import android.util.AttributeSet;
import android.widget.TextView;

@@ -26,18 +28,18 @@ import com.android.documentsui.R;
import com.android.documentsui.base.DocumentInfo;
import com.android.documentsui.base.DummyLookup;
import com.android.documentsui.base.Lookup;
import com.android.documentsui.inspector.InspectorController.DebugDisplay;

import java.text.NumberFormat;
import java.util.Arrays;
import java.util.concurrent.Executor;
import java.util.function.Consumer;

/**
 * Organizes and Displays the debug information about a file. This view
 * should only be made visible when build is debuggable and system policies
 * allow debug "stuff".
 */
public class DebugView extends TableView implements Consumer<DocumentInfo> {
public class DebugView extends TableView implements DebugDisplay {

    private final Context mContext;
    private final Resources mRes;
@@ -59,6 +61,7 @@ public class DebugView extends TableView implements Consumer<DocumentInfo> {

    void init(Lookup<String, Executor> executors) {
        assert executors != null;
        setBackgroundColor(0xFFFFFFFF);  // it's just debug. We do what we want!
        mExecutors = executors;
    }

@@ -103,6 +106,31 @@ public class DebugView extends TableView implements Consumer<DocumentInfo> {
        }
    }

    @Override
    public void accept(Bundle metadata) {
        if (metadata == null) {
            return;
        }

        String[] types = metadata.getStringArray(DocumentsContract.METADATA_TYPES);
        if (types == null) {
            return;
        }

        for (String type : types) {
            dumpMetadata(type, metadata.getBundle(type));
        }
    }

    private void dumpMetadata(String type, Bundle bundle) {
        String title = mContext.getResources().getString(
                R.string.inspector_debug_metadata_section);
        putTitle(String.format(title, type));
        for (String key : bundle.keySet()) {
            put(key, String.valueOf(bundle.get(key)));
        }
    }

    private void put(@StringRes int key, boolean value) {
        KeyValueRow row = put(mRes.getString(key), String.valueOf(value));
        TextView valueView = ((TextView) row.findViewById(R.id.table_row_value));
+21 −4
Original line number Diff line number Diff line
@@ -54,7 +54,7 @@ public final class InspectorController {
    private final MediaDisplay mMedia;
    private final ActionDisplay mShowProvider;
    private final ActionDisplay mAppDefaults;
    private final Consumer<DocumentInfo> mDebugView;
    private final DebugDisplay mDebugView;
    private final Context mContext;
    private final PackageManager mPackageManager;
    private final ProvidersAccess mProviders;
@@ -75,7 +75,7 @@ public final class InspectorController {
            MediaDisplay media,
            ActionDisplay showProvider,
            ActionDisplay appDefaults,
            Consumer<DocumentInfo> debugView,
            DebugDisplay debugView,
            Bundle args,
            Runnable errorRunnable) {

@@ -136,8 +136,6 @@ public final class InspectorController {
        if (args.getBoolean(Shared.EXTRA_SHOW_DEBUG)) {
            DebugView view = (DebugView) layout.findViewById(R.id.inspector_debug_view);
            view.init(ProviderExecutor::forAuthority);
            view.setVisibility(View.VISIBLE);
            view.setBackgroundColor(0xFFFFFFFF);  // it's just debug. We do what we want!
        }
    }

@@ -199,6 +197,8 @@ public final class InspectorController {
            if (mArgs.getBoolean(Shared.EXTRA_SHOW_DEBUG)) {
                mDebugView.accept(docInfo);
            }
            mDebugView.setVisible(mArgs.getBoolean(Shared.EXTRA_SHOW_DEBUG)
                    && !mDebugView.isEmpty());
        }
    }

@@ -220,6 +220,10 @@ public final class InspectorController {
        }

        mMedia.accept(doc, metadata, geoClickListener);

        if (mArgs.getBoolean(Shared.EXTRA_SHOW_DEBUG)) {
            mDebugView.accept(metadata);
        }
    }

    /**
@@ -378,6 +382,19 @@ public final class InspectorController {
        boolean isEmpty();
    }

    /**
     * Provides details about a media file.
     */
    public interface DebugDisplay extends Display {
        void accept(DocumentInfo info);
        void accept(Bundle metadata);

        /**
         * Returns true if there are now rows in the display. Does not consider the title.
         */
        boolean isEmpty();
    }

    /**
     * Displays a table of image metadata.
     */
+1 −1
Original line number Diff line number Diff line
@@ -53,7 +53,7 @@ public class KeyValueRow extends LinearLayout {
     * Sets the raw value of the key. Only localized values
     * should be passed.
     */
    public void setKey(String key) {
    public void setKey(CharSequence key) {
        ((TextView) findViewById(R.id.table_row_key)).setText(key);
    }

+14 −8
Original line number Diff line number Diff line
@@ -19,7 +19,6 @@ package com.android.documentsui.inspector;
import android.annotation.StringRes;
import android.content.Context;
import android.content.res.Resources;
import android.support.annotation.Nullable;
import android.util.AttributeSet;
import android.view.LayoutInflater;
import android.view.View;
@@ -40,9 +39,9 @@ public class TableView extends LinearLayout implements TableDisplay {

    private final LayoutInflater mInflater;

    private final Map<String, KeyValueRow> mRows = new HashMap<>();
    private final Map<CharSequence, KeyValueRow> mRows = new HashMap<>();
    private final Resources mRes;
    private @Nullable TextView mTitle;
    private Map<CharSequence, TextView> mTitles = new HashMap<>();

    public TableView(Context context) {
        this(context, null);
@@ -60,11 +59,18 @@ public class TableView extends LinearLayout implements TableDisplay {

    @Override
    public void setTitle(@StringRes int title) {
        if (mTitle == null) {
            mTitle = (TextView) mInflater.inflate(R.layout.inspector_section_title, null);
            addView(mTitle);
        putTitle(mContext.getResources().getString(title));
    }
        mTitle.setText(mContext.getResources().getString(title));

    // A naughty title method (that takes strings, not message ids), mostly for DebugView.
    protected void putTitle(CharSequence title) {
        TextView view = mTitles.get(title);
        if (view == null) {
            view = (TextView) mInflater.inflate(R.layout.inspector_section_title, null);
            addView(view);
            mTitles.put(title, view);
        }
        view.setText(title);
    }

    protected KeyValueRow createKeyValueRow(ViewGroup parent) {
@@ -84,7 +90,7 @@ public class TableView extends LinearLayout implements TableDisplay {
    /**
     * Puts or updates an value in the table view.
     */
    protected KeyValueRow put(String key, CharSequence value) {
    protected KeyValueRow put(CharSequence key, CharSequence value) {
        KeyValueRow row = mRows.get(key);

        if (row == null) {
Loading