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

Commit c763acef authored by Julia Reynolds's avatar Julia Reynolds Committed by Automerger Merge Worker
Browse files

Merge "Record whether apps have sent msg notifications" into rvc-dev am:...

Merge "Record whether apps have sent msg notifications" into rvc-dev am: 37e724b1 am: 9cfa34a6 am: ac099a3a

Change-Id: If9e4eb5c1310c913e69dd7ab6696661abad55f32
parents 449008d6 ac099a3a
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -58,6 +58,7 @@ interface INotificationManager

    void setShowBadge(String pkg, int uid, boolean showBadge);
    boolean canShowBadge(String pkg, int uid);
    boolean hasSentMessage(String pkg, int uid);
    void setNotificationsEnabledForPackage(String pkg, int uid, boolean enabled);
    /**
     * Updates the notification's enabled state. Additionally locks importance for all of the
+17 −0
Original line number Diff line number Diff line
@@ -2719,6 +2719,16 @@ public class NotificationManagerService extends SystemService {
        return text == null ? null : String.valueOf(text);
    }
    
    protected void maybeRegisterMessageSent(NotificationRecord r) {
        Context appContext = r.getSbn().getPackageContext(getContext());
        Notification.Builder nb = 
                Notification.Builder.recoverBuilder(appContext, r.getNotification());
        if (nb.getStyle() instanceof Notification.MessagingStyle) {
            mPreferencesHelper.setMessageSent(r.getSbn().getPackageName(), r.getUid());
            handleSavePolicyFile();
        }
    }

    /**
     * Report to usage stats that the user interacted with the notification.
     * @param r notification record
@@ -3145,6 +3155,12 @@ public class NotificationManagerService extends SystemService {
            handleSavePolicyFile();
        }

        @Override
        public boolean hasSentMessage(String pkg, int uid) {
            checkCallerIsSystem();
            return mPreferencesHelper.hasSentMessage(pkg, uid);
        }

        @Override
        public void setNotificationDelegate(String callingPkg, String delegate) {
            checkCallerIsSameApp(callingPkg);
@@ -6459,6 +6475,7 @@ public class NotificationManagerService extends SystemService {
                    }

                    maybeRecordInterruptionLocked(r);
                    maybeRegisterMessageSent(r);

                    // Log event to statsd
                    mNotificationRecordLogger.maybeLogNotificationPosted(r, old, position,
+19 −1
Original line number Diff line number Diff line
@@ -116,6 +116,7 @@ public class PreferencesHelper implements RankingConfig {
    private static final String ATT_ENABLED = "enabled";
    private static final String ATT_USER_ALLOWED = "allowed";
    private static final String ATT_HIDE_SILENT = "hide_gentle";
    private static final String ATT_SENT_MESSAGE = "sent_msg";

    private static final int DEFAULT_PRIORITY = Notification.PRIORITY_DEFAULT;
    private static final int DEFAULT_VISIBILITY = NotificationManager.VISIBILITY_NO_OVERRIDE;
@@ -269,6 +270,8 @@ public class PreferencesHelper implements RankingConfig {
                                    parser, ATT_SHOW_BADGE, DEFAULT_SHOW_BADGE);
                            r.lockedAppFields = XmlUtils.readIntAttribute(parser,
                                    ATT_APP_USER_LOCKED_FIELDS, DEFAULT_LOCKED_APP_FIELDS);
                            r.hasSentMessage = XmlUtils.readBooleanAttribute(
                                    parser, ATT_SENT_MESSAGE, false);

                            final int innerDepth = parser.getDepth();
                            while ((type = parser.next()) != XmlPullParser.END_DOCUMENT
@@ -510,7 +513,8 @@ public class PreferencesHelper implements RankingConfig {
                                || r.channels.size() > 0
                                || r.groups.size() > 0
                                || r.delegate != null
                                || r.bubblePreference != DEFAULT_BUBBLE_PREFERENCE;
                                || r.bubblePreference != DEFAULT_BUBBLE_PREFERENCE
                                || r.hasSentMessage;
                if (hasNonDefaultSettings) {
                    out.startTag(null, TAG_PACKAGE);
                    out.attribute(null, ATT_NAME, r.pkg);
@@ -529,6 +533,7 @@ public class PreferencesHelper implements RankingConfig {
                    out.attribute(null, ATT_SHOW_BADGE, Boolean.toString(r.showBadge));
                    out.attribute(null, ATT_APP_USER_LOCKED_FIELDS,
                            Integer.toString(r.lockedAppFields));
                    out.attribute(null, ATT_SENT_MESSAGE, Boolean.toString(r.hasSentMessage));

                    if (!forBackup) {
                        out.attribute(null, ATT_UID, Integer.toString(r.uid));
@@ -647,6 +652,18 @@ public class PreferencesHelper implements RankingConfig {
        updateConfig();
    }

    public boolean hasSentMessage(String packageName, int uid) {
        synchronized (mPackagePreferences) {
            return getOrCreatePackagePreferencesLocked(packageName, uid).hasSentMessage;
        }
    }

    public void setMessageSent(String packageName, int uid) {
        synchronized (mPackagePreferences) {
            getOrCreatePackagePreferencesLocked(packageName, uid).hasSentMessage = true;
        }
    }

    @Override
    public boolean isGroupBlocked(String packageName, int uid, String groupId) {
        if (groupId == null) {
@@ -2271,6 +2288,7 @@ public class PreferencesHelper implements RankingConfig {
        boolean oemLockedImportance = DEFAULT_OEM_LOCKED_IMPORTANCE;
        List<String> oemLockedChannels = new ArrayList<>();
        boolean defaultAppLockedImportance = DEFAULT_APP_LOCKED_IMPORTANCE;
        boolean hasSentMessage = false;

        Delegate delegate = null;
        ArrayMap<String, NotificationChannel> channels = new ArrayMap<>();
+12 −0
Original line number Diff line number Diff line
@@ -6573,4 +6573,16 @@ public class NotificationManagerServiceTest extends UiServiceTestCase {
            fail(e.getMessage());
        }
    }

    @Test
    public void testRecordMessages() throws RemoteException {
        NotificationRecord nr =
                generateMessageBubbleNotifRecord(mTestNotificationChannel,
                        "testRecordMessages");
        mBinderService.enqueueNotificationWithTag(PKG, PKG, nr.getSbn().getTag(),
                nr.getSbn().getId(), nr.getSbn().getNotification(), nr.getSbn().getUserId());
        waitForIdle();

        assertTrue(mBinderService.hasSentMessage(PKG, mUid));
    }
}
+16 −0
Original line number Diff line number Diff line
@@ -454,6 +454,7 @@ public class PreferencesHelperTest extends UiServiceTestCase {
        mHelper.createNotificationChannel(PKG_O, UID_O, getChannel(), true, false);

        mHelper.setShowBadge(PKG_N_MR1, UID_N_MR1, true);
        mHelper.setMessageSent(PKG_P, UID_P);

        mHelper.setImportance(PKG_O, UID_O, IMPORTANCE_NONE);

@@ -469,6 +470,8 @@ public class PreferencesHelperTest extends UiServiceTestCase {

        assertEquals(IMPORTANCE_NONE, mHelper.getImportance(PKG_O, UID_O));
        assertTrue(mHelper.canShowBadge(PKG_N_MR1, UID_N_MR1));
        assertTrue(mHelper.hasSentMessage(PKG_P, UID_P));
        assertFalse(mHelper.hasSentMessage(PKG_N_MR1, UID_N_MR1));
        assertEquals(channel1,
                mHelper.getNotificationChannel(PKG_N_MR1, UID_N_MR1, channel1.getId(), false));
        compareChannels(channel2,
@@ -3390,4 +3393,17 @@ public class PreferencesHelperTest extends UiServiceTestCase {
                        .NOTIFICATION_CHANNEL_CONVERSATION_DELETED,
                mLogger.get(6).event);  // Delete Channel channel2 - Conversation A person calls
    }

    @Test
    public void testMessageSent() {
        // create package preferences
        mHelper.canShowBadge(PKG_P, UID_P);

        // check default value
        assertFalse(mHelper.hasSentMessage(PKG_P, UID_P));

        // change it
        mHelper.setMessageSent(PKG_P, UID_P);
        assertTrue(mHelper.hasSentMessage(PKG_P, UID_P));
    }
}