OSDN Git Service

Do not allow draw on top for App notification settings
[android-x86/packages-apps-Settings.git] / src / com / android / settings / notification / AppNotificationSettings.java
index c028298..bbfbe5e 100644 (file)
 
 package com.android.settings.notification;
 
+import static android.view.WindowManager.LayoutParams.PRIVATE_FLAG_HIDE_NON_SYSTEM_OVERLAY_WINDOWS;
+
 import android.app.NotificationChannel;
 import android.app.NotificationChannelGroup;
 import android.content.Context;
 import android.os.AsyncTask;
+import android.os.Bundle;
 import android.support.v14.preference.SwitchPreference;
 import android.support.v7.preference.Preference;
 import android.support.v7.preference.PreferenceCategory;
 import android.support.v7.preference.PreferenceGroup;
+import android.support.v7.preference.PreferenceScreen;
 import android.text.TextUtils;
 import android.util.Log;
+import android.view.Window;
+import android.view.WindowManager;
 
 import com.android.internal.logging.nano.MetricsProto.MetricsEvent;
 import com.android.internal.widget.LockPatternUtils;
@@ -45,6 +51,9 @@ public class AppNotificationSettings extends NotificationSettingsBase {
     private static final boolean DEBUG = Log.isLoggable(TAG, Log.DEBUG);
 
     private static String KEY_GENERAL_CATEGORY = "categories";
+    private static String KEY_ADVANCED_CATEGORY = "app_advanced";
+    private static String KEY_BADGE = "badge";
+    private static String KEY_APP_LINK = "app_link";
 
     private List<NotificationChannelGroup> mChannelGroupList;
 
@@ -54,24 +63,38 @@ public class AppNotificationSettings extends NotificationSettingsBase {
     }
 
     @Override
+    public void onCreate(Bundle savedInstanceState) {
+        super.onCreate(savedInstanceState);
+        final PreferenceScreen screen = getPreferenceScreen();
+        if (mShowLegacyChannelConfig && screen != null) {
+            // if showing legacy settings, pull advanced settings out of the advanced category
+            Preference badge = findPreference(KEY_BADGE);
+            Preference appLink = findPreference(KEY_APP_LINK);
+            removePreference(KEY_ADVANCED_CATEGORY);
+            if (badge != null) {
+                screen.addPreference(badge);
+
+            }
+            if (appLink != null) {
+                screen.addPreference(appLink);
+            }
+        }
+    }
+
+    @Override
     public void onResume() {
         super.onResume();
 
+        getActivity().getWindow().addPrivateFlags(PRIVATE_FLAG_HIDE_NON_SYSTEM_OVERLAY_WINDOWS);
+        android.util.EventLog.writeEvent(0x534e4554, "119115683", -1, "");
+
         if (mUid < 0 || TextUtils.isEmpty(mPkg) || mPkgInfo == null) {
             Log.w(TAG, "Missing package or uid or packageinfo");
             finish();
             return;
         }
 
-        if (getPreferenceScreen() != null) {
-            getPreferenceScreen().removeAll();
-            mDynamicPreferences.clear();
-        }
-
-        if (mShowLegacyChannelConfig) {
-            addPreferencesFromResource(R.xml.channel_notification_settings);
-        } else {
-            addPreferencesFromResource(R.xml.app_notification_settings);
+        if (!mShowLegacyChannelConfig) {
             // Load channel settings
             new AsyncTask<Void, Void, Void>() {
                 @Override
@@ -90,7 +113,6 @@ public class AppNotificationSettings extends NotificationSettingsBase {
                 }
             }.execute();
         }
-        getPreferenceScreen().setOrderingAsAdded(true);
 
         for (NotificationPreferenceController controller : mControllers) {
             controller.onResume(mAppRow, mChannel, mChannelGroup, mSuspendedAppsAdmin);
@@ -100,13 +122,22 @@ public class AppNotificationSettings extends NotificationSettingsBase {
     }
 
     @Override
+    public void onPause() {
+        super.onPause();
+        final Window window = getActivity().getWindow();
+        final WindowManager.LayoutParams attrs = window.getAttributes();
+        attrs.privateFlags &= ~PRIVATE_FLAG_HIDE_NON_SYSTEM_OVERLAY_WINDOWS;
+        window.setAttributes(attrs);
+    }
+
+    @Override
     protected String getLogTag() {
         return TAG;
     }
 
     @Override
     protected int getPreferenceScreenResId() {
-        return R.xml.notification_settings;
+        return R.xml.app_notification_settings;
     }
 
     @Override
@@ -125,7 +156,7 @@ public class AppNotificationSettings extends NotificationSettingsBase {
         mControllers.add(new VibrationPreferenceController(context, mBackend));
         mControllers.add(new VisibilityPreferenceController(context, new LockPatternUtils(context),
                 mBackend));
-        mControllers.add(new DndPreferenceController(context, getLifecycle(), mBackend));
+        mControllers.add(new DndPreferenceController(context, mBackend));
         mControllers.add(new AppLinkPreferenceController(context));
         mControllers.add(new DescriptionPreferenceController(context));
         mControllers.add(new NotificationsOffPreferenceController(context));
@@ -135,13 +166,10 @@ public class AppNotificationSettings extends NotificationSettingsBase {
 
     private void populateList() {
         if (!mDynamicPreferences.isEmpty()) {
-            // If there's anything in mChannelGroups, we've called populateChannelList twice.
-            // Clear out existing channels and log.
-            Log.w(TAG, "Notification channel group posted twice to settings - old size " +
-                    mDynamicPreferences.size() + ", new size " + mChannelGroupList.size());
             for (Preference p : mDynamicPreferences) {
                 getPreferenceScreen().removePreference(p);
             }
+            mDynamicPreferences.clear();
         }
         if (mChannelGroupList.isEmpty()) {
             PreferenceCategory groupCategory = new PreferenceCategory(getPrefContext());