Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 7eadc1bf authored by Rubin Xu's avatar Rubin Xu
Browse files

Canel all work notification when the profile is turned off

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
parent 15d21b3a
Loading
Loading
Loading
Loading
+1 −0
Original line number Original line Diff line number Diff line
@@ -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_BANNED = 7; // 0x7
    field public static final int REASON_PACKAGE_CHANGED = 5; // 0x5
    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_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_TOPIC_BANNED = 14; // 0xe
    field public static final int REASON_USER_STOPPED = 6; // 0x6
    field public static final int REASON_USER_STOPPED = 6; // 0x6
    field public static final java.lang.String SERVICE_INTERFACE = "android.service.notification.NotificationAssistantService";
    field public static final java.lang.String SERVICE_INTERFACE = "android.service.notification.NotificationAssistantService";
+1 −0
Original line number Original line Diff line number Diff line
@@ -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_BANNED = 7; // 0x7
    field public static final int REASON_PACKAGE_CHANGED = 5; // 0x5
    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_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_TOPIC_BANNED = 14; // 0xe
    field public static final int REASON_USER_STOPPED = 6; // 0x6
    field public static final int REASON_USER_STOPPED = 6; // 0x6
    field public static final java.lang.String SERVICE_INTERFACE = "android.service.notification.NotificationAssistantService";
    field public static final java.lang.String SERVICE_INTERFACE = "android.service.notification.NotificationAssistantService";
+1 −0
Original line number Original line Diff line number Diff line
@@ -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_BANNED = 7; // 0x7
    field public static final int REASON_PACKAGE_CHANGED = 5; // 0x5
    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_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_TOPIC_BANNED = 14; // 0xe
    field public static final int REASON_USER_STOPPED = 6; // 0x6
    field public static final int REASON_USER_STOPPED = 6; // 0x6
    field public static final java.lang.String SERVICE_INTERFACE = "android.service.notification.NotificationAssistantService";
    field public static final java.lang.String SERVICE_INTERFACE = "android.service.notification.NotificationAssistantService";
+3 −0
Original line number Original line Diff line number Diff line
@@ -101,6 +101,9 @@ public abstract class NotificationAssistantService extends NotificationListenerS
    /** Notification was canceled by the device administrator suspending the package. */
    /** Notification was canceled by the device administrator suspending the package. */
    public static final int REASON_PACKAGE_SUSPENDED = 15;
    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 {
    public class Adjustment {
        int mImportance;
        int mImportance;
        CharSequence mExplanation;
        CharSequence mExplanation;
+12 −1
Original line number Original line Diff line number Diff line
@@ -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_BANNED;
import static android.service.notification.NotificationAssistantService.REASON_PACKAGE_CHANGED;
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_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_TOPIC_BANNED;
import static android.service.notification.NotificationAssistantService.REASON_USER_STOPPED;
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.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_LIGHTS;
import static android.service.notification.NotificationListenerService.SUPPRESSED_EFFECT_PEEK;
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.SUPPRESSED_EFFECT_SCREEN_ON;
import static android.service.notification.NotificationListenerService.TRIM_FULL;
import static android.service.notification.NotificationListenerService.TRIM_FULL;
import static android.service.notification.NotificationListenerService.TRIM_LIGHT;
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_DOCUMENT;
import static org.xmlpull.v1.XmlPullParser.END_TAG;
import static org.xmlpull.v1.XmlPullParser.END_TAG;
import static org.xmlpull.v1.XmlPullParser.START_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.AccessibilityEvent;
import android.view.accessibility.AccessibilityManager;
import android.view.accessibility.AccessibilityManager;
import android.widget.Toast;
import android.widget.Toast;

import com.android.internal.R;
import com.android.internal.R;
import com.android.internal.statusbar.NotificationVisibility;
import com.android.internal.statusbar.NotificationVisibility;
import com.android.internal.util.FastXmlSerializer;
import com.android.internal.util.FastXmlSerializer;
@@ -134,6 +136,7 @@ import com.android.server.vr.VrManagerInternal;
import com.android.server.vr.VrStateListener;
import com.android.server.vr.VrStateListener;


import libcore.io.IoUtils;
import libcore.io.IoUtils;

import org.json.JSONArray;
import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONException;
import org.json.JSONObject;
import org.json.JSONObject;
@@ -787,6 +790,13 @@ public class NotificationManagerService extends SystemService {
                    cancelAllNotificationsInt(MY_UID, MY_PID, null, 0, 0, true, userHandle,
                    cancelAllNotificationsInt(MY_UID, MY_PID, null, 0, 0, true, userHandle,
                            REASON_USER_STOPPED, null, null);
                            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)) {
            } else if (action.equals(Intent.ACTION_USER_PRESENT)) {
                // turn off LED when user passes through lock screen
                // turn off LED when user passes through lock screen
                mNotificationLight.turnOff();
                mNotificationLight.turnOff();
@@ -984,6 +994,7 @@ public class NotificationManagerService extends SystemService {
        filter.addAction(Intent.ACTION_USER_SWITCHED);
        filter.addAction(Intent.ACTION_USER_SWITCHED);
        filter.addAction(Intent.ACTION_USER_ADDED);
        filter.addAction(Intent.ACTION_USER_ADDED);
        filter.addAction(Intent.ACTION_USER_REMOVED);
        filter.addAction(Intent.ACTION_USER_REMOVED);
        filter.addAction(Intent.ACTION_MANAGED_PROFILE_AVAILABILITY_CHANGED);
        getContext().registerReceiver(mIntentReceiver, filter);
        getContext().registerReceiver(mIntentReceiver, filter);


        IntentFilter pkgFilter = new IntentFilter();
        IntentFilter pkgFilter = new IntentFilter();