Search in sources :

Example 91 with ShortcutInfo

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

the class ShortcutPackage method addOrUpdateDynamicShortcut.

/**
     * Add a shortcut, or update one with the same ID, with taking over existing flags.
     *
     * It checks the max number of dynamic shortcuts.
     */
public void addOrUpdateDynamicShortcut(@NonNull ShortcutInfo newShortcut) {
    Preconditions.checkArgument(newShortcut.isEnabled(), "add/setDynamicShortcuts() cannot publish disabled shortcuts");
    newShortcut.addFlags(ShortcutInfo.FLAG_DYNAMIC);
    final ShortcutInfo oldShortcut = mShortcuts.get(newShortcut.getId());
    final boolean wasPinned;
    if (oldShortcut == null) {
        wasPinned = false;
    } else {
        // It's an update case.
        // Make sure the target is updatable. (i.e. should be mutable.)
        oldShortcut.ensureUpdatableWith(newShortcut);
        wasPinned = oldShortcut.isPinned();
    }
    // If it was originally pinned, the new one should be pinned too.
    if (wasPinned) {
        newShortcut.addFlags(ShortcutInfo.FLAG_PINNED);
    }
    addShortcutInner(newShortcut);
}
Also used : ShortcutInfo(android.content.pm.ShortcutInfo)

Example 92 with ShortcutInfo

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

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 93 with ShortcutInfo

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

the class ShortcutPackage method dumpCheckin.

@Override
public JSONObject dumpCheckin(boolean clear) throws JSONException {
    final JSONObject result = super.dumpCheckin(clear);
    int numDynamic = 0;
    int numPinned = 0;
    int numManifest = 0;
    int numBitmaps = 0;
    long totalBitmapSize = 0;
    final ArrayMap<String, ShortcutInfo> shortcuts = mShortcuts;
    final int size = shortcuts.size();
    for (int i = 0; i < size; i++) {
        final ShortcutInfo si = shortcuts.valueAt(i);
        if (si.isDynamic())
            numDynamic++;
        if (si.isDeclaredInManifest())
            numManifest++;
        if (si.isPinned())
            numPinned++;
        if (si.getBitmapPath() != null) {
            numBitmaps++;
            totalBitmapSize += new File(si.getBitmapPath()).length();
        }
    }
    result.put(KEY_DYNAMIC, numDynamic);
    result.put(KEY_MANIFEST, numManifest);
    result.put(KEY_PINNED, numPinned);
    result.put(KEY_BITMAPS, numBitmaps);
    result.put(KEY_BITMAP_BYTES, totalBitmapSize);
    return result;
}
Also used : JSONObject(org.json.JSONObject) ShortcutInfo(android.content.pm.ShortcutInfo) File(java.io.File)

Example 94 with ShortcutInfo

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

the class ShortcutPackage method sortShortcutsToActivities.

/**
     * Build a list of shortcuts for each target activity and return as a map. The result won't
     * contain "floating" shortcuts because they don't belong on any activities.
     */
private ArrayMap<ComponentName, ArrayList<ShortcutInfo>> sortShortcutsToActivities() {
    final ArrayMap<ComponentName, ArrayList<ShortcutInfo>> activitiesToShortcuts = new ArrayMap<>();
    for (int i = mShortcuts.size() - 1; i >= 0; i--) {
        final ShortcutInfo si = mShortcuts.valueAt(i);
        if (si.isFloating()) {
            // Ignore floating shortcuts, which are not tied to any activities.
            continue;
        }
        final ComponentName activity = si.getActivity();
        ArrayList<ShortcutInfo> list = activitiesToShortcuts.get(activity);
        if (list == null) {
            list = new ArrayList<>();
            activitiesToShortcuts.put(activity, list);
        }
        list.add(si);
    }
    return activitiesToShortcuts;
}
Also used : ShortcutInfo(android.content.pm.ShortcutInfo) ArrayList(java.util.ArrayList) ArrayMap(android.util.ArrayMap) ComponentName(android.content.ComponentName)

Example 95 with ShortcutInfo

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

the class ShortcutPackage method deleteAllDynamicShortcuts.

/**
     * Remove all dynamic shortcuts.
     */
public void deleteAllDynamicShortcuts() {
    final long now = mShortcutUser.mService.injectCurrentTimeMillis();
    boolean changed = false;
    for (int i = mShortcuts.size() - 1; i >= 0; i--) {
        final ShortcutInfo si = mShortcuts.valueAt(i);
        if (si.isDynamic()) {
            changed = true;
            si.setTimestamp(now);
            si.clearFlags(ShortcutInfo.FLAG_DYNAMIC);
            // It may still be pinned, so clear the rank.
            si.setRank(0);
        }
    }
    if (changed) {
        removeOrphans();
    }
}
Also used : ShortcutInfo(android.content.pm.ShortcutInfo)

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