Search in sources :

Example 11 with ShortcutInfo

use of android.content.pm.ShortcutInfo in project platform_frameworks_base by android.

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

use of android.content.pm.ShortcutInfo in project platform_frameworks_base by android.

the class ShortcutPackage method verifyStates.

@Override
public void verifyStates() {
    super.verifyStates();
    boolean failed = false;
    final ArrayMap<ComponentName, ArrayList<ShortcutInfo>> all = sortShortcutsToActivities();
    // Make sure each activity won't have more than max shortcuts.
    for (int outer = all.size() - 1; outer >= 0; outer--) {
        final ArrayList<ShortcutInfo> list = all.valueAt(outer);
        if (list.size() > mShortcutUser.mService.getMaxActivityShortcuts()) {
            failed = true;
            Log.e(TAG_VERIFY, "Package " + getPackageName() + ": activity " + all.keyAt(outer) + " has " + all.valueAt(outer).size() + " shortcuts.");
        }
        // Sort by rank.
        Collections.sort(list, (a, b) -> Integer.compare(a.getRank(), b.getRank()));
        // Split into two arrays for each kind.
        final ArrayList<ShortcutInfo> dynamicList = new ArrayList<>(list);
        dynamicList.removeIf((si) -> !si.isDynamic());
        final ArrayList<ShortcutInfo> manifestList = new ArrayList<>(list);
        dynamicList.removeIf((si) -> !si.isManifestShortcut());
        verifyRanksSequential(dynamicList);
        verifyRanksSequential(manifestList);
    }
    // Verify each shortcut's status.
    for (int i = mShortcuts.size() - 1; i >= 0; i--) {
        final ShortcutInfo si = mShortcuts.valueAt(i);
        if (!(si.isDeclaredInManifest() || si.isDynamic() || si.isPinned())) {
            failed = true;
            Log.e(TAG_VERIFY, "Package " + getPackageName() + ": shortcut " + si.getId() + " is not manifest, dynamic or pinned.");
        }
        if (si.isDeclaredInManifest() && si.isDynamic()) {
            failed = true;
            Log.e(TAG_VERIFY, "Package " + getPackageName() + ": shortcut " + si.getId() + " is both dynamic and manifest at the same time.");
        }
        if (si.getActivity() == null) {
            failed = true;
            Log.e(TAG_VERIFY, "Package " + getPackageName() + ": shortcut " + si.getId() + " has null activity.");
        }
        if ((si.isDynamic() || si.isManifestShortcut()) && !si.isEnabled()) {
            failed = true;
            Log.e(TAG_VERIFY, "Package " + getPackageName() + ": shortcut " + si.getId() + " is not floating, but is disabled.");
        }
        if (si.isFloating() && si.getRank() != 0) {
            failed = true;
            Log.e(TAG_VERIFY, "Package " + getPackageName() + ": shortcut " + si.getId() + " is floating, but has rank=" + si.getRank());
        }
        if (si.getIcon() != null) {
            failed = true;
            Log.e(TAG_VERIFY, "Package " + getPackageName() + ": shortcut " + si.getId() + " still has an icon");
        }
        if (si.hasIconFile() && si.hasIconResource()) {
            failed = true;
            Log.e(TAG_VERIFY, "Package " + getPackageName() + ": shortcut " + si.getId() + " has both resource and bitmap icons");
        }
    }
    if (failed) {
        throw new IllegalStateException("See logcat for errors");
    }
}
Also used : ShortcutInfo(android.content.pm.ShortcutInfo) ArrayList(java.util.ArrayList) ComponentName(android.content.ComponentName)

Example 13 with ShortcutInfo

use of android.content.pm.ShortcutInfo in project platform_frameworks_base by android.

the class ShortcutPackage method verifyRanksSequential.

private boolean verifyRanksSequential(List<ShortcutInfo> list) {
    boolean failed = false;
    for (int i = 0; i < list.size(); i++) {
        final ShortcutInfo si = list.get(i);
        if (si.getRank() != i) {
            failed = true;
            Log.e(TAG_VERIFY, "Package " + getPackageName() + ": shortcut " + si.getId() + " rank=" + si.getRank() + " but expected to be " + i);
        }
    }
    return failed;
}
Also used : ShortcutInfo(android.content.pm.ShortcutInfo)

Example 14 with ShortcutInfo

use of android.content.pm.ShortcutInfo in project platform_frameworks_base by android.

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

use of android.content.pm.ShortcutInfo in project platform_frameworks_base by android.

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)

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