Repository navigation
Secure DFU: don't wait for a disconnect after the connection was already closed - #528
Open
niklavsBariss wants to merge 1 commit into
Open
niklavsBariss wants to merge 1 commit into
niklavsBariss wants to merge 1 commit into
Conversation
This branch has not been deployed
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.
Problem
terminateConnectioncloses the GATT and reports the error, but its callers inSecureDfuImplthen return normally. FromsendFirmware,performDfucarries on intowaitUntilDisconnected, which waits for a disconnect a closed GATT never delivers. TheIntentServicethread parks there, so every laterDfuServiceInitiator.start()queues behind it until the app is killed:From
sendInitPacketthey don't hang, butsendFirmware's first write then throwsDeviceDisconnectedException, so the error is followed by a restart or a second broadcast with code 0.How it shows up
Phone B resumes an upload phone A left in the bootloader, the upload ends in a CRC error, and the next start never connects. That CRC error is a separate bug (a stale stream mark after the resume), fixed in #530, stacked on this PR.
Fix
This PR makes a final CRC, file or progress error end the upload with one error report instead of leaving the DFU service stuck. Throwing lets
onHandleIntent's existingDfuExceptionhandler terminate and report once, with the same error code. That handler logs throughGattError.parse, hence theERROR_PROGRESS_LOSTcase.LegacyDfuImpl's calls already return out ofperformDfu.Verified
Xiaomi 14T (Android 16), 2.4.2 from source, with a fault that fails one object's CRC 3 times. Without the change, no
DFU service destroyedand the next start never connects; with it, the service stops and the next start uploads.