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); } 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..0c98cab7e3 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,20 @@ 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){ + 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" ); } }