Skip to content

Commit f2b533b

Browse files
author
Julian Kast
committed
Merge branch 'develop' into bugfix/issue_1676
2 parents 76cbf36 + ad5fc1e commit f2b533b

12 files changed

Lines changed: 54 additions & 39 deletions

File tree

android/sdl_android/src/main/java/com/smartdevicelink/transport/MultiplexBluetoothTransport.java

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,8 @@ public class MultiplexBluetoothTransport extends MultiplexBaseTransport {
7777
Handler timeOutHandler;
7878
Runnable socketRunnable;
7979
boolean keepSocketAlive = true;
80-
80+
BluetoothDevice connectedDevice;
81+
8182
/**
8283
* Constructor. Prepares a new BluetoothChat session.
8384
*
@@ -112,6 +113,14 @@ public void setKeepSocketAlive(boolean keepSocketAlive) {
112113
this.keepSocketAlive = keepSocketAlive;
113114
}
114115

116+
/**
117+
* A method to retrieve the currently connected bluetooth device
118+
* @return the connected bluetooth device if connected, null otherwise.
119+
*/
120+
public BluetoothDevice getConnectedDevice(){
121+
return connectedDevice;
122+
}
123+
115124
/**
116125
* Start the chat service. Specifically start AcceptThread to begin a
117126
* session in listening (server) mode. Called by the Activity onResume()
@@ -225,6 +234,7 @@ public synchronized void connected(BluetoothSocket socket, BluetoothDevice devic
225234

226235
//Store a static name of the device that is connected.
227236
if (device != null) {
237+
connectedDevice = device;
228238
connectedDeviceName = device.getName();
229239
connectedDeviceAddress = device.getAddress();
230240
if (connectedDeviceAddress != null) {

android/sdl_android/src/main/java/com/smartdevicelink/transport/SdlBroadcastReceiver.java

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -275,9 +275,16 @@ public void onComplete(Vector<ComponentName> routerServices) {
275275
DebugTool.logInfo(TAG, ": This app's package: " + myPackage);
276276
DebugTool.logInfo(TAG, ": Router service app's package: " + routerServicePackage);
277277
if (myPackage != null && myPackage.equalsIgnoreCase(routerServicePackage)) {
278-
SdlDeviceListener sdlDeviceListener = getSdlDeviceListener(context, device);
279-
if (!sdlDeviceListener.isRunning()) {
280-
sdlDeviceListener.start();
278+
//If the device is not null the listener should start as well as the
279+
//case where this app was installed after BT connected and is the
280+
//only SDL app installed on the device. (Rare corner case)
281+
if(device != null || sdlAppInfoList.size() == 1) {
282+
SdlDeviceListener sdlDeviceListener = getSdlDeviceListener(context, device);
283+
if (!sdlDeviceListener.isRunning()) {
284+
sdlDeviceListener.start();
285+
}
286+
} else {
287+
DebugTool.logInfo(TAG, "Not starting device listener, bluetooth device is null and other SDL apps installed.");
281288
}
282289
} else {
283290
DebugTool.logInfo(TAG, ": Not the app to start the router service nor device listener");

android/sdl_android/src/main/java/com/smartdevicelink/transport/utl/SdlDeviceListener.java

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ public class SdlDeviceListener {
6161

6262
private final WeakReference<Context> contextWeakReference;
6363
private final Callback callback;
64-
private final BluetoothDevice connectedDevice;
64+
private BluetoothDevice connectedDevice;
6565
private MultiplexBluetoothTransport bluetoothTransport;
6666
private TransportHandler bluetoothHandler;
6767
private Handler timeoutHandler;
@@ -87,24 +87,21 @@ public SdlDeviceListener(Context context, BluetoothDevice device, Callback callb
8787
public void start() {
8888
if (connectedDevice == null) {
8989
DebugTool.logInfo(TAG, ": No supplied bluetooth device");
90-
if (callback != null) {
91-
callback.onTransportError(null);
92-
}
93-
return;
94-
}
95-
96-
if (hasSDLConnected(contextWeakReference.get(), connectedDevice.getAddress())) {
90+
} else if (hasSDLConnected(contextWeakReference.get(), connectedDevice.getAddress())) {
9791
DebugTool.logInfo(TAG, ": Confirmed SDL device, should start router service");
9892
//This device has connected to SDL previously, it is ok to start the RS right now
9993
callback.onTransportConnected(contextWeakReference.get(), connectedDevice);
10094
return;
10195
}
96+
10297
synchronized (RUNNING_LOCK) {
10398
isRunning = true;
10499
// set timeout = if first time seeing BT device, 30s, if not 15s
105-
int timeout = isFirstStatusCheck(connectedDevice.getAddress()) ? 30000 : 15000;
100+
int timeout = connectedDevice != null && isFirstStatusCheck(connectedDevice.getAddress()) ? 30000 : 15000;
106101
//Set our preference as false for this device for now
107-
setSDLConnectedStatus(contextWeakReference.get(), connectedDevice.getAddress(), false);
102+
if(connectedDevice != null) {
103+
setSDLConnectedStatus(contextWeakReference.get(), connectedDevice.getAddress(), false);
104+
}
108105
bluetoothHandler = new TransportHandler(this);
109106
bluetoothTransport = new MultiplexBluetoothTransport(bluetoothHandler);
110107
bluetoothTransport.start();
@@ -155,6 +152,9 @@ public void handleMessage(@NonNull Message msg) {
155152
case SdlRouterService.MESSAGE_STATE_CHANGE:
156153
switch (msg.arg1) {
157154
case MultiplexBaseTransport.STATE_CONNECTED:
155+
if(sdlListener.connectedDevice == null) {
156+
sdlListener.connectedDevice = sdlListener.bluetoothTransport.getConnectedDevice();
157+
}
158158
sdlListener.setSDLConnectedStatus(sdlListener.contextWeakReference.get(), sdlListener.connectedDevice.getAddress(), true);
159159
boolean keepConnectionOpen = sdlListener.callback.onTransportConnected(sdlListener.contextWeakReference.get(), sdlListener.connectedDevice);
160160
if (!keepConnectionOpen) {

base/src/main/java/com/smartdevicelink/exception/SdlException.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,6 @@ public String toString() {
7171
}
7272
if (detail != null) {
7373
ret += "\nnested: " + detail.toString();
74-
detail.printStackTrace();
7574
}
7675
return ret;
7776
}

base/src/main/java/com/smartdevicelink/managers/BaseSdlManager.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -205,7 +205,7 @@ public void onResponse(int correlationId, RPCResponse response) {
205205
try {
206206
DebugTool.logInfo(TAG, response.serializeJSON().toString());
207207
} catch (JSONException e) {
208-
e.printStackTrace();
208+
DebugTool.logError(TAG, "Error attempting to serialize ChangeRegistrationResponse", e);
209209
}
210210

211211
// go through and change sdlManager properties that were changed via the LCU update

base/src/main/java/com/smartdevicelink/managers/file/UploadFileOperation.java

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@
4343
import com.smartdevicelink.proxy.rpc.PutFile;
4444
import com.smartdevicelink.proxy.rpc.PutFileResponse;
4545
import com.smartdevicelink.proxy.rpc.listeners.OnRPCResponseListener;
46+
import com.smartdevicelink.util.DebugTool;
4647

4748
import java.io.IOException;
4849
import java.io.InputStream;
@@ -221,7 +222,7 @@ private void closeInputStream() {
221222
try {
222223
this.inputStream.close();
223224
} catch (IOException e) {
224-
e.printStackTrace();
225+
DebugTool.logError(TAG,"Error attempting to close input stream", e);
225226
}
226227
}
227228

@@ -330,7 +331,7 @@ private byte[] getDataChunkWithSize(int size, InputStream inputStream) {
330331
try {
331332
bytesRead = inputStream.read(buffer, 0, size);
332333
} catch (IOException e) {
333-
e.printStackTrace();
334+
DebugTool.logError(TAG,"Error attempting to read from input stream", e);
334335
}
335336

336337
if (bytesRead > 0) {
@@ -365,7 +366,7 @@ private int getFileSizeFromInputStream(InputStream inputStream) {
365366
try {
366367
size = inputStream.available();
367368
} catch (IOException e) {
368-
e.printStackTrace();
369+
DebugTool.logError(TAG,"Error trying to get input stream size", e);
369370
}
370371
}
371372
return size;

base/src/main/java/com/smartdevicelink/managers/lifecycle/BaseLifecycleManager.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,7 @@ public void start() {
146146
try {
147147
session.startSession();
148148
} catch (SdlException e) {
149-
e.printStackTrace();
149+
DebugTool.logError(TAG,"Error attempting to start session", e);
150150
}
151151
}
152152

@@ -851,7 +851,7 @@ private void sendRPCMessagePrivate(RPCMessage message, boolean isInternalMessage
851851
session.sendMessage(pm);
852852

853853
} catch (OutOfMemoryError e) {
854-
e.printStackTrace();
854+
DebugTool.logError(TAG,"Error attempting to send RPC message.", e);
855855
}
856856
}
857857

base/src/main/java/com/smartdevicelink/managers/screen/menu/BaseMenuManager.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1275,7 +1275,7 @@ public void onResponse(int correlationId, RPCResponse response) {
12751275
try {
12761276
DebugTool.logInfo(TAG, "Main Menu response: " + response.serializeJSON().toString());
12771277
} catch (JSONException e) {
1278-
e.printStackTrace();
1278+
DebugTool.logError(TAG,"Error attempting to serialize JSON of RPC response", e);
12791279
}
12801280
} else {
12811281
DebugTool.logError(TAG, "Result: " + response.getResultCode() + " Info: " + response.getInfo());
@@ -1313,7 +1313,7 @@ public void onResponse(int correlationId, RPCResponse response) {
13131313
try {
13141314
DebugTool.logInfo(TAG, "Sub Menu response: " + response.serializeJSON().toString());
13151315
} catch (JSONException e) {
1316-
e.printStackTrace();
1316+
DebugTool.logError(TAG,"Error attempting to serialize JSON of RPC response", e);
13171317
}
13181318
} else {
13191319
DebugTool.logError(TAG, "Failed to send sub menu commands: " + response.getInfo());
@@ -1365,7 +1365,7 @@ public void onResponse(int correlationId, RPCResponse response) {
13651365
try {
13661366
DebugTool.logInfo(TAG, "Dynamic Sub Menu response: " + response.serializeJSON().toString());
13671367
} catch (JSONException e) {
1368-
e.printStackTrace();
1368+
DebugTool.logError(TAG,"Error attempting to serialize JSON of RPC response", e);
13691369
}
13701370
} else {
13711371
DebugTool.logError(TAG, "Result: " + response.getResultCode() + " Info: " + response.getInfo());

base/src/main/java/com/smartdevicelink/proxy/RPCStruct.java

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,8 @@
5050
import java.util.Set;
5151

5252
public class RPCStruct implements Cloneable {
53+
private static final String TAG = "RPCStruct";
54+
5355
public static final String KEY_BULK_DATA = "bulkData";
5456
public static final String KEY_PROTECTED = "protected";
5557

@@ -268,7 +270,7 @@ protected Object formatObject(Class tClass, Object obj) {
268270

269271
return customObject;
270272
} catch (Exception e) {
271-
e.printStackTrace();
273+
DebugTool.logError(TAG,"Error attempting to format an object from a Hashtable", e);
272274
}
273275
} else if (obj instanceof List<?>) {
274276
List<?> list = (List<?>) obj;
@@ -300,7 +302,7 @@ protected Object formatObject(Class tClass, Object obj) {
300302
}
301303
newList.add(customObject);
302304
} catch (Exception e) {
303-
e.printStackTrace();
305+
DebugTool.logError(TAG,"Error attempting to format object from list of Hashtables", e);
304306
return null;
305307
}
306308
}
@@ -334,15 +336,15 @@ protected Object getValueForString(Class tClass, String s) {
334336
try {
335337
valueForString = tClass.getDeclaredMethod("valueForString", String.class);
336338
} catch (NoSuchMethodException e) {
337-
e.printStackTrace();
339+
DebugTool.logError(TAG,"Error attempting to find valueForString method in class", e);
338340
}
339341
if (valueForString != null) {
340342
try {
341343
return valueForString.invoke(null, (String) s);
342344
} catch (IllegalAccessException e) {
343-
e.printStackTrace();
345+
DebugTool.logError(TAG,"Illegal access while using reflection to get enum from string", e);
344346
} catch (InvocationTargetException e) {
345-
e.printStackTrace();
347+
DebugTool.logError(TAG,"Error attempting to use method from reflection to get enum from string", e);
346348
}
347349
}
348350
return null;

base/src/main/java/com/smartdevicelink/proxy/rpc/OnSystemRequest.java

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -179,11 +179,9 @@ private void handleBulkData(byte[] bulkData) {
179179
tempBody = getBody(httpJson);
180180
tempHeaders = getHeaders(httpJson);
181181
} catch (JSONException e) {
182-
DebugTool.logError(TAG, "HTTPRequest in bulk data was malformed.");
183-
e.printStackTrace();
182+
DebugTool.logError(TAG, "HTTPRequest in bulk data was malformed.", e);
184183
} catch (NullPointerException e) {
185-
DebugTool.logError(TAG, "Invalid HTTPRequest object in bulk data.");
186-
e.printStackTrace();
184+
DebugTool.logError(TAG, "Invalid HTTPRequest object in bulk data.", e);
187185
}
188186
} else if (RequestType.HTTP.equals(this.getRequestType())) {
189187
tempHeaders = new Headers();
@@ -209,8 +207,7 @@ private String getBody(JSONObject httpJson) {
209207
try {
210208
result = httpJson.getString(KEY_BODY);
211209
} catch (JSONException e) {
212-
DebugTool.logError(TAG, KEY_BODY + " key doesn't exist in bulk data.");
213-
e.printStackTrace();
210+
DebugTool.logError(TAG, KEY_BODY + " key doesn't exist in bulk data.", e);
214211
}
215212

216213
return result;
@@ -224,8 +221,7 @@ private Headers getHeaders(JSONObject httpJson) {
224221
Hashtable<String, Object> httpHeadersHash = JsonRPCMarshaller.deserializeJSONObject(httpHeadersJson);
225222
result = new Headers(httpHeadersHash);
226223
} catch (JSONException e) {
227-
DebugTool.logError(TAG, KEY_HEADERS + " key doesn't exist in bulk data.");
228-
e.printStackTrace();
224+
DebugTool.logError(TAG, KEY_HEADERS + " key doesn't exist in bulk data.", e);
229225
}
230226

231227
return result;

0 commit comments

Comments
 (0)