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

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

Merge "Up to date apps must provide conversation shortcuts" into rvc-dev am: c79df044

Change-Id: Ic9ae817c870422c49c92febc49ccc47935a3bda3
parents 5d236a37 c79df044
Loading
Loading
Loading
Loading
+10 −2
Original line number Original line Diff line number Diff line
@@ -1382,13 +1382,21 @@ public final class NotificationRecord {
     */
     */
    public boolean isConversation() {
    public boolean isConversation() {
        Notification notification = getNotification();
        Notification notification = getNotification();
        if (mChannel.isDemoted()
        if (!Notification.MessagingStyle.class.equals(notification.getNotificationStyle())) {
                || !Notification.MessagingStyle.class.equals(notification.getNotificationStyle())) {
            // very common; don't bother logging
            return false;
        }
        if (mChannel.isDemoted()) {
            return false;
            return false;
        }
        }
        if (mIsNotConversationOverride) {
        if (mIsNotConversationOverride) {
            return false;
            return false;
        }
        }
        if (mTargetSdkVersion >= Build.VERSION_CODES.R
            && Notification.MessagingStyle.class.equals(notification.getNotificationStyle())
            && mShortcutInfo == null) {
            return false;
        }
        return true;
        return true;
    }
    }


+3 −0
Original line number Original line Diff line number Diff line
@@ -41,6 +41,7 @@ public class UiServiceTestCase {
    protected static final String PKG_N_MR1 = "com.example.n_mr1";
    protected static final String PKG_N_MR1 = "com.example.n_mr1";
    protected static final String PKG_O = "com.example.o";
    protected static final String PKG_O = "com.example.o";
    protected static final String PKG_P = "com.example.p";
    protected static final String PKG_P = "com.example.p";
    protected static final String PKG_R = "com.example.r";


    @Rule
    @Rule
    public final TestableContext mContext =
    public final TestableContext mContext =
@@ -69,6 +70,8 @@ public class UiServiceTestCase {
                            return Build.VERSION_CODES.O;
                            return Build.VERSION_CODES.O;
                        case PKG_P:
                        case PKG_P:
                            return Build.VERSION_CODES.P;
                            return Build.VERSION_CODES.P;
                        case PKG_R:
                            return Build.VERSION_CODES.R;
                        default:
                        default:
                            return Build.VERSION_CODES.CUR_DEVELOPMENT;
                            return Build.VERSION_CODES.CUR_DEVELOPMENT;
                    }
                    }
+22 −27
Original line number Original line Diff line number Diff line
@@ -250,6 +250,8 @@ public class NotificationManagerServiceTest extends UiServiceTestCase {


    private static final int NOTIFICATION_LOCATION_UNKNOWN = 0;
    private static final int NOTIFICATION_LOCATION_UNKNOWN = 0;


    private static final String VALID_CONVO_SHORTCUT_ID = "shortcut";

    @Mock
    @Mock
    private NotificationListeners mListeners;
    private NotificationListeners mListeners;
    @Mock private NotificationAssistants mAssistants;
    @Mock private NotificationAssistants mAssistants;
@@ -471,6 +473,19 @@ public class NotificationManagerServiceTest extends UiServiceTestCase {
        mShortcutHelper.setLauncherApps(mLauncherApps);
        mShortcutHelper.setLauncherApps(mLauncherApps);
        mShortcutHelper.setShortcutServiceInternal(mShortcutServiceInternal);
        mShortcutHelper.setShortcutServiceInternal(mShortcutServiceInternal);


        // Pretend the shortcut exists
        List<ShortcutInfo> shortcutInfos = new ArrayList<>();
        ShortcutInfo info = mock(ShortcutInfo.class);
        when(info.getPackage()).thenReturn(PKG);
        when(info.getId()).thenReturn(VALID_CONVO_SHORTCUT_ID);
        when(info.getUserId()).thenReturn(USER_SYSTEM);
        when(info.isLongLived()).thenReturn(true);
        when(info.isEnabled()).thenReturn(true);
        shortcutInfos.add(info);
        when(mLauncherApps.getShortcuts(any(), any())).thenReturn(shortcutInfos);
        when(mShortcutServiceInternal.isSharingShortcut(anyInt(), anyString(), anyString(),
                anyString(), anyInt(), any())).thenReturn(true);

        // Set the testable bubble extractor
        // Set the testable bubble extractor
        RankingHelper rankingHelper = mService.getRankingHelper();
        RankingHelper rankingHelper = mService.getRankingHelper();
        BubbleExtractor extractor = rankingHelper.findExtractor(BubbleExtractor.class);
        BubbleExtractor extractor = rankingHelper.findExtractor(BubbleExtractor.class);
@@ -704,6 +719,7 @@ public class NotificationManagerServiceTest extends UiServiceTestCase {
                )
                )
                .setActions(replyAction)
                .setActions(replyAction)
                .setSmallIcon(android.R.drawable.sym_def_app_icon)
                .setSmallIcon(android.R.drawable.sym_def_app_icon)
                .setShortcutId(VALID_CONVO_SHORTCUT_ID)
                .setGroupSummary(isSummary);
                .setGroupSummary(isSummary);
        if (groupKey != null) {
        if (groupKey != null) {
            nb.setGroup(groupKey);
            nb.setGroup(groupKey);
@@ -6100,7 +6116,6 @@ public class NotificationManagerServiceTest extends UiServiceTestCase {
    @Test
    @Test
    public void testNotificationBubbles_flagRemoved_whenShortcutRemoved()
    public void testNotificationBubbles_flagRemoved_whenShortcutRemoved()
            throws RemoteException {
            throws RemoteException {
        final String shortcutId = "someshortcutId";
        setUpPrefsForBubbles(PKG, mUid,
        setUpPrefsForBubbles(PKG, mUid,
                true /* global */,
                true /* global */,
                BUBBLE_PREFERENCE_ALL /* app */,
                BUBBLE_PREFERENCE_ALL /* app */,
@@ -6111,27 +6126,16 @@ public class NotificationManagerServiceTest extends UiServiceTestCase {


        // Messaging notification with shortcut info
        // Messaging notification with shortcut info
        Notification.BubbleMetadata metadata =
        Notification.BubbleMetadata metadata =
                new Notification.BubbleMetadata.Builder(shortcutId).build();
                new Notification.BubbleMetadata.Builder(VALID_CONVO_SHORTCUT_ID).build();
        Notification.Builder nb = getMessageStyleNotifBuilder(false /* addDefaultMetadata */,
        Notification.Builder nb = getMessageStyleNotifBuilder(false /* addDefaultMetadata */,
                null /* groupKey */, false /* isSummary */);
                null /* groupKey */, false /* isSummary */);
        nb.setShortcutId(shortcutId);
        nb.setShortcutId(VALID_CONVO_SHORTCUT_ID);
        nb.setBubbleMetadata(metadata);
        nb.setBubbleMetadata(metadata);
        StatusBarNotification sbn = new StatusBarNotification(PKG, PKG, 1,
        StatusBarNotification sbn = new StatusBarNotification(PKG, PKG, 1,
                "tag", mUid, 0, nb.build(), new UserHandle(mUid), null, 0);
                "tag", mUid, 0, nb.build(), new UserHandle(mUid), null, 0);
        NotificationRecord nr = new NotificationRecord(mContext, sbn, mTestNotificationChannel);
        NotificationRecord nr = new NotificationRecord(mContext, sbn, mTestNotificationChannel);


        // Pretend the shortcut exists

        List<ShortcutInfo> shortcutInfos = new ArrayList<>();
        ShortcutInfo info = mock(ShortcutInfo.class);
        when(info.getPackage()).thenReturn(PKG);
        when(info.getId()).thenReturn(shortcutId);
        when(info.getUserId()).thenReturn(USER_SYSTEM);
        when(info.isLongLived()).thenReturn(true);
        when(info.isEnabled()).thenReturn(true);
        shortcutInfos.add(info);
        when(mLauncherApps.getShortcuts(any(), any())).thenReturn(shortcutInfos);
        when(mShortcutServiceInternal.isSharingShortcut(anyInt(), anyString(), anyString(),
                anyString(), anyInt(), any())).thenReturn(true);


        // Test: Send the bubble notification
        // Test: Send the bubble notification
        mBinderService.enqueueNotificationWithTag(PKG, PKG, nr.getSbn().getTag(),
        mBinderService.enqueueNotificationWithTag(PKG, PKG, nr.getSbn().getTag(),
@@ -6149,7 +6153,7 @@ public class NotificationManagerServiceTest extends UiServiceTestCase {


        // Make sure the shortcut is cached.
        // Make sure the shortcut is cached.
        verify(mShortcutServiceInternal).cacheShortcuts(
        verify(mShortcutServiceInternal).cacheShortcuts(
                anyInt(), any(), eq(PKG), eq(Collections.singletonList(shortcutId)),
                anyInt(), any(), eq(PKG), eq(Collections.singletonList(VALID_CONVO_SHORTCUT_ID)),
                eq(USER_SYSTEM));
                eq(USER_SYSTEM));


        // Test: Remove the shortcut
        // Test: Remove the shortcut
@@ -6613,6 +6617,7 @@ public class NotificationManagerServiceTest extends UiServiceTestCase {
        convo2.setNotificationChannel(channel2);
        convo2.setNotificationChannel(channel2);
        convos.add(convo2);
        convos.add(convo2);
        when(mPreferencesHelper.getConversations(anyString(), anyInt())).thenReturn(convos);
        when(mPreferencesHelper.getConversations(anyString(), anyInt())).thenReturn(convos);
        when(mLauncherApps.getShortcuts(any(), any())).thenReturn(null);


        List<ConversationChannelWrapper> conversations =
        List<ConversationChannelWrapper> conversations =
                mBinderService.getConversationsForPackage(PKG_P, mUid).getList();
                mBinderService.getConversationsForPackage(PKG_P, mUid).getList();
@@ -6640,6 +6645,7 @@ public class NotificationManagerServiceTest extends UiServiceTestCase {
        NotificationRecord nr =
        NotificationRecord nr =
                generateMessageBubbleNotifRecord(mTestNotificationChannel,
                generateMessageBubbleNotifRecord(mTestNotificationChannel,
                        "testRecordMessages_invalidMsg");
                        "testRecordMessages_invalidMsg");
        when(mLauncherApps.getShortcuts(any(), any())).thenReturn(null);
        mBinderService.enqueueNotificationWithTag(PKG, PKG, nr.getSbn().getTag(),
        mBinderService.enqueueNotificationWithTag(PKG, PKG, nr.getSbn().getTag(),
                nr.getSbn().getId(), nr.getSbn().getNotification(), nr.getSbn().getUserId());
                nr.getSbn().getId(), nr.getSbn().getNotification(), nr.getSbn().getUserId());
        waitForIdle();
        waitForIdle();
@@ -6660,17 +6666,6 @@ public class NotificationManagerServiceTest extends UiServiceTestCase {
                "testRecordMessages_validMsg", mUid, 0, nb.build(), new UserHandle(mUid), null, 0);
                "testRecordMessages_validMsg", mUid, 0, nb.build(), new UserHandle(mUid), null, 0);
        NotificationRecord nr = new NotificationRecord(mContext, sbn, mTestNotificationChannel);
        NotificationRecord nr = new NotificationRecord(mContext, sbn, mTestNotificationChannel);


        // Pretend the shortcut exists
        List<ShortcutInfo> shortcutInfos = new ArrayList<>();
        ShortcutInfo info = mock(ShortcutInfo.class);
        when(info.getPackage()).thenReturn(PKG);
        when(info.getId()).thenReturn("id");
        when(info.getUserId()).thenReturn(USER_SYSTEM);
        when(info.isLongLived()).thenReturn(true);
        when(info.isEnabled()).thenReturn(true);
        shortcutInfos.add(info);
        when(mLauncherApps.getShortcuts(any(), any())).thenReturn(shortcutInfos);

        mBinderService.enqueueNotificationWithTag(PKG, PKG, nr.getSbn().getTag(),
        mBinderService.enqueueNotificationWithTag(PKG, PKG, nr.getSbn().getTag(),
                nr.getSbn().getId(), nr.getSbn().getNotification(), nr.getSbn().getUserId());
                nr.getSbn().getId(), nr.getSbn().getNotification(), nr.getSbn().getUserId());
        waitForIdle();
        waitForIdle();
+18 −6
Original line number Original line Diff line number Diff line
@@ -39,7 +39,6 @@ import static org.mockito.ArgumentMatchers.eq;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;
import static org.mockito.Mockito.when;


import android.annotation.Nullable;
import android.app.ActivityManager;
import android.app.ActivityManager;
import android.app.IActivityManager;
import android.app.IActivityManager;
import android.app.Notification;
import android.app.Notification;
@@ -90,7 +89,7 @@ public class NotificationRecordTest extends UiServiceTestCase {
    @Mock private PackageManager mPm;
    @Mock private PackageManager mPm;
    @Mock private ContentResolver mContentResolver;
    @Mock private ContentResolver mContentResolver;


    private final String pkg = PKG_N_MR1;
    private final String mPkg = PKG_O;
    private final int uid = 9583;
    private final int uid = 9583;
    private final int id1 = 1;
    private final int id1 = 1;
    private final String tag1 = "tag1";
    private final String tag1 = "tag1";
@@ -198,10 +197,14 @@ public class NotificationRecordTest extends UiServiceTestCase {
        }
        }


        Notification n = builder.build();
        Notification n = builder.build();
        return new StatusBarNotification(pkg, pkg, id1, tag1, uid, uid, n, mUser, null, uid);
        return new StatusBarNotification(mPkg, mPkg, id1, tag1, uid, uid, n, mUser, null, uid);
    }
    }


    private StatusBarNotification getMessagingStyleNotification() {
    private StatusBarNotification getMessagingStyleNotification() {
        return getMessagingStyleNotification(mPkg);
    }

    private StatusBarNotification getMessagingStyleNotification(String pkg) {
        final Builder builder = new Builder(mMockContext)
        final Builder builder = new Builder(mMockContext)
                .setContentTitle("foo")
                .setContentTitle("foo")
                .setSmallIcon(android.R.drawable.sym_def_app_icon);
                .setSmallIcon(android.R.drawable.sym_def_app_icon);
@@ -658,7 +661,7 @@ public class NotificationRecordTest extends UiServiceTestCase {


        Bundle signals = new Bundle();
        Bundle signals = new Bundle();
        signals.putInt(Adjustment.KEY_USER_SENTIMENT, USER_SENTIMENT_NEGATIVE);
        signals.putInt(Adjustment.KEY_USER_SENTIMENT, USER_SENTIMENT_NEGATIVE);
        record.addAdjustment(new Adjustment(pkg, record.getKey(), signals, null, sbn.getUserId()));
        record.addAdjustment(new Adjustment(mPkg, record.getKey(), signals, null, sbn.getUserId()));


        record.applyAdjustments();
        record.applyAdjustments();


@@ -687,7 +690,7 @@ public class NotificationRecordTest extends UiServiceTestCase {


        Bundle signals = new Bundle();
        Bundle signals = new Bundle();
        signals.putInt(Adjustment.KEY_USER_SENTIMENT, USER_SENTIMENT_NEGATIVE);
        signals.putInt(Adjustment.KEY_USER_SENTIMENT, USER_SENTIMENT_NEGATIVE);
        record.addAdjustment(new Adjustment(pkg, record.getKey(), signals, null, sbn.getUserId()));
        record.addAdjustment(new Adjustment(mPkg, record.getKey(), signals, null, sbn.getUserId()));
        record.applyAdjustments();
        record.applyAdjustments();


        assertEquals(USER_SENTIMENT_POSITIVE, record.getUserSentiment());
        assertEquals(USER_SENTIMENT_POSITIVE, record.getUserSentiment());
@@ -705,7 +708,7 @@ public class NotificationRecordTest extends UiServiceTestCase {


        Bundle signals = new Bundle();
        Bundle signals = new Bundle();
        signals.putInt(Adjustment.KEY_USER_SENTIMENT, USER_SENTIMENT_NEGATIVE);
        signals.putInt(Adjustment.KEY_USER_SENTIMENT, USER_SENTIMENT_NEGATIVE);
        record.addAdjustment(new Adjustment(pkg, record.getKey(), signals, null, sbn.getUserId()));
        record.addAdjustment(new Adjustment(mPkg, record.getKey(), signals, null, sbn.getUserId()));


        record.applyAdjustments();
        record.applyAdjustments();


@@ -1133,6 +1136,15 @@ public class NotificationRecordTest extends UiServiceTestCase {
        assertTrue(record.isConversation());
        assertTrue(record.isConversation());
    }
    }


    @Test
    public void testIsConversation_noShortcut_targetsR() {
        StatusBarNotification sbn = getMessagingStyleNotification(PKG_R);
        NotificationRecord record = new NotificationRecord(mMockContext, sbn, channel);
        record.setShortcutInfo(null);

        assertFalse(record.isConversation());
    }

    @Test
    @Test
    public void testIsConversation_channelDemoted() {
    public void testIsConversation_channelDemoted() {
        StatusBarNotification sbn = getMessagingStyleNotification();
        StatusBarNotification sbn = getMessagingStyleNotification();