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

Commit fb059fc0 authored by Pinyao Ting's avatar Pinyao Ting
Browse files

Various fixes in ShortcutService

1. Currently AppSearchSession#setSchema is only invoked when the schema
hasn't been created. The correct logic should be, call setSchema if the
schema version on the device is older than current.

2. Add null check on the call-site of ShortcutPackage#getShortcutById,
the return value is generally non-null (on misses it simply return an
empty list), the only case it can be null is when there was an
exception thrown from AppSearch.

3. Update ShortcutManagerTest10 in comply with security fix in
LauncherAppService#getShortcutConfigActivityIntent

Bug: 151359749
Test: atest ShortcutManagerTest1 ShortcutManagerTest2
    ShortcutManagerTest3 ShortcutManagerTest4 ShortcutManagerTest5
    ShortcutManagerTest6 ShortcutManagerTest7 ShortcutManagerTest8
    ShortcutManagerTest9 ShortcutManagerTest10 ShortcutManagerTest11
    ShortcutManagerTest12
Test: atest CtsShortcutManagerTestCases
Change-Id: I214b0e9c8030f45cff5e6451733bf853f6303030
parent 252d85cf
Loading
Loading
Loading
Loading
+15 −10
Original line number Original line Diff line number Diff line
@@ -663,12 +663,14 @@ class ShortcutPackage extends ShortcutPackageItem {
        });
        });
        // Then, update the pinned state if necessary.
        // Then, update the pinned state if necessary.
        final List<ShortcutInfo> pinned = getShortcutById(pinnedShortcuts);
        final List<ShortcutInfo> pinned = getShortcutById(pinnedShortcuts);
        if (pinned != null) {
            pinned.forEach(si -> {
            pinned.forEach(si -> {
                if (!si.isPinned()) {
                if (!si.isPinned()) {
                    si.addFlags(ShortcutInfo.FLAG_PINNED);
                    si.addFlags(ShortcutInfo.FLAG_PINNED);
                }
                }
            });
            });
            saveShortcut(pinned);
            saveShortcut(pinned);
        }
        forEachShortcutMutateIf(AppSearchShortcutInfo.QUERY_IS_PINNED, si -> {
        forEachShortcutMutateIf(AppSearchShortcutInfo.QUERY_IS_PINNED, si -> {
            if (!pinnedShortcuts.contains(si.getId()) && si.isPinned()) {
            if (!pinnedShortcuts.contains(si.getId()) && si.isPinned()) {
                si.clearFlags(ShortcutInfo.FLAG_PINNED);
                si.clearFlags(ShortcutInfo.FLAG_PINNED);
@@ -826,11 +828,13 @@ class ShortcutPackage extends ShortcutPackageItem {
                : s.getLauncherShortcutsLocked(callingLauncher, getPackageUserId(), launcherUserId)
                : s.getLauncherShortcutsLocked(callingLauncher, getPackageUserId(), launcherUserId)
                        .getPinnedShortcutIds(getPackageName(), getPackageUserId());
                        .getPinnedShortcutIds(getPackageName(), getPackageUserId());
        final List<ShortcutInfo> shortcuts = getShortcutById(ids);
        final List<ShortcutInfo> shortcuts = getShortcutById(ids);
        if (shortcuts != null) {
            for (ShortcutInfo si : shortcuts) {
            for (ShortcutInfo si : shortcuts) {
                filter(result, query, cloneFlag, callingLauncher, pinnedByCallerSet,
                filter(result, query, cloneFlag, callingLauncher, pinnedByCallerSet,
                        getPinnedByAnyLauncher, si);
                        getPinnedByAnyLauncher, si);
            }
            }
        }
        }
    }


    /**
    /**
     * Find all pinned shortcuts that match {@code query}.
     * Find all pinned shortcuts that match {@code query}.
@@ -1903,7 +1907,8 @@ class ShortcutPackage extends ShortcutPackageItem {
        final ShortcutPackage ret = new ShortcutPackage(shortcutUser,
        final ShortcutPackage ret = new ShortcutPackage(shortcutUser,
                shortcutUser.getUserId(), packageName);
                shortcutUser.getUserId(), packageName);


        ret.mIsInitilized = ShortcutService.parseIntAttribute(parser, ATTR_SCHEMA_VERSON, 0) > 0;
        ret.mIsInitilized = ShortcutService.parseIntAttribute(parser, ATTR_SCHEMA_VERSON, 0)
                == AppSearchShortcutInfo.SCHEMA_VERSION;
        ret.mApiCallCount =
        ret.mApiCallCount =
                ShortcutService.parseIntAttribute(parser, ATTR_CALL_COUNT);
                ShortcutService.parseIntAttribute(parser, ATTR_CALL_COUNT);
        ret.mLastResetTime =
        ret.mLastResetTime =
+8 −0
Original line number Original line Diff line number Diff line
@@ -125,6 +125,7 @@ import java.io.IOException;
import java.io.InputStreamReader;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
import java.util.HashMap;
import java.util.HashSet;
import java.util.HashSet;
import java.util.LinkedHashMap;
import java.util.LinkedHashMap;
@@ -2598,6 +2599,13 @@ public abstract class BaseShortcutManagerTest extends InstrumentationTestCase {
        }).when(mMockPackageManagerInternal).getHomeActivitiesAsUser(any(List.class), eq(userId));
        }).when(mMockPackageManagerInternal).getHomeActivitiesAsUser(any(List.class), eq(userId));
    }
    }


    protected void prepareIntentActivities(ComponentName cn) {
        when(mMockPackageManagerInternal.queryIntentActivities(
                anyOrNull(Intent.class), anyStringOrNull(), anyInt(), anyInt(), anyInt()))
                .thenReturn(Collections.singletonList(
                        ri(cn.getPackageName(), cn.getClassName(), false, 0)));
    }

    protected static ComponentName cn(String packageName, String name) {
    protected static ComponentName cn(String packageName, String name) {
        return new ComponentName(packageName, name);
        return new ComponentName(packageName, name);
    }
    }
+1 −0
Original line number Original line Diff line number Diff line
@@ -159,6 +159,7 @@ public class ShortcutManagerTest10 extends BaseShortcutManagerTest {


    public void testStartConfigActivity_defaultLauncher() {
    public void testStartConfigActivity_defaultLauncher() {
        LauncherActivityInfo info = setupMockActivityInfo();
        LauncherActivityInfo info = setupMockActivityInfo();
        prepareIntentActivities(info.getComponentName());
        setDefaultLauncher(USER_0, LAUNCHER_1);
        setDefaultLauncher(USER_0, LAUNCHER_1);
        runWithCaller(LAUNCHER_1, USER_0, () ->
        runWithCaller(LAUNCHER_1, USER_0, () ->
            assertNotNull(mLauncherApps.getShortcutConfigActivityIntent(info))
            assertNotNull(mLauncherApps.getShortcutConfigActivityIntent(info))