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

Commit 0d4ac4ec authored by Winson Chung's avatar Winson Chung
Browse files

Exposing flickerlib classes and layer tracing to sysui

- Allow recents component to enable/disable layer tracing
- Expose flickerlib classes for use with sysui/launcher tests
- Allow trace files to be moved to a path that the client can read
- Ensure layers are flattened with depth traversal to encode ordering

Bug: 140244969
Test: atest FlickerTests
Change-Id: I7af5699ff5b8a4bc62c1a8105c67b31bc45a2236
Merged-In: Ia0934ec7c2b9484fa6c85f5aa8d9b2e5e6f7dc0f
parent 763cb463
Loading
Loading
Loading
Loading
+10 −0
Original line number Diff line number Diff line
@@ -638,4 +638,14 @@ interface IWindowManager
     * native InputManager before proceeding with tests.
     */
    void syncInputTransactions();

    /**
     * Returns whether SurfaceFlinger layer tracing is enabled.
     */
    boolean isLayerTracing();

    /**
     * Enables/disables SurfaceFlinger layer tracing.
     */
    void setLayerTracing(boolean enabled);
}
+60 −0
Original line number Diff line number Diff line
@@ -7778,4 +7778,64 @@ public class WindowManagerService extends IWindowManager.Stub
                    0 /* configChanges */, !PRESERVE_WINDOWS, true /* notifyClients */);
        }
    }

    /** Return whether layer tracing is enabled */
    public boolean isLayerTracing() {
        mAtmInternal.enforceCallerIsRecentsOrHasPermission(android.Manifest.permission.DUMP,
                "isLayerTracing");
        long token = Binder.clearCallingIdentity();
        try {
            Parcel data = null;
            Parcel reply = null;
            try {
                IBinder sf = ServiceManager.getService("SurfaceFlinger");
                if (sf != null) {
                    reply = Parcel.obtain();
                    data = Parcel.obtain();
                    data.writeInterfaceToken("android.ui.ISurfaceComposer");
                    sf.transact(/* LAYER_TRACE_STATUS_CODE */ 1026, data, reply, 0 /* flags */);
                    return reply.readBoolean();
                }
            } catch (RemoteException e) {
                Slog.e(TAG, "Failed to get layer tracing");
            } finally {
                if (data != null) {
                    data.recycle();
                }
                if (reply != null) {
                    reply.recycle();
                }
            }
        } finally {
            Binder.restoreCallingIdentity(token);
        }
        return false;
    }

    /** Enable or disable layer tracing */
    public void setLayerTracing(boolean enabled) {
        mAtmInternal.enforceCallerIsRecentsOrHasPermission(android.Manifest.permission.DUMP,
                "setLayerTracing");
        long token = Binder.clearCallingIdentity();
        try {
            Parcel data = null;
            try {
                IBinder sf = ServiceManager.getService("SurfaceFlinger");
                if (sf != null) {
                    data = Parcel.obtain();
                    data.writeInterfaceToken("android.ui.ISurfaceComposer");
                    data.writeInt(enabled ? 1 : 0);
                    sf.transact(/* LAYER_TRACE_CONTROL_CODE */ 1025, data, null, 0 /* flags */);
                }
            } catch (RemoteException e) {
                Slog.e(TAG, "Failed to set layer tracing");
            } finally {
                if (data != null) {
                    data.recycle();
                }
            }
        } finally {
            Binder.restoreCallingIdentity(token);
        }
    }
}
+14 −1
Original line number Diff line number Diff line
@@ -29,11 +29,24 @@ java_test {
    ],
}

java_library {
    name: "flickerlib_without_helpers",
    platform_apis: true,
    srcs: ["src/**/*.java"],
    exclude_srcs: ["src/**/helpers/*.java"],
    static_libs: [
        "cts-wm-util",
        "platformprotosnano",
        "layersprotosnano",
        "truth-prebuilt"
    ],
}

java_library {
    name: "flickerautomationhelperlib",
    sdk_version: "test_current",
    srcs: [
        "src/com/android/server/wm/flicker/AutomationUtils.java",
        "src/com/android/server/wm/flicker/helpers/AutomationUtils.java",
        "src/com/android/server/wm/flicker/WindowUtils.java",
    ],
    static_libs: [
+19 −19
Original line number Diff line number Diff line
@@ -24,14 +24,14 @@ import java.util.function.Function;
 * results. Assertions are functions that are applied over a single trace entry and returns a
 * result which includes a detailed reason if the assertion fails.
 */
class Assertions {
public class Assertions {
    /**
     * Checks assertion on a single trace entry.
     *
     * @param <T> trace entry type to perform the assertion on.
     */
    @FunctionalInterface
    interface TraceAssertion<T> extends Function<T, Result> {
    public interface TraceAssertion<T> extends Function<T, Result> {
        /**
         * Returns an assertion that represents the logical negation of this assertion.
         *
@@ -46,7 +46,7 @@ class Assertions {
     * Checks assertion on a single layers trace entry.
     */
    @FunctionalInterface
    interface LayersTraceAssertion extends TraceAssertion<LayersTrace.Entry> {
    public interface LayersTraceAssertion extends TraceAssertion<LayersTrace.Entry> {

    }

@@ -54,11 +54,11 @@ class Assertions {
     * Utility class to store assertions with an identifier to help generate more useful debug
     * data when dealing with multiple assertions.
     */
    static class NamedAssertion<T> {
        final TraceAssertion<T> assertion;
        final String name;
    public static class NamedAssertion<T> {
        public final TraceAssertion<T> assertion;
        public final String name;

        NamedAssertion(TraceAssertion<T> assertion, String name) {
        public NamedAssertion(TraceAssertion<T> assertion, String name) {
            this.assertion = assertion;
            this.name = name;
        }
@@ -67,21 +67,21 @@ class Assertions {
    /**
     * Contains the result of an assertion including the reason for failed assertions.
     */
    static class Result {
        static final String NEGATION_PREFIX = "!";
        final boolean success;
        final long timestamp;
        final String assertionName;
        final String reason;

        Result(boolean success, long timestamp, String assertionName, String reason) {
    public static class Result {
        public static final String NEGATION_PREFIX = "!";
        public final boolean success;
        public final long timestamp;
        public final String assertionName;
        public final String reason;

        public Result(boolean success, long timestamp, String assertionName, String reason) {
            this.success = success;
            this.timestamp = timestamp;
            this.assertionName = assertionName;
            this.reason = reason;
        }

        Result(boolean success, String reason) {
        public Result(boolean success, String reason) {
            this.success = success;
            this.reason = reason;
            this.assertionName = "";
@@ -91,7 +91,7 @@ class Assertions {
        /**
         * Returns the negated {@code Result} and adds a negation prefix to the assertion name.
         */
        Result negate() {
        public Result negate() {
            String negatedAssertionName;
            if (this.assertionName.startsWith(NEGATION_PREFIX)) {
                negatedAssertionName = this.assertionName.substring(NEGATION_PREFIX.length() + 1);
@@ -101,11 +101,11 @@ class Assertions {
            return new Result(!this.success, this.timestamp, negatedAssertionName, this.reason);
        }

        boolean passed() {
        public boolean passed() {
            return this.success;
        }

        boolean failed() {
        public boolean failed() {
            return !this.success;
        }

+3 −3
Original line number Diff line number Diff line
@@ -38,11 +38,11 @@ public class AssertionsChecker<T extends ITraceEntry> {
    private AssertionOption mOption = AssertionOption.NONE;
    private List<NamedAssertion<T>> mAssertions = new LinkedList<>();

    void add(Assertions.TraceAssertion<T> assertion, String name) {
    public void add(Assertions.TraceAssertion<T> assertion, String name) {
        mAssertions.add(new NamedAssertion<>(assertion, name));
    }

    void filterByRange(long startTime, long endTime) {
    public void filterByRange(long startTime, long endTime) {
        mFilterEntriesByRange = true;
        mFilterStartTime = startTime;
        mFilterEndTime = endTime;
@@ -75,7 +75,7 @@ public class AssertionsChecker<T extends ITraceEntry> {
     * @param entries list of entries to perform assertions on
     * @return list of failed assertion results
     */
    List<Result> test(List<T> entries) {
    public List<Result> test(List<T> entries) {
        List<T> filteredEntries;
        List<Result> failures;

Loading