summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJoey Grover <joeygrover@gmail.com>2016-05-10 14:55:57 -0400
committerJoey Grover <joeygrover@gmail.com>2016-05-10 14:55:57 -0400
commitc600b31fc1072dd73908cc13f1955761854bb831 (patch)
tree8a9932520721d05dbe5a37e84464c8086a2c1e36
parent15a6617b9bd7522fa9df80a38cfbecbf4d2a741f (diff)
downloadsdl_android-c600b31fc1072dd73908cc13f1955761854bb831.tar.gz
SdlPackets now have a priority coefficient for the router service to determine priority.
This change touched a lot of classes as it needed to get to the multiplexing transport. Instead of sending a byte[] with offset and length, the entire SdlPacket is now passed through different layers until it reaches the SdlTransport. The router service uses this to lower priority based on if this is a multiframe message or a stream of rpcs.
-rw-r--r--sdl_android_lib/src/com/smartdevicelink/SdlConnection/SdlConnection.java5
-rw-r--r--sdl_android_lib/src/com/smartdevicelink/protocol/AbstractProtocol.java6
-rw-r--r--sdl_android_lib/src/com/smartdevicelink/protocol/IProtocolListener.java2
-rw-r--r--sdl_android_lib/src/com/smartdevicelink/protocol/ProtocolMessage.java13
-rw-r--r--sdl_android_lib/src/com/smartdevicelink/protocol/SdlPacket.java16
-rw-r--r--sdl_android_lib/src/com/smartdevicelink/protocol/WiProProtocol.java3
-rw-r--r--sdl_android_lib/src/com/smartdevicelink/streaming/StreamRPCPacketizer.java5
-rw-r--r--sdl_android_lib/src/com/smartdevicelink/transport/BTTransport.java5
-rw-r--r--sdl_android_lib/src/com/smartdevicelink/transport/MultiplexTransport.java9
-rw-r--r--sdl_android_lib/src/com/smartdevicelink/transport/SdlRouterService.java23
-rw-r--r--sdl_android_lib/src/com/smartdevicelink/transport/SdlTransport.java14
-rw-r--r--sdl_android_lib/src/com/smartdevicelink/transport/TCPTransport.java7
-rw-r--r--sdl_android_lib/src/com/smartdevicelink/transport/TransportBroker.java18
-rw-r--r--sdl_android_lib/src/com/smartdevicelink/transport/TransportConstants.java2
-rw-r--r--sdl_android_lib/src/com/smartdevicelink/transport/USBTransport.java16
-rw-r--r--sdl_android_lib/src/com/smartdevicelink/transport/utl/ByteArrayMessageSpliter.java8
16 files changed, 99 insertions, 53 deletions
diff --git a/sdl_android_lib/src/com/smartdevicelink/SdlConnection/SdlConnection.java b/sdl_android_lib/src/com/smartdevicelink/SdlConnection/SdlConnection.java
index 354ad6956..f99ae19b6 100644
--- a/sdl_android_lib/src/com/smartdevicelink/SdlConnection/SdlConnection.java
+++ b/sdl_android_lib/src/com/smartdevicelink/SdlConnection/SdlConnection.java
@@ -245,12 +245,11 @@ public class SdlConnection implements IProtocolListener, ITransportListener, ISt
}
@Override
- public void onProtocolMessageBytesToSend(byte[] msgBytes, int offset,
- int length) {
+ public void onProtocolMessageBytesToSend(SdlPacket packet) {
// Protocol has packaged bytes to send, pass to transport for transmission
synchronized(TRANSPORT_REFERENCE_LOCK) {
if (_transport != null) {
- _transport.sendBytes(msgBytes, offset, length);
+ _transport.sendBytes(packet);
}
}
}
diff --git a/sdl_android_lib/src/com/smartdevicelink/protocol/AbstractProtocol.java b/sdl_android_lib/src/com/smartdevicelink/protocol/AbstractProtocol.java
index 146b52467..4db9383f1 100644
--- a/sdl_android_lib/src/com/smartdevicelink/protocol/AbstractProtocol.java
+++ b/sdl_android_lib/src/com/smartdevicelink/protocol/AbstractProtocol.java
@@ -91,9 +91,9 @@ public abstract class AbstractProtocol {
synchronized(_frameLock) {
- byte[] frameHeader = header.constructPacket();
- if(frameHeader!=null){
- _protocolListener.onProtocolMessageBytesToSend(frameHeader, 0, frameHeader.length);
+ //byte[] frameHeader = header.constructPacket();
+ if(header!=null){
+ _protocolListener.onProtocolMessageBytesToSend(header);
}//TODO else log out error
}
diff --git a/sdl_android_lib/src/com/smartdevicelink/protocol/IProtocolListener.java b/sdl_android_lib/src/com/smartdevicelink/protocol/IProtocolListener.java
index 56dd88160..0e3ff6842 100644
--- a/sdl_android_lib/src/com/smartdevicelink/protocol/IProtocolListener.java
+++ b/sdl_android_lib/src/com/smartdevicelink/protocol/IProtocolListener.java
@@ -5,7 +5,7 @@ import com.smartdevicelink.protocol.enums.*;
public interface IProtocolListener {
// Called to indicate that these bytes are to be sent as part of a message.
// This call includes the part of the message.
- void onProtocolMessageBytesToSend(byte[] msgBytes, int offset, int length);
+ void onProtocolMessageBytesToSend(SdlPacket packet);
// Called to indicate that a complete message (RPC, BULK, etc.) has been
// received. This call includes the message.
diff --git a/sdl_android_lib/src/com/smartdevicelink/protocol/ProtocolMessage.java b/sdl_android_lib/src/com/smartdevicelink/protocol/ProtocolMessage.java
index c63f560d5..5d0e0fc5d 100644
--- a/sdl_android_lib/src/com/smartdevicelink/protocol/ProtocolMessage.java
+++ b/sdl_android_lib/src/com/smartdevicelink/protocol/ProtocolMessage.java
@@ -12,7 +12,8 @@ public class ProtocolMessage {
private int _functionID;
private int _correlationID;
private int _jsonSize;
-
+ int priorityCoefficient = 0;
+
private byte[] _data = null;
private byte[] _bulkData = null;
@@ -122,4 +123,14 @@ public class ProtocolMessage {
public void setJsonSize(int _jsonSize) {
this._jsonSize = _jsonSize;
}
+ /**
+ * Set the priority for this packet. The lower the number the higher the priority. <br>0 is the highest priority and the default.
+ * @param priority
+ */
+ public void setPriorityCoefficient(int priority){
+ this.priorityCoefficient = priority;
+ }
+ public int getPrioirtyCoefficient(){
+ return this.priorityCoefficient;
+ }
} // end-class \ No newline at end of file
diff --git a/sdl_android_lib/src/com/smartdevicelink/protocol/SdlPacket.java b/sdl_android_lib/src/com/smartdevicelink/protocol/SdlPacket.java
index 34b02991c..f6a24d5e3 100644
--- a/sdl_android_lib/src/com/smartdevicelink/protocol/SdlPacket.java
+++ b/sdl_android_lib/src/com/smartdevicelink/protocol/SdlPacket.java
@@ -63,7 +63,7 @@ public class SdlPacket implements Parcelable{
int sessionId;
int dataSize;
int messageId;
-
+ int priorityCoefficient;
byte[] payload = null;
public SdlPacket(int version, boolean compression, int frameType,
@@ -77,6 +77,7 @@ public class SdlPacket implements Parcelable{
this.sessionId = sessionId;
this.dataSize = dataSize;
this.messageId = messageId;
+ this.priorityCoefficient = 0;
if(payload!=null){
this.payload = new byte[payload.length];
System.arraycopy(payload, 0, this.payload, 0, payload.length);
@@ -94,6 +95,7 @@ public class SdlPacket implements Parcelable{
this.sessionId = sessionId;
this.dataSize = dataSize;
this.messageId = messageId;
+ this.priorityCoefficient = 0;
if(payload!=null){
this.payload = new byte[bytesToWrite];
System.arraycopy(payload, offset, this.payload, 0, bytesToWrite);
@@ -192,6 +194,16 @@ public class SdlPacket implements Parcelable{
this.payload = bytes;
}
/**
+ * Set the priority for this packet. The lower the number the higher the priority. <br>0 is the highest priority and the default.
+ * @param priority
+ */
+ public void setPriorityCoefficient(int priority){
+ this.priorityCoefficient = priority;
+ }
+ public int getPrioirtyCoefficient(){
+ return this.priorityCoefficient;
+ }
+ /**
* This method takes in the various components to the SDL packet structure and creates a new byte array that can be sent via the transport
* @param version
* @param compression
@@ -293,6 +305,7 @@ public class SdlPacket implements Parcelable{
payload = new byte[dataSize];
p.readByteArray(payload);
}
+ this.priorityCoefficient = p.readInt();
}
@@ -316,6 +329,7 @@ public class SdlPacket implements Parcelable{
if(payload!=null){
dest.writeByteArray(payload);
}
+ dest.writeInt(priorityCoefficient);
}
diff --git a/sdl_android_lib/src/com/smartdevicelink/protocol/WiProProtocol.java b/sdl_android_lib/src/com/smartdevicelink/protocol/WiProProtocol.java
index 7420c2da2..6913c160b 100644
--- a/sdl_android_lib/src/com/smartdevicelink/protocol/WiProProtocol.java
+++ b/sdl_android_lib/src/com/smartdevicelink/protocol/WiProProtocol.java
@@ -130,6 +130,7 @@ public class WiProProtocol extends AbstractProtocol {
// Second four bytes are frame count.
System.arraycopy(BitConverter.intToByteArray(frameCount), 0, firstFrameData, 4, 4);
SdlPacket firstHeader = SdlPacketFactory.createMultiSendDataFirst(sessionType, sessionID, messageID, _version,firstFrameData);
+ firstHeader.setPriorityCoefficient(1+protocolMsg.priorityCoefficient);
//Send the first frame
handlePacketToSend(firstHeader);
@@ -154,12 +155,14 @@ public class WiProProtocol extends AbstractProtocol {
bytesToWrite = MAX_DATA_SIZE;
}
SdlPacket consecHeader = SdlPacketFactory.createMultiSendDataRest(sessionType, sessionID, bytesToWrite, frameSequenceNumber , messageID, _version,data, currentOffset, bytesToWrite);
+ consecHeader.setPriorityCoefficient(i+2+protocolMsg.priorityCoefficient);
handlePacketToSend(consecHeader);
currentOffset += bytesToWrite;
}
} else {
messageID++;
SdlPacket header = SdlPacketFactory.createSingleSendData(sessionType, sessionID, data.length, messageID, _version,data);
+ header.setPriorityCoefficient(protocolMsg.priorityCoefficient);
handlePacketToSend(header);
}
}
diff --git a/sdl_android_lib/src/com/smartdevicelink/streaming/StreamRPCPacketizer.java b/sdl_android_lib/src/com/smartdevicelink/streaming/StreamRPCPacketizer.java
index 68a7a02ca..ac9ebb379 100644
--- a/sdl_android_lib/src/com/smartdevicelink/streaming/StreamRPCPacketizer.java
+++ b/sdl_android_lib/src/com/smartdevicelink/streaming/StreamRPCPacketizer.java
@@ -151,7 +151,8 @@ public class StreamRPCPacketizer extends AbstractPacketizer implements IPutFileR
PutFile msg = (PutFile) _request;
long iOffsetCounter = msg.getOffset();
sFileName = msg.getSdlFileName();
-
+ int priorityCoefficient = 1;
+
if (lFileSize != 0)
{
Long iFileSize = (long) lFileSize;
@@ -211,6 +212,8 @@ public class StreamRPCPacketizer extends AbstractPacketizer implements IPutFileR
pm.setBulkDataNoCopy(buffer);
pm.setCorrID(msg.getCorrelationID());
+ priorityCoefficient++;
+ pm.setPriorityCoefficient(priorityCoefficient);
notification = new OnStreamRPC();
notification.setFileName(msg.getSdlFileName());
diff --git a/sdl_android_lib/src/com/smartdevicelink/transport/BTTransport.java b/sdl_android_lib/src/com/smartdevicelink/transport/BTTransport.java
index b9e4e8592..3a1ecdd13 100644
--- a/sdl_android_lib/src/com/smartdevicelink/transport/BTTransport.java
+++ b/sdl_android_lib/src/com/smartdevicelink/transport/BTTransport.java
@@ -307,10 +307,11 @@ public class BTTransport extends SdlTransport {
* Sends data over the transport. Takes a byte array and transmits data provided starting at the
* offset and of the provided length to fragment transmission.
*/
- public boolean sendBytesOverTransport(byte[] msgBytes, int offset, int length) {
+ public boolean sendBytesOverTransport(SdlPacket packet) {
boolean sendResult = false;
try {
- _output.write(msgBytes, offset, length);
+ byte[] msgBytes = packet.constructPacket();
+ _output.write(msgBytes, 0, msgBytes.length);
sendResult = true;
} catch (Exception ex) {
DebugTool.logError("Error writing to Bluetooth socket: " + ex.toString(), ex);
diff --git a/sdl_android_lib/src/com/smartdevicelink/transport/MultiplexTransport.java b/sdl_android_lib/src/com/smartdevicelink/transport/MultiplexTransport.java
index 3bbf3a8e3..5556d9af1 100644
--- a/sdl_android_lib/src/com/smartdevicelink/transport/MultiplexTransport.java
+++ b/sdl_android_lib/src/com/smartdevicelink/transport/MultiplexTransport.java
@@ -85,10 +85,9 @@ public class MultiplexTransport extends SdlTransport{
}
@Override
- protected boolean sendBytesOverTransport(byte[] msgBytes, int offset,
- int length) {
+ protected boolean sendBytesOverTransport(SdlPacket packet) {
if(brokerThread!=null){
- brokerThread.sendPacket(msgBytes,offset,length);
+ brokerThread.sendPacket(packet);
return true;
}
return false; //Sure why not.
@@ -206,8 +205,8 @@ public class MultiplexTransport extends SdlTransport{
}
}
- public void sendPacket(byte[] msgBytes,int offset,int length){
- broker.sendPacketToRouterService(msgBytes,offset,length);
+ public void sendPacket(SdlPacket packet){
+ broker.sendPacketToRouterService(packet);
}
public void requestNewSession(){
diff --git a/sdl_android_lib/src/com/smartdevicelink/transport/SdlRouterService.java b/sdl_android_lib/src/com/smartdevicelink/transport/SdlRouterService.java
index 574dfa8d1..a398c5e7c 100644
--- a/sdl_android_lib/src/com/smartdevicelink/transport/SdlRouterService.java
+++ b/sdl_android_lib/src/com/smartdevicelink/transport/SdlRouterService.java
@@ -1244,7 +1244,7 @@ public class SdlRouterService extends Service{
return false;
}
//Log.w(TAG, "Message too big for single IPC transaction. Breaking apart. Size - " + packet.getDataSize());
- ByteArrayMessageSpliter splitter = new ByteArrayMessageSpliter(appid,TransportConstants.ROUTER_RECEIVED_PACKET,bytes);
+ ByteArrayMessageSpliter splitter = new ByteArrayMessageSpliter(appid,TransportConstants.ROUTER_RECEIVED_PACKET,bytes,0);
while(splitter.isActive()){
if(!sendPacketMessageToClient(app,splitter.nextMessage(),version)){
Log.w(TAG, "Error sending first message of split packet to client " + app.appId);
@@ -1836,6 +1836,7 @@ public class SdlRouterService extends Service{
Messenger messenger;
Vector<Long> sessionIds;
ByteAraryMessageAssembler buffer;
+ int prioirtyForBuffingMessage;
DeathRecipient deathNote = null;
LinkedBlockingQueue<PacketWriteTask> queue;
@@ -1918,6 +1919,9 @@ public class SdlRouterService extends Service{
Log.d(TAG, "Flags received: " + flags);
if(flags!=TransportConstants.BYTES_TO_SEND_FLAG_NONE){
byte[] packet = receivedBundle.getByteArray(TransportConstants.BYTES_TO_SEND_EXTRA_NAME);
+ if(flags == TransportConstants.BYTES_TO_SEND_FLAG_LARGE_PACKET_START){
+ this.prioirtyForBuffingMessage = receivedBundle.getInt(TransportConstants.PACKET_PRIORITY_COEFFICIENT,0);
+ }
handleMessage(flags, packet);
}else{
//Add the write task on the stack
@@ -1962,7 +1966,7 @@ public class SdlRouterService extends Service{
if(buffer.isFinished()){ //We are finished building the buffer so we should write the bytes out
byte[] bytes = buffer.getBytes();
if(queue!=null){
- queue.add(new PacketWriteTask(bytes, 0, bytes.length));
+ queue.add(new PacketWriteTask(bytes, 0, bytes.length,this.prioirtyForBuffingMessage));
if(packetWriteTaskMaster!=null){
packetWriteTaskMaster.alert();
}
@@ -2029,21 +2033,23 @@ public class SdlRouterService extends Service{
*
*/
public class PacketWriteTask implements Runnable{
- private static final long DELAY_CONSTANT = 250; //250ms
+ private static final long DELAY_CONSTANT = 500; //250ms
private static final long SIZE_CONSTANT = 1000; //1kb
- private static final int DELAY_COEF = 5;
+ private static final long PRIORITY_COEF_CONSTATNT = 500;
+ private static final int DELAY_COEF = 1;
private static final int SIZE_COEF = 1;
private byte[] bytesToWrite = null;
- private int offset, size;
+ private int offset, size, priorityCoefficient;
private final long timestamp;
final Bundle receivedBundle;
- public PacketWriteTask(byte[] bytes, int offset, int size){
+ public PacketWriteTask(byte[] bytes, int offset, int size, int priorityCoefficient){
timestamp = System.currentTimeMillis();
bytesToWrite = bytes;
this.offset = offset;
this.size = size;
+ this.priorityCoefficient = priorityCoefficient;
receivedBundle = null;
}
@@ -2053,6 +2059,7 @@ public class SdlRouterService extends Service{
bytesToWrite = bundle.getByteArray(TransportConstants.BYTES_TO_SEND_EXTRA_NAME);
offset = bundle.getInt(TransportConstants.BYTES_TO_SEND_EXTRA_OFFSET, 0); //If nothing, start at the begining of the array
size = bundle.getInt(TransportConstants.BYTES_TO_SEND_EXTRA_COUNT, bytesToWrite.length); //In case there isn't anything just send the whole packet.
+ this.priorityCoefficient = bundle.getInt(TransportConstants.PACKET_PRIORITY_COEFFICIENT,0); Log.d(TAG, "packet priority coef: "+ this.priorityCoefficient);
}
@Override
@@ -2064,8 +2071,8 @@ public class SdlRouterService extends Service{
}
}
- private long getWeight(long currentTime){
- return ((((currentTime-timestamp) + DELAY_CONSTANT) * DELAY_COEF ) - ((size -SIZE_CONSTANT) * SIZE_COEF));
+ private long getWeight(long currentTime){ //Time waiting - size - prioirty_coef
+ return ((((currentTime-timestamp) + DELAY_CONSTANT) * DELAY_COEF ) - ((size -SIZE_CONSTANT) * SIZE_COEF) - (priorityCoefficient * PRIORITY_COEF_CONSTATNT));
}
}
diff --git a/sdl_android_lib/src/com/smartdevicelink/transport/SdlTransport.java b/sdl_android_lib/src/com/smartdevicelink/transport/SdlTransport.java
index deccad903..27c87bcef 100644
--- a/sdl_android_lib/src/com/smartdevicelink/transport/SdlTransport.java
+++ b/sdl_android_lib/src/com/smartdevicelink/transport/SdlTransport.java
@@ -50,25 +50,25 @@ public abstract class SdlTransport {
// This method must be implemented by transport subclass, and is called by this
// base class to actually send an array of bytes out over the transport. This
// method is meant to only be callable within the class hierarchy.
- protected abstract boolean sendBytesOverTransport(byte[] msgBytes, int offset, int length);
+ protected abstract boolean sendBytesOverTransport(SdlPacket packet);
// This method is called by whomever has reference to transport to have bytes
// sent out over transport.
- public boolean sendBytes(byte[] message) {
+ /* public boolean sendBytes(byte[] message) {
return sendBytes(message, 0, message.length);
- } // end-method
+ }*/ // end-method
// This method is called by whomever has reference to transport to have bytes
// sent out over transport.
- public boolean sendBytes(byte[] message, int offset, int length) {
+ public boolean sendBytes(SdlPacket packet) {
boolean bytesWereSent = false;
synchronized (_sendLockObj) {
- bytesWereSent = sendBytesOverTransport(message, offset, length);
+ bytesWereSent = sendBytesOverTransport(packet);//message, offset, length);
} // end-lock
// Send transport data to the siphon server
- SiphonServer.sendBytesFromAPP(message, offset, length);
+ //FIXME SiphonServer.sendBytesFromAPP(message, offset, length);
- SdlTrace.logTransportEvent("", null, InterfaceActivityDirection.Transmit, message, offset, length, SDL_LIB_TRACE_KEY);
+ //FIXME SdlTrace.logTransportEvent("", null, InterfaceActivityDirection.Transmit, message, offset, length, SDL_LIB_TRACE_KEY);
return bytesWereSent;
} // end-method
diff --git a/sdl_android_lib/src/com/smartdevicelink/transport/TCPTransport.java b/sdl_android_lib/src/com/smartdevicelink/transport/TCPTransport.java
index 26a070a7f..9ba789ef8 100644
--- a/sdl_android_lib/src/com/smartdevicelink/transport/TCPTransport.java
+++ b/sdl_android_lib/src/com/smartdevicelink/transport/TCPTransport.java
@@ -108,10 +108,11 @@ public class TCPTransport extends SdlTransport {
* @return True if data was sent successfully, False otherwise
*/
@Override
- protected boolean sendBytesOverTransport(byte[] msgBytes, int offset, int length) {
+ protected boolean sendBytesOverTransport(SdlPacket packet) {
TCPTransportState currentState = getCurrentState();
+ byte[] msgBytes = packet.constructPacket();
logInfo(String.format("TCPTransport: sendBytesOverTransport requested. Size: %d, Offset: %d, Length: %d, Current state is: %s"
- , msgBytes.length, offset, length, currentState.name()));
+ , msgBytes.length, 0, msgBytes.length, currentState.name()));
boolean bResult = false;
@@ -119,7 +120,7 @@ public class TCPTransport extends SdlTransport {
if (mOutputStream != null) {
logInfo("TCPTransport: sendBytesOverTransport request accepted. Trying to send data");
try {
- mOutputStream.write(msgBytes, offset, length);
+ mOutputStream.write(msgBytes, 0, msgBytes.length);
bResult = true;
logInfo("TCPTransport.sendBytesOverTransport: successfully send data");
} catch (IOException e) {
diff --git a/sdl_android_lib/src/com/smartdevicelink/transport/TransportBroker.java b/sdl_android_lib/src/com/smartdevicelink/transport/TransportBroker.java
index 0a1d25364..9203b40cd 100644
--- a/sdl_android_lib/src/com/smartdevicelink/transport/TransportBroker.java
+++ b/sdl_android_lib/src/com/smartdevicelink/transport/TransportBroker.java
@@ -411,36 +411,38 @@ public class TransportBroker {
}
- public boolean sendPacketToRouterService(byte[] bytes, int offset, int count){ //We use ints because that is all that is supported by the outputstream class
+ public boolean sendPacketToRouterService(SdlPacket packet){ //We use ints because that is all that is supported by the outputstream class
//Log.d(TAG,whereToReply + "Sending packet to router service");
if(routerServiceMessenger==null){
Log.d(TAG,whereToReply + " tried to send packet, but no where to send");
return false;
}
- if(bytes == null
- || offset<0
- || count<0
- || count>(bytes.length-offset)){
+ if(packet == null
+ //|| offset<0
+ //|| count<0
+ ){//|| count>(bytes.length-offset)){
Log.w(TAG,whereToReply + "incorrect params supplied");
return false;
}
+ byte[] bytes = packet.constructPacket();
if(bytes.length<ByteArrayMessageSpliter.MAX_BINDER_SIZE){//Determine if this is under the packet length.
Message message = Message.obtain(); //Do we need to always obtain new? or can we just swap bundles?
message.what = TransportConstants.ROUTER_SEND_PACKET;
Bundle bundle = new Bundle();
bundle.putLong(TransportConstants.APP_ID_EXTRA, appId);
bundle.putByteArray(TransportConstants.BYTES_TO_SEND_EXTRA_NAME, bytes); //Do we just change this to the args and objs
- bundle.putInt(TransportConstants.BYTES_TO_SEND_EXTRA_OFFSET, offset);
- bundle.putInt(TransportConstants.BYTES_TO_SEND_EXTRA_COUNT, count);
+ bundle.putInt(TransportConstants.BYTES_TO_SEND_EXTRA_OFFSET, 0);
+ bundle.putInt(TransportConstants.BYTES_TO_SEND_EXTRA_COUNT, bytes.length);
bundle.putInt(TransportConstants.BYTES_TO_SEND_FLAGS, TransportConstants.BYTES_TO_SEND_FLAG_NONE);
+ bundle.putInt(TransportConstants.PACKET_PRIORITY_COEFFICIENT, packet.getPrioirtyCoefficient());
message.setData(bundle);
sendMessageToRouterService(message);
return true;
}else{ //Message is too big for IPC transaction
Log.w(TAG, "Message too big for single IPC transaction. Breaking apart. Size - " + bytes.length);
- ByteArrayMessageSpliter splitter = new ByteArrayMessageSpliter(appId,TransportConstants.ROUTER_SEND_PACKET,bytes);
+ ByteArrayMessageSpliter splitter = new ByteArrayMessageSpliter(appId,TransportConstants.ROUTER_SEND_PACKET,bytes,packet.getPrioirtyCoefficient() );
while(splitter.isActive()){
sendMessageToRouterService(splitter.nextMessage());
}
diff --git a/sdl_android_lib/src/com/smartdevicelink/transport/TransportConstants.java b/sdl_android_lib/src/com/smartdevicelink/transport/TransportConstants.java
index 29432daad..7a989fb47 100644
--- a/sdl_android_lib/src/com/smartdevicelink/transport/TransportConstants.java
+++ b/sdl_android_lib/src/com/smartdevicelink/transport/TransportConstants.java
@@ -174,6 +174,8 @@ public class TransportConstants {
public static final String BYTES_TO_SEND_EXTRA_COUNT = "count";
public static final String BYTES_TO_SEND_FLAGS = "flags";
+ public static final String PACKET_PRIORITY_COEFFICIENT = "priority_coefficient";
+
public static final int BYTES_TO_SEND_FLAG_NONE = 0x00;
public static final int BYTES_TO_SEND_FLAG_SDL_PACKET_INCLUDED = 0x01;
public static final int BYTES_TO_SEND_FLAG_LARGE_PACKET_START = 0x02;
diff --git a/sdl_android_lib/src/com/smartdevicelink/transport/USBTransport.java b/sdl_android_lib/src/com/smartdevicelink/transport/USBTransport.java
index 3c880d4dc..72616084a 100644
--- a/sdl_android_lib/src/com/smartdevicelink/transport/USBTransport.java
+++ b/sdl_android_lib/src/com/smartdevicelink/transport/USBTransport.java
@@ -6,7 +6,7 @@ import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
-
+import android.annotation.SuppressLint;
import android.app.PendingIntent;
import android.content.BroadcastReceiver;
import android.content.Context;
@@ -15,7 +15,6 @@ import android.content.IntentFilter;
import android.hardware.usb.UsbAccessory;
import android.hardware.usb.UsbManager;
import android.os.ParcelFileDescriptor;
-
import com.smartdevicelink.exception.SdlException;
import com.smartdevicelink.exception.SdlExceptionCause;
import com.smartdevicelink.protocol.SdlPacket;
@@ -36,6 +35,7 @@ import com.smartdevicelink.util.DebugTool;
* the other side will NOT be notified and unblocked from reading data until
* some data is sent again or the USB is physically disconnected.
*/
+@SuppressLint("NewApi")
public class USBTransport extends SdlTransport {
/**
* Broadcast action: sent when a USB accessory is attached.
@@ -205,10 +205,10 @@ public class USBTransport extends SdlTransport {
* @return true if the bytes are sent successfully
*/
@Override
- protected boolean sendBytesOverTransport(byte[] msgBytes, int offset,
- int length) {
- logD("SendBytes: array size " + msgBytes.length + ", offset " + offset +
- ", length " + length);
+ protected boolean sendBytesOverTransport(SdlPacket packet) {
+ byte[] msgBytes = packet.constructPacket();
+ logD("SendBytes: array size " + msgBytes.length + ", offset " + 0 +
+ ", length " + msgBytes.length);
boolean result = false;
final State state = getState();
@@ -216,13 +216,13 @@ public class USBTransport extends SdlTransport {
case CONNECTED:
if (mOutputStream != null) {
try {
- mOutputStream.write(msgBytes, offset, length);
+ mOutputStream.write(msgBytes, 0, msgBytes.length);
result = true;
logI("Bytes successfully sent");
SdlTrace.logTransportEvent(TAG + ": bytes sent",
null, InterfaceActivityDirection.Transmit,
- msgBytes, offset, length,
+ msgBytes, 0, msgBytes.length,
SDL_LIB_TRACE_KEY);
} catch (IOException e) {
final String msg = "Failed to send bytes over USB";
diff --git a/sdl_android_lib/src/com/smartdevicelink/transport/utl/ByteArrayMessageSpliter.java b/sdl_android_lib/src/com/smartdevicelink/transport/utl/ByteArrayMessageSpliter.java
index c6ce1780b..b8c33c614 100644
--- a/sdl_android_lib/src/com/smartdevicelink/transport/utl/ByteArrayMessageSpliter.java
+++ b/sdl_android_lib/src/com/smartdevicelink/transport/utl/ByteArrayMessageSpliter.java
@@ -22,23 +22,26 @@ public class ByteArrayMessageSpliter {
Long appId;
byte[] buffer;
int orginalSize;
+ int priorityCoef;
- public ByteArrayMessageSpliter(String appId,int what, byte[] bytes){
+ public ByteArrayMessageSpliter(String appId,int what, byte[] bytes, int priorityCoef){
this.appId = Long.valueOf(appId);
this.what = what;
stream = new ByteArrayInputStream(bytes);
orginalSize = stream.available();
bytesRead = 0;
firstPacket = true;
+ this.priorityCoef = priorityCoef;
}
- public ByteArrayMessageSpliter(Long appId,int what, byte[] bytes){
+ public ByteArrayMessageSpliter(Long appId,int what, byte[] bytes, int priorityCoef){
this.appId = appId;
this.what = what;
stream = new ByteArrayInputStream(bytes);
orginalSize = stream.available();
bytesRead = 0;
firstPacket = true;
+ this.priorityCoef = priorityCoef;
}
public boolean isActive(){
@@ -88,6 +91,7 @@ public class ByteArrayMessageSpliter {
//Determine which flag should be sent for this division of the packet
if(firstPacket){
bundle.putInt(TransportConstants.BYTES_TO_SEND_FLAGS, TransportConstants.BYTES_TO_SEND_FLAG_LARGE_PACKET_START);
+ bundle.putInt(TransportConstants.PACKET_PRIORITY_COEFFICIENT, this.priorityCoef);
firstPacket = false;
}else if(stream.available()<=0){ //We are at the end of the stream so let the flag reflect that
bundle.putInt(TransportConstants.BYTES_TO_SEND_FLAGS, TransportConstants.BYTES_TO_SEND_FLAG_LARGE_PACKET_END);