OSDN Git Service

Canel all work notification when the profile is turned off
authorRubin Xu <rubinxu@google.com>
Mon, 1 Feb 2016 16:13:45 +0000 (16:13 +0000)
committerRubin Xu <rubinxu@google.com>
Mon, 1 Feb 2016 16:13:45 +0000 (16:13 +0000)
When the work profile is turned off, all work apps are killed and the
profile marked as stopped. Cancel all pending work notifications
immediately in this case, with a new reason.

Bug: 22541941
Change-Id: I97935c3bac3eba1e9c38f7449ebcc182f6c66769

api/current.txt
api/system-current.txt
api/test-current.txt
core/java/android/service/notification/NotificationAssistantService.java
services/core/java/com/android/server/notification/NotificationManagerService.java

index 8e797c6..23b9c12 100644 (file)
@@ -34409,6 +34409,7 @@ package android.service.notification {
     field public static final int REASON_PACKAGE_BANNED = 7; // 0x7
     field public static final int REASON_PACKAGE_CHANGED = 5; // 0x5
     field public static final int REASON_PACKAGE_SUSPENDED = 15; // 0xf
+    field public static final int REASON_PROFILE_TURNED_OFF = 16; // 0x10
     field public static final int REASON_TOPIC_BANNED = 14; // 0xe
     field public static final int REASON_USER_STOPPED = 6; // 0x6
     field public static final java.lang.String SERVICE_INTERFACE = "android.service.notification.NotificationAssistantService";
index 6b64643..7ed7644 100644 (file)
@@ -36589,6 +36589,7 @@ package android.service.notification {
     field public static final int REASON_PACKAGE_BANNED = 7; // 0x7
     field public static final int REASON_PACKAGE_CHANGED = 5; // 0x5
     field public static final int REASON_PACKAGE_SUSPENDED = 15; // 0xf
+    field public static final int REASON_PROFILE_TURNED_OFF = 16; // 0x10
     field public static final int REASON_TOPIC_BANNED = 14; // 0xe
     field public static final int REASON_USER_STOPPED = 6; // 0x6
     field public static final java.lang.String SERVICE_INTERFACE = "android.service.notification.NotificationAssistantService";
index f137102..88d6a1b 100644 (file)
@@ -34424,6 +34424,7 @@ package android.service.notification {
     field public static final int REASON_PACKAGE_BANNED = 7; // 0x7
     field public static final int REASON_PACKAGE_CHANGED = 5; // 0x5
     field public static final int REASON_PACKAGE_SUSPENDED = 15; // 0xf
+    field public static final int REASON_PROFILE_TURNED_OFF = 16; // 0x10
     field public static final int REASON_TOPIC_BANNED = 14; // 0xe
     field public static final int REASON_USER_STOPPED = 6; // 0x6
     field public static final java.lang.String SERVICE_INTERFACE = "android.service.notification.NotificationAssistantService";
index bd41fb5..a56e030 100644 (file)
@@ -101,6 +101,9 @@ public abstract class NotificationAssistantService extends NotificationListenerS
     /** Notification was canceled by the device administrator suspending the package. */
     public static final int REASON_PACKAGE_SUSPENDED = 15;
 
+    /** Notification was canceled by the owning managed profile being turned off. */
+    public static final int REASON_PROFILE_TURNED_OFF = 16;
+
     public class Adjustment {
         int mImportance;
         CharSequence mExplanation;
index b54efcc..8790415 100644 (file)
@@ -30,15 +30,16 @@ import static android.service.notification.NotificationAssistantService.REASON_L
 import static android.service.notification.NotificationAssistantService.REASON_PACKAGE_BANNED;
 import static android.service.notification.NotificationAssistantService.REASON_PACKAGE_CHANGED;
 import static android.service.notification.NotificationAssistantService.REASON_PACKAGE_SUSPENDED;
+import static android.service.notification.NotificationAssistantService.REASON_PROFILE_TURNED_OFF;
 import static android.service.notification.NotificationAssistantService.REASON_TOPIC_BANNED;
 import static android.service.notification.NotificationAssistantService.REASON_USER_STOPPED;
 import static android.service.notification.NotificationListenerService.HINT_HOST_DISABLE_EFFECTS;
-import static android.service.notification.NotificationListenerService.Ranking.IMPORTANCE_HIGH;
 import static android.service.notification.NotificationListenerService.SUPPRESSED_EFFECT_LIGHTS;
 import static android.service.notification.NotificationListenerService.SUPPRESSED_EFFECT_PEEK;
 import static android.service.notification.NotificationListenerService.SUPPRESSED_EFFECT_SCREEN_ON;
 import static android.service.notification.NotificationListenerService.TRIM_FULL;
 import static android.service.notification.NotificationListenerService.TRIM_LIGHT;
+import static android.service.notification.NotificationListenerService.Ranking.IMPORTANCE_HIGH;
 import static org.xmlpull.v1.XmlPullParser.END_DOCUMENT;
 import static org.xmlpull.v1.XmlPullParser.END_TAG;
 import static org.xmlpull.v1.XmlPullParser.START_TAG;
@@ -118,6 +119,7 @@ import android.util.Xml;
 import android.view.accessibility.AccessibilityEvent;
 import android.view.accessibility.AccessibilityManager;
 import android.widget.Toast;
+
 import com.android.internal.R;
 import com.android.internal.statusbar.NotificationVisibility;
 import com.android.internal.util.FastXmlSerializer;
@@ -134,6 +136,7 @@ import com.android.server.vr.VrManagerInternal;
 import com.android.server.vr.VrStateListener;
 
 import libcore.io.IoUtils;
+
 import org.json.JSONArray;
 import org.json.JSONException;
 import org.json.JSONObject;
@@ -787,6 +790,13 @@ public class NotificationManagerService extends SystemService {
                     cancelAllNotificationsInt(MY_UID, MY_PID, null, 0, 0, true, userHandle,
                             REASON_USER_STOPPED, null, null);
                 }
+            } else if (action.equals(Intent.ACTION_MANAGED_PROFILE_AVAILABILITY_CHANGED)) {
+                boolean inQuietMode = intent.getBooleanExtra(Intent.EXTRA_QUIET_MODE, false);
+                int userHandle = intent.getIntExtra(Intent.EXTRA_USER_HANDLE, -1);
+                if (inQuietMode && userHandle >= 0) {
+                    cancelAllNotificationsInt(MY_UID, MY_PID, null, 0, 0, true, userHandle,
+                            REASON_PROFILE_TURNED_OFF, null, null);
+                }
             } else if (action.equals(Intent.ACTION_USER_PRESENT)) {
                 // turn off LED when user passes through lock screen
                 mNotificationLight.turnOff();
@@ -984,6 +994,7 @@ public class NotificationManagerService extends SystemService {
         filter.addAction(Intent.ACTION_USER_SWITCHED);
         filter.addAction(Intent.ACTION_USER_ADDED);
         filter.addAction(Intent.ACTION_USER_REMOVED);
+        filter.addAction(Intent.ACTION_MANAGED_PROFILE_AVAILABILITY_CHANGED);
         getContext().registerReceiver(mIntentReceiver, filter);
 
         IntentFilter pkgFilter = new IntentFilter();