Java Code Examples for android.content.pm.ShortcutInfo#clearFlags()
The following examples show how to use
android.content.pm.ShortcutInfo#clearFlags() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ShortcutPackage.java From android_9.0.0_r45 with Apache License 2.0 | 6 votes |
@Override protected void onRestored(int restoreBlockReason) { // Shortcuts have been restored. // - Unshadow all shortcuts. // - Set disabled reason. // - Disable if needed. for (int i = mShortcuts.size() - 1; i >= 0; i--) { ShortcutInfo si = mShortcuts.valueAt(i); si.clearFlags(ShortcutInfo.FLAG_SHADOW); si.setDisabledReason(restoreBlockReason); if (restoreBlockReason != ShortcutInfo.DISABLED_REASON_NOT_DISABLED) { si.addFlags(ShortcutInfo.FLAG_DISABLED); } } // Because some launchers may not have been restored (e.g. allowBackup=false), // we need to re-calculate the pinned shortcuts. refreshPinnedFlags(); }
Example 2
Source File: ShortcutPackage.java From android_9.0.0_r45 with Apache License 2.0 | 6 votes |
/** * Remove all dynamic shortcuts. */ public void deleteAllDynamicShortcuts(boolean ignoreInvisible) { 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() && (!ignoreInvisible || si.isVisibleToPublisher())) { changed = true; si.setTimestamp(now); si.clearFlags(ShortcutInfo.FLAG_DYNAMIC); si.setRank(0); // It may still be pinned, so clear the rank. } } if (changed) { removeOrphans(); } }
Example 3
Source File: ShortcutBitmapSaver.java From android_9.0.0_r45 with Apache License 2.0 | 5 votes |
public void removeIcon(ShortcutInfo shortcut) { // Do not remove the actual bitmap file yet, because if the device crashes before saving // the XML we'd lose the icon. We just remove all dangling files after saving the XML. shortcut.setIconResourceId(0); shortcut.setIconResName(null); shortcut.setBitmapPath(null); shortcut.clearFlags(ShortcutInfo.FLAG_HAS_ICON_FILE | ShortcutInfo.FLAG_ADAPTIVE_BITMAP | ShortcutInfo.FLAG_HAS_ICON_RES | ShortcutInfo.FLAG_ICON_FILE_PENDING_SAVE); }
Example 4
Source File: ShortcutPackage.java From android_9.0.0_r45 with Apache License 2.0 | 5 votes |
/** * Delete a shortcut by ID. This will *always* remove it even if it's immutable or invisible. */ private ShortcutInfo forceDeleteShortcutInner(@NonNull String id) { final ShortcutInfo shortcut = mShortcuts.remove(id); if (shortcut != null) { mShortcutUser.mService.removeIconLocked(shortcut); shortcut.clearFlags(ShortcutInfo.FLAG_DYNAMIC | ShortcutInfo.FLAG_PINNED | ShortcutInfo.FLAG_MANIFEST); } return shortcut; }
Example 5
Source File: ShortcutPackage.java From android_9.0.0_r45 with Apache License 2.0 | 5 votes |
@Nullable private ShortcutInfo deleteOrDisableWithId(@NonNull String shortcutId, boolean disable, boolean overrideImmutable, boolean ignoreInvisible, int disabledReason) { Preconditions.checkState( (disable == (disabledReason != ShortcutInfo.DISABLED_REASON_NOT_DISABLED)), "disable and disabledReason disagree: " + disable + " vs " + disabledReason); final ShortcutInfo oldShortcut = mShortcuts.get(shortcutId); if (oldShortcut == null || !oldShortcut.isEnabled() && (ignoreInvisible && !oldShortcut.isVisibleToPublisher())) { return null; // Doesn't exist or already disabled. } if (!overrideImmutable) { ensureNotImmutable(oldShortcut, /*ignoreInvisible=*/ true); } if (oldShortcut.isPinned()) { oldShortcut.setRank(0); oldShortcut.clearFlags(ShortcutInfo.FLAG_DYNAMIC | ShortcutInfo.FLAG_MANIFEST); if (disable) { oldShortcut.addFlags(ShortcutInfo.FLAG_DISABLED); // Do not overwrite the disabled reason if one is alreay set. if (oldShortcut.getDisabledReason() == ShortcutInfo.DISABLED_REASON_NOT_DISABLED) { oldShortcut.setDisabledReason(disabledReason); } } oldShortcut.setTimestamp(mShortcutUser.mService.injectCurrentTimeMillis()); // See ShortcutRequestPinProcessor.directPinShortcut(). if (mShortcutUser.mService.isDummyMainActivity(oldShortcut.getActivity())) { oldShortcut.setActivity(null); } return oldShortcut; } else { forceDeleteShortcutInner(shortcutId); return null; } }
Example 6
Source File: ShortcutPackage.java From android_9.0.0_r45 with Apache License 2.0 | 5 votes |
public void enableWithId(@NonNull String shortcutId) { final ShortcutInfo shortcut = mShortcuts.get(shortcutId); if (shortcut != null) { ensureNotImmutable(shortcut, /*ignoreInvisible=*/ true); shortcut.clearFlags(ShortcutInfo.FLAG_DISABLED); shortcut.setDisabledReason(ShortcutInfo.DISABLED_REASON_NOT_DISABLED); } }
Example 7
Source File: ShortcutRequestPinProcessor.java From android_9.0.0_r45 with Apache License 2.0 | 4 votes |
/** * Handle {@link android.content.pm.ShortcutManager#requestPinShortcut)}. */ @NonNull private PinItemRequest requestPinShortcutLocked(ShortcutInfo inShortcut, IntentSender resultIntentOriginal, Pair<ComponentName, Integer> confirmActivity) { final ShortcutPackage ps = mService.getPackageShortcutsForPublisherLocked( inShortcut.getPackage(), inShortcut.getUserId()); final ShortcutInfo existing = ps.findShortcutById(inShortcut.getId()); final boolean existsAlready = existing != null; final boolean existingIsVisible = existsAlready && existing.isVisibleToPublisher(); if (DEBUG) { Slog.d(TAG, "requestPinnedShortcut: package=" + inShortcut.getPackage() + " existsAlready=" + existsAlready + " existingIsVisible=" + existingIsVisible + " shortcut=" + inShortcut.toInsecureString()); } // This is the shortcut that'll be sent to the launcher. final ShortcutInfo shortcutForLauncher; final String launcherPackage = confirmActivity.first.getPackageName(); final int launcherUserId = confirmActivity.second; IntentSender resultIntentToSend = resultIntentOriginal; if (existsAlready) { validateExistingShortcut(existing); final boolean isAlreadyPinned = mService.getLauncherShortcutsLocked( launcherPackage, existing.getUserId(), launcherUserId).hasPinned(existing); if (isAlreadyPinned) { // When the shortcut is already pinned by this launcher, the request will always // succeed, so just send the result at this point. sendResultIntent(resultIntentOriginal, null); // So, do not send the intent again. resultIntentToSend = null; } // Pass a clone, not the original. // Note this will remove the intent and icons. shortcutForLauncher = existing.clone(ShortcutInfo.CLONE_REMOVE_FOR_LAUNCHER); if (!isAlreadyPinned) { // FLAG_PINNED may still be set, if it's pinned by other launchers. shortcutForLauncher.clearFlags(ShortcutInfo.FLAG_PINNED); } } else { // If the shortcut has no default activity, try to set the main activity. // But in the request-pin case, it's optional, so it's okay even if the caller // has no default activity. if (inShortcut.getActivity() == null) { inShortcut.setActivity(mService.injectGetDefaultMainActivity( inShortcut.getPackage(), inShortcut.getUserId())); } // It doesn't exist, so it must have all mandatory fields. mService.validateShortcutForPinRequest(inShortcut); // Initialize the ShortcutInfo for pending approval. inShortcut.resolveResourceStrings(mService.injectGetResourcesForApplicationAsUser( inShortcut.getPackage(), inShortcut.getUserId())); if (DEBUG) { Slog.d(TAG, "Resolved shortcut=" + inShortcut.toInsecureString()); } // We should strip out the intent, but should preserve the icon. shortcutForLauncher = inShortcut.clone( ShortcutInfo.CLONE_REMOVE_FOR_LAUNCHER_APPROVAL); } if (DEBUG) { Slog.d(TAG, "Sending to launcher=" + shortcutForLauncher.toInsecureString()); } // Create a request object. final PinShortcutRequestInner inner = new PinShortcutRequestInner(this, inShortcut, shortcutForLauncher, resultIntentToSend, launcherPackage, launcherUserId, mService.injectGetPackageUid(launcherPackage, launcherUserId), existsAlready); return new PinItemRequest(inner, PinItemRequest.REQUEST_TYPE_SHORTCUT); }
Example 8
Source File: ShortcutPackage.java From android_9.0.0_r45 with Apache License 2.0 | 4 votes |
/** * 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, boolean getPinnedByAnyLauncher) { 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 (!getPinnedByAnyLauncher) { if (si.isFloating()) { if (!isPinnedByCaller) { continue; } } } final ShortcutInfo clone = si.clone(cloneFlag); // Fix up isPinned for the caller. Note we need to do it before the "test" callback, // since it may check isPinned. // However, if getPinnedByAnyLauncher is set, we do it after the test. if (!getPinnedByAnyLauncher) { if (!isPinnedByCaller) { clone.clearFlags(ShortcutInfo.FLAG_PINNED); } } if (query == null || query.test(clone)) { if (!isPinnedByCaller) { clone.clearFlags(ShortcutInfo.FLAG_PINNED); } result.add(clone); } } }