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

Commit 8e1d299d authored by Svetoslav's avatar Svetoslav Committed by Svetoslav Ganov
Browse files

Polish the new cross-profile app widget APIs

bug:14991269

Change-Id: I5996f8c69a3d151ff1ecd8f19403dd606f588150
parent 5c8ea2c3
Loading
Loading
Loading
Loading
+2 −2
Original line number Diff line number Diff line
@@ -5747,7 +5747,7 @@ package android.appwidget {
    method protected android.appwidget.AppWidgetHostView onCreateView(android.content.Context, int, android.appwidget.AppWidgetProviderInfo);
    method protected void onProviderChanged(int, android.appwidget.AppWidgetProviderInfo);
    method protected void onProvidersChanged();
    method public final void startAppWidgetConfigureActivityForResult(android.app.Activity, android.content.Intent, int);
    method public final void startAppWidgetConfigureActivityForResult(android.app.Activity, int, int, int, android.os.Bundle);
    method public void startListening();
    method public void stopListening();
  }
@@ -5775,7 +5775,7 @@ package android.appwidget {
    method public android.appwidget.AppWidgetProviderInfo getAppWidgetInfo(int);
    method public android.os.Bundle getAppWidgetOptions(int);
    method public java.util.List<android.appwidget.AppWidgetProviderInfo> getInstalledProviders();
    method public java.util.List<android.appwidget.AppWidgetProviderInfo> getInstalledProvidersForProfiles(android.os.UserHandle[]);
    method public java.util.List<android.appwidget.AppWidgetProviderInfo> getInstalledProvidersForProfile(android.os.UserHandle);
    method public static android.appwidget.AppWidgetManager getInstance(android.content.Context);
    method public void notifyAppWidgetViewDataChanged(int[], int);
    method public void notifyAppWidgetViewDataChanged(int, int);
+16 −15
Original line number Diff line number Diff line
@@ -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();
            }
+16 −21
Original line number Diff line number Diff line
@@ -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();
            }
+3 −2
Original line number Diff line number Diff line
@@ -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);
    }

+4 −3
Original line number Diff line number Diff line
@@ -41,7 +41,8 @@ interface IAppWidgetService {
    void deleteAllHosts();
    RemoteViews getAppWidgetViews(String callingPackage, int appWidgetId);
    int[] getAppWidgetIdsForHost(String callingPackage, int hostId);
    IntentSender createAppWidgetConfigIntentSender(String callingPackage, in Intent intent);
    IntentSender createAppWidgetConfigIntentSender(String callingPackage, int appWidgetId,
            int intentFlags);

    //
    // for AppWidgetManager
@@ -53,8 +54,8 @@ interface IAppWidgetService {
            in RemoteViews views);
    void updateAppWidgetProvider(in ComponentName provider, in RemoteViews views);
    void notifyAppWidgetViewDataChanged(String packageName, in int[] appWidgetIds, int viewId);
    List<AppWidgetProviderInfo> getInstalledProviders(int categoryFilter,
            in int[] profileIds);
    List<AppWidgetProviderInfo> getInstalledProvidersForProfile(int categoryFilter,
            int profileId);
    AppWidgetProviderInfo getAppWidgetInfo(String callingPackage, int appWidgetId);
    boolean hasBindAppWidgetPermission(in String packageName, int userId);
    void setBindAppWidgetPermission(in String packageName, int userId, in boolean permission);
Loading