Skip to content

Commit

Permalink
Merge pull request #1179 from smartdevicelink/feature/fix_code_analyz…
Browse files Browse the repository at this point in the history
…er_issues

Fix code analyzer issues
  • Loading branch information
BrettyWhite authored Oct 2, 2019
2 parents cd90df4 + 31de199 commit 2ae92d9
Show file tree
Hide file tree
Showing 38 changed files with 612 additions and 459 deletions.
Original file line number Diff line number Diff line change
@@ -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));

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -254,8 +254,10 @@ public void onProtocolSessionNACKed(SessionType sessionType, byte sessionID, byt
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");
}
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
Original file line number Diff line number Diff line change
@@ -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;


Expand Down Expand Up @@ -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);

}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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() {
Expand Down
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -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("<total>" + totalSize + "</total><numframes>" + numFrames + "</numframes>");
sb.append("<total>").append(totalSize).append("</total><numframes>").append(numFrames).append("</numframes>");
} else if (hdr.getFrameType() == FrameType.Single ) {
sb.append("<single/>");
}
Expand All @@ -355,8 +355,8 @@ public static String getBTDeviceInfo(BluetoothDevice btDevice) {
sb.append("<btn>");
sb.append(SdlTrace.B64EncodeForXML(btdn));
sb.append("</btn>");
sb.append("<bta>" + btDevice.getAddress() + "</bta>");
sb.append("<bts>" + btDevice.getBondState() + "</bts>");
sb.append("<bta>").append(btDevice.getAddress()).append("</bta>");
sb.append("<bts>").append(btDevice.getBondState()).append("</bts>");
sb.append("</btp>");
return sb.toString();
} // end-method
Expand Down Expand Up @@ -452,25 +452,25 @@ public static String getLogHeader(String dumpReason, int seqNo) {
write.append("<info>");
StringBuilder infoBlock = new StringBuilder();
String hostInfo = Build.BRAND + Sep + Build.MANUFACTURER + Sep + Build.MODEL + "(" + Build.HOST + ")";
infoBlock.append("<host>" + SdlTrace.B64EncodeForXML(hostInfo) + "</host>");
infoBlock.append("<host>").append(SdlTrace.B64EncodeForXML(hostInfo)).append("</host>");
String osv = Build.VERSION.RELEASE + " (" + Build.VERSION.CODENAME + ")";
infoBlock.append("<osv>" + SdlTrace.B64EncodeForXML(osv) + "</osv>");
infoBlock.append("<osv>").append(SdlTrace.B64EncodeForXML(osv)).append("</osv>");
infoBlock.append(TraceDeviceInfo.getTelephonyHeader());

long heapSize = Debug.getNativeHeapFreeSize() / 1024;
long heapAllocated = Debug.getNativeHeapAllocatedSize() / 1024;
infoBlock.append("<mem><hf>" + heapSize + "KB</hf><ha>" + heapAllocated + "KB</ha></mem>");
infoBlock.append("<np>" + Runtime.getRuntime().availableProcessors() + "</np>");
infoBlock.append("<pid>" + Process.myPid() + "</pid>");
infoBlock.append("<tid>" + Thread.currentThread().getId() + "</tid>");
infoBlock.append("<mem><hf>").append(heapSize).append("KB</hf><ha>").append(heapAllocated).append("KB</ha></mem>");
infoBlock.append("<np>").append(Runtime.getRuntime().availableProcessors()).append("</np>");
infoBlock.append("<pid>").append(Process.myPid()).append("</pid>");
infoBlock.append("<tid>").append(Thread.currentThread().getId()).append("</tid>");

// String dateStamp = (String)
// DateFormat.format("yy-MM-dd hh:mm:ss SSS", new Timestamp(baseTics));
Timestamp stamp = new Timestamp(SdlTrace.getBaseTics());
String GMTtime = stamp.toGMTString().substring(0, 19);
long fracSec = stamp.getNanos() / 1000000; // divide by a million
String fracSecStr = String.format("%03d", fracSec);
infoBlock.append("<utc>" + GMTtime + "." + fracSecStr + "</utc>");
infoBlock.append("<utc>").append(GMTtime).append(".").append(fracSecStr).append("</utc>");

infoBlock.append(TraceDeviceInfo.getLogHeaderBluetoothPairs());
infoBlock.append(getSmartDeviceLinkTraceRoot(dumpReason, seqNo));
Expand All @@ -486,12 +486,12 @@ private static String getSmartDeviceLinkTraceRoot(String dumpReason, int seqNo)
+ "</sequencenum>" + "<dumpreason>" + dumpReason
+ "</dumpreason><tracelevel>");

write.append("<tran>" + DiagLevel.getLevel(Mod.tran) + "</tran>");
write.append("<proto>" + DiagLevel.getLevel(Mod.proto) + "</proto>");
write.append("<mar>" + DiagLevel.getLevel(Mod.mar) + "</mar>");
write.append("<rpc>" + DiagLevel.getLevel(Mod.rpc) + "</rpc>");
write.append("<proxy>" + DiagLevel.getLevel(Mod.proxy) + "</proxy>");
write.append("<app>" + DiagLevel.getLevel(Mod.app) + "</app>");
write.append("<tran>").append(DiagLevel.getLevel(Mod.tran)).append("</tran>");
write.append("<proto>").append(DiagLevel.getLevel(Mod.proto)).append("</proto>");
write.append("<mar>").append(DiagLevel.getLevel(Mod.mar)).append("</mar>");
write.append("<rpc>").append(DiagLevel.getLevel(Mod.rpc)).append("</rpc>");
write.append("<proxy>").append(DiagLevel.getLevel(Mod.proxy)).append("</proxy>");
write.append("<app>").append(DiagLevel.getLevel(Mod.app)).append("</app>");

write.append("</tracelevel>");
write.append("</SmartDeviceLinktraceroot>");
Expand Down
Loading

0 comments on commit 2ae92d9

Please sign in to comment.