summaryrefslogtreecommitdiffstats
path: root/core/java/android/appwidget/AppWidgetManager.java
diff options
context:
space:
mode:
Diffstat (limited to 'core/java/android/appwidget/AppWidgetManager.java')
-rw-r--r--core/java/android/appwidget/AppWidgetManager.java413
1 files changed, 297 insertions, 116 deletions
diff --git a/core/java/android/appwidget/AppWidgetManager.java b/core/java/android/appwidget/AppWidgetManager.java
index e5bf7d0..e5d1d95 100644
--- a/core/java/android/appwidget/AppWidgetManager.java
+++ b/core/java/android/appwidget/AppWidgetManager.java
@@ -21,8 +21,8 @@ import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.os.IBinder;
+import android.os.Process;
import android.os.RemoteException;
-import android.os.ServiceManager;
import android.os.UserHandle;
import android.util.DisplayMetrics;
import android.util.TypedValue;
@@ -30,9 +30,8 @@ import android.widget.RemoteViews;
import com.android.internal.appwidget.IAppWidgetService;
-import java.lang.ref.WeakReference;
+import java.util.Collections;
import java.util.List;
-import java.util.WeakHashMap;
/**
* Updates AppWidget state; gets information about installed AppWidget providers and other
@@ -45,7 +44,6 @@ import java.util.WeakHashMap;
* </div>
*/
public class AppWidgetManager {
- static final String TAG = "AppWidgetManager";
/**
* Activity action to launch from your {@link AppWidgetHost} activity when you want to
@@ -72,9 +70,9 @@ public class AppWidgetManager {
* <p>
* When you receive the result from the AppWidget pick activity, if the resultCode is
* {@link android.app.Activity#RESULT_OK}, an AppWidget has been selected. You should then
- * check the AppWidgetProviderInfo for the returned AppWidget, and if it has one, launch its configuration
- * activity. If {@link android.app.Activity#RESULT_CANCELED} is returned, you should delete
- * the appWidgetId.
+ * check the AppWidgetProviderInfo for the returned AppWidget, and if it has one, launch its
+ * configuration activity. If {@link android.app.Activity#RESULT_CANCELED} is returned, you
+ * should delete the appWidgetId.
*
* @see #ACTION_APPWIDGET_CONFIGURE
*/
@@ -103,6 +101,12 @@ public class AppWidgetManager {
* <td>The BroadcastReceiver that will be the AppWidget provider for this AppWidget.
* </td>
* </tr>
+ * <tr>
+ * <td>{@link #EXTRA_APPWIDGET_PROVIDER_PROFILE}</td>
+ * <td>An optional handle to a user profile under which runs the provider
+ * for this AppWidget.
+ * </td>
+ * </tr>
* </table>
*
* <p>
@@ -119,8 +123,7 @@ public class AppWidgetManager {
* {@link android.app.Activity#RESULT_OK}, the AppWidget has been bound. You should then
* check the AppWidgetProviderInfo for the returned AppWidget, and if it has one, launch its
* configuration activity. If {@link android.app.Activity#RESULT_CANCELED} is returned, you
- * should delete
- * the appWidgetId.
+ * should delete the appWidgetId.
*
* @see #ACTION_APPWIDGET_CONFIGURE
*
@@ -130,7 +133,8 @@ public class AppWidgetManager {
/**
* Sent when it is time to configure your AppWidget while it is being added to a host.
* This action is not sent as a broadcast to the AppWidget provider, but as a startActivity
- * to the activity specified in the {@link AppWidgetProviderInfo AppWidgetProviderInfo meta-data}.
+ * to the activity specified in the {@link AppWidgetProviderInfo AppWidgetProviderInfo
+ * meta-data}.
*
* <p>
* The intent will contain the following extras:
@@ -145,7 +149,8 @@ public class AppWidgetManager {
* {@link android.app.Activity#setResult Activity.setResult()}, the AppWidget will be added,
* and you will receive an {@link #ACTION_APPWIDGET_UPDATE} broadcast for this AppWidget.
* If you return {@link android.app.Activity#RESULT_CANCELED}, the host will cancel the add
- * and not display this AppWidget, and you will receive a {@link #ACTION_APPWIDGET_DELETED} broadcast.
+ * and not display this AppWidget, and you will receive a {@link #ACTION_APPWIDGET_DELETED}
+ * broadcast.
*/
public static final String ACTION_APPWIDGET_CONFIGURE = "android.appwidget.action.APPWIDGET_CONFIGURE";
@@ -188,7 +193,9 @@ public class AppWidgetManager {
/**
* An intent extra which points to a bundle of extra information for a particular widget id.
- * In particular this bundle can contain EXTRA_APPWIDGET_WIDTH and EXTRA_APPWIDGET_HEIGHT.
+ * In particular this bundle can contain {@link #OPTION_APPWIDGET_MIN_WIDTH},
+ * {@link #OPTION_APPWIDGET_MIN_HEIGHT}, {@link #OPTION_APPWIDGET_MAX_WIDTH},
+ * {@link #OPTION_APPWIDGET_MAX_HEIGHT}.
*/
public static final String EXTRA_APPWIDGET_OPTIONS = "appWidgetOptions";
@@ -203,11 +210,19 @@ public class AppWidgetManager {
/**
* An intent extra that contains the component name of a AppWidget provider.
* <p>
- * The value will be an ComponentName.
+ * The value will be an {@link android.content.ComponentName}.
*/
public static final String EXTRA_APPWIDGET_PROVIDER = "appWidgetProvider";
/**
+ * An intent extra that contains the user handle of the profile under
+ * which an AppWidget provider is registered.
+ * <p>
+ * The value will be a {@link android.os.UserHandle}.
+ */
+ public static final String EXTRA_APPWIDGET_PROVIDER_PROFILE = "appWidgetProviderProfile";
+
+ /**
* An intent extra to pass to the AppWidget picker containing a {@link java.util.List} of
* {@link AppWidgetProviderInfo} objects to mix in to the list of AppWidgets that are
* installed. (This is how the launcher shows the search widget).
@@ -295,12 +310,12 @@ public class AppWidgetManager {
public static final String ACTION_APPWIDGET_DELETED = "android.appwidget.action.APPWIDGET_DELETED";
/**
- * Sent when an instance of an AppWidget is removed from the last host.
+ * Sent when the last AppWidget of this provider is removed from the last host.
*
* <p class="note">This is a protected intent that can only be sent
* by the system.
*
- * @see AppWidgetProvider#onEnabled AppWidgetProvider.onEnabled(Context context)
+ * @see AppWidgetProvider#onEnabled AppWidgetProvider.onDisabled(Context context)
*/
public static final String ACTION_APPWIDGET_DISABLED = "android.appwidget.action.APPWIDGET_DISABLED";
@@ -403,46 +418,36 @@ public class AppWidgetManager {
*/
public static final String META_DATA_APPWIDGET_PROVIDER = "android.appwidget.provider";
- static WeakHashMap<Context, WeakReference<AppWidgetManager>> sManagerCache =
- new WeakHashMap<Context, WeakReference<AppWidgetManager>>();
- static IAppWidgetService sService;
+ private final String mPackageName;
- Context mContext;
+ private final IAppWidgetService mService;
- private DisplayMetrics mDisplayMetrics;
+ private final DisplayMetrics mDisplayMetrics;
/**
* Get the AppWidgetManager instance to use for the supplied {@link android.content.Context
* Context} object.
*/
public static AppWidgetManager getInstance(Context context) {
- synchronized (sManagerCache) {
- if (sService == null) {
- IBinder b = ServiceManager.getService(Context.APPWIDGET_SERVICE);
- sService = IAppWidgetService.Stub.asInterface(b);
- }
-
- WeakReference<AppWidgetManager> ref = sManagerCache.get(context);
- AppWidgetManager result = null;
- if (ref != null) {
- result = ref.get();
- }
- if (result == null) {
- result = new AppWidgetManager(context);
- sManagerCache.put(context, new WeakReference<AppWidgetManager>(result));
- }
- return result;
- }
+ return (AppWidgetManager) context.getSystemService(Context.APPWIDGET_SERVICE);
}
- private AppWidgetManager(Context context) {
- mContext = context;
+ /**
+ * Creates a new instance.
+ *
+ * @param context The current context in which to operate.
+ * @param service The backing system service.
+ * @hide
+ */
+ public AppWidgetManager(Context context, IAppWidgetService service) {
+ mPackageName = context.getPackageName();
+ mService = service;
mDisplayMetrics = context.getResources().getDisplayMetrics();
}
/**
* Set the RemoteViews to use for the specified appWidgetIds.
- *
+ * <p>
* Note that the RemoteViews parameter will be cached by the AppWidgetService, and hence should
* contain a complete representation of the widget. For performing partial widget updates, see
* {@link #partiallyUpdateAppWidget(int[], RemoteViews)}.
@@ -456,12 +461,15 @@ public class AppWidgetManager {
* The total Bitmap memory used by the RemoteViews object cannot exceed that required to
* fill the screen 1.5 times, ie. (screen width x screen height x 4 x 1.5) bytes.
*
- * @param appWidgetIds The AppWidget instances for which to set the RemoteViews.
- * @param views The RemoteViews object to show.
+ * @param appWidgetIds The AppWidget instances for which to set the RemoteViews.
+ * @param views The RemoteViews object to show.
*/
public void updateAppWidget(int[] appWidgetIds, RemoteViews views) {
+ if (mService == null) {
+ return;
+ }
try {
- sService.updateAppWidgetIds(appWidgetIds, views, mContext.getUserId());
+ mService.updateAppWidgetIds(mPackageName, appWidgetIds, views);
}
catch (RemoteException e) {
throw new RuntimeException("system server dead?", e);
@@ -470,18 +478,21 @@ public class AppWidgetManager {
/**
* Update the extras for a given widget instance.
- *
+ * <p>
* The extras can be used to embed additional information about this widget to be accessed
* by the associated widget's AppWidgetProvider.
*
* @see #getAppWidgetOptions(int)
*
- * @param appWidgetId The AppWidget instances for which to set the RemoteViews.
- * @param options The options to associate with this widget
+ * @param appWidgetId The AppWidget instances for which to set the RemoteViews.
+ * @param options The options to associate with this widget
*/
public void updateAppWidgetOptions(int appWidgetId, Bundle options) {
+ if (mService == null) {
+ return;
+ }
try {
- sService.updateAppWidgetOptions(appWidgetId, options, mContext.getUserId());
+ mService.updateAppWidgetOptions(mPackageName, appWidgetId, options);
}
catch (RemoteException e) {
throw new RuntimeException("system server dead?", e);
@@ -490,18 +501,21 @@ public class AppWidgetManager {
/**
* Get the extras associated with a given widget instance.
- *
+ * <p>
* The extras can be used to embed additional information about this widget to be accessed
* by the associated widget's AppWidgetProvider.
*
* @see #updateAppWidgetOptions(int, Bundle)
*
- * @param appWidgetId The AppWidget instances for which to set the RemoteViews.
- * @return The options associated with the given widget instance.
+ * @param appWidgetId The AppWidget instances for which to set the RemoteViews.
+ * @return The options associated with the given widget instance.
*/
public Bundle getAppWidgetOptions(int appWidgetId) {
+ if (mService == null) {
+ return Bundle.EMPTY;
+ }
try {
- return sService.getAppWidgetOptions(appWidgetId, mContext.getUserId());
+ return mService.getAppWidgetOptions(mPackageName, appWidgetId);
}
catch (RemoteException e) {
throw new RuntimeException("system server dead?", e);
@@ -510,7 +524,7 @@ public class AppWidgetManager {
/**
* Set the RemoteViews to use for the specified appWidgetId.
- *
+ * <p>
* Note that the RemoteViews parameter will be cached by the AppWidgetService, and hence should
* contain a complete representation of the widget. For performing partial widget updates, see
* {@link #partiallyUpdateAppWidget(int, RemoteViews)}.
@@ -528,12 +542,15 @@ public class AppWidgetManager {
* @param views The RemoteViews object to show.
*/
public void updateAppWidget(int appWidgetId, RemoteViews views) {
+ if (mService == null) {
+ return;
+ }
updateAppWidget(new int[] { appWidgetId }, views);
}
/**
* Perform an incremental update or command on the widget(s) specified by appWidgetIds.
- *
+ * <p>
* This update differs from {@link #updateAppWidget(int[], RemoteViews)} in that the
* RemoteViews object which is passed is understood to be an incomplete representation of the
* widget, and hence does not replace the cached representation of the widget. As of API
@@ -556,8 +573,11 @@ public class AppWidgetManager {
* @param views The RemoteViews object containing the incremental update / command.
*/
public void partiallyUpdateAppWidget(int[] appWidgetIds, RemoteViews views) {
+ if (mService == null) {
+ return;
+ }
try {
- sService.partiallyUpdateAppWidgetIds(appWidgetIds, views, mContext.getUserId());
+ mService.partiallyUpdateAppWidgetIds(mPackageName, appWidgetIds, views);
} catch (RemoteException e) {
throw new RuntimeException("system server dead?", e);
}
@@ -565,7 +585,7 @@ public class AppWidgetManager {
/**
* Perform an incremental update or command on the widget specified by appWidgetId.
- *
+ * <p>
* This update differs from {@link #updateAppWidget(int, RemoteViews)} in that the RemoteViews
* object which is passed is understood to be an incomplete representation of the widget, and
* hence is not cached by the AppWidgetService. Note that because these updates are not cached,
@@ -588,6 +608,9 @@ public class AppWidgetManager {
* @param views The RemoteViews object containing the incremental update / command.
*/
public void partiallyUpdateAppWidget(int appWidgetId, RemoteViews views) {
+ if (mService == null) {
+ return;
+ }
partiallyUpdateAppWidget(new int[] { appWidgetId }, views);
}
@@ -605,8 +628,11 @@ public class AppWidgetManager {
* @param views The RemoteViews object to show.
*/
public void updateAppWidget(ComponentName provider, RemoteViews views) {
+ if (mService == null) {
+ return;
+ }
try {
- sService.updateAppWidgetProvider(provider, views, mContext.getUserId());
+ mService.updateAppWidgetProvider(provider, views);
}
catch (RemoteException e) {
throw new RuntimeException("system server dead?", e);
@@ -621,8 +647,11 @@ public class AppWidgetManager {
* @param viewId The collection view id.
*/
public void notifyAppWidgetViewDataChanged(int[] appWidgetIds, int viewId) {
+ if (mService == null) {
+ return;
+ }
try {
- sService.notifyAppWidgetViewDataChanged(appWidgetIds, viewId, mContext.getUserId());
+ mService.notifyAppWidgetViewDataChanged(mPackageName, appWidgetIds, viewId);
}
catch (RemoteException e) {
throw new RuntimeException("system server dead?", e);
@@ -637,37 +666,106 @@ public class AppWidgetManager {
* @param viewId The collection view id.
*/
public void notifyAppWidgetViewDataChanged(int appWidgetId, int viewId) {
+ if (mService == null) {
+ return;
+ }
notifyAppWidgetViewDataChanged(new int[] { appWidgetId }, viewId);
}
/**
+ * Gets the AppWidget providers for the given user profiles. User profiles 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
+ * 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) {
+ if (mService == null) {
+ return Collections.emptyList();
+ }
+ return getInstalledProvidersForProfiles(AppWidgetProviderInfo.WIDGET_CATEGORY_HOME_SCREEN,
+ profiles);
+ }
+
+ /**
* Return a list of the AppWidget providers that are currently installed.
*/
public List<AppWidgetProviderInfo> getInstalledProviders() {
- return getInstalledProviders(AppWidgetProviderInfo.WIDGET_CATEGORY_HOME_SCREEN);
+ if (mService == null) {
+ return Collections.emptyList();
+ }
+ return getInstalledProvidersForProfiles(AppWidgetProviderInfo.WIDGET_CATEGORY_HOME_SCREEN,
+ null);
}
/**
- * Return a list of the AppWidget providers that are currently installed.
+ * Gets the AppWidget providers for the current user.
*
* @param categoryFilter Will only return providers which register as any of the specified
* specified categories. See {@link AppWidgetProviderInfo#widgetCategory}.
+ * @return The intalled providers.
+ *
+ * @see android.os.Process#myUserHandle()
+ * @see android.os.UserManager#getUserProfiles()
+ *
* @hide
*/
public List<AppWidgetProviderInfo> getInstalledProviders(int categoryFilter) {
+ if (mService == null) {
+ return Collections.emptyList();
+ }
+ return getInstalledProvidersForProfiles(categoryFilter, null);
+ }
+
+ /**
+ * Gets the AppWidget providers for the given user profiles. User profiles 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
+ * is itself also a profile. If null, the providers only for the current user
+ * are returned.
+ * @return The intalled providers.
+ *
+ * @see android.os.Process#myUserHandle()
+ * @see android.os.UserManager#getUserProfiles()
+ *
+ * @hide
+ */
+ public List<AppWidgetProviderInfo> getInstalledProvidersForProfiles(int categoryFilter,
+ UserHandle[] profiles) {
+ 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();
+ }
+ }
+
try {
- List<AppWidgetProviderInfo> providers = sService.getInstalledProviders(categoryFilter,
- mContext.getUserId());
+ List<AppWidgetProviderInfo> providers = mService.getInstalledProviders(categoryFilter,
+ profileIds);
+ if (providers == null) {
+ return Collections.emptyList();
+ }
for (AppWidgetProviderInfo info : providers) {
// Converting complex to dp.
- info.minWidth =
- TypedValue.complexToDimensionPixelSize(info.minWidth, mDisplayMetrics);
- info.minHeight =
- TypedValue.complexToDimensionPixelSize(info.minHeight, mDisplayMetrics);
- info.minResizeWidth =
- TypedValue.complexToDimensionPixelSize(info.minResizeWidth, mDisplayMetrics);
- info.minResizeHeight =
- TypedValue.complexToDimensionPixelSize(info.minResizeHeight, mDisplayMetrics);
+ convertSizesToPixels(info);
}
return providers;
}
@@ -683,19 +781,14 @@ public class AppWidgetManager {
* you don't have access to that appWidgetId, null is returned.
*/
public AppWidgetProviderInfo getAppWidgetInfo(int appWidgetId) {
+ if (mService == null) {
+ return null;
+ }
try {
- AppWidgetProviderInfo info = sService.getAppWidgetInfo(appWidgetId,
- mContext.getUserId());
+ AppWidgetProviderInfo info = mService.getAppWidgetInfo(mPackageName, appWidgetId);
if (info != null) {
// Converting complex to dp.
- info.minWidth =
- TypedValue.complexToDimensionPixelSize(info.minWidth, mDisplayMetrics);
- info.minHeight =
- TypedValue.complexToDimensionPixelSize(info.minHeight, mDisplayMetrics);
- info.minResizeWidth =
- TypedValue.complexToDimensionPixelSize(info.minResizeWidth, mDisplayMetrics);
- info.minResizeHeight =
- TypedValue.complexToDimensionPixelSize(info.minResizeHeight, mDisplayMetrics);
+ convertSizesToPixels(info);
}
return info;
}
@@ -717,12 +810,10 @@ public class AppWidgetManager {
* @hide
*/
public void bindAppWidgetId(int appWidgetId, ComponentName provider) {
- try {
- sService.bindAppWidgetId(appWidgetId, provider, null, mContext.getUserId());
- }
- catch (RemoteException e) {
- throw new RuntimeException("system server dead?", e);
+ if (mService == null) {
+ return;
}
+ bindAppWidgetId(appWidgetId, provider, null);
}
/**
@@ -741,12 +832,10 @@ public class AppWidgetManager {
* @hide
*/
public void bindAppWidgetId(int appWidgetId, ComponentName provider, Bundle options) {
- try {
- sService.bindAppWidgetId(appWidgetId, provider, options, mContext.getUserId());
- }
- catch (RemoteException e) {
- throw new RuntimeException("system server dead?", e);
+ if (mService == null) {
+ return;
}
+ bindAppWidgetIdIfAllowed(appWidgetId, Process.myUserHandle(), provider, options);
}
/**
@@ -757,22 +846,16 @@ public class AppWidgetManager {
* method returns false, call {@link #ACTION_APPWIDGET_BIND} to request permission to
* bind
*
- * @param appWidgetId The AppWidget instance for which to set the RemoteViews.
+ * @param appWidgetId The AppWidget id under which to bind the provider.
* @param provider The {@link android.content.BroadcastReceiver} that will be the AppWidget
* provider for this AppWidget.
* @return true if this component has permission to bind the AppWidget
*/
public boolean bindAppWidgetIdIfAllowed(int appWidgetId, ComponentName provider) {
- if (mContext == null) {
+ if (mService == null) {
return false;
}
- try {
- return sService.bindAppWidgetIdIfAllowed(
- mContext.getPackageName(), appWidgetId, provider, null, mContext.getUserId());
- }
- catch (RemoteException e) {
- throw new RuntimeException("system server dead?", e);
- }
+ return bindAppWidgetIdIfAllowed(appWidgetId, UserHandle.myUserId(), provider, null);
}
/**
@@ -783,7 +866,7 @@ public class AppWidgetManager {
* method returns false, call {@link #ACTION_APPWIDGET_BIND} to request permission to
* bind
*
- * @param appWidgetId The AppWidget instance for which to set the RemoteViews.
+ * @param appWidgetId The AppWidget id under which to bind the provider.
* @param provider The {@link android.content.BroadcastReceiver} that will be the AppWidget
* provider for this AppWidget.
* @param options Bundle containing options for the AppWidget. See also
@@ -793,12 +876,52 @@ public class AppWidgetManager {
*/
public boolean bindAppWidgetIdIfAllowed(int appWidgetId, ComponentName provider,
Bundle options) {
- if (mContext == null) {
+ if (mService == null) {
+ return false;
+ }
+ return bindAppWidgetIdIfAllowed(appWidgetId, UserHandle.myUserId(), provider, options);
+ }
+
+ /**
+ * Set the provider for a given appWidgetId if the caller has a permission.
+ * <p>
+ * <strong>Note:</strong> You need the {@link android.Manifest.permission#BIND_APPWIDGET}
+ * permission or the user must have enabled binding widgets always for your component.
+ * Should be used by apps that host widgets. If this method returns false, call {@link
+ * #ACTION_APPWIDGET_BIND} to request permission to bind.
+ * </p>
+ *
+ * @param appWidgetId The AppWidget id under which to bind the provider.
+ * @param user The user id in which the provider resides.
+ * @param provider The component name of the provider.
+ * @param options An optional Bundle containing options for the AppWidget.
+ *
+ * @return true if this component has permission to bind the AppWidget
+ */
+ public boolean bindAppWidgetIdIfAllowed(int appWidgetId, UserHandle user,
+ ComponentName provider, Bundle options) {
+ if (mService == null) {
+ return false;
+ }
+ return bindAppWidgetIdIfAllowed(appWidgetId, user.getIdentifier(), provider, options);
+ }
+
+ /**
+ * Query if a given package was granted permission by the user to bind app widgets
+ *
+ * <p class="note">You need the MODIFY_APPWIDGET_BIND_PERMISSIONS permission
+ *
+ * @param packageName The package for which the permission is being queried
+ * @param userId The user id of the user under which the package runs.
+ * @return true if the package was granted permission by the user to bind app widgets
+ * @hide
+ */
+ public boolean hasBindAppWidgetPermission(String packageName, int userId) {
+ if (mService == null) {
return false;
}
try {
- return sService.bindAppWidgetIdIfAllowed(mContext.getPackageName(), appWidgetId,
- provider, options, mContext.getUserId());
+ return mService.hasBindAppWidgetPermission(packageName, userId);
}
catch (RemoteException e) {
throw new RuntimeException("system server dead?", e);
@@ -815,8 +938,11 @@ public class AppWidgetManager {
* @hide
*/
public boolean hasBindAppWidgetPermission(String packageName) {
+ if (mService == null) {
+ return false;
+ }
try {
- return sService.hasBindAppWidgetPermission(packageName, mContext.getUserId());
+ return mService.hasBindAppWidgetPermission(packageName, UserHandle.myUserId());
}
catch (RemoteException e) {
throw new RuntimeException("system server dead?", e);
@@ -828,13 +954,35 @@ public class AppWidgetManager {
*
* <p class="note">You need the MODIFY_APPWIDGET_BIND_PERMISSIONS permission
*
- * @param provider The package whose permission is being changed
- * @param permission Whether to give the package permission to bind widgets
+ * @param packageName The package whose permission is being changed
+ * @param permission Whether to give the package permission to bind widgets
+ *
* @hide
*/
public void setBindAppWidgetPermission(String packageName, boolean permission) {
+ if (mService == null) {
+ return;
+ }
+ setBindAppWidgetPermission(packageName, UserHandle.myUserId(), permission);
+ }
+
+ /**
+ * Changes any user-granted permission for the given package to bind app widgets
+ *
+ * <p class="note">You need the MODIFY_APPWIDGET_BIND_PERMISSIONS permission
+ *
+ * @param packageName The package whose permission is being changed
+ * @param userId The user under which the package is running.
+ * @param permission Whether to give the package permission to bind widgets
+ *
+ * @hide
+ */
+ public void setBindAppWidgetPermission(String packageName, int userId, boolean permission) {
+ if (mService == null) {
+ return;
+ }
try {
- sService.setBindAppWidgetPermission(packageName, permission, mContext.getUserId());
+ mService.setBindAppWidgetPermission(packageName, userId, permission);
}
catch (RemoteException e) {
throw new RuntimeException("system server dead?", e);
@@ -847,18 +995,20 @@ public class AppWidgetManager {
* The appWidgetId specified must already be bound to the calling AppWidgetHost via
* {@link android.appwidget.AppWidgetManager#bindAppWidgetId AppWidgetManager.bindAppWidgetId()}.
*
+ * @param packageName The package from which the binding is requested.
* @param appWidgetId The AppWidget instance for which to bind the RemoteViewsService.
* @param intent The intent of the service which will be providing the data to the
* RemoteViewsAdapter.
* @param connection The callback interface to be notified when a connection is made or lost.
- * @param userHandle The user to bind to.
* @hide
*/
- public void bindRemoteViewsService(int appWidgetId, Intent intent, IBinder connection,
- UserHandle userHandle) {
+ public void bindRemoteViewsService(String packageName, int appWidgetId, Intent intent,
+ IBinder connection) {
+ if (mService == null) {
+ return;
+ }
try {
- sService.bindRemoteViewsService(appWidgetId, intent, connection,
- userHandle.getIdentifier());
+ mService.bindRemoteViewsService(packageName, appWidgetId, intent, connection);
}
catch (RemoteException e) {
throw new RuntimeException("system server dead?", e);
@@ -871,15 +1021,18 @@ public class AppWidgetManager {
* The appWidgetId specified muse already be bound to the calling AppWidgetHost via
* {@link android.appwidget.AppWidgetManager#bindAppWidgetId AppWidgetManager.bindAppWidgetId()}.
*
+ * @param packageName The package from which the binding is requested.
* @param appWidgetId The AppWidget instance for which to bind the RemoteViewsService.
* @param intent The intent of the service which will be providing the data to the
* RemoteViewsAdapter.
- * @param userHandle The user to unbind from.
* @hide
*/
- public void unbindRemoteViewsService(int appWidgetId, Intent intent, UserHandle userHandle) {
+ public void unbindRemoteViewsService(String packageName, int appWidgetId, Intent intent) {
+ if (mService == null) {
+ return;
+ }
try {
- sService.unbindRemoteViewsService(appWidgetId, intent, userHandle.getIdentifier());
+ mService.unbindRemoteViewsService(packageName, appWidgetId, intent);
}
catch (RemoteException e) {
throw new RuntimeException("system server dead?", e);
@@ -894,12 +1047,40 @@ public class AppWidgetManager {
* AppWidget provider to find appWidgetIds for.
*/
public int[] getAppWidgetIds(ComponentName provider) {
+ if (mService == null) {
+ return new int[0];
+ }
try {
- return sService.getAppWidgetIds(provider, mContext.getUserId());
+ return mService.getAppWidgetIds(provider);
}
catch (RemoteException e) {
throw new RuntimeException("system server dead?", e);
}
}
-}
+ private boolean bindAppWidgetIdIfAllowed(int appWidgetId, int profileId,
+ ComponentName provider, Bundle options) {
+ if (mService == null) {
+ return false;
+ }
+ try {
+ return mService.bindAppWidgetId(mPackageName, appWidgetId,
+ profileId, provider, options);
+ }
+ catch (RemoteException e) {
+ throw new RuntimeException("system server dead?", e);
+ }
+ }
+
+ private void convertSizesToPixels(AppWidgetProviderInfo info) {
+ // Converting complex to dp.
+ info.minWidth = TypedValue.complexToDimensionPixelSize(info.minWidth,
+ mDisplayMetrics);
+ info.minHeight = TypedValue.complexToDimensionPixelSize(info.minHeight,
+ mDisplayMetrics);
+ info.minResizeWidth = TypedValue.complexToDimensionPixelSize(info.minResizeWidth,
+ mDisplayMetrics);
+ info.minResizeHeight = TypedValue.complexToDimensionPixelSize(info.minResizeHeight,
+ mDisplayMetrics);
+ }
+}