Allow app switches for accessibility services
Set allow app switches so the accessibility service can start activity without delay. Bug: 141873810 TEST: atest AccessibilityServiceConnectionTest Change-Id: I4204c4cf0baa1f66d6d2d73d56a342ae803d24dd
This commit is contained in:
committed by
Alex Huang
parent
7e491e14a3
commit
24ef87d5f1
@@ -98,6 +98,7 @@ import com.android.internal.util.DumpUtils;
|
||||
import com.android.internal.util.IntPair;
|
||||
import com.android.server.LocalServices;
|
||||
import com.android.server.SystemService;
|
||||
import com.android.server.wm.ActivityTaskManagerInternal;
|
||||
import com.android.server.wm.WindowManagerInternal;
|
||||
|
||||
import org.xmlpull.v1.XmlPullParserException;
|
||||
@@ -179,6 +180,8 @@ public class AccessibilityManagerService extends IAccessibilityManager.Stub
|
||||
|
||||
private final AccessibilityDisplayListener mA11yDisplayListener;
|
||||
|
||||
private final ActivityTaskManagerInternal mActivityTaskManagerService;
|
||||
|
||||
private final MainHandler mMainHandler;
|
||||
|
||||
private final SystemActionPerformer mSystemActionPerformer;
|
||||
@@ -260,6 +263,7 @@ public class AccessibilityManagerService extends IAccessibilityManager.Stub
|
||||
mWindowManagerService, this, mSecurityPolicy, this);
|
||||
mA11yDisplayListener = new AccessibilityDisplayListener(mContext, mMainHandler);
|
||||
mSecurityPolicy.setAccessibilityWindowManager(mA11yWindowManager);
|
||||
mActivityTaskManagerService = LocalServices.getService(ActivityTaskManagerInternal.class);
|
||||
|
||||
registerBroadcastReceivers();
|
||||
new AccessibilityContentObserver(mMainHandler).register(
|
||||
@@ -1435,7 +1439,7 @@ public class AccessibilityManagerService extends IAccessibilityManager.Stub
|
||||
service = new AccessibilityServiceConnection(userState, mContext, componentName,
|
||||
installedService, sIdCounter++, mMainHandler, mLock, mSecurityPolicy,
|
||||
this, mWindowManagerService, mSystemActionPerformer,
|
||||
mA11yWindowManager);
|
||||
mA11yWindowManager, mActivityTaskManagerService);
|
||||
} else if (userState.mBoundServices.contains(service)) {
|
||||
continue;
|
||||
}
|
||||
@@ -2411,7 +2415,7 @@ public class AccessibilityManagerService extends IAccessibilityManager.Stub
|
||||
userState, mContext,
|
||||
COMPONENT_NAME, info, sIdCounter++, mMainHandler, mLock, mSecurityPolicy,
|
||||
AccessibilityManagerService.this, mWindowManagerService,
|
||||
mSystemActionPerformer, mA11yWindowManager) {
|
||||
mSystemActionPerformer, mA11yWindowManager, mActivityTaskManagerService) {
|
||||
@Override
|
||||
public boolean supportsFlagForNotImportantViews(AccessibilityServiceInfo info) {
|
||||
return true;
|
||||
|
||||
@@ -35,6 +35,7 @@ import android.provider.Settings;
|
||||
import android.util.Slog;
|
||||
import android.view.Display;
|
||||
|
||||
import com.android.server.wm.ActivityTaskManagerInternal;
|
||||
import com.android.server.wm.WindowManagerInternal;
|
||||
|
||||
import java.lang.ref.WeakReference;
|
||||
@@ -59,6 +60,7 @@ class AccessibilityServiceConnection extends AbstractAccessibilityServiceConnect
|
||||
*/
|
||||
final WeakReference<AccessibilityUserState> mUserStateWeakReference;
|
||||
final Intent mIntent;
|
||||
final ActivityTaskManagerInternal mActivityTaskManagerService;
|
||||
|
||||
private final Handler mMainHandler;
|
||||
|
||||
@@ -67,7 +69,8 @@ class AccessibilityServiceConnection extends AbstractAccessibilityServiceConnect
|
||||
AccessibilityServiceInfo accessibilityServiceInfo, int id, Handler mainHandler,
|
||||
Object lock, AccessibilitySecurityPolicy securityPolicy, SystemSupport systemSupport,
|
||||
WindowManagerInternal windowManagerInternal,
|
||||
SystemActionPerformer systemActionPerfomer, AccessibilityWindowManager awm) {
|
||||
SystemActionPerformer systemActionPerfomer, AccessibilityWindowManager awm,
|
||||
ActivityTaskManagerInternal activityTaskManagerService) {
|
||||
super(context, componentName, accessibilityServiceInfo, id, mainHandler, lock,
|
||||
securityPolicy, systemSupport, windowManagerInternal, systemActionPerfomer, awm);
|
||||
mUserStateWeakReference = new WeakReference<AccessibilityUserState>(userState);
|
||||
@@ -75,6 +78,7 @@ class AccessibilityServiceConnection extends AbstractAccessibilityServiceConnect
|
||||
mMainHandler = mainHandler;
|
||||
mIntent.putExtra(Intent.EXTRA_CLIENT_LABEL,
|
||||
com.android.internal.R.string.accessibility_binding_label);
|
||||
mActivityTaskManagerService = activityTaskManagerService;
|
||||
final long identity = Binder.clearCallingIdentity();
|
||||
try {
|
||||
mIntent.putExtra(Intent.EXTRA_CLIENT_INTENT, mSystemSupport.getPendingIntentActivity(
|
||||
@@ -101,6 +105,9 @@ class AccessibilityServiceConnection extends AbstractAccessibilityServiceConnect
|
||||
} finally {
|
||||
Binder.restoreCallingIdentity(identity);
|
||||
}
|
||||
mActivityTaskManagerService.setAllowAppSwitches(mComponentName.flattenToString(),
|
||||
mAccessibilityServiceInfo.getResolveInfo().serviceInfo.applicationInfo.uid,
|
||||
userState.mUserId);
|
||||
}
|
||||
|
||||
public void unbindLocked() {
|
||||
@@ -109,6 +116,8 @@ class AccessibilityServiceConnection extends AbstractAccessibilityServiceConnect
|
||||
if (userState == null) return;
|
||||
userState.removeServiceLocked(this);
|
||||
mSystemSupport.getMagnificationController().resetAllIfNeeded(mId);
|
||||
mActivityTaskManagerService.setAllowAppSwitches(mComponentName.flattenToString(), -1,
|
||||
userState.mUserId);
|
||||
resetLocked();
|
||||
}
|
||||
|
||||
@@ -207,6 +216,11 @@ class AccessibilityServiceConnection extends AbstractAccessibilityServiceConnect
|
||||
@Override
|
||||
public void onServiceDisconnected(ComponentName componentName) {
|
||||
binderDied();
|
||||
AccessibilityUserState userState = mUserStateWeakReference.get();
|
||||
if (userState != null) {
|
||||
mActivityTaskManagerService.setAllowAppSwitches(mComponentName.flattenToString(), -1,
|
||||
userState.mUserId);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -44,6 +44,7 @@ import android.os.UserHandle;
|
||||
import android.testing.DexmakerShareClassLoaderRule;
|
||||
import android.view.Display;
|
||||
|
||||
import com.android.server.wm.ActivityTaskManagerInternal;
|
||||
import com.android.server.wm.WindowManagerInternal;
|
||||
|
||||
import org.junit.After;
|
||||
@@ -80,6 +81,7 @@ public class AccessibilityServiceConnectionTest {
|
||||
@Mock ResolveInfo mMockResolveInfo;
|
||||
@Mock AccessibilitySecurityPolicy mMockSecurityPolicy;
|
||||
@Mock AccessibilityWindowManager mMockA11yWindowManager;
|
||||
@Mock ActivityTaskManagerInternal mMockActivityTaskManagerInternal;
|
||||
@Mock AbstractAccessibilityServiceConnection.SystemSupport mMockSystemSupport;
|
||||
@Mock WindowManagerInternal mMockWindowManagerInternal;
|
||||
@Mock SystemActionPerformer mMockSystemActionPerformer;
|
||||
@@ -111,7 +113,8 @@ public class AccessibilityServiceConnectionTest {
|
||||
mConnection = new AccessibilityServiceConnection(mMockUserState, mMockContext,
|
||||
COMPONENT_NAME, mMockServiceInfo, SERVICE_ID, mHandler, new Object(),
|
||||
mMockSecurityPolicy, mMockSystemSupport, mMockWindowManagerInternal,
|
||||
mMockSystemActionPerformer, mMockA11yWindowManager);
|
||||
mMockSystemActionPerformer, mMockA11yWindowManager,
|
||||
mMockActivityTaskManagerInternal);
|
||||
when(mMockSecurityPolicy.canPerformGestures(mConnection)).thenReturn(true);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user