From d4a82e4c8444116f01ca72926d449991d3ea3bbb Mon Sep 17 00:00:00 2001 From: Joey Grover Date: Tue, 24 Sep 2019 11:31:10 -0400 Subject: [PATCH 1/9] Fix potential NPEs --- .../test/util/CompareUtilsTest.java | 47 ++++++++ .../SdlConnection/SdlSession2.java | 6 +- .../managers/video/VideoStreamManager.java | 11 +- .../protocol/AbstractProtocol.java | 74 +++++++------ .../MultiplexBluetoothTransport.java | 16 ++- .../transport/RouterServiceValidator.java | 22 ++-- .../transport/SdlBroadcastReceiver.java | 4 + .../transport/SdlRouterService.java | 104 +++++++++--------- .../transport/TransportBroker.java | 8 ++ .../smartdevicelink/util/AndroidTools.java | 3 + .../managers/file/BaseFileManager.java | 2 +- .../managers/lifecycle/RpcConverter.java | 2 +- .../permission/BasePermissionManager.java | 2 +- .../screen/BaseTextAndGraphicManager.java | 7 +- .../protocol/SdlProtocolBase.java | 26 +++-- .../com/smartdevicelink/proxy/RPCMessage.java | 66 +++++------ .../com/smartdevicelink/proxy/RPCStruct.java | 77 +++++++------ .../smartdevicelink/util/CompareUtils.java | 23 ++++ 18 files changed, 313 insertions(+), 187 deletions(-) create mode 100644 android/sdl_android/src/androidTest/java/com/smartdevicelink/test/util/CompareUtilsTest.java create mode 100644 baseAndroid/src/main/java/com/smartdevicelink/util/CompareUtils.java 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 0000000000..5edd95ab59 --- /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 cbd45c49a3..b9b9a5e407 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 void onProtocolSessionNACKed(SessionType sessionType, byte sessionID, byt sessionID, version, correlationID, rejectedParams); if(serviceListeners != null && serviceListeners.containsKey(sessionType)){ CopyOnWriteArrayList 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 73065b865e..95144865e7 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 void dispose(){ 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 00becb0624..6b4a2b4675 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 @@ private synchronized void resetIncomingHeartbeat(SessionType sessionType, byte s 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 058fb0d7eb..8b96b2beba 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 void run() { //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 void run() { //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 void run() { //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 void run() { //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 187732a8e9..8a1afb4e47 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 @@ else if(getSecurityLevel(context) == MultiplexTransportConfig.FLAG_MULTI_SECURIT 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 94025de30a..98c1777a34 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 int getRouterServiceVersion(){ 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 60ff45206d..7779bcd078 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 void onTransportDisconnected(TransportRecord record){ 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 boolean writeBytesToTransport(Bundle bundle){ 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 @@ protected List getTransportsForSession(int sessionId){ } 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 10cb518d43..b568527a05 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 void handleMessage(Message msg) { 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 void handleMessage(Message msg) { } 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 c54c8b4f2a..bedc380286 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 static void sendExplicitBroadcast(Context context, Intent intent, List rpcHashTable } } - 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 3e1ee14860..23b0ab8f7d 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 @@ public boolean isRPCAllowed(@NonNull FunctionID rpcName){ */ private boolean isPermissionParameterAllowed(@NonNull FunctionID rpcName, @NonNull String parameter, Map 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 653c3564cf..18e235aad1 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.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 @@ private boolean shouldUpdatePrimaryImage() { } 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 @@ private boolean shouldUpdateSecondaryImage() { } 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 6db1675678..0dcea88f82 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 void start(){ * @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 @@ private void handleSecondaryTransportRegistration(TransportRecord transportRecor // 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 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 @@ else if (protocolMsg.getBulkData() != null) { } 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 339dc4e75d..ac0d115060 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 RPCMessage(Hashtable hash) { store = hash; messageType = getMessageTypeName(hash.keySet()); function = (Hashtable) hash.get(messageType); - parameters = (Hashtable) function.get(KEY_PARAMETERS); + if (function != null) { + parameters = (Hashtable) 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 99af52156e..e2b496348d 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 JSONObject serializeJSON(byte protocolVersion) throws JSONException { if (protocolVersion > 1) { String messageType = getMessageTypeName(store.keySet()); Hashtable function = (Hashtable) store.get(messageType); - Hashtable parameters = (Hashtable) function.get(RPCMessage.KEY_PARAMETERS); - return JsonRPCMarshaller.serializeHashtable(parameters); + if(function != null){ + Hashtable parameters = (Hashtable) function.get(RPCMessage.KEY_PARAMETERS); + return JsonRPCMarshaller.serializeHashtable(parameters); + }else{ + return null; + } + } else return JsonRPCMarshaller.serializeHashtable(store); } @@ -133,7 +138,11 @@ public void format(Version rpcVersion, boolean formatParams){ //retrieved from the store object. String messageType = getMessageTypeName(store.keySet()); Hashtable function = (Hashtable) store.get(messageType); - parameters = (Hashtable) function.get(RPCMessage.KEY_PARAMETERS); + if(function != null){ + parameters = (Hashtable) 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 0000000000..141b6ed356 --- /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); + } + } + } + +} From 0fd15bcbd5f980f8aecc1c11ceb3ded8725b6d8b Mon Sep 17 00:00:00 2001 From: Joey Grover Date: Tue, 24 Sep 2019 11:31:35 -0400 Subject: [PATCH 2/9] Remove redundant namespace in lockscreen xml --- .../src/main/res/layout/activity_sdllock_screen.xml | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/android/sdl_android/src/main/res/layout/activity_sdllock_screen.xml b/android/sdl_android/src/main/res/layout/activity_sdllock_screen.xml index dd2c2a6bb3..43b5e68406 100644 --- a/android/sdl_android/src/main/res/layout/activity_sdllock_screen.xml +++ b/android/sdl_android/src/main/res/layout/activity_sdllock_screen.xml @@ -4,12 +4,12 @@ android:layout_height="fill_parent" android:background="#2c3d4d"> - + Date: Tue, 24 Sep 2019 11:35:40 -0400 Subject: [PATCH 3/9] Fix issues with android versioned API calls --- .../streaming/video/SdlRemoteDisplay.java | 5 +++- .../transport/TransportBroker.java | 2 +- .../util/MediaStreamingStatus.java | 24 +++++++++---------- .../com/smartdevicelink/util/SdlAppInfo.java | 5 +++- .../smartdevicelink/util/ServiceFinder.java | 5 +++- .../com/smartdevicelink/util/FileUtls.java | 4 ++++ 6 files changed, 29 insertions(+), 16 deletions(-) diff --git a/android/sdl_android/src/main/java/com/smartdevicelink/streaming/video/SdlRemoteDisplay.java b/android/sdl_android/src/main/java/com/smartdevicelink/streaming/video/SdlRemoteDisplay.java index a35b4790a8..c720cd22ca 100644 --- a/android/sdl_android/src/main/java/com/smartdevicelink/streaming/video/SdlRemoteDisplay.java +++ b/android/sdl_android/src/main/java/com/smartdevicelink/streaming/video/SdlRemoteDisplay.java @@ -35,6 +35,7 @@ import android.annotation.TargetApi; import android.app.Presentation; import android.content.Context; +import android.os.Build; import android.os.Bundle; import android.os.Handler; import android.os.Looper; @@ -80,7 +81,9 @@ protected void onCreate(Bundle savedInstanceState) { startRefreshTask(); - w.setType(WindowManager.LayoutParams.TYPE_PRIVATE_PRESENTATION); + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) { + w.setType(WindowManager.LayoutParams.TYPE_PRIVATE_PRESENTATION); + } } protected void startRefreshTask() { 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 b568527a05..710e9d610e 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 @@ -145,7 +145,7 @@ protected synchronized boolean sendMessageToRouterService(Message message, int r } catch (RemoteException e) { e.printStackTrace(); //Let's check to see if we should retry - if (e instanceof TransactionTooLargeException + if ((Build.VERSION.SDK_INT >= Build.VERSION_CODES.ICE_CREAM_SANDWICH_MR1 && e instanceof TransactionTooLargeException ) || (retryCount < 5 && routerServiceMessenger.getBinder().isBinderAlive() && routerServiceMessenger.getBinder().pingBinder())) { //We probably just failed on a small transaction =\ try { Thread.sleep(100); diff --git a/android/sdl_android/src/main/java/com/smartdevicelink/util/MediaStreamingStatus.java b/android/sdl_android/src/main/java/com/smartdevicelink/util/MediaStreamingStatus.java index 143b6c6460..be55e11029 100644 --- a/android/sdl_android/src/main/java/com/smartdevicelink/util/MediaStreamingStatus.java +++ b/android/sdl_android/src/main/java/com/smartdevicelink/util/MediaStreamingStatus.java @@ -125,16 +125,8 @@ public synchronized boolean isAudioOutputAvailable() { return false; } - if (android.os.Build.VERSION.SDK_INT >= Build.VERSION_CODES.CUPCAKE - && android.os.Build.VERSION.SDK_INT < Build.VERSION_CODES.M) { - - return audioManager.isBluetoothA2dpOn(); - } - - //If an acceptable audio device hasn't been found or the API level is too low, then only a - //value of false can be returned as there is not enough information to determine if an audio - //device is available. - return false; + //This means the SDK version is < M, and our min is 8 so this API is always available + return audioManager.isBluetoothA2dpOn(); } /** @@ -203,7 +195,11 @@ boolean isUsbActuallyConnected(){ private void setupBluetoothBroadcastReceiver(){ String[] actions = new String[4]; - actions[0] = BluetoothAdapter.ACTION_CONNECTION_STATE_CHANGED; + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) { + actions[0] = BluetoothAdapter.ACTION_CONNECTION_STATE_CHANGED; + }else{ + actions[0] = "android.bluetooth.adapter.action.CONNECTION_STATE_CHANGED"; + } actions[1] = BluetoothAdapter.ACTION_STATE_CHANGED; actions[2] = BluetoothDevice.ACTION_ACL_DISCONNECTED; actions[3] = BluetoothDevice.ACTION_ACL_DISCONNECT_REQUESTED; @@ -213,7 +209,11 @@ private void setupBluetoothBroadcastReceiver(){ private void setupHeadsetBroadcastReceiver(){ String[] actions = new String[1]; - actions[0] = AudioManager.ACTION_HEADSET_PLUG; + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { + actions[0] = AudioManager.ACTION_HEADSET_PLUG; + }else{ + actions[0] = "android.intent.action.HEADSET_PLUG"; + } listenForIntents(actions); } diff --git a/android/sdl_android/src/main/java/com/smartdevicelink/util/SdlAppInfo.java b/android/sdl_android/src/main/java/com/smartdevicelink/util/SdlAppInfo.java index bdc588b1bb..8172811c40 100644 --- a/android/sdl_android/src/main/java/com/smartdevicelink/util/SdlAppInfo.java +++ b/android/sdl_android/src/main/java/com/smartdevicelink/util/SdlAppInfo.java @@ -35,6 +35,7 @@ import android.content.ComponentName; import android.content.pm.PackageInfo; import android.content.pm.ResolveInfo; +import android.os.Build; import android.os.Bundle; import android.util.Log; @@ -80,11 +81,13 @@ public SdlAppInfo(ResolveInfo resolveInfo, PackageInfo packageInfo){ } } - if(packageInfo != null){ + if(packageInfo != null && Build.VERSION.SDK_INT >= Build.VERSION_CODES.GINGERBREAD){ this.lastUpdateTime = packageInfo.lastUpdateTime; if(this.lastUpdateTime <= 0){ this.lastUpdateTime = packageInfo.firstInstallTime; } + }else{ + this.lastUpdateTime = 0; } } diff --git a/android/sdl_android/src/main/java/com/smartdevicelink/util/ServiceFinder.java b/android/sdl_android/src/main/java/com/smartdevicelink/util/ServiceFinder.java index 4e93f9a52a..6f1740878e 100644 --- a/android/sdl_android/src/main/java/com/smartdevicelink/util/ServiceFinder.java +++ b/android/sdl_android/src/main/java/com/smartdevicelink/util/ServiceFinder.java @@ -37,6 +37,7 @@ import android.content.Intent; import android.content.IntentFilter; import android.content.pm.ResolveInfo; +import android.os.Build; import android.os.Handler; import android.os.Looper; import android.util.Log; @@ -163,7 +164,9 @@ private static Intent createQueryIntent(String receiverLocation) { Intent intent = new Intent(); intent.setAction(SdlRouterService.REGISTER_WITH_ROUTER_ACTION); intent.putExtra(SEND_PACKET_TO_APP_LOCATION_EXTRA_NAME, receiverLocation); - intent.setFlags(Intent.FLAG_RECEIVER_FOREGROUND); + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) { + intent.setFlags(Intent.FLAG_RECEIVER_FOREGROUND); + } return intent; } diff --git a/base/src/main/java/com/smartdevicelink/util/FileUtls.java b/base/src/main/java/com/smartdevicelink/util/FileUtls.java index b422cbbb46..17806a8d20 100644 --- a/base/src/main/java/com/smartdevicelink/util/FileUtls.java +++ b/base/src/main/java/com/smartdevicelink/util/FileUtls.java @@ -31,7 +31,9 @@ */ package com.smartdevicelink.util; +import android.os.Build; import android.support.annotation.NonNull; +import android.support.annotation.RequiresApi; import java.io.ByteArrayOutputStream; import java.io.File; @@ -45,10 +47,12 @@ public class FileUtls { + @RequiresApi(api = Build.VERSION_CODES.O) public static byte[] getFileData(String file){ return getFileData(file,null); } + @RequiresApi(api = Build.VERSION_CODES.O) public static byte[] getFileData(String filePath, String fileName){ if(filePath != null && filePath.length() > 0) { File file; From 9c684b0ef84669d4077757363869d2548b502699 Mon Sep 17 00:00:00 2001 From: Joey Grover Date: Tue, 24 Sep 2019 11:37:44 -0400 Subject: [PATCH 4/9] Optimized string usage --- .../com/smartdevicelink/trace/SdlTrace.java | 94 +++++++++---------- .../MultiplexBluetoothTransport.java | 2 +- .../transport/MultiplexTcpTransport.java | 3 +- .../transport/TCPTransport.java | 69 +++++++------- .../utl/ByteAraryMessageAssembler.java | 2 +- .../smartdevicelink/protocol/SdlPacket.java | 16 ++-- .../proxy/rpc/OnKeyboardInput.java | 65 +++++++------ .../smartdevicelink/trace/OpenRPCMessage.java | 64 ++++++------- .../com/smartdevicelink/util/DebugTool.java | 72 +++++++------- .../smartdevicelink/util/HttpRequestTask.java | 2 +- .../smartdevicelink/util/NativeLogTool.java | 75 ++++++++------- 11 files changed, 232 insertions(+), 232 deletions(-) diff --git a/android/sdl_android/src/main/java/com/smartdevicelink/trace/SdlTrace.java b/android/sdl_android/src/main/java/com/smartdevicelink/trace/SdlTrace.java index 70ee2b5474..531f02831a 100644 --- a/android/sdl_android/src/main/java/com/smartdevicelink/trace/SdlTrace.java +++ b/android/sdl_android/src/main/java/com/smartdevicelink/trace/SdlTrace.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.trace; import android.annotation.SuppressLint; @@ -338,7 +338,7 @@ else if (frameData == FrameDataControlFrameType.EndSession.getValue()) } else if (hdr.getFrameType() == FrameType.First ) { int totalSize = BitConverter.intFromByteArray(hdr.getPayload(), 0); int numFrames = BitConverter.intFromByteArray(hdr.getPayload(), 4); - sb.append("" + totalSize + "" + numFrames + ""); + sb.append("").append(totalSize).append("").append(numFrames).append(""); } else if (hdr.getFrameType() == FrameType.Single ) { sb.append(""); } @@ -355,8 +355,8 @@ public static String getBTDeviceInfo(BluetoothDevice btDevice) { sb.append(""); sb.append(SdlTrace.B64EncodeForXML(btdn)); sb.append(""); - sb.append("" + btDevice.getAddress() + ""); - sb.append("" + btDevice.getBondState() + ""); + sb.append("").append(btDevice.getAddress()).append(""); + sb.append("").append(btDevice.getBondState()).append(""); sb.append(""); return sb.toString(); } // end-method @@ -452,17 +452,17 @@ public static String getLogHeader(String dumpReason, int seqNo) { write.append(""); StringBuilder infoBlock = new StringBuilder(); String hostInfo = Build.BRAND + Sep + Build.MANUFACTURER + Sep + Build.MODEL + "(" + Build.HOST + ")"; - infoBlock.append("" + SdlTrace.B64EncodeForXML(hostInfo) + ""); + infoBlock.append("").append(SdlTrace.B64EncodeForXML(hostInfo)).append(""); String osv = Build.VERSION.RELEASE + " (" + Build.VERSION.CODENAME + ")"; - infoBlock.append("" + SdlTrace.B64EncodeForXML(osv) + ""); + infoBlock.append("").append(SdlTrace.B64EncodeForXML(osv)).append(""); infoBlock.append(TraceDeviceInfo.getTelephonyHeader()); long heapSize = Debug.getNativeHeapFreeSize() / 1024; long heapAllocated = Debug.getNativeHeapAllocatedSize() / 1024; - infoBlock.append("" + heapSize + "KB" + heapAllocated + "KB"); - infoBlock.append("" + Runtime.getRuntime().availableProcessors() + ""); - infoBlock.append("" + Process.myPid() + ""); - infoBlock.append("" + Thread.currentThread().getId() + ""); + infoBlock.append("").append(heapSize).append("KB").append(heapAllocated).append("KB"); + infoBlock.append("").append(Runtime.getRuntime().availableProcessors()).append(""); + infoBlock.append("").append(Process.myPid()).append(""); + infoBlock.append("").append(Thread.currentThread().getId()).append(""); // String dateStamp = (String) // DateFormat.format("yy-MM-dd hh:mm:ss SSS", new Timestamp(baseTics)); @@ -470,7 +470,7 @@ public static String getLogHeader(String dumpReason, int seqNo) { String GMTtime = stamp.toGMTString().substring(0, 19); long fracSec = stamp.getNanos() / 1000000; // divide by a million String fracSecStr = String.format("%03d", fracSec); - infoBlock.append("" + GMTtime + "." + fracSecStr + ""); + infoBlock.append("").append(GMTtime).append(".").append(fracSecStr).append(""); infoBlock.append(TraceDeviceInfo.getLogHeaderBluetoothPairs()); infoBlock.append(getSmartDeviceLinkTraceRoot(dumpReason, seqNo)); @@ -486,12 +486,12 @@ private static String getSmartDeviceLinkTraceRoot(String dumpReason, int seqNo) + "" + "" + dumpReason + ""); - write.append("" + DiagLevel.getLevel(Mod.tran) + ""); - write.append("" + DiagLevel.getLevel(Mod.proto) + ""); - write.append("" + DiagLevel.getLevel(Mod.mar) + ""); - write.append("" + DiagLevel.getLevel(Mod.rpc) + ""); - write.append("" + DiagLevel.getLevel(Mod.proxy) + ""); - write.append("" + DiagLevel.getLevel(Mod.app) + ""); + write.append("").append(DiagLevel.getLevel(Mod.tran)).append(""); + write.append("").append(DiagLevel.getLevel(Mod.proto)).append(""); + write.append("").append(DiagLevel.getLevel(Mod.mar)).append(""); + write.append("").append(DiagLevel.getLevel(Mod.rpc)).append(""); + write.append("").append(DiagLevel.getLevel(Mod.proxy)).append(""); + write.append("").append(DiagLevel.getLevel(Mod.app)).append(""); write.append(""); write.append(""); 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 8b96b2beba..fbd284faac 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 @@ -454,7 +454,7 @@ public synchronized void cancel() { } } catch (IOException e) { - Log.e(TAG, mState + " Socket Type " + mSocketType + " close() of server failed "+ e.getStackTrace()); + Log.e(TAG, mState + " Socket Type " + mSocketType + " close() of server failed "+ Arrays.toString(e.getStackTrace())); } } } diff --git a/android/sdl_android/src/main/java/com/smartdevicelink/transport/MultiplexTcpTransport.java b/android/sdl_android/src/main/java/com/smartdevicelink/transport/MultiplexTcpTransport.java index 63766f0b16..0fa211bd96 100644 --- a/android/sdl_android/src/main/java/com/smartdevicelink/transport/MultiplexTcpTransport.java +++ b/android/sdl_android/src/main/java/com/smartdevicelink/transport/MultiplexTcpTransport.java @@ -47,6 +47,7 @@ import java.io.OutputStream; import java.net.InetSocketAddress; import java.net.Socket; +import java.util.Locale; import java.util.concurrent.BlockingQueue; import java.util.concurrent.LinkedBlockingQueue; @@ -237,7 +238,7 @@ private boolean connect() { }else{ if(autoReconnect){ remainingRetry--; - logInfo(String.format("TCPTransport.connect: Socket not connected. AutoReconnect is ON. retryCount is: %d. Waiting for reconnect delay: %d" + logInfo(String.format(Locale.US,"TCPTransport.connect: Socket not connected. AutoReconnect is ON. retryCount is: %d. Waiting for reconnect delay: %d" , remainingRetry, RECONNECT_DELAY)); waitFor(RECONNECT_DELAY); } else { diff --git a/android/sdl_android/src/main/java/com/smartdevicelink/transport/TCPTransport.java b/android/sdl_android/src/main/java/com/smartdevicelink/transport/TCPTransport.java index 4e9f4ffbaf..4ae010a8ce 100644 --- a/android/sdl_android/src/main/java/com/smartdevicelink/transport/TCPTransport.java +++ b/android/sdl_android/src/main/java/com/smartdevicelink/transport/TCPTransport.java @@ -1,36 +1,37 @@ -/* - * 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.transport; +import android.annotation.SuppressLint; import android.annotation.TargetApi; import android.os.Build; import android.os.NetworkOnMainThreadException; @@ -136,11 +137,10 @@ public TCPTransport(TCPTransportConfig tcpTransportConfig, ITransportListener tr /** * Performs actual work of sending array of bytes over the transport - * @param msgBytes Bytes to send - * @param offset Offset in the bytes array to send data from - * @param length Number of bytes to send + * @param packet The SdlPacket that should be sent over the transport * @return True if data was sent successfully, False otherwise */ + @SuppressLint("DefaultLocale") @TargetApi(Build.VERSION_CODES.HONEYCOMB) @Override protected boolean sendBytesOverTransport(SdlPacket packet) { @@ -350,6 +350,7 @@ public void halt() { * * @return true if connection established and false otherwise */ + @SuppressLint("DefaultLocale") private boolean connect() { boolean bConnected; int remainingRetry = RECONNECT_RETRY_COUNT; diff --git a/android/sdl_android/src/main/java/com/smartdevicelink/transport/utl/ByteAraryMessageAssembler.java b/android/sdl_android/src/main/java/com/smartdevicelink/transport/utl/ByteAraryMessageAssembler.java index 5747bbe4ea..4f9c5096eb 100644 --- a/android/sdl_android/src/main/java/com/smartdevicelink/transport/utl/ByteAraryMessageAssembler.java +++ b/android/sdl_android/src/main/java/com/smartdevicelink/transport/utl/ByteAraryMessageAssembler.java @@ -40,7 +40,7 @@ import java.io.IOException; public class ByteAraryMessageAssembler { - private static final String TAG = "ByteAraryMessageAssembler"; + private static final String TAG = "ByteAraryMsgAssembler"; ByteArrayOutputStream buffer; boolean isFinished; TransportType transportType; diff --git a/base/src/main/java/com/smartdevicelink/protocol/SdlPacket.java b/base/src/main/java/com/smartdevicelink/protocol/SdlPacket.java index 6c4d89671a..edc860a427 100644 --- a/base/src/main/java/com/smartdevicelink/protocol/SdlPacket.java +++ b/base/src/main/java/com/smartdevicelink/protocol/SdlPacket.java @@ -340,15 +340,15 @@ public static int getEncryptionBit(boolean encryption){ public String toString() { StringBuilder builder = new StringBuilder(); builder.append("***** Sdl Packet ******"); - builder.append( "\nVersion: " +version); - builder.append( "\nEncryption: " +encryption); - builder.append( "\nFrameType: " +frameType); - builder.append( "\nServiceType: " +serviceType); - builder.append( "\nFrameInfo: " +frameInfo); - builder.append( "\nSessionId: " +sessionId); - builder.append( "\nDataSize: " +dataSize); + builder.append("\nVersion: ").append(version); + builder.append("\nEncryption: ").append(encryption); + builder.append("\nFrameType: ").append(frameType); + builder.append("\nServiceType: ").append(serviceType); + builder.append("\nFrameInfo: ").append(frameInfo); + builder.append("\nSessionId: ").append(sessionId); + builder.append("\nDataSize: ").append(dataSize); if(version>1){ - builder.append( "\nMessageId: " +messageId); + builder.append("\nMessageId: ").append(messageId); } builder.append("\n***** Sdl Packet End******"); diff --git a/base/src/main/java/com/smartdevicelink/proxy/rpc/OnKeyboardInput.java b/base/src/main/java/com/smartdevicelink/proxy/rpc/OnKeyboardInput.java index 10078a707c..2fd2b12217 100644 --- a/base/src/main/java/com/smartdevicelink/proxy/rpc/OnKeyboardInput.java +++ b/base/src/main/java/com/smartdevicelink/proxy/rpc/OnKeyboardInput.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.rpc; import android.support.annotation.NonNull; @@ -124,8 +124,7 @@ public String getData() { @Override public String toString(){ - String result = this.getFunctionName() +": " + " data: " + this.getData() + " event:" + this.getEvent().toString(); - return result; + return this.getFunctionName() +": " + " data: " + this.getData() + " event:" + this.getEvent().toString(); } } diff --git a/base/src/main/java/com/smartdevicelink/trace/OpenRPCMessage.java b/base/src/main/java/com/smartdevicelink/trace/OpenRPCMessage.java index 9aebffd486..9b3831dab2 100644 --- a/base/src/main/java/com/smartdevicelink/trace/OpenRPCMessage.java +++ b/base/src/main/java/com/smartdevicelink/trace/OpenRPCMessage.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.trace; import com.smartdevicelink.proxy.RPCMessage; @@ -51,7 +51,7 @@ public OpenRPCMessage(RPCStruct rpcs) { public String msgDump() { StringBuilder pd = new StringBuilder(); - pd.append(this.getFunctionName() + " " + this.getMessageType()); + pd.append(this.getFunctionName()).append(" ").append(this.getMessageType()); msgDump(pd); diff --git a/base/src/main/java/com/smartdevicelink/util/DebugTool.java b/base/src/main/java/com/smartdevicelink/util/DebugTool.java index f683c25af1..a50f1afbca 100644 --- a/base/src/main/java/com/smartdevicelink/util/DebugTool.java +++ b/base/src/main/java/com/smartdevicelink/util/DebugTool.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.util; import android.util.Log; @@ -163,21 +163,21 @@ protected static Boolean logToSiphon(String msg) { protected static String getLine(Throwable ex) { if (ex == null) { return null; } - String toPrint = ex.toString() + " :" + ex.getMessage(); + StringBuilder toPrint = new StringBuilder(ex.toString() + " :" + ex.getMessage()); for (int i=0; i Date: Tue, 24 Sep 2019 11:48:02 -0400 Subject: [PATCH 5/9] Optimize unnessary reference creation --- .../smartdevicelink/transport/RouterServiceValidator.java | 7 +++---- .../com/smartdevicelink/protocol/SdlPacketFactory.java | 5 ++--- .../src/main/java/com/smartdevicelink/proxy/RPCStruct.java | 3 +-- .../com/smartdevicelink/proxy/rpc/DisplayCapabilities.java | 2 +- .../smartdevicelink/proxy/rpc/SoftButtonCapabilities.java | 2 +- base/src/main/java/com/smartdevicelink/util/DebugTool.java | 3 +-- 6 files changed, 9 insertions(+), 13 deletions(-) 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 8a1afb4e47..06729d62a4 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 @@ -263,14 +263,14 @@ protected static long getRefreshRate(){ /** * This method will find which router service is running. Use that info to find out more about that app and service. * It will store the found service for later use and return the package name if found. - * @param context + * @param pm An instance of a package manager. This is no longer used so null can be sent. * @return */ public ComponentName componentNameForServiceRunning(PackageManager pm){ if(context==null){ return null; } - ActivityManager manager = (ActivityManager) context.getSystemService("activity"); + ActivityManager manager = (ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE); //PackageManager pm = context.getPackageManager(); @@ -556,8 +556,7 @@ protected JSONObject stringToJson(String json){ } try { JSONObject object = new JSONObject(json); - JSONObject trustedApps = object.getJSONObject(JSON_RESPONSE_OBJECT_TAG); - return trustedApps; + return object.getJSONObject(JSON_RESPONSE_OBJECT_TAG); } catch (JSONException e) { e.printStackTrace(); diff --git a/base/src/main/java/com/smartdevicelink/protocol/SdlPacketFactory.java b/base/src/main/java/com/smartdevicelink/protocol/SdlPacketFactory.java index 14ecc029dc..306d94c2ca 100644 --- a/base/src/main/java/com/smartdevicelink/protocol/SdlPacketFactory.java +++ b/base/src/main/java/com/smartdevicelink/protocol/SdlPacketFactory.java @@ -44,11 +44,10 @@ public class SdlPacketFactory { int dataSize, int messageId, byte[] payload) { */ public static SdlPacket createStartSession(SessionType serviceType, int messageID, byte version, byte sessionID, boolean encrypted) { - SdlPacket packet = new SdlPacket(version,encrypted,SdlPacket.FRAME_TYPE_CONTROL, + + return new SdlPacket(version,encrypted,SdlPacket.FRAME_TYPE_CONTROL, serviceType.getValue(),SdlPacket.FRAME_INFO_START_SERVICE,sessionID, 0,messageID,null); - - return packet; } public static SdlPacket createHeartbeat(SessionType serviceType, byte sessionID, byte version) { diff --git a/base/src/main/java/com/smartdevicelink/proxy/RPCStruct.java b/base/src/main/java/com/smartdevicelink/proxy/RPCStruct.java index e2b496348d..69c3e2bc06 100644 --- a/base/src/main/java/com/smartdevicelink/proxy/RPCStruct.java +++ b/base/src/main/java/com/smartdevicelink/proxy/RPCStruct.java @@ -325,8 +325,7 @@ protected Object getValueForString(Class tClass, String s){ } if(valueForString != null){ try { - Object value = valueForString.invoke(null, (String) s); - return value; + return valueForString.invoke(null, (String) s); } catch (IllegalAccessException e) { e.printStackTrace(); } catch (InvocationTargetException e) { diff --git a/base/src/main/java/com/smartdevicelink/proxy/rpc/DisplayCapabilities.java b/base/src/main/java/com/smartdevicelink/proxy/rpc/DisplayCapabilities.java index 8f0fc3fb45..e3da7341c7 100644 --- a/base/src/main/java/com/smartdevicelink/proxy/rpc/DisplayCapabilities.java +++ b/base/src/main/java/com/smartdevicelink/proxy/rpc/DisplayCapabilities.java @@ -158,7 +158,7 @@ public void format(Version rpcVersion, boolean formatParams) { if(!store.containsKey(KEY_GRAPHIC_SUPPORTED)){ // At some point this was added to the RPC spec as mandatory but at least in v1.0.0 // it was not included. - store.put(KEY_GRAPHIC_SUPPORTED, new Boolean(false)); + store.put(KEY_GRAPHIC_SUPPORTED, Boolean.FALSE); } } diff --git a/base/src/main/java/com/smartdevicelink/proxy/rpc/SoftButtonCapabilities.java b/base/src/main/java/com/smartdevicelink/proxy/rpc/SoftButtonCapabilities.java index 3ccba951e6..4fff095913 100644 --- a/base/src/main/java/com/smartdevicelink/proxy/rpc/SoftButtonCapabilities.java +++ b/base/src/main/java/com/smartdevicelink/proxy/rpc/SoftButtonCapabilities.java @@ -123,7 +123,7 @@ public void format(Version rpcVersion, boolean formatParams) { if(!store.containsKey(KEY_IMAGE_SUPPORTED)){ // At some point this was added to the RPC spec as mandatory but at least in v1.0.0 // it was not included. - store.put(KEY_IMAGE_SUPPORTED, new Boolean(false)); + store.put(KEY_IMAGE_SUPPORTED, Boolean.FALSE); } } diff --git a/base/src/main/java/com/smartdevicelink/util/DebugTool.java b/base/src/main/java/com/smartdevicelink/util/DebugTool.java index a50f1afbca..ca7633e7fd 100644 --- a/base/src/main/java/com/smartdevicelink/util/DebugTool.java +++ b/base/src/main/java/com/smartdevicelink/util/DebugTool.java @@ -378,8 +378,7 @@ public static Hashtable getRPCHash(SdlPacket packet){ } if (message.getBulkData() != null) hash.put(RPCStruct.KEY_BULK_DATA, message.getBulkData()); } else { - final Hashtable mhash = JsonRPCMarshaller.unmarshall(message.getData()); - hash = mhash; + hash = JsonRPCMarshaller.unmarshall(message.getData()); } return hash; } From d5b3c985fc28d6b1bd59de0f429cf4e1041f8eeb Mon Sep 17 00:00:00 2001 From: Joey Grover Date: Tue, 24 Sep 2019 11:48:17 -0400 Subject: [PATCH 6/9] Fix lint issues --- .../transport/MultiplexBluetoothTransport.java | 18 ++++++++++++++---- .../com/smartdevicelink/util/DebugTool.java | 1 + 2 files changed, 15 insertions(+), 4 deletions(-) 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 fbd284faac..644cda21bc 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 @@ -19,6 +19,7 @@ package com.smartdevicelink.transport; +import android.Manifest; import android.annotation.SuppressLint; import android.bluetooth.BluetoothAdapter; import android.bluetooth.BluetoothDevice; @@ -28,6 +29,7 @@ import android.os.Handler; import android.os.Looper; import android.os.Message; +import android.support.annotation.RequiresPermission; import android.util.Log; import com.smartdevicelink.protocol.SdlPacket; @@ -40,6 +42,7 @@ import java.lang.reflect.Field; import java.lang.reflect.InvocationTargetException; import java.lang.reflect.Method; +import java.util.Arrays; import java.util.UUID; /** @@ -146,6 +149,8 @@ public void setKeepSocketAlive(boolean keepSocketAlive){ /** * Start the chat service. Specifically start AcceptThread to begin a * session in listening (server) mode. Called by the Activity onResume() */ + @SuppressLint("MissingPermission") + @RequiresPermission(Manifest.permission.BLUETOOTH) public synchronized void start() { //Log.d(TAG, "Starting up Bluetooth Server to Listen"); // Cancel any thread attempting to make a connection @@ -202,6 +207,7 @@ public synchronized void connect(BluetoothDevice device) { * @param socket The BluetoothSocket on which the connection was made * @param device The BluetoothDevice that has been connected */ + @RequiresPermission(Manifest.permission.BLUETOOTH) public synchronized void connected(BluetoothSocket socket, BluetoothDevice device) { // Cancel the thread that completed the connection if (mConnectThread != null) { @@ -284,7 +290,7 @@ protected synchronized void stop(int stateToTransitionTo) { /** * Write to the ConnectedThread in an unsynchronized manner * @param out The bytes to write - * @see ConnectedThread#write(byte[]) + * @see ConnectedWriteThread#write(byte[],int,int) */ public void write(byte[] out, int offset, int count) { // Create temporary object @@ -356,7 +362,8 @@ private class AcceptThread extends Thread { final BluetoothServerSocket mmServerSocket; @SuppressLint("NewApi") - public AcceptThread(boolean secure) { + @RequiresPermission(Manifest.permission.BLUETOOTH) + public AcceptThread(boolean secure) { synchronized(THREAD_LOCK){ //Log.d(TAG, "Creating an Accept Thread"); BluetoothServerSocket tmp = null; @@ -379,7 +386,8 @@ public AcceptThread(boolean secure) { //Log.d(TAG, "Accepting Connections on SDP Server Port Number: " + getChannel(mySock) + "\r\n"); } } - + + @RequiresPermission(Manifest.permission.BLUETOOTH) public void run() { synchronized(THREAD_LOCK){ Log.d(TAG, "Socket Type: " + mSocketType + @@ -475,6 +483,7 @@ public ConnectThread(BluetoothDevice device) { } + @RequiresPermission(Manifest.permission.BLUETOOTH_ADMIN) public void attemptCancelDiscovery(){ try{ mAdapter.cancelDiscovery(); @@ -482,7 +491,8 @@ public void attemptCancelDiscovery(){ Log.e(TAG, "Don't have required permision to cancel discovery. Moving on"); } } - + + @RequiresPermission(Manifest.permission.BLUETOOTH_ADMIN) public void run() { setName("ConnectThread"); // Always cancel discovery because it will slow down a connection diff --git a/base/src/main/java/com/smartdevicelink/util/DebugTool.java b/base/src/main/java/com/smartdevicelink/util/DebugTool.java index ca7633e7fd..dbf9185a87 100644 --- a/base/src/main/java/com/smartdevicelink/util/DebugTool.java +++ b/base/src/main/java/com/smartdevicelink/util/DebugTool.java @@ -77,6 +77,7 @@ public static boolean isDebugEnabled() return false; } + @SuppressWarnings("ConstantConditions") private static String prependProxyVersionNumberToString(String string) { if (BuildConfig.VERSION_NAME != null && string != null) { string = BuildConfig.VERSION_NAME + ": " + string; From bff9184e2d57a351a66ac1f715b055d279474eef Mon Sep 17 00:00:00 2001 From: Joey Grover Date: Wed, 25 Sep 2019 13:54:44 -0400 Subject: [PATCH 7/9] Move CompareUtils to base src folder and make link --- .../smartdevicelink/util/CompareUtils.java | 23 ++++++++++++++++++ .../smartdevicelink/util/CompareUtils.java | 24 +------------------ 2 files changed, 24 insertions(+), 23 deletions(-) create mode 100644 base/src/main/java/com/smartdevicelink/util/CompareUtils.java mode change 100644 => 120000 baseAndroid/src/main/java/com/smartdevicelink/util/CompareUtils.java diff --git a/base/src/main/java/com/smartdevicelink/util/CompareUtils.java b/base/src/main/java/com/smartdevicelink/util/CompareUtils.java new file mode 100644 index 0000000000..141b6ed356 --- /dev/null +++ b/base/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); + } + } + } + +} diff --git a/baseAndroid/src/main/java/com/smartdevicelink/util/CompareUtils.java b/baseAndroid/src/main/java/com/smartdevicelink/util/CompareUtils.java deleted file mode 100644 index 141b6ed356..0000000000 --- a/baseAndroid/src/main/java/com/smartdevicelink/util/CompareUtils.java +++ /dev/null @@ -1,23 +0,0 @@ -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); - } - } - } - -} 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 120000 index 0000000000..9d331ba9c4 --- /dev/null +++ b/baseAndroid/src/main/java/com/smartdevicelink/util/CompareUtils.java @@ -0,0 +1 @@ +../../../../../../../base/src/main/java/com/smartdevicelink/util/CompareUtils.java \ No newline at end of file From ade0b9cd8fda5c7494872f3093f193cb95accafe Mon Sep 17 00:00:00 2001 From: Joey Grover Date: Tue, 1 Oct 2019 11:57:40 -0400 Subject: [PATCH 8/9] Remove Android codes from FileUtl; added javadoc --- .../com/smartdevicelink/util/FileUtls.java | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/base/src/main/java/com/smartdevicelink/util/FileUtls.java b/base/src/main/java/com/smartdevicelink/util/FileUtls.java index 17806a8d20..762227f211 100644 --- a/base/src/main/java/com/smartdevicelink/util/FileUtls.java +++ b/base/src/main/java/com/smartdevicelink/util/FileUtls.java @@ -31,9 +31,8 @@ */ package com.smartdevicelink.util; -import android.os.Build; +import android.annotation.SuppressLint; import android.support.annotation.NonNull; -import android.support.annotation.RequiresApi; import java.io.ByteArrayOutputStream; import java.io.File; @@ -46,13 +45,22 @@ public class FileUtls { - - @RequiresApi(api = Build.VERSION_CODES.O) + /** + * When using on Android, this method should only be used for Android Oreo and newer + * @param file the path to the file + * @return a byte array representation of the file if one exists + */ public static byte[] getFileData(String file){ return getFileData(file,null); } - @RequiresApi(api = Build.VERSION_CODES.O) + /** + * When using on Android, this method should only be used for Android Oreo and newer + * @param filePath the path to the file + * @param fileName the name of the file + * @return a byte array representation of the file if one exists + */ + @SuppressLint("NewApi") public static byte[] getFileData(String filePath, String fileName){ if(filePath != null && filePath.length() > 0) { File file; From 31de199f22e8be3c74c2bc867091da6be510993d Mon Sep 17 00:00:00 2001 From: Joey Grover Date: Tue, 1 Oct 2019 13:33:27 -0400 Subject: [PATCH 9/9] Remove suppressLint annotation in FileUtl --- base/src/main/java/com/smartdevicelink/util/FileUtls.java | 2 -- 1 file changed, 2 deletions(-) diff --git a/base/src/main/java/com/smartdevicelink/util/FileUtls.java b/base/src/main/java/com/smartdevicelink/util/FileUtls.java index 762227f211..5f317340bf 100644 --- a/base/src/main/java/com/smartdevicelink/util/FileUtls.java +++ b/base/src/main/java/com/smartdevicelink/util/FileUtls.java @@ -31,7 +31,6 @@ */ package com.smartdevicelink.util; -import android.annotation.SuppressLint; import android.support.annotation.NonNull; import java.io.ByteArrayOutputStream; @@ -60,7 +59,6 @@ public static byte[] getFileData(String file){ * @param fileName the name of the file * @return a byte array representation of the file if one exists */ - @SuppressLint("NewApi") public static byte[] getFileData(String filePath, String fileName){ if(filePath != null && filePath.length() > 0) { File file;