Java Code Examples for android.content.pm.ShortcutInfo#DISABLED_REASON_NOT_DISABLED

The following examples show how to use android.content.pm.ShortcutInfo#DISABLED_REASON_NOT_DISABLED . 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 vote down vote up
@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: ShortcutPackageInfo.java    From android_9.0.0_r45 with Apache License 2.0 6 votes vote down vote up
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;
}
 
Example 3
Source File: ShortcutLauncher.java    From android_9.0.0_r45 with Apache License 2.0 5 votes vote down vote up
@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();
    }
}
 
Example 4
Source File: ShortcutPackage.java    From android_9.0.0_r45 with Apache License 2.0 5 votes vote down vote up
@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 5
Source File: ShortcutParser.java    From android_9.0.0_r45 with Apache License 2.0 4 votes vote down vote up
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);
}