From 95f26f5eaa28f9e491cc75c4fcb419d1bdea6175 Mon Sep 17 00:00:00 2001 From: Kyriakos Sidiropoulos Date: Thu, 31 Oct 2024 14:24:45 +0100 Subject: [PATCH] clean (AndroidDeviceResetter.java): trivial neutral simplifications on corner-case errors --- .../AndroidDeviceResetter.java | 56 ++++++++----------- 1 file changed, 24 insertions(+), 32 deletions(-) diff --git a/Laerdal.McuMgr.Bindings.Android.Native/mcumgr-laerdal-wrapper/src/main/java/no/laerdal/mcumgr_laerdal_wrapper/AndroidDeviceResetter.java b/Laerdal.McuMgr.Bindings.Android.Native/mcumgr-laerdal-wrapper/src/main/java/no/laerdal/mcumgr_laerdal_wrapper/AndroidDeviceResetter.java index dad2c7f..57ffdfa 100644 --- a/Laerdal.McuMgr.Bindings.Android.Native/mcumgr-laerdal-wrapper/src/main/java/no/laerdal/mcumgr_laerdal_wrapper/AndroidDeviceResetter.java +++ b/Laerdal.McuMgr.Bindings.Android.Native/mcumgr-laerdal-wrapper/src/main/java/no/laerdal/mcumgr_laerdal_wrapper/AndroidDeviceResetter.java @@ -37,43 +37,35 @@ public void beginReset() try { _manager = new DefaultManager(_transport); - } - catch (final Exception ex) - { - setState(EAndroidDeviceResetterState.FAILED); - onError("Failed to create manager: '" + ex.getMessage() + "'", ex); - return; - } - setState(EAndroidDeviceResetterState.RESETTING); + setState(EAndroidDeviceResetterState.RESETTING); - AndroidDeviceResetter self = this; - - _manager.reset(new McuMgrCallback() - { - @Override - public void onResponse(@NotNull final McuMgrOsResponse response) + AndroidDeviceResetter self = this; + _manager.reset(new McuMgrCallback() { - if (!response.isSuccess()) - { // check for an error return code - self.onError("Reset failed (error-code '" + response.getReturnCode().toString() + "')", response.getReturnCode(), response.getGroupReturnCode()); - - setState(EAndroidDeviceResetterState.FAILED); - return; + @Override + public void onResponse(@NotNull final McuMgrOsResponse response) + { + if (!response.isSuccess()) + { // check for an error return code + self.onError("[ADR.BR.002] Reset failed (error-code '" + response.getReturnCode().toString() + "')", response.getReturnCode(), response.getGroupReturnCode()); + return; + } + + setState(EAndroidDeviceResetterState.COMPLETE); } - setState(EAndroidDeviceResetterState.COMPLETE); - } - - @Override - public void onError(@NotNull final McuMgrException exception) - { - self.onError("Reset failed '" + exception.getMessage() + "'", exception); - - setState(EAndroidDeviceResetterState.FAILED); - } - - }); + @Override + public void onError(@NotNull final McuMgrException exception) + { + self.onError("[ADR.BR.005] Reset failed '" + exception.getMessage() + "'", exception); + } + }); + } + catch (final Exception ex) + { + onError("[ADR.BR.010] Failed to initialize reset operation: '" + ex.getMessage() + "'", ex); + } } public void disconnect()