fix(android): Android 7 (API 25) compatibility — prevent launch and service crashes - #86
Open
LeaderOnePro wants to merge 4 commits into
Open
fix(android): Android 7 (API 25) compatibility — prevent launch and service crashes#86LeaderOnePro wants to merge 4 commits into
LeaderOnePro wants to merge 4 commits into
Conversation
On API 23-29 (Android 6-9), WRITE_EXTERNAL_STORAGE and READ_PHONE_STATE are dangerous permissions that must be granted at runtime. Without this the service panicked with "mkdir ... permission denied" when trying to create its workspace in shared storage. Prompts the user from MainActivity.onCreate on first launch. API < 23 (install-time grants) and API 30+ (MANAGE_EXTERNAL_STORAGE path, already handled in onResume) are skipped. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
… equivalents
Crash 1 — on service START (on API < 26):
java.lang.NoSuchMethodError: startForegroundService (added in API 26)
Fix: ContextCompat.startForegroundService (falls back to startService)
Crash 2 — on service STOP (on API < 26):
java.lang.NoSuchMethodError: Process.isAlive (added in API 26)
Fix: thread.isAlive() — logically equivalent since the wait-thread
exits exactly when the process does, and available since API 1.
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
App crashed on launch on API 25 (Android 7.x) with: java.lang.NoClassDefFoundError: android.app.NotificationChannel NotificationChannel was added in API 26 — the unconditional reference prevented theApplication from even finishing onCreate. Skips channel creation on API < 26; the foreground service still works, it just uses the default notification style on those older devices. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
… Android 7 On API 25 (Android 7.x) the Go binary's -public flag is not detected by flag.Visit, causing effectivePublic to fall back to the config default (false) and the service binds to 127.0.0.1 only. Switch to -host 0.0.0.0 which takes the exact-binding code path and binds to all interfaces reliably on every API level. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
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.
Summary
Fixes three crashes that prevent the app from running on Android 7.x (API 25) devices:
android.app.NotificationChanneldoes not exist on API 25.Context.startForegroundService()was added in API 26.Process.isAlive()was added in API 26.Additionally, the service panics with
mkdir ... permission deniedbecauseWRITE_EXTERNAL_STORAGEwas never requested at runtime on API 23-29.Changes
MainActivity.ktWRITE_EXTERNAL_STORAGE/READ_PHONE_STATEat runtime on API 23-29PicoClawService.ktContextCompat.startForegroundService()+thread.isAlive()instead ofProcess.isAlive()PicoClawApp.ktNotificationChannelcreation behindBuild.VERSION.SDK_INT >= OVerification
Tested on Honor 5A running LineageOS Android 7.1.2 (API 25):
On API 26+ devices all three codepaths behave identically to before (no regression).