Essential packages' notifications can no longer be silenced.

Particularly useful for Dialer, whose incoming call
notifications are basically useless if you accidentally mute
them.

Test: manual. With config_nonBlockableNotificationPackages
      set to include com.android.dialer, receive or miss a
      call and longpress the notification. No radio buttons
      should be available.
Bug: 31360343
Change-Id: I6b8fa374fb8e811ec6922acbf222f23f18775a61
diff --git a/packages/SystemUI/res/layout/notification_guts.xml b/packages/SystemUI/res/layout/notification_guts.xml
index e84ed23..17bade4 100644
--- a/packages/SystemUI/res/layout/notification_guts.xml
+++ b/packages/SystemUI/res/layout/notification_guts.xml
@@ -91,6 +91,16 @@
                 style="@style/TextAppearance.NotificationGuts.Radio"
                 android:buttonTint="@color/notification_guts_buttons" />
     </RadioGroup>
+    <!-- When neither blocking or silencing is available -->
+    <TextView
+        android:id="@+id/cant_silence_or_block"
+        android:layout_width="match_parent"
+        android:layout_height="48dp"
+        android:gravity="center_vertical"
+        style="@style/TextAppearance.NotificationGuts.Radio"
+        android:text="@string/cant_silence_or_block"
+        android:visibility="gone"
+        />
     <!-- Importance slider -->
     <LinearLayout
             android:id="@+id/importance_slider"
diff --git a/packages/SystemUI/res/values/strings.xml b/packages/SystemUI/res/values/strings.xml
index d13039e..2ea475a 100644
--- a/packages/SystemUI/res/values/strings.xml
+++ b/packages/SystemUI/res/values/strings.xml
@@ -1666,7 +1666,10 @@
     <!-- accessibility label for button to edit quick settings [CHAR LIMIT=NONE] -->
     <string name="accessibility_quick_settings_edit">Edit order of settings.</string>
 
-    <!-- accessibility label for paging indicator in quick settings [CHAR LIMITi=NONE] -->
+    <!-- accessibility label for paging indicator in quick settings [CHAR LIMIT=NONE] -->
     <string name="accessibility_quick_settings_page">Page <xliff:g name="current_page" example="1">%1$d</xliff:g> of <xliff:g name="num_pages" example="2">%2$d</xliff:g></string>
 
+    <!-- Label that replaces other notification controls when the notification is from the system
+         and cannot be silenced (see @string/show_silently) or blocked (see @string/block) -->
+    <string name="cant_silence_or_block">Notifications can\'t be silenced or blocked</string>
 </resources>
diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/BaseStatusBar.java b/packages/SystemUI/src/com/android/systemui/statusbar/BaseStatusBar.java
index 98957dd..abe3b7e 100644
--- a/packages/SystemUI/src/com/android/systemui/statusbar/BaseStatusBar.java
+++ b/packages/SystemUI/src/com/android/systemui/statusbar/BaseStatusBar.java
@@ -829,7 +829,7 @@
             Slog.e(TAG, "Failed to register VR mode state listener: " + e);
         }
 
-        mNonBlockablePkgs = new HashSet<String>();
+        mNonBlockablePkgs = new ArraySet<String>();
         Collections.addAll(mNonBlockablePkgs, mContext.getResources().getStringArray(
                 com.android.internal.R.array.config_nonBlockableNotificationPackages));
     }
diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/NotificationGuts.java b/packages/SystemUI/src/com/android/systemui/statusbar/NotificationGuts.java
index 62d730a..c850a25 100644
--- a/packages/SystemUI/src/com/android/systemui/statusbar/NotificationGuts.java
+++ b/packages/SystemUI/src/com/android/systemui/statusbar/NotificationGuts.java
@@ -184,28 +184,38 @@
                     mINotificationManager.getImportance(sbn.getPackageName(), sbn.getUid());
         } catch (RemoteException e) {}
         mNotificationImportance = importance;
-        boolean nonBlockable = false;
-        try {
-            final PackageInfo info =
-                    pm.getPackageInfo(sbn.getPackageName(), PackageManager.GET_SIGNATURES);
-            nonBlockable = Utils.isSystemPackage(getResources(), pm, info);
-        } catch (PackageManager.NameNotFoundException e) {
-            // unlikely.
-        }
-        if (nonBlockablePkgs != null) {
-            nonBlockable |= nonBlockablePkgs.contains(sbn.getPackageName());
-        }
 
         final View importanceSlider = findViewById(R.id.importance_slider);
         final View importanceButtons = findViewById(R.id.importance_buttons);
-        if (mShowSlider) {
-            bindSlider(importanceSlider, nonBlockable);
-            importanceSlider.setVisibility(View.VISIBLE);
+        final View cantTouchThis = findViewById(R.id.cant_silence_or_block);
+
+        final boolean essentialPackage =
+                (nonBlockablePkgs != null && nonBlockablePkgs.contains(sbn.getPackageName()));
+        if (essentialPackage) {
             importanceButtons.setVisibility(View.GONE);
-        } else {
-            bindToggles(importanceButtons, mStartingUserImportance, nonBlockable);
-            importanceButtons.setVisibility(View.VISIBLE);
             importanceSlider.setVisibility(View.GONE);
+            cantTouchThis.setVisibility(View.VISIBLE);
+        } else {
+            cantTouchThis.setVisibility(View.GONE);
+
+            boolean nonBlockable = false;
+            try {
+                final PackageInfo info =
+                        pm.getPackageInfo(sbn.getPackageName(), PackageManager.GET_SIGNATURES);
+                nonBlockable = Utils.isSystemPackage(getResources(), pm, info);
+            } catch (PackageManager.NameNotFoundException e) {
+                // unlikely.
+            }
+
+            if (mShowSlider) {
+                bindSlider(importanceSlider, nonBlockable);
+                importanceSlider.setVisibility(View.VISIBLE);
+                importanceButtons.setVisibility(View.GONE);
+            } else {
+                bindToggles(importanceButtons, mStartingUserImportance, nonBlockable);
+                importanceButtons.setVisibility(View.VISIBLE);
+                importanceSlider.setVisibility(View.GONE);
+            }
         }
     }