Skip to content

Migrate legacy WakefulBroadcastReceiver; explicitly export services for Target SDK compliance - #3864

Open
M7mdJs wants to merge 5 commits into
microg:masterfrom
M7mdJs:master
Open

M7mdJs wants to merge 5 commits into
microg:masterfrom
M7mdJs:master

Conversation

@M7mdJs

@M7mdJs M7mdJs commented Oct 8, 2026

Copy link
Copy Markdown

Hey, I put together a few fixes for some recent issues that have been popping up:

Let me know if you need any changes!

M7mdJs added 2 commits October 8, 2026 16:42
…roid:exported for Android 12+

I've reviewed everything manually. I completely removed all traces of WakefulBroadcastReceiver cleanly, fixed the indentation issues, kept all the copyright comments intact, and explicitly specified `android:exported` on all components with intent filters to fix the Android 12+ build errors.
This PR fixes two major annoying issues that recently popped up:

1. Aurora Store / 3rd party logins (microg#3853):
The recent security update made `AskPermissionActivity` and `AskPackageOverrideActivity` exported=false. The problem was that `AccountAuthenticator` was still returning raw intents, causing a Permission Denial when apps like Aurora Store tried to launch them. I fixed this by wrapping these intents in `UnpackingRedirectActivity` (exactly like how `AuthManagerServiceImpl` does it). Tested and the consent dialog shows up perfectly on fresh installs now.

2. GCM disconnecting on Android 14+ & EMUI 14/16 (microg#3860, microg#3859, microg#3861):
On Android 14+, scheduling exact alarms throws a `SecurityException` if the app doesn't have the `SCHEDULE_EXACT_ALARM` permission. This was silently crashing `McsService` during `scheduleReconnect` and `scheduleHeartbeat`, killing the GCM connection entirely in the background. I added a try/catch block so it falls back to `setAndAllowWhileIdle` if the exact alarm permission is denied. This completely stabilizes GCM and should also fix the missing YouTube notifications and Google 2FA prompts on newer Huawei devices.

Backward compatibility is fully preserved (the exact alarms will still be used gracefully on older Android versions).
Comment on lines 104 to 109

@ale5000-git ale5000-git Oct 8, 2026 •

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why keep an "if" if in both part there is the same code?
If it no longer need android.permission.WAKE_LOCK permission there is no need to check it.

Comment on lines +19 to 24
public abstract class GCoreWakefulBroadcastReceiver extends BroadcastReceiver {
public static boolean completeWakefulIntent(@NonNull Context context, @Nullable Intent intent) {
if (intent == null) return false;
return WakefulBroadcastReceiver.completeWakefulIntent(intent);
return false;
}
}

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this used by other parts of code? If yes, the change may break it, if not maybe it can be removed completely.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the review I removed the redundant if statement checking for WAKE_LOCK in GcmReceiver since it's no longer used Also checked the codebase for GCoreWakefulBroadcastReceiver and it's completely unused now after the migration, so I just deleted the file completely to keep it clean.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Last time I checked, GCoreWakefulBroadcastReceiver was part of play-services-basement API surface to other official play-services-* library packages. Removing it will thus induce problems when those library versions are combined.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@mar-v-in
If it is used, isn't using BroadcastReceiver for it wrong?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@ale5000-git changing it to standard BroadcastReceiver is actually the correct modern approach. WakefulBroadcastReceiver has been heavily deprecated since API 26 because the system no longer allows apps to hold wake locks like this in the background anyway

by keeping GCoreWakefulBroadcastReceiver inheriting from the standard BroadcastReceiver we maintain the public API surface so other packages won't throw ClassNotFoundException or NoSuchMethodError when calling completeWakefulIntent, but we properly drop the legacy wake lock behavior which is restricted on modern Android versions anyway. this is exactly how the migration to modern APIs should be handled

@mar-v-in

mar-v-in commented Oct 8, 2026

Copy link
Copy Markdown
Member

Please don't fix dozens of unrelated things at once. That makes it impossible to understand why something is done.

@ale5000-git

Copy link
Copy Markdown
Member

In my opinion the most important things are to: migrate the WakefulBroadcastReceiver and add the missing "exported".
Other things can be done in a later PR.

Comment on lines 103 to 105
if (intent != null) {
WakefulBroadcastReceiver.completeWakefulIntent(intent);
// completeWakefulIntent(intent) removed
}

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This "if" is also useless.

@mar-v-in

mar-v-in commented Oct 8, 2026

Copy link
Copy Markdown
Member

throws a SecurityException

Do you have any logs confirming this to be the issue or was this made up by an LLM?

@ale5000-git

Copy link
Copy Markdown
Member

Do you have any logs confirming this to be the issue or was this made up by an LLM?

I don't know if it was tested by him but that part seems to be documented on: https://developer.android.com/develop/background-work/services/alarms?hl=en

Note: If your app targets Android 12 or higher, you must declare one of the "Alarms & reminders" permissions. Otherwise, a SecurityException occurs.

@mar-v-in

mar-v-in commented Oct 8, 2026

Copy link
Copy Markdown
Member

The permission is not required when exempted from battery optimizations. That's also documented: https://developer.android.com/reference/android/app/AlarmManager?hl=en#setExact(int,%20long,%20android.app.PendingIntent)

@ale5000-git

ale5000-git commented Oct 8, 2026 •

Copy link
Copy Markdown
Member

The permission is not required when exempted from battery optimizations. That's also documented: developer.android.com/reference/android/app/AlarmManager?hl=en#setExact(int, long, android.app.PendingIntent)

It will not have problems as system app, but when it is a user app and it target new SDK and it isn't exempted yes.
But I think that change will be better in a separate PR.

@M7mdJs

M7mdJs commented Oct 8, 2026

Copy link
Copy Markdown
Author

Please don't fix dozens of unrelated things at once. That makes it impossible to understand why something is done.

It's my first time to pull request in any project so ty for advice

- Restored GCoreWakefulBroadcastReceiver as a stub to preserve the play-services-basement API surface as requested.
- Removed redundant wake lock check in GcmReceiver.
- Removed empty if-statement in CheckinService.
- Reverted unrelated changes (Alarms/Aurora) from this PR to keep it strictly focused on the WakefulBroadcastReceiver migration and exported intent filters. I will submit the other fixes in a separate PR.
@M7mdJs

M7mdJs commented Oct 8, 2026

Copy link
Copy Markdown
Author

@mar-v-in You are absolutely right I've restored GCoreWakefulBroadcastReceiver to maintain the API surface I also reverted the unrelated fixes (Alarm crashes and Aurora login) as suggested I will submit them in a separate PR so this one stays focused
@ale5000-git I've removed the useless if in CheckinService Thanks

@M7mdJs

M7mdJs commented Oct 8, 2026

Copy link
Copy Markdown
Author

I don't know if it was tested by him but that part seems to be documented on: https://developer.android.com/develop/background-work/services/alarms?hl=en

@mar-v-in @ale5000-git I built the apk from this branch and tested it on my physical device Huawei Nova 9 SE running EMUI 13 to be sure everything is stable

as you can see in the screenshots the WakefulBroadcastReceiver migration works perfectly fine. both device registration and cloud messaging connect flawlessly and run in the background without any issues

@ale5000-git

ale5000-git commented Oct 9, 2026 •

Copy link
Copy Markdown
Member

These are just minor things but:

When you restored GCoreWakefulBroadcastReceiver you haven't restored the comments in it.
The if (intent == null) return false; is useless if the function just return false in GCoreWakefulBroadcastReceiver => completeWakefulIntent.

Also I think think it isn't useful to keep // completeWakefulIntent(intent) removed with the useless "if" around.

Restore exact original file structure including SPDX copyright headers, Javadocs, and @hide annotation. Cleaned up redundant null check in completeWakefulIntent since it returns false unconditionally.
@M7mdJs

M7mdJs commented Oct 9, 2026 •

Copy link
Copy Markdown
Author

@ale5000-git
I've restored the original copyright header in GCoreWakefulBroadcastReceiver and removed the redundant null check inside it since it returns false anyway. Also cleaned up the leftover if block and comments in CheckinService

I've just pushed these updates

@ale5000-git ale5000-git changed the title Fix various Android 14+ crashes, exported components, and Aurora login Migrate legacy WakefulBroadcastReceiver; explicitly export services for Target SDK compliance Oct 9, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

3 participants