Skip to content

Allow background start activity for configure widget #5351

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 3 commits into
base: main
Choose a base branch
from

Conversation

TimoPtr
Copy link
Collaborator

@TimoPtr TimoPtr commented May 23, 2025

Summary

Since Android 15, we need to opt-in to be able to start an activity in background. Even if we are not actually starting a new activity when pinning a widget the activity is put in background when dragging so we need to opt-in. This PR generalize the creation of the PendingIntent to avoid duplicating the logic on all our configure screens.

Checklist

  • New or updated tests have been added to cover the changes following the testing guidelines.
  • The code follows the project's code style and best_practices.
  • The changes have been thoroughly tested, and edge cases have been considered.
  • Changes are backward compatible whenever feasible. Any breaking changes are documented in the changelog for users and/or in the code for developers depending on the relevance.

Any other notes

Fixes #5349

@dshokouhi
Copy link
Member

Tested the debug APK here but still got the same error, here are some more logs just above in case its helpful

2025-05-23 10:38:51.350 19275-19275 ButtonWidget            io....stant.companion.android.debug  D  Broadcast received: 
                                                                                                    Broadcast action: android.appwidget.action.APPWIDGET_ENABLED
                                                                                                    AppWidgetId: -1
2025-05-23 10:38:51.356 19275-19275 ButtonWidget            io....stant.companion.android.debug  D  Broadcast received: 
                                                                                                    Broadcast action: android.appwidget.action.APPWIDGET_UPDATE
                                                                                                    AppWidgetId: -1
2025-05-23 10:38:51.627 19275-19275 VRI[Button...eActivity] io....stant.companion.android.debug  D  visibilityChanged oldVisibility=true newVisibility=false
2025-05-23 10:38:51.662 19275-19275 AutofillManager         io....stant.companion.android.debug  I  onInvisibleForAutofill(): expiringResponse
2025-05-23 10:38:53.067  1663-6673  ActivityTaskManager     system_server                        E  Background activity launch blocked! goo.gle/android-bal [callingPackage: io.homeassistant.companion.android.debug; callingPackageTargetSdk: 34; callingUid: 10455; callingPid: -1; appSwitchState: 2; callingUidHasVisibleActivity: false; callingUidHasNonAppVisibleWindow: false; callingUidProcState: LAST_ACTIVITY; isCallingUidPersistentSystemProcess: false; allowBalExemptionForSystemProcess: false; intent: Intent { flg=0x20000000 cmp=io.homeassistant.companion.android.debug/io.homeassistant.companion.android.widgets.button.ButtonWidgetConfigureActivity (has extras) }; callerApp: null; balAllowedByPiCreator: BSP.ALLOW_BAL; balAllowedByPiCreatorWithHardening: BSP.ALLOW_BAL; resultIfPiCreatorAllowsBal: BAL_BLOCK; callerStartMode: MODE_BACKGROUND_ACTIVITY_START_ALLOWED; hasRealCaller: true; isCallForResult: false; isPendingIntent: true; autoOptInReason: null; realCallingPackage: com.google.android.apps.nexuslauncher; realCallingPackageTargetSdk: 35; realCallingUid: 10256; realCallingPid: 24412; realCallingUidHasVisibleActivity: true; realCallingUidHasNonAppVisibleWindow: true; realCallingUidProcState: TOP; isRealCallingUidPersistentSystemProcess: false; originatingPendingIntent: PendingIntentRecord{3e82d3c io.homeassistant.companion.android.debug startActivity}; realCallerApp: ProcessRecord{7c70108 24412:com.google.android.apps.nexuslauncher/u0a256}; realInVisibleTask: true; balAllowedByPiSender: BSP.NONE; resultIfPiSenderAllowsBal: BAL_ALLOW_VISIBLE_WINDOW; realCallerStartMode: MODE_BACKGROUND_ACTIVITY_START_DENIED; balRequireOptInByPendingIntentCreator: true; balDontBringExistingBackgroundTaskStackToFg: true]

@TimoPtr
Copy link
Collaborator Author

TimoPtr commented May 26, 2025

I didn't find any way to make it works on Android 15. The only solution seems to move away from getting the result in the activity to get the result in a BroadcastReceiver which works on all the version.

@jpelgrom
Copy link
Member

The only solution seems to move away from getting the result in the activity to get the result in a BroadcastReceiver which works on all the version.

I agree. The callback intent currently used already forwards the data to the AppWidgetProvider (which is a BroadcastReceiver) so that should be possible without changes to the flow for the user.

@TimoPtr TimoPtr marked this pull request as draft May 27, 2025 11:12
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

When dragging a widget from the manage widget screens the configuration may not save once dragged to the home screen
3 participants