下面列出了android.content.pm.ShortcutInfo#DISABLED_REASON_NOT_DISABLED 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
@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();
}
public int canRestoreTo(ShortcutService s, PackageInfo currentPackage, boolean anyVersionOkay) {
PackageManagerInternal pmi = LocalServices.getService(PackageManagerInternal.class);
if (!BackupUtils.signaturesMatch(mSigHashes, currentPackage, pmi)) {
Slog.w(TAG, "Can't restore: Package signature mismatch");
return ShortcutInfo.DISABLED_REASON_SIGNATURE_MISMATCH;
}
if (!ShortcutService.shouldBackupApp(currentPackage) || !mBackupSourceBackupAllowed) {
// "allowBackup" was true when backed up, but now false.
Slog.w(TAG, "Can't restore: package didn't or doesn't allow backup");
return ShortcutInfo.DISABLED_REASON_BACKUP_NOT_SUPPORTED;
}
if (!anyVersionOkay && (currentPackage.getLongVersionCode() < mBackupSourceVersionCode)) {
Slog.w(TAG, String.format(
"Can't restore: package current version %d < backed up version %d",
currentPackage.getLongVersionCode(), mBackupSourceVersionCode));
return ShortcutInfo.DISABLED_REASON_VERSION_LOWER;
}
return ShortcutInfo.DISABLED_REASON_NOT_DISABLED;
}
@Override
protected void onRestored(int restoreBlockReason) {
// For launcher, possible reasons here are DISABLED_REASON_SIGNATURE_MISMATCH or
// DISABLED_REASON_BACKUP_NOT_SUPPORTED.
// DISABLED_REASON_VERSION_LOWER will NOT happen because we don't check version
// code for launchers.
if (restoreBlockReason != ShortcutInfo.DISABLED_REASON_NOT_DISABLED) {
onRestoreBlocked();
}
}
@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;
}
}
private static ShortcutInfo createShortcutFromManifest(ShortcutService service,
@UserIdInt int userId, String id, String packageName, ComponentName activityComponent,
int titleResId, int textResId, int disabledMessageResId,
int rank, int iconResId, boolean enabled) {
final int flags =
(enabled ? ShortcutInfo.FLAG_MANIFEST : ShortcutInfo.FLAG_DISABLED)
| ShortcutInfo.FLAG_IMMUTABLE
| ((iconResId != 0) ? ShortcutInfo.FLAG_HAS_ICON_RES : 0);
final int disabledReason =
enabled ? ShortcutInfo.DISABLED_REASON_NOT_DISABLED
: ShortcutInfo.DISABLED_REASON_BY_APP;
// Note we don't need to set resource names here yet. They'll be set when they're about
// to be published.
return new ShortcutInfo(
userId,
id,
packageName,
activityComponent,
null, // icon
null, // title string
titleResId,
null, // title res name
null, // text string
textResId,
null, // text res name
null, // disabled message string
disabledMessageResId,
null, // disabled message res name
null, // categories
null, // intent
rank,
null, // extras
service.injectCurrentTimeMillis(),
flags,
iconResId,
null, // icon res name
null, // bitmap path
disabledReason);
}