Clear calling identity before calling createContextAsUser.
In TelecomServiceImpl#callingUidMatchesPackageManagerRecords, we need to
clear the calling identity before invoking mContext.createContextAsUser.
The issue is that createContextUser is trying to enforce NETWORK_STACK
permissions. Clearing the identity beforehand should prevent this issue.
Bug: 278889696
Test: atest TelecomUnitTests
Test: Manual (verified no regressions in basic call flow when calling into TelecomServiceImpl#enforceCallingPackage, which enforces callingUidMatchesPackageManagerRecords under the hood)
Test: Manual (verified invocations to TM#getCallState are not resulting in exceptions when clearing the calling identity
Change-Id: I5d11b564a2afcbf4e3d9371aa5b1fd53189bc118
diff --git a/src/com/android/server/telecom/TelecomServiceImpl.java b/src/com/android/server/telecom/TelecomServiceImpl.java
index f33b185..7d3eeb6 100644
--- a/src/com/android/server/telecom/TelecomServiceImpl.java
+++ b/src/com/android/server/telecom/TelecomServiceImpl.java
@@ -2707,6 +2707,7 @@
int packageUid = -1;
int callingUid = Binder.getCallingUid();
PackageManager pm;
+ long token = Binder.clearCallingIdentity();
try{
pm = mContext.createContextAsUser(
UserHandle.getUserHandleForUid(callingUid), 0).getPackageManager();
@@ -2715,6 +2716,8 @@
Log.i(this, "callingUidMatchesPackageManagerRecords:"
+ " createContextAsUser hit exception=[%s]", e.toString());
return false;
+ } finally {
+ Binder.restoreCallingIdentity(token);
}
if (pm != null) {
try {