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

Commit 7af2eac9 authored by Danning Chen's avatar Danning Chen Committed by Automerger Merge Worker
Browse files

Merge "Keep the conversation shortcut criteria in People Service consistent...

Merge "Keep the conversation shortcut criteria in People Service consistent with the one in Notification Manager" into rvc-dev am: 068558b4 am: 71af36bb

Change-Id: Idd31cf5bb3d989865ff77decdddecd0850f6792f
parents 791e7c85 71af36bb
Loading
Loading
Loading
Loading
+26 −15
Original line number Original line 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 static android.content.pm.LauncherApps.ShortcutQuery.FLAG_MATCH_PINNED;


import android.annotation.NonNull;
import android.annotation.NonNull;
import android.content.Intent;
import android.content.IntentFilter;
import android.content.IntentFilter;
import android.content.pm.LauncherApps;
import android.content.pm.LauncherApps;
import android.content.pm.ShortcutInfo;
import android.content.pm.ShortcutInfo;
@@ -41,9 +40,18 @@ import java.util.List;
/**
/**
 * Helper for querying shortcuts.
 * Helper for querying shortcuts.
 */
 */
class ShortcutHelper {
public class ShortcutHelper {
    private static final String TAG = "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.
     * Listener to call when a shortcut we're tracking has been removed.
     */
     */
@@ -54,7 +62,6 @@ class ShortcutHelper {
    private LauncherApps mLauncherAppsService;
    private LauncherApps mLauncherAppsService;
    private ShortcutListener mShortcutListener;
    private ShortcutListener mShortcutListener;
    private ShortcutServiceInternal mShortcutServiceInternal;
    private ShortcutServiceInternal mShortcutServiceInternal;
    private IntentFilter mSharingFilter;


    // Key: packageName Value: <shortcutId, notifId>
    // Key: packageName Value: <shortcutId, notifId>
    private HashMap<String, HashMap<String, String>> mActiveShortcutBubbles = new HashMap<>();
    private HashMap<String, HashMap<String, String>> mActiveShortcutBubbles = new HashMap<>();
@@ -122,12 +129,6 @@ class ShortcutHelper {
            ShortcutServiceInternal shortcutServiceInternal) {
            ShortcutServiceInternal shortcutServiceInternal) {
        mLauncherAppsService = launcherApps;
        mLauncherAppsService = launcherApps;
        mShortcutListener = listener;
        mShortcutListener = listener;
        mSharingFilter = new IntentFilter();
        try {
            mSharingFilter.addDataType("*/*");
        } catch (IntentFilter.MalformedMimeTypeException e) {
            Slog.e(TAG, "Bad mime type", e);
        }
        mShortcutServiceInternal = shortcutServiceInternal;
        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) {
    ShortcutInfo getValidShortcutInfo(String shortcutId, String packageName, UserHandle user) {
        if (mLauncherAppsService == null) {
        if (mLauncherAppsService == null) {
@@ -161,11 +176,7 @@ class ShortcutHelper {
            ShortcutInfo info = shortcuts != null && shortcuts.size() > 0
            ShortcutInfo info = shortcuts != null && shortcuts.size() > 0
                    ? shortcuts.get(0)
                    ? shortcuts.get(0)
                    : null;
                    : null;
            if (info == null || !info.isLongLived() || !info.isEnabled()) {
            if (isConversationShortcut(info, mShortcutServiceInternal, user.getIdentifier())) {
                return null;
            }
            if (mShortcutServiceInternal.isSharingShortcut(user.getIdentifier(),
                    "android", packageName, shortcutId, user.getIdentifier(), mSharingFilter)) {
                return info;
                return info;
            }
            }
            return null;
            return null;
+3 −5
Original line number Original line Diff line number Diff line
@@ -67,6 +67,7 @@ import com.android.internal.os.BackgroundThread;
import com.android.internal.telephony.SmsApplication;
import com.android.internal.telephony.SmsApplication;
import com.android.server.LocalServices;
import com.android.server.LocalServices;
import com.android.server.notification.NotificationManagerInternal;
import com.android.server.notification.NotificationManagerInternal;
import com.android.server.notification.ShortcutHelper;


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


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

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


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


        ShortcutInfo si = mock(ShortcutInfo.class);
        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.getShortLabel()).thenReturn("Hello");
        when(si.isLongLived()).thenReturn(true);
        when(si.isLongLived()).thenReturn(true);
        when(si.isEnabled()).thenReturn(true);
        when(si.isEnabled()).thenReturn(true);
@@ -6514,6 +6523,9 @@ public class NotificationManagerServiceTest extends UiServiceTestCase {
        when(mPreferencesHelper.getConversations(anyString(), anyInt())).thenReturn(convos);
        when(mPreferencesHelper.getConversations(anyString(), anyInt())).thenReturn(convos);


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