Search in sources :

Example 71 with ShortcutInfo

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

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

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

the class ShortcutPackage method deleteShortcutInner.

private ShortcutInfo deleteShortcutInner(@NonNull String id) {
    final ShortcutInfo shortcut = mShortcuts.remove(id);
    if (shortcut != null) {
        mShortcutUser.mService.removeIcon(getPackageUserId(), shortcut);
        shortcut.clearFlags(ShortcutInfo.FLAG_DYNAMIC | ShortcutInfo.FLAG_PINNED | ShortcutInfo.FLAG_MANIFEST);
    }
    return shortcut;
}
Also used : ShortcutInfo(android.content.pm.ShortcutInfo)

Example 73 with ShortcutInfo

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

the class ShortcutPackage method enableWithId.

public void enableWithId(@NonNull String shortcutId) {
    final ShortcutInfo shortcut = mShortcuts.get(shortcutId);
    if (shortcut != null) {
        ensureNotImmutable(shortcut);
        shortcut.clearFlags(ShortcutInfo.FLAG_DISABLED);
    }
}
Also used : ShortcutInfo(android.content.pm.ShortcutInfo)

Example 74 with ShortcutInfo

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

the class ShortcutService method fillInDefaultActivity.

/**
     * When a shortcut has no target activity, set the default one from the package.
     */
private void fillInDefaultActivity(List<ShortcutInfo> shortcuts) {
    ComponentName defaultActivity = null;
    for (int i = shortcuts.size() - 1; i >= 0; i--) {
        final ShortcutInfo si = shortcuts.get(i);
        if (si.getActivity() == null) {
            if (defaultActivity == null) {
                defaultActivity = injectGetDefaultMainActivity(si.getPackage(), si.getUserId());
                Preconditions.checkState(defaultActivity != null, "Launcher activity not found for package " + si.getPackage());
            }
            si.setActivity(defaultActivity);
        }
    }
}
Also used : ShortcutInfo(android.content.pm.ShortcutInfo) ComponentName(android.content.ComponentName)

Example 75 with ShortcutInfo

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

the class ShortcutManagerTestUtils method parceled.

public static ShortcutInfo parceled(ShortcutInfo si) {
    Parcel p = Parcel.obtain();
    p.writeParcelable(si, 0);
    p.setDataPosition(0);
    ShortcutInfo si2 = p.readParcelable(ShortcutManagerTestUtils.class.getClassLoader());
    p.recycle();
    return si2;
}
Also used : ShortcutInfo(android.content.pm.ShortcutInfo) Parcel(android.os.Parcel)

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