svetoslavganov | 75986cf | 2009-05-14 22:28:01 -0700 | [diff] [blame] | 1 | /* |
| 2 | ** Copyright 2009, 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 | |
Jeff Brown | 6e6cd7a | 2011-03-30 03:27:08 -0700 | [diff] [blame] | 17 | package com.android.server.accessibility; |
svetoslavganov | 75986cf | 2009-05-14 22:28:01 -0700 | [diff] [blame] | 18 | |
Svetoslav Ganov | 4213804 | 2012-03-20 11:51:39 -0700 | [diff] [blame] | 19 | import static android.accessibilityservice.AccessibilityServiceInfo.DEFAULT; |
Svetoslav Ganov | 4213804 | 2012-03-20 11:51:39 -0700 | [diff] [blame] | 20 | |
Svetoslav Ganov | 8643aa0 | 2011-04-20 12:12:33 -0700 | [diff] [blame] | 21 | import android.Manifest; |
svetoslavganov | 75986cf | 2009-05-14 22:28:01 -0700 | [diff] [blame] | 22 | import android.accessibilityservice.AccessibilityService; |
| 23 | import android.accessibilityservice.AccessibilityServiceInfo; |
Svetoslav Ganov | 4213804 | 2012-03-20 11:51:39 -0700 | [diff] [blame] | 24 | import android.accessibilityservice.IAccessibilityServiceClient; |
svetoslavganov | 75986cf | 2009-05-14 22:28:01 -0700 | [diff] [blame] | 25 | import android.accessibilityservice.IAccessibilityServiceConnection; |
Svetoslav Ganov | 447d946 | 2013-02-01 19:46:20 +0000 | [diff] [blame] | 26 | import android.app.AlertDialog; |
Dianne Hackborn | dd9b82c | 2009-09-03 00:18:47 -0700 | [diff] [blame] | 27 | import android.app.PendingIntent; |
Svetoslav Ganov | 5c89f44 | 2012-05-15 13:28:09 -0700 | [diff] [blame] | 28 | import android.app.StatusBarManager; |
svetoslavganov | 75986cf | 2009-05-14 22:28:01 -0700 | [diff] [blame] | 29 | import android.content.BroadcastReceiver; |
| 30 | import android.content.ComponentName; |
| 31 | import android.content.ContentResolver; |
| 32 | import android.content.Context; |
Svetoslav Ganov | 447d946 | 2013-02-01 19:46:20 +0000 | [diff] [blame] | 33 | import android.content.DialogInterface; |
| 34 | import android.content.DialogInterface.OnClickListener; |
svetoslavganov | 75986cf | 2009-05-14 22:28:01 -0700 | [diff] [blame] | 35 | import android.content.Intent; |
| 36 | import android.content.IntentFilter; |
| 37 | import android.content.ServiceConnection; |
| 38 | import android.content.pm.PackageManager; |
| 39 | import android.content.pm.ResolveInfo; |
Svetoslav Ganov | 53e184d | 2012-05-16 15:57:10 -0700 | [diff] [blame] | 40 | import android.content.pm.ServiceInfo; |
svetoslavganov | 75986cf | 2009-05-14 22:28:01 -0700 | [diff] [blame] | 41 | import android.database.ContentObserver; |
Svetoslav Ganov | a94c319 | 2012-10-31 18:28:49 -0700 | [diff] [blame] | 42 | import android.graphics.Point; |
Svetoslav Ganov | 7961be7 | 2011-06-21 12:31:56 -0700 | [diff] [blame] | 43 | import android.graphics.Rect; |
Svetoslav Ganov | a94c319 | 2012-10-31 18:28:49 -0700 | [diff] [blame] | 44 | import android.hardware.display.DisplayManager; |
Svetoslav Ganov | 005b83b | 2012-04-16 18:17:17 -0700 | [diff] [blame] | 45 | import android.hardware.input.InputManager; |
svetoslavganov | 75986cf | 2009-05-14 22:28:01 -0700 | [diff] [blame] | 46 | import android.net.Uri; |
| 47 | import android.os.Binder; |
Svetoslav Ganov | 4213804 | 2012-03-20 11:51:39 -0700 | [diff] [blame] | 48 | import android.os.Build; |
Svetoslav Ganov | aa780c1 | 2012-04-19 23:01:39 -0700 | [diff] [blame] | 49 | import android.os.Bundle; |
svetoslavganov | 75986cf | 2009-05-14 22:28:01 -0700 | [diff] [blame] | 50 | import android.os.Handler; |
| 51 | import android.os.IBinder; |
Svetoslav Ganov | 1cf70bb | 2012-08-06 10:53:34 -0700 | [diff] [blame] | 52 | import android.os.Looper; |
svetoslavganov | 75986cf | 2009-05-14 22:28:01 -0700 | [diff] [blame] | 53 | import android.os.Message; |
Svetoslav Ganov | 58d37b5 | 2012-09-18 12:04:19 -0700 | [diff] [blame] | 54 | import android.os.Process; |
| 55 | import android.os.RemoteCallbackList; |
svetoslavganov | 75986cf | 2009-05-14 22:28:01 -0700 | [diff] [blame] | 56 | import android.os.RemoteException; |
Jeff Brown | 0029c66 | 2011-03-30 02:25:18 -0700 | [diff] [blame] | 57 | import android.os.ServiceManager; |
Svetoslav Ganov | 005b83b | 2012-04-16 18:17:17 -0700 | [diff] [blame] | 58 | import android.os.SystemClock; |
Svetoslav Ganov | 58d37b5 | 2012-09-18 12:04:19 -0700 | [diff] [blame] | 59 | import android.os.UserHandle; |
Svetoslav Ganov | 7befb7d | 2012-09-27 16:49:23 -0700 | [diff] [blame] | 60 | import android.os.UserManager; |
svetoslavganov | 75986cf | 2009-05-14 22:28:01 -0700 | [diff] [blame] | 61 | import android.provider.Settings; |
| 62 | import android.text.TextUtils; |
| 63 | import android.text.TextUtils.SimpleStringSplitter; |
Svetoslav | c4fccd1 | 2013-04-09 12:58:41 -0700 | [diff] [blame] | 64 | import android.util.Pools.Pool; |
| 65 | import android.util.Pools.SimplePool; |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 66 | import android.util.Slog; |
svetoslavganov | 75986cf | 2009-05-14 22:28:01 -0700 | [diff] [blame] | 67 | import android.util.SparseArray; |
Svetoslav Ganov | a94c319 | 2012-10-31 18:28:49 -0700 | [diff] [blame] | 68 | import android.view.Display; |
Svetoslav Ganov | 8643aa0 | 2011-04-20 12:12:33 -0700 | [diff] [blame] | 69 | import android.view.IWindow; |
Svetoslav Ganov | c9c9a48 | 2012-07-16 08:46:07 -0700 | [diff] [blame] | 70 | import android.view.IWindowManager; |
Svetoslav Ganov | 005b83b | 2012-04-16 18:17:17 -0700 | [diff] [blame] | 71 | import android.view.InputDevice; |
Svetoslav | c4fccd1 | 2013-04-09 12:58:41 -0700 | [diff] [blame] | 72 | import android.view.InputEventConsistencyVerifier; |
Svetoslav Ganov | 005b83b | 2012-04-16 18:17:17 -0700 | [diff] [blame] | 73 | import android.view.KeyCharacterMap; |
| 74 | import android.view.KeyEvent; |
Svetoslav Ganov | 152e9bb | 2012-10-12 20:15:29 -0700 | [diff] [blame] | 75 | import android.view.MagnificationSpec; |
Svetoslav Ganov | 447d946 | 2013-02-01 19:46:20 +0000 | [diff] [blame] | 76 | import android.view.WindowManager; |
Svetoslav | c4fccd1 | 2013-04-09 12:58:41 -0700 | [diff] [blame] | 77 | import android.view.WindowManagerPolicy; |
svetoslavganov | 75986cf | 2009-05-14 22:28:01 -0700 | [diff] [blame] | 78 | import android.view.accessibility.AccessibilityEvent; |
Svetoslav Ganov | e15ccb9 | 2012-05-16 15:48:55 -0700 | [diff] [blame] | 79 | import android.view.accessibility.AccessibilityInteractionClient; |
Svetoslav Ganov | 00aabf7 | 2011-07-21 11:35:03 -0700 | [diff] [blame] | 80 | import android.view.accessibility.AccessibilityManager; |
Svetoslav Ganov | 8643aa0 | 2011-04-20 12:12:33 -0700 | [diff] [blame] | 81 | import android.view.accessibility.AccessibilityNodeInfo; |
| 82 | import android.view.accessibility.IAccessibilityInteractionConnection; |
| 83 | import android.view.accessibility.IAccessibilityInteractionConnectionCallback; |
svetoslavganov | 75986cf | 2009-05-14 22:28:01 -0700 | [diff] [blame] | 84 | import android.view.accessibility.IAccessibilityManager; |
| 85 | import android.view.accessibility.IAccessibilityManagerClient; |
| 86 | |
Svetoslav Ganov | e15ccb9 | 2012-05-16 15:48:55 -0700 | [diff] [blame] | 87 | import com.android.internal.R; |
Svetoslav Ganov | 8643aa0 | 2011-04-20 12:12:33 -0700 | [diff] [blame] | 88 | import com.android.internal.content.PackageMonitor; |
Svetoslav Ganov | c682fc9 | 2012-06-04 14:02:09 -0700 | [diff] [blame] | 89 | import com.android.internal.statusbar.IStatusBarService; |
Svetoslav Ganov | 8643aa0 | 2011-04-20 12:12:33 -0700 | [diff] [blame] | 90 | |
| 91 | import org.xmlpull.v1.XmlPullParserException; |
| 92 | |
Svetoslav Ganov | 6ce77cd | 2012-11-21 16:35:57 -0800 | [diff] [blame] | 93 | import java.io.FileDescriptor; |
Svetoslav Ganov | cc4053e | 2011-05-23 13:37:44 -0700 | [diff] [blame] | 94 | import java.io.IOException; |
Svetoslav Ganov | 6ce77cd | 2012-11-21 16:35:57 -0800 | [diff] [blame] | 95 | import java.io.PrintWriter; |
svetoslavganov | 75986cf | 2009-05-14 22:28:01 -0700 | [diff] [blame] | 96 | import java.util.ArrayList; |
| 97 | import java.util.Arrays; |
Svetoslav Ganov | 319d55b | 2013-05-17 19:12:38 -0700 | [diff] [blame] | 98 | import java.util.Collections; |
svetoslavganov | 75986cf | 2009-05-14 22:28:01 -0700 | [diff] [blame] | 99 | import java.util.HashMap; |
| 100 | import java.util.HashSet; |
Dianne Hackborn | 21f1bd1 | 2010-02-19 17:02:21 -0800 | [diff] [blame] | 101 | import java.util.Iterator; |
svetoslavganov | 75986cf | 2009-05-14 22:28:01 -0700 | [diff] [blame] | 102 | import java.util.List; |
| 103 | import java.util.Map; |
| 104 | import java.util.Set; |
Svetoslav Ganov | 58d37b5 | 2012-09-18 12:04:19 -0700 | [diff] [blame] | 105 | import java.util.concurrent.CopyOnWriteArrayList; |
svetoslavganov | 75986cf | 2009-05-14 22:28:01 -0700 | [diff] [blame] | 106 | |
| 107 | /** |
| 108 | * This class is instantiated by the system as a system level service and can be |
| 109 | * accessed only by the system. The task of this service is to be a centralized |
| 110 | * event dispatch for {@link AccessibilityEvent}s generated across all processes |
| 111 | * on the device. Events are dispatched to {@link AccessibilityService}s. |
| 112 | * |
| 113 | * @hide |
| 114 | */ |
Svetoslav Ganov | e15ccb9 | 2012-05-16 15:48:55 -0700 | [diff] [blame] | 115 | public class AccessibilityManagerService extends IAccessibilityManager.Stub { |
svetoslavganov | 75986cf | 2009-05-14 22:28:01 -0700 | [diff] [blame] | 116 | |
Svetoslav Ganov | 736c275 | 2011-04-22 18:30:36 -0700 | [diff] [blame] | 117 | private static final boolean DEBUG = false; |
| 118 | |
svetoslavganov | 75986cf | 2009-05-14 22:28:01 -0700 | [diff] [blame] | 119 | private static final String LOG_TAG = "AccessibilityManagerService"; |
| 120 | |
Svetoslav Ganov | 7befb7d | 2012-09-27 16:49:23 -0700 | [diff] [blame] | 121 | // TODO: This is arbitrary. When there is time implement this by watching |
| 122 | // when that accessibility services are bound. |
Svetoslav Ganov | 59f0769 | 2012-10-01 19:01:32 -0700 | [diff] [blame] | 123 | private static final int WAIT_FOR_USER_STATE_FULLY_INITIALIZED_MILLIS = 3000; |
Svetoslav Ganov | 7befb7d | 2012-09-27 16:49:23 -0700 | [diff] [blame] | 124 | |
Svetoslav Ganov | 0d04e24 | 2012-02-21 13:46:36 -0800 | [diff] [blame] | 125 | private static final String FUNCTION_REGISTER_UI_TEST_AUTOMATION_SERVICE = |
| 126 | "registerUiTestAutomationService"; |
Svetoslav Ganov | 8643aa0 | 2011-04-20 12:12:33 -0700 | [diff] [blame] | 127 | |
Svetoslav Ganov | 7befb7d | 2012-09-27 16:49:23 -0700 | [diff] [blame] | 128 | private static final String TEMPORARY_ENABLE_ACCESSIBILITY_UNTIL_KEYGUARD_REMOVED = |
| 129 | "temporaryEnableAccessibilityStateUntilKeyguardRemoved"; |
| 130 | |
Svetoslav | 57bf885 | 2013-02-07 19:21:42 -0800 | [diff] [blame] | 131 | private static final ComponentName sFakeAccessibilityServiceComponentName = |
| 132 | new ComponentName("foo.bar", "FakeService"); |
| 133 | |
Svetoslav Ganov | 6ce77cd | 2012-11-21 16:35:57 -0800 | [diff] [blame] | 134 | private static final String FUNCTION_DUMP = "dump"; |
| 135 | |
Svetoslav Ganov | 9a4c5cd | 2012-05-30 14:06:32 -0700 | [diff] [blame] | 136 | private static final char COMPONENT_NAME_SEPARATOR = ':'; |
| 137 | |
svetoslavganov | 75986cf | 2009-05-14 22:28:01 -0700 | [diff] [blame] | 138 | private static final int OWN_PROCESS_ID = android.os.Process.myPid(); |
| 139 | |
Svetoslav | c4fccd1 | 2013-04-09 12:58:41 -0700 | [diff] [blame] | 140 | private static final int MAX_POOL_SIZE = 10; |
| 141 | |
Svetoslav Ganov | fefd20e | 2012-04-19 21:44:35 -0700 | [diff] [blame] | 142 | private static int sIdCounter = 0; |
| 143 | |
Svetoslav Ganov | 8643aa0 | 2011-04-20 12:12:33 -0700 | [diff] [blame] | 144 | private static int sNextWindowId; |
| 145 | |
Svetoslav Ganov | 58d37b5 | 2012-09-18 12:04:19 -0700 | [diff] [blame] | 146 | private final Context mContext; |
svetoslavganov | 75986cf | 2009-05-14 22:28:01 -0700 | [diff] [blame] | 147 | |
Svetoslav Ganov | 58d37b5 | 2012-09-18 12:04:19 -0700 | [diff] [blame] | 148 | private final Object mLock = new Object(); |
svetoslavganov | 75986cf | 2009-05-14 22:28:01 -0700 | [diff] [blame] | 149 | |
Svetoslav | c4fccd1 | 2013-04-09 12:58:41 -0700 | [diff] [blame] | 150 | private final Pool<PendingEvent> mPendingEventPool = |
| 151 | new SimplePool<PendingEvent>(MAX_POOL_SIZE); |
| 152 | |
Svetoslav Ganov | 58d37b5 | 2012-09-18 12:04:19 -0700 | [diff] [blame] | 153 | private final SimpleStringSplitter mStringColonSplitter = |
| 154 | new SimpleStringSplitter(COMPONENT_NAME_SEPARATOR); |
svetoslavganov | 75986cf | 2009-05-14 22:28:01 -0700 | [diff] [blame] | 155 | |
Svetoslav Ganov | 58d37b5 | 2012-09-18 12:04:19 -0700 | [diff] [blame] | 156 | private final List<AccessibilityServiceInfo> mEnabledServicesForFeedbackTempList = |
| 157 | new ArrayList<AccessibilityServiceInfo>(); |
svetoslavganov | 75986cf | 2009-05-14 22:28:01 -0700 | [diff] [blame] | 158 | |
Svetoslav Ganov | a94c319 | 2012-10-31 18:28:49 -0700 | [diff] [blame] | 159 | private final Rect mTempRect = new Rect(); |
| 160 | |
| 161 | private final Point mTempPoint = new Point(); |
| 162 | |
| 163 | private final Display mDefaultDisplay; |
| 164 | |
Svetoslav Ganov | 58d37b5 | 2012-09-18 12:04:19 -0700 | [diff] [blame] | 165 | private final PackageManager mPackageManager; |
svetoslavganov | 75986cf | 2009-05-14 22:28:01 -0700 | [diff] [blame] | 166 | |
Svetoslav Ganov | 58d37b5 | 2012-09-18 12:04:19 -0700 | [diff] [blame] | 167 | private final IWindowManager mWindowManagerService; |
Svetoslav Ganov | 8643aa0 | 2011-04-20 12:12:33 -0700 | [diff] [blame] | 168 | |
| 169 | private final SecurityPolicy mSecurityPolicy; |
| 170 | |
Svetoslav Ganov | 1cf70bb | 2012-08-06 10:53:34 -0700 | [diff] [blame] | 171 | private final MainHandler mMainHandler; |
Svetoslav Ganov | e15ccb9 | 2012-05-16 15:48:55 -0700 | [diff] [blame] | 172 | |
Svetoslav Ganov | e15ccb9 | 2012-05-16 15:48:55 -0700 | [diff] [blame] | 173 | private Service mQueryBridge; |
svetoslavganov | 75986cf | 2009-05-14 22:28:01 -0700 | [diff] [blame] | 174 | |
Svetoslav Ganov | 447d946 | 2013-02-01 19:46:20 +0000 | [diff] [blame] | 175 | private AlertDialog mEnableTouchExplorationDialog; |
| 176 | |
Svetoslav Ganov | 58d37b5 | 2012-09-18 12:04:19 -0700 | [diff] [blame] | 177 | private AccessibilityInputFilter mInputFilter; |
| 178 | |
| 179 | private boolean mHasInputFilter; |
| 180 | |
Svetoslav | 57bf885 | 2013-02-07 19:21:42 -0800 | [diff] [blame] | 181 | private final Set<ComponentName> mTempComponentNameSet = new HashSet<ComponentName>(); |
| 182 | |
| 183 | private final List<AccessibilityServiceInfo> mTempAccessibilityServiceInfoList = |
| 184 | new ArrayList<AccessibilityServiceInfo>(); |
| 185 | |
Svetoslav Ganov | 58d37b5 | 2012-09-18 12:04:19 -0700 | [diff] [blame] | 186 | private final RemoteCallbackList<IAccessibilityManagerClient> mGlobalClients = |
| 187 | new RemoteCallbackList<IAccessibilityManagerClient>(); |
| 188 | |
| 189 | private final SparseArray<AccessibilityConnectionWrapper> mGlobalInteractionConnections = |
| 190 | new SparseArray<AccessibilityConnectionWrapper>(); |
| 191 | |
| 192 | private final SparseArray<IBinder> mGlobalWindowTokens = new SparseArray<IBinder>(); |
| 193 | |
| 194 | private final SparseArray<UserState> mUserStates = new SparseArray<UserState>(); |
| 195 | |
Svetoslav Ganov | a8afa69 | 2012-09-25 13:03:18 -0700 | [diff] [blame] | 196 | private int mCurrentUserId = UserHandle.USER_OWNER; |
Svetoslav Ganov | 58d37b5 | 2012-09-18 12:04:19 -0700 | [diff] [blame] | 197 | |
Svetoslav | 3b817ae | 2013-06-19 16:28:30 -0700 | [diff] [blame] | 198 | //TODO: Remove this hack |
| 199 | private boolean mInitialized; |
| 200 | |
Svetoslav Ganov | 58d37b5 | 2012-09-18 12:04:19 -0700 | [diff] [blame] | 201 | private UserState getCurrentUserStateLocked() { |
| 202 | return getUserStateLocked(mCurrentUserId); |
| 203 | } |
| 204 | |
| 205 | private UserState getUserStateLocked(int userId) { |
| 206 | UserState state = mUserStates.get(userId); |
| 207 | if (state == null) { |
| 208 | state = new UserState(userId); |
| 209 | mUserStates.put(userId, state); |
| 210 | } |
| 211 | return state; |
| 212 | } |
| 213 | |
svetoslavganov | 75986cf | 2009-05-14 22:28:01 -0700 | [diff] [blame] | 214 | /** |
| 215 | * Creates a new instance. |
| 216 | * |
| 217 | * @param context A {@link Context} instance. |
| 218 | */ |
Jeff Brown | 6e6cd7a | 2011-03-30 03:27:08 -0700 | [diff] [blame] | 219 | public AccessibilityManagerService(Context context) { |
svetoslavganov | 75986cf | 2009-05-14 22:28:01 -0700 | [diff] [blame] | 220 | mContext = context; |
| 221 | mPackageManager = mContext.getPackageManager(); |
Svetoslav Ganov | 58d37b5 | 2012-09-18 12:04:19 -0700 | [diff] [blame] | 222 | mWindowManagerService = (IWindowManager) ServiceManager.getService(Context.WINDOW_SERVICE); |
Svetoslav Ganov | 8643aa0 | 2011-04-20 12:12:33 -0700 | [diff] [blame] | 223 | mSecurityPolicy = new SecurityPolicy(); |
Svetoslav Ganov | 1cf70bb | 2012-08-06 10:53:34 -0700 | [diff] [blame] | 224 | mMainHandler = new MainHandler(mContext.getMainLooper()); |
Svetoslav Ganov | a94c319 | 2012-10-31 18:28:49 -0700 | [diff] [blame] | 225 | //TODO: (multi-display) We need to support multiple displays. |
| 226 | DisplayManager displayManager = (DisplayManager) |
| 227 | mContext.getSystemService(Context.DISPLAY_SERVICE); |
| 228 | mDefaultDisplay = displayManager.getDisplay(Display.DEFAULT_DISPLAY); |
Svetoslav Ganov | 58d37b5 | 2012-09-18 12:04:19 -0700 | [diff] [blame] | 229 | registerBroadcastReceivers(); |
| 230 | new AccessibilityContentObserver(mMainHandler).register( |
| 231 | context.getContentResolver()); |
svetoslavganov | 75986cf | 2009-05-14 22:28:01 -0700 | [diff] [blame] | 232 | } |
| 233 | |
Svetoslav Ganov | 58d37b5 | 2012-09-18 12:04:19 -0700 | [diff] [blame] | 234 | private void registerBroadcastReceivers() { |
Dianne Hackborn | 21f1bd1 | 2010-02-19 17:02:21 -0800 | [diff] [blame] | 235 | PackageMonitor monitor = new PackageMonitor() { |
svetoslavganov | 75986cf | 2009-05-14 22:28:01 -0700 | [diff] [blame] | 236 | @Override |
Dianne Hackborn | 21f1bd1 | 2010-02-19 17:02:21 -0800 | [diff] [blame] | 237 | public void onSomePackagesChanged() { |
svetoslavganov | 75986cf | 2009-05-14 22:28:01 -0700 | [diff] [blame] | 238 | synchronized (mLock) { |
Svetoslav Ganov | 58d37b5 | 2012-09-18 12:04:19 -0700 | [diff] [blame] | 239 | if (getChangingUserId() != mCurrentUserId) { |
| 240 | return; |
| 241 | } |
Svetoslav Ganov | 4074e8a | 2012-05-23 11:52:36 -0700 | [diff] [blame] | 242 | // We will update when the automation service dies. |
Svetoslav | 57bf885 | 2013-02-07 19:21:42 -0800 | [diff] [blame] | 243 | UserState userState = getCurrentUserStateLocked(); |
Svetoslav Ganov | 0ecfa01 | 2013-04-18 09:35:43 -0700 | [diff] [blame] | 244 | // We have to reload the installed services since some services may |
| 245 | // have different attributes, resolve info (does not support equals), |
| 246 | // etc. Remove them then to force reload. Do it even if automation is |
| 247 | // running since when it goes away, we will have to reload as well. |
| 248 | userState.mInstalledServices.clear(); |
Svetoslav | 57bf885 | 2013-02-07 19:21:42 -0800 | [diff] [blame] | 249 | if (userState.mUiAutomationService == null) { |
| 250 | if (readConfigurationForUserStateLocked(userState)) { |
| 251 | onUserStateChangedLocked(userState); |
| 252 | } |
Svetoslav Ganov | 4074e8a | 2012-05-23 11:52:36 -0700 | [diff] [blame] | 253 | } |
Dianne Hackborn | 21f1bd1 | 2010-02-19 17:02:21 -0800 | [diff] [blame] | 254 | } |
| 255 | } |
Svetoslav Ganov | 00aabf7 | 2011-07-21 11:35:03 -0700 | [diff] [blame] | 256 | |
Dianne Hackborn | 21f1bd1 | 2010-02-19 17:02:21 -0800 | [diff] [blame] | 257 | @Override |
Svetoslav Ganov | d07d60b | 2011-09-14 11:41:29 -0700 | [diff] [blame] | 258 | public void onPackageRemoved(String packageName, int uid) { |
| 259 | synchronized (mLock) { |
Svetoslav Ganov | 58d37b5 | 2012-09-18 12:04:19 -0700 | [diff] [blame] | 260 | final int userId = getChangingUserId(); |
| 261 | if (userId != mCurrentUserId) { |
| 262 | return; |
| 263 | } |
Svetoslav | 57bf885 | 2013-02-07 19:21:42 -0800 | [diff] [blame] | 264 | UserState userState = getUserStateLocked(userId); |
| 265 | Iterator<ComponentName> it = userState.mEnabledServices.iterator(); |
Svetoslav Ganov | d07d60b | 2011-09-14 11:41:29 -0700 | [diff] [blame] | 266 | while (it.hasNext()) { |
| 267 | ComponentName comp = it.next(); |
| 268 | String compPkg = comp.getPackageName(); |
| 269 | if (compPkg.equals(packageName)) { |
| 270 | it.remove(); |
Svetoslav Ganov | 9a4c5cd | 2012-05-30 14:06:32 -0700 | [diff] [blame] | 271 | // Update the enabled services setting. |
| 272 | persistComponentNamesToSettingLocked( |
| 273 | Settings.Secure.ENABLED_ACCESSIBILITY_SERVICES, |
Svetoslav | 57bf885 | 2013-02-07 19:21:42 -0800 | [diff] [blame] | 274 | userState.mEnabledServices, userId); |
Svetoslav Ganov | 447d946 | 2013-02-01 19:46:20 +0000 | [diff] [blame] | 275 | // Update the touch exploration granted services setting. |
Svetoslav | 57bf885 | 2013-02-07 19:21:42 -0800 | [diff] [blame] | 276 | userState.mTouchExplorationGrantedServices.remove(comp); |
Svetoslav Ganov | 447d946 | 2013-02-01 19:46:20 +0000 | [diff] [blame] | 277 | persistComponentNamesToSettingLocked( |
| 278 | Settings.Secure. |
| 279 | TOUCH_EXPLORATION_GRANTED_ACCESSIBILITY_SERVICES, |
Svetoslav | 57bf885 | 2013-02-07 19:21:42 -0800 | [diff] [blame] | 280 | userState.mTouchExplorationGrantedServices, userId); |
| 281 | // We will update when the automation service dies. |
| 282 | if (userState.mUiAutomationService == null) { |
| 283 | onUserStateChangedLocked(userState); |
| 284 | } |
Svetoslav Ganov | d07d60b | 2011-09-14 11:41:29 -0700 | [diff] [blame] | 285 | return; |
| 286 | } |
| 287 | } |
| 288 | } |
| 289 | } |
| 290 | |
| 291 | @Override |
Dianne Hackborn | 21f1bd1 | 2010-02-19 17:02:21 -0800 | [diff] [blame] | 292 | public boolean onHandleForceStop(Intent intent, String[] packages, |
| 293 | int uid, boolean doit) { |
| 294 | synchronized (mLock) { |
Svetoslav Ganov | 58d37b5 | 2012-09-18 12:04:19 -0700 | [diff] [blame] | 295 | final int userId = getChangingUserId(); |
| 296 | if (userId != mCurrentUserId) { |
| 297 | return false; |
| 298 | } |
Svetoslav | 57bf885 | 2013-02-07 19:21:42 -0800 | [diff] [blame] | 299 | UserState userState = getUserStateLocked(userId); |
| 300 | Iterator<ComponentName> it = userState.mEnabledServices.iterator(); |
Dianne Hackborn | 21f1bd1 | 2010-02-19 17:02:21 -0800 | [diff] [blame] | 301 | while (it.hasNext()) { |
| 302 | ComponentName comp = it.next(); |
| 303 | String compPkg = comp.getPackageName(); |
| 304 | for (String pkg : packages) { |
| 305 | if (compPkg.equals(pkg)) { |
| 306 | if (!doit) { |
| 307 | return true; |
| 308 | } |
| 309 | it.remove(); |
Svetoslav Ganov | 9a4c5cd | 2012-05-30 14:06:32 -0700 | [diff] [blame] | 310 | persistComponentNamesToSettingLocked( |
| 311 | Settings.Secure.ENABLED_ACCESSIBILITY_SERVICES, |
Svetoslav | 57bf885 | 2013-02-07 19:21:42 -0800 | [diff] [blame] | 312 | userState.mEnabledServices, userId); |
| 313 | // We will update when the automation service dies. |
| 314 | if (userState.mUiAutomationService == null) { |
| 315 | onUserStateChangedLocked(userState); |
| 316 | } |
Dianne Hackborn | 21f1bd1 | 2010-02-19 17:02:21 -0800 | [diff] [blame] | 317 | } |
| 318 | } |
| 319 | } |
Dianne Hackborn | 21f1bd1 | 2010-02-19 17:02:21 -0800 | [diff] [blame] | 320 | return false; |
| 321 | } |
| 322 | } |
svetoslavganov | 75986cf | 2009-05-14 22:28:01 -0700 | [diff] [blame] | 323 | }; |
| 324 | |
| 325 | // package changes |
Svetoslav Ganov | 58d37b5 | 2012-09-18 12:04:19 -0700 | [diff] [blame] | 326 | monitor.register(mContext, null, UserHandle.ALL, true); |
svetoslavganov | 75986cf | 2009-05-14 22:28:01 -0700 | [diff] [blame] | 327 | |
Svetoslav Ganov | 7befb7d | 2012-09-27 16:49:23 -0700 | [diff] [blame] | 328 | // user change and unlock |
| 329 | IntentFilter intentFilter = new IntentFilter(); |
| 330 | intentFilter.addAction(Intent.ACTION_USER_SWITCHED); |
| 331 | intentFilter.addAction(Intent.ACTION_USER_REMOVED); |
| 332 | intentFilter.addAction(Intent.ACTION_USER_PRESENT); |
Svetoslav Ganov | 58d37b5 | 2012-09-18 12:04:19 -0700 | [diff] [blame] | 333 | |
Svetoslav Ganov | 7befb7d | 2012-09-27 16:49:23 -0700 | [diff] [blame] | 334 | mContext.registerReceiverAsUser(new BroadcastReceiver() { |
Svetoslav Ganov | 58d37b5 | 2012-09-18 12:04:19 -0700 | [diff] [blame] | 335 | @Override |
| 336 | public void onReceive(Context context, Intent intent) { |
| 337 | String action = intent.getAction(); |
| 338 | if (Intent.ACTION_USER_SWITCHED.equals(action)) { |
| 339 | switchUser(intent.getIntExtra(Intent.EXTRA_USER_HANDLE, 0)); |
| 340 | } else if (Intent.ACTION_USER_REMOVED.equals(action)) { |
| 341 | removeUser(intent.getIntExtra(Intent.EXTRA_USER_HANDLE, 0)); |
Svetoslav Ganov | 7befb7d | 2012-09-27 16:49:23 -0700 | [diff] [blame] | 342 | } else if (Intent.ACTION_USER_PRESENT.equals(action)) { |
Svetoslav | 57bf885 | 2013-02-07 19:21:42 -0800 | [diff] [blame] | 343 | // We will update when the automation service dies. |
| 344 | UserState userState = getCurrentUserStateLocked(); |
| 345 | if (userState.mUiAutomationService == null) { |
| 346 | if (readConfigurationForUserStateLocked(userState)) { |
| 347 | onUserStateChangedLocked(userState); |
| 348 | } |
| 349 | } |
Svetoslav Ganov | 58d37b5 | 2012-09-18 12:04:19 -0700 | [diff] [blame] | 350 | } |
| 351 | } |
Svetoslav Ganov | 7befb7d | 2012-09-27 16:49:23 -0700 | [diff] [blame] | 352 | }, UserHandle.ALL, intentFilter, null, null); |
svetoslavganov | 75986cf | 2009-05-14 22:28:01 -0700 | [diff] [blame] | 353 | } |
| 354 | |
Svetoslav Ganov | 58d37b5 | 2012-09-18 12:04:19 -0700 | [diff] [blame] | 355 | public int addClient(IAccessibilityManagerClient client, int userId) { |
svetoslavganov | 75986cf | 2009-05-14 22:28:01 -0700 | [diff] [blame] | 356 | synchronized (mLock) { |
Svetoslav Ganov | 58d37b5 | 2012-09-18 12:04:19 -0700 | [diff] [blame] | 357 | final int resolvedUserId = mSecurityPolicy |
| 358 | .resolveCallingUserIdEnforcingPermissionsLocked(userId); |
| 359 | // If the client is from a process that runs across users such as |
| 360 | // the system UI or the system we add it to the global state that |
| 361 | // is shared across users. |
| 362 | UserState userState = getUserStateLocked(resolvedUserId); |
| 363 | if (mSecurityPolicy.isCallerInteractingAcrossUsers(userId)) { |
| 364 | mGlobalClients.register(client); |
Svetoslav Ganov | a8afa69 | 2012-09-25 13:03:18 -0700 | [diff] [blame] | 365 | if (DEBUG) { |
| 366 | Slog.i(LOG_TAG, "Added global client for pid:" + Binder.getCallingPid()); |
| 367 | } |
Svetoslav | 57bf885 | 2013-02-07 19:21:42 -0800 | [diff] [blame] | 368 | return userState.getClientState(); |
Svetoslav Ganov | 58d37b5 | 2012-09-18 12:04:19 -0700 | [diff] [blame] | 369 | } else { |
| 370 | userState.mClients.register(client); |
| 371 | // If this client is not for the current user we do not |
| 372 | // return a state since it is not for the foreground user. |
| 373 | // We will send the state to the client on a user switch. |
Svetoslav Ganov | a8afa69 | 2012-09-25 13:03:18 -0700 | [diff] [blame] | 374 | if (DEBUG) { |
| 375 | Slog.i(LOG_TAG, "Added user client for pid:" + Binder.getCallingPid() |
| 376 | + " and userId:" + mCurrentUserId); |
| 377 | } |
Svetoslav | 57bf885 | 2013-02-07 19:21:42 -0800 | [diff] [blame] | 378 | return (resolvedUserId == mCurrentUserId) ? userState.getClientState() : 0; |
Svetoslav Ganov | 58d37b5 | 2012-09-18 12:04:19 -0700 | [diff] [blame] | 379 | } |
svetoslavganov | 75986cf | 2009-05-14 22:28:01 -0700 | [diff] [blame] | 380 | } |
| 381 | } |
| 382 | |
Svetoslav Ganov | 58d37b5 | 2012-09-18 12:04:19 -0700 | [diff] [blame] | 383 | public boolean sendAccessibilityEvent(AccessibilityEvent event, int userId) { |
svetoslavganov | 75986cf | 2009-05-14 22:28:01 -0700 | [diff] [blame] | 384 | synchronized (mLock) { |
Svetoslav Ganov | 58d37b5 | 2012-09-18 12:04:19 -0700 | [diff] [blame] | 385 | final int resolvedUserId = mSecurityPolicy |
| 386 | .resolveCallingUserIdEnforcingPermissionsLocked(userId); |
| 387 | // This method does nothing for a background user. |
| 388 | if (resolvedUserId != mCurrentUserId) { |
| 389 | return true; // yes, recycle the event |
| 390 | } |
Svetoslav Ganov | eeee4d2 | 2011-06-10 20:51:30 -0700 | [diff] [blame] | 391 | if (mSecurityPolicy.canDispatchAccessibilityEvent(event)) { |
Svetoslav Ganov | a8afa69 | 2012-09-25 13:03:18 -0700 | [diff] [blame] | 392 | mSecurityPolicy.updateEventSourceLocked(event); |
| 393 | mMainHandler.obtainMessage(MainHandler.MSG_UPDATE_ACTIVE_WINDOW, |
| 394 | event.getWindowId(), event.getEventType()).sendToTarget(); |
Svetoslav Ganov | eeee4d2 | 2011-06-10 20:51:30 -0700 | [diff] [blame] | 395 | notifyAccessibilityServicesDelayedLocked(event, false); |
| 396 | notifyAccessibilityServicesDelayedLocked(event, true); |
| 397 | } |
Svetoslav Ganov | 8678347 | 2012-06-06 21:12:20 -0700 | [diff] [blame] | 398 | if (mHasInputFilter && mInputFilter != null) { |
Svetoslav Ganov | 58d37b5 | 2012-09-18 12:04:19 -0700 | [diff] [blame] | 399 | mMainHandler.obtainMessage(MainHandler.MSG_SEND_ACCESSIBILITY_EVENT_TO_INPUT_FILTER, |
Svetoslav Ganov | e45c0b2 | 2012-06-08 17:44:29 -0700 | [diff] [blame] | 400 | AccessibilityEvent.obtain(event)).sendToTarget(); |
Svetoslav Ganov | 8678347 | 2012-06-06 21:12:20 -0700 | [diff] [blame] | 401 | } |
Svetoslav Ganov | cd94caf | 2012-06-03 19:34:34 -0700 | [diff] [blame] | 402 | event.recycle(); |
Svetoslav Ganov | 58d37b5 | 2012-09-18 12:04:19 -0700 | [diff] [blame] | 403 | getUserStateLocked(resolvedUserId).mHandledFeedbackTypes = 0; |
svetoslavganov | 75986cf | 2009-05-14 22:28:01 -0700 | [diff] [blame] | 404 | } |
svetoslavganov | 75986cf | 2009-05-14 22:28:01 -0700 | [diff] [blame] | 405 | return (OWN_PROCESS_ID != Binder.getCallingPid()); |
| 406 | } |
| 407 | |
Svetoslav Ganov | 58d37b5 | 2012-09-18 12:04:19 -0700 | [diff] [blame] | 408 | public List<AccessibilityServiceInfo> getInstalledAccessibilityServiceList(int userId) { |
svetoslavganov | 75986cf | 2009-05-14 22:28:01 -0700 | [diff] [blame] | 409 | synchronized (mLock) { |
Svetoslav Ganov | 58d37b5 | 2012-09-18 12:04:19 -0700 | [diff] [blame] | 410 | final int resolvedUserId = mSecurityPolicy |
| 411 | .resolveCallingUserIdEnforcingPermissionsLocked(userId); |
Svetoslav Ganov | 319d55b | 2013-05-17 19:12:38 -0700 | [diff] [blame] | 412 | // The automation service is a fake one and should not be reported |
| 413 | // to clients as being installed - it really is not. |
| 414 | UserState userState = getUserStateLocked(resolvedUserId); |
| 415 | if (userState.mUiAutomationService != null) { |
| 416 | List<AccessibilityServiceInfo> installedServices = |
| 417 | new ArrayList<AccessibilityServiceInfo>(); |
| 418 | installedServices.addAll(userState.mInstalledServices); |
| 419 | installedServices.remove(userState.mUiAutomationService); |
| 420 | return installedServices; |
| 421 | } |
| 422 | return userState.mInstalledServices; |
svetoslavganov | 75986cf | 2009-05-14 22:28:01 -0700 | [diff] [blame] | 423 | } |
| 424 | } |
| 425 | |
Svetoslav Ganov | 58d37b5 | 2012-09-18 12:04:19 -0700 | [diff] [blame] | 426 | public List<AccessibilityServiceInfo> getEnabledAccessibilityServiceList(int feedbackType, |
| 427 | int userId) { |
| 428 | List<AccessibilityServiceInfo> result = null; |
Svetoslav Ganov | 736c275 | 2011-04-22 18:30:36 -0700 | [diff] [blame] | 429 | synchronized (mLock) { |
Svetoslav Ganov | 58d37b5 | 2012-09-18 12:04:19 -0700 | [diff] [blame] | 430 | final int resolvedUserId = mSecurityPolicy |
| 431 | .resolveCallingUserIdEnforcingPermissionsLocked(userId); |
Svetoslav Ganov | 319d55b | 2013-05-17 19:12:38 -0700 | [diff] [blame] | 432 | |
| 433 | // The automation service is a fake one and should not be reported |
| 434 | // to clients as being enabled. The automation service is always the |
| 435 | // only active one, if it exists. |
| 436 | UserState userState = getUserStateLocked(resolvedUserId); |
| 437 | if (userState.mUiAutomationService != null) { |
| 438 | return Collections.emptyList(); |
| 439 | } |
| 440 | |
Svetoslav Ganov | 58d37b5 | 2012-09-18 12:04:19 -0700 | [diff] [blame] | 441 | result = mEnabledServicesForFeedbackTempList; |
| 442 | result.clear(); |
Svetoslav Ganov | 319d55b | 2013-05-17 19:12:38 -0700 | [diff] [blame] | 443 | List<Service> services = userState.mBoundServices; |
Svetoslav Ganov | cc4053e | 2011-05-23 13:37:44 -0700 | [diff] [blame] | 444 | while (feedbackType != 0) { |
| 445 | final int feedbackTypeBit = (1 << Integer.numberOfTrailingZeros(feedbackType)); |
| 446 | feedbackType &= ~feedbackTypeBit; |
Svetoslav Ganov | f9886f3 | 2011-05-10 15:28:33 -0700 | [diff] [blame] | 447 | final int serviceCount = services.size(); |
| 448 | for (int i = 0; i < serviceCount; i++) { |
| 449 | Service service = services.get(i); |
Svetoslav Ganov | c321c19 | 2011-06-03 19:43:23 -0700 | [diff] [blame] | 450 | if ((service.mFeedbackType & feedbackTypeBit) != 0) { |
Svetoslav Ganov | f9886f3 | 2011-05-10 15:28:33 -0700 | [diff] [blame] | 451 | result.add(service.mAccessibilityServiceInfo); |
| 452 | } |
Svetoslav Ganov | cc4053e | 2011-05-23 13:37:44 -0700 | [diff] [blame] | 453 | } |
Svetoslav Ganov | 736c275 | 2011-04-22 18:30:36 -0700 | [diff] [blame] | 454 | } |
Svetoslav Ganov | 736c275 | 2011-04-22 18:30:36 -0700 | [diff] [blame] | 455 | } |
Svetoslav Ganov | f9886f3 | 2011-05-10 15:28:33 -0700 | [diff] [blame] | 456 | return result; |
Svetoslav Ganov | 736c275 | 2011-04-22 18:30:36 -0700 | [diff] [blame] | 457 | } |
| 458 | |
Svetoslav Ganov | 58d37b5 | 2012-09-18 12:04:19 -0700 | [diff] [blame] | 459 | public void interrupt(int userId) { |
| 460 | CopyOnWriteArrayList<Service> services; |
svetoslavganov | 75986cf | 2009-05-14 22:28:01 -0700 | [diff] [blame] | 461 | synchronized (mLock) { |
Svetoslav Ganov | 58d37b5 | 2012-09-18 12:04:19 -0700 | [diff] [blame] | 462 | final int resolvedUserId = mSecurityPolicy |
| 463 | .resolveCallingUserIdEnforcingPermissionsLocked(userId); |
| 464 | // This method does nothing for a background user. |
| 465 | if (resolvedUserId != mCurrentUserId) { |
| 466 | return; |
| 467 | } |
Svetoslav | 57bf885 | 2013-02-07 19:21:42 -0800 | [diff] [blame] | 468 | services = getUserStateLocked(resolvedUserId).mBoundServices; |
Svetoslav Ganov | 58d37b5 | 2012-09-18 12:04:19 -0700 | [diff] [blame] | 469 | } |
| 470 | for (int i = 0, count = services.size(); i < count; i++) { |
| 471 | Service service = services.get(i); |
| 472 | try { |
| 473 | service.mServiceInterface.onInterrupt(); |
| 474 | } catch (RemoteException re) { |
| 475 | Slog.e(LOG_TAG, "Error during sending interrupt request to " |
| 476 | + service.mService, re); |
svetoslavganov | 75986cf | 2009-05-14 22:28:01 -0700 | [diff] [blame] | 477 | } |
| 478 | } |
| 479 | } |
| 480 | |
Svetoslav Ganov | 8643aa0 | 2011-04-20 12:12:33 -0700 | [diff] [blame] | 481 | public int addAccessibilityInteractionConnection(IWindow windowToken, |
Svetoslav Ganov | 58d37b5 | 2012-09-18 12:04:19 -0700 | [diff] [blame] | 482 | IAccessibilityInteractionConnection connection, int userId) throws RemoteException { |
Svetoslav Ganov | 8643aa0 | 2011-04-20 12:12:33 -0700 | [diff] [blame] | 483 | synchronized (mLock) { |
Svetoslav Ganov | 58d37b5 | 2012-09-18 12:04:19 -0700 | [diff] [blame] | 484 | final int resolvedUserId = mSecurityPolicy |
| 485 | .resolveCallingUserIdEnforcingPermissionsLocked(userId); |
Svetoslav Ganov | 8643aa0 | 2011-04-20 12:12:33 -0700 | [diff] [blame] | 486 | final int windowId = sNextWindowId++; |
Svetoslav Ganov | 58d37b5 | 2012-09-18 12:04:19 -0700 | [diff] [blame] | 487 | // If the window is from a process that runs across users such as |
| 488 | // the system UI or the system we add it to the global state that |
| 489 | // is shared across users. |
| 490 | if (mSecurityPolicy.isCallerInteractingAcrossUsers(userId)) { |
| 491 | AccessibilityConnectionWrapper wrapper = new AccessibilityConnectionWrapper( |
| 492 | windowId, connection, UserHandle.USER_ALL); |
| 493 | wrapper.linkToDeath(); |
| 494 | mGlobalInteractionConnections.put(windowId, wrapper); |
| 495 | mGlobalWindowTokens.put(windowId, windowToken.asBinder()); |
Svetoslav Ganov | a8afa69 | 2012-09-25 13:03:18 -0700 | [diff] [blame] | 496 | if (DEBUG) { |
| 497 | Slog.i(LOG_TAG, "Added global connection for pid:" + Binder.getCallingPid() |
| 498 | + " with windowId: " + windowId); |
| 499 | } |
Svetoslav Ganov | 58d37b5 | 2012-09-18 12:04:19 -0700 | [diff] [blame] | 500 | } else { |
| 501 | AccessibilityConnectionWrapper wrapper = new AccessibilityConnectionWrapper( |
| 502 | windowId, connection, resolvedUserId); |
| 503 | wrapper.linkToDeath(); |
| 504 | UserState userState = getUserStateLocked(resolvedUserId); |
| 505 | userState.mInteractionConnections.put(windowId, wrapper); |
| 506 | userState.mWindowTokens.put(windowId, windowToken.asBinder()); |
Svetoslav Ganov | a8afa69 | 2012-09-25 13:03:18 -0700 | [diff] [blame] | 507 | if (DEBUG) { |
| 508 | Slog.i(LOG_TAG, "Added user connection for pid:" + Binder.getCallingPid() |
| 509 | + " with windowId: " + windowId + " and userId:" + mCurrentUserId); |
| 510 | } |
Svetoslav Ganov | 58d37b5 | 2012-09-18 12:04:19 -0700 | [diff] [blame] | 511 | } |
Svetoslav Ganov | 8643aa0 | 2011-04-20 12:12:33 -0700 | [diff] [blame] | 512 | if (DEBUG) { |
| 513 | Slog.i(LOG_TAG, "Adding interaction connection to windowId: " + windowId); |
| 514 | } |
| 515 | return windowId; |
| 516 | } |
| 517 | } |
| 518 | |
Svetoslav Ganov | 58d37b5 | 2012-09-18 12:04:19 -0700 | [diff] [blame] | 519 | public void removeAccessibilityInteractionConnection(IWindow window) { |
Svetoslav Ganov | 8643aa0 | 2011-04-20 12:12:33 -0700 | [diff] [blame] | 520 | synchronized (mLock) { |
Svetoslav Ganov | 58d37b5 | 2012-09-18 12:04:19 -0700 | [diff] [blame] | 521 | mSecurityPolicy.resolveCallingUserIdEnforcingPermissionsLocked( |
| 522 | UserHandle.getCallingUserId()); |
| 523 | IBinder token = window.asBinder(); |
Svetoslav Ganov | a8afa69 | 2012-09-25 13:03:18 -0700 | [diff] [blame] | 524 | final int removedWindowId = removeAccessibilityInteractionConnectionInternalLocked( |
Svetoslav Ganov | 58d37b5 | 2012-09-18 12:04:19 -0700 | [diff] [blame] | 525 | token, mGlobalWindowTokens, mGlobalInteractionConnections); |
Svetoslav Ganov | a8afa69 | 2012-09-25 13:03:18 -0700 | [diff] [blame] | 526 | if (removedWindowId >= 0) { |
| 527 | if (DEBUG) { |
| 528 | Slog.i(LOG_TAG, "Removed global connection for pid:" + Binder.getCallingPid() |
| 529 | + " with windowId: " + removedWindowId); |
| 530 | } |
Svetoslav Ganov | 58d37b5 | 2012-09-18 12:04:19 -0700 | [diff] [blame] | 531 | return; |
| 532 | } |
| 533 | final int userCount = mUserStates.size(); |
| 534 | for (int i = 0; i < userCount; i++) { |
| 535 | UserState userState = mUserStates.valueAt(i); |
Svetoslav Ganov | a8afa69 | 2012-09-25 13:03:18 -0700 | [diff] [blame] | 536 | final int removedWindowIdForUser = |
Svetoslav Ganov | 58d37b5 | 2012-09-18 12:04:19 -0700 | [diff] [blame] | 537 | removeAccessibilityInteractionConnectionInternalLocked( |
| 538 | token, userState.mWindowTokens, userState.mInteractionConnections); |
Svetoslav Ganov | a8afa69 | 2012-09-25 13:03:18 -0700 | [diff] [blame] | 539 | if (removedWindowIdForUser >= 0) { |
| 540 | if (DEBUG) { |
| 541 | Slog.i(LOG_TAG, "Removed user connection for pid:" + Binder.getCallingPid() |
| 542 | + " with windowId: " + removedWindowIdForUser + " and userId:" |
| 543 | + mUserStates.keyAt(i)); |
| 544 | } |
Svetoslav Ganov | 8643aa0 | 2011-04-20 12:12:33 -0700 | [diff] [blame] | 545 | return; |
| 546 | } |
| 547 | } |
| 548 | } |
| 549 | } |
| 550 | |
Svetoslav Ganov | a8afa69 | 2012-09-25 13:03:18 -0700 | [diff] [blame] | 551 | private int removeAccessibilityInteractionConnectionInternalLocked(IBinder windowToken, |
Svetoslav Ganov | 58d37b5 | 2012-09-18 12:04:19 -0700 | [diff] [blame] | 552 | SparseArray<IBinder> windowTokens, |
| 553 | SparseArray<AccessibilityConnectionWrapper> interactionConnections) { |
| 554 | final int count = windowTokens.size(); |
| 555 | for (int i = 0; i < count; i++) { |
| 556 | if (windowTokens.valueAt(i) == windowToken) { |
| 557 | final int windowId = windowTokens.keyAt(i); |
| 558 | windowTokens.removeAt(i); |
| 559 | AccessibilityConnectionWrapper wrapper = interactionConnections.get(windowId); |
| 560 | wrapper.unlinkToDeath(); |
| 561 | interactionConnections.remove(windowId); |
Svetoslav Ganov | a8afa69 | 2012-09-25 13:03:18 -0700 | [diff] [blame] | 562 | return windowId; |
Svetoslav Ganov | 58d37b5 | 2012-09-18 12:04:19 -0700 | [diff] [blame] | 563 | } |
| 564 | } |
Svetoslav Ganov | a8afa69 | 2012-09-25 13:03:18 -0700 | [diff] [blame] | 565 | return -1; |
Svetoslav Ganov | 58d37b5 | 2012-09-18 12:04:19 -0700 | [diff] [blame] | 566 | } |
| 567 | |
Svetoslav | db7da0e | 2013-04-22 18:34:02 -0700 | [diff] [blame] | 568 | public void registerUiTestAutomationService(IBinder owner, |
| 569 | IAccessibilityServiceClient serviceClient, |
Svetoslav Ganov | 79311c4 | 2012-01-17 20:24:26 -0800 | [diff] [blame] | 570 | AccessibilityServiceInfo accessibilityServiceInfo) { |
Svetoslav Ganov | 8643aa0 | 2011-04-20 12:12:33 -0700 | [diff] [blame] | 571 | mSecurityPolicy.enforceCallingPermission(Manifest.permission.RETRIEVE_WINDOW_CONTENT, |
Svetoslav Ganov | 0d04e24 | 2012-02-21 13:46:36 -0800 | [diff] [blame] | 572 | FUNCTION_REGISTER_UI_TEST_AUTOMATION_SERVICE); |
Svetoslav | 57bf885 | 2013-02-07 19:21:42 -0800 | [diff] [blame] | 573 | |
| 574 | accessibilityServiceInfo.setComponentName(sFakeAccessibilityServiceComponentName); |
| 575 | |
Svetoslav Ganov | 8643aa0 | 2011-04-20 12:12:33 -0700 | [diff] [blame] | 576 | synchronized (mLock) { |
Svetoslav | 57bf885 | 2013-02-07 19:21:42 -0800 | [diff] [blame] | 577 | UserState userState = getCurrentUserStateLocked(); |
| 578 | |
| 579 | if (userState.mUiAutomationService != null) { |
Svetoslav Ganov | 80943d8 | 2013-01-02 10:25:37 -0800 | [diff] [blame] | 580 | throw new IllegalStateException("UiAutomationService " + serviceClient |
| 581 | + "already registered!"); |
| 582 | } |
Svetoslav Ganov | b6eca6e | 2011-09-27 10:47:58 -0700 | [diff] [blame] | 583 | |
Svetoslav | 3c55e5c | 2013-02-27 18:24:28 -0800 | [diff] [blame] | 584 | try { |
| 585 | owner.linkToDeath(userState.mUiAutomationSerivceOnwerDeathRecipient, 0); |
| 586 | } catch (RemoteException re) { |
| 587 | Slog.e(LOG_TAG, "Couldn't register for the death of a" |
| 588 | + " UiTestAutomationService!", re); |
| 589 | return; |
| 590 | } |
| 591 | |
| 592 | userState.mUiAutomationServiceOwner = owner; |
Svetoslav | 57bf885 | 2013-02-07 19:21:42 -0800 | [diff] [blame] | 593 | userState.mUiAutomationServiceClient = serviceClient; |
| 594 | |
| 595 | // Set the temporary state. |
| 596 | userState.mIsAccessibilityEnabled = true; |
Svetoslav Ganov | 657968a | 2012-09-21 19:08:35 -0700 | [diff] [blame] | 597 | userState.mIsTouchExplorationEnabled = false; |
Svetoslav | 3822896 | 2013-01-29 01:04:35 -0800 | [diff] [blame] | 598 | userState.mIsEnhancedWebAccessibilityEnabled = false; |
Svetoslav | 57bf885 | 2013-02-07 19:21:42 -0800 | [diff] [blame] | 599 | userState.mIsDisplayMagnificationEnabled = false; |
| 600 | userState.mInstalledServices.add(accessibilityServiceInfo); |
| 601 | userState.mEnabledServices.clear(); |
| 602 | userState.mEnabledServices.add(sFakeAccessibilityServiceComponentName); |
| 603 | userState.mTouchExplorationGrantedServices.add(sFakeAccessibilityServiceComponentName); |
Svetoslav | 3822896 | 2013-01-29 01:04:35 -0800 | [diff] [blame] | 604 | |
Svetoslav | 57bf885 | 2013-02-07 19:21:42 -0800 | [diff] [blame] | 605 | // Use the new state instead of settings. |
| 606 | onUserStateChangedLocked(userState); |
| 607 | } |
| 608 | } |
Svetoslav Ganov | 657968a | 2012-09-21 19:08:35 -0700 | [diff] [blame] | 609 | |
Svetoslav | 57bf885 | 2013-02-07 19:21:42 -0800 | [diff] [blame] | 610 | public void unregisterUiTestAutomationService(IAccessibilityServiceClient serviceClient) { |
| 611 | synchronized (mLock) { |
| 612 | UserState userState = getCurrentUserStateLocked(); |
| 613 | // Automation service is not bound, so pretend it died to perform clean up. |
| 614 | if (userState.mUiAutomationService != null |
Svetoslav | 57bf885 | 2013-02-07 19:21:42 -0800 | [diff] [blame] | 615 | && serviceClient != null |
Svetoslav | 0726843 | 2013-02-13 14:55:19 -0800 | [diff] [blame] | 616 | && userState.mUiAutomationService != null |
| 617 | && userState.mUiAutomationService.mServiceInterface != null |
Svetoslav | 57bf885 | 2013-02-07 19:21:42 -0800 | [diff] [blame] | 618 | && userState.mUiAutomationService.mServiceInterface.asBinder() |
| 619 | == serviceClient.asBinder()) { |
| 620 | userState.mUiAutomationService.binderDied(); |
| 621 | } else { |
| 622 | throw new IllegalStateException("UiAutomationService " + serviceClient |
| 623 | + " not registered!"); |
| 624 | } |
Svetoslav Ganov | 8643aa0 | 2011-04-20 12:12:33 -0700 | [diff] [blame] | 625 | } |
Svetoslav Ganov | d116d7c | 2011-11-21 18:41:59 -0800 | [diff] [blame] | 626 | } |
| 627 | |
Svetoslav Ganov | 7befb7d | 2012-09-27 16:49:23 -0700 | [diff] [blame] | 628 | public void temporaryEnableAccessibilityStateUntilKeyguardRemoved( |
| 629 | ComponentName service, boolean touchExplorationEnabled) { |
| 630 | mSecurityPolicy.enforceCallingPermission( |
| 631 | Manifest.permission.TEMPORARY_ENABLE_ACCESSIBILITY, |
| 632 | TEMPORARY_ENABLE_ACCESSIBILITY_UNTIL_KEYGUARD_REMOVED); |
| 633 | try { |
| 634 | if (!mWindowManagerService.isKeyguardLocked()) { |
| 635 | return; |
| 636 | } |
| 637 | } catch (RemoteException re) { |
| 638 | return; |
| 639 | } |
| 640 | synchronized (mLock) { |
Svetoslav Ganov | 7befb7d | 2012-09-27 16:49:23 -0700 | [diff] [blame] | 641 | // Set the temporary state. |
Svetoslav | 57bf885 | 2013-02-07 19:21:42 -0800 | [diff] [blame] | 642 | UserState userState = getCurrentUserStateLocked(); |
| 643 | |
| 644 | // This is a nop if UI automation is enabled. |
| 645 | if (userState.mUiAutomationService != null) { |
| 646 | return; |
| 647 | } |
| 648 | |
Svetoslav Ganov | 7befb7d | 2012-09-27 16:49:23 -0700 | [diff] [blame] | 649 | userState.mIsAccessibilityEnabled = true; |
Svetoslav | 3822896 | 2013-01-29 01:04:35 -0800 | [diff] [blame] | 650 | userState.mIsTouchExplorationEnabled = touchExplorationEnabled; |
| 651 | userState.mIsEnhancedWebAccessibilityEnabled = false; |
Svetoslav Ganov | 7befb7d | 2012-09-27 16:49:23 -0700 | [diff] [blame] | 652 | userState.mIsDisplayMagnificationEnabled = false; |
| 653 | userState.mEnabledServices.clear(); |
| 654 | userState.mEnabledServices.add(service); |
Svetoslav | 57bf885 | 2013-02-07 19:21:42 -0800 | [diff] [blame] | 655 | userState.mBindingServices.clear(); |
Svetoslav Ganov | 447d946 | 2013-02-01 19:46:20 +0000 | [diff] [blame] | 656 | userState.mTouchExplorationGrantedServices.clear(); |
| 657 | userState.mTouchExplorationGrantedServices.add(service); |
Svetoslav Ganov | 7befb7d | 2012-09-27 16:49:23 -0700 | [diff] [blame] | 658 | |
Svetoslav | 57bf885 | 2013-02-07 19:21:42 -0800 | [diff] [blame] | 659 | // User the current state instead settings. |
| 660 | onUserStateChangedLocked(userState); |
Svetoslav Ganov | 79311c4 | 2012-01-17 20:24:26 -0800 | [diff] [blame] | 661 | } |
| 662 | } |
| 663 | |
Svetoslav Ganov | e15ccb9 | 2012-05-16 15:48:55 -0700 | [diff] [blame] | 664 | boolean onGesture(int gestureId) { |
Svetoslav Ganov | 4213804 | 2012-03-20 11:51:39 -0700 | [diff] [blame] | 665 | synchronized (mLock) { |
Svetoslav Ganov | fefd20e | 2012-04-19 21:44:35 -0700 | [diff] [blame] | 666 | boolean handled = notifyGestureLocked(gestureId, false); |
| 667 | if (!handled) { |
| 668 | handled = notifyGestureLocked(gestureId, true); |
Svetoslav Ganov | 4213804 | 2012-03-20 11:51:39 -0700 | [diff] [blame] | 669 | } |
Svetoslav Ganov | fefd20e | 2012-04-19 21:44:35 -0700 | [diff] [blame] | 670 | return handled; |
| 671 | } |
| 672 | } |
| 673 | |
Svetoslav | c4fccd1 | 2013-04-09 12:58:41 -0700 | [diff] [blame] | 674 | boolean notifyKeyEvent(KeyEvent event, int policyFlags) { |
| 675 | synchronized (mLock) { |
| 676 | KeyEvent localClone = KeyEvent.obtain(event); |
| 677 | boolean handled = notifyKeyEventLocked(localClone, policyFlags, false); |
| 678 | if (!handled) { |
| 679 | handled = notifyKeyEventLocked(localClone, policyFlags, true); |
| 680 | } |
| 681 | return handled; |
| 682 | } |
| 683 | } |
| 684 | |
Svetoslav Ganov | e15ccb9 | 2012-05-16 15:48:55 -0700 | [diff] [blame] | 685 | /** |
Svetoslav Ganov | 8678347 | 2012-06-06 21:12:20 -0700 | [diff] [blame] | 686 | * Gets the bounds of the accessibility focus in the active window. |
Svetoslav Ganov | e15ccb9 | 2012-05-16 15:48:55 -0700 | [diff] [blame] | 687 | * |
Svetoslav Ganov | e15ccb9 | 2012-05-16 15:48:55 -0700 | [diff] [blame] | 688 | * @param outBounds The output to which to write the focus bounds. |
Svetoslav Ganov | 8678347 | 2012-06-06 21:12:20 -0700 | [diff] [blame] | 689 | * @return Whether accessibility focus was found and the bounds are populated. |
Svetoslav Ganov | e15ccb9 | 2012-05-16 15:48:55 -0700 | [diff] [blame] | 690 | */ |
Svetoslav Ganov | a94c319 | 2012-10-31 18:28:49 -0700 | [diff] [blame] | 691 | // TODO: (multi-display) Make sure this works for multiple displays. |
Svetoslav Ganov | 8678347 | 2012-06-06 21:12:20 -0700 | [diff] [blame] | 692 | boolean getAccessibilityFocusBoundsInActiveWindow(Rect outBounds) { |
Svetoslav Ganov | e15ccb9 | 2012-05-16 15:48:55 -0700 | [diff] [blame] | 693 | // Instead of keeping track of accessibility focus events per |
| 694 | // window to be able to find the focus in the active window, |
| 695 | // we take a stateless approach and look it up. This is fine |
| 696 | // since we do this only when the user clicks/long presses. |
| 697 | Service service = getQueryBridge(); |
| 698 | final int connectionId = service.mId; |
| 699 | AccessibilityInteractionClient client = AccessibilityInteractionClient.getInstance(); |
| 700 | client.addConnection(connectionId, service); |
| 701 | try { |
| 702 | AccessibilityNodeInfo root = AccessibilityInteractionClient.getInstance() |
| 703 | .getRootInActiveWindow(connectionId); |
| 704 | if (root == null) { |
| 705 | return false; |
| 706 | } |
Svetoslav Ganov | e15ccb9 | 2012-05-16 15:48:55 -0700 | [diff] [blame] | 707 | AccessibilityNodeInfo focus = root.findFocus( |
| 708 | AccessibilityNodeInfo.FOCUS_ACCESSIBILITY); |
| 709 | if (focus == null) { |
| 710 | return false; |
| 711 | } |
| 712 | focus.getBoundsInScreen(outBounds); |
Svetoslav Ganov | 152e9bb | 2012-10-12 20:15:29 -0700 | [diff] [blame] | 713 | |
| 714 | MagnificationSpec spec = service.getCompatibleMagnificationSpec(focus.getWindowId()); |
| 715 | if (spec != null && !spec.isNop()) { |
| 716 | outBounds.offset((int) -spec.offsetX, (int) -spec.offsetY); |
| 717 | outBounds.scale(1 / spec.scale); |
| 718 | } |
| 719 | |
Svetoslav Ganov | a94c319 | 2012-10-31 18:28:49 -0700 | [diff] [blame] | 720 | // Clip to the window rectangle. |
| 721 | Rect windowBounds = mTempRect; |
| 722 | getActiveWindowBounds(windowBounds); |
| 723 | outBounds.intersect(windowBounds); |
| 724 | // Clip to the screen rectangle. |
| 725 | mDefaultDisplay.getRealSize(mTempPoint); |
| 726 | outBounds.intersect(0, 0, mTempPoint.x, mTempPoint.y); |
Svetoslav Ganov | 152e9bb | 2012-10-12 20:15:29 -0700 | [diff] [blame] | 727 | |
Svetoslav Ganov | e15ccb9 | 2012-05-16 15:48:55 -0700 | [diff] [blame] | 728 | return true; |
| 729 | } finally { |
| 730 | client.removeConnection(connectionId); |
| 731 | } |
| 732 | } |
| 733 | |
Svetoslav Ganov | 8678347 | 2012-06-06 21:12:20 -0700 | [diff] [blame] | 734 | /** |
| 735 | * Gets the bounds of the active window. |
| 736 | * |
| 737 | * @param outBounds The output to which to write the bounds. |
| 738 | */ |
Svetoslav Ganov | c9c9a48 | 2012-07-16 08:46:07 -0700 | [diff] [blame] | 739 | boolean getActiveWindowBounds(Rect outBounds) { |
Svetoslav Ganov | 58d37b5 | 2012-09-18 12:04:19 -0700 | [diff] [blame] | 740 | IBinder token; |
Svetoslav Ganov | 8678347 | 2012-06-06 21:12:20 -0700 | [diff] [blame] | 741 | synchronized (mLock) { |
| 742 | final int windowId = mSecurityPolicy.mActiveWindowId; |
Svetoslav Ganov | 58d37b5 | 2012-09-18 12:04:19 -0700 | [diff] [blame] | 743 | token = mGlobalWindowTokens.get(windowId); |
| 744 | if (token == null) { |
| 745 | token = getCurrentUserStateLocked().mWindowTokens.get(windowId); |
Svetoslav Ganov | c9c9a48 | 2012-07-16 08:46:07 -0700 | [diff] [blame] | 746 | } |
Svetoslav Ganov | 58d37b5 | 2012-09-18 12:04:19 -0700 | [diff] [blame] | 747 | } |
Svetoslav Ganov | 58d37b5 | 2012-09-18 12:04:19 -0700 | [diff] [blame] | 748 | try { |
Svetoslav Ganov | 152e9bb | 2012-10-12 20:15:29 -0700 | [diff] [blame] | 749 | mWindowManagerService.getWindowFrame(token, outBounds); |
| 750 | if (!outBounds.isEmpty()) { |
Svetoslav Ganov | 58d37b5 | 2012-09-18 12:04:19 -0700 | [diff] [blame] | 751 | return true; |
| 752 | } |
| 753 | } catch (RemoteException re) { |
| 754 | /* ignore */ |
Svetoslav Ganov | 58d37b5 | 2012-09-18 12:04:19 -0700 | [diff] [blame] | 755 | } |
| 756 | return false; |
| 757 | } |
| 758 | |
| 759 | int getActiveWindowId() { |
| 760 | return mSecurityPolicy.mActiveWindowId; |
| 761 | } |
| 762 | |
Svetoslav Ganov | 6ae8a24 | 2012-10-10 13:09:00 -0700 | [diff] [blame] | 763 | void onTouchInteractionStart() { |
| 764 | mSecurityPolicy.onTouchInteractionStart(); |
| 765 | } |
| 766 | |
Svetoslav Ganov | f772cba | 2012-10-05 18:49:17 -0700 | [diff] [blame] | 767 | void onTouchInteractionEnd() { |
| 768 | mSecurityPolicy.onTouchInteractionEnd(); |
| 769 | } |
| 770 | |
Svetoslav Ganov | 152e9bb | 2012-10-12 20:15:29 -0700 | [diff] [blame] | 771 | void onMagnificationStateChanged() { |
| 772 | notifyClearAccessibilityNodeInfoCacheLocked(); |
| 773 | } |
| 774 | |
Svetoslav Ganov | 58d37b5 | 2012-09-18 12:04:19 -0700 | [diff] [blame] | 775 | private void switchUser(int userId) { |
| 776 | synchronized (mLock) { |
Svetoslav | 3b817ae | 2013-06-19 16:28:30 -0700 | [diff] [blame] | 777 | if (mCurrentUserId == userId && mInitialized) { |
| 778 | return; |
| 779 | } |
| 780 | |
Svetoslav Ganov | 58d37b5 | 2012-09-18 12:04:19 -0700 | [diff] [blame] | 781 | // Disconnect from services for the old user. |
| 782 | UserState oldUserState = getUserStateLocked(mCurrentUserId); |
Svetoslav | 5fec0c5 | 2013-02-15 12:18:33 -0800 | [diff] [blame] | 783 | oldUserState.onSwitchToAnotherUser(); |
Svetoslav Ganov | 58d37b5 | 2012-09-18 12:04:19 -0700 | [diff] [blame] | 784 | |
| 785 | // Disable the local managers for the old user. |
| 786 | if (oldUserState.mClients.getRegisteredCallbackCount() > 0) { |
| 787 | mMainHandler.obtainMessage(MainHandler.MSG_SEND_CLEARED_STATE_TO_CLIENTS_FOR_USER, |
| 788 | oldUserState.mUserId, 0).sendToTarget(); |
| 789 | } |
| 790 | |
Svetoslav Ganov | 59f0769 | 2012-10-01 19:01:32 -0700 | [diff] [blame] | 791 | // Announce user changes only if more that one exist. |
| 792 | UserManager userManager = (UserManager) mContext.getSystemService(Context.USER_SERVICE); |
| 793 | final boolean announceNewUser = userManager.getUsers().size() > 1; |
| 794 | |
Svetoslav Ganov | 58d37b5 | 2012-09-18 12:04:19 -0700 | [diff] [blame] | 795 | // The user changed. |
| 796 | mCurrentUserId = userId; |
| 797 | |
Svetoslav | 57bf885 | 2013-02-07 19:21:42 -0800 | [diff] [blame] | 798 | UserState userState = getCurrentUserStateLocked(); |
| 799 | if (userState.mUiAutomationService != null) { |
| 800 | // Switching users disables the UI automation service. |
| 801 | userState.mUiAutomationService.binderDied(); |
Svetoslav | 57bf885 | 2013-02-07 19:21:42 -0800 | [diff] [blame] | 802 | } |
Svetoslav Ganov | 7befb7d | 2012-09-27 16:49:23 -0700 | [diff] [blame] | 803 | |
Svetoslav | 5fec0c5 | 2013-02-15 12:18:33 -0800 | [diff] [blame] | 804 | readConfigurationForUserStateLocked(userState); |
| 805 | // Even if reading did not yield change, we have to update |
| 806 | // the state since the context in which the current user |
| 807 | // state was used has changed since it was inactive. |
| 808 | onUserStateChangedLocked(userState); |
| 809 | |
Svetoslav Ganov | 59f0769 | 2012-10-01 19:01:32 -0700 | [diff] [blame] | 810 | if (announceNewUser) { |
| 811 | // Schedule announcement of the current user if needed. |
| 812 | mMainHandler.sendEmptyMessageDelayed(MainHandler.MSG_ANNOUNCE_NEW_USER_IF_NEEDED, |
| 813 | WAIT_FOR_USER_STATE_FULLY_INITIALIZED_MILLIS); |
| 814 | } |
Svetoslav Ganov | 8678347 | 2012-06-06 21:12:20 -0700 | [diff] [blame] | 815 | } |
| 816 | } |
| 817 | |
Svetoslav Ganov | 58d37b5 | 2012-09-18 12:04:19 -0700 | [diff] [blame] | 818 | private void removeUser(int userId) { |
| 819 | synchronized (mLock) { |
| 820 | mUserStates.remove(userId); |
| 821 | } |
Svetoslav Ganov | 385d9f2 | 2012-06-07 16:35:04 -0700 | [diff] [blame] | 822 | } |
| 823 | |
Svetoslav Ganov | e15ccb9 | 2012-05-16 15:48:55 -0700 | [diff] [blame] | 824 | private Service getQueryBridge() { |
| 825 | if (mQueryBridge == null) { |
| 826 | AccessibilityServiceInfo info = new AccessibilityServiceInfo(); |
Svetoslav | 108fe59 | 2013-04-26 15:08:16 -0700 | [diff] [blame] | 827 | info.setCapabilities(AccessibilityServiceInfo.CAPABILITY_CAN_RETRIEVE_WINDOW_CONTENT); |
Svetoslav | 57bf885 | 2013-02-07 19:21:42 -0800 | [diff] [blame] | 828 | mQueryBridge = new Service(UserHandle.USER_NULL, |
| 829 | sFakeAccessibilityServiceComponentName, info); |
Svetoslav Ganov | e15ccb9 | 2012-05-16 15:48:55 -0700 | [diff] [blame] | 830 | } |
| 831 | return mQueryBridge; |
| 832 | } |
| 833 | |
Svetoslav Ganov | 4213804 | 2012-03-20 11:51:39 -0700 | [diff] [blame] | 834 | private boolean notifyGestureLocked(int gestureId, boolean isDefault) { |
Svetoslav Ganov | fefd20e | 2012-04-19 21:44:35 -0700 | [diff] [blame] | 835 | // TODO: Now we are giving the gestures to the last enabled |
| 836 | // service that can handle them which is the last one |
| 837 | // in our list since we write the last enabled as the |
| 838 | // last record in the enabled services setting. Ideally, |
| 839 | // the user should make the call which service handles |
| 840 | // gestures. However, only one service should handle |
Svetoslav Ganov | e4abc51 | 2012-05-09 11:02:38 -0700 | [diff] [blame] | 841 | // gestures to avoid user frustration when different |
| 842 | // behavior is observed from different combinations of |
Svetoslav Ganov | fefd20e | 2012-04-19 21:44:35 -0700 | [diff] [blame] | 843 | // enabled accessibility services. |
Svetoslav Ganov | 58d37b5 | 2012-09-18 12:04:19 -0700 | [diff] [blame] | 844 | UserState state = getCurrentUserStateLocked(); |
Svetoslav | 57bf885 | 2013-02-07 19:21:42 -0800 | [diff] [blame] | 845 | for (int i = state.mBoundServices.size() - 1; i >= 0; i--) { |
| 846 | Service service = state.mBoundServices.get(i); |
Svetoslav Ganov | a43ef3d | 2012-07-12 13:07:55 -0700 | [diff] [blame] | 847 | if (service.mRequestTouchExplorationMode && service.mIsDefault == isDefault) { |
Svetoslav Ganov | e15ccb9 | 2012-05-16 15:48:55 -0700 | [diff] [blame] | 848 | service.notifyGesture(gestureId); |
Svetoslav Ganov | fefd20e | 2012-04-19 21:44:35 -0700 | [diff] [blame] | 849 | return true; |
Svetoslav Ganov | 4213804 | 2012-03-20 11:51:39 -0700 | [diff] [blame] | 850 | } |
| 851 | } |
| 852 | return false; |
| 853 | } |
| 854 | |
Svetoslav | c4fccd1 | 2013-04-09 12:58:41 -0700 | [diff] [blame] | 855 | private boolean notifyKeyEventLocked(KeyEvent event, int policyFlags, boolean isDefault) { |
| 856 | // TODO: Now we are giving the key events to the last enabled |
Svetoslav | 688a697 | 2013-04-16 18:55:38 -0700 | [diff] [blame] | 857 | // service that can handle them Ideally, the user should |
| 858 | // make the call which service handles key events. However, |
| 859 | // only one service should handle key events to avoid user |
| 860 | // frustration when different behavior is observed from |
| 861 | // different combinations of enabled accessibility services. |
Svetoslav | c4fccd1 | 2013-04-09 12:58:41 -0700 | [diff] [blame] | 862 | UserState state = getCurrentUserStateLocked(); |
| 863 | for (int i = state.mBoundServices.size() - 1; i >= 0; i--) { |
| 864 | Service service = state.mBoundServices.get(i); |
Svetoslav | 688a697 | 2013-04-16 18:55:38 -0700 | [diff] [blame] | 865 | // Key events are handled only by services that declared |
| 866 | // this capability and requested to filter key events. |
| 867 | if (!service.mRequestFilterKeyEvents || |
| 868 | (service.mAccessibilityServiceInfo.getCapabilities() & AccessibilityServiceInfo |
| 869 | .CAPABILITY_CAN_REQUEST_FILTER_KEY_EVENTS) == 0) { |
| 870 | continue; |
| 871 | } |
Svetoslav | c4fccd1 | 2013-04-09 12:58:41 -0700 | [diff] [blame] | 872 | if (service.mIsDefault == isDefault) { |
| 873 | service.notifyKeyEvent(event, policyFlags); |
| 874 | return true; |
| 875 | } |
| 876 | } |
| 877 | return false; |
| 878 | } |
| 879 | |
Svetoslav Ganov | 152e9bb | 2012-10-12 20:15:29 -0700 | [diff] [blame] | 880 | private void notifyClearAccessibilityNodeInfoCacheLocked() { |
| 881 | UserState state = getCurrentUserStateLocked(); |
Svetoslav | 57bf885 | 2013-02-07 19:21:42 -0800 | [diff] [blame] | 882 | for (int i = state.mBoundServices.size() - 1; i >= 0; i--) { |
| 883 | Service service = state.mBoundServices.get(i); |
Svetoslav Ganov | 152e9bb | 2012-10-12 20:15:29 -0700 | [diff] [blame] | 884 | service.notifyClearAccessibilityNodeInfoCache(); |
| 885 | } |
| 886 | } |
| 887 | |
Svetoslav Ganov | d116d7c | 2011-11-21 18:41:59 -0800 | [diff] [blame] | 888 | /** |
| 889 | * Removes an AccessibilityInteractionConnection. |
| 890 | * |
| 891 | * @param windowId The id of the window to which the connection is targeted. |
Svetoslav Ganov | 58d37b5 | 2012-09-18 12:04:19 -0700 | [diff] [blame] | 892 | * @param userId The id of the user owning the connection. UserHandle.USER_ALL |
| 893 | * if global. |
Svetoslav Ganov | d116d7c | 2011-11-21 18:41:59 -0800 | [diff] [blame] | 894 | */ |
Svetoslav Ganov | 58d37b5 | 2012-09-18 12:04:19 -0700 | [diff] [blame] | 895 | private void removeAccessibilityInteractionConnectionLocked(int windowId, int userId) { |
| 896 | if (userId == UserHandle.USER_ALL) { |
| 897 | mGlobalWindowTokens.remove(windowId); |
| 898 | mGlobalInteractionConnections.remove(windowId); |
| 899 | } else { |
| 900 | UserState userState = getCurrentUserStateLocked(); |
| 901 | userState.mWindowTokens.remove(windowId); |
| 902 | userState.mInteractionConnections.remove(windowId); |
| 903 | } |
Svetoslav Ganov | d116d7c | 2011-11-21 18:41:59 -0800 | [diff] [blame] | 904 | if (DEBUG) { |
| 905 | Slog.i(LOG_TAG, "Removing interaction connection to windowId: " + windowId); |
| 906 | } |
Svetoslav Ganov | 8643aa0 | 2011-04-20 12:12:33 -0700 | [diff] [blame] | 907 | } |
| 908 | |
Svetoslav | 57bf885 | 2013-02-07 19:21:42 -0800 | [diff] [blame] | 909 | private boolean readInstalledAccessibilityServiceLocked(UserState userState) { |
| 910 | mTempAccessibilityServiceInfoList.clear(); |
svetoslavganov | 75986cf | 2009-05-14 22:28:01 -0700 | [diff] [blame] | 911 | |
Svetoslav Ganov | 58d37b5 | 2012-09-18 12:04:19 -0700 | [diff] [blame] | 912 | List<ResolveInfo> installedServices = mPackageManager.queryIntentServicesAsUser( |
Svetoslav Ganov | cc4053e | 2011-05-23 13:37:44 -0700 | [diff] [blame] | 913 | new Intent(AccessibilityService.SERVICE_INTERFACE), |
Svetoslav Ganov | 58d37b5 | 2012-09-18 12:04:19 -0700 | [diff] [blame] | 914 | PackageManager.GET_SERVICES | PackageManager.GET_META_DATA, |
| 915 | mCurrentUserId); |
svetoslavganov | 75986cf | 2009-05-14 22:28:01 -0700 | [diff] [blame] | 916 | |
| 917 | for (int i = 0, count = installedServices.size(); i < count; i++) { |
Svetoslav Ganov | cc4053e | 2011-05-23 13:37:44 -0700 | [diff] [blame] | 918 | ResolveInfo resolveInfo = installedServices.get(i); |
Svetoslav Ganov | 53e184d | 2012-05-16 15:57:10 -0700 | [diff] [blame] | 919 | ServiceInfo serviceInfo = resolveInfo.serviceInfo; |
Svetoslav Ganov | 58d37b5 | 2012-09-18 12:04:19 -0700 | [diff] [blame] | 920 | if (!android.Manifest.permission.BIND_ACCESSIBILITY_SERVICE.equals( |
| 921 | serviceInfo.permission)) { |
Svetoslav Ganov | 53e184d | 2012-05-16 15:57:10 -0700 | [diff] [blame] | 922 | Slog.w(LOG_TAG, "Skipping accessibilty service " + new ComponentName( |
| 923 | serviceInfo.packageName, serviceInfo.name).flattenToShortString() |
| 924 | + ": it does not require the permission " |
| 925 | + android.Manifest.permission.BIND_ACCESSIBILITY_SERVICE); |
| 926 | continue; |
| 927 | } |
Svetoslav Ganov | cc4053e | 2011-05-23 13:37:44 -0700 | [diff] [blame] | 928 | AccessibilityServiceInfo accessibilityServiceInfo; |
| 929 | try { |
| 930 | accessibilityServiceInfo = new AccessibilityServiceInfo(resolveInfo, mContext); |
Svetoslav | 57bf885 | 2013-02-07 19:21:42 -0800 | [diff] [blame] | 931 | mTempAccessibilityServiceInfoList.add(accessibilityServiceInfo); |
Svetoslav Ganov | cc4053e | 2011-05-23 13:37:44 -0700 | [diff] [blame] | 932 | } catch (XmlPullParserException xppe) { |
| 933 | Slog.e(LOG_TAG, "Error while initializing AccessibilityServiceInfo", xppe); |
| 934 | } catch (IOException ioe) { |
| 935 | Slog.e(LOG_TAG, "Error while initializing AccessibilityServiceInfo", ioe); |
| 936 | } |
svetoslavganov | 75986cf | 2009-05-14 22:28:01 -0700 | [diff] [blame] | 937 | } |
Svetoslav | 57bf885 | 2013-02-07 19:21:42 -0800 | [diff] [blame] | 938 | |
| 939 | if (!mTempAccessibilityServiceInfoList.equals(userState.mInstalledServices)) { |
| 940 | userState.mInstalledServices.clear(); |
| 941 | userState.mInstalledServices.addAll(mTempAccessibilityServiceInfoList); |
| 942 | mTempAccessibilityServiceInfoList.clear(); |
| 943 | return true; |
| 944 | } |
| 945 | |
| 946 | mTempAccessibilityServiceInfoList.clear(); |
| 947 | return false; |
svetoslavganov | 75986cf | 2009-05-14 22:28:01 -0700 | [diff] [blame] | 948 | } |
| 949 | |
Svetoslav | 57bf885 | 2013-02-07 19:21:42 -0800 | [diff] [blame] | 950 | private boolean readEnabledAccessibilityServicesLocked(UserState userState) { |
| 951 | mTempComponentNameSet.clear(); |
| 952 | readComponentNamesFromSettingLocked(Settings.Secure.ENABLED_ACCESSIBILITY_SERVICES, |
| 953 | userState.mUserId, mTempComponentNameSet); |
| 954 | if (!mTempComponentNameSet.equals(userState.mEnabledServices)) { |
| 955 | userState.mEnabledServices.clear(); |
| 956 | userState.mEnabledServices.addAll(mTempComponentNameSet); |
| 957 | mTempComponentNameSet.clear(); |
| 958 | return true; |
| 959 | } |
| 960 | mTempComponentNameSet.clear(); |
| 961 | return false; |
Svetoslav Ganov | 9a4c5cd | 2012-05-30 14:06:32 -0700 | [diff] [blame] | 962 | } |
| 963 | |
Svetoslav | 57bf885 | 2013-02-07 19:21:42 -0800 | [diff] [blame] | 964 | private boolean readTouchExplorationGrantedAccessibilityServicesLocked( |
| 965 | UserState userState) { |
| 966 | mTempComponentNameSet.clear(); |
| 967 | readComponentNamesFromSettingLocked( |
Svetoslav Ganov | 447d946 | 2013-02-01 19:46:20 +0000 | [diff] [blame] | 968 | Settings.Secure.TOUCH_EXPLORATION_GRANTED_ACCESSIBILITY_SERVICES, |
Svetoslav | 57bf885 | 2013-02-07 19:21:42 -0800 | [diff] [blame] | 969 | userState.mUserId, mTempComponentNameSet); |
| 970 | if (!mTempComponentNameSet.equals(userState.mTouchExplorationGrantedServices)) { |
| 971 | userState.mTouchExplorationGrantedServices.clear(); |
| 972 | userState.mTouchExplorationGrantedServices.addAll(mTempComponentNameSet); |
| 973 | mTempComponentNameSet.clear(); |
| 974 | return true; |
| 975 | } |
| 976 | mTempComponentNameSet.clear(); |
| 977 | return false; |
Svetoslav Ganov | 447d946 | 2013-02-01 19:46:20 +0000 | [diff] [blame] | 978 | } |
| 979 | |
svetoslavganov | 75986cf | 2009-05-14 22:28:01 -0700 | [diff] [blame] | 980 | /** |
| 981 | * Performs {@link AccessibilityService}s delayed notification. The delay is configurable |
| 982 | * and denotes the period after the last event before notifying the service. |
| 983 | * |
| 984 | * @param event The event. |
| 985 | * @param isDefault True to notify default listeners, not default services. |
| 986 | */ |
| 987 | private void notifyAccessibilityServicesDelayedLocked(AccessibilityEvent event, |
| 988 | boolean isDefault) { |
Charles Chen | 85b598b | 2009-07-29 17:23:50 -0700 | [diff] [blame] | 989 | try { |
Svetoslav Ganov | 58d37b5 | 2012-09-18 12:04:19 -0700 | [diff] [blame] | 990 | UserState state = getCurrentUserStateLocked(); |
Svetoslav | 57bf885 | 2013-02-07 19:21:42 -0800 | [diff] [blame] | 991 | for (int i = 0, count = state.mBoundServices.size(); i < count; i++) { |
| 992 | Service service = state.mBoundServices.get(i); |
svetoslavganov | 75986cf | 2009-05-14 22:28:01 -0700 | [diff] [blame] | 993 | |
Charles Chen | 85b598b | 2009-07-29 17:23:50 -0700 | [diff] [blame] | 994 | if (service.mIsDefault == isDefault) { |
Svetoslav Ganov | 58d37b5 | 2012-09-18 12:04:19 -0700 | [diff] [blame] | 995 | if (canDispathEventLocked(service, event, state.mHandledFeedbackTypes)) { |
| 996 | state.mHandledFeedbackTypes |= service.mFeedbackType; |
Svetoslav Ganov | e15ccb9 | 2012-05-16 15:48:55 -0700 | [diff] [blame] | 997 | service.notifyAccessibilityEvent(event); |
Charles Chen | 85b598b | 2009-07-29 17:23:50 -0700 | [diff] [blame] | 998 | } |
svetoslavganov | 75986cf | 2009-05-14 22:28:01 -0700 | [diff] [blame] | 999 | } |
| 1000 | } |
Charles Chen | 85b598b | 2009-07-29 17:23:50 -0700 | [diff] [blame] | 1001 | } catch (IndexOutOfBoundsException oobe) { |
| 1002 | // An out of bounds exception can happen if services are going away |
| 1003 | // as the for loop is running. If that happens, just bail because |
| 1004 | // there are no more services to notify. |
| 1005 | return; |
svetoslavganov | 75986cf | 2009-05-14 22:28:01 -0700 | [diff] [blame] | 1006 | } |
| 1007 | } |
| 1008 | |
Svetoslav | 57bf885 | 2013-02-07 19:21:42 -0800 | [diff] [blame] | 1009 | private void addServiceLocked(Service service, UserState userState) { |
Svetoslav Ganov | f9886f3 | 2011-05-10 15:28:33 -0700 | [diff] [blame] | 1010 | try { |
Svetoslav | 2602a39 | 2013-04-15 16:26:39 -0700 | [diff] [blame] | 1011 | service.linkToOwnDeathLocked(); |
Svetoslav | 57bf885 | 2013-02-07 19:21:42 -0800 | [diff] [blame] | 1012 | userState.mBoundServices.add(service); |
Svetoslav Ganov | 58d37b5 | 2012-09-18 12:04:19 -0700 | [diff] [blame] | 1013 | userState.mComponentNameToServiceMap.put(service.mComponentName, service); |
Svetoslav | 57bf885 | 2013-02-07 19:21:42 -0800 | [diff] [blame] | 1014 | } catch (RemoteException re) { |
Svetoslav Ganov | f9886f3 | 2011-05-10 15:28:33 -0700 | [diff] [blame] | 1015 | /* do nothing */ |
| 1016 | } |
| 1017 | } |
| 1018 | |
| 1019 | /** |
| 1020 | * Removes a service. |
svetoslavganov | 75986cf | 2009-05-14 22:28:01 -0700 | [diff] [blame] | 1021 | * |
| 1022 | * @param service The service. |
| 1023 | * @return True if the service was removed, false otherwise. |
| 1024 | */ |
Svetoslav | 6f8218a | 2013-02-20 16:28:39 -0800 | [diff] [blame] | 1025 | private void removeServiceLocked(Service service, UserState userState) { |
Svetoslav | 57bf885 | 2013-02-07 19:21:42 -0800 | [diff] [blame] | 1026 | userState.mBoundServices.remove(service); |
Svetoslav Ganov | 58d37b5 | 2012-09-18 12:04:19 -0700 | [diff] [blame] | 1027 | userState.mComponentNameToServiceMap.remove(service.mComponentName); |
Svetoslav | 2602a39 | 2013-04-15 16:26:39 -0700 | [diff] [blame] | 1028 | service.unlinkToOwnDeathLocked(); |
svetoslavganov | 75986cf | 2009-05-14 22:28:01 -0700 | [diff] [blame] | 1029 | } |
| 1030 | |
| 1031 | /** |
| 1032 | * Determines if given event can be dispatched to a service based on the package of the |
| 1033 | * event source and already notified services for that event type. Specifically, a |
| 1034 | * service is notified if it is interested in events from the package and no other service |
| 1035 | * providing the same feedback type has been notified. Exception are services the |
| 1036 | * provide generic feedback (feedback type left as a safety net for unforeseen feedback |
| 1037 | * types) which are always notified. |
| 1038 | * |
| 1039 | * @param service The potential receiver. |
| 1040 | * @param event The event. |
| 1041 | * @param handledFeedbackTypes The feedback types for which services have been notified. |
| 1042 | * @return True if the listener should be notified, false otherwise. |
| 1043 | */ |
| 1044 | private boolean canDispathEventLocked(Service service, AccessibilityEvent event, |
| 1045 | int handledFeedbackTypes) { |
| 1046 | |
Svetoslav | 3822896 | 2013-01-29 01:04:35 -0800 | [diff] [blame] | 1047 | if (!service.canReceiveEventsLocked()) { |
svetoslavganov | 75986cf | 2009-05-14 22:28:01 -0700 | [diff] [blame] | 1048 | return false; |
| 1049 | } |
| 1050 | |
Svetoslav Ganov | 4213804 | 2012-03-20 11:51:39 -0700 | [diff] [blame] | 1051 | if (!event.isImportantForAccessibility() |
Svetoslav Ganov | 80943d8 | 2013-01-02 10:25:37 -0800 | [diff] [blame] | 1052 | && (service.mFetchFlags |
| 1053 | & AccessibilityNodeInfo.FLAG_INCLUDE_NOT_IMPORTANT_VIEWS) == 0) { |
Svetoslav Ganov | 4213804 | 2012-03-20 11:51:39 -0700 | [diff] [blame] | 1054 | return false; |
| 1055 | } |
| 1056 | |
svetoslavganov | 75986cf | 2009-05-14 22:28:01 -0700 | [diff] [blame] | 1057 | int eventType = event.getEventType(); |
| 1058 | if ((service.mEventTypes & eventType) != eventType) { |
| 1059 | return false; |
| 1060 | } |
| 1061 | |
| 1062 | Set<String> packageNames = service.mPackageNames; |
| 1063 | CharSequence packageName = event.getPackageName(); |
| 1064 | |
| 1065 | if (packageNames.isEmpty() || packageNames.contains(packageName)) { |
| 1066 | int feedbackType = service.mFeedbackType; |
| 1067 | if ((handledFeedbackTypes & feedbackType) != feedbackType |
| 1068 | || feedbackType == AccessibilityServiceInfo.FEEDBACK_GENERIC) { |
| 1069 | return true; |
| 1070 | } |
| 1071 | } |
| 1072 | |
| 1073 | return false; |
| 1074 | } |
| 1075 | |
Svetoslav Ganov | 58d37b5 | 2012-09-18 12:04:19 -0700 | [diff] [blame] | 1076 | private void unbindAllServicesLocked(UserState userState) { |
Svetoslav | 57bf885 | 2013-02-07 19:21:42 -0800 | [diff] [blame] | 1077 | List<Service> services = userState.mBoundServices; |
svetoslavganov | 75986cf | 2009-05-14 22:28:01 -0700 | [diff] [blame] | 1078 | for (int i = 0, count = services.size(); i < count; i++) { |
| 1079 | Service service = services.get(i); |
Svetoslav | 57bf885 | 2013-02-07 19:21:42 -0800 | [diff] [blame] | 1080 | if (service.unbindLocked()) { |
Svetoslav Ganov | 6ff5f10 | 2011-01-10 13:12:55 -0800 | [diff] [blame] | 1081 | i--; |
| 1082 | count--; |
| 1083 | } |
svetoslavganov | 75986cf | 2009-05-14 22:28:01 -0700 | [diff] [blame] | 1084 | } |
svetoslavganov | 75986cf | 2009-05-14 22:28:01 -0700 | [diff] [blame] | 1085 | } |
| 1086 | |
| 1087 | /** |
Svetoslav Ganov | 9a4c5cd | 2012-05-30 14:06:32 -0700 | [diff] [blame] | 1088 | * Populates a set with the {@link ComponentName}s stored in a colon |
Svetoslav Ganov | 58d37b5 | 2012-09-18 12:04:19 -0700 | [diff] [blame] | 1089 | * separated value setting for a given user. |
svetoslavganov | 75986cf | 2009-05-14 22:28:01 -0700 | [diff] [blame] | 1090 | * |
Svetoslav Ganov | 9a4c5cd | 2012-05-30 14:06:32 -0700 | [diff] [blame] | 1091 | * @param settingName The setting to parse. |
Svetoslav Ganov | 58d37b5 | 2012-09-18 12:04:19 -0700 | [diff] [blame] | 1092 | * @param userId The user id. |
Svetoslav Ganov | 9a4c5cd | 2012-05-30 14:06:32 -0700 | [diff] [blame] | 1093 | * @param outComponentNames The output component names. |
svetoslavganov | 75986cf | 2009-05-14 22:28:01 -0700 | [diff] [blame] | 1094 | */ |
Svetoslav | 57bf885 | 2013-02-07 19:21:42 -0800 | [diff] [blame] | 1095 | private void readComponentNamesFromSettingLocked(String settingName, int userId, |
Svetoslav Ganov | 9a4c5cd | 2012-05-30 14:06:32 -0700 | [diff] [blame] | 1096 | Set<ComponentName> outComponentNames) { |
Svetoslav Ganov | 58d37b5 | 2012-09-18 12:04:19 -0700 | [diff] [blame] | 1097 | String settingValue = Settings.Secure.getStringForUser(mContext.getContentResolver(), |
| 1098 | settingName, userId); |
Svetoslav Ganov | 9a4c5cd | 2012-05-30 14:06:32 -0700 | [diff] [blame] | 1099 | outComponentNames.clear(); |
Svetoslav Ganov | 9a4c5cd | 2012-05-30 14:06:32 -0700 | [diff] [blame] | 1100 | if (settingValue != null) { |
svetoslavganov | 75986cf | 2009-05-14 22:28:01 -0700 | [diff] [blame] | 1101 | TextUtils.SimpleStringSplitter splitter = mStringColonSplitter; |
Svetoslav Ganov | 9a4c5cd | 2012-05-30 14:06:32 -0700 | [diff] [blame] | 1102 | splitter.setString(settingValue); |
svetoslavganov | 75986cf | 2009-05-14 22:28:01 -0700 | [diff] [blame] | 1103 | while (splitter.hasNext()) { |
Dianne Hackborn | 21f1bd1 | 2010-02-19 17:02:21 -0800 | [diff] [blame] | 1104 | String str = splitter.next(); |
| 1105 | if (str == null || str.length() <= 0) { |
| 1106 | continue; |
| 1107 | } |
| 1108 | ComponentName enabledService = ComponentName.unflattenFromString(str); |
| 1109 | if (enabledService != null) { |
Svetoslav Ganov | 9a4c5cd | 2012-05-30 14:06:32 -0700 | [diff] [blame] | 1110 | outComponentNames.add(enabledService); |
Dianne Hackborn | 21f1bd1 | 2010-02-19 17:02:21 -0800 | [diff] [blame] | 1111 | } |
svetoslavganov | 75986cf | 2009-05-14 22:28:01 -0700 | [diff] [blame] | 1112 | } |
| 1113 | } |
| 1114 | } |
| 1115 | |
| 1116 | /** |
Svetoslav Ganov | 9a4c5cd | 2012-05-30 14:06:32 -0700 | [diff] [blame] | 1117 | * Persists the component names in the specified setting in a |
| 1118 | * colon separated fashion. |
| 1119 | * |
| 1120 | * @param settingName The setting name. |
| 1121 | * @param componentNames The component names. |
| 1122 | */ |
| 1123 | private void persistComponentNamesToSettingLocked(String settingName, |
Svetoslav Ganov | 58d37b5 | 2012-09-18 12:04:19 -0700 | [diff] [blame] | 1124 | Set<ComponentName> componentNames, int userId) { |
Svetoslav Ganov | 9a4c5cd | 2012-05-30 14:06:32 -0700 | [diff] [blame] | 1125 | StringBuilder builder = new StringBuilder(); |
| 1126 | for (ComponentName componentName : componentNames) { |
| 1127 | if (builder.length() > 0) { |
| 1128 | builder.append(COMPONENT_NAME_SEPARATOR); |
| 1129 | } |
| 1130 | builder.append(componentName.flattenToShortString()); |
| 1131 | } |
Svetoslav Ganov | 58d37b5 | 2012-09-18 12:04:19 -0700 | [diff] [blame] | 1132 | Settings.Secure.putStringForUser(mContext.getContentResolver(), |
| 1133 | settingName, builder.toString(), userId); |
Svetoslav Ganov | 9a4c5cd | 2012-05-30 14:06:32 -0700 | [diff] [blame] | 1134 | } |
| 1135 | |
Svetoslav | 57bf885 | 2013-02-07 19:21:42 -0800 | [diff] [blame] | 1136 | private void manageServicesLocked(UserState userState) { |
Svetoslav Ganov | 58d37b5 | 2012-09-18 12:04:19 -0700 | [diff] [blame] | 1137 | Map<ComponentName, Service> componentNameToServiceMap = |
| 1138 | userState.mComponentNameToServiceMap; |
| 1139 | boolean isEnabled = userState.mIsAccessibilityEnabled; |
svetoslavganov | 75986cf | 2009-05-14 22:28:01 -0700 | [diff] [blame] | 1140 | |
Svetoslav Ganov | 58d37b5 | 2012-09-18 12:04:19 -0700 | [diff] [blame] | 1141 | for (int i = 0, count = userState.mInstalledServices.size(); i < count; i++) { |
| 1142 | AccessibilityServiceInfo installedService = userState.mInstalledServices.get(i); |
Svetoslav Ganov | cc4053e | 2011-05-23 13:37:44 -0700 | [diff] [blame] | 1143 | ComponentName componentName = ComponentName.unflattenFromString( |
| 1144 | installedService.getId()); |
svetoslavganov | 75986cf | 2009-05-14 22:28:01 -0700 | [diff] [blame] | 1145 | Service service = componentNameToServiceMap.get(componentName); |
| 1146 | |
Svetoslav Ganov | f2245aa | 2010-12-28 15:48:52 -0800 | [diff] [blame] | 1147 | if (isEnabled) { |
Svetoslav | 57bf885 | 2013-02-07 19:21:42 -0800 | [diff] [blame] | 1148 | // Wait for the binding if it is in process. |
| 1149 | if (userState.mBindingServices.contains(componentName)) { |
| 1150 | continue; |
| 1151 | } |
Svetoslav Ganov | 58d37b5 | 2012-09-18 12:04:19 -0700 | [diff] [blame] | 1152 | if (userState.mEnabledServices.contains(componentName)) { |
Svetoslav Ganov | 563d784 | 2011-01-06 17:40:26 -0800 | [diff] [blame] | 1153 | if (service == null) { |
Svetoslav | 57bf885 | 2013-02-07 19:21:42 -0800 | [diff] [blame] | 1154 | service = new Service(userState.mUserId, componentName, installedService); |
| 1155 | } else if (userState.mBoundServices.contains(service)) { |
| 1156 | continue; |
Svetoslav Ganov | 563d784 | 2011-01-06 17:40:26 -0800 | [diff] [blame] | 1157 | } |
Svetoslav | 57bf885 | 2013-02-07 19:21:42 -0800 | [diff] [blame] | 1158 | service.bindLocked(); |
Svetoslav Ganov | 35bfede | 2011-07-14 17:57:06 -0700 | [diff] [blame] | 1159 | } else { |
Svetoslav Ganov | 563d784 | 2011-01-06 17:40:26 -0800 | [diff] [blame] | 1160 | if (service != null) { |
Svetoslav | 57bf885 | 2013-02-07 19:21:42 -0800 | [diff] [blame] | 1161 | service.unbindLocked(); |
Svetoslav Ganov | 563d784 | 2011-01-06 17:40:26 -0800 | [diff] [blame] | 1162 | } |
svetoslavganov | 75986cf | 2009-05-14 22:28:01 -0700 | [diff] [blame] | 1163 | } |
| 1164 | } else { |
| 1165 | if (service != null) { |
Svetoslav | 57bf885 | 2013-02-07 19:21:42 -0800 | [diff] [blame] | 1166 | service.unbindLocked(); |
| 1167 | } else { |
| 1168 | userState.mBindingServices.remove(componentName); |
svetoslavganov | 75986cf | 2009-05-14 22:28:01 -0700 | [diff] [blame] | 1169 | } |
| 1170 | } |
| 1171 | } |
Svetoslav | cefac5a | 2013-03-22 17:09:11 -0700 | [diff] [blame] | 1172 | |
| 1173 | // No enabled installed services => disable accessibility to avoid |
| 1174 | // sending accessibility events with no recipient across processes. |
| 1175 | if (isEnabled && userState.mEnabledServices.isEmpty()) { |
| 1176 | userState.mIsAccessibilityEnabled = false; |
| 1177 | Settings.Secure.putIntForUser(mContext.getContentResolver(), |
| 1178 | Settings.Secure.ACCESSIBILITY_ENABLED, 0, userState.mUserId); |
| 1179 | } |
Svetoslav Ganov | 37fedf8 | 2011-09-14 10:44:09 -0700 | [diff] [blame] | 1180 | } |
| 1181 | |
Svetoslav | 57bf885 | 2013-02-07 19:21:42 -0800 | [diff] [blame] | 1182 | private void scheduleUpdateClientsIfNeededLocked(UserState userState) { |
| 1183 | final int clientState = userState.getClientState(); |
| 1184 | if (userState.mLastSentClientState != clientState |
| 1185 | && (mGlobalClients.getRegisteredCallbackCount() > 0 |
| 1186 | || userState.mClients.getRegisteredCallbackCount() > 0)) { |
| 1187 | userState.mLastSentClientState = clientState; |
Svetoslav Ganov | 58d37b5 | 2012-09-18 12:04:19 -0700 | [diff] [blame] | 1188 | mMainHandler.obtainMessage(MainHandler.MSG_SEND_STATE_TO_CLIENTS, |
| 1189 | clientState, userState.mUserId) .sendToTarget(); |
| 1190 | } |
| 1191 | } |
| 1192 | |
Svetoslav Ganov | 545252f | 2012-12-10 18:29:24 -0800 | [diff] [blame] | 1193 | private void scheduleUpdateInputFilter(UserState userState) { |
| 1194 | mMainHandler.obtainMessage(MainHandler.MSG_UPDATE_INPUT_FILTER, userState).sendToTarget(); |
| 1195 | } |
| 1196 | |
| 1197 | private void updateInputFilter(UserState userState) { |
Svetoslav Ganov | 58d37b5 | 2012-09-18 12:04:19 -0700 | [diff] [blame] | 1198 | boolean setInputFilter = false; |
| 1199 | AccessibilityInputFilter inputFilter = null; |
| 1200 | synchronized (mLock) { |
Svetoslav | ca523d6 | 2013-04-26 13:11:11 -0700 | [diff] [blame] | 1201 | int flags = 0; |
| 1202 | if (userState.mIsDisplayMagnificationEnabled) { |
| 1203 | flags |= AccessibilityInputFilter.FLAG_FEATURE_SCREEN_MAGNIFIER; |
| 1204 | } |
| 1205 | // Touch exploration without accessibility makes no sense. |
| 1206 | if (userState.mIsAccessibilityEnabled && userState.mIsTouchExplorationEnabled) { |
| 1207 | flags |= AccessibilityInputFilter.FLAG_FEATURE_TOUCH_EXPLORATION; |
| 1208 | } |
| 1209 | if (userState.mIsFilterKeyEventsEnabled) { |
| 1210 | flags |= AccessibilityInputFilter.FLAG_FEATURE_FILTER_KEY_EVENTS; |
| 1211 | } |
| 1212 | if (flags != 0) { |
Svetoslav Ganov | 58d37b5 | 2012-09-18 12:04:19 -0700 | [diff] [blame] | 1213 | if (!mHasInputFilter) { |
| 1214 | mHasInputFilter = true; |
| 1215 | if (mInputFilter == null) { |
| 1216 | mInputFilter = new AccessibilityInputFilter(mContext, |
| 1217 | AccessibilityManagerService.this); |
| 1218 | } |
| 1219 | inputFilter = mInputFilter; |
| 1220 | setInputFilter = true; |
| 1221 | } |
Svetoslav Ganov | 58d37b5 | 2012-09-18 12:04:19 -0700 | [diff] [blame] | 1222 | mInputFilter.setEnabledFeatures(flags); |
| 1223 | } else { |
| 1224 | if (mHasInputFilter) { |
| 1225 | mHasInputFilter = false; |
Svetoslav | ca523d6 | 2013-04-26 13:11:11 -0700 | [diff] [blame] | 1226 | mInputFilter.disableFeatures(); |
Svetoslav Ganov | 58d37b5 | 2012-09-18 12:04:19 -0700 | [diff] [blame] | 1227 | inputFilter = null; |
| 1228 | setInputFilter = true; |
| 1229 | } |
| 1230 | } |
| 1231 | } |
| 1232 | if (setInputFilter) { |
svetoslavganov | 75986cf | 2009-05-14 22:28:01 -0700 | [diff] [blame] | 1233 | try { |
Svetoslav Ganov | 58d37b5 | 2012-09-18 12:04:19 -0700 | [diff] [blame] | 1234 | mWindowManagerService.setInputFilter(inputFilter); |
svetoslavganov | 75986cf | 2009-05-14 22:28:01 -0700 | [diff] [blame] | 1235 | } catch (RemoteException re) { |
Svetoslav Ganov | 58d37b5 | 2012-09-18 12:04:19 -0700 | [diff] [blame] | 1236 | /* ignore */ |
svetoslavganov | 75986cf | 2009-05-14 22:28:01 -0700 | [diff] [blame] | 1237 | } |
| 1238 | } |
| 1239 | } |
| 1240 | |
Svetoslav Ganov | 447d946 | 2013-02-01 19:46:20 +0000 | [diff] [blame] | 1241 | private void showEnableTouchExplorationDialog(final Service service) { |
Svetoslav Ganov | 447d946 | 2013-02-01 19:46:20 +0000 | [diff] [blame] | 1242 | synchronized (mLock) { |
Svetoslav | 57bf885 | 2013-02-07 19:21:42 -0800 | [diff] [blame] | 1243 | String label = service.mResolveInfo.loadLabel( |
| 1244 | mContext.getPackageManager()).toString(); |
| 1245 | |
Svetoslav Ganov | 447d946 | 2013-02-01 19:46:20 +0000 | [diff] [blame] | 1246 | final UserState state = getCurrentUserStateLocked(); |
| 1247 | if (state.mIsTouchExplorationEnabled) { |
| 1248 | return; |
| 1249 | } |
| 1250 | if (mEnableTouchExplorationDialog != null |
| 1251 | && mEnableTouchExplorationDialog.isShowing()) { |
| 1252 | return; |
| 1253 | } |
| 1254 | mEnableTouchExplorationDialog = new AlertDialog.Builder(mContext) |
| 1255 | .setIconAttribute(android.R.attr.alertDialogIcon) |
| 1256 | .setPositiveButton(android.R.string.ok, new OnClickListener() { |
| 1257 | @Override |
| 1258 | public void onClick(DialogInterface dialog, int which) { |
| 1259 | // The user allowed the service to toggle touch exploration. |
| 1260 | state.mTouchExplorationGrantedServices.add(service.mComponentName); |
| 1261 | persistComponentNamesToSettingLocked( |
| 1262 | Settings.Secure.TOUCH_EXPLORATION_GRANTED_ACCESSIBILITY_SERVICES, |
| 1263 | state.mTouchExplorationGrantedServices, state.mUserId); |
| 1264 | // Enable touch exploration. |
Svetoslav | 57bf885 | 2013-02-07 19:21:42 -0800 | [diff] [blame] | 1265 | UserState userState = getUserStateLocked(service.mUserId); |
| 1266 | userState.mIsTouchExplorationEnabled = true; |
Svetoslav Ganov | 447d946 | 2013-02-01 19:46:20 +0000 | [diff] [blame] | 1267 | Settings.Secure.putIntForUser(mContext.getContentResolver(), |
| 1268 | Settings.Secure.TOUCH_EXPLORATION_ENABLED, 1, |
| 1269 | service.mUserId); |
Svetoslav | 57bf885 | 2013-02-07 19:21:42 -0800 | [diff] [blame] | 1270 | onUserStateChangedLocked(userState); |
Svetoslav Ganov | 447d946 | 2013-02-01 19:46:20 +0000 | [diff] [blame] | 1271 | } |
| 1272 | }) |
| 1273 | .setNegativeButton(android.R.string.cancel, new OnClickListener() { |
| 1274 | @Override |
| 1275 | public void onClick(DialogInterface dialog, int which) { |
| 1276 | dialog.dismiss(); |
| 1277 | } |
| 1278 | }) |
| 1279 | .setTitle(R.string.enable_explore_by_touch_warning_title) |
| 1280 | .setMessage(mContext.getString( |
| 1281 | R.string.enable_explore_by_touch_warning_message, label)) |
| 1282 | .create(); |
| 1283 | mEnableTouchExplorationDialog.getWindow().setType( |
| 1284 | WindowManager.LayoutParams.TYPE_SYSTEM_ALERT); |
| 1285 | mEnableTouchExplorationDialog.getWindow().getAttributes().privateFlags |
| 1286 | |= WindowManager.LayoutParams.PRIVATE_FLAG_SHOW_FOR_ALL_USERS; |
| 1287 | mEnableTouchExplorationDialog.setCanceledOnTouchOutside(true); |
| 1288 | mEnableTouchExplorationDialog.show(); |
| 1289 | } |
| 1290 | } |
| 1291 | |
Svetoslav | 57bf885 | 2013-02-07 19:21:42 -0800 | [diff] [blame] | 1292 | private void onUserStateChangedLocked(UserState userState) { |
Svetoslav | 3b817ae | 2013-06-19 16:28:30 -0700 | [diff] [blame] | 1293 | // TODO: Remove this hack |
| 1294 | mInitialized = true; |
Svetoslav | 11adf6d | 2013-04-24 14:51:29 -0700 | [diff] [blame] | 1295 | updateLegacyCapabilities(userState); |
Svetoslav | 57bf885 | 2013-02-07 19:21:42 -0800 | [diff] [blame] | 1296 | updateServicesLocked(userState); |
Svetoslav | ca523d6 | 2013-04-26 13:11:11 -0700 | [diff] [blame] | 1297 | updateFilterKeyEventsLocked(userState); |
Svetoslav | 57bf885 | 2013-02-07 19:21:42 -0800 | [diff] [blame] | 1298 | updateTouchExplorationLocked(userState); |
| 1299 | updateEnhancedWebAccessibilityLocked(userState); |
Svetoslav Ganov | 545252f | 2012-12-10 18:29:24 -0800 | [diff] [blame] | 1300 | scheduleUpdateInputFilter(userState); |
Svetoslav | 57bf885 | 2013-02-07 19:21:42 -0800 | [diff] [blame] | 1301 | scheduleUpdateClientsIfNeededLocked(userState); |
Svetoslav Ganov | 1cf70bb | 2012-08-06 10:53:34 -0700 | [diff] [blame] | 1302 | } |
| 1303 | |
Svetoslav | 11adf6d | 2013-04-24 14:51:29 -0700 | [diff] [blame] | 1304 | private void updateLegacyCapabilities(UserState userState) { |
| 1305 | // Up to JB-MR1 we had a white list with services that can enable touch |
| 1306 | // exploration. When a service is first started we show a dialog to the |
| 1307 | // use to get a permission to white list the service. |
| 1308 | final int installedServiceCount = userState.mInstalledServices.size(); |
| 1309 | for (int i = 0; i < installedServiceCount; i++) { |
| 1310 | AccessibilityServiceInfo serviceInfo = userState.mInstalledServices.get(i); |
| 1311 | ResolveInfo resolveInfo = serviceInfo.getResolveInfo(); |
| 1312 | if ((serviceInfo.getCapabilities() |
| 1313 | & AccessibilityServiceInfo.CAPABILITY_CAN_REQUEST_TOUCH_EXPLORATION) == 0 |
| 1314 | && resolveInfo.serviceInfo.applicationInfo.targetSdkVersion |
| 1315 | <= Build.VERSION_CODES.JELLY_BEAN_MR1) { |
| 1316 | ComponentName componentName = new ComponentName( |
| 1317 | resolveInfo.serviceInfo.packageName, resolveInfo.serviceInfo.name); |
| 1318 | if (userState.mTouchExplorationGrantedServices.contains(componentName)) { |
| 1319 | serviceInfo.setCapabilities(serviceInfo.getCapabilities() |
| 1320 | | AccessibilityServiceInfo.CAPABILITY_CAN_REQUEST_TOUCH_EXPLORATION); |
| 1321 | } |
| 1322 | } |
| 1323 | } |
| 1324 | } |
| 1325 | |
Svetoslav | ca523d6 | 2013-04-26 13:11:11 -0700 | [diff] [blame] | 1326 | private void updateFilterKeyEventsLocked(UserState userState) { |
| 1327 | final int serviceCount = userState.mBoundServices.size(); |
| 1328 | for (int i = 0; i < serviceCount; i++) { |
| 1329 | Service service = userState.mBoundServices.get(i); |
| 1330 | if (service.mRequestFilterKeyEvents |
| 1331 | && (service.mAccessibilityServiceInfo.getCapabilities() |
| 1332 | & AccessibilityServiceInfo |
| 1333 | .CAPABILITY_CAN_REQUEST_FILTER_KEY_EVENTS) != 0) { |
| 1334 | userState.mIsFilterKeyEventsEnabled = true; |
| 1335 | return; |
| 1336 | } |
| 1337 | } |
| 1338 | userState.mIsFilterKeyEventsEnabled = false; |
| 1339 | } |
| 1340 | |
Svetoslav | 57bf885 | 2013-02-07 19:21:42 -0800 | [diff] [blame] | 1341 | private void updateServicesLocked(UserState userState) { |
| 1342 | if (userState.mIsAccessibilityEnabled) { |
Svetoslav Ganov | 58d37b5 | 2012-09-18 12:04:19 -0700 | [diff] [blame] | 1343 | manageServicesLocked(userState); |
Svetoslav Ganov | b6eca6e | 2011-09-27 10:47:58 -0700 | [diff] [blame] | 1344 | } else { |
Svetoslav Ganov | 58d37b5 | 2012-09-18 12:04:19 -0700 | [diff] [blame] | 1345 | unbindAllServicesLocked(userState); |
Svetoslav Ganov | b6eca6e | 2011-09-27 10:47:58 -0700 | [diff] [blame] | 1346 | } |
Svetoslav Ganov | 0d04e24 | 2012-02-21 13:46:36 -0800 | [diff] [blame] | 1347 | } |
| 1348 | |
Svetoslav | 57bf885 | 2013-02-07 19:21:42 -0800 | [diff] [blame] | 1349 | private boolean readConfigurationForUserStateLocked(UserState userState) { |
| 1350 | boolean somthingChanged = false; |
| 1351 | somthingChanged |= readAccessibilityEnabledSettingLocked(userState); |
| 1352 | somthingChanged |= readInstalledAccessibilityServiceLocked(userState); |
| 1353 | somthingChanged |= readEnabledAccessibilityServicesLocked(userState); |
| 1354 | somthingChanged |= readTouchExplorationGrantedAccessibilityServicesLocked(userState); |
| 1355 | somthingChanged |= readTouchExplorationEnabledSettingLocked(userState); |
| 1356 | somthingChanged |= readEnhancedWebAccessibilityEnabledChangedLocked(userState); |
| 1357 | somthingChanged |= readDisplayMagnificationEnabledSettingLocked(userState); |
| 1358 | return somthingChanged; |
Svetoslav Ganov | b6eca6e | 2011-09-27 10:47:58 -0700 | [diff] [blame] | 1359 | } |
| 1360 | |
Svetoslav | 57bf885 | 2013-02-07 19:21:42 -0800 | [diff] [blame] | 1361 | private boolean readAccessibilityEnabledSettingLocked(UserState userState) { |
| 1362 | final boolean accessibilityEnabled = Settings.Secure.getIntForUser( |
| 1363 | mContext.getContentResolver(), |
| 1364 | Settings.Secure.ACCESSIBILITY_ENABLED, 0, userState.mUserId) == 1; |
| 1365 | if (accessibilityEnabled != userState.mIsAccessibilityEnabled) { |
| 1366 | userState.mIsAccessibilityEnabled = accessibilityEnabled; |
| 1367 | return true; |
| 1368 | } |
| 1369 | return false; |
| 1370 | } |
| 1371 | |
| 1372 | private boolean readTouchExplorationEnabledSettingLocked(UserState userState) { |
| 1373 | final boolean touchExplorationEnabled = Settings.Secure.getIntForUser( |
| 1374 | mContext.getContentResolver(), |
| 1375 | Settings.Secure.TOUCH_EXPLORATION_ENABLED, 0, userState.mUserId) == 1; |
| 1376 | if (touchExplorationEnabled != userState.mIsTouchExplorationEnabled) { |
| 1377 | userState.mIsTouchExplorationEnabled = touchExplorationEnabled; |
| 1378 | return true; |
| 1379 | } |
| 1380 | return false; |
| 1381 | } |
| 1382 | |
| 1383 | private boolean readDisplayMagnificationEnabledSettingLocked(UserState userState) { |
| 1384 | final boolean displayMagnificationEnabled = Settings.Secure.getIntForUser( |
Svetoslav Ganov | 1cf70bb | 2012-08-06 10:53:34 -0700 | [diff] [blame] | 1385 | mContext.getContentResolver(), |
Svetoslav Ganov | 58d37b5 | 2012-09-18 12:04:19 -0700 | [diff] [blame] | 1386 | Settings.Secure.ACCESSIBILITY_DISPLAY_MAGNIFICATION_ENABLED, |
| 1387 | 0, userState.mUserId) == 1; |
Svetoslav | 57bf885 | 2013-02-07 19:21:42 -0800 | [diff] [blame] | 1388 | if (displayMagnificationEnabled != userState.mIsDisplayMagnificationEnabled) { |
| 1389 | userState.mIsDisplayMagnificationEnabled = displayMagnificationEnabled; |
| 1390 | return true; |
| 1391 | } |
| 1392 | return false; |
Svetoslav Ganov | 1cf70bb | 2012-08-06 10:53:34 -0700 | [diff] [blame] | 1393 | } |
| 1394 | |
Svetoslav | 57bf885 | 2013-02-07 19:21:42 -0800 | [diff] [blame] | 1395 | private boolean readEnhancedWebAccessibilityEnabledChangedLocked(UserState userState) { |
| 1396 | final boolean enhancedWeAccessibilityEnabled = Settings.Secure.getIntForUser( |
| 1397 | mContext.getContentResolver(), Settings.Secure.ACCESSIBILITY_SCRIPT_INJECTION, |
| 1398 | 0, userState.mUserId) == 1; |
| 1399 | if (enhancedWeAccessibilityEnabled != userState.mIsEnhancedWebAccessibilityEnabled) { |
| 1400 | userState.mIsEnhancedWebAccessibilityEnabled = enhancedWeAccessibilityEnabled; |
| 1401 | return true; |
| 1402 | } |
| 1403 | return false; |
| 1404 | } |
| 1405 | |
| 1406 | private void updateTouchExplorationLocked(UserState userState) { |
Svetoslav | 042ccec | 2013-05-08 11:13:11 -0700 | [diff] [blame] | 1407 | boolean enabled = false; |
Svetoslav | 57bf885 | 2013-02-07 19:21:42 -0800 | [diff] [blame] | 1408 | final int serviceCount = userState.mBoundServices.size(); |
Svetoslav Ganov | 447d946 | 2013-02-01 19:46:20 +0000 | [diff] [blame] | 1409 | for (int i = 0; i < serviceCount; i++) { |
Svetoslav | 57bf885 | 2013-02-07 19:21:42 -0800 | [diff] [blame] | 1410 | Service service = userState.mBoundServices.get(i); |
Svetoslav | 042ccec | 2013-05-08 11:13:11 -0700 | [diff] [blame] | 1411 | if (canRequestAndRequestsTouchExplorationLocked(service)) { |
| 1412 | enabled = true; |
Svetoslav | 57bf885 | 2013-02-07 19:21:42 -0800 | [diff] [blame] | 1413 | break; |
| 1414 | } |
Svetoslav Ganov | 447d946 | 2013-02-01 19:46:20 +0000 | [diff] [blame] | 1415 | } |
Svetoslav | 042ccec | 2013-05-08 11:13:11 -0700 | [diff] [blame] | 1416 | if (enabled != userState.mIsTouchExplorationEnabled) { |
| 1417 | userState.mIsTouchExplorationEnabled = enabled; |
| 1418 | Settings.Secure.putIntForUser(mContext.getContentResolver(), |
| 1419 | Settings.Secure.TOUCH_EXPLORATION_ENABLED, enabled ? 1 : 0, |
| 1420 | userState.mUserId); |
| 1421 | } |
Svetoslav Ganov | 447d946 | 2013-02-01 19:46:20 +0000 | [diff] [blame] | 1422 | } |
| 1423 | |
Svetoslav | 042ccec | 2013-05-08 11:13:11 -0700 | [diff] [blame] | 1424 | private boolean canRequestAndRequestsTouchExplorationLocked(Service service) { |
| 1425 | // Service not ready or cannot request the feature - well nothing to do. |
Svetoslav Ganov | 447d946 | 2013-02-01 19:46:20 +0000 | [diff] [blame] | 1426 | if (!service.canReceiveEventsLocked() || !service.mRequestTouchExplorationMode) { |
Svetoslav | 57bf885 | 2013-02-07 19:21:42 -0800 | [diff] [blame] | 1427 | return false; |
Svetoslav Ganov | a43ef3d | 2012-07-12 13:07:55 -0700 | [diff] [blame] | 1428 | } |
Svetoslav Ganov | 447d946 | 2013-02-01 19:46:20 +0000 | [diff] [blame] | 1429 | // UI test automation service can always enable it. |
| 1430 | if (service.mIsAutomation) { |
Svetoslav | 57bf885 | 2013-02-07 19:21:42 -0800 | [diff] [blame] | 1431 | return true; |
Svetoslav Ganov | 447d946 | 2013-02-01 19:46:20 +0000 | [diff] [blame] | 1432 | } |
| 1433 | if (service.mResolveInfo.serviceInfo.applicationInfo.targetSdkVersion |
| 1434 | <= Build.VERSION_CODES.JELLY_BEAN_MR1) { |
| 1435 | // Up to JB-MR1 we had a white list with services that can enable touch |
| 1436 | // exploration. When a service is first started we show a dialog to the |
| 1437 | // use to get a permission to white list the service. |
Svetoslav | 042ccec | 2013-05-08 11:13:11 -0700 | [diff] [blame] | 1438 | UserState userState = getUserStateLocked(service.mUserId); |
| 1439 | if (userState.mTouchExplorationGrantedServices.contains(service.mComponentName)) { |
Svetoslav | 57bf885 | 2013-02-07 19:21:42 -0800 | [diff] [blame] | 1440 | return true; |
Svetoslav | 042ccec | 2013-05-08 11:13:11 -0700 | [diff] [blame] | 1441 | } else if (mEnableTouchExplorationDialog == null |
| 1442 | || !mEnableTouchExplorationDialog.isShowing()) { |
| 1443 | mMainHandler.obtainMessage( |
| 1444 | MainHandler.MSG_SHOW_ENABLED_TOUCH_EXPLORATION_DIALOG, |
| 1445 | service).sendToTarget(); |
Svetoslav Ganov | 447d946 | 2013-02-01 19:46:20 +0000 | [diff] [blame] | 1446 | } |
| 1447 | } else { |
Svetoslav | 688a697 | 2013-04-16 18:55:38 -0700 | [diff] [blame] | 1448 | // Starting in JB-MR2 we request an accessibility service to declare |
| 1449 | // certain capabilities in its meta-data to allow it to enable the |
| 1450 | // corresponding features. |
Svetoslav | 042ccec | 2013-05-08 11:13:11 -0700 | [diff] [blame] | 1451 | if ((service.mAccessibilityServiceInfo.getCapabilities() |
Svetoslav | 688a697 | 2013-04-16 18:55:38 -0700 | [diff] [blame] | 1452 | & AccessibilityServiceInfo.CAPABILITY_CAN_REQUEST_TOUCH_EXPLORATION) != 0) { |
Svetoslav | 57bf885 | 2013-02-07 19:21:42 -0800 | [diff] [blame] | 1453 | return true; |
Svetoslav Ganov | 447d946 | 2013-02-01 19:46:20 +0000 | [diff] [blame] | 1454 | } |
Svetoslav Ganov | e15ccb9 | 2012-05-16 15:48:55 -0700 | [diff] [blame] | 1455 | } |
Svetoslav | 57bf885 | 2013-02-07 19:21:42 -0800 | [diff] [blame] | 1456 | return false; |
Svetoslav Ganov | e15ccb9 | 2012-05-16 15:48:55 -0700 | [diff] [blame] | 1457 | } |
| 1458 | |
Svetoslav | 57bf885 | 2013-02-07 19:21:42 -0800 | [diff] [blame] | 1459 | private void updateEnhancedWebAccessibilityLocked(UserState userState) { |
Svetoslav | 042ccec | 2013-05-08 11:13:11 -0700 | [diff] [blame] | 1460 | boolean enabled = false; |
Svetoslav | 57bf885 | 2013-02-07 19:21:42 -0800 | [diff] [blame] | 1461 | final int serviceCount = userState.mBoundServices.size(); |
Svetoslav Ganov | 447d946 | 2013-02-01 19:46:20 +0000 | [diff] [blame] | 1462 | for (int i = 0; i < serviceCount; i++) { |
Svetoslav | 57bf885 | 2013-02-07 19:21:42 -0800 | [diff] [blame] | 1463 | Service service = userState.mBoundServices.get(i); |
Svetoslav | 042ccec | 2013-05-08 11:13:11 -0700 | [diff] [blame] | 1464 | if (canRequestAndRequestsEnhancedWebAccessibilityLocked(service)) { |
| 1465 | enabled = true; |
| 1466 | break; |
Svetoslav Ganov | 447d946 | 2013-02-01 19:46:20 +0000 | [diff] [blame] | 1467 | } |
| 1468 | } |
Svetoslav | 042ccec | 2013-05-08 11:13:11 -0700 | [diff] [blame] | 1469 | if (enabled != userState.mIsEnhancedWebAccessibilityEnabled) { |
| 1470 | userState.mIsEnhancedWebAccessibilityEnabled = enabled; |
| 1471 | Settings.Secure.putIntForUser(mContext.getContentResolver(), |
| 1472 | Settings.Secure.ACCESSIBILITY_SCRIPT_INJECTION, enabled ? 1 : 0, |
| 1473 | userState.mUserId); |
| 1474 | } |
Svetoslav Ganov | 447d946 | 2013-02-01 19:46:20 +0000 | [diff] [blame] | 1475 | } |
| 1476 | |
Svetoslav | 042ccec | 2013-05-08 11:13:11 -0700 | [diff] [blame] | 1477 | private boolean canRequestAndRequestsEnhancedWebAccessibilityLocked(Service service) { |
Svetoslav | 57bf885 | 2013-02-07 19:21:42 -0800 | [diff] [blame] | 1478 | if (!service.canReceiveEventsLocked() || !service.mRequestEnhancedWebAccessibility ) { |
| 1479 | return false; |
| 1480 | } |
Svetoslav | 688a697 | 2013-04-16 18:55:38 -0700 | [diff] [blame] | 1481 | if (service.mIsAutomation || (service.mAccessibilityServiceInfo.getCapabilities() |
| 1482 | & AccessibilityServiceInfo.CAPABILITY_CAN_REQUEST_ENHANCED_WEB_ACCESSIBILITY) != 0) { |
Svetoslav | 57bf885 | 2013-02-07 19:21:42 -0800 | [diff] [blame] | 1483 | return true; |
| 1484 | } |
| 1485 | return false; |
Svetoslav | 3822896 | 2013-01-29 01:04:35 -0800 | [diff] [blame] | 1486 | } |
| 1487 | |
Svetoslav Ganov | 6ce77cd | 2012-11-21 16:35:57 -0800 | [diff] [blame] | 1488 | @Override |
| 1489 | public void dump(FileDescriptor fd, final PrintWriter pw, String[] args) { |
| 1490 | mSecurityPolicy.enforceCallingPermission(Manifest.permission.DUMP, FUNCTION_DUMP); |
| 1491 | synchronized (mLock) { |
| 1492 | pw.println("ACCESSIBILITY MANAGER (dumpsys accessibility)"); |
| 1493 | pw.println(); |
Svetoslav Ganov | 6ce77cd | 2012-11-21 16:35:57 -0800 | [diff] [blame] | 1494 | final int userCount = mUserStates.size(); |
| 1495 | for (int i = 0; i < userCount; i++) { |
| 1496 | UserState userState = mUserStates.valueAt(i); |
| 1497 | pw.append("User state[attributes:{id=" + userState.mUserId); |
| 1498 | pw.append(", currentUser=" + (userState.mUserId == mCurrentUserId)); |
| 1499 | pw.append(", accessibilityEnabled=" + userState.mIsAccessibilityEnabled); |
| 1500 | pw.append(", touchExplorationEnabled=" + userState.mIsTouchExplorationEnabled); |
| 1501 | pw.append(", displayMagnificationEnabled=" |
| 1502 | + userState.mIsDisplayMagnificationEnabled); |
Svetoslav | 57bf885 | 2013-02-07 19:21:42 -0800 | [diff] [blame] | 1503 | if (userState.mUiAutomationService != null) { |
| 1504 | pw.append(", "); |
| 1505 | userState.mUiAutomationService.dump(fd, pw, args); |
| 1506 | pw.println(); |
| 1507 | } |
Svetoslav Ganov | 6ce77cd | 2012-11-21 16:35:57 -0800 | [diff] [blame] | 1508 | pw.append("}"); |
| 1509 | pw.println(); |
| 1510 | pw.append(" services:{"); |
Svetoslav | 57bf885 | 2013-02-07 19:21:42 -0800 | [diff] [blame] | 1511 | final int serviceCount = userState.mBoundServices.size(); |
Svetoslav Ganov | 6ce77cd | 2012-11-21 16:35:57 -0800 | [diff] [blame] | 1512 | for (int j = 0; j < serviceCount; j++) { |
| 1513 | if (j > 0) { |
| 1514 | pw.append(", "); |
| 1515 | pw.println(); |
| 1516 | pw.append(" "); |
| 1517 | } |
Svetoslav | 57bf885 | 2013-02-07 19:21:42 -0800 | [diff] [blame] | 1518 | Service service = userState.mBoundServices.get(j); |
Svetoslav Ganov | 6ce77cd | 2012-11-21 16:35:57 -0800 | [diff] [blame] | 1519 | service.dump(fd, pw, args); |
| 1520 | } |
| 1521 | pw.println("}]"); |
| 1522 | pw.println(); |
| 1523 | } |
| 1524 | } |
| 1525 | } |
| 1526 | |
Svetoslav Ganov | d116d7c | 2011-11-21 18:41:59 -0800 | [diff] [blame] | 1527 | private class AccessibilityConnectionWrapper implements DeathRecipient { |
| 1528 | private final int mWindowId; |
Svetoslav Ganov | 58d37b5 | 2012-09-18 12:04:19 -0700 | [diff] [blame] | 1529 | private final int mUserId; |
Svetoslav Ganov | d116d7c | 2011-11-21 18:41:59 -0800 | [diff] [blame] | 1530 | private final IAccessibilityInteractionConnection mConnection; |
| 1531 | |
| 1532 | public AccessibilityConnectionWrapper(int windowId, |
Svetoslav Ganov | 58d37b5 | 2012-09-18 12:04:19 -0700 | [diff] [blame] | 1533 | IAccessibilityInteractionConnection connection, int userId) { |
Svetoslav Ganov | d116d7c | 2011-11-21 18:41:59 -0800 | [diff] [blame] | 1534 | mWindowId = windowId; |
Svetoslav Ganov | 58d37b5 | 2012-09-18 12:04:19 -0700 | [diff] [blame] | 1535 | mUserId = userId; |
Svetoslav Ganov | d116d7c | 2011-11-21 18:41:59 -0800 | [diff] [blame] | 1536 | mConnection = connection; |
| 1537 | } |
| 1538 | |
| 1539 | public void linkToDeath() throws RemoteException { |
| 1540 | mConnection.asBinder().linkToDeath(this, 0); |
| 1541 | } |
| 1542 | |
| 1543 | public void unlinkToDeath() { |
| 1544 | mConnection.asBinder().unlinkToDeath(this, 0); |
| 1545 | } |
| 1546 | |
| 1547 | @Override |
| 1548 | public void binderDied() { |
| 1549 | unlinkToDeath(); |
| 1550 | synchronized (mLock) { |
Svetoslav Ganov | 58d37b5 | 2012-09-18 12:04:19 -0700 | [diff] [blame] | 1551 | removeAccessibilityInteractionConnectionLocked(mWindowId, mUserId); |
Svetoslav Ganov | d116d7c | 2011-11-21 18:41:59 -0800 | [diff] [blame] | 1552 | } |
| 1553 | } |
| 1554 | } |
| 1555 | |
Svetoslav Ganov | 58d37b5 | 2012-09-18 12:04:19 -0700 | [diff] [blame] | 1556 | private final class MainHandler extends Handler { |
| 1557 | public static final int MSG_SEND_ACCESSIBILITY_EVENT_TO_INPUT_FILTER = 1; |
| 1558 | public static final int MSG_SEND_STATE_TO_CLIENTS = 2; |
| 1559 | public static final int MSG_SEND_CLEARED_STATE_TO_CLIENTS_FOR_USER = 3; |
Svetoslav | 57bf885 | 2013-02-07 19:21:42 -0800 | [diff] [blame] | 1560 | public static final int MSG_UPDATE_ACTIVE_WINDOW = 4; |
| 1561 | public static final int MSG_ANNOUNCE_NEW_USER_IF_NEEDED = 5; |
| 1562 | public static final int MSG_UPDATE_INPUT_FILTER = 6; |
| 1563 | public static final int MSG_SHOW_ENABLED_TOUCH_EXPLORATION_DIALOG = 7; |
Svetoslav | c4fccd1 | 2013-04-09 12:58:41 -0700 | [diff] [blame] | 1564 | public static final int MSG_SEND_KEY_EVENT_TO_INPUT_FILTER = 8; |
Svetoslav Ganov | 1cf70bb | 2012-08-06 10:53:34 -0700 | [diff] [blame] | 1565 | |
| 1566 | public MainHandler(Looper looper) { |
| 1567 | super(looper); |
| 1568 | } |
| 1569 | |
Svetoslav Ganov | e15ccb9 | 2012-05-16 15:48:55 -0700 | [diff] [blame] | 1570 | @Override |
| 1571 | public void handleMessage(Message msg) { |
| 1572 | final int type = msg.what; |
| 1573 | switch (type) { |
Svetoslav Ganov | e45c0b2 | 2012-06-08 17:44:29 -0700 | [diff] [blame] | 1574 | case MSG_SEND_ACCESSIBILITY_EVENT_TO_INPUT_FILTER: { |
| 1575 | AccessibilityEvent event = (AccessibilityEvent) msg.obj; |
Svetoslav Ganov | 58d37b5 | 2012-09-18 12:04:19 -0700 | [diff] [blame] | 1576 | synchronized (mLock) { |
| 1577 | if (mHasInputFilter && mInputFilter != null) { |
| 1578 | mInputFilter.notifyAccessibilityEvent(event); |
| 1579 | } |
Svetoslav Ganov | e45c0b2 | 2012-06-08 17:44:29 -0700 | [diff] [blame] | 1580 | } |
| 1581 | event.recycle(); |
| 1582 | } break; |
Svetoslav | c4fccd1 | 2013-04-09 12:58:41 -0700 | [diff] [blame] | 1583 | case MSG_SEND_KEY_EVENT_TO_INPUT_FILTER: { |
| 1584 | KeyEvent event = (KeyEvent) msg.obj; |
| 1585 | final int policyFlags = msg.arg1; |
| 1586 | synchronized (mLock) { |
| 1587 | if (mHasInputFilter && mInputFilter != null) { |
| 1588 | mInputFilter.sendInputEvent(event, policyFlags); |
| 1589 | } |
| 1590 | } |
| 1591 | event.recycle(); |
| 1592 | } break; |
Svetoslav Ganov | 58d37b5 | 2012-09-18 12:04:19 -0700 | [diff] [blame] | 1593 | case MSG_SEND_STATE_TO_CLIENTS: { |
| 1594 | final int clientState = msg.arg1; |
| 1595 | final int userId = msg.arg2; |
| 1596 | sendStateToClients(clientState, mGlobalClients); |
| 1597 | sendStateToClientsForUser(clientState, userId); |
| 1598 | } break; |
| 1599 | case MSG_SEND_CLEARED_STATE_TO_CLIENTS_FOR_USER: { |
| 1600 | final int userId = msg.arg1; |
| 1601 | sendStateToClientsForUser(0, userId); |
| 1602 | } break; |
Svetoslav Ganov | a8afa69 | 2012-09-25 13:03:18 -0700 | [diff] [blame] | 1603 | case MSG_UPDATE_ACTIVE_WINDOW: { |
| 1604 | final int windowId = msg.arg1; |
| 1605 | final int eventType = msg.arg2; |
| 1606 | mSecurityPolicy.updateActiveWindow(windowId, eventType); |
| 1607 | } break; |
Svetoslav Ganov | 7befb7d | 2012-09-27 16:49:23 -0700 | [diff] [blame] | 1608 | case MSG_ANNOUNCE_NEW_USER_IF_NEEDED: { |
| 1609 | announceNewUserIfNeeded(); |
| 1610 | } break; |
Svetoslav Ganov | 545252f | 2012-12-10 18:29:24 -0800 | [diff] [blame] | 1611 | case MSG_UPDATE_INPUT_FILTER: { |
| 1612 | UserState userState = (UserState) msg.obj; |
Svetoslav Ganov | 447d946 | 2013-02-01 19:46:20 +0000 | [diff] [blame] | 1613 | updateInputFilter(userState); |
Svetoslav Ganov | 545252f | 2012-12-10 18:29:24 -0800 | [diff] [blame] | 1614 | } break; |
Svetoslav | 57bf885 | 2013-02-07 19:21:42 -0800 | [diff] [blame] | 1615 | case MSG_SHOW_ENABLED_TOUCH_EXPLORATION_DIALOG: { |
| 1616 | Service service = (Service) msg.obj; |
| 1617 | showEnableTouchExplorationDialog(service); |
| 1618 | } break; |
Svetoslav Ganov | 7befb7d | 2012-09-27 16:49:23 -0700 | [diff] [blame] | 1619 | } |
| 1620 | } |
| 1621 | |
| 1622 | private void announceNewUserIfNeeded() { |
| 1623 | synchronized (mLock) { |
| 1624 | UserState userState = getCurrentUserStateLocked(); |
| 1625 | if (userState.mIsAccessibilityEnabled) { |
| 1626 | UserManager userManager = (UserManager) mContext.getSystemService( |
| 1627 | Context.USER_SERVICE); |
| 1628 | String message = mContext.getString(R.string.user_switched, |
| 1629 | userManager.getUserInfo(mCurrentUserId).name); |
| 1630 | AccessibilityEvent event = AccessibilityEvent.obtain( |
| 1631 | AccessibilityEvent.TYPE_ANNOUNCEMENT); |
| 1632 | event.getText().add(message); |
Svetoslav Ganov | fc9c4cd | 2012-11-02 11:49:22 -0700 | [diff] [blame] | 1633 | event.setWindowId(mSecurityPolicy.getRetrievalAllowingWindowLocked()); |
Svetoslav Ganov | 7befb7d | 2012-09-27 16:49:23 -0700 | [diff] [blame] | 1634 | sendAccessibilityEvent(event, mCurrentUserId); |
| 1635 | } |
Svetoslav Ganov | 58d37b5 | 2012-09-18 12:04:19 -0700 | [diff] [blame] | 1636 | } |
| 1637 | } |
| 1638 | |
| 1639 | private void sendStateToClientsForUser(int clientState, int userId) { |
| 1640 | final UserState userState; |
| 1641 | synchronized (mLock) { |
| 1642 | userState = getUserStateLocked(userId); |
| 1643 | } |
| 1644 | sendStateToClients(clientState, userState.mClients); |
| 1645 | } |
| 1646 | |
| 1647 | private void sendStateToClients(int clientState, |
| 1648 | RemoteCallbackList<IAccessibilityManagerClient> clients) { |
| 1649 | try { |
| 1650 | final int userClientCount = clients.beginBroadcast(); |
| 1651 | for (int i = 0; i < userClientCount; i++) { |
| 1652 | IAccessibilityManagerClient client = clients.getBroadcastItem(i); |
| 1653 | try { |
| 1654 | client.setState(clientState); |
| 1655 | } catch (RemoteException re) { |
| 1656 | /* ignore */ |
| 1657 | } |
| 1658 | } |
| 1659 | } finally { |
| 1660 | clients.finishBroadcast(); |
Svetoslav Ganov | e15ccb9 | 2012-05-16 15:48:55 -0700 | [diff] [blame] | 1661 | } |
| 1662 | } |
| 1663 | } |
| 1664 | |
Svetoslav | c4fccd1 | 2013-04-09 12:58:41 -0700 | [diff] [blame] | 1665 | private PendingEvent obtainPendingEventLocked(KeyEvent event, int policyFlags, int sequence) { |
| 1666 | PendingEvent pendingEvent = mPendingEventPool.acquire(); |
| 1667 | if (pendingEvent == null) { |
| 1668 | pendingEvent = new PendingEvent(); |
| 1669 | } |
| 1670 | pendingEvent.event = event; |
| 1671 | pendingEvent.policyFlags = policyFlags; |
| 1672 | pendingEvent.sequence = sequence; |
| 1673 | return pendingEvent; |
| 1674 | } |
| 1675 | |
| 1676 | private void recyclePendingEventLocked(PendingEvent pendingEvent) { |
| 1677 | pendingEvent.clear(); |
| 1678 | mPendingEventPool.release(pendingEvent); |
| 1679 | } |
| 1680 | |
Svetoslav Ganov | b6eca6e | 2011-09-27 10:47:58 -0700 | [diff] [blame] | 1681 | /** |
svetoslavganov | 75986cf | 2009-05-14 22:28:01 -0700 | [diff] [blame] | 1682 | * This class represents an accessibility service. It stores all per service |
| 1683 | * data required for the service management, provides API for starting/stopping the |
| 1684 | * service and is responsible for adding/removing the service in the data structures |
| 1685 | * for service management. The class also exposes configuration interface that is |
| 1686 | * passed to the service it represents as soon it is bound. It also serves as the |
| 1687 | * connection for the service. |
| 1688 | */ |
Svetoslav Ganov | f9886f3 | 2011-05-10 15:28:33 -0700 | [diff] [blame] | 1689 | class Service extends IAccessibilityServiceConnection.Stub |
Svetoslav | c4fccd1 | 2013-04-09 12:58:41 -0700 | [diff] [blame] | 1690 | implements ServiceConnection, DeathRecipient {; |
Svetoslav Ganov | e15ccb9 | 2012-05-16 15:48:55 -0700 | [diff] [blame] | 1691 | |
Svetoslav Ganov | 58d37b5 | 2012-09-18 12:04:19 -0700 | [diff] [blame] | 1692 | final int mUserId; |
| 1693 | |
svetoslavganov | 75986cf | 2009-05-14 22:28:01 -0700 | [diff] [blame] | 1694 | int mId = 0; |
| 1695 | |
Svetoslav Ganov | cc4053e | 2011-05-23 13:37:44 -0700 | [diff] [blame] | 1696 | AccessibilityServiceInfo mAccessibilityServiceInfo; |
Svetoslav Ganov | 736c275 | 2011-04-22 18:30:36 -0700 | [diff] [blame] | 1697 | |
svetoslavganov | 75986cf | 2009-05-14 22:28:01 -0700 | [diff] [blame] | 1698 | IBinder mService; |
| 1699 | |
Svetoslav Ganov | 4213804 | 2012-03-20 11:51:39 -0700 | [diff] [blame] | 1700 | IAccessibilityServiceClient mServiceInterface; |
svetoslavganov | 75986cf | 2009-05-14 22:28:01 -0700 | [diff] [blame] | 1701 | |
| 1702 | int mEventTypes; |
| 1703 | |
| 1704 | int mFeedbackType; |
| 1705 | |
| 1706 | Set<String> mPackageNames = new HashSet<String>(); |
| 1707 | |
| 1708 | boolean mIsDefault; |
| 1709 | |
Svetoslav Ganov | e15ccb9 | 2012-05-16 15:48:55 -0700 | [diff] [blame] | 1710 | boolean mRequestTouchExplorationMode; |
| 1711 | |
Svetoslav | 3822896 | 2013-01-29 01:04:35 -0800 | [diff] [blame] | 1712 | boolean mRequestEnhancedWebAccessibility; |
| 1713 | |
Svetoslav | 688a697 | 2013-04-16 18:55:38 -0700 | [diff] [blame] | 1714 | boolean mRequestFilterKeyEvents; |
| 1715 | |
Svetoslav Ganov | 80943d8 | 2013-01-02 10:25:37 -0800 | [diff] [blame] | 1716 | int mFetchFlags; |
Svetoslav Ganov | 4213804 | 2012-03-20 11:51:39 -0700 | [diff] [blame] | 1717 | |
svetoslavganov | 75986cf | 2009-05-14 22:28:01 -0700 | [diff] [blame] | 1718 | long mNotificationTimeout; |
| 1719 | |
svetoslavganov | 75986cf | 2009-05-14 22:28:01 -0700 | [diff] [blame] | 1720 | ComponentName mComponentName; |
| 1721 | |
| 1722 | Intent mIntent; |
| 1723 | |
Svetoslav Ganov | e8f9535 | 2011-07-06 17:24:03 -0700 | [diff] [blame] | 1724 | boolean mIsAutomation; |
Svetoslav Ganov | 8643aa0 | 2011-04-20 12:12:33 -0700 | [diff] [blame] | 1725 | |
Svetoslav Ganov | 7961be7 | 2011-06-21 12:31:56 -0700 | [diff] [blame] | 1726 | final Rect mTempBounds = new Rect(); |
| 1727 | |
Svetoslav Ganov | e15ccb9 | 2012-05-16 15:48:55 -0700 | [diff] [blame] | 1728 | final ResolveInfo mResolveInfo; |
| 1729 | |
svetoslavganov | 75986cf | 2009-05-14 22:28:01 -0700 | [diff] [blame] | 1730 | // the events pending events to be dispatched to this service |
| 1731 | final SparseArray<AccessibilityEvent> mPendingEvents = |
| 1732 | new SparseArray<AccessibilityEvent>(); |
| 1733 | |
Svetoslav | c4fccd1 | 2013-04-09 12:58:41 -0700 | [diff] [blame] | 1734 | final KeyEventDispatcher mKeyEventDispatcher = new KeyEventDispatcher(); |
| 1735 | |
Svetoslav Ganov | bfa1bf0 | 2013-05-03 01:13:05 -0700 | [diff] [blame] | 1736 | boolean mWasConnectedAndDied; |
| 1737 | |
Svetoslav | c4fccd1 | 2013-04-09 12:58:41 -0700 | [diff] [blame] | 1738 | // Handler only for dispatching accessibility events since we use event |
| 1739 | // types as message types allowing us to remove messages per event type. |
| 1740 | public Handler mEventDispatchHandler = new Handler(mMainHandler.getLooper()) { |
Svetoslav Ganov | e15ccb9 | 2012-05-16 15:48:55 -0700 | [diff] [blame] | 1741 | @Override |
| 1742 | public void handleMessage(Message message) { |
Svetoslav | c4fccd1 | 2013-04-09 12:58:41 -0700 | [diff] [blame] | 1743 | final int eventType = message.what; |
| 1744 | notifyAccessibilityEventInternal(eventType); |
Svetoslav Ganov | e15ccb9 | 2012-05-16 15:48:55 -0700 | [diff] [blame] | 1745 | } |
| 1746 | }; |
| 1747 | |
Svetoslav | c4fccd1 | 2013-04-09 12:58:41 -0700 | [diff] [blame] | 1748 | // Handler for scheduling method invocations on the main thread. |
| 1749 | public InvocationHandler mInvocationHandler = new InvocationHandler( |
| 1750 | mMainHandler.getLooper()); |
| 1751 | |
Svetoslav Ganov | 58d37b5 | 2012-09-18 12:04:19 -0700 | [diff] [blame] | 1752 | public Service(int userId, ComponentName componentName, |
Svetoslav | 57bf885 | 2013-02-07 19:21:42 -0800 | [diff] [blame] | 1753 | AccessibilityServiceInfo accessibilityServiceInfo) { |
Svetoslav Ganov | 58d37b5 | 2012-09-18 12:04:19 -0700 | [diff] [blame] | 1754 | mUserId = userId; |
Svetoslav Ganov | e15ccb9 | 2012-05-16 15:48:55 -0700 | [diff] [blame] | 1755 | mResolveInfo = accessibilityServiceInfo.getResolveInfo(); |
svetoslavganov | 75986cf | 2009-05-14 22:28:01 -0700 | [diff] [blame] | 1756 | mId = sIdCounter++; |
Svetoslav Ganov | 8643aa0 | 2011-04-20 12:12:33 -0700 | [diff] [blame] | 1757 | mComponentName = componentName; |
| 1758 | mAccessibilityServiceInfo = accessibilityServiceInfo; |
Svetoslav | 57bf885 | 2013-02-07 19:21:42 -0800 | [diff] [blame] | 1759 | mIsAutomation = (sFakeAccessibilityServiceComponentName.equals(componentName)); |
| 1760 | if (!mIsAutomation) { |
Svetoslav Ganov | 8643aa0 | 2011-04-20 12:12:33 -0700 | [diff] [blame] | 1761 | mIntent = new Intent().setComponent(mComponentName); |
| 1762 | mIntent.putExtra(Intent.EXTRA_CLIENT_LABEL, |
| 1763 | com.android.internal.R.string.accessibility_binding_label); |
| 1764 | mIntent.putExtra(Intent.EXTRA_CLIENT_INTENT, PendingIntent.getActivity( |
| 1765 | mContext, 0, new Intent(Settings.ACTION_ACCESSIBILITY_SETTINGS), 0)); |
Svetoslav Ganov | 8643aa0 | 2011-04-20 12:12:33 -0700 | [diff] [blame] | 1766 | } |
| 1767 | setDynamicallyConfigurableProperties(accessibilityServiceInfo); |
svetoslavganov | 75986cf | 2009-05-14 22:28:01 -0700 | [diff] [blame] | 1768 | } |
| 1769 | |
Svetoslav Ganov | 8643aa0 | 2011-04-20 12:12:33 -0700 | [diff] [blame] | 1770 | public void setDynamicallyConfigurableProperties(AccessibilityServiceInfo info) { |
Svetoslav Ganov | cc4053e | 2011-05-23 13:37:44 -0700 | [diff] [blame] | 1771 | mEventTypes = info.eventTypes; |
| 1772 | mFeedbackType = info.feedbackType; |
| 1773 | String[] packageNames = info.packageNames; |
| 1774 | if (packageNames != null) { |
| 1775 | mPackageNames.addAll(Arrays.asList(packageNames)); |
| 1776 | } |
| 1777 | mNotificationTimeout = info.notificationTimeout; |
Svetoslav Ganov | 4213804 | 2012-03-20 11:51:39 -0700 | [diff] [blame] | 1778 | mIsDefault = (info.flags & DEFAULT) != 0; |
| 1779 | |
Guang Zhu | df549f8 | 2012-05-08 23:09:24 -0700 | [diff] [blame] | 1780 | if (mIsAutomation || info.getResolveInfo().serviceInfo.applicationInfo.targetSdkVersion |
Svetoslav Ganov | 5a48f97 | 2012-05-13 13:33:53 -0700 | [diff] [blame] | 1781 | >= Build.VERSION_CODES.JELLY_BEAN) { |
Svetoslav | 9e06512 | 2013-02-15 15:24:09 -0800 | [diff] [blame] | 1782 | if ((info.flags & AccessibilityServiceInfo.FLAG_INCLUDE_NOT_IMPORTANT_VIEWS) != 0) { |
| 1783 | mFetchFlags |= AccessibilityNodeInfo.FLAG_INCLUDE_NOT_IMPORTANT_VIEWS; |
| 1784 | } else { |
| 1785 | mFetchFlags &= ~AccessibilityNodeInfo.FLAG_INCLUDE_NOT_IMPORTANT_VIEWS; |
| 1786 | } |
Svetoslav Ganov | 4213804 | 2012-03-20 11:51:39 -0700 | [diff] [blame] | 1787 | } |
Svetoslav Ganov | c321c19 | 2011-06-03 19:43:23 -0700 | [diff] [blame] | 1788 | |
Svetoslav | 9e06512 | 2013-02-15 15:24:09 -0800 | [diff] [blame] | 1789 | if ((info.flags & AccessibilityServiceInfo.FLAG_REPORT_VIEW_IDS) != 0) { |
| 1790 | mFetchFlags |= AccessibilityNodeInfo.FLAG_REPORT_VIEW_IDS; |
| 1791 | } else { |
| 1792 | mFetchFlags &= ~AccessibilityNodeInfo.FLAG_REPORT_VIEW_IDS; |
| 1793 | } |
Svetoslav Ganov | 80943d8 | 2013-01-02 10:25:37 -0800 | [diff] [blame] | 1794 | |
Svetoslav | db7da0e | 2013-04-22 18:34:02 -0700 | [diff] [blame] | 1795 | mRequestTouchExplorationMode = (info.flags |
| 1796 | & AccessibilityServiceInfo.FLAG_REQUEST_TOUCH_EXPLORATION_MODE) != 0; |
| 1797 | mRequestEnhancedWebAccessibility = (info.flags |
| 1798 | & AccessibilityServiceInfo.FLAG_REQUEST_ENHANCED_WEB_ACCESSIBILITY) != 0; |
| 1799 | mRequestFilterKeyEvents = (info.flags |
| 1800 | & AccessibilityServiceInfo.FLAG_REQUEST_FILTER_KEY_EVENTS) != 0; |
Svetoslav Ganov | cc4053e | 2011-05-23 13:37:44 -0700 | [diff] [blame] | 1801 | } |
| 1802 | |
svetoslavganov | 75986cf | 2009-05-14 22:28:01 -0700 | [diff] [blame] | 1803 | /** |
| 1804 | * Binds to the accessibility service. |
Svetoslav Ganov | 6ff5f10 | 2011-01-10 13:12:55 -0800 | [diff] [blame] | 1805 | * |
| 1806 | * @return True if binding is successful. |
svetoslavganov | 75986cf | 2009-05-14 22:28:01 -0700 | [diff] [blame] | 1807 | */ |
Svetoslav | 57bf885 | 2013-02-07 19:21:42 -0800 | [diff] [blame] | 1808 | public boolean bindLocked() { |
| 1809 | UserState userState = getUserStateLocked(mUserId); |
| 1810 | if (!mIsAutomation) { |
Svetoslav | 6f8218a | 2013-02-20 16:28:39 -0800 | [diff] [blame] | 1811 | if (mService == null && mContext.bindServiceAsUser( |
| 1812 | mIntent, this, Context.BIND_AUTO_CREATE, new UserHandle(mUserId))) { |
| 1813 | userState.mBindingServices.add(mComponentName); |
Svetoslav | 57bf885 | 2013-02-07 19:21:42 -0800 | [diff] [blame] | 1814 | } |
| 1815 | } else { |
| 1816 | userState.mBindingServices.add(mComponentName); |
| 1817 | mService = userState.mUiAutomationServiceClient.asBinder(); |
| 1818 | onServiceConnected(mComponentName, mService); |
| 1819 | userState.mUiAutomationService = this; |
svetoslavganov | 75986cf | 2009-05-14 22:28:01 -0700 | [diff] [blame] | 1820 | } |
Svetoslav Ganov | 6ff5f10 | 2011-01-10 13:12:55 -0800 | [diff] [blame] | 1821 | return false; |
svetoslavganov | 75986cf | 2009-05-14 22:28:01 -0700 | [diff] [blame] | 1822 | } |
| 1823 | |
| 1824 | /** |
| 1825 | * Unbinds form the accessibility service and removes it from the data |
| 1826 | * structures for service management. |
Svetoslav Ganov | 6ff5f10 | 2011-01-10 13:12:55 -0800 | [diff] [blame] | 1827 | * |
| 1828 | * @return True if unbinding is successful. |
svetoslavganov | 75986cf | 2009-05-14 22:28:01 -0700 | [diff] [blame] | 1829 | */ |
Svetoslav | 57bf885 | 2013-02-07 19:21:42 -0800 | [diff] [blame] | 1830 | public boolean unbindLocked() { |
| 1831 | if (mService == null) { |
| 1832 | return false; |
svetoslavganov | 75986cf | 2009-05-14 22:28:01 -0700 | [diff] [blame] | 1833 | } |
Svetoslav | 6f8218a | 2013-02-20 16:28:39 -0800 | [diff] [blame] | 1834 | UserState userState = getUserStateLocked(mUserId); |
Svetoslav | c4fccd1 | 2013-04-09 12:58:41 -0700 | [diff] [blame] | 1835 | mKeyEventDispatcher.flush(); |
Svetoslav | 57bf885 | 2013-02-07 19:21:42 -0800 | [diff] [blame] | 1836 | if (!mIsAutomation) { |
| 1837 | mContext.unbindService(this); |
| 1838 | } else { |
Svetoslav | 3c55e5c | 2013-02-27 18:24:28 -0800 | [diff] [blame] | 1839 | userState.destroyUiAutomationService(); |
Svetoslav | 57bf885 | 2013-02-07 19:21:42 -0800 | [diff] [blame] | 1840 | } |
Svetoslav | 6f8218a | 2013-02-20 16:28:39 -0800 | [diff] [blame] | 1841 | removeServiceLocked(this, userState); |
Svetoslav | 2602a39 | 2013-04-15 16:26:39 -0700 | [diff] [blame] | 1842 | resetLocked(); |
Svetoslav | 57bf885 | 2013-02-07 19:21:42 -0800 | [diff] [blame] | 1843 | return true; |
svetoslavganov | 75986cf | 2009-05-14 22:28:01 -0700 | [diff] [blame] | 1844 | } |
| 1845 | |
Svetoslav | 3822896 | 2013-01-29 01:04:35 -0800 | [diff] [blame] | 1846 | public boolean canReceiveEventsLocked() { |
Svetoslav Ganov | c321c19 | 2011-06-03 19:43:23 -0700 | [diff] [blame] | 1847 | return (mEventTypes != 0 && mFeedbackType != 0 && mService != null); |
svetoslavganov | 75986cf | 2009-05-14 22:28:01 -0700 | [diff] [blame] | 1848 | } |
| 1849 | |
Svetoslav Ganov | 4213804 | 2012-03-20 11:51:39 -0700 | [diff] [blame] | 1850 | @Override |
Svetoslav | c4fccd1 | 2013-04-09 12:58:41 -0700 | [diff] [blame] | 1851 | public void setOnKeyEventResult(boolean handled, int sequence) { |
| 1852 | mKeyEventDispatcher.setOnKeyEventResult(handled, sequence); |
| 1853 | } |
| 1854 | |
| 1855 | @Override |
Svetoslav Ganov | 4213804 | 2012-03-20 11:51:39 -0700 | [diff] [blame] | 1856 | public AccessibilityServiceInfo getServiceInfo() { |
| 1857 | synchronized (mLock) { |
| 1858 | return mAccessibilityServiceInfo; |
| 1859 | } |
svetoslavganov | 75986cf | 2009-05-14 22:28:01 -0700 | [diff] [blame] | 1860 | } |
| 1861 | |
Svetoslav Ganov | 4213804 | 2012-03-20 11:51:39 -0700 | [diff] [blame] | 1862 | @Override |
| 1863 | public void setServiceInfo(AccessibilityServiceInfo info) { |
Svetoslav Ganov | 58d37b5 | 2012-09-18 12:04:19 -0700 | [diff] [blame] | 1864 | final long identity = Binder.clearCallingIdentity(); |
| 1865 | try { |
| 1866 | synchronized (mLock) { |
| 1867 | // If the XML manifest had data to configure the service its info |
| 1868 | // should be already set. In such a case update only the dynamically |
| 1869 | // configurable properties. |
| 1870 | AccessibilityServiceInfo oldInfo = mAccessibilityServiceInfo; |
| 1871 | if (oldInfo != null) { |
| 1872 | oldInfo.updateDynamicallyConfigurableProperties(info); |
| 1873 | setDynamicallyConfigurableProperties(oldInfo); |
| 1874 | } else { |
| 1875 | setDynamicallyConfigurableProperties(info); |
| 1876 | } |
Svetoslav | 57bf885 | 2013-02-07 19:21:42 -0800 | [diff] [blame] | 1877 | UserState userState = getUserStateLocked(mUserId); |
| 1878 | onUserStateChangedLocked(userState); |
Svetoslav Ganov | 4213804 | 2012-03-20 11:51:39 -0700 | [diff] [blame] | 1879 | } |
Svetoslav Ganov | 58d37b5 | 2012-09-18 12:04:19 -0700 | [diff] [blame] | 1880 | } finally { |
| 1881 | Binder.restoreCallingIdentity(identity); |
Svetoslav Ganov | 4213804 | 2012-03-20 11:51:39 -0700 | [diff] [blame] | 1882 | } |
| 1883 | } |
| 1884 | |
| 1885 | @Override |
svetoslavganov | 75986cf | 2009-05-14 22:28:01 -0700 | [diff] [blame] | 1886 | public void onServiceConnected(ComponentName componentName, IBinder service) { |
Svetoslav | 57bf885 | 2013-02-07 19:21:42 -0800 | [diff] [blame] | 1887 | synchronized (mLock) { |
Svetoslav | 57bf885 | 2013-02-07 19:21:42 -0800 | [diff] [blame] | 1888 | mService = service; |
| 1889 | mServiceInterface = IAccessibilityServiceClient.Stub.asInterface(service); |
| 1890 | UserState userState = getUserStateLocked(mUserId); |
Svetoslav | 6f8218a | 2013-02-20 16:28:39 -0800 | [diff] [blame] | 1891 | addServiceLocked(this, userState); |
Svetoslav Ganov | bfa1bf0 | 2013-05-03 01:13:05 -0700 | [diff] [blame] | 1892 | if (userState.mBindingServices.contains(mComponentName) || mWasConnectedAndDied) { |
Svetoslav | 57bf885 | 2013-02-07 19:21:42 -0800 | [diff] [blame] | 1893 | userState.mBindingServices.remove(mComponentName); |
Svetoslav Ganov | bfa1bf0 | 2013-05-03 01:13:05 -0700 | [diff] [blame] | 1894 | mWasConnectedAndDied = false; |
Svetoslav | a60fdfa | 2013-02-26 19:16:18 -0800 | [diff] [blame] | 1895 | try { |
Svetoslav | 072906e | 2013-04-15 12:10:36 -0700 | [diff] [blame] | 1896 | mServiceInterface.setConnection(this, mId); |
| 1897 | onUserStateChangedLocked(userState); |
Svetoslav | a60fdfa | 2013-02-26 19:16:18 -0800 | [diff] [blame] | 1898 | } catch (RemoteException re) { |
Svetoslav | 072906e | 2013-04-15 12:10:36 -0700 | [diff] [blame] | 1899 | Slog.w(LOG_TAG, "Error while setting connection for service: " |
| 1900 | + service, re); |
| 1901 | binderDied(); |
Svetoslav | a60fdfa | 2013-02-26 19:16:18 -0800 | [diff] [blame] | 1902 | } |
| 1903 | } else { |
| 1904 | binderDied(); |
svetoslavganov | 75986cf | 2009-05-14 22:28:01 -0700 | [diff] [blame] | 1905 | } |
Svetoslav | 57bf885 | 2013-02-07 19:21:42 -0800 | [diff] [blame] | 1906 | } |
svetoslavganov | 75986cf | 2009-05-14 22:28:01 -0700 | [diff] [blame] | 1907 | } |
| 1908 | |
Svetoslav Ganov | 4213804 | 2012-03-20 11:51:39 -0700 | [diff] [blame] | 1909 | @Override |
Svetoslav Ganov | 80943d8 | 2013-01-02 10:25:37 -0800 | [diff] [blame] | 1910 | public boolean findAccessibilityNodeInfosByViewId(int accessibilityWindowId, |
| 1911 | long accessibilityNodeId, String viewIdResName, int interactionId, |
Svetoslav Ganov | 79311c4 | 2012-01-17 20:24:26 -0800 | [diff] [blame] | 1912 | IAccessibilityInteractionConnectionCallback callback, long interrogatingTid) |
Svetoslav Ganov | 4a49d9f | 2011-07-17 12:22:08 -0700 | [diff] [blame] | 1913 | throws RemoteException { |
Svetoslav Ganov | 58d37b5 | 2012-09-18 12:04:19 -0700 | [diff] [blame] | 1914 | final int resolvedWindowId; |
Svetoslav Ganov | 8643aa0 | 2011-04-20 12:12:33 -0700 | [diff] [blame] | 1915 | IAccessibilityInteractionConnection connection = null; |
| 1916 | synchronized (mLock) { |
Svetoslav Ganov | 58d37b5 | 2012-09-18 12:04:19 -0700 | [diff] [blame] | 1917 | final int resolvedUserId = mSecurityPolicy |
| 1918 | .resolveCallingUserIdEnforcingPermissionsLocked( |
| 1919 | UserHandle.getCallingUserId()); |
| 1920 | if (resolvedUserId != mCurrentUserId) { |
Svetoslav Ganov | 152e9bb | 2012-10-12 20:15:29 -0700 | [diff] [blame] | 1921 | return false; |
Svetoslav Ganov | 58d37b5 | 2012-09-18 12:04:19 -0700 | [diff] [blame] | 1922 | } |
Svetoslav Ganov | 4a49d9f | 2011-07-17 12:22:08 -0700 | [diff] [blame] | 1923 | mSecurityPolicy.enforceCanRetrieveWindowContent(this); |
Svetoslav Ganov | 8643aa0 | 2011-04-20 12:12:33 -0700 | [diff] [blame] | 1924 | final boolean permissionGranted = mSecurityPolicy.canRetrieveWindowContent(this); |
Svetoslav Ganov | e8f9535 | 2011-07-06 17:24:03 -0700 | [diff] [blame] | 1925 | if (!permissionGranted) { |
Svetoslav Ganov | 152e9bb | 2012-10-12 20:15:29 -0700 | [diff] [blame] | 1926 | return false; |
Svetoslav Ganov | e8f9535 | 2011-07-06 17:24:03 -0700 | [diff] [blame] | 1927 | } else { |
Svetoslav Ganov | 58d37b5 | 2012-09-18 12:04:19 -0700 | [diff] [blame] | 1928 | resolvedWindowId = resolveAccessibilityWindowIdLocked(accessibilityWindowId); |
Svetoslav Ganov | 79311c4 | 2012-01-17 20:24:26 -0800 | [diff] [blame] | 1929 | connection = getConnectionLocked(resolvedWindowId); |
Svetoslav Ganov | e8f9535 | 2011-07-06 17:24:03 -0700 | [diff] [blame] | 1930 | if (connection == null) { |
Svetoslav Ganov | 152e9bb | 2012-10-12 20:15:29 -0700 | [diff] [blame] | 1931 | return false; |
Svetoslav Ganov | e8f9535 | 2011-07-06 17:24:03 -0700 | [diff] [blame] | 1932 | } |
Svetoslav Ganov | 8643aa0 | 2011-04-20 12:12:33 -0700 | [diff] [blame] | 1933 | } |
| 1934 | } |
Svetoslav Ganov | 8bd6961 | 2011-08-23 13:40:30 -0700 | [diff] [blame] | 1935 | final int interrogatingPid = Binder.getCallingPid(); |
Svetoslav Ganov | 8643aa0 | 2011-04-20 12:12:33 -0700 | [diff] [blame] | 1936 | final long identityToken = Binder.clearCallingIdentity(); |
Svetoslav Ganov | 152e9bb | 2012-10-12 20:15:29 -0700 | [diff] [blame] | 1937 | MagnificationSpec spec = getCompatibleMagnificationSpec(resolvedWindowId); |
Svetoslav Ganov | 8643aa0 | 2011-04-20 12:12:33 -0700 | [diff] [blame] | 1938 | try { |
Svetoslav Ganov | 80943d8 | 2013-01-02 10:25:37 -0800 | [diff] [blame] | 1939 | connection.findAccessibilityNodeInfosByViewId(accessibilityNodeId, |
| 1940 | viewIdResName, interactionId, callback, mFetchFlags, interrogatingPid, |
| 1941 | interrogatingTid, spec); |
Svetoslav Ganov | 152e9bb | 2012-10-12 20:15:29 -0700 | [diff] [blame] | 1942 | return true; |
Svetoslav Ganov | 8643aa0 | 2011-04-20 12:12:33 -0700 | [diff] [blame] | 1943 | } catch (RemoteException re) { |
| 1944 | if (DEBUG) { |
Svetoslav Ganov | 79311c4 | 2012-01-17 20:24:26 -0800 | [diff] [blame] | 1945 | Slog.e(LOG_TAG, "Error findAccessibilityNodeInfoByViewId()."); |
Svetoslav Ganov | 8643aa0 | 2011-04-20 12:12:33 -0700 | [diff] [blame] | 1946 | } |
| 1947 | } finally { |
| 1948 | Binder.restoreCallingIdentity(identityToken); |
| 1949 | } |
Svetoslav Ganov | 152e9bb | 2012-10-12 20:15:29 -0700 | [diff] [blame] | 1950 | return false; |
Svetoslav Ganov | 8643aa0 | 2011-04-20 12:12:33 -0700 | [diff] [blame] | 1951 | } |
| 1952 | |
Svetoslav Ganov | 4213804 | 2012-03-20 11:51:39 -0700 | [diff] [blame] | 1953 | @Override |
Svetoslav Ganov | 152e9bb | 2012-10-12 20:15:29 -0700 | [diff] [blame] | 1954 | public boolean findAccessibilityNodeInfosByText(int accessibilityWindowId, |
Svetoslav Ganov | 79311c4 | 2012-01-17 20:24:26 -0800 | [diff] [blame] | 1955 | long accessibilityNodeId, String text, int interactionId, |
Svetoslav Ganov | 8bd6961 | 2011-08-23 13:40:30 -0700 | [diff] [blame] | 1956 | IAccessibilityInteractionConnectionCallback callback, long interrogatingTid) |
| 1957 | throws RemoteException { |
Svetoslav Ganov | 58d37b5 | 2012-09-18 12:04:19 -0700 | [diff] [blame] | 1958 | final int resolvedWindowId; |
Svetoslav Ganov | 8643aa0 | 2011-04-20 12:12:33 -0700 | [diff] [blame] | 1959 | IAccessibilityInteractionConnection connection = null; |
| 1960 | synchronized (mLock) { |
Svetoslav Ganov | 58d37b5 | 2012-09-18 12:04:19 -0700 | [diff] [blame] | 1961 | final int resolvedUserId = mSecurityPolicy |
| 1962 | .resolveCallingUserIdEnforcingPermissionsLocked( |
| 1963 | UserHandle.getCallingUserId()); |
| 1964 | if (resolvedUserId != mCurrentUserId) { |
Svetoslav Ganov | 152e9bb | 2012-10-12 20:15:29 -0700 | [diff] [blame] | 1965 | return false; |
Svetoslav Ganov | 58d37b5 | 2012-09-18 12:04:19 -0700 | [diff] [blame] | 1966 | } |
Svetoslav Ganov | 4a49d9f | 2011-07-17 12:22:08 -0700 | [diff] [blame] | 1967 | mSecurityPolicy.enforceCanRetrieveWindowContent(this); |
Svetoslav Ganov | 58d37b5 | 2012-09-18 12:04:19 -0700 | [diff] [blame] | 1968 | resolvedWindowId = resolveAccessibilityWindowIdLocked(accessibilityWindowId); |
Svetoslav Ganov | eeee4d2 | 2011-06-10 20:51:30 -0700 | [diff] [blame] | 1969 | final boolean permissionGranted = |
Svetoslav Ganov | 79311c4 | 2012-01-17 20:24:26 -0800 | [diff] [blame] | 1970 | mSecurityPolicy.canGetAccessibilityNodeInfoLocked(this, resolvedWindowId); |
Svetoslav Ganov | e8f9535 | 2011-07-06 17:24:03 -0700 | [diff] [blame] | 1971 | if (!permissionGranted) { |
Svetoslav Ganov | 152e9bb | 2012-10-12 20:15:29 -0700 | [diff] [blame] | 1972 | return false; |
Svetoslav Ganov | e8f9535 | 2011-07-06 17:24:03 -0700 | [diff] [blame] | 1973 | } else { |
Svetoslav Ganov | 79311c4 | 2012-01-17 20:24:26 -0800 | [diff] [blame] | 1974 | connection = getConnectionLocked(resolvedWindowId); |
Svetoslav Ganov | e8f9535 | 2011-07-06 17:24:03 -0700 | [diff] [blame] | 1975 | if (connection == null) { |
Svetoslav Ganov | 152e9bb | 2012-10-12 20:15:29 -0700 | [diff] [blame] | 1976 | return false; |
Svetoslav Ganov | e8f9535 | 2011-07-06 17:24:03 -0700 | [diff] [blame] | 1977 | } |
Svetoslav Ganov | 8643aa0 | 2011-04-20 12:12:33 -0700 | [diff] [blame] | 1978 | } |
| 1979 | } |
Svetoslav Ganov | 8bd6961 | 2011-08-23 13:40:30 -0700 | [diff] [blame] | 1980 | final int interrogatingPid = Binder.getCallingPid(); |
Svetoslav Ganov | 8643aa0 | 2011-04-20 12:12:33 -0700 | [diff] [blame] | 1981 | final long identityToken = Binder.clearCallingIdentity(); |
Svetoslav Ganov | 152e9bb | 2012-10-12 20:15:29 -0700 | [diff] [blame] | 1982 | MagnificationSpec spec = getCompatibleMagnificationSpec(resolvedWindowId); |
Svetoslav Ganov | 8643aa0 | 2011-04-20 12:12:33 -0700 | [diff] [blame] | 1983 | try { |
Svetoslav Ganov | c9c9a48 | 2012-07-16 08:46:07 -0700 | [diff] [blame] | 1984 | connection.findAccessibilityNodeInfosByText(accessibilityNodeId, text, |
Svetoslav Ganov | 80943d8 | 2013-01-02 10:25:37 -0800 | [diff] [blame] | 1985 | interactionId, callback, mFetchFlags, interrogatingPid, interrogatingTid, |
| 1986 | spec); |
Svetoslav Ganov | 152e9bb | 2012-10-12 20:15:29 -0700 | [diff] [blame] | 1987 | return true; |
Svetoslav Ganov | 8643aa0 | 2011-04-20 12:12:33 -0700 | [diff] [blame] | 1988 | } catch (RemoteException re) { |
| 1989 | if (DEBUG) { |
Svetoslav Ganov | 79311c4 | 2012-01-17 20:24:26 -0800 | [diff] [blame] | 1990 | Slog.e(LOG_TAG, "Error calling findAccessibilityNodeInfosByText()"); |
Svetoslav Ganov | 8643aa0 | 2011-04-20 12:12:33 -0700 | [diff] [blame] | 1991 | } |
| 1992 | } finally { |
| 1993 | Binder.restoreCallingIdentity(identityToken); |
| 1994 | } |
Svetoslav Ganov | 152e9bb | 2012-10-12 20:15:29 -0700 | [diff] [blame] | 1995 | return false; |
Svetoslav Ganov | 8643aa0 | 2011-04-20 12:12:33 -0700 | [diff] [blame] | 1996 | } |
| 1997 | |
Svetoslav Ganov | 4213804 | 2012-03-20 11:51:39 -0700 | [diff] [blame] | 1998 | @Override |
Svetoslav Ganov | 152e9bb | 2012-10-12 20:15:29 -0700 | [diff] [blame] | 1999 | public boolean findAccessibilityNodeInfoByAccessibilityId( |
| 2000 | int accessibilityWindowId, long accessibilityNodeId, int interactionId, |
Svetoslav Ganov | 4213804 | 2012-03-20 11:51:39 -0700 | [diff] [blame] | 2001 | IAccessibilityInteractionConnectionCallback callback, int flags, |
| 2002 | long interrogatingTid) throws RemoteException { |
Svetoslav Ganov | 58d37b5 | 2012-09-18 12:04:19 -0700 | [diff] [blame] | 2003 | final int resolvedWindowId; |
Svetoslav Ganov | 4213804 | 2012-03-20 11:51:39 -0700 | [diff] [blame] | 2004 | IAccessibilityInteractionConnection connection = null; |
| 2005 | synchronized (mLock) { |
Svetoslav Ganov | 58d37b5 | 2012-09-18 12:04:19 -0700 | [diff] [blame] | 2006 | final int resolvedUserId = mSecurityPolicy |
| 2007 | .resolveCallingUserIdEnforcingPermissionsLocked( |
| 2008 | UserHandle.getCallingUserId()); |
| 2009 | if (resolvedUserId != mCurrentUserId) { |
Svetoslav Ganov | 152e9bb | 2012-10-12 20:15:29 -0700 | [diff] [blame] | 2010 | return false; |
Svetoslav Ganov | 58d37b5 | 2012-09-18 12:04:19 -0700 | [diff] [blame] | 2011 | } |
Svetoslav Ganov | 4213804 | 2012-03-20 11:51:39 -0700 | [diff] [blame] | 2012 | mSecurityPolicy.enforceCanRetrieveWindowContent(this); |
Svetoslav Ganov | 58d37b5 | 2012-09-18 12:04:19 -0700 | [diff] [blame] | 2013 | resolvedWindowId = resolveAccessibilityWindowIdLocked(accessibilityWindowId); |
Svetoslav Ganov | 4213804 | 2012-03-20 11:51:39 -0700 | [diff] [blame] | 2014 | final boolean permissionGranted = |
| 2015 | mSecurityPolicy.canGetAccessibilityNodeInfoLocked(this, resolvedWindowId); |
| 2016 | if (!permissionGranted) { |
Svetoslav Ganov | 152e9bb | 2012-10-12 20:15:29 -0700 | [diff] [blame] | 2017 | return false; |
Svetoslav Ganov | 4213804 | 2012-03-20 11:51:39 -0700 | [diff] [blame] | 2018 | } else { |
| 2019 | connection = getConnectionLocked(resolvedWindowId); |
| 2020 | if (connection == null) { |
Svetoslav Ganov | 152e9bb | 2012-10-12 20:15:29 -0700 | [diff] [blame] | 2021 | return false; |
Svetoslav Ganov | 4213804 | 2012-03-20 11:51:39 -0700 | [diff] [blame] | 2022 | } |
| 2023 | } |
| 2024 | } |
Svetoslav Ganov | 4213804 | 2012-03-20 11:51:39 -0700 | [diff] [blame] | 2025 | final int interrogatingPid = Binder.getCallingPid(); |
| 2026 | final long identityToken = Binder.clearCallingIdentity(); |
Svetoslav Ganov | 152e9bb | 2012-10-12 20:15:29 -0700 | [diff] [blame] | 2027 | MagnificationSpec spec = getCompatibleMagnificationSpec(resolvedWindowId); |
Svetoslav Ganov | 4213804 | 2012-03-20 11:51:39 -0700 | [diff] [blame] | 2028 | try { |
| 2029 | connection.findAccessibilityNodeInfoByAccessibilityId(accessibilityNodeId, |
Svetoslav Ganov | 80943d8 | 2013-01-02 10:25:37 -0800 | [diff] [blame] | 2030 | interactionId, callback, mFetchFlags | flags, interrogatingPid, |
| 2031 | interrogatingTid, spec); |
Svetoslav Ganov | 152e9bb | 2012-10-12 20:15:29 -0700 | [diff] [blame] | 2032 | return true; |
Svetoslav Ganov | 4213804 | 2012-03-20 11:51:39 -0700 | [diff] [blame] | 2033 | } catch (RemoteException re) { |
| 2034 | if (DEBUG) { |
| 2035 | Slog.e(LOG_TAG, "Error calling findAccessibilityNodeInfoByAccessibilityId()"); |
| 2036 | } |
| 2037 | } finally { |
| 2038 | Binder.restoreCallingIdentity(identityToken); |
| 2039 | } |
Svetoslav Ganov | 152e9bb | 2012-10-12 20:15:29 -0700 | [diff] [blame] | 2040 | return false; |
Svetoslav Ganov | 4213804 | 2012-03-20 11:51:39 -0700 | [diff] [blame] | 2041 | } |
| 2042 | |
| 2043 | @Override |
Svetoslav Ganov | 152e9bb | 2012-10-12 20:15:29 -0700 | [diff] [blame] | 2044 | public boolean findFocus(int accessibilityWindowId, long accessibilityNodeId, |
Svetoslav Ganov | 4213804 | 2012-03-20 11:51:39 -0700 | [diff] [blame] | 2045 | int focusType, int interactionId, |
| 2046 | IAccessibilityInteractionConnectionCallback callback, long interrogatingTid) |
Svetoslav Ganov | 8bd6961 | 2011-08-23 13:40:30 -0700 | [diff] [blame] | 2047 | throws RemoteException { |
Svetoslav Ganov | 58d37b5 | 2012-09-18 12:04:19 -0700 | [diff] [blame] | 2048 | final int resolvedWindowId; |
Svetoslav Ganov | 8643aa0 | 2011-04-20 12:12:33 -0700 | [diff] [blame] | 2049 | IAccessibilityInteractionConnection connection = null; |
| 2050 | synchronized (mLock) { |
Svetoslav Ganov | 58d37b5 | 2012-09-18 12:04:19 -0700 | [diff] [blame] | 2051 | final int resolvedUserId = mSecurityPolicy |
| 2052 | .resolveCallingUserIdEnforcingPermissionsLocked( |
| 2053 | UserHandle.getCallingUserId()); |
| 2054 | if (resolvedUserId != mCurrentUserId) { |
Svetoslav Ganov | 152e9bb | 2012-10-12 20:15:29 -0700 | [diff] [blame] | 2055 | return false; |
Svetoslav Ganov | 58d37b5 | 2012-09-18 12:04:19 -0700 | [diff] [blame] | 2056 | } |
Svetoslav Ganov | 4a49d9f | 2011-07-17 12:22:08 -0700 | [diff] [blame] | 2057 | mSecurityPolicy.enforceCanRetrieveWindowContent(this); |
Svetoslav Ganov | 58d37b5 | 2012-09-18 12:04:19 -0700 | [diff] [blame] | 2058 | resolvedWindowId = resolveAccessibilityWindowIdLocked(accessibilityWindowId); |
Svetoslav Ganov | 8643aa0 | 2011-04-20 12:12:33 -0700 | [diff] [blame] | 2059 | final boolean permissionGranted = |
Svetoslav Ganov | 79311c4 | 2012-01-17 20:24:26 -0800 | [diff] [blame] | 2060 | mSecurityPolicy.canGetAccessibilityNodeInfoLocked(this, resolvedWindowId); |
Svetoslav Ganov | e8f9535 | 2011-07-06 17:24:03 -0700 | [diff] [blame] | 2061 | if (!permissionGranted) { |
Svetoslav Ganov | 152e9bb | 2012-10-12 20:15:29 -0700 | [diff] [blame] | 2062 | return false; |
Svetoslav Ganov | e8f9535 | 2011-07-06 17:24:03 -0700 | [diff] [blame] | 2063 | } else { |
Svetoslav Ganov | 79311c4 | 2012-01-17 20:24:26 -0800 | [diff] [blame] | 2064 | connection = getConnectionLocked(resolvedWindowId); |
| 2065 | if (connection == null) { |
Svetoslav Ganov | 152e9bb | 2012-10-12 20:15:29 -0700 | [diff] [blame] | 2066 | return false; |
Svetoslav Ganov | e8f9535 | 2011-07-06 17:24:03 -0700 | [diff] [blame] | 2067 | } |
Svetoslav Ganov | 8643aa0 | 2011-04-20 12:12:33 -0700 | [diff] [blame] | 2068 | } |
| 2069 | } |
Svetoslav Ganov | 8bd6961 | 2011-08-23 13:40:30 -0700 | [diff] [blame] | 2070 | final int interrogatingPid = Binder.getCallingPid(); |
Svetoslav Ganov | 8643aa0 | 2011-04-20 12:12:33 -0700 | [diff] [blame] | 2071 | final long identityToken = Binder.clearCallingIdentity(); |
Svetoslav Ganov | 152e9bb | 2012-10-12 20:15:29 -0700 | [diff] [blame] | 2072 | MagnificationSpec spec = getCompatibleMagnificationSpec(resolvedWindowId); |
Svetoslav Ganov | 8643aa0 | 2011-04-20 12:12:33 -0700 | [diff] [blame] | 2073 | try { |
Svetoslav Ganov | c9c9a48 | 2012-07-16 08:46:07 -0700 | [diff] [blame] | 2074 | connection.findFocus(accessibilityNodeId, focusType, interactionId, callback, |
Svetoslav Ganov | 80943d8 | 2013-01-02 10:25:37 -0800 | [diff] [blame] | 2075 | mFetchFlags, interrogatingPid, interrogatingTid, spec); |
Svetoslav Ganov | 152e9bb | 2012-10-12 20:15:29 -0700 | [diff] [blame] | 2076 | return true; |
Svetoslav Ganov | 8643aa0 | 2011-04-20 12:12:33 -0700 | [diff] [blame] | 2077 | } catch (RemoteException re) { |
| 2078 | if (DEBUG) { |
Svetoslav Ganov | 4213804 | 2012-03-20 11:51:39 -0700 | [diff] [blame] | 2079 | Slog.e(LOG_TAG, "Error calling findAccessibilityFocus()"); |
Svetoslav Ganov | 8643aa0 | 2011-04-20 12:12:33 -0700 | [diff] [blame] | 2080 | } |
| 2081 | } finally { |
| 2082 | Binder.restoreCallingIdentity(identityToken); |
| 2083 | } |
Svetoslav Ganov | 152e9bb | 2012-10-12 20:15:29 -0700 | [diff] [blame] | 2084 | return false; |
Svetoslav Ganov | 8643aa0 | 2011-04-20 12:12:33 -0700 | [diff] [blame] | 2085 | } |
| 2086 | |
Svetoslav Ganov | 4213804 | 2012-03-20 11:51:39 -0700 | [diff] [blame] | 2087 | @Override |
Svetoslav Ganov | 152e9bb | 2012-10-12 20:15:29 -0700 | [diff] [blame] | 2088 | public boolean focusSearch(int accessibilityWindowId, long accessibilityNodeId, |
Svetoslav Ganov | 4213804 | 2012-03-20 11:51:39 -0700 | [diff] [blame] | 2089 | int direction, int interactionId, |
| 2090 | IAccessibilityInteractionConnectionCallback callback, long interrogatingTid) |
| 2091 | throws RemoteException { |
Svetoslav Ganov | 58d37b5 | 2012-09-18 12:04:19 -0700 | [diff] [blame] | 2092 | final int resolvedWindowId; |
Svetoslav Ganov | 4213804 | 2012-03-20 11:51:39 -0700 | [diff] [blame] | 2093 | IAccessibilityInteractionConnection connection = null; |
| 2094 | synchronized (mLock) { |
Svetoslav Ganov | 58d37b5 | 2012-09-18 12:04:19 -0700 | [diff] [blame] | 2095 | final int resolvedUserId = mSecurityPolicy |
| 2096 | .resolveCallingUserIdEnforcingPermissionsLocked( |
| 2097 | UserHandle.getCallingUserId()); |
| 2098 | if (resolvedUserId != mCurrentUserId) { |
Svetoslav Ganov | 152e9bb | 2012-10-12 20:15:29 -0700 | [diff] [blame] | 2099 | return false; |
Svetoslav Ganov | 58d37b5 | 2012-09-18 12:04:19 -0700 | [diff] [blame] | 2100 | } |
Svetoslav Ganov | 4213804 | 2012-03-20 11:51:39 -0700 | [diff] [blame] | 2101 | mSecurityPolicy.enforceCanRetrieveWindowContent(this); |
Svetoslav Ganov | 58d37b5 | 2012-09-18 12:04:19 -0700 | [diff] [blame] | 2102 | resolvedWindowId = resolveAccessibilityWindowIdLocked(accessibilityWindowId); |
Svetoslav Ganov | 4213804 | 2012-03-20 11:51:39 -0700 | [diff] [blame] | 2103 | final boolean permissionGranted = |
| 2104 | mSecurityPolicy.canGetAccessibilityNodeInfoLocked(this, resolvedWindowId); |
| 2105 | if (!permissionGranted) { |
Svetoslav Ganov | 152e9bb | 2012-10-12 20:15:29 -0700 | [diff] [blame] | 2106 | return false; |
Svetoslav Ganov | 4213804 | 2012-03-20 11:51:39 -0700 | [diff] [blame] | 2107 | } else { |
| 2108 | connection = getConnectionLocked(resolvedWindowId); |
| 2109 | if (connection == null) { |
Svetoslav Ganov | 152e9bb | 2012-10-12 20:15:29 -0700 | [diff] [blame] | 2110 | return false; |
Svetoslav Ganov | 4213804 | 2012-03-20 11:51:39 -0700 | [diff] [blame] | 2111 | } |
| 2112 | } |
| 2113 | } |
Svetoslav Ganov | 4213804 | 2012-03-20 11:51:39 -0700 | [diff] [blame] | 2114 | final int interrogatingPid = Binder.getCallingPid(); |
| 2115 | final long identityToken = Binder.clearCallingIdentity(); |
Svetoslav Ganov | 152e9bb | 2012-10-12 20:15:29 -0700 | [diff] [blame] | 2116 | MagnificationSpec spec = getCompatibleMagnificationSpec(resolvedWindowId); |
Svetoslav Ganov | 4213804 | 2012-03-20 11:51:39 -0700 | [diff] [blame] | 2117 | try { |
Svetoslav Ganov | c9c9a48 | 2012-07-16 08:46:07 -0700 | [diff] [blame] | 2118 | connection.focusSearch(accessibilityNodeId, direction, interactionId, callback, |
Svetoslav Ganov | 80943d8 | 2013-01-02 10:25:37 -0800 | [diff] [blame] | 2119 | mFetchFlags, interrogatingPid, interrogatingTid, spec); |
Svetoslav Ganov | 152e9bb | 2012-10-12 20:15:29 -0700 | [diff] [blame] | 2120 | return true; |
Svetoslav Ganov | 4213804 | 2012-03-20 11:51:39 -0700 | [diff] [blame] | 2121 | } catch (RemoteException re) { |
| 2122 | if (DEBUG) { |
| 2123 | Slog.e(LOG_TAG, "Error calling accessibilityFocusSearch()"); |
| 2124 | } |
| 2125 | } finally { |
| 2126 | Binder.restoreCallingIdentity(identityToken); |
| 2127 | } |
Svetoslav Ganov | 152e9bb | 2012-10-12 20:15:29 -0700 | [diff] [blame] | 2128 | return false; |
Svetoslav Ganov | 4213804 | 2012-03-20 11:51:39 -0700 | [diff] [blame] | 2129 | } |
| 2130 | |
| 2131 | @Override |
Svetoslav Ganov | 8643aa0 | 2011-04-20 12:12:33 -0700 | [diff] [blame] | 2132 | public boolean performAccessibilityAction(int accessibilityWindowId, |
Svetoslav Ganov | aa780c1 | 2012-04-19 23:01:39 -0700 | [diff] [blame] | 2133 | long accessibilityNodeId, int action, Bundle arguments, int interactionId, |
Svetoslav Ganov | 58d37b5 | 2012-09-18 12:04:19 -0700 | [diff] [blame] | 2134 | IAccessibilityInteractionConnectionCallback callback, long interrogatingTid) |
| 2135 | throws RemoteException { |
| 2136 | final int resolvedWindowId; |
Svetoslav Ganov | 8643aa0 | 2011-04-20 12:12:33 -0700 | [diff] [blame] | 2137 | IAccessibilityInteractionConnection connection = null; |
| 2138 | synchronized (mLock) { |
Svetoslav Ganov | 58d37b5 | 2012-09-18 12:04:19 -0700 | [diff] [blame] | 2139 | final int resolvedUserId = mSecurityPolicy |
| 2140 | .resolveCallingUserIdEnforcingPermissionsLocked( |
| 2141 | UserHandle.getCallingUserId()); |
| 2142 | if (resolvedUserId != mCurrentUserId) { |
| 2143 | return false; |
| 2144 | } |
| 2145 | mSecurityPolicy.enforceCanRetrieveWindowContent(this); |
| 2146 | resolvedWindowId = resolveAccessibilityWindowIdLocked(accessibilityWindowId); |
Svetoslav Ganov | 8643aa0 | 2011-04-20 12:12:33 -0700 | [diff] [blame] | 2147 | final boolean permissionGranted = mSecurityPolicy.canPerformActionLocked(this, |
Svetoslav Ganov | b7ff325 | 2012-04-24 18:40:07 -0700 | [diff] [blame] | 2148 | resolvedWindowId, action, arguments); |
Svetoslav Ganov | e8f9535 | 2011-07-06 17:24:03 -0700 | [diff] [blame] | 2149 | if (!permissionGranted) { |
| 2150 | return false; |
| 2151 | } else { |
Svetoslav Ganov | 79311c4 | 2012-01-17 20:24:26 -0800 | [diff] [blame] | 2152 | connection = getConnectionLocked(resolvedWindowId); |
| 2153 | if (connection == null) { |
Svetoslav Ganov | e8f9535 | 2011-07-06 17:24:03 -0700 | [diff] [blame] | 2154 | return false; |
| 2155 | } |
Svetoslav Ganov | 8643aa0 | 2011-04-20 12:12:33 -0700 | [diff] [blame] | 2156 | } |
| 2157 | } |
Svetoslav Ganov | 9bf21873c | 2012-05-22 17:43:23 -0700 | [diff] [blame] | 2158 | final int interrogatingPid = Binder.getCallingPid(); |
Svetoslav Ganov | 8643aa0 | 2011-04-20 12:12:33 -0700 | [diff] [blame] | 2159 | final long identityToken = Binder.clearCallingIdentity(); |
| 2160 | try { |
Svetoslav Ganov | aa780c1 | 2012-04-19 23:01:39 -0700 | [diff] [blame] | 2161 | connection.performAccessibilityAction(accessibilityNodeId, action, arguments, |
Svetoslav Ganov | 80943d8 | 2013-01-02 10:25:37 -0800 | [diff] [blame] | 2162 | interactionId, callback, mFetchFlags, interrogatingPid, interrogatingTid); |
Svetoslav Ganov | 8643aa0 | 2011-04-20 12:12:33 -0700 | [diff] [blame] | 2163 | } catch (RemoteException re) { |
| 2164 | if (DEBUG) { |
Svetoslav Ganov | 79311c4 | 2012-01-17 20:24:26 -0800 | [diff] [blame] | 2165 | Slog.e(LOG_TAG, "Error calling performAccessibilityAction()"); |
Svetoslav Ganov | 8643aa0 | 2011-04-20 12:12:33 -0700 | [diff] [blame] | 2166 | } |
| 2167 | } finally { |
| 2168 | Binder.restoreCallingIdentity(identityToken); |
| 2169 | } |
Svetoslav Ganov | 8bd6961 | 2011-08-23 13:40:30 -0700 | [diff] [blame] | 2170 | return true; |
Svetoslav Ganov | 8643aa0 | 2011-04-20 12:12:33 -0700 | [diff] [blame] | 2171 | } |
| 2172 | |
Svetoslav Ganov | e20a177 | 2012-09-25 16:07:46 -0700 | [diff] [blame] | 2173 | public boolean performGlobalAction(int action) { |
Svetoslav Ganov | 58d37b5 | 2012-09-18 12:04:19 -0700 | [diff] [blame] | 2174 | synchronized (mLock) { |
| 2175 | final int resolvedUserId = mSecurityPolicy |
| 2176 | .resolveCallingUserIdEnforcingPermissionsLocked( |
| 2177 | UserHandle.getCallingUserId()); |
| 2178 | if (resolvedUserId != mCurrentUserId) { |
| 2179 | return false; |
| 2180 | } |
Svetoslav Ganov | 005b83b | 2012-04-16 18:17:17 -0700 | [diff] [blame] | 2181 | } |
Svetoslav Ganov | 58d37b5 | 2012-09-18 12:04:19 -0700 | [diff] [blame] | 2182 | final long identity = Binder.clearCallingIdentity(); |
| 2183 | try { |
| 2184 | switch (action) { |
| 2185 | case AccessibilityService.GLOBAL_ACTION_BACK: { |
| 2186 | sendDownAndUpKeyEvents(KeyEvent.KEYCODE_BACK); |
| 2187 | } return true; |
| 2188 | case AccessibilityService.GLOBAL_ACTION_HOME: { |
| 2189 | sendDownAndUpKeyEvents(KeyEvent.KEYCODE_HOME); |
| 2190 | } return true; |
| 2191 | case AccessibilityService.GLOBAL_ACTION_RECENTS: { |
| 2192 | openRecents(); |
| 2193 | } return true; |
| 2194 | case AccessibilityService.GLOBAL_ACTION_NOTIFICATIONS: { |
Svetoslav Ganov | e20a177 | 2012-09-25 16:07:46 -0700 | [diff] [blame] | 2195 | expandNotifications(); |
| 2196 | } return true; |
| 2197 | case AccessibilityService.GLOBAL_ACTION_QUICK_SETTINGS: { |
| 2198 | expandQuickSettings(); |
Svetoslav Ganov | 58d37b5 | 2012-09-18 12:04:19 -0700 | [diff] [blame] | 2199 | } return true; |
| 2200 | } |
| 2201 | return false; |
| 2202 | } finally { |
| 2203 | Binder.restoreCallingIdentity(identity); |
| 2204 | } |
Svetoslav Ganov | 005b83b | 2012-04-16 18:17:17 -0700 | [diff] [blame] | 2205 | } |
| 2206 | |
Svetoslav Ganov | 6ce77cd | 2012-11-21 16:35:57 -0800 | [diff] [blame] | 2207 | @Override |
| 2208 | public void dump(FileDescriptor fd, final PrintWriter pw, String[] args) { |
| 2209 | mSecurityPolicy.enforceCallingPermission(Manifest.permission.DUMP, FUNCTION_DUMP); |
| 2210 | synchronized (mLock) { |
| 2211 | pw.append("Service[label=" + mAccessibilityServiceInfo.getResolveInfo() |
| 2212 | .loadLabel(mContext.getPackageManager())); |
| 2213 | pw.append(", feedbackType" |
| 2214 | + AccessibilityServiceInfo.feedbackTypeToString(mFeedbackType)); |
Svetoslav | 11adf6d | 2013-04-24 14:51:29 -0700 | [diff] [blame] | 2215 | pw.append(", capabilities=" + mAccessibilityServiceInfo.getCapabilities()); |
Svetoslav Ganov | 6ce77cd | 2012-11-21 16:35:57 -0800 | [diff] [blame] | 2216 | pw.append(", eventTypes=" |
| 2217 | + AccessibilityEvent.eventTypeToString(mEventTypes)); |
| 2218 | pw.append(", notificationTimeout=" + mNotificationTimeout); |
| 2219 | pw.append("]"); |
| 2220 | } |
| 2221 | } |
| 2222 | |
| 2223 | @Override |
svetoslavganov | 75986cf | 2009-05-14 22:28:01 -0700 | [diff] [blame] | 2224 | public void onServiceDisconnected(ComponentName componentName) { |
Svetoslav Ganov | f9886f3 | 2011-05-10 15:28:33 -0700 | [diff] [blame] | 2225 | /* do nothing - #binderDied takes care */ |
| 2226 | } |
| 2227 | |
Svetoslav | 2602a39 | 2013-04-15 16:26:39 -0700 | [diff] [blame] | 2228 | public void linkToOwnDeathLocked() throws RemoteException { |
Svetoslav Ganov | f9886f3 | 2011-05-10 15:28:33 -0700 | [diff] [blame] | 2229 | mService.linkToDeath(this, 0); |
| 2230 | } |
| 2231 | |
Svetoslav | 2602a39 | 2013-04-15 16:26:39 -0700 | [diff] [blame] | 2232 | public void unlinkToOwnDeathLocked() { |
Svetoslav Ganov | f9886f3 | 2011-05-10 15:28:33 -0700 | [diff] [blame] | 2233 | mService.unlinkToDeath(this, 0); |
| 2234 | } |
| 2235 | |
Svetoslav | 2602a39 | 2013-04-15 16:26:39 -0700 | [diff] [blame] | 2236 | public void resetLocked() { |
Svetoslav Ganov | d116d7c | 2011-11-21 18:41:59 -0800 | [diff] [blame] | 2237 | try { |
| 2238 | // Clear the proxy in the other process so this |
| 2239 | // IAccessibilityServiceConnection can be garbage collected. |
| 2240 | mServiceInterface.setConnection(null, mId); |
| 2241 | } catch (RemoteException re) { |
| 2242 | /* ignore */ |
| 2243 | } |
| 2244 | mService = null; |
| 2245 | mServiceInterface = null; |
| 2246 | } |
| 2247 | |
Svetoslav Ganov | bfa1bf0 | 2013-05-03 01:13:05 -0700 | [diff] [blame] | 2248 | public boolean isConnectedLocked() { |
Svetoslav | 2602a39 | 2013-04-15 16:26:39 -0700 | [diff] [blame] | 2249 | return (mService != null); |
| 2250 | } |
| 2251 | |
Svetoslav Ganov | f9886f3 | 2011-05-10 15:28:33 -0700 | [diff] [blame] | 2252 | public void binderDied() { |
svetoslavganov | 75986cf | 2009-05-14 22:28:01 -0700 | [diff] [blame] | 2253 | synchronized (mLock) { |
Svetoslav | 2602a39 | 2013-04-15 16:26:39 -0700 | [diff] [blame] | 2254 | // It is possible that this service's package was force stopped during |
| 2255 | // whose handling the death recipient is unlinked and still get a call |
| 2256 | // on binderDied since the call was made before we unlink but was |
| 2257 | // waiting on the lock we held during the force stop handling. |
Svetoslav Ganov | bfa1bf0 | 2013-05-03 01:13:05 -0700 | [diff] [blame] | 2258 | if (!isConnectedLocked()) { |
Svetoslav | 2602a39 | 2013-04-15 16:26:39 -0700 | [diff] [blame] | 2259 | return; |
| 2260 | } |
Svetoslav Ganov | bfa1bf0 | 2013-05-03 01:13:05 -0700 | [diff] [blame] | 2261 | mWasConnectedAndDied = true; |
Svetoslav | c4fccd1 | 2013-04-09 12:58:41 -0700 | [diff] [blame] | 2262 | mKeyEventDispatcher.flush(); |
Svetoslav | 57bf885 | 2013-02-07 19:21:42 -0800 | [diff] [blame] | 2263 | UserState userState = getUserStateLocked(mUserId); |
Svetoslav | 6f8218a | 2013-02-20 16:28:39 -0800 | [diff] [blame] | 2264 | // The death recipient is unregistered in removeServiceLocked |
| 2265 | removeServiceLocked(this, userState); |
Svetoslav | 2602a39 | 2013-04-15 16:26:39 -0700 | [diff] [blame] | 2266 | resetLocked(); |
Svetoslav Ganov | b6eca6e | 2011-09-27 10:47:58 -0700 | [diff] [blame] | 2267 | if (mIsAutomation) { |
Svetoslav | 57bf885 | 2013-02-07 19:21:42 -0800 | [diff] [blame] | 2268 | // We no longer have an automation service, so restore |
| 2269 | // the state based on values in the settings database. |
Svetoslav | 7379a95 | 2013-02-13 15:47:29 -0800 | [diff] [blame] | 2270 | userState.mInstalledServices.remove(mAccessibilityServiceInfo); |
| 2271 | userState.mEnabledServices.remove(mComponentName); |
Svetoslav | 3c55e5c | 2013-02-27 18:24:28 -0800 | [diff] [blame] | 2272 | userState.destroyUiAutomationService(); |
Svetoslav Ganov | b6eca6e | 2011-09-27 10:47:58 -0700 | [diff] [blame] | 2273 | } |
svetoslavganov | 75986cf | 2009-05-14 22:28:01 -0700 | [diff] [blame] | 2274 | } |
| 2275 | } |
Svetoslav Ganov | 8643aa0 | 2011-04-20 12:12:33 -0700 | [diff] [blame] | 2276 | |
Svetoslav Ganov | e15ccb9 | 2012-05-16 15:48:55 -0700 | [diff] [blame] | 2277 | /** |
| 2278 | * Performs a notification for an {@link AccessibilityEvent}. |
| 2279 | * |
| 2280 | * @param event The event. |
| 2281 | */ |
| 2282 | public void notifyAccessibilityEvent(AccessibilityEvent event) { |
| 2283 | synchronized (mLock) { |
| 2284 | final int eventType = event.getEventType(); |
| 2285 | // Make a copy since during dispatch it is possible the event to |
| 2286 | // be modified to remove its source if the receiving service does |
| 2287 | // not have permission to access the window content. |
| 2288 | AccessibilityEvent newEvent = AccessibilityEvent.obtain(event); |
| 2289 | AccessibilityEvent oldEvent = mPendingEvents.get(eventType); |
| 2290 | mPendingEvents.put(eventType, newEvent); |
| 2291 | |
| 2292 | final int what = eventType; |
| 2293 | if (oldEvent != null) { |
Svetoslav | c4fccd1 | 2013-04-09 12:58:41 -0700 | [diff] [blame] | 2294 | mEventDispatchHandler.removeMessages(what); |
Svetoslav Ganov | e15ccb9 | 2012-05-16 15:48:55 -0700 | [diff] [blame] | 2295 | oldEvent.recycle(); |
| 2296 | } |
| 2297 | |
Svetoslav | c4fccd1 | 2013-04-09 12:58:41 -0700 | [diff] [blame] | 2298 | Message message = mEventDispatchHandler.obtainMessage(what); |
| 2299 | mEventDispatchHandler.sendMessageDelayed(message, mNotificationTimeout); |
Svetoslav Ganov | e15ccb9 | 2012-05-16 15:48:55 -0700 | [diff] [blame] | 2300 | } |
| 2301 | } |
| 2302 | |
| 2303 | /** |
| 2304 | * Notifies an accessibility service client for a scheduled event given the event type. |
| 2305 | * |
| 2306 | * @param eventType The type of the event to dispatch. |
| 2307 | */ |
| 2308 | private void notifyAccessibilityEventInternal(int eventType) { |
| 2309 | IAccessibilityServiceClient listener; |
| 2310 | AccessibilityEvent event; |
| 2311 | |
| 2312 | synchronized (mLock) { |
| 2313 | listener = mServiceInterface; |
| 2314 | |
| 2315 | // If the service died/was disabled while the message for dispatching |
| 2316 | // the accessibility event was propagating the listener may be null. |
| 2317 | if (listener == null) { |
| 2318 | return; |
| 2319 | } |
| 2320 | |
| 2321 | event = mPendingEvents.get(eventType); |
| 2322 | |
| 2323 | // Check for null here because there is a concurrent scenario in which this |
| 2324 | // happens: 1) A binder thread calls notifyAccessibilityServiceDelayedLocked |
| 2325 | // which posts a message for dispatching an event. 2) The message is pulled |
| 2326 | // from the queue by the handler on the service thread and the latter is |
| 2327 | // just about to acquire the lock and call this method. 3) Now another binder |
| 2328 | // thread acquires the lock calling notifyAccessibilityServiceDelayedLocked |
| 2329 | // so the service thread waits for the lock; 4) The binder thread replaces |
| 2330 | // the event with a more recent one (assume the same event type) and posts a |
| 2331 | // dispatch request releasing the lock. 5) Now the main thread is unblocked and |
| 2332 | // dispatches the event which is removed from the pending ones. 6) And ... now |
| 2333 | // the service thread handles the last message posted by the last binder call |
| 2334 | // but the event is already dispatched and hence looking it up in the pending |
| 2335 | // ones yields null. This check is much simpler that keeping count for each |
| 2336 | // event type of each service to catch such a scenario since only one message |
| 2337 | // is processed at a time. |
| 2338 | if (event == null) { |
| 2339 | return; |
| 2340 | } |
| 2341 | |
| 2342 | mPendingEvents.remove(eventType); |
| 2343 | if (mSecurityPolicy.canRetrieveWindowContent(this)) { |
| 2344 | event.setConnectionId(mId); |
| 2345 | } else { |
| 2346 | event.setSource(null); |
| 2347 | } |
| 2348 | event.setSealed(true); |
| 2349 | } |
| 2350 | |
| 2351 | try { |
| 2352 | listener.onAccessibilityEvent(event); |
| 2353 | if (DEBUG) { |
| 2354 | Slog.i(LOG_TAG, "Event " + event + " sent to " + listener); |
| 2355 | } |
| 2356 | } catch (RemoteException re) { |
| 2357 | Slog.e(LOG_TAG, "Error during sending " + event + " to " + listener, re); |
| 2358 | } finally { |
| 2359 | event.recycle(); |
| 2360 | } |
| 2361 | } |
| 2362 | |
| 2363 | public void notifyGesture(int gestureId) { |
Svetoslav | c4fccd1 | 2013-04-09 12:58:41 -0700 | [diff] [blame] | 2364 | mInvocationHandler.obtainMessage(InvocationHandler.MSG_ON_GESTURE, |
| 2365 | gestureId, 0).sendToTarget(); |
| 2366 | } |
| 2367 | |
| 2368 | public void notifyKeyEvent(KeyEvent event, int policyFlags) { |
| 2369 | mInvocationHandler.obtainMessage(InvocationHandler.MSG_ON_KEY_EVENT, |
| 2370 | policyFlags, 0, event).sendToTarget(); |
Svetoslav Ganov | e15ccb9 | 2012-05-16 15:48:55 -0700 | [diff] [blame] | 2371 | } |
| 2372 | |
Svetoslav Ganov | 152e9bb | 2012-10-12 20:15:29 -0700 | [diff] [blame] | 2373 | public void notifyClearAccessibilityNodeInfoCache() { |
Svetoslav | c4fccd1 | 2013-04-09 12:58:41 -0700 | [diff] [blame] | 2374 | mInvocationHandler.sendEmptyMessage( |
| 2375 | InvocationHandler.MSG_CLEAR_ACCESSIBILITY_NODE_INFO_CACHE); |
Svetoslav Ganov | 152e9bb | 2012-10-12 20:15:29 -0700 | [diff] [blame] | 2376 | } |
| 2377 | |
Svetoslav Ganov | e15ccb9 | 2012-05-16 15:48:55 -0700 | [diff] [blame] | 2378 | private void notifyGestureInternal(int gestureId) { |
| 2379 | IAccessibilityServiceClient listener = mServiceInterface; |
| 2380 | if (listener != null) { |
| 2381 | try { |
| 2382 | listener.onGesture(gestureId); |
| 2383 | } catch (RemoteException re) { |
| 2384 | Slog.e(LOG_TAG, "Error during sending gesture " + gestureId |
| 2385 | + " to " + mService, re); |
| 2386 | } |
| 2387 | } |
| 2388 | } |
| 2389 | |
Svetoslav | c4fccd1 | 2013-04-09 12:58:41 -0700 | [diff] [blame] | 2390 | private void notifyKeyEventInternal(KeyEvent event, int policyFlags) { |
| 2391 | mKeyEventDispatcher.notifyKeyEvent(event, policyFlags); |
| 2392 | } |
| 2393 | |
Svetoslav Ganov | 152e9bb | 2012-10-12 20:15:29 -0700 | [diff] [blame] | 2394 | private void notifyClearAccessibilityNodeInfoCacheInternal() { |
| 2395 | IAccessibilityServiceClient listener = mServiceInterface; |
| 2396 | if (listener != null) { |
| 2397 | try { |
| 2398 | listener.clearAccessibilityNodeInfoCache(); |
| 2399 | } catch (RemoteException re) { |
| 2400 | Slog.e(LOG_TAG, "Error during requesting accessibility info cache" |
| 2401 | + " to be cleared.", re); |
| 2402 | } |
| 2403 | } |
| 2404 | } |
| 2405 | |
Svetoslav Ganov | 005b83b | 2012-04-16 18:17:17 -0700 | [diff] [blame] | 2406 | private void sendDownAndUpKeyEvents(int keyCode) { |
| 2407 | final long token = Binder.clearCallingIdentity(); |
| 2408 | |
| 2409 | // Inject down. |
| 2410 | final long downTime = SystemClock.uptimeMillis(); |
| 2411 | KeyEvent down = KeyEvent.obtain(downTime, downTime, KeyEvent.ACTION_DOWN, keyCode, 0, 0, |
| 2412 | KeyCharacterMap.VIRTUAL_KEYBOARD, 0, KeyEvent.FLAG_FROM_SYSTEM, |
| 2413 | InputDevice.SOURCE_KEYBOARD, null); |
| 2414 | InputManager.getInstance().injectInputEvent(down, |
| 2415 | InputManager.INJECT_INPUT_EVENT_MODE_ASYNC); |
| 2416 | down.recycle(); |
| 2417 | |
| 2418 | // Inject up. |
| 2419 | final long upTime = SystemClock.uptimeMillis(); |
| 2420 | KeyEvent up = KeyEvent.obtain(downTime, upTime, KeyEvent.ACTION_UP, keyCode, 0, 0, |
| 2421 | KeyCharacterMap.VIRTUAL_KEYBOARD, 0, KeyEvent.FLAG_FROM_SYSTEM, |
| 2422 | InputDevice.SOURCE_KEYBOARD, null); |
| 2423 | InputManager.getInstance().injectInputEvent(up, |
| 2424 | InputManager.INJECT_INPUT_EVENT_MODE_ASYNC); |
| 2425 | up.recycle(); |
| 2426 | |
| 2427 | Binder.restoreCallingIdentity(token); |
| 2428 | } |
| 2429 | |
Svetoslav Ganov | e20a177 | 2012-09-25 16:07:46 -0700 | [diff] [blame] | 2430 | private void expandNotifications() { |
Svetoslav Ganov | 5c89f44 | 2012-05-15 13:28:09 -0700 | [diff] [blame] | 2431 | final long token = Binder.clearCallingIdentity(); |
| 2432 | |
| 2433 | StatusBarManager statusBarManager = (StatusBarManager) mContext.getSystemService( |
| 2434 | android.app.Service.STATUS_BAR_SERVICE); |
Daniel Sandler | 11cf178 | 2012-09-27 14:03:08 -0400 | [diff] [blame] | 2435 | statusBarManager.expandNotificationsPanel(); |
Svetoslav Ganov | e20a177 | 2012-09-25 16:07:46 -0700 | [diff] [blame] | 2436 | |
| 2437 | Binder.restoreCallingIdentity(token); |
| 2438 | } |
| 2439 | |
| 2440 | private void expandQuickSettings() { |
| 2441 | final long token = Binder.clearCallingIdentity(); |
| 2442 | |
| 2443 | StatusBarManager statusBarManager = (StatusBarManager) mContext.getSystemService( |
| 2444 | android.app.Service.STATUS_BAR_SERVICE); |
Daniel Sandler | 11cf178 | 2012-09-27 14:03:08 -0400 | [diff] [blame] | 2445 | statusBarManager.expandSettingsPanel(); |
Svetoslav Ganov | 5c89f44 | 2012-05-15 13:28:09 -0700 | [diff] [blame] | 2446 | |
| 2447 | Binder.restoreCallingIdentity(token); |
| 2448 | } |
| 2449 | |
Svetoslav Ganov | c682fc9 | 2012-06-04 14:02:09 -0700 | [diff] [blame] | 2450 | private void openRecents() { |
| 2451 | final long token = Binder.clearCallingIdentity(); |
| 2452 | |
| 2453 | IStatusBarService statusBarService = IStatusBarService.Stub.asInterface( |
| 2454 | ServiceManager.getService("statusbar")); |
| 2455 | try { |
| 2456 | statusBarService.toggleRecentApps(); |
| 2457 | } catch (RemoteException e) { |
| 2458 | Slog.e(LOG_TAG, "Error toggling recent apps."); |
| 2459 | } |
| 2460 | |
| 2461 | Binder.restoreCallingIdentity(token); |
| 2462 | } |
| 2463 | |
Svetoslav Ganov | 79311c4 | 2012-01-17 20:24:26 -0800 | [diff] [blame] | 2464 | private IAccessibilityInteractionConnection getConnectionLocked(int windowId) { |
Svetoslav Ganov | 8643aa0 | 2011-04-20 12:12:33 -0700 | [diff] [blame] | 2465 | if (DEBUG) { |
| 2466 | Slog.i(LOG_TAG, "Trying to get interaction connection to windowId: " + windowId); |
| 2467 | } |
Svetoslav Ganov | 58d37b5 | 2012-09-18 12:04:19 -0700 | [diff] [blame] | 2468 | AccessibilityConnectionWrapper wrapper = mGlobalInteractionConnections.get(windowId); |
| 2469 | if (wrapper == null) { |
| 2470 | wrapper = getCurrentUserStateLocked().mInteractionConnections.get(windowId); |
| 2471 | } |
Svetoslav Ganov | 79311c4 | 2012-01-17 20:24:26 -0800 | [diff] [blame] | 2472 | if (wrapper != null && wrapper.mConnection != null) { |
| 2473 | return wrapper.mConnection; |
| 2474 | } |
| 2475 | if (DEBUG) { |
| 2476 | Slog.e(LOG_TAG, "No interaction connection to window: " + windowId); |
| 2477 | } |
| 2478 | return null; |
| 2479 | } |
| 2480 | |
Svetoslav Ganov | 58d37b5 | 2012-09-18 12:04:19 -0700 | [diff] [blame] | 2481 | private int resolveAccessibilityWindowIdLocked(int accessibilityWindowId) { |
Svetoslav Ganov | 0d04e24 | 2012-02-21 13:46:36 -0800 | [diff] [blame] | 2482 | if (accessibilityWindowId == AccessibilityNodeInfo.ACTIVE_WINDOW_ID) { |
Svetoslav Ganov | e15ccb9 | 2012-05-16 15:48:55 -0700 | [diff] [blame] | 2483 | return mSecurityPolicy.mActiveWindowId; |
Svetoslav Ganov | 79311c4 | 2012-01-17 20:24:26 -0800 | [diff] [blame] | 2484 | } |
| 2485 | return accessibilityWindowId; |
Svetoslav Ganov | 8643aa0 | 2011-04-20 12:12:33 -0700 | [diff] [blame] | 2486 | } |
Svetoslav Ganov | 7961be7 | 2011-06-21 12:31:56 -0700 | [diff] [blame] | 2487 | |
Svetoslav Ganov | 152e9bb | 2012-10-12 20:15:29 -0700 | [diff] [blame] | 2488 | private MagnificationSpec getCompatibleMagnificationSpec(int windowId) { |
Svetoslav Ganov | c9c9a48 | 2012-07-16 08:46:07 -0700 | [diff] [blame] | 2489 | try { |
Svetoslav Ganov | 152e9bb | 2012-10-12 20:15:29 -0700 | [diff] [blame] | 2490 | IBinder windowToken = mGlobalWindowTokens.get(windowId); |
| 2491 | if (windowToken == null) { |
| 2492 | windowToken = getCurrentUserStateLocked().mWindowTokens.get(windowId); |
| 2493 | } |
Svetoslav Ganov | 58d37b5 | 2012-09-18 12:04:19 -0700 | [diff] [blame] | 2494 | if (windowToken != null) { |
Svetoslav Ganov | 545252f | 2012-12-10 18:29:24 -0800 | [diff] [blame] | 2495 | return mWindowManagerService.getCompatibleMagnificationSpecForWindow( |
| 2496 | windowToken); |
Svetoslav Ganov | 58d37b5 | 2012-09-18 12:04:19 -0700 | [diff] [blame] | 2497 | } |
Svetoslav Ganov | c9c9a48 | 2012-07-16 08:46:07 -0700 | [diff] [blame] | 2498 | } catch (RemoteException re) { |
| 2499 | /* ignore */ |
| 2500 | } |
Svetoslav Ganov | 152e9bb | 2012-10-12 20:15:29 -0700 | [diff] [blame] | 2501 | return null; |
Svetoslav Ganov | 7961be7 | 2011-06-21 12:31:56 -0700 | [diff] [blame] | 2502 | } |
Svetoslav | c4fccd1 | 2013-04-09 12:58:41 -0700 | [diff] [blame] | 2503 | |
| 2504 | private final class InvocationHandler extends Handler { |
| 2505 | |
| 2506 | public static final int MSG_ON_GESTURE = 1; |
| 2507 | public static final int MSG_ON_KEY_EVENT = 2; |
| 2508 | public static final int MSG_CLEAR_ACCESSIBILITY_NODE_INFO_CACHE = 3; |
| 2509 | public static final int MSG_ON_KEY_EVENT_TIMEOUT = 4; |
| 2510 | |
| 2511 | public InvocationHandler(Looper looper) { |
| 2512 | super(looper, null, true); |
| 2513 | } |
| 2514 | |
| 2515 | @Override |
| 2516 | public void handleMessage(Message message) { |
| 2517 | final int type = message.what; |
| 2518 | switch (type) { |
| 2519 | case MSG_ON_GESTURE: { |
| 2520 | final int gestureId = message.arg1; |
| 2521 | notifyGestureInternal(gestureId); |
| 2522 | } break; |
| 2523 | case MSG_ON_KEY_EVENT: { |
| 2524 | KeyEvent event = (KeyEvent) message.obj; |
| 2525 | final int policyFlags = message.arg1; |
| 2526 | notifyKeyEventInternal(event, policyFlags); |
| 2527 | } break; |
| 2528 | case MSG_CLEAR_ACCESSIBILITY_NODE_INFO_CACHE: { |
| 2529 | notifyClearAccessibilityNodeInfoCacheInternal(); |
| 2530 | } break; |
| 2531 | case MSG_ON_KEY_EVENT_TIMEOUT: { |
| 2532 | PendingEvent eventState = (PendingEvent) message.obj; |
| 2533 | setOnKeyEventResult(false, eventState.sequence); |
| 2534 | } break; |
| 2535 | default: { |
| 2536 | throw new IllegalArgumentException("Unknown message: " + type); |
| 2537 | } |
| 2538 | } |
| 2539 | } |
| 2540 | } |
| 2541 | |
| 2542 | private final class KeyEventDispatcher { |
| 2543 | |
| 2544 | private static final long ON_KEY_EVENT_TIMEOUT_MILLIS = 500; |
| 2545 | |
| 2546 | private PendingEvent mPendingEvents; |
| 2547 | |
| 2548 | private final InputEventConsistencyVerifier mSentEventsVerifier = |
| 2549 | InputEventConsistencyVerifier.isInstrumentationEnabled() |
| 2550 | ? new InputEventConsistencyVerifier( |
| 2551 | this, 0, KeyEventDispatcher.class.getSimpleName()) : null; |
| 2552 | |
| 2553 | public void notifyKeyEvent(KeyEvent event, int policyFlags) { |
| 2554 | final PendingEvent pendingEvent; |
| 2555 | |
| 2556 | synchronized (mLock) { |
| 2557 | pendingEvent = addPendingEventLocked(event, policyFlags); |
| 2558 | } |
| 2559 | |
| 2560 | Message message = mInvocationHandler.obtainMessage( |
| 2561 | InvocationHandler.MSG_ON_KEY_EVENT_TIMEOUT, pendingEvent); |
| 2562 | mInvocationHandler.sendMessageDelayed(message, ON_KEY_EVENT_TIMEOUT_MILLIS); |
| 2563 | |
| 2564 | try { |
| 2565 | // Accessibility services are exclusively not in the system |
| 2566 | // process, therefore no need to clone the motion event to |
| 2567 | // prevent tampering. It will be cloned in the IPC call. |
| 2568 | mServiceInterface.onKeyEvent(pendingEvent.event, pendingEvent.sequence); |
| 2569 | } catch (RemoteException re) { |
| 2570 | setOnKeyEventResult(false, pendingEvent.sequence); |
| 2571 | } |
| 2572 | } |
| 2573 | |
| 2574 | public void setOnKeyEventResult(boolean handled, int sequence) { |
| 2575 | synchronized (mLock) { |
| 2576 | PendingEvent pendingEvent = removePendingEventLocked(sequence); |
| 2577 | if (pendingEvent != null) { |
| 2578 | mInvocationHandler.removeMessages( |
| 2579 | InvocationHandler.MSG_ON_KEY_EVENT_TIMEOUT, |
| 2580 | pendingEvent); |
| 2581 | pendingEvent.handled = handled; |
| 2582 | finishPendingEventLocked(pendingEvent); |
| 2583 | } |
| 2584 | } |
| 2585 | } |
| 2586 | |
| 2587 | public void flush() { |
| 2588 | synchronized (mLock) { |
| 2589 | cancelAllPendingEventsLocked(); |
Svetoslav | 1487cd5 | 2013-04-15 12:28:42 -0700 | [diff] [blame] | 2590 | if (mSentEventsVerifier != null) { |
| 2591 | mSentEventsVerifier.reset(); |
| 2592 | } |
Svetoslav | c4fccd1 | 2013-04-09 12:58:41 -0700 | [diff] [blame] | 2593 | } |
| 2594 | } |
| 2595 | |
| 2596 | private PendingEvent addPendingEventLocked(KeyEvent event, int policyFlags) { |
| 2597 | final int sequence = event.getSequenceNumber(); |
| 2598 | PendingEvent pendingEvent = obtainPendingEventLocked(event, policyFlags, sequence); |
| 2599 | pendingEvent.next = mPendingEvents; |
| 2600 | mPendingEvents = pendingEvent; |
| 2601 | return pendingEvent; |
| 2602 | } |
| 2603 | |
| 2604 | private PendingEvent removePendingEventLocked(int sequence) { |
| 2605 | PendingEvent previous = null; |
| 2606 | PendingEvent current = mPendingEvents; |
| 2607 | |
| 2608 | while (current != null) { |
| 2609 | if (current.sequence == sequence) { |
| 2610 | if (previous != null) { |
| 2611 | previous.next = current.next; |
| 2612 | } else { |
| 2613 | mPendingEvents = current.next; |
| 2614 | } |
| 2615 | current.next = null; |
| 2616 | return current; |
| 2617 | } |
| 2618 | previous = current; |
| 2619 | current = current.next; |
| 2620 | } |
| 2621 | return null; |
| 2622 | } |
| 2623 | |
| 2624 | private void finishPendingEventLocked(PendingEvent pendingEvent) { |
| 2625 | if (!pendingEvent.handled) { |
| 2626 | sendKeyEventToInputFilter(pendingEvent.event, pendingEvent.policyFlags); |
| 2627 | } |
| 2628 | // Nullify the event since we do not want it to be |
| 2629 | // recycled yet. It will be sent to the input filter. |
| 2630 | pendingEvent.event = null; |
| 2631 | recyclePendingEventLocked(pendingEvent); |
| 2632 | } |
| 2633 | |
| 2634 | private void sendKeyEventToInputFilter(KeyEvent event, int policyFlags) { |
| 2635 | if (DEBUG) { |
| 2636 | Slog.i(LOG_TAG, "Injecting event: " + event); |
| 2637 | } |
| 2638 | if (mSentEventsVerifier != null) { |
| 2639 | mSentEventsVerifier.onKeyEvent(event, 0); |
| 2640 | } |
| 2641 | policyFlags |= WindowManagerPolicy.FLAG_PASS_TO_USER; |
| 2642 | mMainHandler.obtainMessage(MainHandler.MSG_SEND_KEY_EVENT_TO_INPUT_FILTER, |
| 2643 | policyFlags, 0, event).sendToTarget(); |
| 2644 | } |
| 2645 | |
| 2646 | private void cancelAllPendingEventsLocked() { |
| 2647 | while (mPendingEvents != null) { |
| 2648 | PendingEvent pendingEvent = removePendingEventLocked(mPendingEvents.sequence); |
| 2649 | pendingEvent.handled = false; |
| 2650 | mInvocationHandler.removeMessages(InvocationHandler.MSG_ON_KEY_EVENT_TIMEOUT, |
| 2651 | pendingEvent); |
| 2652 | finishPendingEventLocked(pendingEvent); |
| 2653 | } |
| 2654 | } |
| 2655 | } |
| 2656 | } |
| 2657 | |
| 2658 | private static final class PendingEvent { |
| 2659 | PendingEvent next; |
| 2660 | |
| 2661 | KeyEvent event; |
| 2662 | int policyFlags; |
| 2663 | int sequence; |
| 2664 | boolean handled; |
| 2665 | |
| 2666 | public void clear() { |
| 2667 | if (event != null) { |
| 2668 | event.recycle(); |
| 2669 | event = null; |
| 2670 | } |
| 2671 | next = null; |
| 2672 | policyFlags = 0; |
| 2673 | sequence = 0; |
| 2674 | handled = false; |
| 2675 | } |
Svetoslav Ganov | 8643aa0 | 2011-04-20 12:12:33 -0700 | [diff] [blame] | 2676 | } |
| 2677 | |
| 2678 | final class SecurityPolicy { |
Svetoslav Ganov | 4213804 | 2012-03-20 11:51:39 -0700 | [diff] [blame] | 2679 | private static final int VALID_ACTIONS = |
| 2680 | AccessibilityNodeInfo.ACTION_CLICK |
Svetoslav Ganov | 76f287e | 2012-04-23 11:02:36 -0700 | [diff] [blame] | 2681 | | AccessibilityNodeInfo.ACTION_LONG_CLICK |
Svetoslav Ganov | 4213804 | 2012-03-20 11:51:39 -0700 | [diff] [blame] | 2682 | | AccessibilityNodeInfo.ACTION_FOCUS |
| 2683 | | AccessibilityNodeInfo.ACTION_CLEAR_FOCUS |
| 2684 | | AccessibilityNodeInfo.ACTION_SELECT |
| 2685 | | AccessibilityNodeInfo.ACTION_CLEAR_SELECTION |
| 2686 | | AccessibilityNodeInfo.ACTION_ACCESSIBILITY_FOCUS |
Svetoslav Ganov | aa780c1 | 2012-04-19 23:01:39 -0700 | [diff] [blame] | 2687 | | AccessibilityNodeInfo.ACTION_CLEAR_ACCESSIBILITY_FOCUS |
Svetoslav Ganov | 2b435aa | 2012-05-04 17:16:37 -0700 | [diff] [blame] | 2688 | | AccessibilityNodeInfo.ACTION_NEXT_AT_MOVEMENT_GRANULARITY |
| 2689 | | AccessibilityNodeInfo.ACTION_PREVIOUS_AT_MOVEMENT_GRANULARITY |
Svetoslav Ganov | b7ff325 | 2012-04-24 18:40:07 -0700 | [diff] [blame] | 2690 | | AccessibilityNodeInfo.ACTION_NEXT_HTML_ELEMENT |
Svetoslav Ganov | a1dc761 | 2012-05-10 04:14:53 -0700 | [diff] [blame] | 2691 | | AccessibilityNodeInfo.ACTION_PREVIOUS_HTML_ELEMENT |
| 2692 | | AccessibilityNodeInfo.ACTION_SCROLL_FORWARD |
Svetoslav | 7c51284 | 2013-01-30 23:02:08 -0800 | [diff] [blame] | 2693 | | AccessibilityNodeInfo.ACTION_SCROLL_BACKWARD |
| 2694 | | AccessibilityNodeInfo.ACTION_COPY |
| 2695 | | AccessibilityNodeInfo.ACTION_PASTE |
| 2696 | | AccessibilityNodeInfo.ACTION_CUT |
Svetoslav | 3577a28 | 2013-06-06 14:09:10 -0700 | [diff] [blame] | 2697 | | AccessibilityNodeInfo.ACTION_SET_SELECTION |
| 2698 | | AccessibilityNodeInfo.ACTION_EXPAND |
| 2699 | | AccessibilityNodeInfo.ACTION_COLLAPSE |
| 2700 | | AccessibilityNodeInfo.ACTION_DISMISS; |
Svetoslav Ganov | 8643aa0 | 2011-04-20 12:12:33 -0700 | [diff] [blame] | 2701 | |
| 2702 | private static final int RETRIEVAL_ALLOWING_EVENT_TYPES = |
Svetoslav Ganov | 4213804 | 2012-03-20 11:51:39 -0700 | [diff] [blame] | 2703 | AccessibilityEvent.TYPE_VIEW_CLICKED |
| 2704 | | AccessibilityEvent.TYPE_VIEW_FOCUSED |
| 2705 | | AccessibilityEvent.TYPE_VIEW_HOVER_ENTER |
| 2706 | | AccessibilityEvent.TYPE_VIEW_HOVER_EXIT |
| 2707 | | AccessibilityEvent.TYPE_VIEW_LONG_CLICKED |
| 2708 | | AccessibilityEvent.TYPE_VIEW_TEXT_CHANGED |
| 2709 | | AccessibilityEvent.TYPE_WINDOW_STATE_CHANGED |
| 2710 | | AccessibilityEvent.TYPE_VIEW_SELECTED |
Svetoslav Ganov | a015617 | 2011-06-26 17:55:44 -0700 | [diff] [blame] | 2711 | | AccessibilityEvent.TYPE_WINDOW_CONTENT_CHANGED |
| 2712 | | AccessibilityEvent.TYPE_VIEW_TEXT_SELECTION_CHANGED |
Svetoslav Ganov | 4213804 | 2012-03-20 11:51:39 -0700 | [diff] [blame] | 2713 | | AccessibilityEvent.TYPE_VIEW_SCROLLED |
| 2714 | | AccessibilityEvent.TYPE_VIEW_ACCESSIBILITY_FOCUSED |
| 2715 | | AccessibilityEvent.TYPE_VIEW_ACCESSIBILITY_FOCUS_CLEARED; |
Svetoslav Ganov | 8643aa0 | 2011-04-20 12:12:33 -0700 | [diff] [blame] | 2716 | |
Svetoslav Ganov | e15ccb9 | 2012-05-16 15:48:55 -0700 | [diff] [blame] | 2717 | private int mActiveWindowId; |
Svetoslav Ganov | 6ae8a24 | 2012-10-10 13:09:00 -0700 | [diff] [blame] | 2718 | private boolean mTouchInteractionInProgress; |
Svetoslav Ganov | 8643aa0 | 2011-04-20 12:12:33 -0700 | [diff] [blame] | 2719 | |
Svetoslav Ganov | eeee4d2 | 2011-06-10 20:51:30 -0700 | [diff] [blame] | 2720 | private boolean canDispatchAccessibilityEvent(AccessibilityEvent event) { |
Svetoslav Ganov | 58fd9f8 | 2012-10-03 18:10:27 -0700 | [diff] [blame] | 2721 | final int eventType = event.getEventType(); |
| 2722 | switch (eventType) { |
| 2723 | // All events that are for changes in a global window |
| 2724 | // state should *always* be dispatched. |
| 2725 | case AccessibilityEvent.TYPE_WINDOW_STATE_CHANGED: |
| 2726 | case AccessibilityEvent.TYPE_NOTIFICATION_STATE_CHANGED: |
| 2727 | // All events generated by the user touching the |
| 2728 | // screen should *always* be dispatched. |
| 2729 | case AccessibilityEvent.TYPE_TOUCH_EXPLORATION_GESTURE_START: |
| 2730 | case AccessibilityEvent.TYPE_TOUCH_EXPLORATION_GESTURE_END: |
| 2731 | case AccessibilityEvent.TYPE_GESTURE_DETECTION_START: |
| 2732 | case AccessibilityEvent.TYPE_GESTURE_DETECTION_END: |
| 2733 | case AccessibilityEvent.TYPE_TOUCH_INTERACTION_START: |
| 2734 | case AccessibilityEvent.TYPE_TOUCH_INTERACTION_END: |
| 2735 | // These will change the active window, so dispatch. |
| 2736 | case AccessibilityEvent.TYPE_VIEW_HOVER_ENTER: |
| 2737 | case AccessibilityEvent.TYPE_VIEW_HOVER_EXIT: { |
| 2738 | return true; |
| 2739 | } |
| 2740 | // All events for changes in window content should be |
| 2741 | // dispatched *only* if this window is the active one. |
| 2742 | default: |
| 2743 | return event.getWindowId() == mActiveWindowId; |
| 2744 | } |
Svetoslav Ganov | eeee4d2 | 2011-06-10 20:51:30 -0700 | [diff] [blame] | 2745 | } |
| 2746 | |
Svetoslav Ganov | a8afa69 | 2012-09-25 13:03:18 -0700 | [diff] [blame] | 2747 | public void updateEventSourceLocked(AccessibilityEvent event) { |
| 2748 | if ((event.getEventType() & RETRIEVAL_ALLOWING_EVENT_TYPES) == 0) { |
| 2749 | event.setSource(null); |
| 2750 | } |
| 2751 | } |
| 2752 | |
| 2753 | public void updateActiveWindow(int windowId, int eventType) { |
Svetoslav Ganov | e15ccb9 | 2012-05-16 15:48:55 -0700 | [diff] [blame] | 2754 | // The active window is either the window that has input focus or |
| 2755 | // the window that the user is currently touching. If the user is |
| 2756 | // touching a window that does not have input focus as soon as the |
| 2757 | // the user stops touching that window the focused window becomes |
| 2758 | // the active one. |
Svetoslav Ganov | e15ccb9 | 2012-05-16 15:48:55 -0700 | [diff] [blame] | 2759 | switch (eventType) { |
| 2760 | case AccessibilityEvent.TYPE_WINDOW_STATE_CHANGED: { |
| 2761 | if (getFocusedWindowId() == windowId) { |
| 2762 | mActiveWindowId = windowId; |
| 2763 | } |
| 2764 | } break; |
Svetoslav Ganov | f772cba | 2012-10-05 18:49:17 -0700 | [diff] [blame] | 2765 | case AccessibilityEvent.TYPE_VIEW_HOVER_ENTER: { |
Svetoslav Ganov | 6ae8a24 | 2012-10-10 13:09:00 -0700 | [diff] [blame] | 2766 | // Do not allow delayed hover events to confuse us |
| 2767 | // which the active window is. |
| 2768 | if (mTouchInteractionInProgress) { |
| 2769 | mActiveWindowId = windowId; |
| 2770 | } |
Svetoslav Ganov | e15ccb9 | 2012-05-16 15:48:55 -0700 | [diff] [blame] | 2771 | } break; |
Svetoslav Ganov | 4e2a762 | 2011-07-26 20:08:46 -0700 | [diff] [blame] | 2772 | } |
Svetoslav Ganov | 8643aa0 | 2011-04-20 12:12:33 -0700 | [diff] [blame] | 2773 | } |
| 2774 | |
Svetoslav Ganov | 6ae8a24 | 2012-10-10 13:09:00 -0700 | [diff] [blame] | 2775 | public void onTouchInteractionStart() { |
| 2776 | mTouchInteractionInProgress = true; |
| 2777 | } |
| 2778 | |
Svetoslav Ganov | f772cba | 2012-10-05 18:49:17 -0700 | [diff] [blame] | 2779 | public void onTouchInteractionEnd() { |
Svetoslav Ganov | 6ae8a24 | 2012-10-10 13:09:00 -0700 | [diff] [blame] | 2780 | mTouchInteractionInProgress = false; |
Svetoslav Ganov | f772cba | 2012-10-05 18:49:17 -0700 | [diff] [blame] | 2781 | // We want to set the active window to be current immediately |
| 2782 | // after the user has stopped touching the screen since if the |
| 2783 | // user types with the IME he should get a feedback for the |
| 2784 | // letter typed in the text view which is in the input focused |
| 2785 | // window. Note that we always deliver hover accessibility events |
| 2786 | // (they are a result of user touching the screen) so change of |
| 2787 | // the active window before all hover accessibility events from |
| 2788 | // the touched window are delivered is fine. |
| 2789 | mActiveWindowId = getFocusedWindowId(); |
| 2790 | } |
| 2791 | |
Svetoslav Ganov | 8643aa0 | 2011-04-20 12:12:33 -0700 | [diff] [blame] | 2792 | public int getRetrievalAllowingWindowLocked() { |
Svetoslav Ganov | e15ccb9 | 2012-05-16 15:48:55 -0700 | [diff] [blame] | 2793 | return mActiveWindowId; |
Svetoslav Ganov | 8643aa0 | 2011-04-20 12:12:33 -0700 | [diff] [blame] | 2794 | } |
| 2795 | |
| 2796 | public boolean canGetAccessibilityNodeInfoLocked(Service service, int windowId) { |
| 2797 | return canRetrieveWindowContent(service) && isRetrievalAllowingWindow(windowId); |
| 2798 | } |
| 2799 | |
Svetoslav Ganov | b7ff325 | 2012-04-24 18:40:07 -0700 | [diff] [blame] | 2800 | public boolean canPerformActionLocked(Service service, int windowId, int action, |
| 2801 | Bundle arguments) { |
Svetoslav Ganov | 8643aa0 | 2011-04-20 12:12:33 -0700 | [diff] [blame] | 2802 | return canRetrieveWindowContent(service) |
| 2803 | && isRetrievalAllowingWindow(windowId) |
Svetoslav Ganov | afe8cf2 | 2012-04-28 13:26:57 -0700 | [diff] [blame] | 2804 | && isActionPermitted(action); |
Svetoslav Ganov | 8643aa0 | 2011-04-20 12:12:33 -0700 | [diff] [blame] | 2805 | } |
| 2806 | |
| 2807 | public boolean canRetrieveWindowContent(Service service) { |
Svetoslav | 11adf6d | 2013-04-24 14:51:29 -0700 | [diff] [blame] | 2808 | return (service.mAccessibilityServiceInfo.getCapabilities() |
| 2809 | & AccessibilityServiceInfo.CAPABILITY_CAN_RETRIEVE_WINDOW_CONTENT) != 0; |
Svetoslav Ganov | 8643aa0 | 2011-04-20 12:12:33 -0700 | [diff] [blame] | 2810 | } |
| 2811 | |
Svetoslav Ganov | 4a49d9f | 2011-07-17 12:22:08 -0700 | [diff] [blame] | 2812 | public void enforceCanRetrieveWindowContent(Service service) throws RemoteException { |
| 2813 | // This happens due to incorrect registration so make it apparent. |
| 2814 | if (!canRetrieveWindowContent(service)) { |
| 2815 | Slog.e(LOG_TAG, "Accessibility serivce " + service.mComponentName + " does not " + |
| 2816 | "declare android:canRetrieveWindowContent."); |
| 2817 | throw new RemoteException(); |
| 2818 | } |
| 2819 | } |
| 2820 | |
Svetoslav Ganov | 58d37b5 | 2012-09-18 12:04:19 -0700 | [diff] [blame] | 2821 | public int resolveCallingUserIdEnforcingPermissionsLocked(int userId) { |
| 2822 | final int callingUid = Binder.getCallingUid(); |
Svetoslav | d08d7ee | 2013-07-15 10:20:27 -0700 | [diff] [blame] | 2823 | if (callingUid == 0 |
| 2824 | || callingUid == Process.SYSTEM_UID |
Svetoslav Ganov | 58d37b5 | 2012-09-18 12:04:19 -0700 | [diff] [blame] | 2825 | || callingUid == Process.SHELL_UID) { |
| 2826 | return mCurrentUserId; |
| 2827 | } |
| 2828 | final int callingUserId = UserHandle.getUserId(callingUid); |
| 2829 | if (callingUserId == userId) { |
| 2830 | return userId; |
| 2831 | } |
| 2832 | if (!hasPermission(Manifest.permission.INTERACT_ACROSS_USERS) |
| 2833 | && !hasPermission(Manifest.permission.INTERACT_ACROSS_USERS_FULL)) { |
| 2834 | throw new SecurityException("Call from user " + callingUserId + " as user " |
| 2835 | + userId + " without permission INTERACT_ACROSS_USERS or " |
| 2836 | + "INTERACT_ACROSS_USERS_FULL not allowed."); |
| 2837 | } |
| 2838 | if (userId == UserHandle.USER_CURRENT |
| 2839 | || userId == UserHandle.USER_CURRENT_OR_SELF) { |
| 2840 | return mCurrentUserId; |
| 2841 | } |
| 2842 | throw new IllegalArgumentException("Calling user can be changed to only " |
| 2843 | + "UserHandle.USER_CURRENT or UserHandle.USER_CURRENT_OR_SELF."); |
| 2844 | } |
| 2845 | |
| 2846 | public boolean isCallerInteractingAcrossUsers(int userId) { |
| 2847 | final int callingUid = Binder.getCallingUid(); |
Svetoslav Ganov | a8afa69 | 2012-09-25 13:03:18 -0700 | [diff] [blame] | 2848 | return (Binder.getCallingPid() == android.os.Process.myPid() |
Svetoslav Ganov | 58d37b5 | 2012-09-18 12:04:19 -0700 | [diff] [blame] | 2849 | || callingUid == Process.SHELL_UID |
| 2850 | || userId == UserHandle.USER_CURRENT |
| 2851 | || userId == UserHandle.USER_CURRENT_OR_SELF); |
| 2852 | } |
| 2853 | |
Svetoslav Ganov | 8643aa0 | 2011-04-20 12:12:33 -0700 | [diff] [blame] | 2854 | private boolean isRetrievalAllowingWindow(int windowId) { |
Svetoslav Ganov | e15ccb9 | 2012-05-16 15:48:55 -0700 | [diff] [blame] | 2855 | return (mActiveWindowId == windowId); |
Svetoslav Ganov | 8643aa0 | 2011-04-20 12:12:33 -0700 | [diff] [blame] | 2856 | } |
| 2857 | |
| 2858 | private boolean isActionPermitted(int action) { |
| 2859 | return (VALID_ACTIONS & action) != 0; |
| 2860 | } |
| 2861 | |
| 2862 | private void enforceCallingPermission(String permission, String function) { |
| 2863 | if (OWN_PROCESS_ID == Binder.getCallingPid()) { |
| 2864 | return; |
| 2865 | } |
Svetoslav Ganov | 9371a0a | 2012-09-21 18:20:37 -0700 | [diff] [blame] | 2866 | if (!hasPermission(permission)) { |
Svetoslav Ganov | 8643aa0 | 2011-04-20 12:12:33 -0700 | [diff] [blame] | 2867 | throw new SecurityException("You do not have " + permission |
Svetoslav Ganov | 6ce77cd | 2012-11-21 16:35:57 -0800 | [diff] [blame] | 2868 | + " required to call " + function + " from pid=" |
| 2869 | + Binder.getCallingPid() + ", uid=" + Binder.getCallingUid()); |
Svetoslav Ganov | 8643aa0 | 2011-04-20 12:12:33 -0700 | [diff] [blame] | 2870 | } |
| 2871 | } |
Svetoslav Ganov | e15ccb9 | 2012-05-16 15:48:55 -0700 | [diff] [blame] | 2872 | |
Svetoslav Ganov | 58d37b5 | 2012-09-18 12:04:19 -0700 | [diff] [blame] | 2873 | private boolean hasPermission(String permission) { |
| 2874 | return mContext.checkCallingPermission(permission) == PackageManager.PERMISSION_GRANTED; |
| 2875 | } |
| 2876 | |
Svetoslav Ganov | e15ccb9 | 2012-05-16 15:48:55 -0700 | [diff] [blame] | 2877 | private int getFocusedWindowId() { |
Svetoslav Ganov | c9c9a48 | 2012-07-16 08:46:07 -0700 | [diff] [blame] | 2878 | try { |
| 2879 | // We call this only on window focus change or after touch |
| 2880 | // exploration gesture end and the shown windows are not that |
| 2881 | // many, so the linear look up is just fine. |
Svetoslav Ganov | 58d37b5 | 2012-09-18 12:04:19 -0700 | [diff] [blame] | 2882 | IBinder token = mWindowManagerService.getFocusedWindowToken(); |
Svetoslav Ganov | c9c9a48 | 2012-07-16 08:46:07 -0700 | [diff] [blame] | 2883 | if (token != null) { |
Svetoslav Ganov | a8afa69 | 2012-09-25 13:03:18 -0700 | [diff] [blame] | 2884 | synchronized (mLock) { |
| 2885 | int windowId = getFocusedWindowIdLocked(token, mGlobalWindowTokens); |
| 2886 | if (windowId < 0) { |
| 2887 | windowId = getFocusedWindowIdLocked(token, |
| 2888 | getCurrentUserStateLocked().mWindowTokens); |
Svetoslav Ganov | c9c9a48 | 2012-07-16 08:46:07 -0700 | [diff] [blame] | 2889 | } |
Svetoslav Ganov | a8afa69 | 2012-09-25 13:03:18 -0700 | [diff] [blame] | 2890 | return windowId; |
Svetoslav Ganov | e15ccb9 | 2012-05-16 15:48:55 -0700 | [diff] [blame] | 2891 | } |
| 2892 | } |
Svetoslav Ganov | c9c9a48 | 2012-07-16 08:46:07 -0700 | [diff] [blame] | 2893 | } catch (RemoteException re) { |
| 2894 | /* ignore */ |
Svetoslav Ganov | a8afa69 | 2012-09-25 13:03:18 -0700 | [diff] [blame] | 2895 | } |
| 2896 | return -1; |
| 2897 | } |
| 2898 | |
| 2899 | private int getFocusedWindowIdLocked(IBinder token, SparseArray<IBinder> windows) { |
| 2900 | final int windowCount = windows.size(); |
| 2901 | for (int i = 0; i < windowCount; i++) { |
| 2902 | if (windows.valueAt(i) == token) { |
| 2903 | return windows.keyAt(i); |
| 2904 | } |
Svetoslav Ganov | e15ccb9 | 2012-05-16 15:48:55 -0700 | [diff] [blame] | 2905 | } |
| 2906 | return -1; |
| 2907 | } |
Svetoslav Ganov | 8643aa0 | 2011-04-20 12:12:33 -0700 | [diff] [blame] | 2908 | } |
Svetoslav Ganov | 58d37b5 | 2012-09-18 12:04:19 -0700 | [diff] [blame] | 2909 | |
| 2910 | private class UserState { |
| 2911 | public final int mUserId; |
| 2912 | |
Svetoslav | 5fec0c5 | 2013-02-15 12:18:33 -0800 | [diff] [blame] | 2913 | // Non-transient state. |
Svetoslav Ganov | 58d37b5 | 2012-09-18 12:04:19 -0700 | [diff] [blame] | 2914 | |
| 2915 | public final RemoteCallbackList<IAccessibilityManagerClient> mClients = |
| 2916 | new RemoteCallbackList<IAccessibilityManagerClient>(); |
| 2917 | |
Svetoslav | 5fec0c5 | 2013-02-15 12:18:33 -0800 | [diff] [blame] | 2918 | public final SparseArray<AccessibilityConnectionWrapper> mInteractionConnections = |
| 2919 | new SparseArray<AccessibilityConnectionWrapper>(); |
| 2920 | |
| 2921 | public final SparseArray<IBinder> mWindowTokens = new SparseArray<IBinder>(); |
| 2922 | |
| 2923 | // Transient state. |
| 2924 | |
| 2925 | public final CopyOnWriteArrayList<Service> mBoundServices = |
| 2926 | new CopyOnWriteArrayList<Service>(); |
| 2927 | |
Svetoslav Ganov | 58d37b5 | 2012-09-18 12:04:19 -0700 | [diff] [blame] | 2928 | public final Map<ComponentName, Service> mComponentNameToServiceMap = |
| 2929 | new HashMap<ComponentName, Service>(); |
| 2930 | |
| 2931 | public final List<AccessibilityServiceInfo> mInstalledServices = |
| 2932 | new ArrayList<AccessibilityServiceInfo>(); |
| 2933 | |
Svetoslav | 57bf885 | 2013-02-07 19:21:42 -0800 | [diff] [blame] | 2934 | public final Set<ComponentName> mBindingServices = new HashSet<ComponentName>(); |
| 2935 | |
Svetoslav Ganov | 58d37b5 | 2012-09-18 12:04:19 -0700 | [diff] [blame] | 2936 | public final Set<ComponentName> mEnabledServices = new HashSet<ComponentName>(); |
| 2937 | |
Svetoslav Ganov | 447d946 | 2013-02-01 19:46:20 +0000 | [diff] [blame] | 2938 | public final Set<ComponentName> mTouchExplorationGrantedServices = |
| 2939 | new HashSet<ComponentName>(); |
| 2940 | |
Svetoslav Ganov | 58d37b5 | 2012-09-18 12:04:19 -0700 | [diff] [blame] | 2941 | public int mHandledFeedbackTypes = 0; |
| 2942 | |
Svetoslav | 5fec0c5 | 2013-02-15 12:18:33 -0800 | [diff] [blame] | 2943 | public int mLastSentClientState = -1; |
Svetoslav | 57bf885 | 2013-02-07 19:21:42 -0800 | [diff] [blame] | 2944 | |
Svetoslav Ganov | 58d37b5 | 2012-09-18 12:04:19 -0700 | [diff] [blame] | 2945 | public boolean mIsAccessibilityEnabled; |
| 2946 | public boolean mIsTouchExplorationEnabled; |
Svetoslav | 3822896 | 2013-01-29 01:04:35 -0800 | [diff] [blame] | 2947 | public boolean mIsEnhancedWebAccessibilityEnabled; |
Svetoslav Ganov | 58d37b5 | 2012-09-18 12:04:19 -0700 | [diff] [blame] | 2948 | public boolean mIsDisplayMagnificationEnabled; |
Svetoslav | ca523d6 | 2013-04-26 13:11:11 -0700 | [diff] [blame] | 2949 | public boolean mIsFilterKeyEventsEnabled; |
Svetoslav Ganov | 58d37b5 | 2012-09-18 12:04:19 -0700 | [diff] [blame] | 2950 | |
Svetoslav | 57bf885 | 2013-02-07 19:21:42 -0800 | [diff] [blame] | 2951 | private Service mUiAutomationService; |
| 2952 | private IAccessibilityServiceClient mUiAutomationServiceClient; |
| 2953 | |
Svetoslav | 3c55e5c | 2013-02-27 18:24:28 -0800 | [diff] [blame] | 2954 | private IBinder mUiAutomationServiceOwner; |
| 2955 | private final DeathRecipient mUiAutomationSerivceOnwerDeathRecipient = |
| 2956 | new DeathRecipient() { |
| 2957 | @Override |
| 2958 | public void binderDied() { |
| 2959 | mUiAutomationServiceOwner.unlinkToDeath( |
| 2960 | mUiAutomationSerivceOnwerDeathRecipient, 0); |
| 2961 | mUiAutomationServiceOwner = null; |
| 2962 | if (mUiAutomationService != null) { |
| 2963 | mUiAutomationService.binderDied(); |
| 2964 | } |
| 2965 | } |
| 2966 | }; |
| 2967 | |
Svetoslav Ganov | 58d37b5 | 2012-09-18 12:04:19 -0700 | [diff] [blame] | 2968 | public UserState(int userId) { |
| 2969 | mUserId = userId; |
| 2970 | } |
Svetoslav Ganov | 58d37b5 | 2012-09-18 12:04:19 -0700 | [diff] [blame] | 2971 | |
Svetoslav | 57bf885 | 2013-02-07 19:21:42 -0800 | [diff] [blame] | 2972 | public int getClientState() { |
| 2973 | int clientState = 0; |
| 2974 | if (mIsAccessibilityEnabled) { |
| 2975 | clientState |= AccessibilityManager.STATE_FLAG_ACCESSIBILITY_ENABLED; |
| 2976 | } |
| 2977 | // Touch exploration relies on enabled accessibility. |
| 2978 | if (mIsAccessibilityEnabled && mIsTouchExplorationEnabled) { |
| 2979 | clientState |= AccessibilityManager.STATE_FLAG_TOUCH_EXPLORATION_ENABLED; |
| 2980 | } |
| 2981 | return clientState; |
Svetoslav Ganov | 7befb7d | 2012-09-27 16:49:23 -0700 | [diff] [blame] | 2982 | } |
Svetoslav | 5fec0c5 | 2013-02-15 12:18:33 -0800 | [diff] [blame] | 2983 | |
| 2984 | public void onSwitchToAnotherUser() { |
| 2985 | // Clear UI test automation state. |
| 2986 | if (mUiAutomationService != null) { |
| 2987 | mUiAutomationService.binderDied(); |
Svetoslav | 5fec0c5 | 2013-02-15 12:18:33 -0800 | [diff] [blame] | 2988 | } |
| 2989 | |
| 2990 | // Unbind all services. |
| 2991 | unbindAllServicesLocked(this); |
| 2992 | |
| 2993 | // Clear service management state. |
| 2994 | mBoundServices.clear(); |
| 2995 | mBindingServices.clear(); |
| 2996 | |
| 2997 | // Clear event management state. |
| 2998 | mHandledFeedbackTypes = 0; |
| 2999 | mLastSentClientState = -1; |
| 3000 | |
| 3001 | // Clear state persisted in settings. |
| 3002 | mEnabledServices.clear(); |
| 3003 | mTouchExplorationGrantedServices.clear(); |
| 3004 | mIsAccessibilityEnabled = false; |
| 3005 | mIsTouchExplorationEnabled = false; |
| 3006 | mIsEnhancedWebAccessibilityEnabled = false; |
| 3007 | mIsDisplayMagnificationEnabled = false; |
| 3008 | } |
Svetoslav | 3c55e5c | 2013-02-27 18:24:28 -0800 | [diff] [blame] | 3009 | |
| 3010 | public void destroyUiAutomationService() { |
| 3011 | mUiAutomationService = null; |
| 3012 | mUiAutomationServiceClient = null; |
| 3013 | if (mUiAutomationServiceOwner != null) { |
| 3014 | mUiAutomationServiceOwner.unlinkToDeath( |
| 3015 | mUiAutomationSerivceOnwerDeathRecipient, 0); |
| 3016 | mUiAutomationServiceOwner = null; |
| 3017 | } |
| 3018 | } |
Svetoslav Ganov | 7befb7d | 2012-09-27 16:49:23 -0700 | [diff] [blame] | 3019 | } |
| 3020 | |
Svetoslav Ganov | 58d37b5 | 2012-09-18 12:04:19 -0700 | [diff] [blame] | 3021 | private final class AccessibilityContentObserver extends ContentObserver { |
| 3022 | |
| 3023 | private final Uri mAccessibilityEnabledUri = Settings.Secure.getUriFor( |
| 3024 | Settings.Secure.ACCESSIBILITY_ENABLED); |
| 3025 | |
| 3026 | private final Uri mTouchExplorationEnabledUri = Settings.Secure.getUriFor( |
| 3027 | Settings.Secure.TOUCH_EXPLORATION_ENABLED); |
| 3028 | |
| 3029 | private final Uri mDisplayMagnificationEnabledUri = Settings.Secure.getUriFor( |
| 3030 | Settings.Secure.ACCESSIBILITY_DISPLAY_MAGNIFICATION_ENABLED); |
| 3031 | |
| 3032 | private final Uri mEnabledAccessibilityServicesUri = Settings.Secure.getUriFor( |
| 3033 | Settings.Secure.ENABLED_ACCESSIBILITY_SERVICES); |
| 3034 | |
Svetoslav Ganov | 447d946 | 2013-02-01 19:46:20 +0000 | [diff] [blame] | 3035 | private final Uri mTouchExplorationGrantedAccessibilityServicesUri = Settings.Secure |
| 3036 | .getUriFor(Settings.Secure.TOUCH_EXPLORATION_GRANTED_ACCESSIBILITY_SERVICES); |
| 3037 | |
Svetoslav | 57bf885 | 2013-02-07 19:21:42 -0800 | [diff] [blame] | 3038 | private final Uri mEnhancedWebAccessibilityUri = Settings.Secure |
Svetoslav Ganov | 447d946 | 2013-02-01 19:46:20 +0000 | [diff] [blame] | 3039 | .getUriFor(Settings.Secure.ACCESSIBILITY_SCRIPT_INJECTION); |
| 3040 | |
Svetoslav Ganov | 58d37b5 | 2012-09-18 12:04:19 -0700 | [diff] [blame] | 3041 | public AccessibilityContentObserver(Handler handler) { |
| 3042 | super(handler); |
| 3043 | } |
| 3044 | |
| 3045 | public void register(ContentResolver contentResolver) { |
| 3046 | contentResolver.registerContentObserver(mAccessibilityEnabledUri, |
| 3047 | false, this, UserHandle.USER_ALL); |
| 3048 | contentResolver.registerContentObserver(mTouchExplorationEnabledUri, |
| 3049 | false, this, UserHandle.USER_ALL); |
| 3050 | contentResolver.registerContentObserver(mDisplayMagnificationEnabledUri, |
| 3051 | false, this, UserHandle.USER_ALL); |
| 3052 | contentResolver.registerContentObserver(mEnabledAccessibilityServicesUri, |
| 3053 | false, this, UserHandle.USER_ALL); |
Svetoslav Ganov | 447d946 | 2013-02-01 19:46:20 +0000 | [diff] [blame] | 3054 | contentResolver.registerContentObserver( |
| 3055 | mTouchExplorationGrantedAccessibilityServicesUri, |
| 3056 | false, this, UserHandle.USER_ALL); |
Svetoslav | 57bf885 | 2013-02-07 19:21:42 -0800 | [diff] [blame] | 3057 | contentResolver.registerContentObserver(mEnhancedWebAccessibilityUri, |
Svetoslav Ganov | 447d946 | 2013-02-01 19:46:20 +0000 | [diff] [blame] | 3058 | false, this, UserHandle.USER_ALL); |
Svetoslav Ganov | 58d37b5 | 2012-09-18 12:04:19 -0700 | [diff] [blame] | 3059 | } |
| 3060 | |
| 3061 | @Override |
| 3062 | public void onChange(boolean selfChange, Uri uri) { |
| 3063 | if (mAccessibilityEnabledUri.equals(uri)) { |
| 3064 | synchronized (mLock) { |
| 3065 | // We will update when the automation service dies. |
Svetoslav | 57bf885 | 2013-02-07 19:21:42 -0800 | [diff] [blame] | 3066 | UserState userState = getCurrentUserStateLocked(); |
| 3067 | if (userState.mUiAutomationService == null) { |
| 3068 | if (readAccessibilityEnabledSettingLocked(userState)) { |
| 3069 | onUserStateChangedLocked(userState); |
| 3070 | } |
Svetoslav Ganov | 58d37b5 | 2012-09-18 12:04:19 -0700 | [diff] [blame] | 3071 | } |
| 3072 | } |
| 3073 | } else if (mTouchExplorationEnabledUri.equals(uri)) { |
| 3074 | synchronized (mLock) { |
| 3075 | // We will update when the automation service dies. |
Svetoslav | 57bf885 | 2013-02-07 19:21:42 -0800 | [diff] [blame] | 3076 | UserState userState = getCurrentUserStateLocked(); |
| 3077 | if (userState.mUiAutomationService == null) { |
| 3078 | if (readTouchExplorationEnabledSettingLocked(userState)) { |
| 3079 | onUserStateChangedLocked(userState); |
| 3080 | } |
Svetoslav Ganov | 58d37b5 | 2012-09-18 12:04:19 -0700 | [diff] [blame] | 3081 | } |
| 3082 | } |
| 3083 | } else if (mDisplayMagnificationEnabledUri.equals(uri)) { |
| 3084 | synchronized (mLock) { |
| 3085 | // We will update when the automation service dies. |
Svetoslav | 57bf885 | 2013-02-07 19:21:42 -0800 | [diff] [blame] | 3086 | UserState userState = getCurrentUserStateLocked(); |
| 3087 | if (userState.mUiAutomationService == null) { |
| 3088 | if (readDisplayMagnificationEnabledSettingLocked(userState)) { |
| 3089 | onUserStateChangedLocked(userState); |
| 3090 | } |
Svetoslav Ganov | 58d37b5 | 2012-09-18 12:04:19 -0700 | [diff] [blame] | 3091 | } |
| 3092 | } |
| 3093 | } else if (mEnabledAccessibilityServicesUri.equals(uri)) { |
| 3094 | synchronized (mLock) { |
| 3095 | // We will update when the automation service dies. |
Svetoslav | 57bf885 | 2013-02-07 19:21:42 -0800 | [diff] [blame] | 3096 | UserState userState = getCurrentUserStateLocked(); |
| 3097 | if (userState.mUiAutomationService == null) { |
| 3098 | if (readEnabledAccessibilityServicesLocked(userState)) { |
| 3099 | onUserStateChangedLocked(userState); |
| 3100 | } |
Svetoslav Ganov | 58d37b5 | 2012-09-18 12:04:19 -0700 | [diff] [blame] | 3101 | } |
| 3102 | } |
Svetoslav Ganov | 447d946 | 2013-02-01 19:46:20 +0000 | [diff] [blame] | 3103 | } else if (mTouchExplorationGrantedAccessibilityServicesUri.equals(uri)) { |
| 3104 | synchronized (mLock) { |
| 3105 | // We will update when the automation service dies. |
Svetoslav | 57bf885 | 2013-02-07 19:21:42 -0800 | [diff] [blame] | 3106 | UserState userState = getCurrentUserStateLocked(); |
| 3107 | if (userState.mUiAutomationService == null) { |
| 3108 | if (readTouchExplorationGrantedAccessibilityServicesLocked(userState)) { |
| 3109 | onUserStateChangedLocked(userState); |
| 3110 | } |
Svetoslav Ganov | 447d946 | 2013-02-01 19:46:20 +0000 | [diff] [blame] | 3111 | } |
| 3112 | } |
Svetoslav | 57bf885 | 2013-02-07 19:21:42 -0800 | [diff] [blame] | 3113 | } else if (mEnhancedWebAccessibilityUri.equals(uri)) { |
Svetoslav Ganov | 447d946 | 2013-02-01 19:46:20 +0000 | [diff] [blame] | 3114 | synchronized (mLock) { |
| 3115 | // We will update when the automation service dies. |
Svetoslav | 57bf885 | 2013-02-07 19:21:42 -0800 | [diff] [blame] | 3116 | UserState userState = getCurrentUserStateLocked(); |
| 3117 | if (userState.mUiAutomationService == null) { |
| 3118 | if (readEnhancedWebAccessibilityEnabledChangedLocked(userState)) { |
| 3119 | onUserStateChangedLocked(userState); |
| 3120 | } |
Svetoslav Ganov | 447d946 | 2013-02-01 19:46:20 +0000 | [diff] [blame] | 3121 | } |
| 3122 | } |
Svetoslav Ganov | 58d37b5 | 2012-09-18 12:04:19 -0700 | [diff] [blame] | 3123 | } |
| 3124 | } |
| 3125 | } |
svetoslavganov | 75986cf | 2009-05-14 22:28:01 -0700 | [diff] [blame] | 3126 | } |