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

Commit 07cfaa6b authored by Danning Chen's avatar Danning Chen
Browse files

Keep the conversation shortcut criteria in People Service consistent with the...

Keep the conversation shortcut criteria in People Service consistent with the one in Notification Manager

Before this change, People Service uses the presence of the Person object
in ShortcutInfo as the criteria of conversation shortcut. This changes
the criteria that the shortcut needs to be a share shortcut instead of having Person object.

Change-Id: I1ea52a50c909ca96365c1d4e55af97931d048d8f
Test: atest ShortcutHelperTest
Test: atest DataManagerTest
Bug: 154254830
parent d53e8618
Loading
Loading
Loading
Loading
+26 −15
Original line number Diff line number Diff line
@@ -21,7 +21,6 @@ import static android.content.pm.LauncherApps.ShortcutQuery.FLAG_MATCH_DYNAMIC;
import static android.content.pm.LauncherApps.ShortcutQuery.FLAG_MATCH_PINNED;

import android.annotation.NonNull;
import android.content.Intent;
import android.content.IntentFilter;
import android.content.pm.LauncherApps;
import android.content.pm.ShortcutInfo;
@@ -41,9 +40,18 @@ import java.util.List;
/**
 * Helper for querying shortcuts.
 */
class ShortcutHelper {
public class ShortcutHelper {
    private static final String TAG = "ShortcutHelper";

    private static final IntentFilter SHARING_FILTER = new IntentFilter();
    static {
        try {
            SHARING_FILTER.addDataType("*/*");
        } catch (IntentFilter.MalformedMimeTypeException e) {
            Slog.e(TAG, "Bad mime type", e);
        }
    }

    /**
     * Listener to call when a shortcut we're tracking has been removed.
     */
@@ -54,7 +62,6 @@ class ShortcutHelper {
    private LauncherApps mLauncherAppsService;
    private ShortcutListener mShortcutListener;
    private ShortcutServiceInternal mShortcutServiceInternal;
    private IntentFilter mSharingFilter;

    // Key: packageName Value: <shortcutId, notifId>
    private HashMap<String, HashMap<String, String>> mActiveShortcutBubbles = new HashMap<>();
@@ -122,12 +129,6 @@ class ShortcutHelper {
            ShortcutServiceInternal shortcutServiceInternal) {
        mLauncherAppsService = launcherApps;
        mShortcutListener = listener;
        mSharingFilter = new IntentFilter();
        try {
            mSharingFilter.addDataType("*/*");
        } catch (IntentFilter.MalformedMimeTypeException e) {
            Slog.e(TAG, "Bad mime type", e);
        }
        mShortcutServiceInternal = shortcutServiceInternal;
    }

@@ -142,7 +143,21 @@ class ShortcutHelper {
    }

    /**
     * Only returns shortcut info if it's found and if it's {@link ShortcutInfo#isLongLived()}.
     * Returns whether the given shortcut info is a conversation shortcut.
     */
    public static boolean isConversationShortcut(
            ShortcutInfo shortcutInfo, ShortcutServiceInternal mShortcutServiceInternal,
            int callingUserId) {
        if (shortcutInfo == null || !shortcutInfo.isLongLived() || !shortcutInfo.isEnabled()) {
            return false;
        }
        return mShortcutServiceInternal.isSharingShortcut(callingUserId, "android",
                shortcutInfo.getPackage(), shortcutInfo.getId(), shortcutInfo.getUserId(),
                SHARING_FILTER);
    }

    /**
     * Only returns shortcut info if it's found and if it's a conversation shortcut.
     */
    ShortcutInfo getValidShortcutInfo(String shortcutId, String packageName, UserHandle user) {
        if (mLauncherAppsService == null) {
@@ -161,11 +176,7 @@ class ShortcutHelper {
            ShortcutInfo info = shortcuts != null && shortcuts.size() > 0
                    ? shortcuts.get(0)
                    : null;
            if (info == null || !info.isLongLived() || !info.isEnabled()) {
                return null;
            }
            if (mShortcutServiceInternal.isSharingShortcut(user.getIdentifier(),
                    "android", packageName, shortcutId, user.getIdentifier(), mSharingFilter)) {
            if (isConversationShortcut(info, mShortcutServiceInternal, user.getIdentifier())) {
                return info;
            }
            return null;
+3 −5
Original line number Diff line number Diff line
@@ -67,6 +67,7 @@ import com.android.internal.os.BackgroundThread;
import com.android.internal.telephony.SmsApplication;
import com.android.server.LocalServices;
import com.android.server.notification.NotificationManagerInternal;
import com.android.server.notification.ShortcutHelper;

import java.util.ArrayList;
import java.util.Collections;
@@ -497,10 +498,6 @@ public class DataManager {
                EventStore.CATEGORY_SHORTCUT_BASED, shortcutId);
    }

    private boolean isPersonShortcut(@NonNull ShortcutInfo shortcutInfo) {
        return shortcutInfo.getPersons() != null && shortcutInfo.getPersons().length != 0;
    }

    @VisibleForTesting
    @WorkerThread
    void addOrUpdateConversationInfo(@NonNull ShortcutInfo shortcutInfo) {
@@ -712,7 +709,8 @@ public class DataManager {
                @NonNull List<ShortcutInfo> shortcuts, @NonNull UserHandle user) {
            mInjector.getBackgroundExecutor().execute(() -> {
                for (ShortcutInfo shortcut : shortcuts) {
                    if (isPersonShortcut(shortcut)) {
                    if (ShortcutHelper.isConversationShortcut(
                            shortcut, mShortcutServiceInternal, user.getIdentifier())) {
                        addOrUpdateConversationInfo(shortcut);
                    }
                }
+2 −0
Original line number Diff line number Diff line
@@ -215,6 +215,8 @@ public final class DataManagerTest {
        mDataManager = new DataManager(mContext, mInjector);
        mDataManager.initialize();

        when(mShortcutServiceInternal.isSharingShortcut(anyInt(), anyString(), anyString(),
                anyString(), anyInt(), any())).thenReturn(true);
        verify(mShortcutServiceInternal).addShortcutChangeCallback(
                mShortcutChangeCallbackCaptor.capture());
        mShortcutChangeCallback = mShortcutChangeCallbackCaptor.getValue();
+12 −0
Original line number Diff line number Diff line
@@ -6074,6 +6074,9 @@ public class NotificationManagerServiceTest extends UiServiceTestCase {
        // Pretend the shortcut exists
        List<ShortcutInfo> shortcutInfos = new ArrayList<>();
        ShortcutInfo info = mock(ShortcutInfo.class);
        when(info.getPackage()).thenReturn(PKG);
        when(info.getId()).thenReturn("someshortcutId");
        when(info.getUserId()).thenReturn(USER_SYSTEM);
        when(info.isLongLived()).thenReturn(true);
        when(info.isEnabled()).thenReturn(true);
        shortcutInfos.add(info);
@@ -6137,6 +6140,9 @@ public class NotificationManagerServiceTest extends UiServiceTestCase {
        // Pretend the shortcut exists
        List<ShortcutInfo> shortcutInfos = new ArrayList<>();
        ShortcutInfo info = mock(ShortcutInfo.class);
        when(info.getPackage()).thenReturn(PKG);
        when(info.getId()).thenReturn("someshortcutId");
        when(info.getUserId()).thenReturn(USER_SYSTEM);
        when(info.isLongLived()).thenReturn(true);
        when(info.isEnabled()).thenReturn(true);
        shortcutInfos.add(info);
@@ -6483,6 +6489,9 @@ public class NotificationManagerServiceTest extends UiServiceTestCase {
        when(mPreferencesHelper.getConversations(anyString(), anyInt())).thenReturn(convos);

        ShortcutInfo si = mock(ShortcutInfo.class);
        when(si.getPackage()).thenReturn(PKG_P);
        when(si.getId()).thenReturn("convo");
        when(si.getUserId()).thenReturn(USER_SYSTEM);
        when(si.getShortLabel()).thenReturn("Hello");
        when(si.isLongLived()).thenReturn(true);
        when(si.isEnabled()).thenReturn(true);
@@ -6514,6 +6523,9 @@ public class NotificationManagerServiceTest extends UiServiceTestCase {
        when(mPreferencesHelper.getConversations(anyString(), anyInt())).thenReturn(convos);

        ShortcutInfo si = mock(ShortcutInfo.class);
        when(si.getPackage()).thenReturn(PKG_P);
        when(si.getId()).thenReturn("convo");
        when(si.getUserId()).thenReturn(USER_SYSTEM);
        when(si.getShortLabel()).thenReturn("Hello");
        when(si.isLongLived()).thenReturn(false);
        when(mLauncherApps.getShortcuts(any(), any())).thenReturn(Arrays.asList(si));
+12 −0
Original line number Diff line number Diff line
@@ -170,6 +170,9 @@ public class ShortcutHelperTest extends UiServiceTestCase {
    @Test
    public void testGetValidShortcutInfo_notLongLived() {
        ShortcutInfo si = mock(ShortcutInfo.class);
        when(si.getPackage()).thenReturn(PKG);
        when(si.getId()).thenReturn(SHORTCUT_ID);
        when(si.getUserId()).thenReturn(UserHandle.USER_SYSTEM);
        when(si.isLongLived()).thenReturn(false);
        when(si.isEnabled()).thenReturn(true);
        ArrayList<ShortcutInfo> shortcuts = new ArrayList<>();
@@ -184,6 +187,9 @@ public class ShortcutHelperTest extends UiServiceTestCase {
    @Test
    public void testGetValidShortcutInfo_notSharingShortcut() {
        ShortcutInfo si = mock(ShortcutInfo.class);
        when(si.getPackage()).thenReturn(PKG);
        when(si.getId()).thenReturn(SHORTCUT_ID);
        when(si.getUserId()).thenReturn(UserHandle.USER_SYSTEM);
        when(si.isLongLived()).thenReturn(true);
        when(si.isEnabled()).thenReturn(true);
        ArrayList<ShortcutInfo> shortcuts = new ArrayList<>();
@@ -198,6 +204,9 @@ public class ShortcutHelperTest extends UiServiceTestCase {
    @Test
    public void testGetValidShortcutInfo_notEnabled() {
        ShortcutInfo si = mock(ShortcutInfo.class);
        when(si.getPackage()).thenReturn(PKG);
        when(si.getId()).thenReturn(SHORTCUT_ID);
        when(si.getUserId()).thenReturn(UserHandle.USER_SYSTEM);
        when(si.isLongLived()).thenReturn(true);
        when(si.isEnabled()).thenReturn(false);
        ArrayList<ShortcutInfo> shortcuts = new ArrayList<>();
@@ -212,6 +221,9 @@ public class ShortcutHelperTest extends UiServiceTestCase {
    @Test
    public void testGetValidShortcutInfo_isValid() {
        ShortcutInfo si = mock(ShortcutInfo.class);
        when(si.getPackage()).thenReturn(PKG);
        when(si.getId()).thenReturn(SHORTCUT_ID);
        when(si.getUserId()).thenReturn(UserHandle.USER_SYSTEM);
        when(si.isLongLived()).thenReturn(true);
        when(si.isEnabled()).thenReturn(true);
        ArrayList<ShortcutInfo> shortcuts = new ArrayList<>();