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 android.view
18
19 import android.graphics.Region
20 import com.android.systemui.kosmos.Kosmos
21 import org.mockito.ArgumentMatchers.anyInt
22 import org.mockito.Mockito.mock
23 import org.mockito.kotlin.any
24 import org.mockito.kotlin.whenever
25
26 val Kosmos.mockWindowManagerService: IWindowManager by
27 Kosmos.Fixture {
28 mock(IWindowManager::class.java).apply {
29 whenever(registerSystemGestureExclusionListener(any(), anyInt())).then { answer ->
30 val listener = answer.arguments[0] as ISystemGestureExclusionListener
31 val displayId = answer.arguments[1] as Int
32 exclusionListeners.getOrPut(displayId) { mutableListOf() }.add(listener)
33 listener.onSystemGestureExclusionChanged(
34 displayId,
35 restrictedRegionByDisplayId[displayId],
36 null,
37 )
38 }
39
40 whenever(unregisterSystemGestureExclusionListener(any(), anyInt())).then { answer ->
41 val listener = answer.arguments[0] as ISystemGestureExclusionListener
42 val displayId = answer.arguments[1] as Int
43 exclusionListeners[displayId]?.remove(listener)
44 }
45 }
46 }
47
<lambda>null48 var Kosmos.windowManagerService: IWindowManager by Kosmos.Fixture { mockWindowManagerService }
49
50 private var restrictedRegionByDisplayId = mutableMapOf<Int, Region?>()
51 private var exclusionListeners = mutableMapOf<Int, MutableList<ISystemGestureExclusionListener>>()
52
setSystemGestureExclusionRegionnull53 fun setSystemGestureExclusionRegion(displayId: Int, restrictedRegion: Region?) {
54 restrictedRegionByDisplayId[displayId] = restrictedRegion
55 exclusionListeners[displayId]?.forEach { listener ->
56 listener.onSystemGestureExclusionChanged(displayId, restrictedRegion, null)
57 }
58 }
59