fix(android_alarm_manager_plus): catch NPE in AlarmService#3924
Open
HedAurabesh wants to merge 1 commit into
Open
fix(android_alarm_manager_plus): catch NPE in AlarmService#3924HedAurabesh wants to merge 1 commit into
HedAurabesh wants to merge 1 commit into
Conversation
…ervice
On Android 11 phones with aggressive battery optimizations (e.g. Huawei and
OnePlus), the app might be started in a sandboxed mode when receiving the reboot
event.
In that sandbox, the resolution of the app's launch class name might fail with
a NullPointerException, which in turn leads to a crash.
Here is an example stack trace:
---------------------------------------------------------------------------
Fatal Exception: java.lang.RuntimeException: Unable to start receiver dev.fluttercommunity.plus.androidalarmmanager.RebootBroadcastReceiver: java.lang.NullPointerException: class name is null
at android.app.ActivityThread.handleReceiver(ActivityThread.java:4047)
at android.app.ActivityThread.access$1400(ActivityThread.java:239)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1926)
at android.os.Handler.dispatchMessage(Handler.java:106)
at android.os.Looper.loop(Looper.java:223)
[...]
Caused by java.lang.NullPointerException: class name is null
at android.content.ComponentName.<init>(ComponentName.java:103)
at android.content.Intent.setClassName(Intent.java:10044)
at android.app.ApplicationPackageManager.getLaunchIntentForPackage(ApplicationPackageManager.java:252)
at dev.fluttercommunity.plus.androidalarmmanager.AlarmService.createShowPendingIntent(AlarmService.java:362)
at dev.fluttercommunity.plus.androidalarmmanager.AlarmService.scheduleAlarm(AlarmService.java:151)
at dev.fluttercommunity.plus.androidalarmmanager.AlarmService.reschedulePersistentAlarms(AlarmService.java:338)
at dev.fluttercommunity.plus.androidalarmmanager.RebootBroadcastReceiver.onReceive(RebootBroadcastReceiver.java:37)
at android.app.ActivityThread.handleReceiver(ActivityThread.java:4038)
[...]
---------------------------------------------------------------------------
This fix avoids the crash, turning it into a error-log message instead.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
On Android 11 phones with aggressive battery optimizations (e.g. Huawei and OnePlus), the app might be started in a sandboxed mode when receiving the reboot event.
In that sandbox, the resolution of the app's launch class name might fail with a NullPointerException, which in turn leads to a crash.
This fix avoids the crash, turning it into an error-log message instead.
The change is motivated by the following crash stacktrace received via Crashlytics for several Huawei and OnePlus phones on Android 11:
Related Issues
No related issues
Checklist
CHANGELOG.mdnor the plugin version inpubspec.yamlfiles.flutter analyze) does not report any problems on my PR.Breaking Change
Does your PR require plugin users to manually update their apps to accommodate your change?