From 83c994fd85c4ad5a223e82d6ea0050dc00e28f1b Mon Sep 17 00:00:00 2001 From: Amith Yamasani Date: Mon, 1 May 2017 14:29:19 -0700 Subject: [PATCH] Clear calling uid before changing whitelist Avoids security exception for UPDATE_DEVICE_STATS Bug: 37627773 Test: manual Change-Id: I18617d068e7db0813c11b23b281d283908664eae --- .../com/android/server/am/PendingIntentRecord.java | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/services/core/java/com/android/server/am/PendingIntentRecord.java b/services/core/java/com/android/server/am/PendingIntentRecord.java index a580d4bdde5e9..7ba67c5d7ce6a 100644 --- a/services/core/java/com/android/server/am/PendingIntentRecord.java +++ b/services/core/java/com/android/server/am/PendingIntentRecord.java @@ -271,10 +271,15 @@ final class PendingIntentRecord extends IIntentSender.Stub { resolvedType = key.requestResolvedType; } + final int callingUid = Binder.getCallingUid(); + final int callingPid = Binder.getCallingPid(); + + final long origId = Binder.clearCallingIdentity(); + if (whitelistDuration > 0) { StringBuilder tag = new StringBuilder(64); tag.append("pendingintent:"); - UserHandle.formatUid(tag, Binder.getCallingUid()); + UserHandle.formatUid(tag, callingUid); tag.append(":"); if (finalIntent.getAction() != null) { tag.append(finalIntent.getAction()); @@ -283,12 +288,10 @@ final class PendingIntentRecord extends IIntentSender.Stub { } else if (finalIntent.getData() != null) { tag.append(finalIntent.getData()); } - owner.tempWhitelistForPendingIntentLocked(Binder.getCallingPid(), - Binder.getCallingUid(), uid, whitelistDuration, tag.toString()); + owner.tempWhitelistForPendingIntentLocked(callingPid, + callingUid, uid, whitelistDuration, tag.toString()); } - final long origId = Binder.clearCallingIdentity(); - boolean sendFinish = finishedReceiver != null; int userId = key.userId; if (userId == UserHandle.USER_CURRENT) {