1 /* 2 * Copyright (C) 2019 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.server.wm; 18 19 import android.annotation.Nullable; 20 import android.inputmethodservice.InputMethodService; 21 import android.view.WindowInsets; 22 import android.view.WindowInsets.Type.InsetsType; 23 import android.view.inputmethod.ImeTracker; 24 25 /** 26 * Generalization of an object that can control insets state. 27 */ 28 interface InsetsControlTarget { 29 30 /** 31 * Notifies the control target that the insets control has changed. 32 * 33 * @param displayId the display hosting the window of this target 34 */ notifyInsetsControlChanged(int displayId)35 default void notifyInsetsControlChanged(int displayId) { 36 }; 37 38 /** 39 * @return {@link WindowState} of this target, if any. 40 */ getWindow()41 default WindowState getWindow() { 42 return null; 43 } 44 45 /** 46 * @return {@code true} if any of the {@link InsetsType} is requested visible by this target. 47 */ isRequestedVisible(@nsetsType int types)48 default boolean isRequestedVisible(@InsetsType int types) { 49 return (WindowInsets.Type.defaultVisible() & types) != 0; 50 } 51 52 /** 53 * @return {@link InsetsType}s which are requested visible by this target. 54 */ getRequestedVisibleTypes()55 default @InsetsType int getRequestedVisibleTypes() { 56 return WindowInsets.Type.defaultVisible(); 57 } 58 59 /** 60 * Instructs the control target to show inset sources. 61 * 62 * @param types to specify which types of insets source window should be shown. 63 * @param fromIme {@code true} if the IME request originated from {@link InputMethodService}. 64 * @param statsToken the token tracking the current IME request or {@code null} otherwise. 65 */ showInsets(@nsetsType int types, boolean fromIme, @Nullable ImeTracker.Token statsToken)66 default void showInsets(@InsetsType int types, boolean fromIme, 67 @Nullable ImeTracker.Token statsToken) { 68 } 69 70 /** 71 * Instructs the control target to hide inset sources. 72 * 73 * @param types to specify which types of insets source window should be hidden. 74 * @param fromIme {@code true} if the IME request originated from {@link InputMethodService}. 75 * @param statsToken the token tracking the current IME request or {@code null} otherwise. 76 */ hideInsets(@nsetsType int types, boolean fromIme, @Nullable ImeTracker.Token statsToken)77 default void hideInsets(@InsetsType int types, boolean fromIme, 78 @Nullable ImeTracker.Token statsToken) { 79 } 80 81 /** 82 * Returns {@code true} if the control target allows the system to show transient windows. 83 */ canShowTransient()84 default boolean canShowTransient() { 85 return false; 86 } 87 88 /** 89 * @param visible the requested visibility for the IME, used for 90 * {@link com.android.server.wm.DisplayContent.RemoteInsetsControlTarget} 91 */ setImeInputTargetRequestedVisibility(boolean visible)92 default void setImeInputTargetRequestedVisibility(boolean visible) { 93 } 94 95 /** Returns {@code target.getWindow()}, or null if {@code target} is {@code null}. */ asWindowOrNull(InsetsControlTarget target)96 static WindowState asWindowOrNull(InsetsControlTarget target) { 97 return target != null ? target.getWindow() : null; 98 } 99 } 100