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

Commit d446f984 authored by Winson Chung's avatar Winson Chung Committed by Android (Google) Code Review
Browse files

Merge "Adding new tracing call from SysUI" into ub-launcher3-master

parents 7be16017 f3b7246b
Loading
Loading
Loading
Loading
+31 −0
Original line number Diff line number Diff line
/*
 * Copyright (C) 2019 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

syntax = "proto2";

package com.android.launcher3.tracing;

option java_multiple_files = true;

message LauncherTraceProto {

    optional TouchInteractionServiceProto touch_interaction_service = 1;
}

message TouchInteractionServiceProto {

    optional bool service_connected = 1;
}
+49 −0
Original line number Diff line number Diff line
/*
 * Copyright (C) 2019 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

syntax = "proto2";

import "launcher_trace.proto";

package com.android.launcher3.tracing;

option java_multiple_files = true;

/* represents a file full of launcher trace entries.
   Encoded, it should start with 0x9 0x4C 0x4E 0x43 0x48 0x52 0x54 0x52 0x43 (.LNCHRTRC), such
   that they can be easily identified. */
message LauncherTraceFileProto {

    /* constant; MAGIC_NUMBER = (long) MAGIC_NUMBER_H << 32 | MagicNumber.MAGIC_NUMBER_L
       (this is needed because enums have to be 32 bits and there's no nice way to put 64bit
        constants into .proto files. */
    enum MagicNumber {
        INVALID = 0;
        MAGIC_NUMBER_L = 0x48434E4C;  /* LNCH (little-endian ASCII) */
        MAGIC_NUMBER_H = 0x43525452;  /* RTRC (little-endian ASCII) */
    }

    optional fixed64 magic_number = 1;  /* Must be the first field, set to value in MagicNumber */
    repeated LauncherTraceEntryProto entry = 2;
}

/* one launcher trace entry. */
message LauncherTraceEntryProto {
    /* required: elapsed realtime in nanos since boot of when this entry was logged */
    optional fixed64 elapsed_realtime_nanos = 1;

    optional LauncherTraceProto launcher = 3;
}
+29 −1
Original line number Diff line number Diff line
@@ -28,6 +28,7 @@ import static com.android.launcher3.util.Executors.MAIN_EXECUTOR;
import static com.android.launcher3.util.Executors.UI_HELPER_EXECUTOR;
import static com.android.systemui.shared.system.QuickStepContract.KEY_EXTRA_INPUT_MONITOR;
import static com.android.systemui.shared.system.QuickStepContract.KEY_EXTRA_SYSUI_PROXY;
import static com.android.systemui.shared.system.QuickStepContract.SYSUI_STATE_TRACING_ENABLED;
import static com.android.systemui.shared.system.RemoteAnimationTargetCompat.ACTIVITY_TYPE_ASSISTANT;

import android.annotation.TargetApi;
@@ -63,6 +64,8 @@ import com.android.launcher3.model.AppLaunchTracker;
import com.android.launcher3.provider.RestoreDbTask;
import com.android.launcher3.testing.TestLogging;
import com.android.launcher3.testing.TestProtocol;
import com.android.launcher3.tracing.nano.LauncherTraceProto;
import com.android.launcher3.tracing.nano.TouchInteractionServiceProto;
import com.android.launcher3.uioverrides.plugins.PluginManagerWrapper;
import com.android.launcher3.util.TraceHelper;
import com.android.quickstep.inputconsumers.AccessibilityInputConsumer;
@@ -76,6 +79,7 @@ import com.android.quickstep.inputconsumers.ResetGestureInputConsumer;
import com.android.quickstep.inputconsumers.ScreenPinnedInputConsumer;
import com.android.quickstep.util.ActiveGestureLog;
import com.android.quickstep.util.AssistantUtilities;
import com.android.quickstep.util.ProtoTracer;
import com.android.systemui.plugins.OverscrollPlugin;
import com.android.systemui.plugins.PluginListener;
import com.android.systemui.shared.recents.IOverviewProxy;
@@ -85,6 +89,7 @@ import com.android.systemui.shared.system.InputChannelCompat.InputEventReceiver;
import com.android.systemui.shared.system.InputConsumerController;
import com.android.systemui.shared.system.InputMonitorCompat;
import com.android.systemui.shared.system.RecentsAnimationListener;
import com.android.systemui.shared.tracing.ProtoTraceable;

import java.io.FileDescriptor;
import java.io.PrintWriter;
@@ -113,7 +118,8 @@ class ArgList extends LinkedList<String> {
 * Service connected by system-UI for handling touch interaction.
 */
@TargetApi(Build.VERSION_CODES.Q)
public class TouchInteractionService extends Service implements PluginListener<OverscrollPlugin> {
public class TouchInteractionService extends Service implements PluginListener<OverscrollPlugin>,
        ProtoTraceable<LauncherTraceProto> {

    private static final String TAG = "TouchInteractionService";

@@ -275,6 +281,7 @@ public class TouchInteractionService extends Service implements PluginListener<O
        mDeviceState = new RecentsAnimationDeviceState(this);
        mDeviceState.addNavigationModeChangedCallback(this::onNavigationModeChanged);
        mDeviceState.runOnUserUnlocked(this::onUserUnlocked);
        ProtoTracer.INSTANCE.get(this).add(this);

        sConnected = true;
    }
@@ -381,6 +388,13 @@ public class TouchInteractionService extends Service implements PluginListener<O
            SystemUiProxy.INSTANCE.get(this).setLastSystemUiStateFlags(
                    mDeviceState.getSystemUiStateFlags());
            mOverviewComponentObserver.onSystemUiStateChanged();

            // Update the tracing state
            if ((mDeviceState.getSystemUiStateFlags() & SYSUI_STATE_TRACING_ENABLED) != 0) {
                ProtoTracer.INSTANCE.get(TouchInteractionService.this).start();
            } else {
                ProtoTracer.INSTANCE.get(TouchInteractionService.this).stop();
            }
        }
    }

@@ -403,6 +417,8 @@ public class TouchInteractionService extends Service implements PluginListener<O
        disposeEventHandlers();
        mDeviceState.destroy();
        SystemUiProxy.INSTANCE.get(this).setProxy(null);
        ProtoTracer.INSTANCE.get(TouchInteractionService.this).stop();
        ProtoTracer.INSTANCE.get(this).remove(this);

        sConnected = false;
        super.onDestroy();
@@ -723,6 +739,9 @@ public class TouchInteractionService extends Service implements PluginListener<O
            pw.println("  resumed=" + resumed);
            pw.println("  mConsumer=" + mConsumer.getName());
            ActiveGestureLog.INSTANCE.dump("", pw);
            pw.println("ProtoTrace:");
            pw.println("  file="
                    + ProtoTracer.INSTANCE.get(TouchInteractionService.this).getTraceFile());
        }
    }

@@ -781,4 +800,13 @@ public class TouchInteractionService extends Service implements PluginListener<O
    public void onPluginDisconnected(OverscrollPlugin overscrollPlugin) {
        mOverscrollPlugin = null;
    }

    @Override
    public void writeToProto(LauncherTraceProto proto) {
        if (proto.touchInteractionService == null) {
            proto.touchInteractionService = new TouchInteractionServiceProto();
        }
        proto.touchInteractionService.serviceConnected = true;
        proto.touchInteractionService.serviceConnected = true;
    }
}
+127 −0
Original line number Diff line number Diff line
/*
 * Copyright (C) 2019 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package com.android.quickstep.util;

import static com.android.launcher3.tracing.nano.LauncherTraceFileProto.MagicNumber.MAGIC_NUMBER_H;
import static com.android.launcher3.tracing.nano.LauncherTraceFileProto.MagicNumber.MAGIC_NUMBER_L;

import android.content.Context;
import android.os.SystemClock;

import com.android.launcher3.tracing.nano.LauncherTraceProto;
import com.android.launcher3.tracing.nano.LauncherTraceEntryProto;
import com.android.launcher3.tracing.nano.LauncherTraceFileProto;
import com.android.launcher3.util.MainThreadInitializedObject;
import com.android.systemui.shared.tracing.FrameProtoTracer;
import com.android.systemui.shared.tracing.FrameProtoTracer.ProtoTraceParams;
import com.android.systemui.shared.tracing.ProtoTraceable;
import com.google.protobuf.nano.MessageNano;

import java.io.File;
import java.io.FileDescriptor;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.Queue;


/**
 * Controller for coordinating winscope proto tracing.
 */
public class ProtoTracer implements ProtoTraceParams<MessageNano,
        LauncherTraceFileProto, LauncherTraceEntryProto, LauncherTraceProto> {

    public static final MainThreadInitializedObject<ProtoTracer> INSTANCE =
            new MainThreadInitializedObject<>(ProtoTracer::new);

    private static final String TAG = "ProtoTracer";
    private static final long MAGIC_NUMBER_VALUE = ((long) MAGIC_NUMBER_H << 32) | MAGIC_NUMBER_L;

    private final Context mContext;
    private final FrameProtoTracer<MessageNano,
            LauncherTraceFileProto, LauncherTraceEntryProto, LauncherTraceProto> mProtoTracer;

    public ProtoTracer(Context context) {
        mContext = context;
        mProtoTracer = new FrameProtoTracer<>(this);
    }

    @Override
    public File getTraceFile() {
        return new File(mContext.getFilesDir(), "launcher_trace.pb");
    }

    @Override
    public LauncherTraceFileProto getEncapsulatingTraceProto() {
        return new LauncherTraceFileProto();
    }

    @Override
    public LauncherTraceEntryProto updateBufferProto(LauncherTraceEntryProto reuseObj,
            ArrayList<ProtoTraceable<LauncherTraceProto>> traceables) {
        LauncherTraceEntryProto proto = reuseObj != null
                ? reuseObj
                : new LauncherTraceEntryProto();
        proto.elapsedRealtimeNanos = SystemClock.elapsedRealtimeNanos();
        proto.launcher = proto.launcher != null ? proto.launcher : new LauncherTraceProto();
        for (ProtoTraceable t : traceables) {
            t.writeToProto(proto.launcher);
        }
        return proto;
    }

    @Override
    public byte[] serializeEncapsulatingProto(LauncherTraceFileProto encapsulatingProto,
            Queue<LauncherTraceEntryProto> buffer) {
        encapsulatingProto.magicNumber = MAGIC_NUMBER_VALUE;
        encapsulatingProto.entry = buffer.toArray(new LauncherTraceEntryProto[0]);
        return MessageNano.toByteArray(encapsulatingProto);
    }

    @Override
    public byte[] getProtoBytes(MessageNano proto) {
        return MessageNano.toByteArray(proto);
    }

    @Override
    public int getProtoSize(MessageNano proto) {
        return proto.getCachedSize();
    }

    public void start() {
        mProtoTracer.start();
    }

    public void stop() {
        mProtoTracer.stop();
    }

    public void add(ProtoTraceable<LauncherTraceProto> traceable) {
        mProtoTracer.add(traceable);
    }

    public void remove(ProtoTraceable<LauncherTraceProto> traceable) {
        mProtoTracer.remove(traceable);
    }

    public void scheduleFrameUpdate() {
        mProtoTracer.scheduleFrameUpdate();
    }

    public void update() {
        mProtoTracer.update();
    }
}