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

Commit bb031e15 authored by András Kurucz's avatar András Kurucz Committed by Android (Google) Code Review
Browse files

Merge changes from topic "presubmit-am-bdeb5af3ebb64c3b9d2305a5c57271d2" into tm-qpr-dev-plus-aosp

* changes:
  [automerge] Truncate ShortcutInfo Id 2p: 8a5223fc
  Truncate ShortcutInfo Id
parents 43c82f05 f5dc1c9a
Loading
Loading
Loading
Loading
+17 −3
Original line number Original line Diff line number Diff line
@@ -285,6 +285,12 @@ public final class ShortcutInfo implements Parcelable {
     */
     */
    public static final int DISABLED_REASON_OTHER_RESTORE_ISSUE = 103;
    public static final int DISABLED_REASON_OTHER_RESTORE_ISSUE = 103;


    /**
     * The maximum length of Shortcut ID. IDs will be truncated at this limit.
     * @hide
     */
    public static final int MAX_ID_LENGTH = 1000;

    /** @hide */
    /** @hide */
    @IntDef(prefix = { "DISABLED_REASON_" }, value = {
    @IntDef(prefix = { "DISABLED_REASON_" }, value = {
            DISABLED_REASON_NOT_DISABLED,
            DISABLED_REASON_NOT_DISABLED,
@@ -477,8 +483,7 @@ public final class ShortcutInfo implements Parcelable {


    private ShortcutInfo(Builder b) {
    private ShortcutInfo(Builder b) {
        mUserId = b.mContext.getUserId();
        mUserId = b.mContext.getUserId();

        mId = getSafeId(Preconditions.checkStringNotEmpty(b.mId, "Shortcut ID must be provided"));
        mId = Preconditions.checkStringNotEmpty(b.mId, "Shortcut ID must be provided");


        // Note we can't do other null checks here because SM.updateShortcuts() takes partial
        // Note we can't do other null checks here because SM.updateShortcuts() takes partial
        // information.
        // information.
@@ -584,6 +589,14 @@ public final class ShortcutInfo implements Parcelable {
        return ret;
        return ret;
    }
    }


    @NonNull
    private static String getSafeId(@NonNull String id) {
        if (id.length() > MAX_ID_LENGTH) {
            return id.substring(0, MAX_ID_LENGTH);
        }
        return id;
    }

    /**
    /**
     * Throws if any of the mandatory fields is not set.
     * Throws if any of the mandatory fields is not set.
     *
     *
@@ -2342,7 +2355,8 @@ public final class ShortcutInfo implements Parcelable {
        final ClassLoader cl = getClass().getClassLoader();
        final ClassLoader cl = getClass().getClassLoader();


        mUserId = source.readInt();
        mUserId = source.readInt();
        mId = source.readString8();
        mId = getSafeId(Preconditions.checkStringNotEmpty(source.readString8(),
                "Shortcut ID must be provided"));
        mPackageName = source.readString8();
        mPackageName = source.readString8();
        mActivity = source.readParcelable(cl, android.content.ComponentName.class);
        mActivity = source.readParcelable(cl, android.content.ComponentName.class);
        mFlags = source.readInt();
        mFlags = source.readInt();
+9 −0
Original line number Original line Diff line number Diff line
@@ -228,6 +228,15 @@ public class ShortcutManagerTest2 extends BaseShortcutManagerTest {
                });
                });
    }
    }


    public void testShortcutIdTruncated() {
        ShortcutInfo si = new ShortcutInfo.Builder(getTestContext(),
                "s".repeat(Short.MAX_VALUE)).build();

        assertTrue(
                "id must be truncated to MAX_ID_LENGTH",
                si.getId().length() <= ShortcutInfo.MAX_ID_LENGTH);
    }

    public void testShortcutInfoParcel() {
    public void testShortcutInfoParcel() {
        setCaller(CALLING_PACKAGE_1, USER_10);
        setCaller(CALLING_PACKAGE_1, USER_10);
        ShortcutInfo si = parceled(new ShortcutInfo.Builder(mClientContext)
        ShortcutInfo si = parceled(new ShortcutInfo.Builder(mClientContext)