1 /* 2 * Copyright (C) 2021 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; 18 19 import android.annotation.NonNull; 20 import android.annotation.UserIdInt; 21 import android.util.ArraySet; 22 import android.util.SparseArray; 23 import android.view.inputmethod.EditorInfo; 24 25 import com.android.internal.inputmethod.IAccessibilityInputMethodSession; 26 import com.android.internal.inputmethod.IRemoteAccessibilityInputConnection; 27 28 /** 29 * Accessibility manager local system service interface. 30 */ 31 public abstract class AccessibilityManagerInternal { 32 /** Enable or disable the sessions. */ setImeSessionEnabled( SparseArray<IAccessibilityInputMethodSession> sessions, boolean enabled)33 public abstract void setImeSessionEnabled( 34 SparseArray<IAccessibilityInputMethodSession> sessions, boolean enabled); 35 36 /** Unbind input for all accessibility services which require ime capabilities. */ unbindInput()37 public abstract void unbindInput(); 38 39 /** Bind input for all accessibility services which require ime capabilities. */ bindInput()40 public abstract void bindInput(); 41 42 /** 43 * Request input session from all accessibility services which require ime capabilities and 44 * whose id is not in the ignoreSet. 45 */ createImeSession(ArraySet<Integer> ignoreSet)46 public abstract void createImeSession(ArraySet<Integer> ignoreSet); 47 48 /** Start input for all accessibility services which require ime capabilities. */ startInput( IRemoteAccessibilityInputConnection remoteAccessibilityInputConnection, EditorInfo editorInfo, boolean restarting)49 public abstract void startInput( 50 IRemoteAccessibilityInputConnection remoteAccessibilityInputConnection, 51 EditorInfo editorInfo, boolean restarting); 52 53 /** Trigger a system action with the provided {@code actionId}. */ performSystemAction(int actionId)54 public abstract void performSystemAction(int actionId); 55 56 /** 57 * Queries whether touch-exploration mode is enabled or not for the specified user. 58 * 59 * @param userId User ID to be queried about. 60 * @return {@code true} if touch-exploration mode is enabled. 61 * @see android.view.accessibility.AccessibilityManager#isTouchExplorationEnabled() 62 */ isTouchExplorationEnabled(@serIdInt int userId)63 public abstract boolean isTouchExplorationEnabled(@UserIdInt int userId); 64 65 private static final AccessibilityManagerInternal NOP = new AccessibilityManagerInternal() { 66 @Override 67 public void setImeSessionEnabled(SparseArray<IAccessibilityInputMethodSession> sessions, 68 boolean enabled) { 69 } 70 71 @Override 72 public void unbindInput() { 73 } 74 75 @Override 76 public void bindInput() { 77 } 78 79 @Override 80 public void createImeSession(ArraySet<Integer> ignoreSet) { 81 } 82 83 @Override 84 public void startInput(IRemoteAccessibilityInputConnection remoteAccessibility, 85 EditorInfo editorInfo, boolean restarting) { 86 } 87 88 @Override 89 public boolean isTouchExplorationEnabled(int userId) { 90 return false; 91 } 92 93 @Override 94 public void performSystemAction(int actionId) { 95 } 96 }; 97 98 /** 99 * @return Global instance if exists. Otherwise, a fallback no-op instance. 100 */ 101 @NonNull get()102 public static AccessibilityManagerInternal get() { 103 final AccessibilityManagerInternal instance = 104 LocalServices.getService(AccessibilityManagerInternal.class); 105 return instance != null ? instance : NOP; 106 } 107 } 108