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

Commit 63ffeb40 authored by Pinyao Ting's avatar Pinyao Ting
Browse files

Add tracing to RemoteViews

This CL adds tracing when inflating views and applying actions from the RemoteViews.

Bug: 359898871
Change-Id: I3b7e7f0efc06b50d9d2b7aca6c85b26a681e4c9c
Flag: EXEMPT traces
Test: manual
parent e932d31a
Loading
Loading
Loading
Loading
+43 −16
Original line number Diff line number Diff line
@@ -83,6 +83,7 @@ import android.os.Parcelable;
import android.os.Process;
import android.os.RemoteException;
import android.os.StrictMode;
import android.os.Trace;
import android.os.UserHandle;
import android.system.Os;
import android.text.TextUtils;
@@ -6246,6 +6247,18 @@ public class RemoteViews implements Parcelable, Filter {

    private View inflateView(Context context, RemoteViews rv, @Nullable ViewGroup parent,
            @StyleRes int applyThemeResId, @Nullable ColorResources colorResources) {
        try {
            Trace.beginSection(rv.hasDrawInstructions()
                    ? "RemoteViews#inflateViewWithDrawInstructions"
                    : "RemoteViews#inflateView");
            return inflateViewInternal(context, rv, parent, applyThemeResId, colorResources);
        } finally {
            Trace.endSection();
        }
    }

    private View inflateViewInternal(Context context, RemoteViews rv, @Nullable ViewGroup parent,
            @StyleRes int applyThemeResId, @Nullable ColorResources colorResources) {
        // RemoteViews may be built by an application installed in another
        // user. So build a context that loads resources from that user but
        // still returns the current users userId so settings like data / time formats
@@ -6384,7 +6397,7 @@ public class RemoteViews implements Parcelable, Filter {

        private View mResult;
        private ViewTree mTree;
        private Action[] mActions;
        private List<Action> mActions;
        private Exception mError;

        private AsyncApplyTask(
@@ -6411,11 +6424,20 @@ public class RemoteViews implements Parcelable, Filter {

                if (mRV.mActions != null) {
                    int count = mRV.mActions.size();
                    mActions = new Action[count];
                    for (int i = 0; i < count && !isCancelled(); i++) {
                    mActions = new ArrayList<>(count);
                    try {
                        Trace.beginSection(hasDrawInstructions()
                                ? "RemoteViews#initActionAsyncWithDrawInstructions"
                                : "RemoteViews#initActionAsync");
                        for (Action action : mRV.mActions) {
                            if (isCancelled()) {
                                break;
                            }
                            // TODO: check if isCancelled in nested views.
                        mActions[i] = mRV.mActions.get(i)
                                .initActionAsync(mTree, mParent, mApplyParams);
                            mActions.add(action.initActionAsync(mTree, mParent, mApplyParams));
                        }
                    } finally {
                        Trace.endSection();
                    }
                } else {
                    mActions = null;
@@ -6437,14 +6459,7 @@ public class RemoteViews implements Parcelable, Filter {

                try {
                    if (mActions != null) {

                        ActionApplyParams applyParams = mApplyParams.clone();
                        if (applyParams.handler == null) {
                            applyParams.handler = DEFAULT_INTERACTION_HANDLER;
                        }
                        for (Action a : mActions) {
                            a.apply(viewTree.mRoot, mParent, applyParams);
                        }
                        mRV.performApply(viewTree.mRoot, mParent, mApplyParams, mActions);
                    }
                    // If the parent of the view is has is a root, resolve the recycling.
                    if (mTopLevel && mResult instanceof ViewGroup) {
@@ -6620,6 +6635,11 @@ public class RemoteViews implements Parcelable, Filter {
    }

    private void performApply(View v, ViewGroup parent, ActionApplyParams params) {
        performApply(v, parent, params, mActions);
    }

    private void performApply(
            View v, ViewGroup parent, ActionApplyParams params, List<Action> actions) {
        params = params.clone();
        if (params.handler == null) {
            params.handler = DEFAULT_INTERACTION_HANDLER;
@@ -6630,9 +6650,16 @@ public class RemoteViews implements Parcelable, Filter {
        }
        if (mActions != null) {
            final int count = mActions.size();
            try {
                Trace.beginSection(hasDrawInstructions()
                        ? "RemoteViews#applyActionsWithDrawInstructions"
                        : "RemoteViews#applyActions");
                for (int i = 0; i < count; i++) {
                    mActions.get(i).apply(v, parent, params);
                }
            } finally {
                Trace.endSection();
            }
        }
    }