1 /* <lambda>null2 * Copyright (C) 2024 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 com.android.systemui.jank 18 19 import android.os.HandlerThread 20 import android.os.fakeExecutorHandler 21 import android.view.View 22 import com.android.internal.jank.InteractionJankMonitor 23 import com.android.systemui.kosmos.Kosmos 24 import com.android.systemui.kosmos.Kosmos.Fixture 25 import org.mockito.Mockito 26 27 val Kosmos.interactionJankMonitor by 28 Fixture<InteractionJankMonitor> { 29 val worker = 30 Mockito.mock(HandlerThread::class.java).also { worker -> 31 Mockito.doAnswer { 32 fakeExecutorHandler.also { handler -> 33 Mockito.doAnswer { 34 // TODO(b/333927129): Should return `android.os.looper` instead 35 null 36 } 37 .`when`(handler) 38 .looper 39 } 40 } 41 .`when`(worker) 42 .threadHandler 43 } 44 45 // Return a `spy` so that tests can verify method calls 46 Mockito.spy( 47 object : InteractionJankMonitor(worker) { 48 override fun shouldMonitor(): Boolean = true 49 override fun begin(builder: Configuration.Builder): Boolean = true 50 override fun begin(v: View?, cujType: Int): Boolean = true 51 override fun end(cujType: Int): Boolean = true 52 override fun cancel(cujType: Int): Boolean = true 53 override fun cancel(cujType: Int, reason: Int) = true 54 } 55 ) 56 } 57