Using a common class for observing secure settings

Bug: 117519297
Change-Id: Ie9d948130aea50bf10c9fc625fdb16f4cfc4712e
diff --git a/src/com/android/launcher3/LauncherAppState.java b/src/com/android/launcher3/LauncherAppState.java
index b02182c..6bf5812 100644
--- a/src/com/android/launcher3/LauncherAppState.java
+++ b/src/com/android/launcher3/LauncherAppState.java
@@ -16,7 +16,7 @@
 
 package com.android.launcher3;
 
-import static com.android.launcher3.SettingsActivity.NOTIFICATION_BADGING;
+import static com.android.launcher3.util.SecureSettingsObserver.newNotificationSettingsObserver;
 
 import android.content.ComponentName;
 import android.content.ContentProviderClient;
@@ -33,7 +33,7 @@
 import com.android.launcher3.notification.NotificationListener;
 import com.android.launcher3.util.MainThreadInitializedObject;
 import com.android.launcher3.util.Preconditions;
-import com.android.launcher3.util.SettingsObserver;
+import com.android.launcher3.util.SecureSettingsObserver;
 
 public class LauncherAppState {
 
@@ -48,7 +48,7 @@
     private final IconCache mIconCache;
     private final WidgetPreviewLoader mWidgetCache;
     private final InvariantDeviceProfile mInvariantDeviceProfile;
-    private final SettingsObserver mNotificationBadgingObserver;
+    private final SecureSettingsObserver mNotificationBadgingObserver;
 
     public static LauncherAppState getInstance(final Context context) {
         return INSTANCE.get(context);
@@ -99,17 +99,17 @@
             mNotificationBadgingObserver = null;
         } else {
             // Register an observer to rebind the notification listener when badging is re-enabled.
-            mNotificationBadgingObserver = new SettingsObserver.Secure(
-                    mContext.getContentResolver()) {
-                @Override
-                public void onSettingChanged(boolean isNotificationBadgingEnabled) {
-                    if (isNotificationBadgingEnabled) {
-                        NotificationListener.requestRebind(new ComponentName(
-                                mContext, NotificationListener.class));
-                    }
-                }
-            };
-            mNotificationBadgingObserver.register(NOTIFICATION_BADGING);
+            mNotificationBadgingObserver =
+                    newNotificationSettingsObserver(mContext, this::onNotificationSettingsChanged);
+            mNotificationBadgingObserver.register();
+            mNotificationBadgingObserver.dispatchOnChange();
+        }
+    }
+
+    protected void onNotificationSettingsChanged(boolean isNotificationBadgingEnabled) {
+        if (isNotificationBadgingEnabled) {
+            NotificationListener.requestRebind(new ComponentName(
+                    mContext, NotificationListener.class));
         }
     }