summaryrefslogtreecommitdiffstats
path: root/core/java/android/appwidget
diff options
context:
space:
mode:
authorSvetoslav <svetoslavganov@google.com>2014-08-08 12:48:06 -0700
committerSvetoslav Ganov <svetoslavganov@google.com>2014-08-08 20:35:59 +0000
commit8e1d299da27da534b508b1da51ebe351a689cefa (patch)
tree9e83a2646024f422190d0e9ddfee54aa913b9f66 /core/java/android/appwidget
parent5c8ea2c369deab75719fe7c7301846a8ef955702 (diff)
downloadframeworks_base-8e1d299da27da534b508b1da51ebe351a689cefa.zip
frameworks_base-8e1d299da27da534b508b1da51ebe351a689cefa.tar.gz
frameworks_base-8e1d299da27da534b508b1da51ebe351a689cefa.tar.bz2
Polish the new cross-profile app widget APIs
bug:14991269 Change-Id: I5996f8c69a3d151ff1ecd8f19403dd606f588150
Diffstat (limited to 'core/java/android/appwidget')
-rw-r--r--core/java/android/appwidget/AppWidgetHost.java31
-rw-r--r--core/java/android/appwidget/AppWidgetManager.java37
-rw-r--r--core/java/android/appwidget/AppWidgetProviderInfo.java5
3 files changed, 35 insertions, 38 deletions
diff --git a/core/java/android/appwidget/AppWidgetHost.java b/core/java/android/appwidget/AppWidgetHost.java
index 66a6eb6..69716e5 100644
--- a/core/java/android/appwidget/AppWidgetHost.java
+++ b/core/java/android/appwidget/AppWidgetHost.java
@@ -19,12 +19,15 @@ package android.appwidget;
import java.util.ArrayList;
import java.util.HashMap;
+import android.annotation.NonNull;
+import android.annotation.Nullable;
import android.app.Activity;
import android.content.ActivityNotFoundException;
import android.content.Context;
import android.content.Intent;
import android.content.IntentSender;
import android.os.Binder;
+import android.os.Bundle;
import android.os.Handler;
import android.os.IBinder;
import android.os.Looper;
@@ -199,32 +202,30 @@ public class AppWidgetHost {
/**
* Starts an app widget provider configure activity for result on behalf of the caller.
* Use this method if the provider is in another profile as you are not allowed to start
- * an activity in another profile. The provided intent must have action {@link
- * AppWidgetManager#ACTION_APPWIDGET_CONFIGURE}. The widget id must be specified by
- * the {@link AppWidgetManager#EXTRA_APPWIDGET_ID} extra. The provider configure
- * activity must be specified as the component name of the intent via {@link
- * Intent#setComponent(android.content.ComponentName)}. The user profile under which
- * the provider operates is specified via the {@link
- * AppWidgetManager#EXTRA_APPWIDGET_PROVIDER_PROFILE} extra. If a user profile is
- * not provided, the current user is used. Finally, you can optionally provide a
- * request code that is returned in {@link Activity#onActivityResult(int, int,
- * android.content.Intent)}.
+ * an activity in another profile. You can optionally provide a request code that is
+ * returned in {@link Activity#onActivityResult(int, int, android.content.Intent)} and
+ * an options bundle to be passed to the started activity.
+ * <p>
+ * Note that the provided app widget has to be bound for this method to work.
+ * </p>
*
* @param activity The activity from which to start the configure one.
- * @param intent Properly populated intent for launching the configuration activity.
+ * @param appWidgetId The bound app widget whose provider's config activity to start.
* @param requestCode Optional request code retuned with the result.
+ * @param intentFlags Optional intent flags.
*
* @throws android.content.ActivityNotFoundException If the activity is not found.
*
* @see AppWidgetProviderInfo#getProfile()
*/
- public final void startAppWidgetConfigureActivityForResult(Activity activity, Intent intent,
- int requestCode) {
+ public final void startAppWidgetConfigureActivityForResult(@NonNull Activity activity,
+ int appWidgetId, int intentFlags, int requestCode, @Nullable Bundle options) {
try {
IntentSender intentSender = sService.createAppWidgetConfigIntentSender(
- mContext.getPackageName(), intent);
+ mContext.getPackageName(), appWidgetId, intentFlags);
if (intentSender != null) {
- activity.startIntentSenderForResult(intentSender, requestCode, null, 0, 0, 0);
+ activity.startIntentSenderForResult(intentSender, requestCode, null, 0, 0, 0,
+ options);
} else {
throw new ActivityNotFoundException();
}
diff --git a/core/java/android/appwidget/AppWidgetManager.java b/core/java/android/appwidget/AppWidgetManager.java
index e5d1d95..086eb7d 100644
--- a/core/java/android/appwidget/AppWidgetManager.java
+++ b/core/java/android/appwidget/AppWidgetManager.java
@@ -16,6 +16,7 @@
package android.appwidget;
+import android.annotation.Nullable;
import android.content.ComponentName;
import android.content.Context;
import android.content.Intent;
@@ -673,24 +674,24 @@ public class AppWidgetManager {
}
/**
- * Gets the AppWidget providers for the given user profiles. User profiles can only
+ * Gets the AppWidget providers for the given user profile. User profile can only
* be the current user or a profile of the current user. For example, the current
* user may have a corporate profile. In this case the parent user profile has a
* child profile, the corporate one.
*
- * @param profiles The profiles for which to get providers. Passing null is equivaled
+ * @param profile The profile for which to get providers. Passing null is equivaled
* to passing only the current user handle.
* @return The intalled providers.
*
* @see android.os.Process#myUserHandle()
* @see android.os.UserManager#getUserProfiles()
*/
- public List<AppWidgetProviderInfo> getInstalledProvidersForProfiles(UserHandle[] profiles) {
+ public List<AppWidgetProviderInfo> getInstalledProvidersForProfile(@Nullable UserHandle profile) {
if (mService == null) {
return Collections.emptyList();
}
- return getInstalledProvidersForProfiles(AppWidgetProviderInfo.WIDGET_CATEGORY_HOME_SCREEN,
- profiles);
+ return getInstalledProvidersForProfile(AppWidgetProviderInfo.WIDGET_CATEGORY_HOME_SCREEN,
+ profile);
}
/**
@@ -700,7 +701,7 @@ public class AppWidgetManager {
if (mService == null) {
return Collections.emptyList();
}
- return getInstalledProvidersForProfiles(AppWidgetProviderInfo.WIDGET_CATEGORY_HOME_SCREEN,
+ return getInstalledProvidersForProfile(AppWidgetProviderInfo.WIDGET_CATEGORY_HOME_SCREEN,
null);
}
@@ -720,18 +721,18 @@ public class AppWidgetManager {
if (mService == null) {
return Collections.emptyList();
}
- return getInstalledProvidersForProfiles(categoryFilter, null);
+ return getInstalledProvidersForProfile(categoryFilter, null);
}
/**
- * Gets the AppWidget providers for the given user profiles. User profiles can only
+ * Gets the AppWidget providers for the given user profile. User profile can only
* be the current user or a profile of the current user. For example, the current
* user may have a corporate profile. In this case the parent user profile has a
* child profile, the corporate one.
*
* @param categoryFilter Will only return providers which register as any of the specified
* specified categories. See {@link AppWidgetProviderInfo#widgetCategory}.
- * @param profiles Child profiles of the current user which to be queried. The user
+ * @param profile A profile of the current user which to be queried. The user
* is itself also a profile. If null, the providers only for the current user
* are returned.
* @return The intalled providers.
@@ -741,25 +742,19 @@ public class AppWidgetManager {
*
* @hide
*/
- public List<AppWidgetProviderInfo> getInstalledProvidersForProfiles(int categoryFilter,
- UserHandle[] profiles) {
+ public List<AppWidgetProviderInfo> getInstalledProvidersForProfile(int categoryFilter,
+ UserHandle profile) {
if (mService == null) {
return Collections.emptyList();
}
- int[] profileIds = null;
-
- if (profiles != null) {
- final int profileCount = profiles.length;
- profileIds = new int[profileCount];
- for (int i = 0; i < profileCount; i++) {
- profileIds[i] = profiles[i].getIdentifier();
- }
+ if (profile == null) {
+ profile = Process.myUserHandle();
}
try {
- List<AppWidgetProviderInfo> providers = mService.getInstalledProviders(categoryFilter,
- profileIds);
+ List<AppWidgetProviderInfo> providers = mService.getInstalledProvidersForProfile(
+ categoryFilter, profile.getIdentifier());
if (providers == null) {
return Collections.emptyList();
}
diff --git a/core/java/android/appwidget/AppWidgetProviderInfo.java b/core/java/android/appwidget/AppWidgetProviderInfo.java
index 6835368..a767246 100644
--- a/core/java/android/appwidget/AppWidgetProviderInfo.java
+++ b/core/java/android/appwidget/AppWidgetProviderInfo.java
@@ -16,6 +16,7 @@
package android.appwidget;
+import android.annotation.NonNull;
import android.content.Context;
import android.content.pm.ActivityInfo;
import android.content.pm.PackageManager;
@@ -269,7 +270,7 @@ public class AppWidgetProviderInfo implements Parcelable {
* {@link android.util.DisplayMetrics#densityDpi}.
* @return The provider icon.
*/
- public final Drawable loadIcon(Context context, int density) {
+ public final Drawable loadIcon(@NonNull Context context, int density) {
return loadDrawable(context, density, providerInfo.getIconResource());
}
@@ -289,7 +290,7 @@ public class AppWidgetProviderInfo implements Parcelable {
* {@link android.util.DisplayMetrics#densityDpi}.
* @return The widget preview image.
*/
- public final Drawable loadPreviewImage(Context context, int density) {
+ public final Drawable loadPreviewImage(@NonNull Context context, int density) {
return loadDrawable(context, density, previewImage);
}