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

Commit e3be6a45 authored by Garfield Tan's avatar Garfield Tan
Browse files

Report metrics for pick w/ initial location.

Report the initial locations by its roots. If DocumentsUI cannot
determine its root either because the provider doesn't support
getDocumentPath() or error occurs, report ROOT_NONE to indicate the
default root is loaded.

Test: Manual test that it doesn't crash the app.

Bug: 32412499
Change-Id: I1736101f1ef962e31a41658444b6c2b1b5096859
(cherry picked from commit 935c5136)
parent e77419c6
Loading
Loading
Loading
Loading
+26 −0
Original line number Diff line number Diff line
@@ -28,6 +28,7 @@ import android.content.Intent;
import android.content.pm.ResolveInfo;
import android.net.Uri;
import android.provider.DocumentsContract;
import android.provider.DocumentsProvider;
import android.util.Log;

import com.android.documentsui.base.DocumentInfo;
@@ -64,6 +65,9 @@ public final class Metrics {
    private static final String COUNT_STARTUP_MS = "docsui_startup_ms";
    private static final String COUNT_DRAWER_OPENED = "docsui_drawer_opened";
    private static final String COUNT_USER_ACTION = "docsui_menu_action";
    private static final String COUNT_CREATE_AT_LOCATION = "docsui_create_at_location";
    private static final String COUNT_OPEN_AT_LOCATION = "docsui_open_at_location";
    private static final String COUNT_GET_CONTENT_AT_LOCATION = "docsui_get_content_at_location";

    // Indices for bucketing roots in the roots histogram. "Other" is the catch-all index for any
    // root that is not explicitly recognized by the Metrics code (see {@link
@@ -343,6 +347,28 @@ public final class Metrics {
        }
    }

    /**
     * Logs when DocumentsUI are launched with {@link DocumentsContract#EXTRA_INITIAL_URI}.
     *
     * @param context
     * @param state used to resolve action
     * @param rootUri the resolved rootUri, or {@code null} if the provider doesn't
     *                support {@link DocumentsProvider#findDocumentPath(String, String)}
     */
    public static void logLaunchAtLocation(Context context, State state, @Nullable Uri rootUri) {
        switch (state.action) {
            case State.ACTION_CREATE:
                logHistogram(context, COUNT_CREATE_AT_LOCATION, sanitizeRoot(rootUri));
                break;
            case State.ACTION_GET_CONTENT:
                logHistogram(context, COUNT_GET_CONTENT_AT_LOCATION, sanitizeRoot(rootUri));
                break;
            case State.ACTION_OPEN:
                logHistogram(context, COUNT_OPEN_AT_LOCATION, sanitizeRoot(rootUri));
                break;
        }
    }

    /**
     * Logs a root visited event. Call this when the user visits on a root in the RootsFragment.
     *
+5 −0
Original line number Diff line number Diff line
@@ -140,10 +140,15 @@ class ActionHandler<T extends Activity & Addons> extends AbstractActionHandler<T
            }
            mState.stack.reset(stack);
            mActivity.refreshCurrentRootAndDirectory(AnimationView.ANIM_NONE);

            Metrics.logLaunchAtLocation(mActivity, mState, stack.getRoot().getUri());
        } else {
            Log.w(TAG, "Failed to launch into the given uri. Load last accessed stack.");
            loadLastAccessedStack();

            Metrics.logLaunchAtLocation(mActivity, mState, null);
        }

    }

    private void loadLastAccessedStack() {