Pass fake package name for ROOT_UID in WorkSource.
Apparently, root does not have a package name of its own, but
WorkSource's constructor requires one. We can't use the alternative of
WorkSource(int uid), since that causes an exception when the RIL
attmepts to chain it when acquiring a wakelock. So we simply fake a
"root" package name to be attributed for the work. Since this is not for
apps or normal shell use on user builds, we assume this is acceptable.
The use case here is new TelephonyShellCommand usages that plumb through
to the RIL which are intended to be run as root.
Bug: 210884765
Test: make, call ITelephony methods through shell with adb rooted,
verify no more NPE from getWorkSource
Change-Id: I9f2c5bd51fb6bc7021b182e660502b107ee0e0b0
diff --git a/src/com/android/phone/PhoneInterfaceManager.java b/src/com/android/phone/PhoneInterfaceManager.java
index fdc1f1f..eb1cf77 100755
--- a/src/com/android/phone/PhoneInterfaceManager.java
+++ b/src/com/android/phone/PhoneInterfaceManager.java
@@ -8428,6 +8428,16 @@
private WorkSource getWorkSource(int uid) {
String packageName = mApp.getPackageManager().getNameForUid(uid);
+ if (uid == Process.ROOT_UID && packageName == null) {
+ // Downstream WorkSource attribution inside the RIL requires both a UID and package name
+ // to be set for wakelock tracking, otherwise RIL requests fail with a runtime
+ // exception. ROOT_UID seems not to have a valid package name returned by
+ // PackageManager, so just fake it here to avoid issues when running telephony shell
+ // commands that plumb through the RIL as root, like so:
+ // $ adb root
+ // $ adb shell cmd phone ...
+ packageName = "root";
+ }
return new WorkSource(uid, packageName);
}