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 dagger.assisted.Assisted 20 import dagger.assisted.AssistedFactory 21 import dagger.assisted.AssistedInject 22 import javax.inject.Qualifier 23 24 /** 25 * Listener that logs start and end of the fold-unfold transition. 26 * 27 * [tracePrefix] arg helps in differentiating those. Currently, this is expected to be logged twice 28 * for each fold/unfold: in (1) systemui and (2) launcher process. 29 */ 30 class ATraceLoggerTransitionProgressListener 31 @AssistedInject 32 internal constructor(@UnfoldTransitionATracePrefix tracePrefix: String, @Assisted details: String) : 33 TransitionProgressListener { 34 35 private val traceName = "$tracePrefix$details#$UNFOLD_TRANSITION_TRACE_NAME" 36 onTransitionStartednull37 override fun onTransitionStarted() { 38 Trace.beginAsyncSection(traceName, /* cookie= */ 0) 39 } 40 onTransitionFinishednull41 override fun onTransitionFinished() { 42 Trace.endAsyncSection(traceName, /* cookie= */ 0) 43 } 44 onTransitionProgressnull45 override fun onTransitionProgress(progress: Float) { 46 Trace.setCounter(traceName, (progress * 100).toLong()) 47 } 48 49 @AssistedFactory 50 interface Factory { 51 /** Creates an [ATraceLoggerTransitionProgressListener] with [details] in the track name. */ createnull52 fun create(details: String): ATraceLoggerTransitionProgressListener 53 } 54 } 55 56 private const val UNFOLD_TRANSITION_TRACE_NAME = "FoldUnfoldTransitionInProgress" 57 58 @Qualifier annotation class UnfoldTransitionATracePrefix 59