Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -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)));
}

/**
Expand Down Expand Up @@ -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();
}
}

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -601,12 +601,15 @@ public SystemCapabilityManager getSystemCapabilityManager(){
* Send RPC Message <br>
* <strong>Note: Only takes type of RPCRequest for now, notifications and responses will be thrown out</strong>
* @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);
}
}
}

Expand All @@ -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<? extends RPCMessage> rpcs, final OnMultipleRequestListener listener) throws SdlException {
public void sendSequentialRPCs(final List<? extends RPCMessage> rpcs, final OnMultipleRequestListener listener){

List<RPCRequest> rpcRequestList = new ArrayList<>();
for (int i = 0; i < rpcs.size(); i++) {
Expand All @@ -632,7 +634,11 @@ public void sendSequentialRPCs(final List<? extends RPCMessage> rpcs, final OnMu
}

if (rpcRequestList.size() > 0) {
proxy.sendSequentialRequests(rpcRequestList, listener);
try{
proxy.sendSequentialRequests(rpcRequestList, listener);
}catch (SdlException exception){
handleSdlException(exception);
}
}
}

Expand All @@ -646,9 +652,8 @@ public void sendSequentialRPCs(final List<? extends RPCMessage> 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<? extends RPCMessage> rpcs, final OnMultipleRequestListener listener) throws SdlException {
public void sendRPCs(List<? extends RPCMessage> rpcs, final OnMultipleRequestListener listener) {

List<RPCRequest> rpcRequestList = new ArrayList<>();
for (int i = 0; i < rpcs.size(); i++) {
Expand All @@ -658,7 +663,20 @@ public void sendRPCs(List<? extends RPCMessage> 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" );
}
}

Expand Down