Yohei Yukawa | fa6e0a8 | 2015-07-23 15:08:59 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2015 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 | |
Yohei Yukawa | c3de83e | 2018-08-28 16:09:34 -0700 | [diff] [blame] | 17 | package com.android.server.inputmethod; |
Yohei Yukawa | fa6e0a8 | 2015-07-23 15:08:59 -0700 | [diff] [blame] | 18 | |
Yohei Yukawa | a878b95 | 2019-01-10 19:36:24 -0800 | [diff] [blame] | 19 | import android.annotation.NonNull; |
| 20 | import android.annotation.UserIdInt; |
Adam He | bc67f2e | 2019-11-13 14:34:56 -0800 | [diff] [blame] | 21 | import android.content.ComponentName; |
Adam He | bc67f2e | 2019-11-13 14:34:56 -0800 | [diff] [blame] | 22 | import android.view.autofill.AutofillId; |
| 23 | import android.view.inputmethod.InlineSuggestionsRequest; |
Yohei Yukawa | a878b95 | 2019-01-10 19:36:24 -0800 | [diff] [blame] | 24 | import android.view.inputmethod.InputMethodInfo; |
| 25 | |
Adam He | bc67f2e | 2019-11-13 14:34:56 -0800 | [diff] [blame] | 26 | import com.android.internal.view.IInlineSuggestionsRequestCallback; |
Yohei Yukawa | a878b95 | 2019-01-10 19:36:24 -0800 | [diff] [blame] | 27 | import com.android.server.LocalServices; |
| 28 | |
| 29 | import java.util.Collections; |
| 30 | import java.util.List; |
Tarandeep Singh | 89a6c48 | 2017-11-21 14:26:11 -0800 | [diff] [blame] | 31 | |
Yohei Yukawa | fa6e0a8 | 2015-07-23 15:08:59 -0700 | [diff] [blame] | 32 | /** |
| 33 | * Input method manager local system service interface. |
Yohei Yukawa | fa6e0a8 | 2015-07-23 15:08:59 -0700 | [diff] [blame] | 34 | */ |
Yohei Yukawa | e24ed79 | 2018-08-28 19:10:32 -0700 | [diff] [blame] | 35 | public abstract class InputMethodManagerInternal { |
| 36 | /** |
Yohei Yukawa | fa6e0a8 | 2015-07-23 15:08:59 -0700 | [diff] [blame] | 37 | * Called by the power manager to tell the input method manager whether it |
| 38 | * should start watching for wake events. |
| 39 | */ |
Yohei Yukawa | e24ed79 | 2018-08-28 19:10:32 -0700 | [diff] [blame] | 40 | public abstract void setInteractive(boolean interactive); |
Yohei Yukawa | ae61f71 | 2015-12-09 13:00:10 -0800 | [diff] [blame] | 41 | |
| 42 | /** |
Jorim Jaggi | 3c5d0f1 | 2016-05-24 19:04:30 -0700 | [diff] [blame] | 43 | * Hides the current input method, if visible. |
| 44 | */ |
Yohei Yukawa | e24ed79 | 2018-08-28 19:10:32 -0700 | [diff] [blame] | 45 | public abstract void hideCurrentInputMethod(); |
Tarandeep Singh | 89a6c48 | 2017-11-21 14:26:11 -0800 | [diff] [blame] | 46 | |
| 47 | /** |
Yohei Yukawa | a878b95 | 2019-01-10 19:36:24 -0800 | [diff] [blame] | 48 | * Returns the list of installed input methods for the specified user. |
| 49 | * |
| 50 | * @param userId The user ID to be queried. |
| 51 | * @return A list of {@link InputMethodInfo}. VR-only IMEs are already excluded. |
| 52 | */ |
| 53 | public abstract List<InputMethodInfo> getInputMethodListAsUser(@UserIdInt int userId); |
| 54 | |
| 55 | /** |
| 56 | * Returns the list of installed input methods that are enabled for the specified user. |
| 57 | * |
| 58 | * @param userId The user ID to be queried. |
| 59 | * @return A list of {@link InputMethodInfo} that are enabled for {@code userId}. |
| 60 | */ |
| 61 | public abstract List<InputMethodInfo> getEnabledInputMethodListAsUser(@UserIdInt int userId); |
| 62 | |
| 63 | /** |
Adam He | bc67f2e | 2019-11-13 14:34:56 -0800 | [diff] [blame] | 64 | * Called by the Autofill Frameworks to request an {@link InlineSuggestionsRequest} from |
| 65 | * the input method. |
| 66 | * |
| 67 | * @param componentName {@link ComponentName} of current app/activity. |
| 68 | * @param autofillId {@link AutofillId} of currently focused field. |
| 69 | * @param cb {@link IInlineSuggestionsRequestCallback} used to pass back the request object. |
| 70 | */ |
Feng Cao | 16b2de5 | 2020-01-09 17:27:27 -0800 | [diff] [blame] | 71 | public abstract void onCreateInlineSuggestionsRequest(@UserIdInt int userId, |
| 72 | ComponentName componentName, AutofillId autofillId, |
| 73 | IInlineSuggestionsRequestCallback cb); |
Adam He | bc67f2e | 2019-11-13 14:34:56 -0800 | [diff] [blame] | 74 | |
| 75 | /** |
mincheli | 850892b | 2019-12-05 19:47:59 +0800 | [diff] [blame] | 76 | * Force switch to the enabled input method by {@code imeId} for current user. If the input |
| 77 | * method with {@code imeId} is not enabled or not installed, do nothing. |
| 78 | * |
| 79 | * @param imeId The input method ID to be switched to. |
| 80 | * @param userId The user ID to be queried. |
| 81 | * @return {@code true} if the current input method was successfully switched to the input |
| 82 | * method by {@code imeId}; {@code false} the input method with {@code imeId} is not available |
| 83 | * to be switched. |
| 84 | */ |
| 85 | public abstract boolean switchToInputMethod(String imeId, @UserIdInt int userId); |
| 86 | |
| 87 | /** |
Yohei Yukawa | e24ed79 | 2018-08-28 19:10:32 -0700 | [diff] [blame] | 88 | * Fake implementation of {@link InputMethodManagerInternal}. All the methods do nothing. |
| 89 | */ |
Yohei Yukawa | a878b95 | 2019-01-10 19:36:24 -0800 | [diff] [blame] | 90 | private static final InputMethodManagerInternal NOP = |
Yohei Yukawa | e24ed79 | 2018-08-28 19:10:32 -0700 | [diff] [blame] | 91 | new InputMethodManagerInternal() { |
| 92 | @Override |
Yohei Yukawa | e24ed79 | 2018-08-28 19:10:32 -0700 | [diff] [blame] | 93 | public void setInteractive(boolean interactive) { |
| 94 | } |
| 95 | |
| 96 | @Override |
| 97 | public void hideCurrentInputMethod() { |
| 98 | } |
| 99 | |
| 100 | @Override |
Yohei Yukawa | a878b95 | 2019-01-10 19:36:24 -0800 | [diff] [blame] | 101 | public List<InputMethodInfo> getInputMethodListAsUser(int userId) { |
| 102 | return Collections.emptyList(); |
| 103 | } |
| 104 | |
| 105 | @Override |
| 106 | public List<InputMethodInfo> getEnabledInputMethodListAsUser(int userId) { |
| 107 | return Collections.emptyList(); |
| 108 | } |
Adam He | bc67f2e | 2019-11-13 14:34:56 -0800 | [diff] [blame] | 109 | |
| 110 | @Override |
Feng Cao | 16b2de5 | 2020-01-09 17:27:27 -0800 | [diff] [blame] | 111 | public void onCreateInlineSuggestionsRequest(int userId, |
| 112 | ComponentName componentName, AutofillId autofillId, |
| 113 | IInlineSuggestionsRequestCallback cb) { |
Adam He | bc67f2e | 2019-11-13 14:34:56 -0800 | [diff] [blame] | 114 | } |
mincheli | 850892b | 2019-12-05 19:47:59 +0800 | [diff] [blame] | 115 | |
| 116 | @Override |
| 117 | public boolean switchToInputMethod(String imeId, int userId) { |
| 118 | return false; |
| 119 | } |
Yohei Yukawa | e24ed79 | 2018-08-28 19:10:32 -0700 | [diff] [blame] | 120 | }; |
Yohei Yukawa | a878b95 | 2019-01-10 19:36:24 -0800 | [diff] [blame] | 121 | |
| 122 | /** |
| 123 | * @return Global instance if exists. Otherwise, a dummy no-op instance. |
| 124 | */ |
| 125 | @NonNull |
| 126 | public static InputMethodManagerInternal get() { |
| 127 | final InputMethodManagerInternal instance = |
| 128 | LocalServices.getService(InputMethodManagerInternal.class); |
| 129 | return instance != null ? instance : NOP; |
| 130 | } |
Yohei Yukawa | fa6e0a8 | 2015-07-23 15:08:59 -0700 | [diff] [blame] | 131 | } |