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 package com.android.server.inputmethod; 18 19 import android.annotation.NonNull; 20 import android.annotation.UserIdInt; 21 import android.os.IBinder; 22 import android.os.ResultReceiver; 23 import android.view.inputmethod.ImeTracker; 24 import android.view.inputmethod.InputMethod; 25 26 import com.android.internal.inputmethod.SoftInputShowHideReason; 27 28 /** 29 * Interface for IME visibility operations like show/hide and update Z-ordering relative to the IME 30 * targeted window. 31 */ 32 interface ImeVisibilityApplier { 33 /** 34 * Performs showing IME on top of the given window. 35 * 36 * @param showInputToken A token that represents the requester to show IME. 37 * @param statsToken The token tracking the current IME request. 38 * @param resultReceiver If non-null, this will be called back to the caller when 39 * it has processed request to tell what it has done. 40 * @param reason The reason for requesting to show IME. 41 */ performShowIme(IBinder showInputToken, @NonNull ImeTracker.Token statsToken, @InputMethod.ShowFlags int showFlags, ResultReceiver resultReceiver, @SoftInputShowHideReason int reason)42 default void performShowIme(IBinder showInputToken, @NonNull ImeTracker.Token statsToken, 43 @InputMethod.ShowFlags int showFlags, ResultReceiver resultReceiver, 44 @SoftInputShowHideReason int reason) {} 45 46 /** 47 * Performs hiding IME to the given window 48 * 49 * @param hideInputToken A token that represents the requester to hide IME. 50 * @param statsToken The token tracking the current IME request. 51 * @param resultReceiver If non-null, this will be called back to the caller when 52 * it has processed request to tell what it has done. 53 * @param reason The reason for requesting to hide IME. 54 */ performHideIme(IBinder hideInputToken, @NonNull ImeTracker.Token statsToken, ResultReceiver resultReceiver, @SoftInputShowHideReason int reason)55 default void performHideIme(IBinder hideInputToken, @NonNull ImeTracker.Token statsToken, 56 ResultReceiver resultReceiver, @SoftInputShowHideReason int reason) {} 57 58 /** 59 * Applies the IME visibility from {@link android.inputmethodservice.InputMethodService} with 60 * according to the given visibility state. 61 * 62 * @param windowToken The token of a window for applying the IME visibility 63 * @param statsToken The token tracking the current IME request. 64 * @param state The new IME visibility state for the applier to handle 65 */ applyImeVisibility(IBinder windowToken, @NonNull ImeTracker.Token statsToken, @ImeVisibilityStateComputer.VisibilityState int state, @UserIdInt int userId)66 default void applyImeVisibility(IBinder windowToken, @NonNull ImeTracker.Token statsToken, 67 @ImeVisibilityStateComputer.VisibilityState int state, @UserIdInt int userId) {} 68 69 /** 70 * Updates the IME Z-ordering relative to the given window. 71 * 72 * This used to adjust the IME relative layer of the window during 73 * {@link InputMethodManagerService} is in switching IME clients. 74 * 75 * @param windowToken The token of a window to update the Z-ordering relative to the IME. 76 */ updateImeLayeringByTarget(IBinder windowToken)77 default void updateImeLayeringByTarget(IBinder windowToken) { 78 // TODO: add a method in WindowManagerInternal to call DC#updateImeInputAndControlTarget 79 // here to end up updating IME layering after IMMS#attachNewInputLocked called. 80 } 81 82 /** 83 * Shows the IME screenshot and attach it to the given IME target window. 84 * 85 * @param windowToken The token of a window to show the IME screenshot. 86 * @param displayId The unique id to identify the display 87 * @return {@code true} if success, {@code false} otherwise. 88 */ showImeScreenshot(@onNull IBinder windowToken, int displayId)89 default boolean showImeScreenshot(@NonNull IBinder windowToken, int displayId) { 90 return false; 91 } 92 93 /** 94 * Removes the IME screenshot on the given display. 95 * 96 * @param displayId The target display of showing IME screenshot. 97 * @return {@code true} if success, {@code false} otherwise. 98 */ removeImeScreenshot(int displayId)99 default boolean removeImeScreenshot(int displayId) { 100 return false; 101 } 102 } 103