Skip to content

Commit f094e56

Browse files
committed
Alignment to iOS
1 parent a26db32 commit f094e56

1 file changed

Lines changed: 51 additions & 32 deletions

File tree

base/src/main/java/com/smartdevicelink/session/BaseSdlSession.java

Lines changed: 51 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,6 @@
6565
import org.json.JSONException;
6666
import org.json.JSONObject;
6767

68-
import java.util.ArrayList;
6968
import java.util.HashMap;
7069
import java.util.List;
7170
import java.util.ListIterator;
@@ -241,39 +240,28 @@ protected void processControlService(ProtocolMessage msg) {
241240

242241
iNumBytes = sdlSecurity.runHandshake(data, dataToRead);
243242

244-
// Assemble a security query payload header for our response
245-
SecurityQueryPayload responseHeader = new SecurityQueryPayload();
246-
247-
byte[] returnBytes;
243+
ProtocolMessage protocolMessage;
248244
if (iNumBytes == null || iNumBytes <= 0) {
249245
DebugTool.logError(TAG, "Internal Error processing control service");
250-
251-
responseHeader.setQueryID(SecurityQueryID.SEND_INTERNAL_ERROR);
252-
responseHeader.setQueryType(SecurityQueryType.NOTIFICATION);
253-
responseHeader.setCorrelationID(msg.getCorrID());
254-
byte[] jsonData;
255-
JSONObject jsonObject = new JSONObject();
256-
try {
257-
jsonObject.put("id", SecurityQueryErrorCode.ERROR_UNKNOWN_INTERNAL_ERROR.getValue());
258-
jsonObject.put("text", SecurityQueryErrorCode.ERROR_UNKNOWN_INTERNAL_ERROR.getName());
259-
jsonData = jsonObject.toString().getBytes();
260-
} catch (JSONException e) {
261-
DebugTool.logError(TAG, "JSON exception when constructing handshake error Notification");
262-
e.printStackTrace();
263-
jsonData = new byte[0];
264-
}
265-
responseHeader.setJsonData(jsonData);
266-
byte[] errorCode = new byte[1];
267-
errorCode[0] = SecurityQueryErrorCode.ERROR_UNKNOWN_INTERNAL_ERROR.getValue();
268-
responseHeader.setBulkData(errorCode);
246+
protocolMessage = serverSecurityFailedMessageWithClientMessageHeader(msg.getCorrID());
269247
} else {
270-
responseHeader.setQueryID(SecurityQueryID.SEND_HANDSHAKE_DATA);
271-
responseHeader.setQueryType(SecurityQueryType.RESPONSE);
272-
responseHeader.setCorrelationID(msg.getCorrID());
273-
responseHeader.setBulkData(dataToRead);
274-
responseHeader.setJsonData(null);
248+
protocolMessage = serverSecurityHandshakeMessageWithData(msg.getCorrID(), dataToRead);
275249
}
276-
returnBytes = responseHeader.assembleBinaryData();
250+
251+
//sdlSecurity.hs();
252+
253+
sendMessage(protocolMessage);
254+
}
255+
256+
private ProtocolMessage serverSecurityHandshakeMessageWithData(int correlationId, byte[] bulkData) {
257+
SecurityQueryPayload responseHeader = new SecurityQueryPayload();
258+
responseHeader.setQueryID(SecurityQueryID.SEND_HANDSHAKE_DATA);
259+
responseHeader.setQueryType(SecurityQueryType.RESPONSE);
260+
responseHeader.setCorrelationID(correlationId);
261+
responseHeader.setBulkData(bulkData);
262+
responseHeader.setJsonData(null);
263+
264+
byte[] returnBytes = responseHeader.assembleBinaryData();
277265

278266
ProtocolMessage protocolMessage = new ProtocolMessage();
279267
protocolMessage.setSessionType(SessionType.CONTROL);
@@ -282,9 +270,40 @@ protected void processControlService(ProtocolMessage msg) {
282270
protocolMessage.setVersion((byte) sdlProtocol.getProtocolVersion().getMajor());
283271
protocolMessage.setSessionID((byte) this.sessionId);
284272

285-
//sdlSecurity.hs();
273+
return protocolMessage;
274+
}
286275

287-
sendMessage(protocolMessage);
276+
private ProtocolMessage serverSecurityFailedMessageWithClientMessageHeader(int correlationId) {
277+
SecurityQueryPayload responseHeader = new SecurityQueryPayload();
278+
responseHeader.setQueryID(SecurityQueryID.SEND_INTERNAL_ERROR);
279+
responseHeader.setQueryType(SecurityQueryType.NOTIFICATION);
280+
responseHeader.setCorrelationID(correlationId);
281+
byte[] jsonData;
282+
JSONObject jsonObject = new JSONObject();
283+
try {
284+
jsonObject.put("id", SecurityQueryErrorCode.ERROR_UNKNOWN_INTERNAL_ERROR.getValue());
285+
jsonObject.put("text", SecurityQueryErrorCode.ERROR_UNKNOWN_INTERNAL_ERROR.getName());
286+
jsonData = jsonObject.toString().getBytes();
287+
} catch (JSONException e) {
288+
DebugTool.logError(TAG, "JSON exception when constructing handshake error Notification");
289+
e.printStackTrace();
290+
jsonData = new byte[0];
291+
}
292+
responseHeader.setJsonData(jsonData);
293+
byte[] errorCode = new byte[1];
294+
errorCode[0] = SecurityQueryErrorCode.ERROR_UNKNOWN_INTERNAL_ERROR.getValue();
295+
responseHeader.setBulkData(errorCode);
296+
297+
byte[] returnBytes = responseHeader.assembleBinaryData();
298+
299+
ProtocolMessage protocolMessage = new ProtocolMessage();
300+
protocolMessage.setSessionType(SessionType.CONTROL);
301+
protocolMessage.setData(returnBytes);
302+
protocolMessage.setFunctionID(0x01);
303+
protocolMessage.setVersion((byte) sdlProtocol.getProtocolVersion().getMajor());
304+
protocolMessage.setSessionID((byte) this.sessionId);
305+
306+
return protocolMessage;
288307
}
289308

290309
/**

0 commit comments

Comments
 (0)