1 /* 2 * Copyright (C) 2022 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 android.view.inputmethod; 18 19 import android.Manifest; 20 import android.annotation.AnyThread; 21 import android.annotation.Nullable; 22 import android.annotation.RequiresNoPermission; 23 import android.annotation.RequiresPermission; 24 import android.os.RemoteException; 25 26 import com.android.internal.inputmethod.ImeTracing; 27 import com.android.internal.view.IInputMethodManager; 28 29 import java.util.function.Consumer; 30 31 /** 32 * Defines a set of static methods that can be used globally by framework classes. 33 * 34 * @hide 35 */ 36 public class InputMethodManagerGlobal { 37 /** 38 * @return {@code true} if IME tracing is currently is available. 39 */ 40 @AnyThread isImeTraceAvailable()41 public static boolean isImeTraceAvailable() { 42 return IInputMethodManagerGlobalInvoker.isAvailable(); 43 } 44 45 /** 46 * Invokes {@link IInputMethodManager#startProtoDump(byte[], int, String)}. 47 * 48 * @param protoDump client or service side information to be stored by the server 49 * @param source where the information is coming from, refer to 50 * {@link ImeTracing#IME_TRACING_FROM_CLIENT} and 51 * {@link ImeTracing#IME_TRACING_FROM_IMS} 52 * @param where where the information is coming from. 53 * @param exceptionHandler an optional {@link RemoteException} handler. 54 */ 55 @AnyThread 56 @RequiresNoPermission startProtoDump(byte[] protoDump, int source, String where, @Nullable Consumer<RemoteException> exceptionHandler)57 public static void startProtoDump(byte[] protoDump, int source, String where, 58 @Nullable Consumer<RemoteException> exceptionHandler) { 59 IInputMethodManagerGlobalInvoker.startProtoDump(protoDump, source, where, exceptionHandler); 60 } 61 62 /** 63 * Invokes {@link IInputMethodManager#startImeTrace()}. 64 * 65 * @param exceptionHandler an optional {@link RemoteException} handler. 66 */ 67 @AnyThread 68 @RequiresPermission(Manifest.permission.CONTROL_UI_TRACING) startImeTrace(@ullable Consumer<RemoteException> exceptionHandler)69 public static void startImeTrace(@Nullable Consumer<RemoteException> exceptionHandler) { 70 IInputMethodManagerGlobalInvoker.startImeTrace(exceptionHandler); 71 } 72 73 /** 74 * Invokes {@link IInputMethodManager#stopImeTrace()}. 75 * 76 * @param exceptionHandler an optional {@link RemoteException} handler. 77 */ 78 @AnyThread 79 @RequiresPermission(Manifest.permission.CONTROL_UI_TRACING) stopImeTrace(@ullable Consumer<RemoteException> exceptionHandler)80 public static void stopImeTrace(@Nullable Consumer<RemoteException> exceptionHandler) { 81 IInputMethodManagerGlobalInvoker.stopImeTrace(exceptionHandler); 82 } 83 84 /** 85 * Invokes {@link IInputMethodManager#isImeTraceEnabled()}. 86 * 87 * @return The return value of {@link IInputMethodManager#isImeTraceEnabled()}. 88 */ 89 @AnyThread 90 @RequiresNoPermission isImeTraceEnabled()91 public static boolean isImeTraceEnabled() { 92 return IInputMethodManagerGlobalInvoker.isImeTraceEnabled(); 93 } 94 95 /** 96 * Invokes {@link IInputMethodManager#removeImeSurface()} 97 * 98 * @param exceptionHandler an optional {@link RemoteException} handler. 99 */ 100 @AnyThread 101 @RequiresPermission(Manifest.permission.INTERNAL_SYSTEM_WINDOW) removeImeSurface(@ullable Consumer<RemoteException> exceptionHandler)102 public static void removeImeSurface(@Nullable Consumer<RemoteException> exceptionHandler) { 103 IInputMethodManagerGlobalInvoker.removeImeSurface(exceptionHandler); 104 } 105 } 106