Fix potential null package name
If a client doesn't pass a context, ActivityThread.currentPackageName()
may return null if the client is part of the Android framework. To
ensure logic doesn't break due to a null package name, use
PackageManager.getPackagesForUid() to get a valid package name for the
caller.
Bug: 243457763
Test: Run CHQTS and verify it now passes on a device previously seeing
null package names
Merged-In: Ia706a503f9ca068fc997c0acdcd74ca62a1424be
Change-Id: Ia706a503f9ca068fc997c0acdcd74ca62a1424be
(cherry picked from commit 2b69e2cf52)
This commit is contained in:
@@ -322,6 +322,17 @@ public class ContextHubClientBroker extends IContextHubClient.Stub
|
||||
} else {
|
||||
mPendingIntentRequest = new PendingIntentRequest(pendingIntent, nanoAppId);
|
||||
}
|
||||
|
||||
if (packageName == null) {
|
||||
String[] packages = mContext.getPackageManager().getPackagesForUid(
|
||||
Binder.getCallingUid());
|
||||
if (packages != null && packages.length > 0) {
|
||||
packageName = packages[0];
|
||||
}
|
||||
Log.e(TAG, "createClient: Provided package name null. Using first package name "
|
||||
+ packageName);
|
||||
}
|
||||
|
||||
mPackage = packageName;
|
||||
mAttributionTag = attributionTag;
|
||||
mTransactionManager = transactionManager;
|
||||
|
||||
Reference in New Issue
Block a user