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

Commit 37e724b1 authored by Julia Reynolds's avatar Julia Reynolds Committed by Android (Google) Code Review
Browse files

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

parents 56495051 a7dac439
Loading
Loading
Loading
Loading
+1 −0
Original line number Original line Diff line number Diff line
@@ -58,6 +58,7 @@ interface INotificationManager


    void setShowBadge(String pkg, int uid, boolean showBadge);
    void setShowBadge(String pkg, int uid, boolean showBadge);
    boolean canShowBadge(String pkg, int uid);
    boolean canShowBadge(String pkg, int uid);
    boolean hasSentMessage(String pkg, int uid);
    void setNotificationsEnabledForPackage(String pkg, int uid, boolean enabled);
    void setNotificationsEnabledForPackage(String pkg, int uid, boolean enabled);
    /**
    /**
     * Updates the notification's enabled state. Additionally locks importance for all of the
     * Updates the notification's enabled state. Additionally locks importance for all of the
+17 −0
Original line number Original line Diff line number Diff line
@@ -2719,6 +2719,16 @@ public class NotificationManagerService extends SystemService {
        return text == null ? null : String.valueOf(text);
        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.
     * Report to usage stats that the user interacted with the notification.
     * @param r notification record
     * @param r notification record
@@ -3145,6 +3155,12 @@ public class NotificationManagerService extends SystemService {
            handleSavePolicyFile();
            handleSavePolicyFile();
        }
        }


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

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


                    maybeRecordInterruptionLocked(r);
                    maybeRecordInterruptionLocked(r);
                    maybeRegisterMessageSent(r);


                    // Log event to statsd
                    // Log event to statsd
                    mNotificationRecordLogger.maybeLogNotificationPosted(r, old, position,
                    mNotificationRecordLogger.maybeLogNotificationPosted(r, old, position,
+19 −1
Original line number Original line 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_ENABLED = "enabled";
    private static final String ATT_USER_ALLOWED = "allowed";
    private static final String ATT_USER_ALLOWED = "allowed";
    private static final String ATT_HIDE_SILENT = "hide_gentle";
    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_PRIORITY = Notification.PRIORITY_DEFAULT;
    private static final int DEFAULT_VISIBILITY = NotificationManager.VISIBILITY_NO_OVERRIDE;
    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);
                                    parser, ATT_SHOW_BADGE, DEFAULT_SHOW_BADGE);
                            r.lockedAppFields = XmlUtils.readIntAttribute(parser,
                            r.lockedAppFields = XmlUtils.readIntAttribute(parser,
                                    ATT_APP_USER_LOCKED_FIELDS, DEFAULT_LOCKED_APP_FIELDS);
                                    ATT_APP_USER_LOCKED_FIELDS, DEFAULT_LOCKED_APP_FIELDS);
                            r.hasSentMessage = XmlUtils.readBooleanAttribute(
                                    parser, ATT_SENT_MESSAGE, false);


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


                    if (!forBackup) {
                    if (!forBackup) {
                        out.attribute(null, ATT_UID, Integer.toString(r.uid));
                        out.attribute(null, ATT_UID, Integer.toString(r.uid));
@@ -647,6 +652,18 @@ public class PreferencesHelper implements RankingConfig {
        updateConfig();
        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
    @Override
    public boolean isGroupBlocked(String packageName, int uid, String groupId) {
    public boolean isGroupBlocked(String packageName, int uid, String groupId) {
        if (groupId == null) {
        if (groupId == null) {
@@ -2271,6 +2288,7 @@ public class PreferencesHelper implements RankingConfig {
        boolean oemLockedImportance = DEFAULT_OEM_LOCKED_IMPORTANCE;
        boolean oemLockedImportance = DEFAULT_OEM_LOCKED_IMPORTANCE;
        List<String> oemLockedChannels = new ArrayList<>();
        List<String> oemLockedChannels = new ArrayList<>();
        boolean defaultAppLockedImportance = DEFAULT_APP_LOCKED_IMPORTANCE;
        boolean defaultAppLockedImportance = DEFAULT_APP_LOCKED_IMPORTANCE;
        boolean hasSentMessage = false;


        Delegate delegate = null;
        Delegate delegate = null;
        ArrayMap<String, NotificationChannel> channels = new ArrayMap<>();
        ArrayMap<String, NotificationChannel> channels = new ArrayMap<>();
+12 −0
Original line number Original line Diff line number Diff line
@@ -6573,4 +6573,16 @@ public class NotificationManagerServiceTest extends UiServiceTestCase {
            fail(e.getMessage());
            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 Original line Diff line number Diff line
@@ -454,6 +454,7 @@ public class PreferencesHelperTest extends UiServiceTestCase {
        mHelper.createNotificationChannel(PKG_O, UID_O, getChannel(), true, false);
        mHelper.createNotificationChannel(PKG_O, UID_O, getChannel(), true, false);


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


        mHelper.setImportance(PKG_O, UID_O, IMPORTANCE_NONE);
        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));
        assertEquals(IMPORTANCE_NONE, mHelper.getImportance(PKG_O, UID_O));
        assertTrue(mHelper.canShowBadge(PKG_N_MR1, UID_N_MR1));
        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,
        assertEquals(channel1,
                mHelper.getNotificationChannel(PKG_N_MR1, UID_N_MR1, channel1.getId(), false));
                mHelper.getNotificationChannel(PKG_N_MR1, UID_N_MR1, channel1.getId(), false));
        compareChannels(channel2,
        compareChannels(channel2,
@@ -3390,4 +3393,17 @@ public class PreferencesHelperTest extends UiServiceTestCase {
                        .NOTIFICATION_CHANNEL_CONVERSATION_DELETED,
                        .NOTIFICATION_CHANNEL_CONVERSATION_DELETED,
                mLogger.get(6).event);  // Delete Channel channel2 - Conversation A person calls
                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));
    }
}
}