From e2239c9346b9efb8c879c1925d90f70c4eb2405c Mon Sep 17 00:00:00 2001 From: Fyodor Kupolov Date: Tue, 12 Jan 2016 16:46:13 -0800 Subject: [PATCH] Explicitly pass userId to getWindowToken UiAutomationConnection.clearWindowContentFrameStats method currently clears calling identity before calling mAccessibilityManager.getWindowToken. This doesn't work properly when a call is made by a secondary user, because it wouldn't pass a check in getWindowToken. This is now fixed by explicitly passing ID of the calling user. Bug: 26498396 Change-Id: I8f0cdde33e18f04adb1833c6c0d0c329de921018 --- core/java/android/app/UiAutomationConnection.java | 7 +++++-- .../android/view/accessibility/IAccessibilityManager.aidl | 2 +- .../server/accessibility/AccessibilityManagerService.java | 5 ++--- 3 files changed, 8 insertions(+), 6 deletions(-) diff --git a/core/java/android/app/UiAutomationConnection.java b/core/java/android/app/UiAutomationConnection.java index 13e27e29ffbaa..bd10267bc0f5a 100644 --- a/core/java/android/app/UiAutomationConnection.java +++ b/core/java/android/app/UiAutomationConnection.java @@ -28,6 +28,7 @@ import android.os.ParcelFileDescriptor; import android.os.Process; import android.os.RemoteException; import android.os.ServiceManager; +import android.os.UserHandle; import android.view.IWindowManager; import android.view.InputEvent; import android.view.SurfaceControl; @@ -167,9 +168,10 @@ public final class UiAutomationConnection extends IUiAutomationConnection.Stub { throwIfShutdownLocked(); throwIfNotConnectedLocked(); } + int callingUserId = UserHandle.getCallingUserId(); final long identity = Binder.clearCallingIdentity(); try { - IBinder token = mAccessibilityManager.getWindowToken(windowId); + IBinder token = mAccessibilityManager.getWindowToken(windowId, callingUserId); if (token == null) { return false; } @@ -186,9 +188,10 @@ public final class UiAutomationConnection extends IUiAutomationConnection.Stub { throwIfShutdownLocked(); throwIfNotConnectedLocked(); } + int callingUserId = UserHandle.getCallingUserId(); final long identity = Binder.clearCallingIdentity(); try { - IBinder token = mAccessibilityManager.getWindowToken(windowId); + IBinder token = mAccessibilityManager.getWindowToken(windowId, callingUserId); if (token == null) { return null; } diff --git a/core/java/android/view/accessibility/IAccessibilityManager.aidl b/core/java/android/view/accessibility/IAccessibilityManager.aidl index b6570cc374679..9e7905759f2d5 100644 --- a/core/java/android/view/accessibility/IAccessibilityManager.aidl +++ b/core/java/android/view/accessibility/IAccessibilityManager.aidl @@ -58,5 +58,5 @@ interface IAccessibilityManager { void temporaryEnableAccessibilityStateUntilKeyguardRemoved(in ComponentName service, boolean touchExplorationEnabled); - IBinder getWindowToken(int windowId); + IBinder getWindowToken(int windowId, int userId); } diff --git a/services/accessibility/java/com/android/server/accessibility/AccessibilityManagerService.java b/services/accessibility/java/com/android/server/accessibility/AccessibilityManagerService.java index 39d59525b5228..28aeef7c6a2f0 100644 --- a/services/accessibility/java/com/android/server/accessibility/AccessibilityManagerService.java +++ b/services/accessibility/java/com/android/server/accessibility/AccessibilityManagerService.java @@ -715,7 +715,7 @@ public class AccessibilityManagerService extends IAccessibilityManager.Stub { } @Override - public IBinder getWindowToken(int windowId) { + public IBinder getWindowToken(int windowId, int userId) { mSecurityPolicy.enforceCallingPermission( Manifest.permission.RETRIEVE_WINDOW_TOKEN, GET_WINDOW_TOKEN); @@ -724,8 +724,7 @@ public class AccessibilityManagerService extends IAccessibilityManager.Stub { // share the accessibility state of the parent. The call below // performs the current profile parent resolution. final int resolvedUserId = mSecurityPolicy - .resolveCallingUserIdEnforcingPermissionsLocked( - UserHandle.getCallingUserId()); + .resolveCallingUserIdEnforcingPermissionsLocked(userId); if (resolvedUserId != mCurrentUserId) { return null; }