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

Commit 12d73927 authored by TreeHugger Robot's avatar TreeHugger Robot Committed by Automerger Merge Worker
Browse files

Merge "Copy keys to iterate over so we don't concurrently modify the map."...

Merge "Copy keys to iterate over so we don't concurrently modify the map." into rvc-dev am: 5a7298f6

Original change: https://googleplex-android-review.googlesource.com/c/platform/frameworks/base/+/12001034

Change-Id: I437b062be544156e6bdc2738cabdb7413929abb2
parents 9b6d35ce 5a7298f6
Loading
Loading
Loading
Loading
+6 −1
Original line number Original line Diff line number Diff line
@@ -37,7 +37,9 @@ import java.util.ArrayList;
import java.util.Arrays;
import java.util.Arrays;
import java.util.Collections;
import java.util.Collections;
import java.util.HashMap;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.List;
import java.util.Set;


/**
/**
 * Helper for querying shortcuts.
 * Helper for querying shortcuts.
@@ -249,8 +251,11 @@ public class ShortcutHelper {
                if (!TextUtils.isEmpty(shortcutId)) {
                if (!TextUtils.isEmpty(shortcutId)) {
                    packageBubbles.remove(shortcutId);
                    packageBubbles.remove(shortcutId);
                } else {
                } else {
                    // Copy the shortcut IDs to avoid a concurrent modification exception.
                    final Set<String> shortcutIds = new HashSet<>(packageBubbles.keySet());

                    // Check if there was a matching entry
                    // Check if there was a matching entry
                    for (String pkgShortcutId : packageBubbles.keySet()) {
                    for (String pkgShortcutId : shortcutIds) {
                        String entryKey = packageBubbles.get(pkgShortcutId);
                        String entryKey = packageBubbles.get(pkgShortcutId);
                        if (r.getKey().equals(entryKey)) {
                        if (r.getKey().equals(entryKey)) {
                            // No longer has shortcut id so remove it
                            // No longer has shortcut id so remove it
+35 −7
Original line number Original line Diff line number Diff line
@@ -45,6 +45,7 @@ import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.runner.RunWith;
import org.mockito.ArgumentCaptor;
import org.mockito.ArgumentCaptor;
import org.mockito.Mock;
import org.mockito.Mock;
import org.mockito.Mockito;
import org.mockito.MockitoAnnotations;
import org.mockito.MockitoAnnotations;


import java.util.ArrayList;
import java.util.ArrayList;
@@ -85,14 +86,19 @@ public class ShortcutHelperTest extends UiServiceTestCase {


        mShortcutHelper = new ShortcutHelper(
        mShortcutHelper = new ShortcutHelper(
                mLauncherApps, mShortcutListener, mShortcutServiceInternal);
                mLauncherApps, mShortcutListener, mShortcutServiceInternal);
        when(mNr.getKey()).thenReturn(KEY);
        when(mNr.getSbn()).thenReturn(mSbn);
        when(mSbn.getPackageName()).thenReturn(PKG);
        when(mSbn.getPackageName()).thenReturn(PKG);
        when(mNr.getNotification()).thenReturn(mNotif);
        when(mNr.getShortcutInfo()).thenReturn(mShortcutInfo);
        when(mShortcutInfo.getId()).thenReturn(SHORTCUT_ID);
        when(mShortcutInfo.getId()).thenReturn(SHORTCUT_ID);
        when(mNotif.getBubbleMetadata()).thenReturn(mBubbleMetadata);
        when(mNotif.getBubbleMetadata()).thenReturn(mBubbleMetadata);
        when(mBubbleMetadata.getShortcutId()).thenReturn(SHORTCUT_ID);
        when(mBubbleMetadata.getShortcutId()).thenReturn(SHORTCUT_ID);

        setUpMockNotificationRecord(mNr, KEY);
    }

    private void setUpMockNotificationRecord(NotificationRecord mockRecord, String key) {
        when(mockRecord.getKey()).thenReturn(key);
        when(mockRecord.getSbn()).thenReturn(mSbn);
        when(mockRecord.getNotification()).thenReturn(mNotif);
        when(mockRecord.getShortcutInfo()).thenReturn(mShortcutInfo);
    }
    }


    private LauncherApps.Callback addShortcutBubbleAndVerifyListener() {
    private LauncherApps.Callback addShortcutBubbleAndVerifyListener() {
@@ -159,9 +165,31 @@ public class ShortcutHelperTest extends UiServiceTestCase {
        // First set it up to listen
        // First set it up to listen
        addShortcutBubbleAndVerifyListener();
        addShortcutBubbleAndVerifyListener();


        // Clear out shortcutId
        NotificationRecord validMock1 = Mockito.mock(NotificationRecord.class);
        when(mNr.getShortcutInfo()).thenReturn(null);
        setUpMockNotificationRecord(validMock1, "KEY1");
        mShortcutHelper.maybeListenForShortcutChangesForBubbles(mNr,

        NotificationRecord validMock2 = Mockito.mock(NotificationRecord.class);
        setUpMockNotificationRecord(validMock2, "KEY2");

        NotificationRecord validMock3 = Mockito.mock(NotificationRecord.class);
        setUpMockNotificationRecord(validMock3, "KEY3");

        mShortcutHelper.maybeListenForShortcutChangesForBubbles(validMock1,
                false /* removed */,
                null /* handler */);

        mShortcutHelper.maybeListenForShortcutChangesForBubbles(validMock2,
                false /* removed */,
                null /* handler */);

        mShortcutHelper.maybeListenForShortcutChangesForBubbles(validMock3,
                false /* removed */,
                null /* handler */);

        // Clear out shortcutId of the bubble in the middle, to double check that we don't hit a
        // concurrent modification exception (removing the last bubble would sidestep that check).
        when(validMock2.getShortcutInfo()).thenReturn(null);
        mShortcutHelper.maybeListenForShortcutChangesForBubbles(validMock2,
                false /* removed */,
                false /* removed */,
                null /* handler */);
                null /* handler */);