1 /* 2 * Copyright (C) 2023 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 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17 package android.tools.traces.wm 18 19 class WindowManagerTraceEntryBuilder { 20 private var policy: WindowManagerPolicy? = null 21 private var focusedApp = "" 22 private var focusedDisplayId = 0 23 private var focusedWindow = "" 24 private var inputMethodWindowAppToken = "" 25 private var isHomeRecentsComponent = false 26 private var isDisplayFrozen = false 27 private val pendingActivities = mutableListOf<String>() 28 private var root: RootWindowContainer? = null 29 private var keyguardControllerState: KeyguardControllerState? = null 30 private var where = "" 31 32 private var elapsedTimestamp: Long = 0L 33 private var realTimestamp: Long? = null 34 <lambda>null35 fun setPolicy(value: WindowManagerPolicy?): WindowManagerTraceEntryBuilder = apply { 36 policy = value 37 } 38 setFocusedAppnull39 fun setFocusedApp(value: String): WindowManagerTraceEntryBuilder = apply { focusedApp = value } 40 <lambda>null41 fun setFocusedDisplayId(value: Int): WindowManagerTraceEntryBuilder = apply { 42 focusedDisplayId = value 43 } 44 <lambda>null45 fun setFocusedWindow(value: String): WindowManagerTraceEntryBuilder = apply { 46 focusedWindow = value 47 } 48 <lambda>null49 fun setInputMethodWindowAppToken(value: String): WindowManagerTraceEntryBuilder = apply { 50 inputMethodWindowAppToken = value 51 } 52 <lambda>null53 fun setIsHomeRecentsComponent(value: Boolean): WindowManagerTraceEntryBuilder = apply { 54 isHomeRecentsComponent = value 55 } 56 <lambda>null57 fun setIsDisplayFrozen(value: Boolean): WindowManagerTraceEntryBuilder = apply { 58 isDisplayFrozen = value 59 } 60 <lambda>null61 fun setPendingActivities(value: Collection<String>): WindowManagerTraceEntryBuilder = apply { 62 pendingActivities.addAll(value) 63 } 64 <lambda>null65 fun setRoot(value: RootWindowContainer?): WindowManagerTraceEntryBuilder = apply { 66 root = value 67 } 68 setKeyguardControllerStatenull69 fun setKeyguardControllerState( 70 value: KeyguardControllerState? 71 ): WindowManagerTraceEntryBuilder = apply { keyguardControllerState = value } 72 <lambda>null73 fun setWhere(value: String): WindowManagerTraceEntryBuilder = apply { where = value } 74 <lambda>null75 fun setElapsedTimestamp(value: Long): WindowManagerTraceEntryBuilder = apply { 76 elapsedTimestamp = value 77 } 78 <lambda>null79 fun setRealToElapsedTimeOffsetNs(value: Long?): WindowManagerTraceEntryBuilder = apply { 80 realTimestamp = 81 if (value != null && value != 0L) { 82 value + elapsedTimestamp 83 } else { 84 null 85 } 86 } 87 88 /** Constructs the window manager trace entry. */ buildnull89 fun build(): WindowManagerState { 90 val root = root ?: error("Root not set") 91 val keyguardControllerState = 92 keyguardControllerState ?: error("KeyguardControllerState not set") 93 94 return WindowManagerState( 95 elapsedTimestamp, 96 realTimestamp, 97 where, 98 policy, 99 focusedApp, 100 focusedDisplayId, 101 focusedWindow, 102 inputMethodWindowAppToken, 103 isHomeRecentsComponent, 104 isDisplayFrozen, 105 pendingActivities, 106 root, 107 keyguardControllerState 108 ) 109 } 110 } 111