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