Wait to unlock before changing notification importance

Test: runtest systemui
Change-Id: I66614de96e0a5c725ac6f6e7b76f64b39326ba6b
Fixes: 36264464
diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/NotificationInfo.java b/packages/SystemUI/src/com/android/systemui/statusbar/NotificationInfo.java
index 0398f7b..21a0dc9 100644
--- a/packages/SystemUI/src/com/android/systemui/statusbar/NotificationInfo.java
+++ b/packages/SystemUI/src/com/android/systemui/statusbar/NotificationInfo.java
@@ -76,6 +76,7 @@
     private TextView mNumChannelsView;
     private View mChannelDisabledView;
     private Switch mChannelEnabledSwitch;
+    private CheckSaveListener mCheckSaveListener;
 
     private NotificationGuts mGutsContainer;
 
@@ -83,6 +84,13 @@
         super(context, attrs);
     }
 
+    // Specify a CheckSaveListener to override when/if the user's changes are committed.
+    public interface CheckSaveListener {
+        // Invoked when importance has changed and the NotificationInfo wants to try to save it.
+        // Listener should run saveImportance unless the change should be canceled.
+        void checkSave(Runnable saveImportance);
+    }
+
     public interface OnSettingsClickListener {
         void onClick(View v, NotificationChannel channel, int appUid);
     }
@@ -92,11 +100,14 @@
             final String pkg,
             final List<NotificationChannel> notificationChannels,
             OnSettingsClickListener onSettingsClick,
-            OnClickListener onDoneClick, final Set<String> nonBlockablePkgs)
+            OnClickListener onDoneClick,
+            CheckSaveListener checkSaveListener,
+            final Set<String> nonBlockablePkgs)
             throws RemoteException {
         mINotificationManager = iNotificationManager;
         mPkg = pkg;
         mNotificationChannels = notificationChannels;
+        mCheckSaveListener = checkSaveListener;
         boolean isSingleDefaultChannel = false;
         if (mNotificationChannels.isEmpty()) {
             throw new IllegalArgumentException("bindNotification requires at least one channel");
@@ -238,7 +249,7 @@
         doneButton.setOnClickListener(onDoneClick);
     }
 
-    public boolean hasImportanceChanged() {
+    private boolean hasImportanceChanged() {
         return mSingleNotificationChannel != null &&
                 mStartingUserImportance != getSelectedImportance();
     }
@@ -316,8 +327,12 @@
 
     @Override
     public boolean handleCloseControls(boolean save) {
-        if (save) {
-            saveImportance();
+        if (save && hasImportanceChanged()) {
+            if (mCheckSaveListener != null) {
+                mCheckSaveListener.checkSave(() -> { saveImportance(); });
+            } else {
+                saveImportance();
+            }
         }
         return false;
     }