summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSunny Goyal <sunnygoyal@google.com>2017-01-24 11:53:54 -0800
committerSunny Goyal <sunnygoyal@google.com>2017-01-24 17:26:14 -0800
commit7f7372ae2abeecb564d426ec3efbfa039c797885 (patch)
treed277f5c59573bea7e45326c757cbbd200038fd85
parent29d20fc0f9d185ce356a984468142ae5c63e911b (diff)
Adding AppWidgetManager.isRequestPinAppWidgetSupported
Launchers can choose to implement support pin shortcut or pin appwidget or both by specifying different actions in the intent filter Test: Automated tests and CTS Bug: 34174006 Change-Id: I4456dbb943cfba11d465556f0732f0ed629ab3ba
-rw-r--r--api/current.txt4
-rw-r--r--api/system-current.txt4
-rw-r--r--api/test-current.txt4
-rw-r--r--core/java/android/appwidget/AppWidgetManager.java13
-rw-r--r--core/java/android/content/pm/IShortcutService.aidl2
-rw-r--r--core/java/android/content/pm/LauncherApps.java38
-rw-r--r--core/java/android/content/pm/ShortcutManager.java3
-rw-r--r--core/java/android/content/pm/ShortcutServiceInternal.java2
-rw-r--r--core/java/com/android/internal/appwidget/IAppWidgetService.aidl1
-rw-r--r--services/appwidget/java/com/android/server/appwidget/AppWidgetServiceImpl.java8
-rw-r--r--services/core/java/com/android/server/pm/ShortcutRequestPinProcessor.java28
-rw-r--r--services/core/java/com/android/server/pm/ShortcutService.java23
-rw-r--r--services/tests/servicestests/src/com/android/server/appwidget/AppWidgetServiceImplTest.java13
-rw-r--r--services/tests/servicestests/src/com/android/server/pm/BaseShortcutManagerTest.java2
-rw-r--r--services/tests/servicestests/src/com/android/server/pm/ShortcutManagerTest8.java20
-rw-r--r--services/tests/servicestests/src/com/android/server/pm/ShortcutManagerTest9.java2
16 files changed, 127 insertions, 40 deletions
diff --git a/api/current.txt b/api/current.txt
index e7c628a0e9d9..56e8af271266 100644
--- a/api/current.txt
+++ b/api/current.txt
@@ -6841,6 +6841,7 @@ package android.appwidget {
method public java.util.List<android.appwidget.AppWidgetProviderInfo> getInstalledProviders();
method public java.util.List<android.appwidget.AppWidgetProviderInfo> getInstalledProvidersForProfile(android.os.UserHandle);
method public static android.appwidget.AppWidgetManager getInstance(android.content.Context);
+ method public boolean isRequestPinAppWidgetSupported();
method public void notifyAppWidgetViewDataChanged(int[], int);
method public void notifyAppWidgetViewDataChanged(int, int);
method public void partiallyUpdateAppWidget(int[], android.widget.RemoteViews);
@@ -9836,7 +9837,8 @@ package android.content.pm {
method public void startShortcut(java.lang.String, java.lang.String, android.graphics.Rect, android.os.Bundle, android.os.UserHandle);
method public void startShortcut(android.content.pm.ShortcutInfo, android.graphics.Rect, android.os.Bundle);
method public void unregisterCallback(android.content.pm.LauncherApps.Callback);
- field public static final java.lang.String ACTION_CONFIRM_PIN_ITEM = "android.content.pm.action.CONFIRM_PIN_ITEM";
+ field public static final java.lang.String ACTION_CONFIRM_PIN_APPWIDGET = "android.content.pm.action.CONFIRM_PIN_APPWIDGET";
+ field public static final java.lang.String ACTION_CONFIRM_PIN_SHORTCUT = "android.content.pm.action.CONFIRM_PIN_SHORTCUT";
field public static final java.lang.String EXTRA_PIN_ITEM_REQUEST = "android.content.pm.extra.PIN_ITEM_REQUEST";
}
diff --git a/api/system-current.txt b/api/system-current.txt
index e79ebdc2cb57..25d1d24b7fe1 100644
--- a/api/system-current.txt
+++ b/api/system-current.txt
@@ -7177,6 +7177,7 @@ package android.appwidget {
method public java.util.List<android.appwidget.AppWidgetProviderInfo> getInstalledProviders();
method public java.util.List<android.appwidget.AppWidgetProviderInfo> getInstalledProvidersForProfile(android.os.UserHandle);
method public static android.appwidget.AppWidgetManager getInstance(android.content.Context);
+ method public boolean isRequestPinAppWidgetSupported();
method public void notifyAppWidgetViewDataChanged(int[], int);
method public void notifyAppWidgetViewDataChanged(int, int);
method public void partiallyUpdateAppWidget(int[], android.widget.RemoteViews);
@@ -10269,7 +10270,8 @@ package android.content.pm {
method public void startShortcut(java.lang.String, java.lang.String, android.graphics.Rect, android.os.Bundle, android.os.UserHandle);
method public void startShortcut(android.content.pm.ShortcutInfo, android.graphics.Rect, android.os.Bundle);
method public void unregisterCallback(android.content.pm.LauncherApps.Callback);
- field public static final java.lang.String ACTION_CONFIRM_PIN_ITEM = "android.content.pm.action.CONFIRM_PIN_ITEM";
+ field public static final java.lang.String ACTION_CONFIRM_PIN_APPWIDGET = "android.content.pm.action.CONFIRM_PIN_APPWIDGET";
+ field public static final java.lang.String ACTION_CONFIRM_PIN_SHORTCUT = "android.content.pm.action.CONFIRM_PIN_SHORTCUT";
field public static final java.lang.String EXTRA_PIN_ITEM_REQUEST = "android.content.pm.extra.PIN_ITEM_REQUEST";
}
diff --git a/api/test-current.txt b/api/test-current.txt
index f1144e99b29c..1cbf5002f1ab 100644
--- a/api/test-current.txt
+++ b/api/test-current.txt
@@ -6863,6 +6863,7 @@ package android.appwidget {
method public java.util.List<android.appwidget.AppWidgetProviderInfo> getInstalledProviders();
method public java.util.List<android.appwidget.AppWidgetProviderInfo> getInstalledProvidersForProfile(android.os.UserHandle);
method public static android.appwidget.AppWidgetManager getInstance(android.content.Context);
+ method public boolean isRequestPinAppWidgetSupported();
method public void notifyAppWidgetViewDataChanged(int[], int);
method public void notifyAppWidgetViewDataChanged(int, int);
method public void partiallyUpdateAppWidget(int[], android.widget.RemoteViews);
@@ -9864,7 +9865,8 @@ package android.content.pm {
method public void startShortcut(java.lang.String, java.lang.String, android.graphics.Rect, android.os.Bundle, android.os.UserHandle);
method public void startShortcut(android.content.pm.ShortcutInfo, android.graphics.Rect, android.os.Bundle);
method public void unregisterCallback(android.content.pm.LauncherApps.Callback);
- field public static final java.lang.String ACTION_CONFIRM_PIN_ITEM = "android.content.pm.action.CONFIRM_PIN_ITEM";
+ field public static final java.lang.String ACTION_CONFIRM_PIN_APPWIDGET = "android.content.pm.action.CONFIRM_PIN_APPWIDGET";
+ field public static final java.lang.String ACTION_CONFIRM_PIN_SHORTCUT = "android.content.pm.action.CONFIRM_PIN_SHORTCUT";
field public static final java.lang.String EXTRA_PIN_ITEM_REQUEST = "android.content.pm.extra.PIN_ITEM_REQUEST";
}
diff --git a/core/java/android/appwidget/AppWidgetManager.java b/core/java/android/appwidget/AppWidgetManager.java
index 9980e9661dd3..077331e36f05 100644
--- a/core/java/android/appwidget/AppWidgetManager.java
+++ b/core/java/android/appwidget/AppWidgetManager.java
@@ -1072,6 +1072,18 @@ public class AppWidgetManager {
}
/**
+ * Return {@code TRUE} if the default launcher supports
+ * {@link #requestPinAppWidget(ComponentName, PendingIntent)}
+ */
+ public boolean isRequestPinAppWidgetSupported() {
+ try {
+ return mService.isRequestPinAppWidgetSupported();
+ } catch (RemoteException e) {
+ throw e.rethrowFromSystemServer();
+ }
+ }
+
+ /**
* Request to pin an app widget on the current launcher. It's up to the launcher to accept this
* request (optionally showing a user confirmation). If the request is accepted, the caller will
* get a confirmation with extra {@link #EXTRA_APPWIDGET_ID}.
@@ -1095,6 +1107,7 @@ public class AppWidgetManager {
*
* @see android.content.pm.ShortcutManager#isRequestPinShortcutSupported()
* @see android.content.pm.ShortcutManager#requestPinShortcut(ShortcutInfo, IntentSender)
+ * @see #isRequestPinAppWidgetSupported()
*
* @throws IllegalStateException The caller doesn't have a foreground activity or a foreground
* service or when the user is locked.
diff --git a/core/java/android/content/pm/IShortcutService.aidl b/core/java/android/content/pm/IShortcutService.aidl
index c90134a04830..03124be7ab7d 100644
--- a/core/java/android/content/pm/IShortcutService.aidl
+++ b/core/java/android/content/pm/IShortcutService.aidl
@@ -71,5 +71,5 @@ interface IShortcutService {
void applyRestore(in byte[] payload, int user);
- boolean isRequestPinShortcutSupported(int user);
+ boolean isRequestPinItemSupported(int user, int requestType);
} \ No newline at end of file
diff --git a/core/java/android/content/pm/LauncherApps.java b/core/java/android/content/pm/LauncherApps.java
index c6a86748bfe8..37195cb1771f 100644
--- a/core/java/android/content/pm/LauncherApps.java
+++ b/core/java/android/content/pm/LauncherApps.java
@@ -93,22 +93,40 @@ public class LauncherApps {
* @see #EXTRA_PIN_ITEM_REQUEST
*/
@SdkConstant(SdkConstantType.ACTIVITY_INTENT_ACTION)
- public static final String ACTION_CONFIRM_PIN_ITEM =
- "android.content.pm.action.CONFIRM_PIN_ITEM";
+ public static final String ACTION_CONFIRM_PIN_SHORTCUT =
+ "android.content.pm.action.CONFIRM_PIN_SHORTCUT";
/**
- * An extra for {@link #ACTION_CONFIRM_PIN_ITEM} containing a
- * {@link ShortcutInfo} of the shortcut the publisher app asked to pin.
+ * Activity Action: For the default launcher to show the confirmation dialog to create
+ * a pinned app widget.
+ *
+ * <p>See the {@link android.appwidget.AppWidgetManager#requestPinAppWidget} javadoc for
+ * details.
+ *
+ * <p>
+ * Use {@link #getPinItemRequest(Intent)} to get a {@link PinItemRequest} object,
+ * and call {@link PinItemRequest#accept(Bundle)}
+ * if the user accepts. If the user doesn't accept, no further action is required.
+ *
+ * @see #EXTRA_PIN_ITEM_REQUEST
+ */
+ @SdkConstant(SdkConstantType.ACTIVITY_INTENT_ACTION)
+ public static final String ACTION_CONFIRM_PIN_APPWIDGET =
+ "android.content.pm.action.CONFIRM_PIN_APPWIDGET";
+
+ /**
+ * An extra for {@link #ACTION_CONFIRM_PIN_SHORTCUT} &amp; {@link #ACTION_CONFIRM_PIN_APPWIDGET}
+ * containing a {@link PinItemRequest} of appropriate type asked to pin.
*
* <p>A helper function {@link #getPinItemRequest(Intent)} can be used
* instead of using this constant directly.
*
- * @see #ACTION_CONFIRM_PIN_ITEM
+ * @see #ACTION_CONFIRM_PIN_SHORTCUT
+ * @see #ACTION_CONFIRM_PIN_APPWIDGET
*/
public static final String EXTRA_PIN_ITEM_REQUEST =
"android.content.pm.extra.PIN_ITEM_REQUEST";
-
private Context mContext;
private ILauncherApps mService;
private PackageManager mPm;
@@ -1203,8 +1221,9 @@ public class LauncherApps {
}
/**
- * Represents a "pin shortcut" request made by an app, which is sent with
- * an {@link #ACTION_CONFIRM_PIN_ITEM} intent to the default launcher app.
+ * Represents a "pin shortcut" or a "pin appwidget" request made by an app, which is sent with
+ * an {@link #ACTION_CONFIRM_PIN_SHORTCUT} or {@link #ACTION_CONFIRM_PIN_APPWIDGET} intent
+ * respectively to the default launcher app.
*
* <p>Note the launcher may receive a request to pin a shortcut that is already pinned, because
* the user may actually want to have multiple icons of the same shortcut on the launcher.
@@ -1213,6 +1232,9 @@ public class LauncherApps {
* even if the launcher does not call it, the shortcut is already pinned. Also in this case,
* the {@code options} argument to {@link #accept(Bundle)} will be ignored.
*
+ * <p>For AppWidget pin requests launcher should send back the appwidget id as an extra for
+ * {@link #accept(Bundle)} as {@link android.appwidget.AppWidgetManager#EXTRA_APPWIDGET_ID}.
+ *
* @see #EXTRA_PIN_ITEM_REQUEST
* @see #getPinItemRequest(Intent)
*/
diff --git a/core/java/android/content/pm/ShortcutManager.java b/core/java/android/content/pm/ShortcutManager.java
index 805054fad389..fb280a1db28c 100644
--- a/core/java/android/content/pm/ShortcutManager.java
+++ b/core/java/android/content/pm/ShortcutManager.java
@@ -830,7 +830,8 @@ public class ShortcutManager {
*/
public boolean isRequestPinShortcutSupported() {
try {
- return mService.isRequestPinShortcutSupported(injectMyUserId());
+ return mService.isRequestPinItemSupported(injectMyUserId(),
+ LauncherApps.PinItemRequest.REQUEST_TYPE_SHORTCUT);
} catch (RemoteException e) {
throw e.rethrowFromSystemServer();
}
diff --git a/core/java/android/content/pm/ShortcutServiceInternal.java b/core/java/android/content/pm/ShortcutServiceInternal.java
index 4773c730406f..87a6d4a5fa09 100644
--- a/core/java/android/content/pm/ShortcutServiceInternal.java
+++ b/core/java/android/content/pm/ShortcutServiceInternal.java
@@ -74,4 +74,6 @@ public abstract class ShortcutServiceInternal {
public abstract boolean requestPinAppWidget(@NonNull String callingPackage,
@NonNull AppWidgetProviderInfo appWidget, @Nullable IntentSender resultIntent,
int userId);
+
+ public abstract boolean isRequestPinItemSupported(int callingUserId, int requestType);
}
diff --git a/core/java/com/android/internal/appwidget/IAppWidgetService.aidl b/core/java/com/android/internal/appwidget/IAppWidgetService.aidl
index a1eac363a6e8..81db93d05aab 100644
--- a/core/java/com/android/internal/appwidget/IAppWidgetService.aidl
+++ b/core/java/com/android/internal/appwidget/IAppWidgetService.aidl
@@ -69,5 +69,6 @@ interface IAppWidgetService {
boolean isBoundWidgetPackage(String packageName, int userId);
boolean requestPinAppWidget(String packageName, in ComponentName providerComponent,
in IntentSender resultIntent);
+ boolean isRequestPinAppWidgetSupported();
}
diff --git a/services/appwidget/java/com/android/server/appwidget/AppWidgetServiceImpl.java b/services/appwidget/java/com/android/server/appwidget/AppWidgetServiceImpl.java
index 3523706859c0..ce50b301ddbe 100644
--- a/services/appwidget/java/com/android/server/appwidget/AppWidgetServiceImpl.java
+++ b/services/appwidget/java/com/android/server/appwidget/AppWidgetServiceImpl.java
@@ -42,6 +42,7 @@ import android.content.ServiceConnection;
import android.content.pm.ActivityInfo;
import android.content.pm.ApplicationInfo;
import android.content.pm.IPackageManager;
+import android.content.pm.LauncherApps;
import android.content.pm.PackageInfo;
import android.content.pm.PackageManager;
import android.content.pm.PackageManager.NameNotFoundException;
@@ -1547,6 +1548,13 @@ class AppWidgetServiceImpl extends IAppWidgetService.Stub implements WidgetBacku
}
@Override
+ public boolean isRequestPinAppWidgetSupported() {
+ return LocalServices.getService(ShortcutServiceInternal.class)
+ .isRequestPinItemSupported(UserHandle.getCallingUserId(),
+ LauncherApps.PinItemRequest.REQUEST_TYPE_APPWIDGET);
+ }
+
+ @Override
public boolean requestPinAppWidget(String callingPackage, ComponentName componentName,
IntentSender resultSender) {
final int callingUid = Binder.getCallingUid();
diff --git a/services/core/java/com/android/server/pm/ShortcutRequestPinProcessor.java b/services/core/java/com/android/server/pm/ShortcutRequestPinProcessor.java
index 6e967267e51d..6eac5e39cc63 100644
--- a/services/core/java/com/android/server/pm/ShortcutRequestPinProcessor.java
+++ b/services/core/java/com/android/server/pm/ShortcutRequestPinProcessor.java
@@ -25,7 +25,6 @@ import android.content.pm.IPinItemRequest;
import android.content.pm.LauncherApps;
import android.content.pm.LauncherApps.PinItemRequest;
import android.content.pm.ShortcutInfo;
-import android.os.Binder;
import android.os.Bundle;
import android.os.UserHandle;
import android.util.Log;
@@ -168,8 +167,8 @@ class ShortcutRequestPinProcessor {
mLock = lock;
}
- public boolean isRequestPinnedShortcutSupported(int callingUserId) {
- return getRequestPinShortcutConfirmationActivity(callingUserId) != null;
+ public boolean isRequestPinItemSupported(int callingUserId, int requestType) {
+ return getRequestPinConfirmationActivity(callingUserId, requestType) != null;
}
/**
@@ -185,8 +184,10 @@ class ShortcutRequestPinProcessor {
// First, make sure the launcher supports it.
// Find the confirmation activity in the default launcher.
+ final int requestType = inShortcut != null ?
+ PinItemRequest.REQUEST_TYPE_SHORTCUT : PinItemRequest.REQUEST_TYPE_APPWIDGET;
final Pair<ComponentName, Integer> confirmActivity =
- getRequestPinShortcutConfirmationActivity(userId);
+ getRequestPinConfirmationActivity(userId, requestType);
// If the launcher doesn't support it, just return a rejected result and finish.
if (confirmActivity == null) {
@@ -210,7 +211,8 @@ class ShortcutRequestPinProcessor {
request = new PinItemRequest(inAppWidget,
new PinItemRequestInner(this, resultIntent, launcherUid));
}
- return startRequestConfirmActivity(confirmActivity.first, launcherUserId, request);
+ return startRequestConfirmActivity(confirmActivity.first, launcherUserId, request,
+ requestType);
}
/**
@@ -330,9 +332,13 @@ class ShortcutRequestPinProcessor {
}
private boolean startRequestConfirmActivity(ComponentName activity, int launcherUserId,
- PinItemRequest request) {
+ PinItemRequest request, int requestType) {
+ final String action = requestType == LauncherApps.PinItemRequest.REQUEST_TYPE_SHORTCUT ?
+ LauncherApps.ACTION_CONFIRM_PIN_SHORTCUT :
+ LauncherApps.ACTION_CONFIRM_PIN_APPWIDGET;
+
// Start the activity.
- final Intent confirmIntent = new Intent(LauncherApps.ACTION_CONFIRM_PIN_ITEM);
+ final Intent confirmIntent = new Intent(action);
confirmIntent.setComponent(activity);
confirmIntent.putExtra(LauncherApps.EXTRA_PIN_ITEM_REQUEST, request);
confirmIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK);
@@ -351,13 +357,13 @@ class ShortcutRequestPinProcessor {
}
/**
- * Find the activity that handles {@link LauncherApps#ACTION_CONFIRM_PIN_ITEM} in the
+ * Find the activity that handles {@link LauncherApps#ACTION_CONFIRM_PIN_SHORTCUT} in the
* default launcher.
*/
@Nullable
@VisibleForTesting
- Pair<ComponentName, Integer> getRequestPinShortcutConfirmationActivity(
- int callingUserId) {
+ Pair<ComponentName, Integer> getRequestPinConfirmationActivity(
+ int callingUserId, int requestType) {
// Find the default launcher.
final int launcherUserId = mService.getParentOrSelfUserId(callingUserId);
final ComponentName defaultLauncher = mService.getDefaultLauncher(launcherUserId);
@@ -367,7 +373,7 @@ class ShortcutRequestPinProcessor {
return null;
}
final ComponentName activity = mService.injectGetPinConfirmationActivity(
- defaultLauncher.getPackageName(), launcherUserId);
+ defaultLauncher.getPackageName(), launcherUserId, requestType);
return (activity == null) ? null : Pair.create(activity, launcherUserId);
}
diff --git a/services/core/java/com/android/server/pm/ShortcutService.java b/services/core/java/com/android/server/pm/ShortcutService.java
index ae709feb4bd3..7618dcd09b92 100644
--- a/services/core/java/com/android/server/pm/ShortcutService.java
+++ b/services/core/java/com/android/server/pm/ShortcutService.java
@@ -2116,10 +2116,11 @@ public class ShortcutService extends IShortcutService.Stub {
}
@Override
- public boolean isRequestPinShortcutSupported(int callingUserId) {
+ public boolean isRequestPinItemSupported(int callingUserId, int requestType) {
final long token = injectClearCallingIdentity();
try {
- return mShortcutRequestPinProcessor.isRequestPinnedShortcutSupported(callingUserId);
+ return mShortcutRequestPinProcessor
+ .isRequestPinItemSupported(callingUserId, requestType);
} finally {
injectRestoreCallingIdentity(token);
}
@@ -2620,6 +2621,11 @@ public class ShortcutService extends IShortcutService.Stub {
Preconditions.checkNotNull(appWidget);
return requestPinItem(callingPackage, userId, null, appWidget, resultIntent);
}
+
+ @Override
+ public boolean isRequestPinItemSupported(int callingUserId, int requestType) {
+ return ShortcutService.this.isRequestPinItemSupported(callingUserId, requestType);
+ }
}
final BroadcastReceiver mReceiver = new BroadcastReceiver() {
@@ -3241,16 +3247,19 @@ public class ShortcutService extends IShortcutService.Stub {
}
/**
- * Get the {@link LauncherApps#ACTION_CONFIRM_PIN_ITEM} activity in a given package.
+ * Get the {@link LauncherApps#ACTION_CONFIRM_PIN_SHORTCUT} or
+ * {@link LauncherApps#ACTION_CONFIRM_PIN_APPWIDGET} activity in a given package depending on
+ * the requestType.
*/
@Nullable
ComponentName injectGetPinConfirmationActivity(@NonNull String launcherPackageName,
- int launcherUserId) {
+ int launcherUserId, int requestType) {
Preconditions.checkNotNull(launcherPackageName);
+ String action = requestType == LauncherApps.PinItemRequest.REQUEST_TYPE_SHORTCUT ?
+ LauncherApps.ACTION_CONFIRM_PIN_SHORTCUT :
+ LauncherApps.ACTION_CONFIRM_PIN_APPWIDGET;
- final Intent confirmIntent = new Intent(LauncherApps.ACTION_CONFIRM_PIN_ITEM);
- confirmIntent.setPackage(launcherPackageName);
-
+ final Intent confirmIntent = new Intent(action).setPackage(launcherPackageName);
final List<ResolveInfo> candidates = queryActivities(
confirmIntent, launcherUserId, /* exportedOnly =*/ false);
for (ResolveInfo ri : candidates) {
diff --git a/services/tests/servicestests/src/com/android/server/appwidget/AppWidgetServiceImplTest.java b/services/tests/servicestests/src/com/android/server/appwidget/AppWidgetServiceImplTest.java
index 677e468f6550..d7bfc44b14ca 100644
--- a/services/tests/servicestests/src/com/android/server/appwidget/AppWidgetServiceImplTest.java
+++ b/services/tests/servicestests/src/com/android/server/appwidget/AppWidgetServiceImplTest.java
@@ -36,6 +36,7 @@ import android.content.ContextWrapper;
import android.content.Intent;
import android.content.IntentFilter;
import android.content.IntentSender;
+import android.content.pm.LauncherApps;
import android.content.pm.ShortcutServiceInternal;
import android.os.Handler;
import android.os.UserHandle;
@@ -121,6 +122,18 @@ public class AppWidgetServiceImplTest extends InstrumentationTestCase {
assertEquals(provider, providerCaptor.getValue().provider);
}
+ public void testIsRequestPinAppWidgetSupported() {
+ ComponentName provider = new ComponentName(mTestContext, DummyAppWidget.class);
+ // Set up users.
+ when(mMockShortcutService.isRequestPinItemSupported(anyInt(), anyInt()))
+ .thenReturn(true, false);
+ assertTrue(mManager.isRequestPinAppWidgetSupported());
+ assertFalse(mManager.isRequestPinAppWidgetSupported());
+
+ verify(mMockShortcutService, times(2)).isRequestPinItemSupported(anyInt(),
+ eq(LauncherApps.PinItemRequest.REQUEST_TYPE_APPWIDGET));
+ }
+
public void testProviderUpdatesReceived() throws Exception {
int widgetId = setupHostAndWidget();
RemoteViews view = new RemoteViews(mPkgName, android.R.layout.simple_list_item_1);
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 167b33ac31a7..f2bd1184db15 100644
--- a/services/tests/servicestests/src/com/android/server/pm/BaseShortcutManagerTest.java
+++ b/services/tests/servicestests/src/com/android/server/pm/BaseShortcutManagerTest.java
@@ -398,7 +398,7 @@ public abstract class BaseShortcutManagerTest extends InstrumentationTestCase {
@Override
ComponentName injectGetPinConfirmationActivity(@NonNull String launcherPackageName,
- int launcherUserId) {
+ int launcherUserId, int requestType) {
return mPinConfirmActivityFetcher.apply(launcherPackageName, launcherUserId);
}
diff --git a/services/tests/servicestests/src/com/android/server/pm/ShortcutManagerTest8.java b/services/tests/servicestests/src/com/android/server/pm/ShortcutManagerTest8.java
index 96e89485874b..0310e16166d2 100644
--- a/services/tests/servicestests/src/com/android/server/pm/ShortcutManagerTest8.java
+++ b/services/tests/servicestests/src/com/android/server/pm/ShortcutManagerTest8.java
@@ -93,21 +93,24 @@ public class ShortcutManagerTest8 extends BaseShortcutManagerTest {
Pair<ComponentName, Integer> actual;
// User 0
- actual = mProcessor.getRequestPinShortcutConfirmationActivity(USER_0);
+ actual = mProcessor.getRequestPinConfirmationActivity(USER_0,
+ PinItemRequest.REQUEST_TYPE_SHORTCUT);
assertEquals(LAUNCHER_1, actual.first.getPackageName());
assertEquals(PIN_CONFIRM_ACTIVITY_CLASS, actual.first.getClassName());
assertEquals(USER_0, (int) actual.second);
// User 10
- actual = mProcessor.getRequestPinShortcutConfirmationActivity(USER_10);
+ actual = mProcessor.getRequestPinConfirmationActivity(USER_10,
+ PinItemRequest.REQUEST_TYPE_SHORTCUT);
assertEquals(LAUNCHER_2, actual.first.getPackageName());
assertEquals(PIN_CONFIRM_ACTIVITY_CLASS, actual.first.getClassName());
assertEquals(USER_10, (int) actual.second);
// User P0 -> managed profile, return user-0's launcher.
- actual = mProcessor.getRequestPinShortcutConfirmationActivity(USER_P0);
+ actual = mProcessor.getRequestPinConfirmationActivity(USER_P0,
+ PinItemRequest.REQUEST_TYPE_SHORTCUT);
assertEquals(LAUNCHER_1, actual.first.getPackageName());
assertEquals(PIN_CONFIRM_ACTIVITY_CLASS, actual.first.getClassName());
@@ -133,15 +136,18 @@ public class ShortcutManagerTest8 extends BaseShortcutManagerTest {
? null : new ComponentName(packageName, PIN_CONFIRM_ACTIVITY_CLASS);
// User 10 -- still has confirm activity.
- actual = mProcessor.getRequestPinShortcutConfirmationActivity(USER_10);
+ actual = mProcessor.getRequestPinConfirmationActivity(USER_10,
+ PinItemRequest.REQUEST_TYPE_SHORTCUT);
assertEquals(LAUNCHER_2, actual.first.getPackageName());
assertEquals(PIN_CONFIRM_ACTIVITY_CLASS, actual.first.getClassName());
assertEquals(USER_10, (int) actual.second);
// But user-0 and user p0 no longer has a confirmation activity.
- assertNull(mProcessor.getRequestPinShortcutConfirmationActivity(USER_0));
- assertNull(mProcessor.getRequestPinShortcutConfirmationActivity(USER_P0));
+ assertNull(mProcessor.getRequestPinConfirmationActivity(USER_0,
+ PinItemRequest.REQUEST_TYPE_SHORTCUT));
+ assertNull(mProcessor.getRequestPinConfirmationActivity(USER_P0,
+ PinItemRequest.REQUEST_TYPE_SHORTCUT));
// Check from the public API.
runWithCaller(CALLING_PACKAGE_1, USER_0, () -> {
@@ -204,7 +210,7 @@ public class ShortcutManagerTest8 extends BaseShortcutManagerTest {
}
private void assertPinItemRequestIntent(Intent actualIntent, String expectedPackage) {
- assertEquals(LauncherApps.ACTION_CONFIRM_PIN_ITEM, actualIntent.getAction());
+ assertEquals(LauncherApps.ACTION_CONFIRM_PIN_SHORTCUT, actualIntent.getAction());
assertEquals(expectedPackage, actualIntent.getComponent().getPackageName());
assertEquals(PIN_CONFIRM_ACTIVITY_CLASS,
actualIntent.getComponent().getClassName());
diff --git a/services/tests/servicestests/src/com/android/server/pm/ShortcutManagerTest9.java b/services/tests/servicestests/src/com/android/server/pm/ShortcutManagerTest9.java
index cfa35c2c50a2..26033a355967 100644
--- a/services/tests/servicestests/src/com/android/server/pm/ShortcutManagerTest9.java
+++ b/services/tests/servicestests/src/com/android/server/pm/ShortcutManagerTest9.java
@@ -72,7 +72,7 @@ public class ShortcutManagerTest9 extends BaseShortcutManagerTest {
}
private void assertPinItemRequestIntent(Intent actualIntent, String expectedPackage) {
- assertEquals(LauncherApps.ACTION_CONFIRM_PIN_ITEM, actualIntent.getAction());
+ assertEquals(LauncherApps.ACTION_CONFIRM_PIN_APPWIDGET, actualIntent.getAction());
assertEquals(expectedPackage, actualIntent.getComponent().getPackageName());
assertEquals(PIN_CONFIRM_ACTIVITY_CLASS,
actualIntent.getComponent().getClassName());