Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit a96f6a0a authored by Makoto Onuki's avatar Makoto Onuki Committed by Android (Google) Code Review
Browse files

Merge "Return canned messages from getDisabledMessage for..."

parents fe932c78 b1588c0d
Loading
Loading
Loading
Loading
+25 −4
Original line number Diff line number Diff line
@@ -20,8 +20,8 @@ import android.annotation.IntDef;
import android.annotation.NonNull;
import android.annotation.Nullable;
import android.annotation.SdkConstant;
import android.annotation.SystemService;
import android.annotation.SdkConstant.SdkConstantType;
import android.annotation.SystemService;
import android.annotation.TestApi;
import android.app.PendingIntent;
import android.appwidget.AppWidgetManager;
@@ -37,10 +37,10 @@ import android.content.res.Resources;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.Rect;
import android.graphics.drawable.AdaptiveIconDrawable;
import android.graphics.drawable.BitmapDrawable;
import android.graphics.drawable.Drawable;
import android.graphics.drawable.Icon;
import android.graphics.drawable.AdaptiveIconDrawable;
import android.os.Bundle;
import android.os.Handler;
import android.os.Looper;
@@ -678,6 +678,21 @@ public class LauncherApps {
        }
    }

    private List<ShortcutInfo> maybeUpdateDisabledMessage(List<ShortcutInfo> shortcuts) {
        if (shortcuts == null) {
            return null;
        }
        for (int i = shortcuts.size() - 1; i >= 0; i--) {
            final ShortcutInfo si = shortcuts.get(i);
            final String message = ShortcutInfo.getDisabledReasonForRestoreIssue(mContext,
                    si.getDisabledReason());
            if (message != null) {
                si.setDisabledMessage(message);
            }
        }
        return shortcuts;
    }

    /**
     * Returns {@link ShortcutInfo}s that match {@code query}.
     *
@@ -698,10 +713,16 @@ public class LauncherApps {
            @NonNull UserHandle user) {
        logErrorForInvalidProfileAccess(user);
        try {
            return mService.getShortcuts(mContext.getPackageName(),
            // Note this is the only case we need to update the disabled message for shortcuts
            // that weren't restored.
            // The restore problem messages are only shown by the user, and publishers will never
            // see them. The only other API that the launcher gets shortcuts is the shortcut
            // changed callback, but that only returns shortcuts with the "key" information, so
            // that won't return disabled message.
            return maybeUpdateDisabledMessage(mService.getShortcuts(mContext.getPackageName(),
                    query.mChangedSince, query.mPackage, query.mShortcutIds, query.mActivity,
                    query.mQueryFlags, user)
                    .getList();
                    .getList());
        } catch (RemoteException e) {
            throw e.rethrowFromSystemServer();
        }
+36 −3
Original line number Diff line number Diff line
@@ -224,8 +224,11 @@ public final class ShortcutInfo implements Parcelable {
    @Retention(RetentionPolicy.SOURCE)
    public @interface DisabledReason{}

    /** @hide */
    public static String getDisabledReasonLabel(@DisabledReason int disabledReason) {
    /**
     * Return a label for disabled reasons, which are *not* supposed to be shown to the user.
     * @hide
     */
    public static String getDisabledReasonDebugString(@DisabledReason int disabledReason) {
        switch (disabledReason) {
            case DISABLED_REASON_NOT_DISABLED:
                return "[Not disabled]";
@@ -245,6 +248,36 @@ public final class ShortcutInfo implements Parcelable {
        return "[Disabled: unknown reason:" + disabledReason + "]";
    }

    /**
     * Return a label for a disabled reason for shortcuts that are disabled due to a backup and
     * restore issue. If the reason is not due to backup & restore, then it'll return null.
     *
     * This method returns localized, user-facing strings, which will be returned by
     * {@link #getDisabledMessage()}.
     *
     * @hide
     */
    public static String getDisabledReasonForRestoreIssue(Context context,
            @DisabledReason int disabledReason) {
        final Resources res = context.getResources();

        switch (disabledReason) {
            case DISABLED_REASON_VERSION_LOWER:
                return res.getString(
                        com.android.internal.R.string.shortcut_restored_on_lower_version);
            case DISABLED_REASON_BACKUP_NOT_SUPPORTED:
                return res.getString(
                        com.android.internal.R.string.shortcut_restore_not_supported);
            case DISABLED_REASON_SIGNATURE_MISMATCH:
                return res.getString(
                        com.android.internal.R.string.shortcut_restore_signature_mismatch);
            case DISABLED_REASON_OTHER_RESTORE_ISSUE:
                return res.getString(
                        com.android.internal.R.string.shortcut_restore_unknown_issue);
        }
        return null;
    }

    /** @hide */
    public static boolean isDisabledForRestoreIssue(@DisabledReason int disabledReason) {
        return disabledReason >= DISABLED_REASON_RESTORE_ISSUE_START;
@@ -2042,7 +2075,7 @@ public final class ShortcutInfo implements Parcelable {
        addIndentOrComma(sb, indent);

        sb.append("disabledReason=");
        sb.append(getDisabledReasonLabel(mDisabledReason));
        sb.append(getDisabledReasonDebugString(mDisabledReason));

        addIndentOrComma(sb, indent);

+24 −0
Original line number Diff line number Diff line
@@ -4735,4 +4735,28 @@

    <!-- Format string for indicating there is more content in a slice view -->
    <string name="slice_more_content">+ <xliff:g id="number" example="5">%1$d</xliff:g></string>

    <!--
    A toast message shown when an app shortcut that was restored from a previous device is clicked,
    but it cannot be started because the shortcut was created by a newer version of the app.
    -->
    <string name="shortcut_restored_on_lower_version">This shortcut requires latest app</string>

    <!--
    A toast message shown when an app shortcut that was restored from a previous device is clicked,
    but it cannot be started because the shortcut was created by an app that doesn't support backup
    and restore.
    -->
    <string name="shortcut_restore_not_supported">Couldn\u2019t restore shortcut because app doesn\u2019t support backup and restore</string>

    <!--
    A toast message shown when an app shortcut that was restored from a previous device is clicked,
    but it cannot be started because the shortcut was created by an app with a different signature.
    -->
    <string name="shortcut_restore_signature_mismatch">Couldn\u2019t restore shortcut because of app signature mismatch</string>

    <!--
    A toast message shown when an app shortcut that wasn't restored due to an unknown issue is clicked,
    -->
    <string name="shortcut_restore_unknown_issue">Couldn\u2019t restore shortcut</string>
</resources>
+5 −0
Original line number Diff line number Diff line
@@ -3123,4 +3123,9 @@
  <java-symbol type="dimen" name="slice_icon_size" />
  <java-symbol type="dimen" name="slice_padding" />
  <java-symbol type="string" name="slice_more_content" />

  <java-symbol type="string" name="shortcut_restored_on_lower_version" />
  <java-symbol type="string" name="shortcut_restore_not_supported" />
  <java-symbol type="string" name="shortcut_restore_signature_mismatch" />
  <java-symbol type="string" name="shortcut_restore_unknown_issue" />
</resources>
+1 −1
Original line number Diff line number Diff line
@@ -123,7 +123,7 @@ abstract class ShortcutPackageItem {
        if (ShortcutService.DEBUG) {
            Slog.d(TAG, String.format("Restoring package: %s/u%d (version=%d) %s for u%d",
                    mPackageName, mPackageUserId, currentVersionCode,
                    ShortcutInfo.getDisabledReasonLabel(restoreBlockReason),
                    ShortcutInfo.getDisabledReasonDebugString(restoreBlockReason),
                    getOwnerUserId()));
        }

Loading