Fix Android DFU target id handling

This commit is contained in:
yecong 2026-06-17 14:39:05 +08:00
parent 5350017085
commit d6f1e2f6b8
2 changed files with 16 additions and 5 deletions

View File

@ -42,7 +42,3 @@ hermesEnabled=true
# This allows your app to draw behind system bars for an immersive UI.
# Note: Only works with ReactActivity and should not be used with custom Activity.
edgeToEdgeEnabled=false
org.gradle.java.home=E:\\jdk\\jdk-17.0.12

View File

@ -5,6 +5,7 @@ import { RootStackParamList } from "../App";
import RNFS from "react-native-fs";
import {
startDfu,
getDfuTargetId,
addDfuEventListener,
DfuProgressEvent,
DfuStateEvent,
@ -64,6 +65,8 @@ const trace = (step: string, payload?: unknown) => {
export default function DfuScreen({ route, navigation }: Props) {
const {
deviceId,
systemId,
address,
name,
firmware: deviceFirmware,
} = route.params;
@ -154,12 +157,24 @@ export default function DfuScreen({ route, navigation }: Props) {
setError(undefined);
const rawDeviceId = String(deviceId ?? "").trim();
const safeDeviceId = rawDeviceId;
const rawSystemId = String(systemId ?? rawDeviceId).trim();
const rawAddress =
typeof address === "number"
? address
: address !== undefined && address !== null
? Number(address)
: undefined;
const safeDeviceId = getDfuTargetId({
systemId: rawSystemId,
address: Number.isFinite(rawAddress) ? rawAddress : undefined,
});
const firmwareText = String(deviceFirmware ?? "").trim();
trace("resolved input", {
rawDeviceId,
rawSystemId,
rawAddress,
safeDeviceId,
firmwareText,
});