Skip to content

Commit 344161d

Browse files
committed
fix(android): Return null if MCUBOOT mode query isn't supported
1 parent 27db1fe commit 344161d

File tree

1 file changed

+16
-4
lines changed

1 file changed

+16
-4
lines changed

react-native-mcu-manager/android/src/main/java/uk/co/playerdata/reactnativemcumanager/ReactNativeMcuManagerModule.kt

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -78,11 +78,23 @@ class ReactNativeMcuManagerModule() : Module() {
7878
throw ex;
7979
}
8080

81-
if (info.bootloader == MCUBOOT) {
82-
val mcuMgrResult = manager.bootloaderInfo(DefaultManager.BOOTLOADER_INFO_MCUBOOT_QUERY_MODE)
81+
try {
82+
if (info.bootloader == MCUBOOT) {
83+
val mcuMgrResult = manager.bootloaderInfo(DefaultManager.BOOTLOADER_INFO_MCUBOOT_QUERY_MODE)
84+
85+
info.mode = mcuMgrResult.mode
86+
info.noDowngrade = mcuMgrResult.noDowngrade
87+
}
88+
} catch (ex: McuMgrErrorException) {
89+
transport.release()
8390

84-
info.mode = mcuMgrResult.mode
85-
info.noDowngrade = mcuMgrResult.noDowngrade
91+
// For consistency with iOS, if the error code is 8 (MGMT_ERR_ENOTSUP), return null
92+
if (ex.code == McuMgrErrorCode.NOT_SUPPORTED) {
93+
promise.resolve(info)
94+
return@AsyncFunction
95+
}
96+
97+
throw ex;
8698
}
8799

88100
transport.release()

0 commit comments

Comments
 (0)