From 3433ae3348aca52142f5239451ea0e8f471c0e6c Mon Sep 17 00:00:00 2001 From: Joey Grover Date: Tue, 23 Oct 2018 16:31:21 -0400 Subject: [PATCH 1/3] Remove incorrect SdlException throw in SdlManager --- .../smartdevicelink/managers/SdlManager.java | 49 +++++++++++++++---- 1 file changed, 40 insertions(+), 9 deletions(-) diff --git a/sdl_android/src/main/java/com/smartdevicelink/managers/SdlManager.java b/sdl_android/src/main/java/com/smartdevicelink/managers/SdlManager.java index 2717123b58..cb7b0264cb 100644 --- a/sdl_android/src/main/java/com/smartdevicelink/managers/SdlManager.java +++ b/sdl_android/src/main/java/com/smartdevicelink/managers/SdlManager.java @@ -601,12 +601,15 @@ public SystemCapabilityManager getSystemCapabilityManager(){ * Send RPC Message
* Note: Only takes type of RPCRequest for now, notifications and responses will be thrown out * @param message RPCMessage - * @throws SdlException */ - public void sendRPC(RPCMessage message) throws SdlException { + public void sendRPC(RPCMessage message) { if (message instanceof RPCRequest){ - proxy.sendRPCRequest((RPCRequest)message); + try{ + proxy.sendRPCRequest((RPCRequest)message); + }catch (SdlException exception){ + handleSdlException(exception); + } } } @@ -620,9 +623,8 @@ public void sendRPC(RPCMessage message) throws SdlException { * * @param rpcs is the list of RPCMessages being sent * @param listener listener for updates and completions - * @throws SdlException if an unrecoverable error is encountered */ - public void sendSequentialRPCs(final List rpcs, final OnMultipleRequestListener listener) throws SdlException { + public void sendSequentialRPCs(final List rpcs, final OnMultipleRequestListener listener){ List rpcRequestList = new ArrayList<>(); for (int i = 0; i < rpcs.size(); i++) { @@ -632,7 +634,11 @@ public void sendSequentialRPCs(final List rpcs, final OnMu } if (rpcRequestList.size() > 0) { - proxy.sendSequentialRequests(rpcRequestList, listener); + try{ + proxy.sendSequentialRequests(rpcRequestList, listener); + }catch (SdlException exception){ + handleSdlException(exception); + } } } @@ -646,9 +652,8 @@ public void sendSequentialRPCs(final List rpcs, final OnMu * * @param rpcs is the list of RPCMessages being sent * @param listener listener for updates and completions - * @throws SdlException if an unrecoverable error is encountered */ - public void sendRPCs(List rpcs, final OnMultipleRequestListener listener) throws SdlException { + public void sendRPCs(List rpcs, final OnMultipleRequestListener listener) { List rpcRequestList = new ArrayList<>(); for (int i = 0; i < rpcs.size(); i++) { @@ -658,7 +663,33 @@ public void sendRPCs(List rpcs, final OnMultipleRequestLis } if (rpcRequestList.size() > 0) { - proxy.sendRequests(rpcRequestList, listener); + try{ + proxy.sendRequests(rpcRequestList, listener); + }catch (SdlException exception){ + handleSdlException(exception); + } + } + } + + private void handleSdlException(SdlException exception){ + if(exception != null){ + switch(exception.getSdlExceptionCause()){ + case SDL_UNAVAILABLE: + case SDL_PROXY_CYCLED: + case SDL_PROXY_DISPOSED: + case SDL_CONNECTION_FAILED: + case SDL_PROXY_OBSOLETE: + case SDL_REGISTRATION_ERROR: + case SDL_USB_DETACHED: + case BLUETOOTH_SOCKET_UNAVAILABLE: + case BLUETOOTH_DISABLED: + case BLUETOOTH_ADAPTER_NULL: + transitionToState(BaseSubManager.ERROR); + this.dispose(); + break; + default: + DebugTool.logError("Caught SdlException: " + exception.getSdlExceptionCause()); + } } } From a3f35a5ecc3b833839c254c05726d1f5574de31c Mon Sep 17 00:00:00 2001 From: Joey Grover Date: Tue, 23 Oct 2018 17:06:59 -0400 Subject: [PATCH 2/3] Update tests and hello_sdl for no exception throw --- .../com/sdl/hellosdlandroid/SdlService.java | 23 ++++--------------- .../managers/SdlManagerTests.java | 20 ++++++---------- 2 files changed, 11 insertions(+), 32 deletions(-) diff --git a/hello_sdl_android/src/main/java/com/sdl/hellosdlandroid/SdlService.java b/hello_sdl_android/src/main/java/com/sdl/hellosdlandroid/SdlService.java index 2847a3fd68..ea98cbf7f2 100755 --- a/hello_sdl_android/src/main/java/com/sdl/hellosdlandroid/SdlService.java +++ b/hello_sdl_android/src/main/java/com/sdl/hellosdlandroid/SdlService.java @@ -13,14 +13,12 @@ import android.os.IBinder; import android.util.Log; -import com.smartdevicelink.exception.SdlException; import com.smartdevicelink.managers.CompletionListener; import com.smartdevicelink.managers.SdlManager; import com.smartdevicelink.managers.SdlManagerListener; import com.smartdevicelink.managers.file.filetypes.SdlArtwork; import com.smartdevicelink.protocol.enums.FunctionID; import com.smartdevicelink.proxy.RPCNotification; -import com.smartdevicelink.proxy.RPCRequest; import com.smartdevicelink.proxy.TTSChunkFactory; import com.smartdevicelink.proxy.rpc.AddCommand; import com.smartdevicelink.proxy.rpc.MenuParams; @@ -31,11 +29,9 @@ import com.smartdevicelink.proxy.rpc.enums.FileType; import com.smartdevicelink.proxy.rpc.enums.HMILevel; import com.smartdevicelink.proxy.rpc.listeners.OnRPCNotificationListener; -import com.smartdevicelink.transport.BTTransportConfig; import com.smartdevicelink.transport.BaseTransportConfig; import com.smartdevicelink.transport.MultiplexTransportConfig; import com.smartdevicelink.transport.TCPTransportConfig; -import com.smartdevicelink.transport.USBTransportConfig; import java.util.Collections; import java.util.Vector; @@ -217,14 +213,14 @@ private void sendCommands(){ command.setCmdID(TEST_COMMAND_ID); command.setMenuParams(params); command.setVrCommands(Collections.singletonList(TEST_COMMAND_NAME)); - sendRpcRequest(command); + sdlManager.sendRPC(command); } /** * Will speak a sample welcome message */ private void performWelcomeSpeak(){ - sendRpcRequest(new Speak(TTSChunkFactory.createSimpleTTSChunks(WELCOME_SPEAK))); + sdlManager.sendRPC(new Speak(TTSChunkFactory.createSimpleTTSChunks(WELCOME_SPEAK))); } /** @@ -256,19 +252,8 @@ private void showTest(){ sdlManager.getScreenManager().setTextField2(""); sdlManager.getScreenManager().commit(null); - sendRpcRequest(new Speak(TTSChunkFactory.createSimpleTTSChunks(TEST_COMMAND_NAME))); + sdlManager.sendRPC(new Speak(TTSChunkFactory.createSimpleTTSChunks(TEST_COMMAND_NAME))); } - /** - * Sends an RPC Request to the connected head unit. Automatically adds a correlation id. - * @param request the rpc request that is to be sent to the module - */ - private void sendRpcRequest(RPCRequest request){ - try { - sdlManager.sendRPC(request); - } catch (SdlException e) { - e.printStackTrace(); - } - } -} \ No newline at end of file +} diff --git a/sdl_android/src/androidTest/java/com/smartdevicelink/managers/SdlManagerTests.java b/sdl_android/src/androidTest/java/com/smartdevicelink/managers/SdlManagerTests.java index 61626251b9..e22e397d23 100644 --- a/sdl_android/src/androidTest/java/com/smartdevicelink/managers/SdlManagerTests.java +++ b/sdl_android/src/androidTest/java/com/smartdevicelink/managers/SdlManagerTests.java @@ -315,11 +315,8 @@ public void onResponse(int correlationId, RPCResponse response) { listenerCalledCounter++; } }); - try { - sdlManager.sendRPC(request); - } catch (SdlException e) { - e.printStackTrace(); - } + + sdlManager.sendRPC(request); // Make sure the listener is called exactly once assertEquals("Listener was not called or called more/less frequently than expected", listenerCalledCounter, 1); @@ -375,16 +372,13 @@ public void onError(int correlationId, Result resultCode, String info) {} @Override public void onResponse(int correlationId, RPCResponse response) {} }; - try { - if (sequentialSend) { - sdlManager.sendSequentialRPCs(rpcsList, onMultipleRequestListener); - } else { - sdlManager.sendRPCs(rpcsList, onMultipleRequestListener); - } - } catch (SdlException e) { - e.printStackTrace(); + if (sequentialSend) { + sdlManager.sendSequentialRPCs(rpcsList, onMultipleRequestListener); + } else { + sdlManager.sendRPCs(rpcsList, onMultipleRequestListener); } + // Make sure the listener is called exactly once assertEquals("Listener was not called or called more/less frequently than expected", listenerCalledCounter, 1); } From 8e4d44708ed6ffe4cc982630903bb4e06428226b Mon Sep 17 00:00:00 2001 From: Joey Grover Date: Tue, 23 Oct 2018 18:14:11 -0400 Subject: [PATCH 3/3] Revert behavior for manager disposal if SdlException being thrown --- .../smartdevicelink/managers/SdlManager.java | 21 ++++--------------- 1 file changed, 4 insertions(+), 17 deletions(-) diff --git a/sdl_android/src/main/java/com/smartdevicelink/managers/SdlManager.java b/sdl_android/src/main/java/com/smartdevicelink/managers/SdlManager.java index cb7b0264cb..0c98cab7e3 100644 --- a/sdl_android/src/main/java/com/smartdevicelink/managers/SdlManager.java +++ b/sdl_android/src/main/java/com/smartdevicelink/managers/SdlManager.java @@ -673,23 +673,10 @@ public void sendRPCs(List rpcs, final OnMultipleRequestLis private void handleSdlException(SdlException exception){ if(exception != null){ - switch(exception.getSdlExceptionCause()){ - case SDL_UNAVAILABLE: - case SDL_PROXY_CYCLED: - case SDL_PROXY_DISPOSED: - case SDL_CONNECTION_FAILED: - case SDL_PROXY_OBSOLETE: - case SDL_REGISTRATION_ERROR: - case SDL_USB_DETACHED: - case BLUETOOTH_SOCKET_UNAVAILABLE: - case BLUETOOTH_DISABLED: - case BLUETOOTH_ADAPTER_NULL: - transitionToState(BaseSubManager.ERROR); - this.dispose(); - break; - default: - DebugTool.logError("Caught SdlException: " + exception.getSdlExceptionCause()); - } + DebugTool.logError("Caught SdlException: " + exception.getSdlExceptionCause()); + // In the future this should handle logic to dispose the manager if it is an unrecoverable error + }else{ + DebugTool.logError("Caught SdlException" ); } }