Search in sources :

Example 56 with ShortcutInfo

use of android.content.pm.ShortcutInfo in project android_frameworks_base by ResurrectionRemix.

the class ShortcutPackage method parseShortcut.

private static ShortcutInfo parseShortcut(XmlPullParser parser, String packageName, @UserIdInt int userId) throws IOException, XmlPullParserException {
    String id;
    ComponentName activityComponent;
    // Icon icon;
    String title;
    int titleResId;
    String titleResName;
    String text;
    int textResId;
    String textResName;
    String disabledMessage;
    int disabledMessageResId;
    String disabledMessageResName;
    Intent intentLegacy;
    PersistableBundle intentPersistableExtrasLegacy = null;
    ArrayList<Intent> intents = new ArrayList<>();
    int rank;
    PersistableBundle extras = null;
    long lastChangedTimestamp;
    int flags;
    int iconResId;
    String iconResName;
    String bitmapPath;
    ArraySet<String> categories = null;
    id = ShortcutService.parseStringAttribute(parser, ATTR_ID);
    activityComponent = ShortcutService.parseComponentNameAttribute(parser, ATTR_ACTIVITY);
    title = ShortcutService.parseStringAttribute(parser, ATTR_TITLE);
    titleResId = ShortcutService.parseIntAttribute(parser, ATTR_TITLE_RES_ID);
    titleResName = ShortcutService.parseStringAttribute(parser, ATTR_TITLE_RES_NAME);
    text = ShortcutService.parseStringAttribute(parser, ATTR_TEXT);
    textResId = ShortcutService.parseIntAttribute(parser, ATTR_TEXT_RES_ID);
    textResName = ShortcutService.parseStringAttribute(parser, ATTR_TEXT_RES_NAME);
    disabledMessage = ShortcutService.parseStringAttribute(parser, ATTR_DISABLED_MESSAGE);
    disabledMessageResId = ShortcutService.parseIntAttribute(parser, ATTR_DISABLED_MESSAGE_RES_ID);
    disabledMessageResName = ShortcutService.parseStringAttribute(parser, ATTR_DISABLED_MESSAGE_RES_NAME);
    intentLegacy = ShortcutService.parseIntentAttributeNoDefault(parser, ATTR_INTENT_LEGACY);
    rank = (int) ShortcutService.parseLongAttribute(parser, ATTR_RANK);
    lastChangedTimestamp = ShortcutService.parseLongAttribute(parser, ATTR_TIMESTAMP);
    flags = (int) ShortcutService.parseLongAttribute(parser, ATTR_FLAGS);
    iconResId = (int) ShortcutService.parseLongAttribute(parser, ATTR_ICON_RES_ID);
    iconResName = ShortcutService.parseStringAttribute(parser, ATTR_ICON_RES_NAME);
    bitmapPath = ShortcutService.parseStringAttribute(parser, ATTR_BITMAP_PATH);
    final int outerDepth = parser.getDepth();
    int type;
    while ((type = parser.next()) != XmlPullParser.END_DOCUMENT && (type != XmlPullParser.END_TAG || parser.getDepth() > outerDepth)) {
        if (type != XmlPullParser.START_TAG) {
            continue;
        }
        final int depth = parser.getDepth();
        final String tag = parser.getName();
        if (ShortcutService.DEBUG_LOAD) {
            Slog.d(TAG, String.format("  depth=%d type=%d name=%s", depth, type, tag));
        }
        switch(tag) {
            case TAG_INTENT_EXTRAS_LEGACY:
                intentPersistableExtrasLegacy = PersistableBundle.restoreFromXml(parser);
                continue;
            case TAG_INTENT:
                intents.add(parseIntent(parser));
                continue;
            case TAG_EXTRAS:
                extras = PersistableBundle.restoreFromXml(parser);
                continue;
            case TAG_CATEGORIES:
                // This just contains string-array.
                continue;
            case TAG_STRING_ARRAY_XMLUTILS:
                if (NAME_CATEGORIES.equals(ShortcutService.parseStringAttribute(parser, ATTR_NAME_XMLUTILS))) {
                    final String[] ar = XmlUtils.readThisStringArrayXml(parser, TAG_STRING_ARRAY_XMLUTILS, null);
                    categories = new ArraySet<>(ar.length);
                    for (int i = 0; i < ar.length; i++) {
                        categories.add(ar[i]);
                    }
                }
                continue;
        }
        throw ShortcutService.throwForInvalidTag(depth, tag);
    }
    if (intentLegacy != null) {
        // For the legacy file format which supported only one intent per shortcut.
        ShortcutInfo.setIntentExtras(intentLegacy, intentPersistableExtrasLegacy);
        intents.clear();
        intents.add(intentLegacy);
    }
    return new ShortcutInfo(userId, id, packageName, activityComponent, /* icon =*/
    null, title, titleResId, titleResName, text, textResId, textResName, disabledMessage, disabledMessageResId, disabledMessageResName, categories, intents.toArray(new Intent[intents.size()]), rank, extras, lastChangedTimestamp, flags, iconResId, iconResName, bitmapPath);
}
Also used : PersistableBundle(android.os.PersistableBundle) ShortcutInfo(android.content.pm.ShortcutInfo) ArrayList(java.util.ArrayList) ComponentName(android.content.ComponentName) Intent(android.content.Intent)

Example 57 with ShortcutInfo

use of android.content.pm.ShortcutInfo in project android_frameworks_base by ResurrectionRemix.

the class ShortcutPackage method refreshPinnedFlags.

/**
     * Called after a launcher updates the pinned set.  For each shortcut in this package,
     * set FLAG_PINNED if any launcher has pinned it.  Otherwise, clear it.
     *
     * <p>Then remove all shortcuts that are not dynamic and no longer pinned either.
     */
public void refreshPinnedFlags() {
    // First, un-pin all shortcuts
    for (int i = mShortcuts.size() - 1; i >= 0; i--) {
        mShortcuts.valueAt(i).clearFlags(ShortcutInfo.FLAG_PINNED);
    }
    // Then, for the pinned set for each launcher, set the pin flag one by one.
    mShortcutUser.mService.getUserShortcutsLocked(getPackageUserId()).forAllLaunchers(launcherShortcuts -> {
        final ArraySet<String> pinned = launcherShortcuts.getPinnedShortcutIds(getPackageName(), getPackageUserId());
        if (pinned == null || pinned.size() == 0) {
            return;
        }
        for (int i = pinned.size() - 1; i >= 0; i--) {
            final String id = pinned.valueAt(i);
            final ShortcutInfo si = mShortcuts.get(id);
            if (si == null) {
                continue;
            }
            si.addFlags(ShortcutInfo.FLAG_PINNED);
        }
    });
    // Lastly, remove the ones that are no longer pinned nor dynamic.
    removeOrphans();
}
Also used : ShortcutInfo(android.content.pm.ShortcutInfo)

Example 58 with ShortcutInfo

use of android.content.pm.ShortcutInfo in project android_frameworks_base by ResurrectionRemix.

the class ShortcutPackage method loadFromXml.

public static ShortcutPackage loadFromXml(ShortcutService s, ShortcutUser shortcutUser, XmlPullParser parser, boolean fromBackup) throws IOException, XmlPullParserException {
    final String packageName = ShortcutService.parseStringAttribute(parser, ATTR_NAME);
    final ShortcutPackage ret = new ShortcutPackage(shortcutUser, shortcutUser.getUserId(), packageName);
    ret.mApiCallCount = ShortcutService.parseIntAttribute(parser, ATTR_CALL_COUNT);
    ret.mLastResetTime = ShortcutService.parseLongAttribute(parser, ATTR_LAST_RESET);
    final int outerDepth = parser.getDepth();
    int type;
    while ((type = parser.next()) != XmlPullParser.END_DOCUMENT && (type != XmlPullParser.END_TAG || parser.getDepth() > outerDepth)) {
        if (type != XmlPullParser.START_TAG) {
            continue;
        }
        final int depth = parser.getDepth();
        final String tag = parser.getName();
        if (depth == outerDepth + 1) {
            switch(tag) {
                case ShortcutPackageInfo.TAG_ROOT:
                    ret.getPackageInfo().loadFromXml(parser, fromBackup);
                    continue;
                case TAG_SHORTCUT:
                    final ShortcutInfo si = parseShortcut(parser, packageName, shortcutUser.getUserId());
                    // Don't use addShortcut(), we don't need to save the icon.
                    ret.mShortcuts.put(si.getId(), si);
                    continue;
            }
        }
        ShortcutService.warnForInvalidTag(depth, tag);
    }
    return ret;
}
Also used : ShortcutInfo(android.content.pm.ShortcutInfo)

Example 59 with ShortcutInfo

use of android.content.pm.ShortcutInfo in project android_frameworks_base by ResurrectionRemix.

the class ShortcutPackage method findAll.

/**
     * Find all shortcuts that match {@code query}.
     *
     * This will also provide a "view" for each launcher -- a non-dynamic shortcut that's not pinned
     * by the calling launcher will not be included in the result, and also "isPinned" will be
     * adjusted for the caller too.
     */
public void findAll(@NonNull List<ShortcutInfo> result, @Nullable Predicate<ShortcutInfo> query, int cloneFlag, @Nullable String callingLauncher, int launcherUserId) {
    if (getPackageInfo().isShadow()) {
        // Restored and the app not installed yet, so don't return any.
        return;
    }
    final ShortcutService s = mShortcutUser.mService;
    // Set of pinned shortcuts by the calling launcher.
    final ArraySet<String> pinnedByCallerSet = (callingLauncher == null) ? null : s.getLauncherShortcutsLocked(callingLauncher, getPackageUserId(), launcherUserId).getPinnedShortcutIds(getPackageName(), getPackageUserId());
    for (int i = 0; i < mShortcuts.size(); i++) {
        final ShortcutInfo si = mShortcuts.valueAt(i);
        // Need to adjust PINNED flag depending on the caller.
        // Basically if the caller is a launcher (callingLauncher != null) and the launcher
        // isn't pinning it, then we need to clear PINNED for this caller.
        final boolean isPinnedByCaller = (callingLauncher == null) || ((pinnedByCallerSet != null) && pinnedByCallerSet.contains(si.getId()));
        if (si.isFloating()) {
            if (!isPinnedByCaller) {
                continue;
            }
        }
        final ShortcutInfo clone = si.clone(cloneFlag);
        // since it may check isPinned.
        if (!isPinnedByCaller) {
            clone.clearFlags(ShortcutInfo.FLAG_PINNED);
        }
        if (query == null || query.test(clone)) {
            result.add(clone);
        }
    }
}
Also used : ShortcutInfo(android.content.pm.ShortcutInfo)

Example 60 with ShortcutInfo

use of android.content.pm.ShortcutInfo in project android_frameworks_base by ResurrectionRemix.

the class ShortcutPackage method resolveResourceStrings.

/**
     * For all the text fields, refresh the string values if they're from resources.
     */
public void resolveResourceStrings() {
    final ShortcutService s = mShortcutUser.mService;
    boolean changed = false;
    Resources publisherRes = null;
    for (int i = mShortcuts.size() - 1; i >= 0; i--) {
        final ShortcutInfo si = mShortcuts.valueAt(i);
        if (si.hasStringResources()) {
            changed = true;
            if (publisherRes == null) {
                publisherRes = getPackageResources();
                if (publisherRes == null) {
                    // Resources couldn't be loaded.
                    break;
                }
            }
            si.resolveResourceStrings(publisherRes);
            si.setTimestamp(s.injectCurrentTimeMillis());
        }
    }
    if (changed) {
        s.packageShortcutsChanged(getPackageName(), getPackageUserId());
    }
}
Also used : ShortcutInfo(android.content.pm.ShortcutInfo) Resources(android.content.res.Resources)

Aggregations

ShortcutInfo (android.content.pm.ShortcutInfo)324 ComponentName (android.content.ComponentName)144 PersistableBundle (android.os.PersistableBundle)48 ArrayList (java.util.ArrayList)46 Intent (android.content.Intent)44 Icon (android.graphics.drawable.Icon)32 List (java.util.List)17 Matchers.anyString (org.mockito.Matchers.anyString)16 LocaleList (android.os.LocaleList)12 File (java.io.File)12 Nullable (android.annotation.Nullable)8 ShortcutQuery (android.content.pm.LauncherApps.ShortcutQuery)8 Resources (android.content.res.Resources)8 Bundle (android.os.Bundle)8 ArrayMap (android.util.ArrayMap)8 PackageWithUser (com.android.server.pm.ShortcutUser.PackageWithUser)8 ShortcutManagerTestUtils.makeBundle (com.android.server.pm.shortcutmanagertest.ShortcutManagerTestUtils.makeBundle)8 IOException (java.io.IOException)8 ArraySet (android.util.ArraySet)5 Manifest.permission (android.Manifest.permission)4