From 6241b77464a11856a7107419d37484b242a1b07c Mon Sep 17 00:00:00 2001 From: Derek Jedral Date: Mon, 1 May 2023 11:46:20 -0700 Subject: Report correct userId in onUserMayRequestUnlock. obtainMessage with two arguments will set the user id as the object, but this value is retrieved as msg.arg1. We need to call obtainMessage with three arguments instead to make the second argument the userId. Thir third argument will be ignored by the receiver. Test: atest TrustTests:UserUnlockRequestTest Bug: b/278323473 Change-Id: Ie08c643f9fb5fbbe7f107a1f267074805ddc500b --- .../java/com/android/server/trust/TrustManagerService.java | 2 +- .../TrustTests/src/android/trust/test/UserUnlockRequestTest.kt | 10 ++++++++++ 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/services/core/java/com/android/server/trust/TrustManagerService.java b/services/core/java/com/android/server/trust/TrustManagerService.java index 8786005d519f..87b42014d5b4 100644 --- a/services/core/java/com/android/server/trust/TrustManagerService.java +++ b/services/core/java/com/android/server/trust/TrustManagerService.java @@ -1504,7 +1504,7 @@ public class TrustManagerService extends SystemService { @Override public void reportUserMayRequestUnlock(int userId) throws RemoteException { enforceReportPermission(); - mHandler.obtainMessage(MSG_USER_MAY_REQUEST_UNLOCK, userId).sendToTarget(); + mHandler.obtainMessage(MSG_USER_MAY_REQUEST_UNLOCK, userId, /*arg2=*/ 0).sendToTarget(); } @Override diff --git a/tests/TrustTests/src/android/trust/test/UserUnlockRequestTest.kt b/tests/TrustTests/src/android/trust/test/UserUnlockRequestTest.kt index 6a8752abfde7..501b9d33871a 100644 --- a/tests/TrustTests/src/android/trust/test/UserUnlockRequestTest.kt +++ b/tests/TrustTests/src/android/trust/test/UserUnlockRequestTest.kt @@ -79,6 +79,16 @@ class UserUnlockRequestTest { .isEqualTo(oldCount + 1) } + @Test + fun reportUserMayRequestUnlock_differentUserId_doesNotPropagateToAgent() { + val oldCount = trustAgentRule.agent.onUserMayRequestUnlockCallCount + trustManager.reportUserMayRequestUnlock(userId + 1) + await() + + assertThat(trustAgentRule.agent.onUserMayRequestUnlockCallCount) + .isEqualTo(oldCount) + } + companion object { private const val TAG = "UserUnlockRequestTest" private fun await() = Thread.sleep(250) -- cgit v1.2.3-59-g8ed1b