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

Commit 723ac23f authored by Darrell Shi's avatar Darrell Shi
Browse files

Add API that returns IntentSender for widget configuration

This change adds a hidden API in the AppWidgetHost which returns the
IntentSender for widget configuration activity. This allows a client to
start the activity on their own, useful in HSUM where the host may live
in a different user than the activity that needs to start the
configuration.

Bug: 375036327
Test: (with the subsequent change) able to retrieve the IntentSender in
      foreground user and pass that to the headless system user to start
      the configuration activity there
Flag: EXEMPT hidden API
Change-Id: Iac131e82b90ee71c8809edf7db2b545aa8cd3e01
parent e89e0f63
Loading
Loading
Loading
Loading
+35 −10
Original line number Diff line number Diff line
@@ -305,6 +305,38 @@ public class AppWidgetHost {
        }
    }

    /**
     * Returns an {@link IntentSender} for starting the configuration activity for the widget.
     *
     * @return The {@link IntentSender} or null if service is currently unavailable
     *
     * @throws android.content.ActivityNotFoundException If configuration activity is not found.
     *
     * @see #startAppWidgetConfigureActivityForResult
     *
     * @hide
     */
    @Nullable
    public final IntentSender getIntentSenderForConfigureActivity(int appWidgetId,
            int intentFlags)  {
        if (sService == null) {
            return null;
        }

        IntentSender intentSender;
        try {
            intentSender = sService.createAppWidgetConfigIntentSender(mContextOpPackageName,
                    appWidgetId, intentFlags);
        } catch (RemoteException e) {
            throw new RuntimeException("system server dead?", e);
        }

        if (intentSender == null) {
            throw new ActivityNotFoundException();
        }
        return intentSender;
    }

    /**
     * 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
@@ -330,18 +362,11 @@ public class AppWidgetHost {
            return;
        }
        try {
            IntentSender intentSender = sService.createAppWidgetConfigIntentSender(
                    mContextOpPackageName, appWidgetId, intentFlags);
            if (intentSender != null) {
                activity.startIntentSenderForResult(intentSender, requestCode, null, 0, 0, 0,
                        options);
            } else {
                throw new ActivityNotFoundException();
            }
            IntentSender intentSender = getIntentSenderForConfigureActivity(appWidgetId,
                    intentFlags);
            activity.startIntentSenderForResult(intentSender, requestCode, null, 0, 0, 0, options);
        } catch (IntentSender.SendIntentException e) {
            throw new ActivityNotFoundException();
        } catch (RemoteException e) {
            throw new RuntimeException("system server dead?", e);
        }
    }