public @interface RequestType {}
private final int mRequestType;
- private final ShortcutInfo mShortcutInfo;
- private final AppWidgetProviderInfo mAppWidgetInfo;
private final IPinItemRequest mInner;
/**
* @hide
*/
- public PinItemRequest(ShortcutInfo shortcutInfo, IPinItemRequest inner) {
- mRequestType = REQUEST_TYPE_SHORTCUT;
- mShortcutInfo = shortcutInfo;
- mAppWidgetInfo = null;
- mInner = inner;
- }
-
- /**
- * @hide
- */
- public PinItemRequest(AppWidgetProviderInfo appWidgetInfo, IPinItemRequest inner) {
- mRequestType = REQUEST_TYPE_APPWIDGET;
- mShortcutInfo = null;
- mAppWidgetInfo = appWidgetInfo;
+ public PinItemRequest(IPinItemRequest inner, int type) {
mInner = inner;
+ mRequestType = type;
}
/**
*/
@Nullable
public ShortcutInfo getShortcutInfo() {
- return mShortcutInfo;
+ try {
+ return mInner.getShortcutInfo();
+ } catch (RemoteException e) {
+ throw e.rethrowAsRuntimeException();
+ }
}
/**
*/
@Nullable
public AppWidgetProviderInfo getAppWidgetProviderInfo(Context context) {
- if (mAppWidgetInfo != null) {
- AppWidgetProviderInfo info = mAppWidgetInfo.clone();
+ try {
+ final AppWidgetProviderInfo info = mInner.getAppWidgetProviderInfo();
+ if (info == null) {
+ return null;
+ }
info.updateDimensions(context.getResources().getDisplayMetrics());
return info;
+ } catch (RemoteException e) {
+ throw e.rethrowAsRuntimeException();
}
- return null;
}
/**
final ClassLoader cl = getClass().getClassLoader();
mRequestType = source.readInt();
- mShortcutInfo = mRequestType == REQUEST_TYPE_SHORTCUT ?
- (ShortcutInfo) source.readParcelable(cl) : null;
- mAppWidgetInfo = mRequestType == REQUEST_TYPE_APPWIDGET ?
- (AppWidgetProviderInfo) source.readParcelable(cl) : null;
mInner = IPinItemRequest.Stub.asInterface(source.readStrongBinder());
}
@Override
public void writeToParcel(Parcel dest, int flags) {
dest.writeInt(mRequestType);
- if (mRequestType == REQUEST_TYPE_SHORTCUT) {
- dest.writeParcelable(mShortcutInfo, flags);
- }
- if (mRequestType == REQUEST_TYPE_APPWIDGET) {
- dest.writeParcelable(mAppWidgetInfo, flags);
- }
dest.writeStrongBinder(mInner.asBinder());
}
/**
* Internal for {@link android.content.pm.LauncherApps.PinItemRequest} which receives callbacks.
*/
- private static class PinItemRequestInner extends IPinItemRequest.Stub {
+ private abstract static class PinItemRequestInner extends IPinItemRequest.Stub {
protected final ShortcutRequestPinProcessor mProcessor;
private final IntentSender mResultIntent;
private final int mLauncherUid;
mLauncherUid = launcherUid;
}
+ public ShortcutInfo getShortcutInfo() {
+ return null;
+ }
+
+ public AppWidgetProviderInfo getAppWidgetProviderInfo() {
+ return null;
+ }
+
/**
* Returns true if the caller is same as the default launcher app when this request
* object was created.
/**
* Internal for {@link android.content.pm.LauncherApps.PinItemRequest} which receives callbacks.
*/
+ private static class PinAppWidgetRequestInner extends PinItemRequestInner {
+ final AppWidgetProviderInfo mAppWidgetProviderInfo;
+
+ private PinAppWidgetRequestInner(ShortcutRequestPinProcessor processor,
+ IntentSender resultIntent, int launcherUid,
+ AppWidgetProviderInfo appWidgetProviderInfo) {
+ super(processor, resultIntent, launcherUid);
+
+ mAppWidgetProviderInfo = appWidgetProviderInfo;
+ }
+
+ @Override
+ public AppWidgetProviderInfo getAppWidgetProviderInfo() {
+ return mAppWidgetProviderInfo;
+ }
+ }
+
+ /**
+ * Internal for {@link android.content.pm.LauncherApps.PinItemRequest} which receives callbacks.
+ */
private static class PinShortcutRequestInner extends PinItemRequestInner {
/** Original shortcut passed by the app. */
public final ShortcutInfo shortcutOriginal;
}
@Override
+ public ShortcutInfo getShortcutInfo() {
+ return shortcutForLauncher;
+ }
+
+ @Override
protected boolean tryAccept() {
if (DEBUG) {
Slog.d(TAG, "Launcher accepted shortcut. ID=" + shortcutOriginal.getId()
} else {
int launcherUid = mService.injectGetPackageUid(
confirmActivity.first.getPackageName(), launcherUserId);
- request = new PinItemRequest(inAppWidget,
- new PinItemRequestInner(this, resultIntent, launcherUid));
+ request = new PinItemRequest(
+ new PinAppWidgetRequestInner(this, resultIntent, launcherUid, inAppWidget),
+ PinItemRequest.REQUEST_TYPE_APPWIDGET);
}
return startRequestConfirmActivity(confirmActivity.first, launcherUserId, request,
requestType);
mService.injectGetPackageUid(launcherPackage, launcherUserId),
existsAlready);
- return new PinItemRequest(shortcutForLauncher, inner);
+ return new PinItemRequest(inner, PinItemRequest.REQUEST_TYPE_SHORTCUT);
}
private void validateExistingShortcut(ShortcutInfo shortcutInfo) {