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 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 18 package com.android.systemui.keyguard.data.repository 19 20 import android.content.Context 21 import androidx.collection.ArrayMap 22 import com.android.internal.statusbar.StatusBarIcon 23 import com.android.systemui.dagger.SysUISingleton 24 import com.android.systemui.settings.DisplayTracker 25 import com.android.systemui.statusbar.CommandQueue 26 import dagger.Binds 27 import dagger.Module 28 import javax.inject.Inject 29 import org.mockito.Mockito.mock 30 31 @SysUISingleton 32 class FakeCommandQueue @Inject constructor() : 33 CommandQueue(mock(Context::class.java), mock(DisplayTracker::class.java)) { 34 private val callbacks = mutableListOf<Callbacks>() 35 36 val icons = ArrayMap<String, StatusBarIcon>() 37 38 private val perDisplayDisableFlags1 = mutableMapOf<Int, Int>() 39 private val perDisplayDisableFlags2 = mutableMapOf<Int, Int>() 40 addCallbacknull41 override fun addCallback(callback: Callbacks) { 42 callbacks.add(callback) 43 } 44 removeCallbacknull45 override fun removeCallback(callback: Callbacks) { 46 callbacks.remove(callback) 47 } 48 doForEachCallbacknull49 fun doForEachCallback(func: (callback: Callbacks) -> Unit) { 50 callbacks.forEach { func(it) } 51 } 52 callbackCountnull53 fun callbackCount(): Int = callbacks.size 54 55 override fun setIcon(slot: String, icon: StatusBarIcon) { 56 icons[slot] = icon 57 } 58 disablenull59 override fun disable(displayId: Int, state1: Int, state2: Int, animate: Boolean) { 60 perDisplayDisableFlags1[displayId] = state1 61 perDisplayDisableFlags2[displayId] = state2 62 } 63 disablenull64 override fun disable(displayId: Int, state1: Int, state2: Int) { 65 disable(displayId, state1, state2, /* animate= */ false) 66 } 67 disableFlags1ForDisplaynull68 fun disableFlags1ForDisplay(displayId: Int) = perDisplayDisableFlags1[displayId] 69 70 fun disableFlags2ForDisplay(displayId: Int) = perDisplayDisableFlags2[displayId] 71 } 72 73 @Module 74 interface FakeCommandQueueModule { 75 @Binds fun bindFake(fake: FakeCommandQueue): CommandQueue 76 } 77