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

Commit d6d5a59e authored by Julia Reynolds's avatar Julia Reynolds
Browse files

Ensure that the blocking helper will run

On upgraded devices.

Test: runtest systemui-notification
Change-Id: I600d40100fc97ea25718ebc8800425d6bf7194ef
Fixes: 77325257
parent 61b93505
Loading
Loading
Loading
Loading
+1 −1
Original line number Original line Diff line number Diff line
@@ -110,7 +110,7 @@ abstract public class ManagedServices {
    protected final Object mMutex;
    protected final Object mMutex;
    private final UserProfiles mUserProfiles;
    private final UserProfiles mUserProfiles;
    private final IPackageManager mPm;
    private final IPackageManager mPm;
    private final UserManager mUm;
    protected final UserManager mUm;
    private final Config mConfig;
    private final Config mConfig;
    private final Handler mHandler = new Handler(Looper.getMainLooper());
    private final Handler mHandler = new Handler(Looper.getMainLooper());


+13 −7
Original line number Original line Diff line number Diff line
@@ -114,6 +114,7 @@ import android.content.pm.IPackageManager;
import android.content.pm.PackageManager;
import android.content.pm.PackageManager;
import android.content.pm.PackageManager.NameNotFoundException;
import android.content.pm.PackageManager.NameNotFoundException;
import android.content.pm.ParceledListSlice;
import android.content.pm.ParceledListSlice;
import android.content.pm.UserInfo;
import android.content.res.Resources;
import android.content.res.Resources;
import android.database.ContentObserver;
import android.database.ContentObserver;
import android.media.AudioAttributes;
import android.media.AudioAttributes;
@@ -492,8 +493,8 @@ public class NotificationManagerService extends SystemService {
                                    | PackageManager.MATCH_DIRECT_BOOT_UNAWARE, userId);
                                    | PackageManager.MATCH_DIRECT_BOOT_UNAWARE, userId);
            for (ComponentName cn : approvedAssistants) {
            for (ComponentName cn : approvedAssistants) {
                try {
                try {
                    getBinderService().setNotificationAssistantAccessGrantedForUser(cn,
                    getBinderService().setNotificationAssistantAccessGrantedForUser(
                            userId, true);
                            cn, userId, true);
                } catch (RemoteException e) {
                } catch (RemoteException e) {
                    e.printStackTrace();
                    e.printStackTrace();
                }
                }
@@ -535,6 +536,8 @@ public class NotificationManagerService extends SystemService {
            mConditionProviders.migrateToXml();
            mConditionProviders.migrateToXml();
            savePolicyFile();
            savePolicyFile();
        }
        }

        mAssistants.ensureAssistant();
    }
    }


    private void loadPolicyFile() {
    private void loadPolicyFile() {
@@ -6134,14 +6137,17 @@ public class NotificationManagerService extends SystemService {
            return !getServices().isEmpty();
            return !getServices().isEmpty();
        }
        }


        protected void upgradeXml(final int xmlVersion, final int userId) {
        protected void ensureAssistant() {
            if (xmlVersion == 0) {
            final List<UserInfo> activeUsers = mUm.getUsers(true);
                // one time approval of the OOB assistant
            for (UserInfo userInfo : activeUsers) {
                int userId = userInfo.getUserHandle().getIdentifier();
                if (getAllowedPackages(userId).isEmpty()) {
                    Slog.d(TAG, "Approving default notification assistant for user " + userId);
                    Slog.d(TAG, "Approving default notification assistant for user " + userId);
                    readDefaultAssistant(userId);
                    readDefaultAssistant(userId);
                }
                }
            }
            }
        }
        }
    }


    public class NotificationListeners extends ManagedServices {
    public class NotificationListeners extends ManagedServices {
        static final String TAG_ENABLED_NOTIFICATION_LISTENERS = "enabled_listeners";
        static final String TAG_ENABLED_NOTIFICATION_LISTENERS = "enabled_listeners";
+3 −44
Original line number Original line Diff line number Diff line
@@ -33,7 +33,6 @@ import android.content.pm.ResolveInfo;
import android.content.pm.ServiceInfo;
import android.content.pm.ServiceInfo;
import android.content.pm.UserInfo;
import android.content.pm.UserInfo;
import android.os.UserManager;
import android.os.UserManager;
import android.util.Slog;
import android.util.Xml;
import android.util.Xml;


import com.android.internal.util.FastXmlSerializer;
import com.android.internal.util.FastXmlSerializer;
@@ -108,14 +107,8 @@ public class NotificationAssistantsTest extends UiServiceTestCase {
    }
    }


    @Test
    @Test
    public void testXmlUpgrade() throws Exception {
    public void testXmlUpgrade() {
        String xml = "<enabled_assistants/>";
        mAssistants.ensureAssistant();

        XmlPullParser parser = Xml.newPullParser();
        parser.setInput(new BufferedInputStream(
                new ByteArrayInputStream(xml.toString().getBytes())), null);
        parser.nextTag();
        mAssistants.readXml(parser);


        //once per user
        //once per user
        verify(mNm, times(mUm.getUsers().size())).readDefaultAssistant(anyInt());
        verify(mNm, times(mUm.getUsers().size())).readDefaultAssistant(anyInt());
@@ -133,42 +126,8 @@ public class NotificationAssistantsTest extends UiServiceTestCase {
        parser.nextTag();
        parser.nextTag();
        mAssistants.readXml(parser);
        mAssistants.readXml(parser);


        // once per user
        verify(mNm, never()).readDefaultAssistant(anyInt());
        verify(mNm, times(mUm.getUsers().size())).readDefaultAssistant(anyInt());
        verify(mAssistants, times(1)).addApprovedList(
        verify(mAssistants, times(1)).addApprovedList(
                new ComponentName("b", "b").flattenToString(),10, true);
                new ComponentName("b", "b").flattenToString(),10, true);
    }
    }

    @Test
    public void testXmlUpgradeOnce() throws Exception {
        String xml = "<enabled_assistants/>";

        XmlPullParser parser = Xml.newPullParser();
        parser.setInput(new BufferedInputStream(
                new ByteArrayInputStream(xml.toString().getBytes())), null);
        parser.nextTag();
        mAssistants.readXml(parser);

        XmlSerializer serializer = new FastXmlSerializer();
        ByteArrayOutputStream baos = new ByteArrayOutputStream();
        serializer.setOutput(new BufferedOutputStream(baos), "utf-8");
        serializer.startDocument(null, true);
        mAssistants.writeXml(serializer, true);
        serializer.endDocument();
        serializer.flush();

        //once per user
        verify(mNm, times(mUm.getUsers().size())).readDefaultAssistant(anyInt());

        Mockito.reset(mNm);

        parser = Xml.newPullParser();
        parser.setInput(new BufferedInputStream(
                new ByteArrayInputStream(baos.toByteArray())), null);
        parser.nextTag();
        mAssistants.readXml(parser);

        //once per user
        verify(mNm, never()).readDefaultAssistant(anyInt());
    }
}
}
+4 −2
Original line number Original line Diff line number Diff line
@@ -2184,7 +2184,7 @@ public class NotificationManagerServiceTest extends UiServiceTestCase {


    @Test
    @Test
    public void testReadPolicyXml_readApprovedServicesFromXml() throws Exception {
    public void testReadPolicyXml_readApprovedServicesFromXml() throws Exception {
        final String preupgradeXml = "<notification-policy version=\"1\">"
        final String upgradeXml = "<notification-policy version=\"1\">"
                + "<zen></zen>"
                + "<zen></zen>"
                + "<ranking></ranking>"
                + "<ranking></ranking>"
                + "<enabled_listeners>"
                + "<enabled_listeners>"
@@ -2198,7 +2198,7 @@ public class NotificationManagerServiceTest extends UiServiceTestCase {
                + "</dnd_apps>"
                + "</dnd_apps>"
                + "</notification-policy>";
                + "</notification-policy>";
        mService.readPolicyXml(
        mService.readPolicyXml(
                new BufferedInputStream(new ByteArrayInputStream(preupgradeXml.getBytes())), false);
                new BufferedInputStream(new ByteArrayInputStream(upgradeXml.getBytes())), false);
        verify(mListeners, times(1)).readXml(any());
        verify(mListeners, times(1)).readXml(any());
        verify(mConditionProviders, times(1)).readXml(any());
        verify(mConditionProviders, times(1)).readXml(any());
        verify(mAssistants, times(1)).readXml(any());
        verify(mAssistants, times(1)).readXml(any());
@@ -2207,6 +2207,7 @@ public class NotificationManagerServiceTest extends UiServiceTestCase {
        verify(mListeners, times(1)).migrateToXml();
        verify(mListeners, times(1)).migrateToXml();
        verify(mConditionProviders, times(1)).migrateToXml();
        verify(mConditionProviders, times(1)).migrateToXml();
        verify(mAssistants, times(1)).migrateToXml();
        verify(mAssistants, times(1)).migrateToXml();
        verify(mAssistants, times(2)).ensureAssistant();
    }
    }


    @Test
    @Test
@@ -2225,6 +2226,7 @@ public class NotificationManagerServiceTest extends UiServiceTestCase {
        verify(mListeners, times(2)).migrateToXml();
        verify(mListeners, times(2)).migrateToXml();
        verify(mConditionProviders, times(2)).migrateToXml();
        verify(mConditionProviders, times(2)).migrateToXml();
        verify(mAssistants, times(2)).migrateToXml();
        verify(mAssistants, times(2)).migrateToXml();
        verify(mAssistants, times(2)).ensureAssistant();
    }
    }