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; |
lpeter | 133fce0 | 2020-03-05 20:32:16 +0800 | [diff] [blame] | 21 | import android.os.IBinder; |
Adam He | bc67f2e | 2019-11-13 14:34:56 -0800 | [diff] [blame] | 22 | import android.view.inputmethod.InlineSuggestionsRequest; |
Yohei Yukawa | a878b95 | 2019-01-10 19:36:24 -0800 | [diff] [blame] | 23 | import android.view.inputmethod.InputMethodInfo; |
| 24 | |
lumark | d85e158 | 2019-12-29 20:20:41 +0800 | [diff] [blame] | 25 | import com.android.internal.inputmethod.SoftInputShowHideReason; |
Adam He | bc67f2e | 2019-11-13 14:34:56 -0800 | [diff] [blame] | 26 | import com.android.internal.view.IInlineSuggestionsRequestCallback; |
Feng Cao | 36960ee | 2020-02-18 18:23:30 -0800 | [diff] [blame] | 27 | import com.android.internal.view.InlineSuggestionsRequestInfo; |
Yohei Yukawa | a878b95 | 2019-01-10 19:36:24 -0800 | [diff] [blame] | 28 | import com.android.server.LocalServices; |
| 29 | |
| 30 | import java.util.Collections; |
| 31 | import java.util.List; |
Tarandeep Singh | 89a6c48 | 2017-11-21 14:26:11 -0800 | [diff] [blame] | 32 | |
Yohei Yukawa | fa6e0a8 | 2015-07-23 15:08:59 -0700 | [diff] [blame] | 33 | /** |
| 34 | * Input method manager local system service interface. |
Yohei Yukawa | fa6e0a8 | 2015-07-23 15:08:59 -0700 | [diff] [blame] | 35 | */ |
Yohei Yukawa | e24ed79 | 2018-08-28 19:10:32 -0700 | [diff] [blame] | 36 | public abstract class InputMethodManagerInternal { |
| 37 | /** |
Yuichiro Hanada | 34c4c0e | 2020-01-15 16:53:07 +0900 | [diff] [blame] | 38 | * Listener for input method list changed events. |
| 39 | */ |
| 40 | public interface InputMethodListListener { |
| 41 | /** |
| 42 | * Called with the list of the installed IMEs when it's updated. |
| 43 | */ |
| 44 | void onInputMethodListUpdated(List<InputMethodInfo> info, @UserIdInt int userId); |
| 45 | } |
| 46 | |
| 47 | /** |
Ming-Shin Lu | 2c6e80b | 2020-05-13 00:12:26 +0800 | [diff] [blame] | 48 | * Called by the power manager to tell the input method manager whether it |
| 49 | * should start watching for wake events. |
| 50 | */ |
| 51 | public abstract void setInteractive(boolean interactive); |
| 52 | |
| 53 | /** |
Jorim Jaggi | 3c5d0f1 | 2016-05-24 19:04:30 -0700 | [diff] [blame] | 54 | * Hides the current input method, if visible. |
| 55 | */ |
lumark | d85e158 | 2019-12-29 20:20:41 +0800 | [diff] [blame] | 56 | public abstract void hideCurrentInputMethod(@SoftInputShowHideReason int reason); |
Tarandeep Singh | 89a6c48 | 2017-11-21 14:26:11 -0800 | [diff] [blame] | 57 | |
| 58 | /** |
Yohei Yukawa | a878b95 | 2019-01-10 19:36:24 -0800 | [diff] [blame] | 59 | * Returns the list of installed input methods for the specified user. |
| 60 | * |
| 61 | * @param userId The user ID to be queried. |
| 62 | * @return A list of {@link InputMethodInfo}. VR-only IMEs are already excluded. |
| 63 | */ |
| 64 | public abstract List<InputMethodInfo> getInputMethodListAsUser(@UserIdInt int userId); |
| 65 | |
| 66 | /** |
| 67 | * Returns the list of installed input methods that are enabled for the specified user. |
| 68 | * |
| 69 | * @param userId The user ID to be queried. |
| 70 | * @return A list of {@link InputMethodInfo} that are enabled for {@code userId}. |
| 71 | */ |
| 72 | public abstract List<InputMethodInfo> getEnabledInputMethodListAsUser(@UserIdInt int userId); |
| 73 | |
| 74 | /** |
Adam He | bc67f2e | 2019-11-13 14:34:56 -0800 | [diff] [blame] | 75 | * Called by the Autofill Frameworks to request an {@link InlineSuggestionsRequest} from |
| 76 | * the input method. |
| 77 | * |
Feng Cao | 36960ee | 2020-02-18 18:23:30 -0800 | [diff] [blame] | 78 | * @param requestInfo information needed to create an {@link InlineSuggestionsRequest}. |
Adam He | bc67f2e | 2019-11-13 14:34:56 -0800 | [diff] [blame] | 79 | * @param cb {@link IInlineSuggestionsRequestCallback} used to pass back the request object. |
| 80 | */ |
Feng Cao | 16b2de5 | 2020-01-09 17:27:27 -0800 | [diff] [blame] | 81 | public abstract void onCreateInlineSuggestionsRequest(@UserIdInt int userId, |
Feng Cao | 36960ee | 2020-02-18 18:23:30 -0800 | [diff] [blame] | 82 | InlineSuggestionsRequestInfo requestInfo, IInlineSuggestionsRequestCallback cb); |
Adam He | bc67f2e | 2019-11-13 14:34:56 -0800 | [diff] [blame] | 83 | |
| 84 | /** |
mincheli | 850892b | 2019-12-05 19:47:59 +0800 | [diff] [blame] | 85 | * Force switch to the enabled input method by {@code imeId} for current user. If the input |
| 86 | * method with {@code imeId} is not enabled or not installed, do nothing. |
| 87 | * |
| 88 | * @param imeId The input method ID to be switched to. |
| 89 | * @param userId The user ID to be queried. |
| 90 | * @return {@code true} if the current input method was successfully switched to the input |
| 91 | * method by {@code imeId}; {@code false} the input method with {@code imeId} is not available |
| 92 | * to be switched. |
| 93 | */ |
| 94 | public abstract boolean switchToInputMethod(String imeId, @UserIdInt int userId); |
| 95 | |
| 96 | /** |
Yuichiro Hanada | 34c4c0e | 2020-01-15 16:53:07 +0900 | [diff] [blame] | 97 | * Registers a new {@link InputMethodListListener}. |
| 98 | */ |
| 99 | public abstract void registerInputMethodListListener(InputMethodListListener listener); |
| 100 | |
| 101 | /** |
lpeter | 133fce0 | 2020-03-05 20:32:16 +0800 | [diff] [blame] | 102 | * Transfers input focus from a given input token to that of the IME window. |
| 103 | * |
| 104 | * @param sourceInputToken The source token. |
| 105 | * @param displayId The display hosting the IME window. |
| 106 | * @return {@code true} if the transfer is successful. |
| 107 | */ |
| 108 | public abstract boolean transferTouchFocusToImeWindow(@NonNull IBinder sourceInputToken, |
| 109 | int displayId); |
| 110 | |
| 111 | /** |
Yohei Yukawa | e24ed79 | 2018-08-28 19:10:32 -0700 | [diff] [blame] | 112 | * Fake implementation of {@link InputMethodManagerInternal}. All the methods do nothing. |
| 113 | */ |
Yohei Yukawa | a878b95 | 2019-01-10 19:36:24 -0800 | [diff] [blame] | 114 | private static final InputMethodManagerInternal NOP = |
Yohei Yukawa | e24ed79 | 2018-08-28 19:10:32 -0700 | [diff] [blame] | 115 | new InputMethodManagerInternal() { |
| 116 | @Override |
Ming-Shin Lu | 2c6e80b | 2020-05-13 00:12:26 +0800 | [diff] [blame] | 117 | public void setInteractive(boolean interactive) { |
| 118 | } |
| 119 | |
| 120 | @Override |
lumark | d85e158 | 2019-12-29 20:20:41 +0800 | [diff] [blame] | 121 | public void hideCurrentInputMethod(@SoftInputShowHideReason int reason) { |
Yohei Yukawa | e24ed79 | 2018-08-28 19:10:32 -0700 | [diff] [blame] | 122 | } |
| 123 | |
| 124 | @Override |
Yohei Yukawa | a878b95 | 2019-01-10 19:36:24 -0800 | [diff] [blame] | 125 | public List<InputMethodInfo> getInputMethodListAsUser(int userId) { |
| 126 | return Collections.emptyList(); |
| 127 | } |
| 128 | |
| 129 | @Override |
| 130 | public List<InputMethodInfo> getEnabledInputMethodListAsUser(int userId) { |
| 131 | return Collections.emptyList(); |
| 132 | } |
Adam He | bc67f2e | 2019-11-13 14:34:56 -0800 | [diff] [blame] | 133 | |
| 134 | @Override |
Feng Cao | 16b2de5 | 2020-01-09 17:27:27 -0800 | [diff] [blame] | 135 | public void onCreateInlineSuggestionsRequest(int userId, |
Feng Cao | 36960ee | 2020-02-18 18:23:30 -0800 | [diff] [blame] | 136 | InlineSuggestionsRequestInfo requestInfo, |
Feng Cao | 16b2de5 | 2020-01-09 17:27:27 -0800 | [diff] [blame] | 137 | IInlineSuggestionsRequestCallback cb) { |
Adam He | bc67f2e | 2019-11-13 14:34:56 -0800 | [diff] [blame] | 138 | } |
mincheli | 850892b | 2019-12-05 19:47:59 +0800 | [diff] [blame] | 139 | |
| 140 | @Override |
| 141 | public boolean switchToInputMethod(String imeId, int userId) { |
| 142 | return false; |
| 143 | } |
Yuichiro Hanada | 34c4c0e | 2020-01-15 16:53:07 +0900 | [diff] [blame] | 144 | |
| 145 | @Override |
| 146 | public void registerInputMethodListListener(InputMethodListListener listener) { |
| 147 | } |
lpeter | 133fce0 | 2020-03-05 20:32:16 +0800 | [diff] [blame] | 148 | |
| 149 | @Override |
| 150 | public boolean transferTouchFocusToImeWindow(@NonNull IBinder sourceInputToken, |
| 151 | int displayId) { |
| 152 | return false; |
| 153 | } |
Yohei Yukawa | e24ed79 | 2018-08-28 19:10:32 -0700 | [diff] [blame] | 154 | }; |
Yohei Yukawa | a878b95 | 2019-01-10 19:36:24 -0800 | [diff] [blame] | 155 | |
| 156 | /** |
| 157 | * @return Global instance if exists. Otherwise, a dummy no-op instance. |
| 158 | */ |
| 159 | @NonNull |
| 160 | public static InputMethodManagerInternal get() { |
| 161 | final InputMethodManagerInternal instance = |
| 162 | LocalServices.getService(InputMethodManagerInternal.class); |
| 163 | return instance != null ? instance : NOP; |
| 164 | } |
Yohei Yukawa | fa6e0a8 | 2015-07-23 15:08:59 -0700 | [diff] [blame] | 165 | } |