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

Commit 40f65862 authored by Sunny Goyal's avatar Sunny Goyal
Browse files

Adding utility method to dump encoded view hierarchy

Test: Verified the library change with launcher (after generating a bug report)
Bug: 79861035
Change-Id: Id1eabbfd293ee43c46cbecae82442fc77b661744
parent 84bf0708
Loading
Loading
Loading
Loading
+27 −0
Original line number Diff line number Diff line
@@ -17,6 +17,10 @@
package com.android.systemui.shared.system;

import android.app.Activity;
import android.view.View;
import android.view.ViewHierarchyEncoder;

import java.io.ByteArrayOutputStream;

public class ActivityCompat {
    private final Activity mWrapped;
@@ -31,4 +35,27 @@ public class ActivityCompat {
    public void registerRemoteAnimations(RemoteAnimationDefinitionCompat definition) {
        mWrapped.registerRemoteAnimations(definition.getWrapped());
    }

    /**
     * @see android.view.ViewDebug#dumpv2(View, ByteArrayOutputStream)
     */
    public boolean encodeViewHierarchy(ByteArrayOutputStream out) {
        View view = null;
        if (mWrapped.getWindow() != null &&
                mWrapped.getWindow().peekDecorView() != null &&
                mWrapped.getWindow().peekDecorView().getViewRootImpl() != null) {
            view = mWrapped.getWindow().peekDecorView().getViewRootImpl().getView();
        }
        if (view == null) {
            return false;
        }

        final ViewHierarchyEncoder encoder = new ViewHierarchyEncoder(out);
        int[] location = view.getLocationOnScreen();
        encoder.addProperty("window:left", location[0]);
        encoder.addProperty("window:top", location[1]);
        view.encode(encoder);
        encoder.endStream();
        return true;
    }
}