Allow adding target activity via requestPinShortcut().

Also now ShortcutManager tries to fill in the main activity as the target
activity if the caller has one.

Test: adb shell am instrument -e class com.android.server.pm.ShortcutManagerTest1 -w com.android.frameworks.servicestests
Test: adb shell am instrument -e class com.android.server.pm.ShortcutManagerTest2 -w com.android.frameworks.servicestests
Test: adb shell am instrument -e class com.android.server.pm.ShortcutManagerTest3 -w com.android.frameworks.servicestests
Test: adb shell am instrument -e class com.android.server.pm.ShortcutManagerTest4 -w com.android.frameworks.servicestests
Test: adb shell am instrument -e class com.android.server.pm.ShortcutManagerTest5 -w com.android.frameworks.servicestests
Test: adb shell am instrument -e class com.android.server.pm.ShortcutManagerTest6 -w com.android.frameworks.servicestests
Test: adb shell am instrument -e class com.android.server.pm.ShortcutManagerTest7 -w com.android.frameworks.servicestests
Test: adb shell am instrument -e class com.android.server.pm.ShortcutManagerTest8 -w com.android.frameworks.servicestests
Test: adb shell am instrument -e class com.android.server.pm.ShortcutManagerTest9 -w com.android.frameworks.servicestests
Test: Running: cts-tradefed run cts --skip-device-info --skip-preconditions --skip-system-status-check com.android.compatibility.common.tradefed.targetprep.NetworkConnectivityChecker -a armeabi-v7a -m CtsShortcutManagerTestCases
Test: cts-tradefed run cts --skip-device-info --skip-preconditions --skip-system-status-check com.android.compatibility.common.tradefed.targetprep.NetworkConnectivityChecker -a armeabi-v7a -m CtsShortcutHostTestCases

Bug 34047091

Change-Id: I2bf2b20e94a2384cfa6e6b7d40d56cfe96a94fd9
This commit is contained in:
Makoto Onuki
2017-01-10 11:47:25 -08:00
parent a2b61657c4
commit 255461f676
6 changed files with 250 additions and 23 deletions

View File

@@ -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);
@@ -1515,6 +1520,8 @@ class ShortcutPackage extends ShortcutPackageItem {
boolean failed = false;
final ShortcutService s = mShortcutUser.mService;
final ArrayMap<ComponentName, ArrayList<ShortcutInfo>> all =
sortShortcutsToActivities();
@@ -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;
@@ -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) {

View File

@@ -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;
@@ -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());
}
@@ -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);
@@ -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 =
@@ -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));
}

View File

@@ -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"
@@ -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) {
@@ -1870,9 +1868,7 @@ public class ShortcutService extends IShortcutService.Stub {
throwIfUserLockedL(userId);
Preconditions.checkState(isUidForegroundLocked(injectBinderCallingUid()),
"Calling application must have a foreground activity or a foreground service");
// TODO Cancel all pending requests from the caller.
"Calling application must have a foreground activity or a foreground service");
// Send request to the launcher, if supported.
ret = mShortcutRequestPinProcessor.requestPinItemLocked(shortcut, appWidget, userId,
@@ -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.
*/

View File

@@ -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);
@@ -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);
@@ -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);

View File

@@ -38,6 +38,7 @@ import android.graphics.drawable.Icon;
import android.os.UserHandle;
import android.test.MoreAsserts;
import android.test.suitebuilder.annotation.SmallTest;
import android.util.Log;
import android.util.Pair;
import com.android.frameworks.servicestests.R;
@@ -227,8 +228,9 @@ public class ShortcutManagerTest8 extends BaseShortcutManagerTest {
private void assertPinItemRequest(PinItemRequest actualRequest) {
assertNotNull(actualRequest);
assertEquals(PinItemRequest.REQUEST_TYPE_SHORTCUT, actualRequest.getRequestType());
Log.i(TAG, "Requested shortcut: " + actualRequest.getShortcutInfo().toInsecureString());
}
/**
@@ -243,9 +245,16 @@ public class ShortcutManagerTest8 extends BaseShortcutManagerTest {
final Icon res32x32 = Icon.createWithResource(getTestContext(), R.drawable.black_32x32);
runWithCaller(CALLING_PACKAGE_1, USER_P0, () -> {
ShortcutInfo s1 = makeShortcutWithIcon("s1", res32x32);
/// Create a shortcut with no target activity.
final ShortcutInfo.Builder b = new ShortcutInfo.Builder(mClientContext, "s1")
.setShortLabel("Title-" + "s1")
.setIcon(res32x32)
.setIntent(makeIntent(Intent.ACTION_VIEW, ShortcutActivity.class));
final ShortcutInfo s = b.build();
assertTrue(mManager.requestPinShortcut(s1,
assertNull(s.getActivity());
assertTrue(mManager.requestPinShortcut(s,
resultIntent == null ? null : resultIntent.getIntentSender()));
verify(mServiceContext, times(0)).sendIntentSender(any(IntentSender.class));
@@ -271,6 +280,7 @@ public class ShortcutManagerTest8 extends BaseShortcutManagerTest {
assertWith(request.getShortcutInfo())
.haveIds("s1")
.areAllOrphan()
.areAllWithActivity(new ComponentName(CALLING_PACKAGE_1, MAIN_ACTIVITY_CLASS))
.areAllWithNoIntent();
assertAllHaveIcon(list(request.getShortcutInfo()));
@@ -295,6 +305,7 @@ public class ShortcutManagerTest8 extends BaseShortcutManagerTest {
.areAllNotDynamic()
.areAllEnabled()
.areAllPinned()
.areAllWithActivity(new ComponentName(CALLING_PACKAGE_1, MAIN_ACTIVITY_CLASS))
.areAllWithIntent();
});
}
@@ -310,6 +321,145 @@ public class ShortcutManagerTest8 extends BaseShortcutManagerTest {
checkRequestPinShortcut(resultIntent);
}
public void testRequestPinShortcut_explicitTargetActivity() {
setDefaultLauncher(USER_0, mMainActivityFetcher.apply(LAUNCHER_1, USER_0));
setDefaultLauncher(USER_10, mMainActivityFetcher.apply(LAUNCHER_2, USER_10));
runWithCaller(CALLING_PACKAGE_1, USER_P0, () -> {
ShortcutInfo s1 = makeShortcutWithActivity("s1",
new ComponentName(CALLING_PACKAGE_1, "different_activity"));
assertTrue(mManager.requestPinShortcut(s1, null));
verify(mServiceContext, times(0)).sendIntentSender(any(IntentSender.class));
// Shortcut shouldn't be registered yet.
assertWith(getCallerShortcuts())
.isEmpty();
});
runWithCaller(LAUNCHER_1, USER_0, () -> {
// Check the intent passed to startActivityAsUser().
final ArgumentCaptor<Intent> intent = ArgumentCaptor.forClass(Intent.class);
verify(mServiceContext).startActivityAsUser(intent.capture(), eq(HANDLE_USER_0));
assertPinItemRequestIntent(intent.getValue(), mInjectedClientPackage);
// Check the request object.
final PinItemRequest request = mLauncherApps.getPinItemRequest(intent.getValue());
assertPinItemRequest(request);
assertWith(request.getShortcutInfo())
.haveIds("s1")
.areAllOrphan()
.areAllWithActivity(new ComponentName(CALLING_PACKAGE_1, "different_activity"))
.areAllWithNoIntent();
// Accept the request.
assertForLauncherCallbackNoThrow(mLauncherApps,
() -> assertTrue(request.accept()))
.assertCallbackCalledForPackageAndUser(CALLING_PACKAGE_1, HANDLE_USER_P0)
.haveIds("s1");
});
verify(mServiceContext, times(1)).sendIntentSender(eq(null));
runWithCaller(CALLING_PACKAGE_1, USER_P0, () -> {
assertWith(getCallerShortcuts())
.haveIds("s1")
.areAllNotDynamic()
.areAllEnabled()
.areAllPinned()
.areAllWithActivity(new ComponentName(CALLING_PACKAGE_1, "different_activity"))
.areAllWithIntent();
});
}
public void testRequestPinShortcut_wrongTargetActivity() {
setDefaultLauncher(USER_0, mMainActivityFetcher.apply(LAUNCHER_1, USER_0));
runWithCaller(CALLING_PACKAGE_1, USER_P0, () -> {
// Create dynamic shortcut
ShortcutInfo s1 = makeShortcutWithActivity("s1",
new ComponentName("wrong_package", "different_activity"));
assertExpectException(IllegalStateException.class, "not belong to package", () -> {
assertTrue(mManager.requestPinShortcut(s1, /* resultIntent=*/ null));
});
verify(mServiceContext, times(0)).sendIntentSender(any(IntentSender.class));
verify(mServiceContext, times(0)).startActivityAsUser(
any(Intent.class), any(UserHandle.class));
});
}
public void testRequestPinShortcut_noTargetActivity_noMainActivity() {
setDefaultLauncher(USER_0, mMainActivityFetcher.apply(LAUNCHER_1, USER_0));
setDefaultLauncher(USER_10, mMainActivityFetcher.apply(LAUNCHER_2, USER_10));
runWithCaller(CALLING_PACKAGE_1, USER_P0, () -> {
/// Create a shortcut with no target activity.
final ShortcutInfo.Builder b = new ShortcutInfo.Builder(mClientContext, "s1")
.setShortLabel("Title-" + "s1")
.setIntent(makeIntent(Intent.ACTION_VIEW, ShortcutActivity.class));
final ShortcutInfo s = b.build();
assertNull(s.getActivity());
// Caller has no main activity.
mMainActivityFetcher = (packageName, userId) -> null;
assertTrue(mManager.requestPinShortcut(s, null));
verify(mServiceContext, times(0)).sendIntentSender(any(IntentSender.class));
// Shortcut shouldn't be registered yet.
assertWith(getCallerShortcuts())
.isEmpty();
});
runWithCaller(LAUNCHER_1, USER_0, () -> {
// Check the intent passed to startActivityAsUser().
final ArgumentCaptor<Intent> intent = ArgumentCaptor.forClass(Intent.class);
verify(mServiceContext).startActivityAsUser(intent.capture(), eq(HANDLE_USER_0));
assertPinItemRequestIntent(intent.getValue(), mInjectedClientPackage);
// Check the request object.
final PinItemRequest request = mLauncherApps.getPinItemRequest(intent.getValue());
assertPinItemRequest(request);
assertWith(request.getShortcutInfo())
.haveIds("s1")
.areAllOrphan()
.areAllWithNoActivity() // Activity is not set; expected.
.areAllWithNoIntent();
// Accept the request.
assertForLauncherCallbackNoThrow(mLauncherApps,
() -> assertTrue(request.accept()))
.assertCallbackCalledForPackageAndUser(CALLING_PACKAGE_1, HANDLE_USER_P0)
.haveIds("s1");
});
verify(mServiceContext, times(1)).sendIntentSender(eq(null));
runWithCaller(CALLING_PACKAGE_1, USER_P0, () -> {
assertWith(getCallerShortcuts())
.haveIds("s1")
.areAllNotDynamic()
.areAllEnabled()
.areAllPinned()
.areAllWithNoActivity() // Activity is not set; expected.
.areAllWithIntent();
});
}
public void testRequestPinShortcut_dynamicExists() {
setDefaultLauncher(USER_0, mMainActivityFetcher.apply(LAUNCHER_1, USER_0));
@@ -328,6 +478,7 @@ public class ShortcutManagerTest8 extends BaseShortcutManagerTest {
assertWith(getCallerShortcuts())
.haveIds("s1")
.areAllDynamic()
.areAllWithActivity(new ComponentName(CALLING_PACKAGE_1, "main"))
.areAllNotPinned();
});
@@ -348,6 +499,7 @@ public class ShortcutManagerTest8 extends BaseShortcutManagerTest {
.haveIds("s1")
.areAllDynamic()
.areAllNotPinned()
.areAllWithActivity(new ComponentName(CALLING_PACKAGE_1, "main"))
.areAllWithNoIntent();
assertAllHaveIcon(list(request.getShortcutInfo()));
@@ -361,6 +513,7 @@ public class ShortcutManagerTest8 extends BaseShortcutManagerTest {
.haveIds("s1")
.areAllDynamic()
.areAllEnabled()
.areAllWithActivity(new ComponentName(CALLING_PACKAGE_1, "main"))
.areAllPinned();
});
}
@@ -379,6 +532,8 @@ public class ShortcutManagerTest8 extends BaseShortcutManagerTest {
assertWith(getCallerShortcuts())
.haveIds("ms1")
.areAllManifest()
.areAllWithActivity(new ComponentName(CALLING_PACKAGE_1,
ShortcutActivity.class.getName()))
.areAllNotPinned();
});
@@ -399,6 +554,8 @@ public class ShortcutManagerTest8 extends BaseShortcutManagerTest {
.haveIds("ms1")
.areAllManifest()
.areAllNotPinned()
.areAllWithActivity(new ComponentName(CALLING_PACKAGE_1,
ShortcutActivity.class.getName()))
.areAllWithNoIntent();
assertAllHaveIcon(list(request.getShortcutInfo()));
@@ -412,6 +569,8 @@ public class ShortcutManagerTest8 extends BaseShortcutManagerTest {
.haveIds("ms1")
.areAllManifest()
.areAllEnabled()
.areAllWithActivity(new ComponentName(CALLING_PACKAGE_1,
ShortcutActivity.class.getName()))
.areAllPinned();
});
}
@@ -431,6 +590,7 @@ public class ShortcutManagerTest8 extends BaseShortcutManagerTest {
assertWith(getCallerShortcuts())
.haveIds("s1")
.areAllDynamic()
.areAllWithActivity(new ComponentName(CALLING_PACKAGE_1, "main"))
.areAllPinned();
assertTrue(mManager.requestPinShortcut(makeShortcutIdOnly("s1"),
@@ -456,6 +616,8 @@ public class ShortcutManagerTest8 extends BaseShortcutManagerTest {
assertWith(getCallerShortcuts())
.haveIds("ms1")
.areAllManifest()
.areAllWithActivity(new ComponentName(CALLING_PACKAGE_1,
ShortcutActivity.class.getName()))
.areAllPinned();
assertTrue(mManager.requestPinShortcut(makeShortcutIdOnly("ms1"),
@@ -483,6 +645,7 @@ public class ShortcutManagerTest8 extends BaseShortcutManagerTest {
.haveIds("s1")
.areAllNotDynamic()
.areAllEnabled()
.areAllWithActivity(new ComponentName(CALLING_PACKAGE_1, "main"))
.areAllPinned();
assertTrue(mManager.requestPinShortcut(makeShortcutIdOnly("s1"),
@@ -511,6 +674,7 @@ public class ShortcutManagerTest8 extends BaseShortcutManagerTest {
.haveIds("s1")
.areAllNotDynamic()
.areAllDisabled()
.areAllWithActivity(new ComponentName(CALLING_PACKAGE_1, "main"))
.areAllPinned();
assertExpectException(IllegalArgumentException.class, "exists but disabled", () -> {
@@ -541,6 +705,8 @@ public class ShortcutManagerTest8 extends BaseShortcutManagerTest {
.haveIds("ms1")
.areAllNotManifest()
.areAllDisabled()
.areAllWithActivity(new ComponentName(CALLING_PACKAGE_1,
ShortcutActivity.class.getName()))
.areAllPinned();
assertExpectException(IllegalArgumentException.class, "exists but disabled", () -> {
@@ -570,6 +736,7 @@ public class ShortcutManagerTest8 extends BaseShortcutManagerTest {
assertWith(getCallerShortcuts())
.haveIds("s1")
.areAllDynamic()
.areAllWithActivity(new ComponentName(CALLING_PACKAGE_1, "main"))
.areAllPinned();
// The shortcut is already pinned, but not by the current launcher, so it'll still
@@ -597,6 +764,7 @@ public class ShortcutManagerTest8 extends BaseShortcutManagerTest {
.haveIds("s1")
.areAllDynamic()
.areAllNotPinned() // Note it's not pinned by this launcher.
.areAllWithActivity(new ComponentName(CALLING_PACKAGE_1, "main"))
.areAllWithNoIntent();
// Accept the request.
@@ -608,6 +776,7 @@ public class ShortcutManagerTest8 extends BaseShortcutManagerTest {
.haveIds("s1")
.areAllDynamic()
.areAllEnabled()
.areAllWithActivity(new ComponentName(CALLING_PACKAGE_1, "main"))
.areAllPinned();
});
}
@@ -629,6 +798,8 @@ public class ShortcutManagerTest8 extends BaseShortcutManagerTest {
assertWith(getCallerShortcuts())
.haveIds("ms1")
.areAllManifest()
.areAllWithActivity(new ComponentName(CALLING_PACKAGE_1,
ShortcutActivity.class.getName()))
.areAllPinned();
// The shortcut is already pinned, but not by the current launcher, so it'll still
@@ -656,6 +827,8 @@ public class ShortcutManagerTest8 extends BaseShortcutManagerTest {
.haveIds("ms1")
.areAllManifest()
.areAllNotPinned() // Note it's not pinned by this launcher.
.areAllWithActivity(new ComponentName(CALLING_PACKAGE_1,
ShortcutActivity.class.getName()))
.areAllWithNoIntent();
// Accept the request.
@@ -667,6 +840,8 @@ public class ShortcutManagerTest8 extends BaseShortcutManagerTest {
.haveIds("ms1")
.areAllManifest()
.areAllEnabled()
.areAllWithActivity(new ComponentName(CALLING_PACKAGE_1,
ShortcutActivity.class.getName()))
.areAllPinned();
});
}
@@ -710,6 +885,7 @@ public class ShortcutManagerTest8 extends BaseShortcutManagerTest {
.haveIds("s1")
.areAllDynamic()
.areAllNotPinned()
.areAllWithActivity(new ComponentName(CALLING_PACKAGE_1, "main"))
.areAllWithNoIntent();
// Accept the request.
@@ -719,6 +895,7 @@ public class ShortcutManagerTest8 extends BaseShortcutManagerTest {
.haveIds("s1", "s2")
.areAllDynamic()
.areAllEnabled()
.areAllWithActivity(new ComponentName(CALLING_PACKAGE_1, "main"))
.areAllPinned();
});
@@ -727,6 +904,7 @@ public class ShortcutManagerTest8 extends BaseShortcutManagerTest {
.haveIds("s1", "s2")
.areAllDynamic()
.areAllEnabled()
.areAllWithActivity(new ComponentName(CALLING_PACKAGE_1, "main"))
.areAllPinned();
});
}
@@ -752,6 +930,7 @@ public class ShortcutManagerTest8 extends BaseShortcutManagerTest {
assertWith(getCallerShortcuts())
.haveIds("s1")
.areAllDynamic()
.areAllWithActivity(new ComponentName(CALLING_PACKAGE_1, "main"))
.areAllNotPinned();
});
@@ -772,6 +951,7 @@ public class ShortcutManagerTest8 extends BaseShortcutManagerTest {
.haveIds("s1")
.areAllDynamic()
.areAllNotPinned()
.areAllWithActivity(new ComponentName(CALLING_PACKAGE_1, "main"))
.areAllWithNoIntent();
assertAllHaveIcon(list(request.getShortcutInfo()));
@@ -786,6 +966,7 @@ public class ShortcutManagerTest8 extends BaseShortcutManagerTest {
.areAllDynamic()
.areAllEnabled()
.areAllPinned()
.areAllWithActivity(new ComponentName(CALLING_PACKAGE_1, "main"))
.forShortcutWithId("s1", (si) -> {
// Still the original title.
assertEquals("Title-s1", si.getShortLabel());
@@ -810,6 +991,8 @@ public class ShortcutManagerTest8 extends BaseShortcutManagerTest {
assertWith(getCallerShortcuts())
.haveIds("ms1")
.areAllManifest()
.areAllWithActivity(new ComponentName(CALLING_PACKAGE_1,
ShortcutActivity.class.getName()))
.areAllNotPinned();
});
@@ -830,6 +1013,8 @@ public class ShortcutManagerTest8 extends BaseShortcutManagerTest {
.haveIds("ms1")
.areAllManifest()
.areAllNotPinned()
.areAllWithActivity(new ComponentName(CALLING_PACKAGE_1,
ShortcutActivity.class.getName()))
.areAllWithNoIntent();
assertAllHaveIcon(list(request.getShortcutInfo()));
@@ -844,6 +1029,8 @@ public class ShortcutManagerTest8 extends BaseShortcutManagerTest {
.areAllManifest()
.areAllEnabled()
.areAllPinned()
.areAllWithActivity(new ComponentName(CALLING_PACKAGE_1,
ShortcutActivity.class.getName()))
.forShortcutWithId("ms1", (si) -> {
// Still the original title.
// Title should be something like:
@@ -893,6 +1080,7 @@ public class ShortcutManagerTest8 extends BaseShortcutManagerTest {
.haveIds("s1")
.areAllDynamic()
.areAllNotPinned()
.areAllWithActivity(new ComponentName(CALLING_PACKAGE_1, "main"))
.areAllWithNoIntent();
// Accept the request -> should fail.
@@ -950,9 +1138,9 @@ public class ShortcutManagerTest8 extends BaseShortcutManagerTest {
.haveIds("s1")
.areAllDynamic()
.areAllNotPinned()
.areAllWithActivity(new ComponentName(CALLING_PACKAGE_1, "main"))
.areAllWithNoIntent();
// Accept the request -> should fail.
assertTrue(request.accept());
});
@@ -1004,6 +1192,8 @@ public class ShortcutManagerTest8 extends BaseShortcutManagerTest {
.haveIds("ms1")
.areAllManifest()
.areAllNotPinned()
.areAllWithActivity(new ComponentName(CALLING_PACKAGE_1,
ShortcutActivity.class.getName()))
.areAllWithNoIntent();
// Accept the request -> should fail.
@@ -1059,10 +1249,11 @@ public class ShortcutManagerTest8 extends BaseShortcutManagerTest {
.haveIds("ms1")
.areAllManifest()
.areAllNotPinned()
.areAllWithActivity(new ComponentName(CALLING_PACKAGE_1,
ShortcutActivity.class.getName()))
.areAllWithNoIntent();
// Accept the request -> should fail.
assertTrue(request.accept());
});
@@ -1071,6 +1262,9 @@ public class ShortcutManagerTest8 extends BaseShortcutManagerTest {
.haveIds("ms1")
.areAllMutable() // Note it's no longer immutable.
.areAllFloating()
// Note it's the activity from makeShortcutWithShortLabel().
.areAllWithActivity(new ComponentName(CALLING_PACKAGE_1, "main"))
.forShortcutWithId("ms1", si -> {
assertEquals("new", si.getShortLabel());
});
@@ -1104,6 +1298,7 @@ public class ShortcutManagerTest8 extends BaseShortcutManagerTest {
mManager.disableShortcuts(list("s1"));
assertWith(getCallerShortcuts())
.haveIds("s1")
.areAllWithActivity(new ComponentName(CALLING_PACKAGE_1, "main"))
.areAllDisabled();
});
@@ -1125,6 +1320,7 @@ public class ShortcutManagerTest8 extends BaseShortcutManagerTest {
.haveIds("s1")
.areAllDynamic()
.areAllNotPinned()
.areAllWithActivity(new ComponentName(CALLING_PACKAGE_1, "main"))
.areAllWithNoIntent();
// Accept the request -> should fail.
@@ -1144,6 +1340,7 @@ public class ShortcutManagerTest8 extends BaseShortcutManagerTest {
runWithCaller(CALLING_PACKAGE_1, USER_P0, () -> {
assertWith(getCallerShortcuts())
.haveIds("s1")
.areAllWithActivity(new ComponentName(CALLING_PACKAGE_1, "main"))
.areAllDisabled();
});
}
@@ -1174,6 +1371,8 @@ public class ShortcutManagerTest8 extends BaseShortcutManagerTest {
publishManifestShortcutsAsCaller(R.xml.shortcut_0);
assertWith(getCallerShortcuts())
.haveIds("ms1")
.areAllWithActivity(new ComponentName(CALLING_PACKAGE_1,
ShortcutActivity.class.getName()))
.areAllDisabled();
});
@@ -1195,6 +1394,8 @@ public class ShortcutManagerTest8 extends BaseShortcutManagerTest {
.haveIds("ms1")
.areAllManifest()
.areAllNotPinned()
.areAllWithActivity(new ComponentName(CALLING_PACKAGE_1,
ShortcutActivity.class.getName()))
.areAllWithNoIntent();
// Accept the request -> should fail.
@@ -1214,6 +1415,8 @@ public class ShortcutManagerTest8 extends BaseShortcutManagerTest {
runWithCaller(CALLING_PACKAGE_1, USER_P0, () -> {
assertWith(getCallerShortcuts())
.haveIds("ms1")
.areAllWithActivity(new ComponentName(CALLING_PACKAGE_1,
ShortcutActivity.class.getName()))
.areAllDisabled();
});
}

View File

@@ -925,7 +925,7 @@ public class ShortcutManagerTestUtils {
}
public ShortcutListAsserter areAllWithActivity(ComponentName activity) {
forAllShortcuts(s -> assertTrue("id=" + s.getId(), s.getActivity().equals(activity)));
forAllShortcuts(s -> assertEquals("id=" + s.getId(), activity, s.getActivity()));
return this;
}