diff options
| author | 2024-10-31 17:16:45 +0000 | |
|---|---|---|
| committer | 2024-10-31 20:12:09 +0000 | |
| commit | 723ac23f447a45ae14da395dc66f823b66ad4f11 (patch) | |
| tree | 369c697c572645bb12eb116b9f7a8ef8e5426d03 | |
| parent | e89e0f63b694554700982d34d5daa72f27c9e2dc (diff) | |
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
| -rw-r--r-- | core/java/android/appwidget/AppWidgetHost.java | 45 |
1 files changed, 35 insertions, 10 deletions
diff --git a/core/java/android/appwidget/AppWidgetHost.java b/core/java/android/appwidget/AppWidgetHost.java index 72f992ab3917..79eeaa914771 100644 --- a/core/java/android/appwidget/AppWidgetHost.java +++ b/core/java/android/appwidget/AppWidgetHost.java @@ -306,6 +306,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 * an activity in another profile. You can optionally provide a request code that is @@ -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); } } |