blob: 9c421524d723d5a84d5162648d5fa82fd6ffd6c7 [file] [log] [blame]
Yohei Yukawafa6e0a82015-07-23 15:08:59 -07001/*
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 Yukawac3de83e2018-08-28 16:09:34 -070017package com.android.server.inputmethod;
Yohei Yukawafa6e0a82015-07-23 15:08:59 -070018
Yohei Yukawaa878b952019-01-10 19:36:24 -080019import android.annotation.NonNull;
20import android.annotation.UserIdInt;
Adam Hebc67f2e2019-11-13 14:34:56 -080021import android.content.ComponentName;
Adam Hebc67f2e2019-11-13 14:34:56 -080022import android.view.autofill.AutofillId;
23import android.view.inputmethod.InlineSuggestionsRequest;
Yohei Yukawaa878b952019-01-10 19:36:24 -080024import android.view.inputmethod.InputMethodInfo;
25
Adam Hebc67f2e2019-11-13 14:34:56 -080026import com.android.internal.view.IInlineSuggestionsRequestCallback;
Yohei Yukawaa878b952019-01-10 19:36:24 -080027import com.android.server.LocalServices;
28
29import java.util.Collections;
30import java.util.List;
Tarandeep Singh89a6c482017-11-21 14:26:11 -080031
Yohei Yukawafa6e0a82015-07-23 15:08:59 -070032/**
33 * Input method manager local system service interface.
Yohei Yukawafa6e0a82015-07-23 15:08:59 -070034 */
Yohei Yukawae24ed792018-08-28 19:10:32 -070035public abstract class InputMethodManagerInternal {
36 /**
Yohei Yukawafa6e0a82015-07-23 15:08:59 -070037 * Called by the power manager to tell the input method manager whether it
38 * should start watching for wake events.
39 */
Yohei Yukawae24ed792018-08-28 19:10:32 -070040 public abstract void setInteractive(boolean interactive);
Yohei Yukawaae61f712015-12-09 13:00:10 -080041
42 /**
Jorim Jaggi3c5d0f12016-05-24 19:04:30 -070043 * Hides the current input method, if visible.
44 */
Yohei Yukawae24ed792018-08-28 19:10:32 -070045 public abstract void hideCurrentInputMethod();
Tarandeep Singh89a6c482017-11-21 14:26:11 -080046
47 /**
Yohei Yukawaa878b952019-01-10 19:36:24 -080048 * 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 Hebc67f2e2019-11-13 14:34:56 -080064 * 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 Cao16b2de52020-01-09 17:27:27 -080071 public abstract void onCreateInlineSuggestionsRequest(@UserIdInt int userId,
72 ComponentName componentName, AutofillId autofillId,
73 IInlineSuggestionsRequestCallback cb);
Adam Hebc67f2e2019-11-13 14:34:56 -080074
75 /**
mincheli850892b2019-12-05 19:47:59 +080076 * 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 Yukawae24ed792018-08-28 19:10:32 -070088 * Fake implementation of {@link InputMethodManagerInternal}. All the methods do nothing.
89 */
Yohei Yukawaa878b952019-01-10 19:36:24 -080090 private static final InputMethodManagerInternal NOP =
Yohei Yukawae24ed792018-08-28 19:10:32 -070091 new InputMethodManagerInternal() {
92 @Override
Yohei Yukawae24ed792018-08-28 19:10:32 -070093 public void setInteractive(boolean interactive) {
94 }
95
96 @Override
97 public void hideCurrentInputMethod() {
98 }
99
100 @Override
Yohei Yukawaa878b952019-01-10 19:36:24 -0800101 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 Hebc67f2e2019-11-13 14:34:56 -0800109
110 @Override
Feng Cao16b2de52020-01-09 17:27:27 -0800111 public void onCreateInlineSuggestionsRequest(int userId,
112 ComponentName componentName, AutofillId autofillId,
113 IInlineSuggestionsRequestCallback cb) {
Adam Hebc67f2e2019-11-13 14:34:56 -0800114 }
mincheli850892b2019-12-05 19:47:59 +0800115
116 @Override
117 public boolean switchToInputMethod(String imeId, int userId) {
118 return false;
119 }
Yohei Yukawae24ed792018-08-28 19:10:32 -0700120 };
Yohei Yukawaa878b952019-01-10 19:36:24 -0800121
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 Yukawafa6e0a82015-07-23 15:08:59 -0700131}