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 17 package com.android.server.inputmethod; 18 19 import android.annotation.NonNull; 20 import android.annotation.UserIdInt; 21 import android.view.inputmethod.InputMethodInfo; 22 23 import com.android.server.LocalServices; 24 25 import java.util.Collections; 26 import java.util.List; 27 28 /** 29 * Input method manager local system service interface. 30 */ 31 public abstract class InputMethodManagerInternal { 32 /** 33 * Called by the power manager to tell the input method manager whether it 34 * should start watching for wake events. 35 */ setInteractive(boolean interactive)36 public abstract void setInteractive(boolean interactive); 37 38 /** 39 * Hides the current input method, if visible. 40 */ hideCurrentInputMethod()41 public abstract void hideCurrentInputMethod(); 42 43 /** 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 */ getInputMethodListAsUser(@serIdInt int userId)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 */ getEnabledInputMethodListAsUser(@serIdInt int userId)57 public abstract List<InputMethodInfo> getEnabledInputMethodListAsUser(@UserIdInt int userId); 58 59 /** 60 * Fake implementation of {@link InputMethodManagerInternal}. All the methods do nothing. 61 */ 62 private static final InputMethodManagerInternal NOP = 63 new InputMethodManagerInternal() { 64 @Override 65 public void setInteractive(boolean interactive) { 66 } 67 68 @Override 69 public void hideCurrentInputMethod() { 70 } 71 72 @Override 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 } 81 }; 82 83 /** 84 * @return Global instance if exists. Otherwise, a dummy no-op instance. 85 */ 86 @NonNull get()87 public static InputMethodManagerInternal get() { 88 final InputMethodManagerInternal instance = 89 LocalServices.getService(InputMethodManagerInternal.class); 90 return instance != null ? instance : NOP; 91 } 92 } 93