1 /*
2  * Copyright (C) 2020 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.internal.inputmethod;
18 
19 import static java.lang.annotation.RetentionPolicy.SOURCE;
20 
21 import android.annotation.IntDef;
22 import android.os.IBinder;
23 import android.view.WindowManager;
24 import android.view.WindowManager.LayoutParams;
25 import android.view.inputmethod.EditorInfo;
26 import android.view.inputmethod.ImeProtoEnums;
27 import android.view.inputmethod.InputMethodManager;
28 
29 import java.lang.annotation.Retention;
30 
31 /**
32  * Describes the reason why Soft input window visible / hidden.
33  */
34 @Retention(SOURCE)
35 @IntDef(value = {
36         SoftInputShowHideReason.SHOW_SOFT_INPUT,
37         SoftInputShowHideReason.ATTACH_NEW_INPUT,
38         SoftInputShowHideReason.SHOW_SOFT_INPUT_FROM_IME,
39         SoftInputShowHideReason.HIDE_SOFT_INPUT,
40         SoftInputShowHideReason.HIDE_SOFT_INPUT_FROM_IME,
41         SoftInputShowHideReason.SHOW_AUTO_EDITOR_FORWARD_NAV,
42         SoftInputShowHideReason.SHOW_STATE_VISIBLE_FORWARD_NAV,
43         SoftInputShowHideReason.SHOW_STATE_ALWAYS_VISIBLE,
44         SoftInputShowHideReason.SHOW_SETTINGS_ON_CHANGE,
45         SoftInputShowHideReason.HIDE_SWITCH_USER,
46         SoftInputShowHideReason.HIDE_INVALID_USER,
47         SoftInputShowHideReason.HIDE_UNSPECIFIED_WINDOW,
48         SoftInputShowHideReason.HIDE_STATE_HIDDEN_FORWARD_NAV,
49         SoftInputShowHideReason.HIDE_ALWAYS_HIDDEN_STATE,
50         SoftInputShowHideReason.HIDE_RESET_SHELL_COMMAND,
51         SoftInputShowHideReason.HIDE_SETTINGS_ON_CHANGE,
52         SoftInputShowHideReason.HIDE_POWER_BUTTON_GO_HOME,
53         SoftInputShowHideReason.HIDE_DOCKED_STACK_ATTACHED,
54         SoftInputShowHideReason.HIDE_RECENTS_ANIMATION,
55         SoftInputShowHideReason.HIDE_BUBBLES,
56         SoftInputShowHideReason.HIDE_SAME_WINDOW_FOCUSED_WITHOUT_EDITOR,
57         SoftInputShowHideReason.HIDE_REMOVE_CLIENT,
58         SoftInputShowHideReason.SHOW_RESTORE_IME_VISIBILITY,
59         SoftInputShowHideReason.SHOW_TOGGLE_SOFT_INPUT,
60         SoftInputShowHideReason.HIDE_TOGGLE_SOFT_INPUT,
61         SoftInputShowHideReason.SHOW_SOFT_INPUT_BY_INSETS_API,
62         SoftInputShowHideReason.HIDE_DISPLAY_IME_POLICY_HIDE,
63         SoftInputShowHideReason.HIDE_SOFT_INPUT_BY_INSETS_API,
64         SoftInputShowHideReason.HIDE_SOFT_INPUT_BY_BACK_KEY,
65         SoftInputShowHideReason.HIDE_SOFT_INPUT_IME_TOGGLE_SOFT_INPUT,
66         SoftInputShowHideReason.HIDE_SOFT_INPUT_EXTRACT_INPUT_CHANGED,
67         SoftInputShowHideReason.HIDE_SOFT_INPUT_IMM_DEPRECATION,
68         SoftInputShowHideReason.HIDE_WINDOW_GAINED_FOCUS_WITHOUT_EDITOR,
69         SoftInputShowHideReason.SHOW_IME_SCREENSHOT_FROM_IMMS,
70         SoftInputShowHideReason.REMOVE_IME_SCREENSHOT_FROM_IMMS,
71         SoftInputShowHideReason.HIDE_WHEN_INPUT_TARGET_INVISIBLE,
72 })
73 public @interface SoftInputShowHideReason {
74     /** Show soft input by {@link android.view.inputmethod.InputMethodManager#showSoftInput}. */
75     int SHOW_SOFT_INPUT = ImeProtoEnums.REASON_SHOW_SOFT_INPUT;
76 
77     /** Show soft input when {@code InputMethodManagerService#attachNewInputLocked} called. */
78     int ATTACH_NEW_INPUT = ImeProtoEnums.REASON_ATTACH_NEW_INPUT;
79 
80     /** Show soft input by {@code InputMethodManagerService#showMySoftInput}. This is triggered when
81      *  the IME process try to show the keyboard.
82      *
83      * @see android.inputmethodservice.InputMethodService#requestShowSelf(int)
84      */
85     int SHOW_SOFT_INPUT_FROM_IME = ImeProtoEnums.REASON_SHOW_SOFT_INPUT_FROM_IME;
86 
87     /**
88      * Hide soft input by
89      * {@link android.view.inputmethod.InputMethodManager#hideSoftInputFromWindow}.
90      */
91     int HIDE_SOFT_INPUT = ImeProtoEnums.REASON_HIDE_SOFT_INPUT;
92 
93     /**
94      * Hide soft input by
95      * {@link android.inputmethodservice.InputMethodService#requestHideSelf(int)}.
96      */
97     int HIDE_SOFT_INPUT_FROM_IME = ImeProtoEnums.REASON_HIDE_SOFT_INPUT_FROM_IME;
98 
99     /**
100      * Show soft input when navigated forward to the window (with
101      * {@link LayoutParams#SOFT_INPUT_IS_FORWARD_NAVIGATION}) which the focused view is text
102      * editor and system will auto-show the IME when the window can resize or running on a large
103      * screen.
104      */
105     int SHOW_AUTO_EDITOR_FORWARD_NAV = ImeProtoEnums.REASON_SHOW_AUTO_EDITOR_FORWARD_NAV;
106 
107     /**
108      * Show soft input when navigated forward to the window with
109      * {@link LayoutParams#SOFT_INPUT_IS_FORWARD_NAVIGATION} and
110      * {@link LayoutParams#SOFT_INPUT_STATE_VISIBLE}.
111      */
112     int SHOW_STATE_VISIBLE_FORWARD_NAV = ImeProtoEnums.REASON_SHOW_STATE_VISIBLE_FORWARD_NAV;
113 
114     /**
115      * Show soft input when the window with {@link LayoutParams#SOFT_INPUT_STATE_ALWAYS_VISIBLE}.
116      */
117     int SHOW_STATE_ALWAYS_VISIBLE = ImeProtoEnums.REASON_SHOW_STATE_ALWAYS_VISIBLE;
118 
119     /**
120      * Show soft input during {@code InputMethodManagerService} receive changes from
121      * {@code SettingsProvider}.
122      */
123     int SHOW_SETTINGS_ON_CHANGE = ImeProtoEnums.REASON_SHOW_SETTINGS_ON_CHANGE;
124 
125     /** Hide soft input during switching user. */
126     int HIDE_SWITCH_USER = ImeProtoEnums.REASON_HIDE_SWITCH_USER;
127 
128     /** Hide soft input when the user is invalid. */
129     int HIDE_INVALID_USER = ImeProtoEnums.REASON_HIDE_INVALID_USER;
130 
131     /**
132      * Hide soft input when the window with {@link LayoutParams#SOFT_INPUT_STATE_UNSPECIFIED} which
133      * the focused view is not text editor.
134      */
135     int HIDE_UNSPECIFIED_WINDOW = ImeProtoEnums.REASON_HIDE_UNSPECIFIED_WINDOW;
136 
137     /**
138      * Hide soft input when navigated forward to the window with
139      * {@link LayoutParams#SOFT_INPUT_IS_FORWARD_NAVIGATION} and
140      * {@link LayoutParams#SOFT_INPUT_STATE_HIDDEN}.
141      */
142     int HIDE_STATE_HIDDEN_FORWARD_NAV = ImeProtoEnums.REASON_HIDE_STATE_HIDDEN_FORWARD_NAV;
143 
144     /**
145      * Hide soft input when the window with {@link LayoutParams#SOFT_INPUT_STATE_ALWAYS_HIDDEN}.
146      */
147     int HIDE_ALWAYS_HIDDEN_STATE = ImeProtoEnums.REASON_HIDE_ALWAYS_HIDDEN_STATE;
148 
149     /** Hide soft input when "adb shell ime <command>" called. */
150     int HIDE_RESET_SHELL_COMMAND = ImeProtoEnums.REASON_HIDE_RESET_SHELL_COMMAND;
151 
152     /**
153      * Hide soft input during {@code InputMethodManagerService} receive changes from
154      * {@code SettingsProvider}.
155      */
156     int HIDE_SETTINGS_ON_CHANGE = ImeProtoEnums.REASON_HIDE_SETTINGS_ON_CHANGE;
157 
158     /**
159      * Hide soft input from {@link com.android.server.policy.PhoneWindowManager} when setting
160      * {@link com.android.internal.R.integer#config_shortPressOnPowerBehavior} in config.xml as
161      * dismiss IME.
162      */
163     int HIDE_POWER_BUTTON_GO_HOME = ImeProtoEnums.REASON_HIDE_POWER_BUTTON_GO_HOME;
164 
165     /** Hide soft input when attaching docked stack. */
166     int HIDE_DOCKED_STACK_ATTACHED = ImeProtoEnums.REASON_HIDE_DOCKED_STACK_ATTACHED;
167 
168     /**
169      * Hide soft input when {@link com.android.server.wm.RecentsAnimationController} starts
170      * intercept touch from app window.
171      */
172     int HIDE_RECENTS_ANIMATION = ImeProtoEnums.REASON_HIDE_RECENTS_ANIMATION;
173 
174     /**
175      * Hide soft input when {@link com.android.wm.shell.bubbles.BubbleController} is expanding,
176      * switching, or collapsing Bubbles.
177      */
178     int HIDE_BUBBLES = ImeProtoEnums.REASON_HIDE_BUBBLES;
179 
180     /**
181      * Hide soft input when focusing the same window (e.g. screen turned-off and turn-on) which no
182      * valid focused editor.
183      *
184      * Note: From Android R, the window focus change callback is processed by InputDispatcher,
185      * some focus behavior changes (e.g. There are an activity with a dialog window, after
186      * screen turned-off and turned-on, before Android R the window focus sequence would be
187      * the activity first and then the dialog focused, however, in R the focus sequence would be
188      * only the dialog focused as it's the latest window with input focus) makes we need to hide
189      * soft-input when the same window focused again to align with the same behavior prior to R.
190      */
191     int HIDE_SAME_WINDOW_FOCUSED_WITHOUT_EDITOR =
192             ImeProtoEnums.REASON_HIDE_SAME_WINDOW_FOCUSED_WITHOUT_EDITOR;
193 
194     /**
195      * Hide soft input when a {@link com.android.internal.inputmethod.IInputMethodClient} is
196      * removed.
197      */
198     int HIDE_REMOVE_CLIENT = ImeProtoEnums.REASON_HIDE_REMOVE_CLIENT;
199 
200     /**
201      * Show soft input when the system invoking
202      * {@link com.android.server.wm.WindowManagerInternal#shouldRestoreImeVisibility}.
203      */
204     int SHOW_RESTORE_IME_VISIBILITY = ImeProtoEnums.REASON_SHOW_RESTORE_IME_VISIBILITY;
205 
206     /**
207      * Show soft input by
208      * {@link android.view.inputmethod.InputMethodManager#toggleSoftInput(int, int)};
209      */
210     int SHOW_TOGGLE_SOFT_INPUT = ImeProtoEnums.REASON_SHOW_TOGGLE_SOFT_INPUT;
211 
212     /**
213      * Hide soft input by
214      * {@link android.view.inputmethod.InputMethodManager#toggleSoftInput(int, int)};
215      */
216     int HIDE_TOGGLE_SOFT_INPUT = ImeProtoEnums.REASON_HIDE_TOGGLE_SOFT_INPUT;
217 
218     /**
219      * Show soft input by
220      * {@link android.view.InsetsController#show(int)};
221      */
222     int SHOW_SOFT_INPUT_BY_INSETS_API = ImeProtoEnums.REASON_SHOW_SOFT_INPUT_BY_INSETS_API;
223 
224     /**
225      * Hide soft input if Ime policy has been set to {@link WindowManager#DISPLAY_IME_POLICY_HIDE}.
226      * See also {@code InputMethodManagerService#mImeHiddenByDisplayPolicy}.
227      */
228     int HIDE_DISPLAY_IME_POLICY_HIDE = ImeProtoEnums.REASON_HIDE_DISPLAY_IME_POLICY_HIDE;
229 
230     /**
231      * Hide soft input by {@link android.view.InsetsController#hide(int)}.
232      */
233     int HIDE_SOFT_INPUT_BY_INSETS_API = ImeProtoEnums.REASON_HIDE_SOFT_INPUT_BY_INSETS_API;
234 
235     /**
236      * Hide soft input by {@link android.inputmethodservice.InputMethodService#handleBack(boolean)}.
237      */
238     int HIDE_SOFT_INPUT_BY_BACK_KEY = ImeProtoEnums.REASON_HIDE_SOFT_INPUT_BY_BACK_KEY;
239 
240     /**
241      * Hide soft input by
242      * {@link android.inputmethodservice.InputMethodService#onToggleSoftInput(int, int)}.
243      */
244     int HIDE_SOFT_INPUT_IME_TOGGLE_SOFT_INPUT =
245             ImeProtoEnums.REASON_HIDE_SOFT_INPUT_IME_TOGGLE_SOFT_INPUT;
246 
247     /**
248      * Hide soft input by
249      * {@link android.inputmethodservice.InputMethodService#onExtractingInputChanged(EditorInfo)})}.
250      */
251     int HIDE_SOFT_INPUT_EXTRACT_INPUT_CHANGED =
252             ImeProtoEnums.REASON_HIDE_SOFT_INPUT_EXTRACT_INPUT_CHANGED;
253 
254     /**
255      * Hide soft input by the deprecated
256      * {@link InputMethodManager#hideSoftInputFromInputMethod(IBinder, int)}.
257      */
258     int HIDE_SOFT_INPUT_IMM_DEPRECATION = ImeProtoEnums.REASON_HIDE_SOFT_INPUT_IMM_DEPRECATION;
259 
260     /**
261      * Hide soft input when the window gained focus without an editor from the IME shown window.
262      */
263     int HIDE_WINDOW_GAINED_FOCUS_WITHOUT_EDITOR =
264             ImeProtoEnums.REASON_HIDE_WINDOW_GAINED_FOCUS_WITHOUT_EDITOR;
265 
266     /**
267      * Shows ime screenshot by {@link com.android.server.inputmethod.InputMethodManagerService}.
268      */
269     int SHOW_IME_SCREENSHOT_FROM_IMMS = ImeProtoEnums.REASON_SHOW_IME_SCREENSHOT_FROM_IMMS;
270 
271     /**
272      * Removes ime screenshot by {@link com.android.server.inputmethod.InputMethodManagerService}.
273      */
274     int REMOVE_IME_SCREENSHOT_FROM_IMMS = ImeProtoEnums.REASON_REMOVE_IME_SCREENSHOT_FROM_IMMS;
275 
276     /**
277      * Hide soft input when the input target being removed or being obscured by an non-IME
278      * focusable overlay window.
279      */
280     int HIDE_WHEN_INPUT_TARGET_INVISIBLE = ImeProtoEnums.REASON_HIDE_WHEN_INPUT_TARGET_INVISIBLE;
281 }
282