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
This commit is contained in:
Derek Jedral
2023-05-01 11:46:20 -07:00
parent cfbdee1159
commit 6241b77464
2 changed files with 11 additions and 1 deletions

View File

@@ -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

View File

@@ -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)