1 /* 2 * 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.quickstep 18 19 import android.os.RemoteException 20 import android.util.Log 21 import com.android.launcher3.config.FeatureFlags 22 import com.android.launcher3.util.Executors 23 import com.android.wm.shell.shared.IHomeTransitionListener.Stub 24 import com.android.wm.shell.shared.IShellTransitions 25 26 /** Class to track visibility state of Launcher */ 27 class HomeVisibilityState { 28 29 var isHomeVisible = true 30 private set 31 32 private var listeners = mutableSetOf<VisibilityChangeListener>() 33 addListenernull34 fun addListener(l: VisibilityChangeListener) = listeners.add(l) 35 36 fun removeListener(l: VisibilityChangeListener) = listeners.remove(l) 37 38 fun init(transitions: IShellTransitions?) { 39 if (!FeatureFlags.enableHomeTransitionListener()) return 40 try { 41 transitions?.setHomeTransitionListener( 42 object : Stub() { 43 override fun onHomeVisibilityChanged(isVisible: Boolean) { 44 Executors.MAIN_EXECUTOR.execute { 45 isHomeVisible = isVisible 46 listeners.forEach { it.onHomeVisibilityChanged(isVisible) } 47 } 48 } 49 } 50 ) 51 } catch (e: RemoteException) { 52 Log.w(TAG, "Failed call setHomeTransitionListener", e) 53 } 54 } 55 56 interface VisibilityChangeListener { onHomeVisibilityChangednull57 fun onHomeVisibilityChanged(isVisible: Boolean) 58 } 59 60 override fun toString() = "{HomeVisibilityState isHomeVisible=$isHomeVisible}" 61 62 companion object { 63 64 private const val TAG = "HomeVisibilityState" 65 } 66 } 67