diff --git a/core/java/android/content/pm/ShortcutInfo.java b/core/java/android/content/pm/ShortcutInfo.java index a4d891650c887..b4dcdf7e4e51b 100644 --- a/core/java/android/content/pm/ShortcutInfo.java +++ b/core/java/android/content/pm/ShortcutInfo.java @@ -1061,11 +1061,6 @@ public final class ShortcutInfo implements Parcelable { * Launcher apps should show the launcher icon for the returned activity alongside * this shortcut. * - *
When a shortcut is dynamic or manifest - * (i.e. either {@link #isDynamic()} or {@link #isDeclaredInManifest()} returns {@code TRUE}), - * then it should always have a non-null target activity. - * Otherwise it will return null. - * * @see Builder#setActivity */ @Nullable @@ -1372,7 +1367,7 @@ public final class ShortcutInfo implements Parcelable { } /** - * Return {@code TRUE} if a shortcut is pinned but neither manifest nor dynamic. + * @return true if pinned but neither static nor dynamic. * @hide */ public boolean isFloating() { diff --git a/services/core/java/com/android/server/pm/ShortcutPackage.java b/services/core/java/com/android/server/pm/ShortcutPackage.java index b74506229ff78..ddbc5fa59e166 100644 --- a/services/core/java/com/android/server/pm/ShortcutPackage.java +++ b/services/core/java/com/android/server/pm/ShortcutPackage.java @@ -259,11 +259,6 @@ class ShortcutPackage extends ShortcutPackageItem { for (int i = mShortcuts.size() - 1; i >= 0; i--) { final ShortcutInfo si = mShortcuts.valueAt(i); - if (si.isFloating()) { - si.setRank(0); - si.setActivity(null); - } - if (si.isAlive()) continue; if (removeList == null) { @@ -293,7 +288,6 @@ class ShortcutPackage extends ShortcutPackageItem { si.setTimestamp(now); si.clearFlags(ShortcutInfo.FLAG_DYNAMIC); si.setRank(0); // It may still be pinned, so clear the rank. - si.setActivity(null); } } if (changed) { @@ -361,7 +355,6 @@ class ShortcutPackage extends ShortcutPackageItem { if (oldShortcut.isPinned()) { oldShortcut.setRank(0); - oldShortcut.setActivity(null); oldShortcut.clearFlags(ShortcutInfo.FLAG_DYNAMIC | ShortcutInfo.FLAG_MANIFEST); if (disable) { oldShortcut.addFlags(ShortcutInfo.FLAG_DISABLED); @@ -602,10 +595,6 @@ class ShortcutPackage extends ShortcutPackageItem { for (int i = mShortcuts.size() - 1; i >= 0; i--) { final ShortcutInfo si = mShortcuts.valueAt(i); - - if (si.isFloating()) { - continue; // Ignore floating shortcuts, which are not tied to any activities. - } final ComponentName activity = si.getActivity(); if (checked.contains(activity)) { @@ -1368,10 +1357,6 @@ class ShortcutPackage extends ShortcutPackageItem { case TAG_SHORTCUT: final ShortcutInfo si = parseShortcut(parser, packageName, shortcutUser.getUserId()); - // Floating shortcut used to have target activities, but not anymore. - if (si.isFloating()) { // Not really needed by just in case. - si.setActivity(null); - } // Don't use addShortcut(), we don't need to save the icon. ret.mShortcuts.put(si.getId(), si); @@ -1478,6 +1463,7 @@ class ShortcutPackage extends ShortcutPackageItem { intents.clear(); intents.add(intentLegacy); } + return new ShortcutInfo( userId, id, packageName, activityComponent, /* icon =*/ null, title, titleResId, titleResName, text, textResId, textResName, @@ -1568,17 +1554,12 @@ class ShortcutPackage extends ShortcutPackageItem { Log.e(TAG_VERIFY, "Package " + getPackageName() + ": shortcut " + si.getId() + " is both dynamic and manifest at the same time."); } - if (!si.isFloating() && si.getActivity() == null) { + if (si.getActivity() == null) { failed = true; Log.e(TAG_VERIFY, "Package " + getPackageName() + ": shortcut " + si.getId() - + " is not floating, but has null activity."); + + " has null activity."); } - if (si.isFloating() && si.getActivity() != null) { - failed = true; - Log.e(TAG_VERIFY, "Package " + getPackageName() + ": shortcut " + si.getId() - + " is floating, but has non-null activity."); - } - if (!si.isFloating() && !si.isEnabled()) { + if ((si.isDynamic() || si.isManifestShortcut()) && !si.isEnabled()) { failed = true; Log.e(TAG_VERIFY, "Package " + getPackageName() + ": shortcut " + si.getId() + " is not floating, but is disabled."); @@ -1601,7 +1582,7 @@ class ShortcutPackage extends ShortcutPackageItem { } if (failed) { - mShortcutUser.mService.verifyError(); + throw new IllegalStateException("See logcat for errors"); } } diff --git a/services/core/java/com/android/server/pm/ShortcutService.java b/services/core/java/com/android/server/pm/ShortcutService.java index 86f755694f43c..c02ce6e0daeb4 100644 --- a/services/core/java/com/android/server/pm/ShortcutService.java +++ b/services/core/java/com/android/server/pm/ShortcutService.java @@ -129,7 +129,6 @@ import java.nio.charset.StandardCharsets; import java.util.ArrayList; import java.util.Collections; import java.util.List; -import java.util.Objects; import java.util.concurrent.atomic.AtomicBoolean; import java.util.function.Consumer; import java.util.function.Predicate; @@ -413,9 +412,6 @@ public class ShortcutService extends IShortcutService.Stub { @VisibleForTesting ShortcutService(Context context, Looper looper, boolean onlyForPackageManagerApis) { - if (DEBUG) { - Binder.LOG_RUNTIME_EXCEPTION = true; - } mContext = Preconditions.checkNotNull(context); LocalServices.addService(ShortcutServiceInternal.class, new LocalService()); mHandler = new Handler(looper); @@ -1778,9 +1774,6 @@ public class ShortcutService extends IShortcutService.Stub { // Note copyNonNullFieldsFrom() does the "updatable with?" check too. target.copyNonNullFieldsFrom(source); - if (target.isFloating()) { - target.setActivity(null); - } target.setTimestamp(injectCurrentTimeMillis()); if (replacingIcon) { @@ -2414,7 +2407,8 @@ public class ShortcutService extends IShortcutService.Stub { return false; } if (componentName != null) { - if (!Objects.equals(componentName, si.getActivity())) { + if (si.getActivity() != null + && !si.getActivity().equals(componentName)) { return false; } } @@ -3934,8 +3928,4 @@ public class ShortcutService extends IShortcutService.Stub { forEachLoadedUserLocked(u -> u.forAllPackageItems(ShortcutPackageItem::verifyStates)); } } - - void verifyError() { - Slog.e(TAG, "See logcat for errors"); - } } diff --git a/services/tests/servicestests/src/com/android/server/pm/BaseShortcutManagerTest.java b/services/tests/servicestests/src/com/android/server/pm/BaseShortcutManagerTest.java index dcaab76b1f535..10ca90207d85b 100644 --- a/services/tests/servicestests/src/com/android/server/pm/BaseShortcutManagerTest.java +++ b/services/tests/servicestests/src/com/android/server/pm/BaseShortcutManagerTest.java @@ -404,7 +404,6 @@ public abstract class BaseShortcutManagerTest extends InstrumentationTestCase { @Override boolean injectIsActivityEnabledAndExported(ComponentName activity, @UserIdInt int userId) { - assertNotNull(activity); return mEnabledActivityChecker.test(activity, userId); } @@ -450,11 +449,6 @@ public abstract class BaseShortcutManagerTest extends InstrumentationTestCase { // During tests, WTF is fatal. fail(message + " exception: " + th + "\n" + Log.getStackTraceString(th)); } - - @Override - void verifyError() { - fail("Verify error"); - } } /** ShortcutManager with injection override methods. */ diff --git a/services/tests/servicestests/src/com/android/server/pm/ShortcutManagerTest1.java b/services/tests/servicestests/src/com/android/server/pm/ShortcutManagerTest1.java index 97bcaf0a565a3..74c1ca5015c8a 100644 --- a/services/tests/servicestests/src/com/android/server/pm/ShortcutManagerTest1.java +++ b/services/tests/servicestests/src/com/android/server/pm/ShortcutManagerTest1.java @@ -1292,43 +1292,7 @@ public class ShortcutManagerTest1 extends BaseShortcutManagerTest { /* activity =*/ null, /* flags */ 0), getCallingUser()); }); - // Make sure floating shortcuts don't match with an activity. - // At this point, s1 is dynamic and pinned, so it still has a target activity. - runWithCaller(LAUNCHER_1, USER_0, () -> { - assertWith(mLauncherApps.getShortcuts(buildQuery( - /* time =*/ 0, - CALLING_PACKAGE_2, - /* activity =*/ new ComponentName(CALLING_PACKAGE_2, - ShortcutActivity2.class.getName()), - ShortcutQuery.FLAG_GET_PINNED), - getCallingUser())) - .haveIds("s3") - .areAllPinned() - .areAllDynamic() - .areAllWithActivity(new ComponentName(CALLING_PACKAGE_2, - ShortcutActivity2.class.getName())); - }); - - // Now remove as a dynamic, making it floating. - runWithCaller(CALLING_PACKAGE_2, USER_0, () -> { - mManager.removeDynamicShortcuts(list("s3")); - assertWith(mManager.getPinnedShortcuts()) - .selectFloating() - .areAllWithNoActivity(); - }); - - runWithCaller(LAUNCHER_1, USER_0, () -> { - // This shouldn't match now. - assertWith(mLauncherApps.getShortcuts(buildQuery( - /* time =*/ 0, - CALLING_PACKAGE_2, - /* activity =*/ new ComponentName(CALLING_PACKAGE_2, - ShortcutActivity2.class.getName()), - ShortcutQuery.FLAG_GET_PINNED), - getCallingUser())) - .isEmpty(); - }); - + // TODO More tests: pinned but dynamic. } public void testGetShortcuts_shortcutKinds() throws Exception { diff --git a/services/tests/servicestests/src/com/android/server/pm/ShortcutManagerTest2.java b/services/tests/servicestests/src/com/android/server/pm/ShortcutManagerTest2.java index 7486858eeaced..d25923c019cac 100644 --- a/services/tests/servicestests/src/com/android/server/pm/ShortcutManagerTest2.java +++ b/services/tests/servicestests/src/com/android/server/pm/ShortcutManagerTest2.java @@ -1052,7 +1052,7 @@ public class ShortcutManagerTest2 extends BaseShortcutManagerTest { assertEquals(CALLING_PACKAGE_1, si.getPackage()); assertEquals("id", si.getId()); - assertNull(si.getActivity()); // It's now floating, so no target activity. + assertEquals(ShortcutActivity2.class.getName(), si.getActivity().getClassName()); assertEquals(null, si.getIcon()); assertEquals("title", si.getTitle()); assertEquals("text", si.getText()); @@ -1116,7 +1116,7 @@ public class ShortcutManagerTest2 extends BaseShortcutManagerTest { assertEquals(CALLING_PACKAGE_1, si.getPackage()); assertEquals("id", si.getId()); - assertNull(si.getActivity()); // It's now floating, so no target activity. + assertEquals(ShortcutActivity2.class.getName(), si.getActivity().getClassName()); assertEquals(null, si.getIcon()); assertEquals(10, si.getTitleResId()); assertEquals("r10", si.getTitleResName());