"Fix" NPE in PhoneStatusBarPolicy
Callback returns a copy of the list
Makes PrivacyItemController dumpable
Test: atest
Test: adb shell dumpsys activity service com.android.systemui/.SystemUIService Dependency
Fixes: 124234367
Change-Id: I1400ee8294f34b129723bb0f0ce7745dafaf5545
diff --git a/packages/SystemUI/src/com/android/systemui/privacy/PrivacyItem.kt b/packages/SystemUI/src/com/android/systemui/privacy/PrivacyItem.kt
index f7ca51d..a6e48f8 100644
--- a/packages/SystemUI/src/com/android/systemui/privacy/PrivacyItem.kt
+++ b/packages/SystemUI/src/com/android/systemui/privacy/PrivacyItem.kt
@@ -62,4 +62,6 @@
context.packageManager.getApplicationLabel(it) as String
} ?: packageName
}
+
+ override fun toString() = "PrivacyApplication(packageName=$packageName, uid=$uid)"
}
diff --git a/packages/SystemUI/src/com/android/systemui/privacy/PrivacyItemController.kt b/packages/SystemUI/src/com/android/systemui/privacy/PrivacyItemController.kt
index 0f33937..625eacd 100644
--- a/packages/SystemUI/src/com/android/systemui/privacy/PrivacyItemController.kt
+++ b/packages/SystemUI/src/com/android/systemui/privacy/PrivacyItemController.kt
@@ -31,6 +31,9 @@
import com.android.systemui.R
import com.android.systemui.appops.AppOpItem
import com.android.systemui.appops.AppOpsController
+import com.android.systemui.Dumpable
+import java.io.FileDescriptor
+import java.io.PrintWriter
import java.lang.ref.WeakReference
import javax.inject.Inject
import javax.inject.Named
@@ -42,7 +45,7 @@
private val appOpsController: AppOpsController,
@Named(MAIN_HANDLER_NAME) private val uiHandler: Handler,
@Named(BG_HANDLER_NAME) private val bgHandler: Handler
-) {
+) : Dumpable {
companion object {
val OPS = intArrayOf(AppOpsManager.OP_CAMERA,
@@ -56,7 +59,10 @@
const val SYSTEM_UID = 1000
}
- private var privacyList = emptyList<PrivacyItem>()
+ @VisibleForTesting
+ internal var privacyList = emptyList<PrivacyItem>()
+ get() = field.toList() // Provides a shallow copy of the list
+
private val userManager = context.getSystemService(UserManager::class.java)
private var currentUserIds = emptyList<Int>()
private var listening = false
@@ -189,4 +195,22 @@
callback?.privacyChanged(list)
}
}
+
+ override fun dump(fd: FileDescriptor?, pw: PrintWriter?, args: Array<out String>?) {
+ pw?.println("PrivacyItemController state:")
+ pw?.println(" Listening: $listening")
+ pw?.println(" Current user ids: $currentUserIds")
+ pw?.println(" Privacy Items:")
+ privacyList.forEach {
+ pw?.print(" ")
+ pw?.println(it.toString())
+ }
+ pw?.println(" Callbacks:")
+ callbacks.forEach {
+ it.get()?.let {
+ pw?.print(" ")
+ pw?.println(it.toString())
+ }
+ }
+ }
}
\ No newline at end of file
diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/phone/PhoneStatusBarPolicy.java b/packages/SystemUI/src/com/android/systemui/statusbar/phone/PhoneStatusBarPolicy.java
index 2799191..e0c5e59 100644
--- a/packages/SystemUI/src/com/android/systemui/statusbar/phone/PhoneStatusBarPolicy.java
+++ b/packages/SystemUI/src/com/android/systemui/statusbar/phone/PhoneStatusBarPolicy.java
@@ -92,6 +92,8 @@
import com.android.systemui.statusbar.policy.ZenModeController;
import com.android.systemui.util.NotificationChannels;
+import java.io.PrintWriter;
+import java.io.StringWriter;
import java.util.List;
import java.util.Locale;
@@ -793,6 +795,15 @@
boolean showMicrophone = false;
boolean showLocation = false;
for (PrivacyItem item : items) {
+ if (item == null /* b/124234367 */) {
+ if (DEBUG) {
+ Log.e(TAG, "updatePrivacyItems - null item found");
+ StringWriter out = new StringWriter();
+ mPrivacyItemController.dump(null, new PrintWriter(out), null);
+ Log.e(TAG, out.toString());
+ }
+ continue;
+ }
switch (item.getPrivacyType()) {
case TYPE_CAMERA:
showCamera = true;