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

Commit 17e94691 authored by Makoto Onuki's avatar Makoto Onuki Committed by android-build-merger
Browse files

Merge \\"Don\\'t accept resource references in string fields\\" into nyc-mr1-dev am: 6fa0e4d5

am: 3d3e2e2b

Change-Id: Ib5a83728239cfa074fb9800b76bc217dcf990b30
parents 8dd615fd 3d3e2e2b
Loading
Loading
Loading
Loading
+14 −4
Original line number Original line Diff line number Diff line
@@ -29,6 +29,7 @@ import android.util.ArraySet;
import android.util.AttributeSet;
import android.util.AttributeSet;
import android.util.Log;
import android.util.Log;
import android.util.Slog;
import android.util.Slog;
import android.util.TypedValue;
import android.util.Xml;
import android.util.Xml;


import com.android.internal.R;
import com.android.internal.R;
@@ -260,7 +261,12 @@ public class ShortcutParser {
        final TypedArray sa = service.mContext.getResources().obtainAttributes(attrs,
        final TypedArray sa = service.mContext.getResources().obtainAttributes(attrs,
                R.styleable.ShortcutCategories);
                R.styleable.ShortcutCategories);
        try {
        try {
            return sa.getString(R.styleable.ShortcutCategories_name);
            if (sa.getType(R.styleable.ShortcutCategories_name) == TypedValue.TYPE_STRING) {
                return sa.getNonResourceString(R.styleable.ShortcutCategories_name);
            } else {
                Log.w(TAG, "android:name for shortcut category must be string literal.");
                return null;
            }
        } finally {
        } finally {
            sa.recycle();
            sa.recycle();
        }
        }
@@ -272,7 +278,11 @@ public class ShortcutParser {
        final TypedArray sa = service.mContext.getResources().obtainAttributes(attrs,
        final TypedArray sa = service.mContext.getResources().obtainAttributes(attrs,
                R.styleable.Shortcut);
                R.styleable.Shortcut);
        try {
        try {
            final String id = sa.getString(R.styleable.Shortcut_shortcutId);
            if (sa.getType(R.styleable.Shortcut_shortcutId) != TypedValue.TYPE_STRING) {
                Log.w(TAG, "android:shortcutId must be string literal. activity=" + activity);
                return null;
            }
            final String id = sa.getNonResourceString(R.styleable.Shortcut_shortcutId);
            final boolean enabled = sa.getBoolean(R.styleable.Shortcut_enabled, true);
            final boolean enabled = sa.getBoolean(R.styleable.Shortcut_enabled, true);
            final int iconResId = sa.getResourceId(R.styleable.Shortcut_icon, 0);
            final int iconResId = sa.getResourceId(R.styleable.Shortcut_icon, 0);
            final int titleResId = sa.getResourceId(R.styleable.Shortcut_shortcutShortLabel, 0);
            final int titleResId = sa.getResourceId(R.styleable.Shortcut_shortcutShortLabel, 0);
@@ -281,11 +291,11 @@ public class ShortcutParser {
                    R.styleable.Shortcut_shortcutDisabledMessage, 0);
                    R.styleable.Shortcut_shortcutDisabledMessage, 0);


            if (TextUtils.isEmpty(id)) {
            if (TextUtils.isEmpty(id)) {
                Slog.w(TAG, "Shortcut ID must be provided. activity=" + activity);
                Log.w(TAG, "android:shortcutId must be provided. activity=" + activity);
                return null;
                return null;
            }
            }
            if (titleResId == 0) {
            if (titleResId == 0) {
                Slog.w(TAG, "Shortcut title must be provided. activity=" + activity);
                Log.w(TAG, "android:shortcutShortLabel must be provided. activity=" + activity);
                return null;
                return null;
            }
            }


+6 −0
Original line number Original line Diff line number Diff line
@@ -18,6 +18,10 @@
        android:shortcutId="manifest-shortcut-3"
        android:shortcutId="manifest-shortcut-3"
        android:shortcutShortLabel="@string/shortcut_title1"
        android:shortcutShortLabel="@string/shortcut_title1"
    />
    />
    <shortcut
        android:shortcutId="@string/shortcut_title1"
        android:shortcutShortLabel="@string/shortcut_title1"
    />
    <shortcut
    <shortcut
        android:shortcutId="x3"
        android:shortcutId="x3"
        android:shortcutShortLabel="@string/shortcut_title1"
        android:shortcutShortLabel="@string/shortcut_title1"
@@ -26,5 +30,7 @@
            android:action="android.intent.action.VIEW"
            android:action="android.intent.action.VIEW"
            >
            >
        </intent>
        </intent>
        <categories android:name="@string/shortcut_title1" />
        <categories android:name="cat2" />
    </shortcut>
    </shortcut>
</shortcuts>
</shortcuts>
+18 −9
Original line number Original line Diff line number Diff line
@@ -5859,9 +5859,11 @@ public class ShortcutManagerTest1 extends BaseShortcutManagerTest {


        // Only the valid one is published.
        // Only the valid one is published.
        runWithCaller(CALLING_PACKAGE_1, USER_0, () -> {
        runWithCaller(CALLING_PACKAGE_1, USER_0, () -> {
            assertShortcutIds(assertAllManifest(assertAllImmutable(assertAllEnabled(
            assertWith(getCallerShortcuts())
                    mManager.getManifestShortcuts()))),
                    .areAllManifest()
                    "x1");
                    .areAllImmutable()
                    .areAllEnabled()
                    .haveIds("x1");
        });
        });


        // Package 1 updated, which has one valid manifest shortcut and one invalid.
        // Package 1 updated, which has one valid manifest shortcut and one invalid.
@@ -5874,9 +5876,11 @@ public class ShortcutManagerTest1 extends BaseShortcutManagerTest {


        // Only the valid one is published.
        // Only the valid one is published.
        runWithCaller(CALLING_PACKAGE_1, USER_0, () -> {
        runWithCaller(CALLING_PACKAGE_1, USER_0, () -> {
            assertShortcutIds(assertAllManifest(assertAllImmutable(assertAllEnabled(
            assertWith(getCallerShortcuts())
                    mManager.getManifestShortcuts()))),
                    .areAllManifest()
                    "x2");
                    .areAllImmutable()
                    .areAllEnabled()
                    .haveIds("x2");
        });
        });


        // Package 1 updated, which has one valid manifest shortcut and one invalid.
        // Package 1 updated, which has one valid manifest shortcut and one invalid.
@@ -5889,9 +5893,14 @@ public class ShortcutManagerTest1 extends BaseShortcutManagerTest {


        // Only the valid one is published.
        // Only the valid one is published.
        runWithCaller(CALLING_PACKAGE_1, USER_0, () -> {
        runWithCaller(CALLING_PACKAGE_1, USER_0, () -> {
            assertShortcutIds(assertAllManifest(assertAllImmutable(assertAllEnabled(
            assertWith(getCallerShortcuts())
                    mManager.getManifestShortcuts()))),
                    .areAllManifest()
                    "x3");
                    .areAllImmutable()
                    .areAllEnabled()
                    .haveIds("x3")
                    .forShortcutWithId("x3", si -> {
                        assertEquals(set("cat2"), si.getCategories());
                     });
        });
        });
    }
    }