Search in sources :

Example 66 with ShortcutInfo

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

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

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

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)

Example 68 with ShortcutInfo

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

the class ShortcutPackage method clearAllImplicitRanks.

/** Clears the implicit ranks for all shortcuts. */
public void clearAllImplicitRanks() {
    for (int i = mShortcuts.size() - 1; i >= 0; i--) {
        final ShortcutInfo si = mShortcuts.valueAt(i);
        si.clearImplicitRankAndRankChangedFlag();
    }
}
Also used : ShortcutInfo(android.content.pm.ShortcutInfo)

Example 69 with ShortcutInfo

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

the class ShortcutPackage method dump.

public void dump(@NonNull PrintWriter pw, @NonNull String prefix) {
    pw.println();
    pw.print(prefix);
    pw.print("Package: ");
    pw.print(getPackageName());
    pw.print("  UID: ");
    pw.print(mPackageUid);
    pw.println();
    pw.print(prefix);
    pw.print("  ");
    pw.print("Calls: ");
    pw.print(getApiCallCount());
    pw.println();
    // getApiCallCount() may have updated mLastKnownForegroundElapsedTime.
    pw.print(prefix);
    pw.print("  ");
    pw.print("Last known FG: ");
    pw.print(mLastKnownForegroundElapsedTime);
    pw.println();
    // This should be after getApiCallCount(), which may update it.
    pw.print(prefix);
    pw.print("  ");
    pw.print("Last reset: [");
    pw.print(mLastResetTime);
    pw.print("] ");
    pw.print(ShortcutService.formatTime(mLastResetTime));
    pw.println();
    getPackageInfo().dump(pw, prefix + "  ");
    pw.println();
    pw.print(prefix);
    pw.println("  Shortcuts:");
    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);
        pw.print(prefix);
        pw.print("    ");
        pw.println(si.toInsecureString());
        if (si.getBitmapPath() != null) {
            final long len = new File(si.getBitmapPath()).length();
            pw.print(prefix);
            pw.print("      ");
            pw.print("bitmap size=");
            pw.println(len);
            totalBitmapSize += len;
        }
    }
    pw.print(prefix);
    pw.print("  ");
    pw.print("Total bitmap size: ");
    pw.print(totalBitmapSize);
    pw.print(" (");
    pw.print(Formatter.formatFileSize(mShortcutUser.mService.mContext, totalBitmapSize));
    pw.println(")");
}
Also used : ShortcutInfo(android.content.pm.ShortcutInfo) File(java.io.File)

Example 70 with ShortcutInfo

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

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)

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