1 /* 2 * Copyright (C) 2021 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.statusbar.phone; 18 19 import androidx.annotation.NonNull; 20 21 import com.android.keyguard.KeyguardViewController; 22 import com.android.systemui.Dumpable; 23 import com.android.systemui.dagger.SysUISingleton; 24 import com.android.systemui.dump.DumpManager; 25 26 import java.io.PrintWriter; 27 import java.util.HashSet; 28 import java.util.Set; 29 30 import javax.inject.Inject; 31 32 /** 33 * Register dialogs to this manager if extraneous affordances (like the UDFPS sensor area) 34 * should be hidden from the screen when the dialog shows. 35 * 36 * Currently, only used if UDFPS is supported on the device; however, can be extended in the future 37 * for other use cases. 38 */ 39 @SysUISingleton 40 public class SystemUIDialogManager implements Dumpable { 41 private final KeyguardViewController mKeyguardViewController; 42 43 private final Set<SystemUIDialog> mDialogsShowing = new HashSet<>(); 44 private final Set<Listener> mListeners = new HashSet<>(); 45 46 @Inject SystemUIDialogManager( DumpManager dumpManager, KeyguardViewController keyguardViewController)47 public SystemUIDialogManager( 48 DumpManager dumpManager, 49 KeyguardViewController keyguardViewController) { 50 dumpManager.registerDumpable(this); 51 mKeyguardViewController = keyguardViewController; 52 } 53 54 /** 55 * Whether listeners should hide affordances like the UDFPS sensor icon. 56 */ shouldHideAffordance()57 public boolean shouldHideAffordance() { 58 return !mDialogsShowing.isEmpty(); 59 } 60 61 /** 62 * Register a listener to receive callbacks. 63 */ registerListener(@onNull Listener listener)64 public void registerListener(@NonNull Listener listener) { 65 mListeners.add(listener); 66 } 67 68 /** 69 * Unregister a listener from receiving callbacks. 70 */ unregisterListener(@onNull Listener listener)71 public void unregisterListener(@NonNull Listener listener) { 72 mListeners.remove(listener); 73 } 74 setShowing(SystemUIDialog dialog, boolean showing)75 void setShowing(SystemUIDialog dialog, boolean showing) { 76 final boolean wasHidingAffordances = shouldHideAffordance(); 77 if (showing) { 78 mDialogsShowing.add(dialog); 79 } else { 80 mDialogsShowing.remove(dialog); 81 } 82 83 if (wasHidingAffordances != shouldHideAffordance()) { 84 updateDialogListeners(); 85 } 86 } 87 updateDialogListeners()88 private void updateDialogListeners() { 89 if (shouldHideAffordance()) { 90 mKeyguardViewController.hideAlternateBouncer(true); 91 } 92 93 for (Listener listener : mListeners) { 94 listener.shouldHideAffordances(shouldHideAffordance()); 95 } 96 } 97 98 @Override dump(@onNull PrintWriter pw, @NonNull String[] args)99 public void dump(@NonNull PrintWriter pw, @NonNull String[] args) { 100 pw.println("listeners:"); 101 for (Listener listener : mListeners) { 102 pw.println("\t" + listener); 103 } 104 pw.println("dialogs tracked:"); 105 for (SystemUIDialog dialog : mDialogsShowing) { 106 pw.println("\t" + dialog); 107 } 108 } 109 110 /** SystemUIDialogManagerListener */ 111 public interface Listener { 112 /** 113 * Callback where shouldHide=true if listeners should hide their views that may overlap 114 * a showing dialog. 115 */ shouldHideAffordances(boolean shouldHide)116 void shouldHideAffordances(boolean shouldHide); 117 } 118 } 119