Skip to content

fix(app): don't open a window in a process started for a backup - #344

Open
Tarquinen wants to merge 1 commit into
devfrom
crash-343
Open

Tarquinen wants to merge 1 commit into
devfrom
crash-343

Conversation

@Tarquinen

Copy link
Copy Markdown
Member

Opening OpenCode while Android was backing up or restoring its data crashed the app at start, with IllegalStateException: AppContext is installed by OpenCodeApplication.onCreate before first use. For a full (Auto Backup) backup or restore, Android starts the process in restricted mode with a plain Application, so OpenCodeApplication.onCreate never runs. When the app is opened during that time, MainActivity starts in that same process and its first dependency() read throws. On dev that read is in TranscriptCachePersistence. The sample stack in #343 comes from an older build and goes through migrateBeforeRestore. Now MainActivity ends that process when it isn't running under OpenCodeApplication, and Android starts the activity again in a normal process.

I reproduced it on an API 36 emulator on dev: I ran bmgr backupnow with the local transport and about 22 MB in files/, then launched MainActivity as soon as the backup process appeared. Logcat showed Start proc … for backup {android/FullBackupAgent} and then the crash. With the fix, the same steps start the activity in a new process (for top-activity) and the app opens normally. The new Robolectric test fails without the guard and also without the killProcess call. scripts/check.sh passes.

I didn't test a real restore (a new phone or Smart Switch), but it goes through the same restricted mode. Ending the process cancels that backup or restore. The crash did that too, and Android tries again later. This PR only guards MainActivity, which is the only entry point in the Play reports. The other exported activities (share, Ask OpenCode, widget configuration, system actions, background call) could hit the same thing and aren't covered here. Nothing visible changes.

Fixes #343

A full backup or restore starts the process with a plain Application, so OpenCodeApplication.onCreate never runs and MainActivity's first dependency read threw. MainActivity now ends that process and Android starts it again normally. Reproduced with bmgr backupnow on an API 36 emulator; scripts/check.sh passes.

Fixes #343

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Crash: IllegalStateException in AppContext.getLiveValue

1 participant