diff options
author | Joey Grover <joeygrover@gmail.com> | 2019-09-24 11:31:10 -0400 |
---|---|---|
committer | Joey Grover <joeygrover@gmail.com> | 2019-09-24 11:31:10 -0400 |
commit | d4a82e4c8444116f01ca72926d449991d3ea3bbb (patch) | |
tree | c25b615fb9b113f3659babe71e039e94fd61411a | |
parent | 1b57bdc3c71475a9b2c071ebdfdc805cc1dff32e (diff) | |
download | sdl_android-d4a82e4c8444116f01ca72926d449991d3ea3bbb.tar.gz |
Fix potential NPEs
18 files changed, 313 insertions, 187 deletions
diff --git a/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/util/CompareUtilsTest.java b/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/util/CompareUtilsTest.java new file mode 100644 index 000000000..5edd95ab5 --- /dev/null +++ b/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/util/CompareUtilsTest.java @@ -0,0 +1,47 @@ +package com.smartdevicelink.test.util; + +import com.smartdevicelink.AndroidTestCase2; +import com.smartdevicelink.test.Test; +import com.smartdevicelink.util.CompareUtils; + +public class CompareUtilsTest extends AndroidTestCase2 { + + public void testAreStringsEqual(){ + + assertTrue(CompareUtils.areStringsEqual(Test.GENERAL_STRING, Test.GENERAL_STRING, true, true)); + assertTrue(CompareUtils.areStringsEqual(Test.GENERAL_STRING, Test.GENERAL_STRING, false, true)); + assertTrue(CompareUtils.areStringsEqual(Test.GENERAL_STRING, Test.GENERAL_STRING, true, false)); + assertTrue(CompareUtils.areStringsEqual(Test.GENERAL_STRING, Test.GENERAL_STRING, false, false)); + + assertFalse(CompareUtils.areStringsEqual(Test.GENERAL_STRING, Test.GENERAL_APP_ID, true, true)); + assertFalse(CompareUtils.areStringsEqual(Test.GENERAL_STRING, Test.GENERAL_APP_ID, false, true)); + assertFalse(CompareUtils.areStringsEqual(Test.GENERAL_STRING, Test.GENERAL_APP_ID, true, false)); + assertFalse(CompareUtils.areStringsEqual(Test.GENERAL_STRING, Test.GENERAL_APP_ID, false, false)); + + assertFalse(CompareUtils.areStringsEqual(Test.GENERAL_STRING, Test.GENERAL_STRING.toUpperCase(), false, false)); + assertFalse(CompareUtils.areStringsEqual(Test.GENERAL_STRING, Test.GENERAL_STRING.toUpperCase(), false, true)); + assertTrue(CompareUtils.areStringsEqual(Test.GENERAL_STRING, Test.GENERAL_STRING.toUpperCase(), true, false)); + assertTrue(CompareUtils.areStringsEqual(Test.GENERAL_STRING, Test.GENERAL_STRING.toUpperCase(), true, true)); + + assertFalse(CompareUtils.areStringsEqual(Test.GENERAL_STRING.toUpperCase(), Test.GENERAL_STRING, false, false)); + assertFalse(CompareUtils.areStringsEqual(Test.GENERAL_STRING.toUpperCase(), Test.GENERAL_STRING, false, true)); + assertTrue(CompareUtils.areStringsEqual(Test.GENERAL_STRING.toUpperCase(), Test.GENERAL_STRING.toUpperCase(), true, false)); + assertTrue(CompareUtils.areStringsEqual(Test.GENERAL_STRING.toUpperCase(), Test.GENERAL_STRING.toUpperCase(), true, true)); + + assertTrue(CompareUtils.areStringsEqual(null, null, true, true)); + assertFalse(CompareUtils.areStringsEqual(null, null, true, false)); + assertTrue(CompareUtils.areStringsEqual(null, null, false, true)); + assertFalse(CompareUtils.areStringsEqual(null, null, false, false)); + + assertFalse(CompareUtils.areStringsEqual(Test.GENERAL_STRING, null, true, true)); + assertFalse(CompareUtils.areStringsEqual(Test.GENERAL_STRING, null, true, false)); + assertFalse(CompareUtils.areStringsEqual(Test.GENERAL_STRING, null, false, true)); + assertFalse(CompareUtils.areStringsEqual(Test.GENERAL_STRING, null, false, false)); + + assertFalse(CompareUtils.areStringsEqual(null, Test.GENERAL_STRING, false, true)); + assertFalse(CompareUtils.areStringsEqual(null, Test.GENERAL_STRING, false, false)); + assertFalse(CompareUtils.areStringsEqual(null, Test.GENERAL_STRING, true, true)); + assertFalse(CompareUtils.areStringsEqual(null, Test.GENERAL_STRING, true, false)); + + } +} diff --git a/android/sdl_android/src/main/java/com/smartdevicelink/SdlConnection/SdlSession2.java b/android/sdl_android/src/main/java/com/smartdevicelink/SdlConnection/SdlSession2.java index cbd45c49a..b9b9a5e40 100644 --- a/android/sdl_android/src/main/java/com/smartdevicelink/SdlConnection/SdlSession2.java +++ b/android/sdl_android/src/main/java/com/smartdevicelink/SdlConnection/SdlSession2.java @@ -254,8 +254,10 @@ public class SdlSession2 extends SdlSession implements ISdlProtocol{ sessionID, version, correlationID, rejectedParams); if(serviceListeners != null && serviceListeners.containsKey(sessionType)){ CopyOnWriteArrayList<ISdlServiceListener> listeners = serviceListeners.get(sessionType); - for(ISdlServiceListener listener:listeners){ - listener.onServiceError(this, sessionType, "Start "+ sessionType.toString() +" Service NAKed"); + if(listeners != null) { + for (ISdlServiceListener listener : listeners) { + listener.onServiceError(this, sessionType, "Start " + sessionType.toString() + " Service NAKed"); + } } } } diff --git a/android/sdl_android/src/main/java/com/smartdevicelink/managers/video/VideoStreamManager.java b/android/sdl_android/src/main/java/com/smartdevicelink/managers/video/VideoStreamManager.java index 73065b865..95144865e 100644 --- a/android/sdl_android/src/main/java/com/smartdevicelink/managers/video/VideoStreamManager.java +++ b/android/sdl_android/src/main/java/com/smartdevicelink/managers/video/VideoStreamManager.java @@ -361,14 +361,15 @@ public class VideoStreamManager extends BaseVideoStreamManager { remoteDisplay = null; parameters = null; virtualDisplayEncoder = null; - if(internalInterface!=null){ + if (internalInterface != null) { internalInterface.stopVideoService(); + // Remove listeners + internalInterface.removeServiceListener(SessionType.NAV, serviceListener); + internalInterface.removeOnRPCNotificationListener(FunctionID.ON_TOUCH_EVENT, touchListener); + internalInterface.removeOnRPCNotificationListener(FunctionID.ON_HMI_STATUS, hmiListener); } - // Remove listeners - internalInterface.removeServiceListener(SessionType.NAV, serviceListener); - internalInterface.removeOnRPCNotificationListener(FunctionID.ON_TOUCH_EVENT, touchListener); - internalInterface.removeOnRPCNotificationListener(FunctionID.ON_HMI_STATUS, hmiListener); + stateMachine.transitionToState(StreamingStateMachine.NONE); super.dispose(); diff --git a/android/sdl_android/src/main/java/com/smartdevicelink/protocol/AbstractProtocol.java b/android/sdl_android/src/main/java/com/smartdevicelink/protocol/AbstractProtocol.java index 00becb062..6b4a2b467 100644 --- a/android/sdl_android/src/main/java/com/smartdevicelink/protocol/AbstractProtocol.java +++ b/android/sdl_android/src/main/java/com/smartdevicelink/protocol/AbstractProtocol.java @@ -1,34 +1,34 @@ -/* - * Copyright (c) 2017 - 2019, SmartDeviceLink Consortium, Inc. - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are met: - * - * Redistributions of source code must retain the above copyright notice, this - * list of conditions and the following disclaimer. - * - * Redistributions in binary form must reproduce the above copyright notice, - * this list of conditions and the following - * disclaimer in the documentation and/or other materials provided with the - * distribution. - * - * Neither the name of the SmartDeviceLink Consortium, Inc. nor the names of its - * contributors may be used to endorse or promote products derived from this - * software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" - * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE - * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR - * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF - * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS - * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN - * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) - * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE - * POSSIBILITY OF SUCH DAMAGE. - */ +/*
+ * Copyright (c) 2017 - 2019, SmartDeviceLink Consortium, Inc.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ *
+ * Redistributions of source code must retain the above copyright notice, this
+ * list of conditions and the following disclaimer.
+ *
+ * Redistributions in binary form must reproduce the above copyright notice,
+ * this list of conditions and the following
+ * disclaimer in the documentation and/or other materials provided with the
+ * distribution.
+ *
+ * Neither the name of the SmartDeviceLink Consortium, Inc. nor the names of its
+ * contributors may be used to endorse or promote products derived from this
+ * software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
+ * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ */
package com.smartdevicelink.protocol;
@@ -127,15 +127,17 @@ public abstract class AbstractProtocol { protected void handlePacketToSend(SdlPacket header) {
//FIXME SdlTrace.logProtocolEvent(InterfaceActivityDirection.Transmit, header, data,
// offset, length, SDL_LIB_TRACE_KEY);
- resetOutgoingHeartbeat(SessionType.valueOf((byte)header.getServiceType()), (byte)header.getSessionId());
+ if(header == null){
+ return;
+ }
+
+ resetOutgoingHeartbeat(SessionType.valueOf((byte)header.getServiceType()), (byte)header.getSessionId());
synchronized(_frameLock) {
//byte[] frameHeader = header.constructPacket();
- if(header!=null){
- _protocolListener.onProtocolMessageBytesToSend(header);
- }//TODO else log out error
-
+ _protocolListener.onProtocolMessageBytesToSend(header);
+
}
}
diff --git a/android/sdl_android/src/main/java/com/smartdevicelink/transport/MultiplexBluetoothTransport.java b/android/sdl_android/src/main/java/com/smartdevicelink/transport/MultiplexBluetoothTransport.java index 058fb0d7e..8b96b2beb 100644 --- a/android/sdl_android/src/main/java/com/smartdevicelink/transport/MultiplexBluetoothTransport.java +++ b/android/sdl_android/src/main/java/com/smartdevicelink/transport/MultiplexBluetoothTransport.java @@ -525,7 +525,9 @@ public class MultiplexBluetoothTransport extends MultiplexBaseTransport{ //Looper.loop(); mmSocket.connect(); timeOutHandler.removeCallbacks(socketRunable); - Looper.myLooper().quit(); + if(Looper.myLooper() != null){ + Looper.myLooper().quit(); + } success=true; SdlRouterService.setBluetoothPrefs(1,SHARED_PREFS); break; @@ -554,7 +556,9 @@ public class MultiplexBluetoothTransport extends MultiplexBaseTransport{ //Looper.loop(); mmSocket.connect(); timeOutHandler.removeCallbacks(socketRunable); - Looper.myLooper().quit(); + if(Looper.myLooper() != null){ + Looper.myLooper().quit(); + } success=true; SdlRouterService.setBluetoothPrefs(2,SHARED_PREFS); break; @@ -583,7 +587,9 @@ public class MultiplexBluetoothTransport extends MultiplexBaseTransport{ //Looper.loop(); mmSocket.connect(); timeOutHandler.removeCallbacks(socketRunable); - Looper.myLooper().quit(); + if(Looper.myLooper() != null){ + Looper.myLooper().quit(); + } success=true; tryInsecure = false; SdlRouterService.setBluetoothPrefs(3,SHARED_PREFS); @@ -608,7 +614,9 @@ public class MultiplexBluetoothTransport extends MultiplexBaseTransport{ //Looper.loop(); mmSocket.connect(); timeOutHandler.removeCallbacks(socketRunable); - Looper.myLooper().quit(); + if(Looper.myLooper() != null){ + Looper.myLooper().quit(); + } success=true; SdlRouterService.setBluetoothPrefs(4,SHARED_PREFS); break; diff --git a/android/sdl_android/src/main/java/com/smartdevicelink/transport/RouterServiceValidator.java b/android/sdl_android/src/main/java/com/smartdevicelink/transport/RouterServiceValidator.java index 187732a8e..8a1afb4e4 100644 --- a/android/sdl_android/src/main/java/com/smartdevicelink/transport/RouterServiceValidator.java +++ b/android/sdl_android/src/main/java/com/smartdevicelink/transport/RouterServiceValidator.java @@ -470,16 +470,18 @@ public class RouterServiceValidator { final JSONObject object = new JSONObject(); JSONArray array = new JSONArray(); JSONObject jsonApp; - - for(SdlApp app: apps){ //Format all the apps into a JSON object and add it to the JSON array - try{ - jsonApp = new JSONObject(); - jsonApp.put(JSON_APP_PACKAGE_TAG, app.packageName); - jsonApp.put(JSON_APP_VERSION_TAG, app.versionCode); - array.put(jsonApp); - }catch(JSONException e){ - e.printStackTrace(); - continue; + + if(apps != null) { + for (SdlApp app : apps) { //Format all the apps into a JSON object and add it to the JSON array + try { + jsonApp = new JSONObject(); + jsonApp.put(JSON_APP_PACKAGE_TAG, app.packageName); + jsonApp.put(JSON_APP_VERSION_TAG, app.versionCode); + array.put(jsonApp); + } catch (JSONException e) { + e.printStackTrace(); + continue; + } } } diff --git a/android/sdl_android/src/main/java/com/smartdevicelink/transport/SdlBroadcastReceiver.java b/android/sdl_android/src/main/java/com/smartdevicelink/transport/SdlBroadcastReceiver.java index 94025de30..98c1777a3 100644 --- a/android/sdl_android/src/main/java/com/smartdevicelink/transport/SdlBroadcastReceiver.java +++ b/android/sdl_android/src/main/java/com/smartdevicelink/transport/SdlBroadcastReceiver.java @@ -90,6 +90,10 @@ public abstract class SdlBroadcastReceiver extends BroadcastReceiver{ public void onReceive(Context context, Intent intent) { //Log.i(TAG, "Sdl Receiver Activated"); final String action = intent.getAction(); + if(action == null){ + return; + } + BluetoothDevice device = null; if(action.equalsIgnoreCase(Intent.ACTION_PACKAGE_ADDED) diff --git a/android/sdl_android/src/main/java/com/smartdevicelink/transport/SdlRouterService.java b/android/sdl_android/src/main/java/com/smartdevicelink/transport/SdlRouterService.java index 60ff45206..7779bcd07 100644 --- a/android/sdl_android/src/main/java/com/smartdevicelink/transport/SdlRouterService.java +++ b/android/sdl_android/src/main/java/com/smartdevicelink/transport/SdlRouterService.java @@ -1754,40 +1754,42 @@ public class SdlRouterService extends Service{ master.alert(); } } - //Ensure the associated transport is dealt with - switch (record.getType()){ - case BLUETOOTH: - synchronized(SESSION_LOCK){ - if(bluetoothSessionMap!= null){ - bluetoothSessionMap.clear(); + if(record != null) { + //Ensure the associated transport is dealt with + switch (record.getType()) { + case BLUETOOTH: + synchronized (SESSION_LOCK) { + if (bluetoothSessionMap != null) { + bluetoothSessionMap.clear(); + } } - } - if(!connectAsClient ){ - if(!legacyModeEnabled && !closing){ - initBluetoothSerialService(); + if (!connectAsClient) { + if (!legacyModeEnabled && !closing) { + initBluetoothSerialService(); + } } - } - break; - case USB: - if(usbTransport != null){ - usbTransport = null; - } - synchronized(SESSION_LOCK){ - if(usbSessionMap!= null){ - usbSessionMap.clear(); + break; + case USB: + if (usbTransport != null) { + usbTransport = null; } - } - break; - case TCP: - if(tcpTransport != null){ - tcpTransport = null; - } - synchronized(SESSION_LOCK){ - if(tcpSessionMap!=null){ - tcpSessionMap.clear(); + synchronized (SESSION_LOCK) { + if (usbSessionMap != null) { + usbSessionMap.clear(); + } } - } - break; + break; + case TCP: + if (tcpTransport != null) { + tcpTransport = null; + } + synchronized (SESSION_LOCK) { + if (tcpSessionMap != null) { + tcpSessionMap.clear(); + } + } + break; + } } if(!getConnectedTransports().isEmpty()){ @@ -1926,26 +1928,28 @@ public class SdlRouterService extends Service{ int offset = bundle.getInt(TransportConstants.BYTES_TO_SEND_EXTRA_OFFSET, 0); //If nothing, start at the beginning of the array int count = bundle.getInt(TransportConstants.BYTES_TO_SEND_EXTRA_COUNT, packet.length); //In case there isn't anything just send the whole packet. TransportType transportType = TransportType.valueForString(bundle.getString(TransportConstants.TRANSPORT_TYPE)); - switch ((transportType)){ - case BLUETOOTH: - if(bluetoothTransport !=null && bluetoothTransport.getState() == MultiplexBluetoothTransport.STATE_CONNECTED) { - bluetoothTransport.write(packet, offset, count); - return true; - } - case USB: - if(usbTransport != null && usbTransport.getState() == MultiplexBaseTransport.STATE_CONNECTED) { - usbTransport.write(packet, offset, count); - return true; - } - case TCP: - if(tcpTransport != null && tcpTransport.getState() == MultiplexBaseTransport.STATE_CONNECTED) { - tcpTransport.write(packet, offset, count); - return true; - } + if(transportType != null) { + switch ((transportType)) { + case BLUETOOTH: + if (bluetoothTransport != null && bluetoothTransport.getState() == MultiplexBluetoothTransport.STATE_CONNECTED) { + bluetoothTransport.write(packet, offset, count); + return true; + } + case USB: + if (usbTransport != null && usbTransport.getState() == MultiplexBaseTransport.STATE_CONNECTED) { + usbTransport.write(packet, offset, count); + return true; + } + case TCP: + if (tcpTransport != null && tcpTransport.getState() == MultiplexBaseTransport.STATE_CONNECTED) { + tcpTransport.write(packet, offset, count); + return true; + } default: - if(sendThroughAltTransport(bundle)){ + if (sendThroughAltTransport(bundle)) { return true; } + } } Log.e(TAG, "Can't send data, no transport of specified type connected"); return false; @@ -3133,9 +3137,11 @@ public class SdlRouterService extends Service{ } protected boolean unregisterTransport(int sessionId, @NonNull TransportType transportType){ - if(queues != null && queues.containsValue(transportType)){ + if(queues != null && queues.containsKey(transportType)){ PacketWriteTaskBlockingQueue queue = queues.remove(transportType); - queue.clear(); + if(queue != null){ + queue.clear(); + } } synchronized (TRANSPORT_LOCK){ if(sessionId == -1){ diff --git a/android/sdl_android/src/main/java/com/smartdevicelink/transport/TransportBroker.java b/android/sdl_android/src/main/java/com/smartdevicelink/transport/TransportBroker.java index 10cb518d4..b568527a0 100644 --- a/android/sdl_android/src/main/java/com/smartdevicelink/transport/TransportBroker.java +++ b/android/sdl_android/src/main/java/com/smartdevicelink/transport/TransportBroker.java @@ -266,6 +266,10 @@ public class TransportBroker { break; case TransportConstants.ROUTER_RECEIVED_PACKET: + if(bundle == null){ + DebugTool.logWarning("Received packet message from router service with no bundle"); + return; + } //So the intent has a packet with it. PEFRECT! Let's send it through the library int flags = bundle.getInt(TransportConstants.BYTES_TO_SEND_FLAGS, TransportConstants.BYTES_TO_SEND_FLAG_NONE); @@ -320,6 +324,10 @@ public class TransportBroker { } break; case TransportConstants.HARDWARE_CONNECTION_EVENT: + if(bundle == null){ + DebugTool.logWarning("Received hardware connection message from router service with no bundle"); + return; + } if (bundle.containsKey(TransportConstants.TRANSPORT_DISCONNECTED) || bundle.containsKey(TransportConstants.HARDWARE_DISCONNECTED)) { //We should shut down, so call diff --git a/android/sdl_android/src/main/java/com/smartdevicelink/util/AndroidTools.java b/android/sdl_android/src/main/java/com/smartdevicelink/util/AndroidTools.java index c54c8b4f2..bedc38028 100644 --- a/android/sdl_android/src/main/java/com/smartdevicelink/util/AndroidTools.java +++ b/android/sdl_android/src/main/java/com/smartdevicelink/util/AndroidTools.java @@ -176,6 +176,9 @@ public class AndroidTools { */ public static boolean isUSBCableConnected(Context context) { Intent intent = context.registerReceiver(null, new IntentFilter(Intent.ACTION_BATTERY_CHANGED)); + if (intent == null ) { + return false; + } int plugged = intent.getIntExtra(BatteryManager.EXTRA_PLUGGED, -1); return plugged == BatteryManager.BATTERY_PLUGGED_AC || plugged == BatteryManager.BATTERY_PLUGGED_USB; } diff --git a/base/src/main/java/com/smartdevicelink/managers/file/BaseFileManager.java b/base/src/main/java/com/smartdevicelink/managers/file/BaseFileManager.java index a02cd58db..50b34effa 100644 --- a/base/src/main/java/com/smartdevicelink/managers/file/BaseFileManager.java +++ b/base/src/main/java/com/smartdevicelink/managers/file/BaseFileManager.java @@ -249,7 +249,7 @@ abstract class BaseFileManager extends BaseSubManager { @Override public void onError(int correlationId, Result resultCode, String info) { - if(fileNameMap.get(correlationId) != null){ + if(fileNameMap != null && fileNameMap.get(correlationId) != null){ errors.put(fileNameMap.get(correlationId), buildErrorString(resultCode, info)); }// else no fileName for given correlation ID } diff --git a/base/src/main/java/com/smartdevicelink/managers/lifecycle/RpcConverter.java b/base/src/main/java/com/smartdevicelink/managers/lifecycle/RpcConverter.java index 8b705bb75..c8e234504 100644 --- a/base/src/main/java/com/smartdevicelink/managers/lifecycle/RpcConverter.java +++ b/base/src/main/java/com/smartdevicelink/managers/lifecycle/RpcConverter.java @@ -137,7 +137,7 @@ public class RpcConverter { } } - if(params.containsKey(RPCMessage.KEY_FUNCTION_NAME)){ + if(params != null && params.containsKey(RPCMessage.KEY_FUNCTION_NAME)){ StringBuilder rpcClassName = new StringBuilder(); String functionName = (String)params.get(RPCMessage.KEY_FUNCTION_NAME); if(FunctionID.SHOW_CONSTANT_TBT.toString().equals(functionName)) { diff --git a/base/src/main/java/com/smartdevicelink/managers/permission/BasePermissionManager.java b/base/src/main/java/com/smartdevicelink/managers/permission/BasePermissionManager.java index 3e1ee1486..23b0ab8f7 100644 --- a/base/src/main/java/com/smartdevicelink/managers/permission/BasePermissionManager.java +++ b/base/src/main/java/com/smartdevicelink/managers/permission/BasePermissionManager.java @@ -234,7 +234,7 @@ abstract class BasePermissionManager extends BaseSubManager{ */ private boolean isPermissionParameterAllowed(@NonNull FunctionID rpcName, @NonNull String parameter, Map<FunctionID, PermissionItem> permissionItems, HMILevel hmiLevel){ PermissionItem permissionItem = permissionItems.get(rpcName); - if (!isRPCAllowed(rpcName, permissionItems, hmiLevel) || permissionItem.getParameterPermissions() == null || permissionItem.getParameterPermissions().getAllowed() == null){ + if (permissionItem == null || !isRPCAllowed(rpcName, permissionItems, hmiLevel) || permissionItem.getParameterPermissions() == null || permissionItem.getParameterPermissions().getAllowed() == null){ return false; } else if (permissionItem.getParameterPermissions().getUserDisallowed() != null){ return permissionItem.getParameterPermissions().getAllowed().contains(parameter) && !permissionItem.getParameterPermissions().getUserDisallowed().contains(parameter); diff --git a/base/src/main/java/com/smartdevicelink/managers/screen/BaseTextAndGraphicManager.java b/base/src/main/java/com/smartdevicelink/managers/screen/BaseTextAndGraphicManager.java index 653c3564c..18e235aad 100644 --- a/base/src/main/java/com/smartdevicelink/managers/screen/BaseTextAndGraphicManager.java +++ b/base/src/main/java/com/smartdevicelink/managers/screen/BaseTextAndGraphicManager.java @@ -58,6 +58,7 @@ import com.smartdevicelink.proxy.rpc.enums.TextAlignment; import com.smartdevicelink.proxy.rpc.enums.TextFieldName; import com.smartdevicelink.proxy.rpc.listeners.OnRPCNotificationListener; import com.smartdevicelink.proxy.rpc.listeners.OnRPCResponseListener; +import com.smartdevicelink.util.CompareUtils; import com.smartdevicelink.util.DebugTool; import java.lang.ref.WeakReference; @@ -732,7 +733,8 @@ abstract class BaseTextAndGraphicManager extends BaseSubManager { } else if (currentScreenData.getGraphic() == null && primaryGraphic == null) { return false; } - return currentScreenData != null && (primaryGraphic != null && !currentScreenData.getGraphic().getValue().equalsIgnoreCase(primaryGraphic.getName())); + return currentScreenData != null + && (primaryGraphic != null && !CompareUtils.areStringsEqual(currentScreenData.getGraphic().getValue(), primaryGraphic.getName(), true, true) ); } return false; } @@ -745,7 +747,8 @@ abstract class BaseTextAndGraphicManager extends BaseSubManager { } else if (currentScreenData.getGraphic() == null && secondaryGraphic == null) { return false; } - return currentScreenData != null && (secondaryGraphic != null && !currentScreenData.getGraphic().getValue().equalsIgnoreCase(secondaryGraphic.getName())); + return currentScreenData != null + && (secondaryGraphic != null && !CompareUtils.areStringsEqual(currentScreenData.getGraphic().getValue(), secondaryGraphic.getName(),true,true)); } return false; } diff --git a/base/src/main/java/com/smartdevicelink/protocol/SdlProtocolBase.java b/base/src/main/java/com/smartdevicelink/protocol/SdlProtocolBase.java index 6db167567..0dcea88f8 100644 --- a/base/src/main/java/com/smartdevicelink/protocol/SdlProtocolBase.java +++ b/base/src/main/java/com/smartdevicelink/protocol/SdlProtocolBase.java @@ -171,14 +171,17 @@ public class SdlProtocolBase { * @return the max transfer unit */ public int getMtu(){ - return mtus.get(SessionType.RPC).intValue(); + return Long.valueOf(getMtu(SessionType.RPC)).intValue(); } public long getMtu(SessionType type){ Long mtu = mtus.get(type); - if(mtu == null){ + if (mtu == null) { mtu = mtus.get(SessionType.RPC); } + if (mtu == null) { //If MTU is still null, use the oldest/smallest + mtu = (long) V1_V2_MTU_SIZE; + } return mtu; } @@ -306,13 +309,16 @@ public class SdlProtocolBase { // If this service type has extra information from the RPC StartServiceACK // parse through it to find which transport should be used to start this // specific service type - for(int transportNum : transportPriorityForServiceMap.get(secondaryService)){ - if(transportNum == PRIMARY_TRANSPORT_ID){ - break; // Primary is favored for this service type, break out... - }else if(transportNum == SECONDARY_TRANSPORT_ID){ - // The secondary transport can be used to start this service - activeTransports.put(secondaryService, transportRecord); - break; + List<Integer> transportNumList = transportPriorityForServiceMap.get(secondaryService); + if (transportNumList != null){ + for (int transportNum : transportNumList) { + if (transportNum == PRIMARY_TRANSPORT_ID) { + break; // Primary is favored for this service type, break out... + } else if (transportNum == SECONDARY_TRANSPORT_ID) { + // The secondary transport can be used to start this service + activeTransports.put(secondaryService, transportRecord); + break; + } } } } @@ -601,7 +607,7 @@ public class SdlProtocolBase { } synchronized(messageLock) { - if (data.length > getMtu(sessionType)) { + if (data != null && data.length > getMtu(sessionType)) { messageID++; diff --git a/base/src/main/java/com/smartdevicelink/proxy/RPCMessage.java b/base/src/main/java/com/smartdevicelink/proxy/RPCMessage.java index 339dc4e75..ac0d11506 100644 --- a/base/src/main/java/com/smartdevicelink/proxy/RPCMessage.java +++ b/base/src/main/java/com/smartdevicelink/proxy/RPCMessage.java @@ -1,34 +1,34 @@ -/* - * Copyright (c) 2017 - 2019, SmartDeviceLink Consortium, Inc. - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are met: - * - * Redistributions of source code must retain the above copyright notice, this - * list of conditions and the following disclaimer. - * - * Redistributions in binary form must reproduce the above copyright notice, - * this list of conditions and the following - * disclaimer in the documentation and/or other materials provided with the - * distribution. - * - * Neither the name of the SmartDeviceLink Consortium, Inc. nor the names of its - * contributors may be used to endorse or promote products derived from this - * software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" - * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE - * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR - * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF - * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS - * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN - * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) - * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE - * POSSIBILITY OF SUCH DAMAGE. - */ +/*
+ * Copyright (c) 2017 - 2019, SmartDeviceLink Consortium, Inc.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ *
+ * Redistributions of source code must retain the above copyright notice, this
+ * list of conditions and the following disclaimer.
+ *
+ * Redistributions in binary form must reproduce the above copyright notice,
+ * this list of conditions and the following
+ * disclaimer in the documentation and/or other materials provided with the
+ * distribution.
+ *
+ * Neither the name of the SmartDeviceLink Consortium, Inc. nor the names of its
+ * contributors may be used to endorse or promote products derived from this
+ * software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
+ * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ */
package com.smartdevicelink.proxy;
import com.smartdevicelink.protocol.enums.FunctionID;
@@ -74,7 +74,9 @@ public class RPCMessage extends RPCStruct { store = hash;
messageType = getMessageTypeName(hash.keySet());
function = (Hashtable<String, Object>) hash.get(messageType);
- parameters = (Hashtable<String, Object>) function.get(KEY_PARAMETERS);
+ if (function != null) {
+ parameters = (Hashtable<String, Object>) function.get(KEY_PARAMETERS);
+ }
if (hasKey(hash.keySet(), RPCStruct.KEY_BULK_DATA)) {
setBulkData((byte[]) hash.get(RPCStruct.KEY_BULK_DATA));
}
diff --git a/base/src/main/java/com/smartdevicelink/proxy/RPCStruct.java b/base/src/main/java/com/smartdevicelink/proxy/RPCStruct.java index 99af52156..e2b496348 100644 --- a/base/src/main/java/com/smartdevicelink/proxy/RPCStruct.java +++ b/base/src/main/java/com/smartdevicelink/proxy/RPCStruct.java @@ -1,34 +1,34 @@ -/* - * Copyright (c) 2017 - 2019, SmartDeviceLink Consortium, Inc. - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are met: - * - * Redistributions of source code must retain the above copyright notice, this - * list of conditions and the following disclaimer. - * - * Redistributions in binary form must reproduce the above copyright notice, - * this list of conditions and the following - * disclaimer in the documentation and/or other materials provided with the - * distribution. - * - * Neither the name of the SmartDeviceLink Consortium, Inc. nor the names of its - * contributors may be used to endorse or promote products derived from this - * software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" - * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE - * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR - * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF - * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS - * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN - * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) - * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE - * POSSIBILITY OF SUCH DAMAGE. - */ +/*
+ * Copyright (c) 2017 - 2019, SmartDeviceLink Consortium, Inc.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ *
+ * Redistributions of source code must retain the above copyright notice, this
+ * list of conditions and the following disclaimer.
+ *
+ * Redistributions in binary form must reproduce the above copyright notice,
+ * this list of conditions and the following
+ * disclaimer in the documentation and/or other materials provided with the
+ * distribution.
+ *
+ * Neither the name of the SmartDeviceLink Consortium, Inc. nor the names of its
+ * contributors may be used to endorse or promote products derived from this
+ * software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
+ * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ */
package com.smartdevicelink.proxy;
import com.smartdevicelink.marshal.JsonRPCMarshaller;
@@ -108,8 +108,13 @@ public class RPCStruct { if (protocolVersion > 1) {
String messageType = getMessageTypeName(store.keySet());
Hashtable<String, Object> function = (Hashtable<String, Object>) store.get(messageType);
- Hashtable<String, Object> parameters = (Hashtable<String, Object>) function.get(RPCMessage.KEY_PARAMETERS);
- return JsonRPCMarshaller.serializeHashtable(parameters);
+ if(function != null){
+ Hashtable<String, Object> parameters = (Hashtable<String, Object>) function.get(RPCMessage.KEY_PARAMETERS);
+ return JsonRPCMarshaller.serializeHashtable(parameters);
+ }else{
+ return null;
+ }
+
} else return JsonRPCMarshaller.serializeHashtable(store);
}
@@ -133,7 +138,11 @@ public class RPCStruct { //retrieved from the store object.
String messageType = getMessageTypeName(store.keySet());
Hashtable<String, Object> function = (Hashtable<String, Object>) store.get(messageType);
- parameters = (Hashtable<String, Object>) function.get(RPCMessage.KEY_PARAMETERS);
+ if(function != null){
+ parameters = (Hashtable<String, Object>) function.get(RPCMessage.KEY_PARAMETERS);
+ }else {
+ parameters = null;
+ }
} else {
//If this is just an RPC struct the store itself should be used
parameters = store;
diff --git a/baseAndroid/src/main/java/com/smartdevicelink/util/CompareUtils.java b/baseAndroid/src/main/java/com/smartdevicelink/util/CompareUtils.java new file mode 100644 index 000000000..141b6ed35 --- /dev/null +++ b/baseAndroid/src/main/java/com/smartdevicelink/util/CompareUtils.java @@ -0,0 +1,23 @@ +package com.smartdevicelink.util; + +public class CompareUtils { + + public static boolean areStringsEqual(String string1, String string2, boolean ignoreCase, boolean nullIsEqual){ + + if (string1 == null) { + if (string2 == null) { + return nullIsEqual; + } else { + return false; + } + } else { + //At least String 1 is not null, use it for the remaining checks + if (ignoreCase) { + return string1.equalsIgnoreCase(string2); + } else { + return string1.equals(string2); + } + } + } + +} |