1 /* 2 * Copyright (C) 2022 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software distributed under the 11 * License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 12 * KIND, either express or implied. See the License for the specific language governing 13 * permissions and limitations under the License. 14 */ 15 package com.android.systemui.unfold.util 16 17 import android.os.Trace 18 import com.android.systemui.unfold.UnfoldTransitionProgressProvider.TransitionProgressListener 19 import javax.inject.Inject 20 import javax.inject.Qualifier 21 22 /** 23 * Listener that logs start and end of the fold-unfold transition. 24 * 25 * [tracePrefix] arg helps in differentiating those. Currently, this is expected to be logged twice 26 * for each fold/unfold: in (1) systemui and (2) launcher process. 27 */ 28 class ATraceLoggerTransitionProgressListener 29 @Inject 30 internal constructor(@UnfoldTransitionATracePrefix tracePrefix: String) : 31 TransitionProgressListener { 32 33 private val traceName = "$tracePrefix#$UNFOLD_TRANSITION_TRACE_NAME" 34 35 override fun onTransitionStarted() { 36 Trace.beginAsyncSection(traceName, /* cookie= */ 0) 37 } 38 39 override fun onTransitionFinished() { 40 Trace.endAsyncSection(traceName, /* cookie= */ 0) 41 } 42 43 override fun onTransitionProgress(progress: Float) { 44 Trace.setCounter(traceName, (progress * 100).toLong()) 45 } 46 } 47 48 private const val UNFOLD_TRANSITION_TRACE_NAME = "FoldUnfoldTransitionInProgress" 49 50 @Qualifier annotation class UnfoldTransitionATracePrefix 51