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; |
Yohei Yukawa | a878b95 | 2019-01-10 19:36:24 -0800 | [diff] [blame] | 21 | import android.view.inputmethod.InputMethodInfo; |
| 22 | |
| 23 | import com.android.server.LocalServices; |
| 24 | |
| 25 | import java.util.Collections; |
| 26 | import java.util.List; |
Tarandeep Singh | 89a6c48 | 2017-11-21 14:26:11 -0800 | [diff] [blame] | 27 | |
Yohei Yukawa | fa6e0a8 | 2015-07-23 15:08:59 -0700 | [diff] [blame] | 28 | /** |
| 29 | * Input method manager local system service interface. |
Yohei Yukawa | fa6e0a8 | 2015-07-23 15:08:59 -0700 | [diff] [blame] | 30 | */ |
Yohei Yukawa | e24ed79 | 2018-08-28 19:10:32 -0700 | [diff] [blame] | 31 | public abstract class InputMethodManagerInternal { |
| 32 | /** |
Yohei Yukawa | fa6e0a8 | 2015-07-23 15:08:59 -0700 | [diff] [blame] | 33 | * Called by the power manager to tell the input method manager whether it |
| 34 | * should start watching for wake events. |
| 35 | */ |
Yohei Yukawa | e24ed79 | 2018-08-28 19:10:32 -0700 | [diff] [blame] | 36 | public abstract void setInteractive(boolean interactive); |
Yohei Yukawa | ae61f71 | 2015-12-09 13:00:10 -0800 | [diff] [blame] | 37 | |
| 38 | /** |
Jorim Jaggi | 3c5d0f1 | 2016-05-24 19:04:30 -0700 | [diff] [blame] | 39 | * Hides the current input method, if visible. |
| 40 | */ |
Yohei Yukawa | e24ed79 | 2018-08-28 19:10:32 -0700 | [diff] [blame] | 41 | public abstract void hideCurrentInputMethod(); |
Tarandeep Singh | 89a6c48 | 2017-11-21 14:26:11 -0800 | [diff] [blame] | 42 | |
| 43 | /** |
Yohei Yukawa | a878b95 | 2019-01-10 19:36:24 -0800 | [diff] [blame] | 44 | * Returns the list of installed input methods for the specified user. |
| 45 | * |
| 46 | * @param userId The user ID to be queried. |
| 47 | * @return A list of {@link InputMethodInfo}. VR-only IMEs are already excluded. |
| 48 | */ |
| 49 | public abstract List<InputMethodInfo> getInputMethodListAsUser(@UserIdInt int userId); |
| 50 | |
| 51 | /** |
| 52 | * Returns the list of installed input methods that are enabled for the specified user. |
| 53 | * |
| 54 | * @param userId The user ID to be queried. |
| 55 | * @return A list of {@link InputMethodInfo} that are enabled for {@code userId}. |
| 56 | */ |
| 57 | public abstract List<InputMethodInfo> getEnabledInputMethodListAsUser(@UserIdInt int userId); |
| 58 | |
| 59 | /** |
Yohei Yukawa | e24ed79 | 2018-08-28 19:10:32 -0700 | [diff] [blame] | 60 | * Fake implementation of {@link InputMethodManagerInternal}. All the methods do nothing. |
| 61 | */ |
Yohei Yukawa | a878b95 | 2019-01-10 19:36:24 -0800 | [diff] [blame] | 62 | private static final InputMethodManagerInternal NOP = |
Yohei Yukawa | e24ed79 | 2018-08-28 19:10:32 -0700 | [diff] [blame] | 63 | new InputMethodManagerInternal() { |
| 64 | @Override |
Yohei Yukawa | e24ed79 | 2018-08-28 19:10:32 -0700 | [diff] [blame] | 65 | public void setInteractive(boolean interactive) { |
| 66 | } |
| 67 | |
| 68 | @Override |
| 69 | public void hideCurrentInputMethod() { |
| 70 | } |
| 71 | |
| 72 | @Override |
Yohei Yukawa | a878b95 | 2019-01-10 19:36:24 -0800 | [diff] [blame] | 73 | public List<InputMethodInfo> getInputMethodListAsUser(int userId) { |
| 74 | return Collections.emptyList(); |
| 75 | } |
| 76 | |
| 77 | @Override |
| 78 | public List<InputMethodInfo> getEnabledInputMethodListAsUser(int userId) { |
| 79 | return Collections.emptyList(); |
| 80 | } |
Yohei Yukawa | e24ed79 | 2018-08-28 19:10:32 -0700 | [diff] [blame] | 81 | }; |
Yohei Yukawa | a878b95 | 2019-01-10 19:36:24 -0800 | [diff] [blame] | 82 | |
| 83 | /** |
| 84 | * @return Global instance if exists. Otherwise, a dummy no-op instance. |
| 85 | */ |
| 86 | @NonNull |
| 87 | public static InputMethodManagerInternal get() { |
| 88 | final InputMethodManagerInternal instance = |
| 89 | LocalServices.getService(InputMethodManagerInternal.class); |
| 90 | return instance != null ? instance : NOP; |
| 91 | } |
Yohei Yukawa | fa6e0a8 | 2015-07-23 15:08:59 -0700 | [diff] [blame] | 92 | } |