Loading services/core/java/com/android/server/pm/ShortcutPackage.java +14 −2 Original line number Diff line number Diff line Loading @@ -361,6 +361,11 @@ class ShortcutPackage extends ShortcutPackageItem { } oldShortcut.setTimestamp(mShortcutUser.mService.injectCurrentTimeMillis()); // See ShortcutRequestPinProcessor.directPinShortcut(). if (mShortcutUser.mService.isDummyMainActivity(oldShortcut.getActivity())) { oldShortcut.setActivity(null); } return oldShortcut; } else { deleteShortcutInner(shortcutId); Loading Loading @@ -1515,6 +1520,8 @@ class ShortcutPackage extends ShortcutPackageItem { boolean failed = false; final ShortcutService s = mShortcutUser.mService; final ArrayMap<ComponentName, ArrayList<ShortcutInfo>> all = sortShortcutsToActivities(); Loading Loading @@ -1554,10 +1561,10 @@ class ShortcutPackage extends ShortcutPackageItem { Log.e(TAG_VERIFY, "Package " + getPackageName() + ": shortcut " + si.getId() + " is both dynamic and manifest at the same time."); } if (si.getActivity() == null) { if (si.getActivity() == null && !si.isFloating()) { failed = true; Log.e(TAG_VERIFY, "Package " + getPackageName() + ": shortcut " + si.getId() + " has null activity."); + " has null activity, but not floating."); } if ((si.isDynamic() || si.isManifestShortcut()) && !si.isEnabled()) { failed = true; Loading @@ -1579,6 +1586,11 @@ class ShortcutPackage extends ShortcutPackageItem { Log.e(TAG_VERIFY, "Package " + getPackageName() + ": shortcut " + si.getId() + " has both resource and bitmap icons"); } if (s.isDummyMainActivity(si.getActivity())) { failed = true; Log.e(TAG_VERIFY, "Package " + getPackageName() + ": shortcut " + si.getId() + " has a dummy target activity"); } } if (failed) { Loading services/core/java/com/android/server/pm/ShortcutRequestPinProcessor.java +16 −4 Original line number Diff line number Diff line Loading @@ -16,7 +16,6 @@ package com.android.server.pm; import android.annotation.Nullable; import android.app.PendingIntent; import android.appwidget.AppWidgetProviderInfo; import android.content.ComponentName; import android.content.Intent; Loading Loading @@ -209,7 +208,7 @@ class ShortcutRequestPinProcessor { final boolean existsAlready = existing != null; if (DEBUG) { Slog.d(TAG, "requestPinnedShortcut package=" + inShortcut.getPackage() Slog.d(TAG, "requestPinnedShortcut: package=" + inShortcut.getPackage() + " existsAlready=" + existsAlready + " shortcut=" + inShortcut.toInsecureString()); } Loading Loading @@ -237,6 +236,14 @@ class ShortcutRequestPinProcessor { // FLAG_PINNED is still set, if it's pinned by other launchers. shortcutForLauncher.clearFlags(ShortcutInfo.FLAG_PINNED); } else { // If the shortcut has no default activity, try to set the main activity. // But in the request-pin case, it's optional, so it's okay even if the caller // has no default activity. if (inShortcut.getActivity() == null) { inShortcut.setActivity(mService.injectGetDefaultMainActivity( inShortcut.getPackage(), inShortcut.getUserId())); } // It doesn't exist, so it must have all mandatory fields. mService.validateShortcutForPinRequest(inShortcut); Loading @@ -244,12 +251,15 @@ class ShortcutRequestPinProcessor { inShortcut.resolveResourceStrings(mService.injectGetResourcesForApplicationAsUser( inShortcut.getPackage(), inShortcut.getUserId())); if (DEBUG) { Slog.d(TAG, "resolved shortcut=" + inShortcut.toInsecureString()); Slog.d(TAG, "Resolved shortcut=" + inShortcut.toInsecureString()); } // We should strip out the intent, but should preserve the icon. shortcutForLauncher = inShortcut.clone( ShortcutInfo.CLONE_REMOVE_FOR_LAUNCHER_APPROVAL); } if (DEBUG) { Slog.d(TAG, "Sending to launcher=" + shortcutForLauncher.toInsecureString()); } // Create a request object. final PinShortcutRequestInner inner = Loading Loading @@ -360,7 +370,9 @@ class ShortcutRequestPinProcessor { if (DEBUG) { Slog.d(TAG, "Temporarily adding " + shortcutId + " as dynamic"); } // Add as a dynamic shortcut. // Add as a dynamic shortcut. In order for a shortcut to be dynamic, it must // have a target activity, so we set a dummy here. It's later removed // in deleteDynamicWithId(). if (original.getActivity() == null) { original.setActivity(mService.getDummyMainActivity(appPackageName)); } Loading services/core/java/com/android/server/pm/ShortcutService.java +8 −8 Original line number Diff line number Diff line Loading @@ -1604,7 +1604,7 @@ public class ShortcutService extends IShortcutService.Stub { private void fixUpIncomingShortcutInfo(@NonNull ShortcutInfo shortcut, boolean forUpdate, boolean forPinRequest) { Preconditions.checkNotNull(shortcut, "Null shortcut detected"); if (!forPinRequest && shortcut.getActivity() != null) { if (shortcut.getActivity() != null) { Preconditions.checkState( shortcut.getPackage().equals(shortcut.getActivity().getPackageName()), "Cannot publish shortcut: activity " + shortcut.getActivity() + " does not" Loading @@ -1618,10 +1618,8 @@ public class ShortcutService extends IShortcutService.Stub { if (!forUpdate) { shortcut.enforceMandatoryFields(/* forPinned= */ forPinRequest); if (!forPinRequest) { Preconditions.checkArgument( injectIsMainActivity(shortcut.getActivity(), shortcut.getUserId()), "Cannot publish shortcut: " + shortcut.getActivity() + " is not main activity"); Preconditions.checkState(shortcut.getActivity() != null, "Cannot publish shortcut: target activity is not set"); } } if (shortcut.getIcon() != null) { Loading Loading @@ -1872,8 +1870,6 @@ public class ShortcutService extends IShortcutService.Stub { Preconditions.checkState(isUidForegroundLocked(injectBinderCallingUid()), "Calling application must have a foreground activity or a foreground service"); // TODO Cancel all pending requests from the caller. // Send request to the launcher, if supported. ret = mShortcutRequestPinProcessor.requestPinItemLocked(shortcut, appWidget, userId, resultIntent); Loading Loading @@ -3193,6 +3189,10 @@ public class ShortcutService extends IShortcutService.Stub { return new ComponentName(packageName, DUMMY_MAIN_ACTIVITY); } boolean isDummyMainActivity(@Nullable ComponentName name) { return name != null && DUMMY_MAIN_ACTIVITY.equals(name.getClassName()); } /** * Return all the enabled, exported and main activities from a package. */ Loading services/tests/servicestests/src/com/android/server/pm/BaseShortcutManagerTest.java +3 −3 Original line number Diff line number Diff line Loading @@ -1403,7 +1403,7 @@ public abstract class BaseShortcutManagerTest extends InstrumentationTestCase { protected ShortcutInfo makeShortcut(String id, String title, ComponentName activity, Icon icon, Intent intent, int rank) { final ShortcutInfo.Builder b = new ShortcutInfo.Builder(mClientContext, id) .setActivity(new ComponentName(mClientContext.getPackageName(), "dummy")) .setActivity(new ComponentName(mClientContext.getPackageName(), "main")) .setShortLabel(title) .setRank(rank) .setIntent(intent); Loading Loading @@ -1432,7 +1432,7 @@ public abstract class BaseShortcutManagerTest extends InstrumentationTestCase { protected ShortcutInfo makeShortcut(String id, String title, ComponentName activity, Icon icon, Intent[] intents, int rank) { final ShortcutInfo.Builder b = new ShortcutInfo.Builder(mClientContext, id) .setActivity(new ComponentName(mClientContext.getPackageName(), "dummy")) .setActivity(new ComponentName(mClientContext.getPackageName(), "main")) .setShortLabel(title) .setRank(rank) .setIntents(intents); Loading @@ -1455,7 +1455,7 @@ public abstract class BaseShortcutManagerTest extends InstrumentationTestCase { protected ShortcutInfo makeShortcutWithExtras(String id, Intent intent, PersistableBundle extras) { final ShortcutInfo.Builder b = new ShortcutInfo.Builder(mClientContext, id) .setActivity(new ComponentName(mClientContext.getPackageName(), "dummy")) .setActivity(new ComponentName(mClientContext.getPackageName(), "main")) .setShortLabel("title-" + id) .setExtras(extras) .setIntent(intent); Loading services/tests/servicestests/src/com/android/server/pm/ShortcutManagerTest8.java +208 −5 File changed.Preview size limit exceeded, changes collapsed. Show changes Loading
services/core/java/com/android/server/pm/ShortcutPackage.java +14 −2 Original line number Diff line number Diff line Loading @@ -361,6 +361,11 @@ class ShortcutPackage extends ShortcutPackageItem { } oldShortcut.setTimestamp(mShortcutUser.mService.injectCurrentTimeMillis()); // See ShortcutRequestPinProcessor.directPinShortcut(). if (mShortcutUser.mService.isDummyMainActivity(oldShortcut.getActivity())) { oldShortcut.setActivity(null); } return oldShortcut; } else { deleteShortcutInner(shortcutId); Loading Loading @@ -1515,6 +1520,8 @@ class ShortcutPackage extends ShortcutPackageItem { boolean failed = false; final ShortcutService s = mShortcutUser.mService; final ArrayMap<ComponentName, ArrayList<ShortcutInfo>> all = sortShortcutsToActivities(); Loading Loading @@ -1554,10 +1561,10 @@ class ShortcutPackage extends ShortcutPackageItem { Log.e(TAG_VERIFY, "Package " + getPackageName() + ": shortcut " + si.getId() + " is both dynamic and manifest at the same time."); } if (si.getActivity() == null) { if (si.getActivity() == null && !si.isFloating()) { failed = true; Log.e(TAG_VERIFY, "Package " + getPackageName() + ": shortcut " + si.getId() + " has null activity."); + " has null activity, but not floating."); } if ((si.isDynamic() || si.isManifestShortcut()) && !si.isEnabled()) { failed = true; Loading @@ -1579,6 +1586,11 @@ class ShortcutPackage extends ShortcutPackageItem { Log.e(TAG_VERIFY, "Package " + getPackageName() + ": shortcut " + si.getId() + " has both resource and bitmap icons"); } if (s.isDummyMainActivity(si.getActivity())) { failed = true; Log.e(TAG_VERIFY, "Package " + getPackageName() + ": shortcut " + si.getId() + " has a dummy target activity"); } } if (failed) { Loading
services/core/java/com/android/server/pm/ShortcutRequestPinProcessor.java +16 −4 Original line number Diff line number Diff line Loading @@ -16,7 +16,6 @@ package com.android.server.pm; import android.annotation.Nullable; import android.app.PendingIntent; import android.appwidget.AppWidgetProviderInfo; import android.content.ComponentName; import android.content.Intent; Loading Loading @@ -209,7 +208,7 @@ class ShortcutRequestPinProcessor { final boolean existsAlready = existing != null; if (DEBUG) { Slog.d(TAG, "requestPinnedShortcut package=" + inShortcut.getPackage() Slog.d(TAG, "requestPinnedShortcut: package=" + inShortcut.getPackage() + " existsAlready=" + existsAlready + " shortcut=" + inShortcut.toInsecureString()); } Loading Loading @@ -237,6 +236,14 @@ class ShortcutRequestPinProcessor { // FLAG_PINNED is still set, if it's pinned by other launchers. shortcutForLauncher.clearFlags(ShortcutInfo.FLAG_PINNED); } else { // If the shortcut has no default activity, try to set the main activity. // But in the request-pin case, it's optional, so it's okay even if the caller // has no default activity. if (inShortcut.getActivity() == null) { inShortcut.setActivity(mService.injectGetDefaultMainActivity( inShortcut.getPackage(), inShortcut.getUserId())); } // It doesn't exist, so it must have all mandatory fields. mService.validateShortcutForPinRequest(inShortcut); Loading @@ -244,12 +251,15 @@ class ShortcutRequestPinProcessor { inShortcut.resolveResourceStrings(mService.injectGetResourcesForApplicationAsUser( inShortcut.getPackage(), inShortcut.getUserId())); if (DEBUG) { Slog.d(TAG, "resolved shortcut=" + inShortcut.toInsecureString()); Slog.d(TAG, "Resolved shortcut=" + inShortcut.toInsecureString()); } // We should strip out the intent, but should preserve the icon. shortcutForLauncher = inShortcut.clone( ShortcutInfo.CLONE_REMOVE_FOR_LAUNCHER_APPROVAL); } if (DEBUG) { Slog.d(TAG, "Sending to launcher=" + shortcutForLauncher.toInsecureString()); } // Create a request object. final PinShortcutRequestInner inner = Loading Loading @@ -360,7 +370,9 @@ class ShortcutRequestPinProcessor { if (DEBUG) { Slog.d(TAG, "Temporarily adding " + shortcutId + " as dynamic"); } // Add as a dynamic shortcut. // Add as a dynamic shortcut. In order for a shortcut to be dynamic, it must // have a target activity, so we set a dummy here. It's later removed // in deleteDynamicWithId(). if (original.getActivity() == null) { original.setActivity(mService.getDummyMainActivity(appPackageName)); } Loading
services/core/java/com/android/server/pm/ShortcutService.java +8 −8 Original line number Diff line number Diff line Loading @@ -1604,7 +1604,7 @@ public class ShortcutService extends IShortcutService.Stub { private void fixUpIncomingShortcutInfo(@NonNull ShortcutInfo shortcut, boolean forUpdate, boolean forPinRequest) { Preconditions.checkNotNull(shortcut, "Null shortcut detected"); if (!forPinRequest && shortcut.getActivity() != null) { if (shortcut.getActivity() != null) { Preconditions.checkState( shortcut.getPackage().equals(shortcut.getActivity().getPackageName()), "Cannot publish shortcut: activity " + shortcut.getActivity() + " does not" Loading @@ -1618,10 +1618,8 @@ public class ShortcutService extends IShortcutService.Stub { if (!forUpdate) { shortcut.enforceMandatoryFields(/* forPinned= */ forPinRequest); if (!forPinRequest) { Preconditions.checkArgument( injectIsMainActivity(shortcut.getActivity(), shortcut.getUserId()), "Cannot publish shortcut: " + shortcut.getActivity() + " is not main activity"); Preconditions.checkState(shortcut.getActivity() != null, "Cannot publish shortcut: target activity is not set"); } } if (shortcut.getIcon() != null) { Loading Loading @@ -1872,8 +1870,6 @@ public class ShortcutService extends IShortcutService.Stub { Preconditions.checkState(isUidForegroundLocked(injectBinderCallingUid()), "Calling application must have a foreground activity or a foreground service"); // TODO Cancel all pending requests from the caller. // Send request to the launcher, if supported. ret = mShortcutRequestPinProcessor.requestPinItemLocked(shortcut, appWidget, userId, resultIntent); Loading Loading @@ -3193,6 +3189,10 @@ public class ShortcutService extends IShortcutService.Stub { return new ComponentName(packageName, DUMMY_MAIN_ACTIVITY); } boolean isDummyMainActivity(@Nullable ComponentName name) { return name != null && DUMMY_MAIN_ACTIVITY.equals(name.getClassName()); } /** * Return all the enabled, exported and main activities from a package. */ Loading
services/tests/servicestests/src/com/android/server/pm/BaseShortcutManagerTest.java +3 −3 Original line number Diff line number Diff line Loading @@ -1403,7 +1403,7 @@ public abstract class BaseShortcutManagerTest extends InstrumentationTestCase { protected ShortcutInfo makeShortcut(String id, String title, ComponentName activity, Icon icon, Intent intent, int rank) { final ShortcutInfo.Builder b = new ShortcutInfo.Builder(mClientContext, id) .setActivity(new ComponentName(mClientContext.getPackageName(), "dummy")) .setActivity(new ComponentName(mClientContext.getPackageName(), "main")) .setShortLabel(title) .setRank(rank) .setIntent(intent); Loading Loading @@ -1432,7 +1432,7 @@ public abstract class BaseShortcutManagerTest extends InstrumentationTestCase { protected ShortcutInfo makeShortcut(String id, String title, ComponentName activity, Icon icon, Intent[] intents, int rank) { final ShortcutInfo.Builder b = new ShortcutInfo.Builder(mClientContext, id) .setActivity(new ComponentName(mClientContext.getPackageName(), "dummy")) .setActivity(new ComponentName(mClientContext.getPackageName(), "main")) .setShortLabel(title) .setRank(rank) .setIntents(intents); Loading @@ -1455,7 +1455,7 @@ public abstract class BaseShortcutManagerTest extends InstrumentationTestCase { protected ShortcutInfo makeShortcutWithExtras(String id, Intent intent, PersistableBundle extras) { final ShortcutInfo.Builder b = new ShortcutInfo.Builder(mClientContext, id) .setActivity(new ComponentName(mClientContext.getPackageName(), "dummy")) .setActivity(new ComponentName(mClientContext.getPackageName(), "main")) .setShortLabel("title-" + id) .setExtras(extras) .setIntent(intent); Loading
services/tests/servicestests/src/com/android/server/pm/ShortcutManagerTest8.java +208 −5 File changed.Preview size limit exceeded, changes collapsed. Show changes