Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 61a5b016 authored by Michael Jurka's avatar Michael Jurka
Browse files

New API to allow third-party apps to bind widgets

Change-Id: I1a3761c1a0f557a32d4d3bdd0207567fec918ba7
parent bdb1c406
Loading
Loading
Loading
Loading
+0 −1
Original line number Diff line number Diff line
@@ -4151,7 +4151,6 @@ package android.appwidget {
  }
  public class AppWidgetManager {
    method public void bindAppWidgetId(int, android.content.ComponentName);
    method public int[] getAppWidgetIds(android.content.ComponentName);
    method public android.appwidget.AppWidgetProviderInfo getAppWidgetInfo(int);
    method public java.util.List<android.appwidget.AppWidgetProviderInfo> getInstalledProviders();
+3 −1
Original line number Diff line number Diff line
@@ -4313,7 +4313,7 @@ package android.appwidget {
  }
  public class AppWidgetManager {
    method public void bindAppWidgetId(int, android.content.ComponentName);
    method public boolean bindAppWidgetIdIfAllowed(int, android.content.ComponentName);
    method public android.os.Bundle getAppWidgetExtras(int);
    method public int[] getAppWidgetIds(android.content.ComponentName);
    method public android.appwidget.AppWidgetProviderInfo getAppWidgetInfo(int);
@@ -4327,6 +4327,7 @@ package android.appwidget {
    method public void updateAppWidget(int, android.widget.RemoteViews);
    method public void updateAppWidget(android.content.ComponentName, android.widget.RemoteViews);
    method public void updateAppWidgetExtras(int, android.os.Bundle);
    field public static final java.lang.String ACTION_APPWIDGET_BIND = "android.appwidget.action.APPWIDGET_BIND";
    field public static final java.lang.String ACTION_APPWIDGET_CONFIGURE = "android.appwidget.action.APPWIDGET_CONFIGURE";
    field public static final java.lang.String ACTION_APPWIDGET_DELETED = "android.appwidget.action.APPWIDGET_DELETED";
    field public static final java.lang.String ACTION_APPWIDGET_DISABLED = "android.appwidget.action.APPWIDGET_DISABLED";
@@ -4341,6 +4342,7 @@ package android.appwidget {
    field public static final java.lang.String EXTRA_APPWIDGET_MAX_WIDTH = "appWidgetMaxWidth";
    field public static final java.lang.String EXTRA_APPWIDGET_MIN_HEIGHT = "appWidgetMinHeight";
    field public static final java.lang.String EXTRA_APPWIDGET_MIN_WIDTH = "appWidgetMinWidth";
    field public static final java.lang.String EXTRA_APPWIDGET_PROVIDER = "appWidgetProvider";
    field public static final java.lang.String EXTRA_CUSTOM_EXTRAS = "customExtras";
    field public static final java.lang.String EXTRA_CUSTOM_INFO = "customInfo";
    field public static final int INVALID_APPWIDGET_ID = 0; // 0x0
+113 −2
Original line number Diff line number Diff line
@@ -79,6 +79,46 @@ public class AppWidgetManager {
     */
    public static final String ACTION_APPWIDGET_PICK = "android.appwidget.action.APPWIDGET_PICK";

    /**
     * Send this from your {@link AppWidgetHost} activity when you want to bind an AppWidget to
     * display and bindAppWidgetIdIfAllowed returns false.
     * <p>
     * You must supply the following extras:
     * <table>
     *   <tr>
     *     <td>{@link #EXTRA_APPWIDGET_ID}</td>
     *     <td>A newly allocated appWidgetId, which will be bound to the AppWidget provider
     *         you provide.</td>
     *  </tr>
     *  <tr>
     *     <td>{@link #EXTRA_APPWIDGET_PROVIDER}</td>
     *     <td>The BroadcastReceiver that will be the AppWidget provider for this AppWidget.
     *     </td>
     *  </tr>
     * </table>
     *
     * <p>
     * The system will respond with an onActivityResult call with the following extras in
     * the intent:
     * <table>
     *   <tr>
     *     <td>{@link #EXTRA_APPWIDGET_ID}</td>
     *     <td>The appWidgetId that you supplied in the original intent.</td>
     *  </tr>
     * </table>
     * <p>
     * When you receive the result from the AppWidget bind activity, if the resultCode is
     * {@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.
     *
     * @see #ACTION_APPWIDGET_CONFIGURE
     *
     */
    public static final String ACTION_APPWIDGET_BIND = "android.appwidget.action.APPWIDGET_BIND";

    /**
     * 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
@@ -143,6 +183,13 @@ public class AppWidgetManager {
     */
    public static final String EXTRA_APPWIDGET_IDS = "appWidgetIds";

    /**
     * An intent extra that contains the component name of a AppWidget provider.
     * <p>
     * The value will be an ComponentName.
     */
    public static final String EXTRA_APPWIDGET_PROVIDER = "appWidgetProvider";

    /**
     * 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
@@ -501,12 +548,14 @@ public class AppWidgetManager {
    /**
     * Set the component for a given appWidgetId.
     *
     * <p class="note">You need the APPWIDGET_LIST permission.  This method is to be used by the
     * AppWidget picker.
     * <p class="note">You need the BIND_APPWIDGET permission or the user must have enabled binding
     *         widgets always for your component. This method is used by the AppWidget picker and
     *         should not be used by other apps.
     *
     * @param appWidgetId     The AppWidget instance for which to set the RemoteViews.
     * @param provider      The {@link android.content.BroadcastReceiver} that will be the AppWidget
     *                      provider for this AppWidget.
     * @hide
     */
    public void bindAppWidgetId(int appWidgetId, ComponentName provider) {
        try {
@@ -517,6 +566,68 @@ public class AppWidgetManager {
        }
    }

    /**
     * Set the component for a given appWidgetId.
     *
     * <p class="note">You need the 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
     *
     * @param appWidgetId     The AppWidget instance for which to set the RemoteViews.
     * @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) {
            return false;
        }
        try {
            return sService.bindAppWidgetIdIfAllowed(
                    mContext.getPackageName(), appWidgetId, provider);
        }
        catch (RemoteException e) {
            throw new RuntimeException("system server dead?", e);
        }
    }

    /**
     * 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
     * @return true if the package was granted permission by the user to bind app widgets
     * @hide
     */
    public boolean hasBindAppWidgetPermission(String packageName) {
        try {
            return sService.hasBindAppWidgetPermission(packageName);
        }
        catch (RemoteException e) {
            throw new RuntimeException("system server dead?", e);
        }
    }

    /**
     * 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 provider        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) {
        try {
            sService.setBindAppWidgetPermission(packageName, permission);
        }
        catch (RemoteException e) {
            throw new RuntimeException("system server dead?", e);
        }
    }

    /**
     * Binds the RemoteViewsService for a given appWidgetId and intent.
     *
+4 −0
Original line number Diff line number Diff line
@@ -50,7 +50,11 @@ interface IAppWidgetService {
    void notifyAppWidgetViewDataChanged(in int[] appWidgetIds, int viewId);
    List<AppWidgetProviderInfo> getInstalledProviders();
    AppWidgetProviderInfo getAppWidgetInfo(int appWidgetId);
    boolean hasBindAppWidgetPermission(in String packageName);
    void setBindAppWidgetPermission(in String packageName, in boolean permission);
    void bindAppWidgetId(int appWidgetId, in ComponentName provider);
    boolean bindAppWidgetIdIfAllowed(
            in String packageName, int appWidgetId, in ComponentName provider);
    void bindRemoteViewsService(int appWidgetId, in Intent intent, in IBinder connection);
    void unbindRemoteViewsService(int appWidgetId, in Intent intent);
    int[] getAppWidgetIds(in ComponentName provider);
+7 −0
Original line number Diff line number Diff line
@@ -1472,6 +1472,13 @@
        android:description="@string/permdesc_bindGadget"
        android:protectionLevel="signature|system" />

    <!-- Internal permission allowing an application to query/set which
         applications can bind AppWidgets.
         @hide -->
    <permission android:name="android.permission.MODIFY_APPWIDGET_BIND_PERMISSIONS"
        android:permissionGroup="android.permission-group.SYSTEM_TOOLS"
        android:protectionLevel="signature|system" />

    <!-- Allows applications to change the background data setting
         @hide pending API council -->
    <permission android:name="android.permission.CHANGE_BACKGROUND_DATA_SETTING"
Loading