Repository navigation
Conversation
GutenbergView started the upload server and built the window.GBKit JSON on the main thread in onPageStarted, and created its EditorService on the main dispatcher. Hosts running StrictMode with penaltyDeath crashed on every editor launch. Both are now built on Dispatchers.IO before loadUrl, and onPageStarted only injects the prebuilt JSON. The media processor and uploader are still captured on the main thread, one pass after construction. Fixes #848
The library no longer does main-thread disk or SSL work while the editor loads (#848), so the demo's ThreadPolicy adds penaltyDeath. VmPolicy stays on penaltyLog.
XCFramework BuildThis PR's XCFramework is available for testing. Add the following to your .package(url: "https://github.com/wordpress-mobile/GutenbergKit", branch: "pr-build/859")Built from e08b871 |
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.
What?
Fixes #848. Opening the editor on Android no longer reads the disk or sets up SSL on the main thread, so host apps that run
StrictModewithpenaltyDeathno longer crash when the editor opens. The demo'sThreadPolicynow usespenaltyDeath.Stacked on #489, which added the demo's StrictMode setup and
docs/code/strictmode.md.Why?
GutenbergViewdid this work on the main thread while the page loaded. The host had no call it could move to a background thread:onPageStarted: started the upload server (OkHttp SSL setup,cacheDir, temp file sweep) and built thewindow.GBKitJSON (reads the asset bundle from disk).prepareAndLoadEditor: createdEditorServiceon the main dispatcher (SSL setup and several disk reads).How?
GutenbergView.ktwindow.GBKitJSON are built onDispatchers.IObeforeloadUrl.onPageStartedonly injects the prebuilt JSON. A reload reuses the same JSON.mediaProcessorandmediaUploaderare still read on the main thread, one main-thread pass after construction. Setting them right after construction still works, and setting them later still throws.prepareAndLoadEditorcreates and preparesEditorServiceonDispatchers.IO, then loads the editor on Main. Progress updates are posted to the main thread.Demo and docs
GutenbergKitApplication:ThreadPolicyis nowpenaltyLog().penaltyDeath(). The log keeps the full violation.VmPolicystays onpenaltyLog.docs/code/strictmode.md: replaces the table of remaining violations with a short note, and updates the configuration and verified flows.Tests
onEditorPageStartedthrough reflection to start the server.Testing Instructions
Run the demo in a debug build, then open the editor from a connected site's Editor Configuration screen:
The editor should load each time without crashing.
adb logcat -s StrictModeshould show onlyUntaggedSocketViolation, which isVmPolicynoise.Test plan
:Gutenberg:testDebugUnitTest: 764 tests, 0 failures.make lint-android(Detekt) is clean. Prettier is clean ondocs/code/strictmode.md.penaltyDeathon. No crash. OnlyUntaggedSocketViolationwas logged. With native upload on, the app had a loopback listener; with it off, it had none.strictmode.mdwithpenaltyDeathon: Standalone editor → Prepare Editor → Start with typing, the inserter sheet (category tabs and search), background and resume, and Browse → open a post without preparing. No crash.GutenbergView.ktcrashes on Start withCustomViolation: newSSLContext. This confirmspenaltyDeathis active.