diff options
author | Bilal Alsharifi <bilal.alsharifi@gmail.com> | 2020-09-10 17:21:10 -0400 |
---|---|---|
committer | Bilal Alsharifi <bilal.alsharifi@gmail.com> | 2020-09-10 17:21:10 -0400 |
commit | 2e3f8f94c1828c7f8f4858cde480e24d18d72c6c (patch) | |
tree | e3bd531b9e1e633d4ce96fc661530e9feaec7a79 | |
parent | 288207f3be59817b8a9244c9fc2dae22dc1d32a4 (diff) | |
download | sdl_android-2e3f8f94c1828c7f8f4858cde480e24d18d72c6c.tar.gz |
fix warnings in transport part2
15 files changed, 110 insertions, 111 deletions
diff --git a/android/sdl_android/src/main/java/com/smartdevicelink/transport/MultiplexBaseTransport.java b/android/sdl_android/src/main/java/com/smartdevicelink/transport/MultiplexBaseTransport.java index e1f138978..a8eecd484 100644 --- a/android/sdl_android/src/main/java/com/smartdevicelink/transport/MultiplexBaseTransport.java +++ b/android/sdl_android/src/main/java/com/smartdevicelink/transport/MultiplexBaseTransport.java @@ -124,7 +124,7 @@ public abstract class MultiplexBaseTransport { } protected abstract void stop(int state); - protected void stop(int state, byte error) {}; + protected void stop(int state, byte error) {} public abstract void write(byte[] out, int offset, int count); 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 449774d57..554b37478 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 @@ -63,7 +63,7 @@ public class MultiplexBluetoothTransport extends MultiplexBaseTransport{ // Key names received from the BluetoothSerialServer Handler private static final long MS_TILL_TIMEOUT = 2500; private static final int READ_BUFFER_SIZE = 4096; - private final Object THREAD_LOCK = new Object();; + private final Object THREAD_LOCK = new Object(); protected static final String SHARED_PREFS = "sdl.bluetoothprefs"; @@ -75,7 +75,7 @@ public class MultiplexBluetoothTransport extends MultiplexBaseTransport{ private ConnectedThread mConnectedThread; private ConnectedWriteThread mConnectedWriteThread; Handler timeOutHandler; - Runnable socketRunable; + Runnable socketRunnable; boolean keepSocketAlive = true; /** @@ -310,7 +310,7 @@ public class MultiplexBluetoothTransport extends MultiplexBaseTransport{ private void timerDelayRemoveDialog(final BluetoothSocket sock){ timeOutHandler = new Handler(); - socketRunable = new Runnable() { + socketRunnable = new Runnable() { public void run() { //Log.e(TAG, "BLUETOOTH SOCKET CONNECT TIMEOUT - ATTEMPT TO CLOSE SOCKET"); try { @@ -320,7 +320,7 @@ public class MultiplexBluetoothTransport extends MultiplexBaseTransport{ } } }; - timeOutHandler.postDelayed(socketRunable, MS_TILL_TIMEOUT); + timeOutHandler.postDelayed(socketRunnable, MS_TILL_TIMEOUT); } @@ -332,7 +332,7 @@ public class MultiplexBluetoothTransport extends MultiplexBaseTransport{ */ private class AcceptThread extends Thread { // The local server socket - private String mSocketType; + private final String mSocketType; final BluetoothServerSocket mmServerSocket; @SuppressLint("NewApi") @@ -350,7 +350,7 @@ public class MultiplexBluetoothTransport extends MultiplexBaseTransport{ } catch (IOException e) { //Log.e(TAG, "Socket Type: " + mSocketType + "listen() failed", e); MultiplexBluetoothTransport.this.stop(STATE_ERROR, REASON_SPP_ERROR); - //Let's try to shut down this thead + //Let's try to shut down this thread }catch(SecurityException e2){ //Log.e(TAG, "<LIVIO> Security Exception in Accept Thread - "+e2.toString()); interrupt(); @@ -369,7 +369,7 @@ public class MultiplexBluetoothTransport extends MultiplexBaseTransport{ " BEGIN mAcceptThread" + this); setName("AcceptThread" + mSocketType); - BluetoothSocket socket = null; + BluetoothSocket socket; int listenAttempts = 0; // Listen to the server socket if we're not connected @@ -453,8 +453,8 @@ public class MultiplexBluetoothTransport extends MultiplexBaseTransport{ private final BluetoothDevice mmDevice; public ConnectThread(BluetoothDevice device) { mmDevice = device; - //Log.d(TAG, "Attempting to conenct to " + device.getName()); - //Log.d(TAG, "UUID to conenct to " + SERVER_UUID.toString()); + //Log.d(TAG, "Attempting to connect to " + device.getName()); + //Log.d(TAG, "UUID to connect to " + SERVER_UUID.toString()); } @@ -463,7 +463,7 @@ public class MultiplexBluetoothTransport extends MultiplexBaseTransport{ try{ mAdapter.cancelDiscovery(); }catch(SecurityException e2){ - DebugTool.logError(TAG, "Don't have required permision to cancel discovery. Moving on"); + DebugTool.logError(TAG, "Don't have required permission to cancel discovery. Moving on"); } } @@ -499,13 +499,13 @@ public class MultiplexBluetoothTransport extends MultiplexBaseTransport{ try { Method m = mmDevice.getClass().getMethod("createRfcommSocket", new Class[]{int.class}); //Log.i(TAG,"connecting using createRfcommSocket"); - mmSocket = (BluetoothSocket) m.invoke(mmDevice, Integer.valueOf(1)); + mmSocket = (BluetoothSocket) m.invoke(mmDevice, 1); if (mmSocket != null) { //Looper.prepare(); timerDelayRemoveDialog(mmSocket); //Looper.loop(); mmSocket.connect(); - timeOutHandler.removeCallbacks(socketRunable); + timeOutHandler.removeCallbacks(socketRunnable); if (Looper.myLooper() != null) { Looper.myLooper().quit(); } @@ -533,7 +533,7 @@ public class MultiplexBluetoothTransport extends MultiplexBaseTransport{ timerDelayRemoveDialog(mmSocket); //Looper.loop(); mmSocket.connect(); - timeOutHandler.removeCallbacks(socketRunable); + timeOutHandler.removeCallbacks(socketRunnable); if (Looper.myLooper() != null) { Looper.myLooper().quit(); } @@ -562,7 +562,7 @@ public class MultiplexBluetoothTransport extends MultiplexBaseTransport{ timerDelayRemoveDialog(mmSocket); //Looper.loop(); mmSocket.connect(); - timeOutHandler.removeCallbacks(socketRunable); + timeOutHandler.removeCallbacks(socketRunnable); if (Looper.myLooper() != null) { Looper.myLooper().quit(); } @@ -584,7 +584,7 @@ public class MultiplexBluetoothTransport extends MultiplexBaseTransport{ timerDelayRemoveDialog(mmSocket); //Looper.loop(); mmSocket.connect(); - timeOutHandler.removeCallbacks(socketRunable); + timeOutHandler.removeCallbacks(socketRunnable); if (Looper.myLooper() != null) { Looper.myLooper().quit(); } @@ -701,7 +701,7 @@ public class MultiplexBluetoothTransport extends MultiplexBaseTransport{ private class ConnectedThread extends Thread { private final BluetoothSocket mmSocket; private final InputStream mmInStream; - SdlPsm psm; + final SdlPsm psm; public ConnectedThread(BluetoothSocket socket) { this.psm = new SdlPsm(); //Log.d(TAG, "Creating a Connected - Read Thread"); @@ -791,7 +791,7 @@ public class MultiplexBluetoothTransport extends MultiplexBaseTransport{ Field[] f = bsSocket.getClass().getDeclaredFields(); //int channel = -1; - BluetoothSocket mySocket = null; + BluetoothSocket mySocket; for (Field field : f) { if(field.getName().equals("mSocket")){ field.setAccessible(true); 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 50d6ba051..c640f67ba 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 @@ -70,7 +70,7 @@ public class MultiplexTcpTransport extends MultiplexBaseTransport { private OutputStream mOutputStream = null; private MultiplexTcpTransport.TcpTransportThread mThread = null; private WriterThread writerThread; - private Context mContext; + private final Context mContext; public MultiplexTcpTransport(int port, String ipAddress, boolean autoReconnect, Handler handler, Context context) { @@ -182,7 +182,7 @@ public class MultiplexTcpTransport extends MultiplexBaseTransport { * Internal class that represents separate thread, that does actual work, related to connecting/reading/writing data */ private class TcpTransportThread extends Thread { - SdlPsm psm; + final SdlPsm psm; public TcpTransportThread(){ psm = new SdlPsm(); } @@ -358,7 +358,7 @@ public class MultiplexTcpTransport extends MultiplexBaseTransport { private class WriterThread extends Thread { private boolean isHalted = false; - private boolean mVerbose = false; + private final boolean mVerbose = false; final BlockingQueue<OutPacket> packetQueue = new LinkedBlockingQueue<>(); @Override @@ -433,9 +433,9 @@ public class MultiplexTcpTransport extends MultiplexBaseTransport { } private final class OutPacket{ - byte[] bytes; - int count; - int offset; + final byte[] bytes; + final int count; + final int offset; OutPacket(byte[] bytes, int offset, int count){ this.bytes = bytes; diff --git a/android/sdl_android/src/main/java/com/smartdevicelink/transport/MultiplexTransportConfig.java b/android/sdl_android/src/main/java/com/smartdevicelink/transport/MultiplexTransportConfig.java index 4d0ab0670..e2dd06521 100644 --- a/android/sdl_android/src/main/java/com/smartdevicelink/transport/MultiplexTransportConfig.java +++ b/android/sdl_android/src/main/java/com/smartdevicelink/transport/MultiplexTransportConfig.java @@ -67,8 +67,8 @@ public class MultiplexTransportConfig extends BaseTransportConfig{ */ public static final int FLAG_MULTI_SECURITY_HIGH = 0x30; - Context context; - String appId; + final Context context; + final String appId; ComponentName service; int securityLevel; @@ -143,7 +143,7 @@ public class MultiplexTransportConfig extends BaseTransportConfig{ } /** - * Get the securitly level that will be used to verify a router service before binding + * Get the security level that will be used to verify a router service before binding * @return the set security level * @see #FLAG_MULTI_SECURITY_OFF * @see #FLAG_MULTI_SECURITY_LOW diff --git a/android/sdl_android/src/main/java/com/smartdevicelink/transport/MultiplexUsbTransport.java b/android/sdl_android/src/main/java/com/smartdevicelink/transport/MultiplexUsbTransport.java index 42bbc29a4..e76f2180c 100644 --- a/android/sdl_android/src/main/java/com/smartdevicelink/transport/MultiplexUsbTransport.java +++ b/android/sdl_android/src/main/java/com/smartdevicelink/transport/MultiplexUsbTransport.java @@ -205,7 +205,7 @@ public class MultiplexUsbTransport extends MultiplexBaseTransport{ } private class ReaderThread extends Thread{ - SdlPsm psm; + final SdlPsm psm; final InputStream inputStream; 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 78f78ccb2..a7d9f775a 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 @@ -89,7 +89,7 @@ public class RouterServiceValidator { private static final String JSON_RESPONSE_OBJECT_TAG = "response"; - private static final String JSON_RESONSE_APP_VERSIONS_TAG = "versionBlacklist"; + private static final String JSON_RESPONSE_APP_VERSIONS_TAG = "versionBlacklist"; private static final String JSON_PUT_ARRAY_TAG = "installedApps"; private static final String JSON_APP_PACKAGE_TAG = "packageName"; @@ -112,7 +112,7 @@ public class RouterServiceValidator { * This will flag the validator to check for app version during debugging. * <br><br><b>NOTE: This flag will include a package check as well. */ - public static final int FLAG_DEBUG_VERSION_CHECK = 0x03; //We use 3 becuase version check will be 2, but since a version check implies a package check we do 2+1=3; + public static final int FLAG_DEBUG_VERSION_CHECK = 0x03; //We use 3 because version check will be 2, but since a version check implies a package check we do 2+1=3; public static final int FLAG_DEBUG_INSTALLED_FROM_CHECK = 0x04; public static final int FLAG_DEBUG_USE_TIMESTAMP_CHECK = 0x05; @@ -121,11 +121,10 @@ public class RouterServiceValidator { private int flags = FLAG_DEBUG_NONE; - private Context context= null; + private Context context; private boolean inDebugMode = false; - @SuppressWarnings("unused") private static boolean pendingListRefresh = false; - + private ComponentName service;//This is how we can save different routers over another in a waterfall method if we choose to. private static int securityLevel = -1; @@ -240,7 +239,7 @@ public class RouterServiceValidator { * FindRouterTask: AsyncTask to find the connected RouterService. */ class FindRouterTask extends AsyncTask<Context, Void, ComponentName> { - FindConnectedRouterCallback mCallback; + final FindConnectedRouterCallback mCallback; final Handler mHandler = new Handler(Looper.getMainLooper()); final Integer TIMEOUT_MSEC = 10000; // 10 sec @@ -356,7 +355,6 @@ public class RouterServiceValidator { || (this.inDebugMode && ((this.flags & FLAG_DEBUG_INSTALLED_FROM_CHECK) != FLAG_DEBUG_INSTALLED_FROM_CHECK)); } - @SuppressWarnings("unused") private boolean shouldOverrideTimeCheck(){ return (this.inDebugMode && ((this.flags & FLAG_DEBUG_USE_TIMESTAMP_CHECK) != FLAG_DEBUG_USE_TIMESTAMP_CHECK)); } @@ -402,17 +400,18 @@ public class RouterServiceValidator { ActivityManager manager = (ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE); //PackageManager pm = context.getPackageManager(); - - for (RunningServiceInfo service : manager.getRunningServices(Integer.MAX_VALUE)) { - //Log.d(TAG, service.service.getClassName()); - //We will check to see if it contains this name, should be pretty specific - if ((service.service.getClassName()).toLowerCase(Locale.US).contains(SdlBroadcastReceiver.SDL_ROUTER_SERVICE_CLASS_NAME)){ - //this.service = service.service; //This is great - if(service.started && service.restarting==0){ //If this service has been started and is not crashed - return service.service; //appPackageForComponenetName(service.service,pm); + if (manager != null) { + for (RunningServiceInfo service : manager.getRunningServices(Integer.MAX_VALUE)) { + //Log.d(TAG, service.service.getClassName()); + //We will check to see if it contains this name, should be pretty specific + if ((service.service.getClassName()).toLowerCase(Locale.US).contains(SdlBroadcastReceiver.SDL_ROUTER_SERVICE_CLASS_NAME)) { + //this.service = service.service; //This is great + if (service.started && service.restarting == 0) { //If this service has been started and is not crashed + return service.service; //appPackageForComponenetName(service.service,pm); + } } } - } + } return null; } @@ -484,7 +483,7 @@ public class RouterServiceValidator { JSONObject trustedApps = stringToJson(getTrustedList(context)); JSONArray versions; - JSONObject app = null; + JSONObject app; try { app = trustedApps.getJSONObject(packageName); @@ -498,7 +497,7 @@ public class RouterServiceValidator { if(shouldOverrideVersionCheck()){ //If we don't care about versions, just return true return true; } - try { versions = app.getJSONArray(JSON_RESONSE_APP_VERSIONS_TAG); } catch (JSONException e) { e.printStackTrace();return false;} + try { versions = app.getJSONArray(JSON_RESPONSE_APP_VERSIONS_TAG); } catch (JSONException e) { e.printStackTrace();return false;} return verifyVersion(version, versions); } @@ -530,12 +529,12 @@ public class RouterServiceValidator { * @return */ private static List<SdlApp> findAllSdlApps(Context context){ - List<SdlApp> apps = new ArrayList<SdlApp>(); + List<SdlApp> apps = new ArrayList<>(); PackageManager packageManager = context.getPackageManager(); Intent intent = new Intent(); intent.setAction(TransportConstants.START_ROUTER_SERVICE_ACTION); List<ResolveInfo> infoList = packageManager.queryBroadcastReceivers(intent, 0); - //We want to sort our list so that we know it's the same everytime + //We want to sort our list so that we know it's the same every time Collections.sort(infoList,new Comparator<ResolveInfo>() { @Override public int compare(ResolveInfo lhs, ResolveInfo rhs) { @@ -583,7 +582,7 @@ public class RouterServiceValidator { } return false; } - + pendingListRefresh = true; //Might want to store a flag letting this class know a request is currently pending StringBuilder builder = new StringBuilder(); @@ -660,11 +659,13 @@ public class RouterServiceValidator { */ protected boolean isServiceRunning(Context context, ComponentName service){ ActivityManager manager = (ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE); - for (RunningServiceInfo serviceInfo : manager.getRunningServices(Integer.MAX_VALUE)) { - if (serviceInfo.service.equals(service)) { - return true; - } - } + if (manager != null) { + for (RunningServiceInfo serviceInfo : manager.getRunningServices(Integer.MAX_VALUE)) { + if (serviceInfo.service.equals(service)) { + return true; + } + } + } return false; } @@ -703,9 +704,9 @@ public class RouterServiceValidator { return prefAdd.commit(); } /****************************************************************** - * + * * Saving the list for later!!! - * + * ******************************************************************/ /** @@ -796,8 +797,8 @@ public class RouterServiceValidator { * Class that holds all the info we want to send/receive from the validation server */ public static class SdlApp{ - String packageName; - int versionCode; + final String packageName; + final int versionCode; SdlApp(String packageName, int versionCode){ this.packageName = packageName; @@ -805,7 +806,7 @@ public class RouterServiceValidator { } } - public static enum TrustedAppStore{ + public enum TrustedAppStore{ PLAY_STORE("com.android.vending"), AMAZON("com.amazon.venezia"), XIAOMI("com.xiaomi.market"), @@ -815,7 +816,7 @@ public class RouterServiceValidator { HIAPK("com.hiapk.marketpho"), ; - String packageString; + final String packageString; private TrustedAppStore(String packageString){ this.packageString = packageString; } @@ -830,8 +831,8 @@ public class RouterServiceValidator { return false; } TrustedAppStore[] stores = TrustedAppStore.values(); - for(int i =0; i<stores.length; i++){ - if(packageString.equalsIgnoreCase(stores[i].packageString)){ + for (TrustedAppStore store : stores) { + if (packageString.equalsIgnoreCase(store.packageString)) { return true; } } @@ -843,8 +844,8 @@ public class RouterServiceValidator { * This interface is used as a callback to know when we have either obtained a list or at least returned from our attempt. * */ - public static interface TrustedListCallback{ - public void onListObtained(boolean successful); + public interface TrustedListCallback{ + void onListObtained(boolean successful); } } 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 bad3ccc2e..8942ce76e 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 @@ -162,7 +162,7 @@ public abstract class SdlBroadcastReceiver extends BroadcastReceiver{ RouterServiceValidator.createTrustedListRequest(context, false, new TrustedListCallback(){ @Override public void onListObtained(boolean successful) { - //Log.v(TAG, "SDL enabled by router service from " + packageName + " compnent package " + componentName.getPackageName() + " - " + componentName.getClassName()); + //Log.v(TAG, "SDL enabled by router service from " + packageName + " component package " + componentName.getPackageName() + " - " + componentName.getClassName()); //List obtained. Let's start our service queuedService = componentName; finalIntent.setAction("com.sdl.noaction"); //Replace what's there so we do go into some unintended loop @@ -261,7 +261,7 @@ public abstract class SdlBroadcastReceiver extends BroadcastReceiver{ new ServiceFinder(context, context.getPackageName(), new ServiceFinder.ServiceFinderCallback() { @Override public void onComplete(Vector<ComponentName> routerServices) { - runningBluetoothServicePackage = new Vector<ComponentName>(); + runningBluetoothServicePackage = new Vector<>(); runningBluetoothServicePackage.addAll(routerServices); if (runningBluetoothServicePackage.isEmpty()) { //If there isn't a service running we should try to start one @@ -350,6 +350,7 @@ public abstract class SdlBroadcastReceiver extends BroadcastReceiver{ if (e != null && e instanceof AndroidRuntimeException && "android.app.RemoteServiceException".equals(e.getClass().getName()) //android.app.RemoteServiceException is a private class + && e.getMessage() != null && e.getMessage().contains("SdlRouterService")) { DebugTool.logInfo(TAG, "Handling failed startForegroundService call"); @@ -375,13 +376,15 @@ public abstract class SdlBroadcastReceiver extends BroadcastReceiver{ return false; } if (runningBluetoothServicePackage == null) { - runningBluetoothServicePackage = new Vector<ComponentName>(); + runningBluetoothServicePackage = new Vector<>(); } else { runningBluetoothServicePackage.clear(); } ActivityManager manager = (ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE); - manager.getRunningAppProcesses(); - List<RunningServiceInfo> runningServices = null; + if (manager != null) { + manager.getRunningAppProcesses(); + } + List<RunningServiceInfo> runningServices; try { runningServices = manager.getRunningServices(Integer.MAX_VALUE); } catch (NullPointerException e) { @@ -450,7 +453,7 @@ public abstract class SdlBroadcastReceiver extends BroadcastReceiver{ ServiceFinder finder = new ServiceFinder(context, context.getPackageName(), new ServiceFinder.ServiceFinderCallback() { @Override public void onComplete(Vector<ComponentName> routerServices) { - runningBluetoothServicePackage = new Vector<ComponentName>(); + runningBluetoothServicePackage = new Vector<>(); runningBluetoothServicePackage.addAll(routerServices); requestTransportStatus(context,null,true,false); } @@ -473,7 +476,7 @@ public abstract class SdlBroadcastReceiver extends BroadcastReceiver{ return; } if((!lookForServices || isRouterServiceRunning(context)) && !runningBluetoothServicePackage.isEmpty()){ //So there is a service up, let's see if it's connected - final ConcurrentLinkedQueue<ComponentName> list = new ConcurrentLinkedQueue<ComponentName>(runningBluetoothServicePackage); + final ConcurrentLinkedQueue<ComponentName> list = new ConcurrentLinkedQueue<>(runningBluetoothServicePackage); final SdlRouterStatusProvider.ConnectedStatusCallback sdlBrCallback = new SdlRouterStatusProvider.ConnectedStatusCallback() { @Override 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 84a766978..3fc7d4b8f 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 @@ -157,8 +157,7 @@ public class SdlRouterService extends Service{ /** Message types sent from the BluetoothReadService Handler */ public static final int MESSAGE_STATE_CHANGE = 1; public static final int MESSAGE_READ = 2; - @SuppressWarnings("unused") - public static final int MESSAGE_WRITE = 3; + public static final int MESSAGE_WRITE = 3; public static final int MESSAGE_DEVICE_NAME = 4; public static final int MESSAGE_LOG = 5; @@ -1018,7 +1017,6 @@ public class SdlRouterService extends Service{ return true; } - @SuppressWarnings("unused") private void pingClients(){ Message message = Message.obtain(); DebugTool.logInfo(TAG, "Pinging "+ registeredApps.size()+ " clients"); @@ -1224,6 +1222,7 @@ public class SdlRouterService extends Service{ if (e != null && e instanceof AndroidRuntimeException && "android.app.RemoteServiceException".equals(e.getClass().getName()) //android.app.RemoteServiceException is a private class + && e.getMessage() != null && e.getMessage().contains("invalid channel for service notification")) { //This is the message received in the exception for notification channel issues // Set the flag to not delete the notification channel to avoid this exception in the future @@ -1437,7 +1436,6 @@ public class SdlRouterService extends Service{ } @SuppressLint("NewApi") - @SuppressWarnings("deprecation") private void enterForeground(String content, long chronometerLength, boolean ongoing) { DebugTool.logInfo(TAG, "Attempting to enter the foreground - " + System.currentTimeMillis()); @@ -1981,7 +1979,7 @@ public class SdlRouterService extends Service{ } } - @SuppressWarnings("unused") //The return false after the packet null check is not dead code. Read the getByteArray method from bundle + //The return false after the packet null check is not dead code. Read the getByteArray method from bundle public boolean writeBytesToTransport(Bundle bundle){ if(bundle == null){ return false; @@ -2354,7 +2352,7 @@ public class SdlRouterService extends Service{ * And start SDL * @return a boolean if a connection was attempted */ - @SuppressWarnings({"MissingPermission", "unused"}) + @SuppressWarnings({"MissingPermission"}) public synchronized boolean bluetoothQuerryAndConnect(){ BluetoothAdapter adapter = BluetoothAdapter.getDefaultAdapter(); if(adapter != null && adapter.isEnabled()){ @@ -2408,7 +2406,7 @@ public class SdlRouterService extends Service{ SharedPreferences preferences = this.getSharedPreferences(SDL_DEVICE_STATUS_SHARED_PREFS, Context.MODE_PRIVATE); SharedPreferences.Editor editor = preferences.edit(); editor.putBoolean(address,hasSDLConnected); - editor.commit(); + editor.apply(); } /** @@ -2439,7 +2437,7 @@ public class SdlRouterService extends Service{ SharedPreferences preferences = this.getSharedPreferences(SDL_ROUTER_SERVICE_PREFS, Context.MODE_PRIVATE); SharedPreferences.Editor editor = preferences.edit(); editor.putBoolean(key,value); - editor.commit(); + editor.apply(); DebugTool.logInfo(TAG, "Preference set: " + key + " : " + value); } @@ -2702,7 +2700,6 @@ public class SdlRouterService extends Service{ // *********************************************************** UTILITY **************************************************************** //*****************************************************************************************************************************************/ - @SuppressWarnings("unused") private void debugPacket(byte[] bytes){ //DEBUG @@ -2886,7 +2883,7 @@ public class SdlRouterService extends Service{ * @deprecated Move to the new version checking system with meta-data * */ - @SuppressWarnings({"unused", "DeprecatedIsStillUsed"}) + @SuppressWarnings({"DeprecatedIsStillUsed"}) @Deprecated static class LocalRouterService implements Parcelable{ Intent launchIntent = null; @@ -3112,7 +3109,6 @@ public class SdlRouterService extends Service{ } } - @SuppressWarnings("unused") public void clearSessionIds(){ this.sessionIds.clear(); } @@ -3432,7 +3428,7 @@ public class SdlRouterService extends Service{ private static final int DELAY_COEF = 1; private static final int SIZE_COEF = 1; - private byte[] bytesToWrite = null; + private byte[] bytesToWrite; private final int offset, size, priorityCoefficient; private final long timestamp; final Bundle receivedBundle; diff --git a/android/sdl_android/src/main/java/com/smartdevicelink/transport/SdlRouterStatusProvider.java b/android/sdl_android/src/main/java/com/smartdevicelink/transport/SdlRouterStatusProvider.java index 20fcf8997..0640017d5 100644 --- a/android/sdl_android/src/main/java/com/smartdevicelink/transport/SdlRouterStatusProvider.java +++ b/android/sdl_android/src/main/java/com/smartdevicelink/transport/SdlRouterStatusProvider.java @@ -54,16 +54,16 @@ public class SdlRouterStatusProvider { private static final String TAG = "SdlRouterStateProvider"; - private Context context = null; + private Context context; private boolean isBound = false; - ConnectedStatusCallback cb = null; + ConnectedStatusCallback cb; Messenger routerServiceMessenger = null; - private ComponentName routerService = null; + private ComponentName routerService; private int flags = 0; final Messenger clientMessenger; - private ServiceConnection routerConnection= new ServiceConnection() { + private final ServiceConnection routerConnection= new ServiceConnection() { public void onServiceConnected(ComponentName className, IBinder service) { DebugTool.logInfo(TAG, "Bound to service " + className.toString()); @@ -167,7 +167,7 @@ public class SdlRouterStatusProvider { public ClientHandler(SdlRouterStatusProvider provider){ super(Looper.getMainLooper()); - this.provider = new WeakReference<SdlRouterStatusProvider>(provider); + this.provider = new WeakReference<>(provider); } @Override @@ -183,7 +183,7 @@ public class SdlRouterStatusProvider { break; } } - }; + } public interface ConnectedStatusCallback{ void onConnectionStatusUpdate(boolean connected, ComponentName service, Context context); diff --git a/android/sdl_android/src/main/java/com/smartdevicelink/transport/TCPTransportManager.java b/android/sdl_android/src/main/java/com/smartdevicelink/transport/TCPTransportManager.java index 3df010bcf..4381b97c6 100644 --- a/android/sdl_android/src/main/java/com/smartdevicelink/transport/TCPTransportManager.java +++ b/android/sdl_android/src/main/java/com/smartdevicelink/transport/TCPTransportManager.java @@ -14,9 +14,9 @@ public class TCPTransportManager extends TransportManagerBase{ private static final String TAG = "TCPTransportManager"; - private TCPHandler tcpHandler; + private final TCPHandler tcpHandler; private MultiplexTcpTransport transport; - private TCPTransportConfig config; + private final TCPTransportConfig config; public TCPTransportManager(TCPTransportConfig config, TransportEventListener transportEventListener){ super(config,transportEventListener); 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 e2e3c1d87..31e9e0302 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 @@ -84,8 +84,8 @@ public class TransportBroker { private static final TransportRecord LEGACY_TRANSPORT_RECORD = new TransportRecord(TransportType.BLUETOOTH,null); private final String WHERE_TO_REPLY_PREFIX = "com.sdl.android."; - private String appId; - private String whereToReply; + private final String appId; + private final String whereToReply; private Context currentContext; private final Object INIT_LOCK = new Object(); @@ -96,7 +96,7 @@ public class TransportBroker { boolean isBound = false, registeredWithRouterService = false; private String routerPackage = null, routerClassName = null; - private ComponentName routerService = null; + private ComponentName routerService; private SdlPacket bufferedPacket = null; @@ -104,7 +104,7 @@ public class TransportBroker { private ServiceConnection routerConnection; private int routerServiceVersion = 1; - private int messagingVersion = MAX_MESSAGING_VERSION; + private final int messagingVersion = MAX_MESSAGING_VERSION; private void initRouterConnection() { routerConnection = new ServiceConnection() { @@ -184,11 +184,11 @@ public class TransportBroker { * Handler of incoming messages from service. */ static class ClientHandler extends Handler { - ClassLoader loader; + final ClassLoader loader; final WeakReference<TransportBroker> provider; public ClientHandler(TransportBroker provider) { - this.provider = new WeakReference<TransportBroker>(provider); + this.provider = new WeakReference<>(provider); loader = getClass().getClassLoader(); } @@ -246,7 +246,7 @@ public class TransportBroker { DebugTool.logWarning(TAG, "Registration denied from router service. Reason - " + msg.arg1); break; } - ; + break; @@ -356,7 +356,7 @@ public class TransportBroker { } /** - * Handle a potential connection event. This will adapt legacy router service implementaions + * Handle a potential connection event. This will adapt legacy router service implementations * into the new multiple transport scheme. * @param bundle the received bundle from the router service * @param broker reference to the transport broker that this handler exists @@ -499,7 +499,7 @@ public class TransportBroker { return routerServiceVersion; } - public boolean sendPacketToRouterService(SdlPacket packet) { //We use ints because that is all that is supported by the outputstream class + public boolean sendPacketToRouterService(SdlPacket packet) { //We use ints because that is all that is supported by the output stream class //Log.d(TAG,whereToReply + "Sending packet to router service"); if (routerServiceMessenger == null) { @@ -678,7 +678,7 @@ public class TransportBroker { */ private static boolean legacyModeEnabled = false; - private static Object LEGACY_LOCK = new Object(); + private static final Object LEGACY_LOCK = new Object(); protected void enableLegacyMode(boolean enable) { synchronized (LEGACY_LOCK) { diff --git a/android/sdl_android/src/main/java/com/smartdevicelink/transport/TransportManager.java b/android/sdl_android/src/main/java/com/smartdevicelink/transport/TransportManager.java index e3614faa9..13edfb5f1 100644 --- a/android/sdl_android/src/main/java/com/smartdevicelink/transport/TransportManager.java +++ b/android/sdl_android/src/main/java/com/smartdevicelink/transport/TransportManager.java @@ -55,7 +55,6 @@ import com.smartdevicelink.util.DebugTool; import java.lang.ref.WeakReference; import java.util.List; -@SuppressWarnings("unused") public class TransportManager extends TransportManagerBase{ private static final String TAG = "TransportManager"; @@ -244,7 +243,7 @@ public class TransportManager extends TransportManagerBase{ String[] split = address.split(":"); if(split.length == 2) { bundle.putString(ControlFrameTags.RPC.TransportEventUpdate.TCP_IP_ADDRESS, split[0]); - bundle.putInt(ControlFrameTags.RPC.TransportEventUpdate.TCP_PORT, Integer.valueOf(split[1])); + bundle.putInt(ControlFrameTags.RPC.TransportEventUpdate.TCP_PORT, Integer.parseInt(split[1])); } //else {something went wrong;} }else{ bundle.putString(ControlFrameTags.RPC.TransportEventUpdate.TCP_IP_ADDRESS, address); @@ -450,7 +449,7 @@ public class TransportManager extends TransportManagerBase{ String action = intent.getAction(); if(BluetoothDevice.ACTION_ACL_DISCONNECTED.equals(action)){ exitLegacyMode("Bluetooth disconnected"); - }else if(action.equalsIgnoreCase(BluetoothAdapter.ACTION_STATE_CHANGED)){ + }else if(action != null && action.equalsIgnoreCase(BluetoothAdapter.ACTION_STATE_CHANGED)){ int bluetoothState = intent.getIntExtra(BluetoothAdapter.EXTRA_STATE, -1); if(bluetoothState == BluetoothAdapter.STATE_TURNING_OFF || bluetoothState == BluetoothAdapter.STATE_OFF){ DebugTool.logInfo(TAG, "Bluetooth is shutting off, exiting legacy mode."); diff --git a/android/sdl_android/src/main/java/com/smartdevicelink/transport/UsbTransferProvider.java b/android/sdl_android/src/main/java/com/smartdevicelink/transport/UsbTransferProvider.java index cd351a622..0b0c9b88d 100644 --- a/android/sdl_android/src/main/java/com/smartdevicelink/transport/UsbTransferProvider.java +++ b/android/sdl_android/src/main/java/com/smartdevicelink/transport/UsbTransferProvider.java @@ -71,7 +71,7 @@ public class UsbTransferProvider { ParcelFileDescriptor usbPfd; Bundle usbInfoBundle; - private ServiceConnection routerConnection= new ServiceConnection() { + private final ServiceConnection routerConnection= new ServiceConnection() { public void onServiceConnected(ComponentName className, IBinder service) { DebugTool.logInfo(TAG, "Bound to service " + className.toString()); @@ -212,7 +212,7 @@ public class UsbTransferProvider { public ClientHandler(UsbTransferProvider provider){ super(Looper.getMainLooper()); - this.provider = new WeakReference<UsbTransferProvider>(provider); + this.provider = new WeakReference<>(provider); } @Override diff --git a/android/sdl_android/src/main/java/com/smartdevicelink/transport/utl/ByteArrayMessageSpliter.java b/android/sdl_android/src/main/java/com/smartdevicelink/transport/utl/ByteArrayMessageSpliter.java index 9ab93aea9..670711709 100644 --- a/android/sdl_android/src/main/java/com/smartdevicelink/transport/utl/ByteArrayMessageSpliter.java +++ b/android/sdl_android/src/main/java/com/smartdevicelink/transport/utl/ByteArrayMessageSpliter.java @@ -50,11 +50,11 @@ public class ByteArrayMessageSpliter { boolean firstPacket; ByteArrayInputStream stream; int bytesRead; - int what; - String appId; + final int what; + final String appId; byte[] buffer; - int orginalSize; - int priorityCoef; + final int orginalSize; + final int priorityCoef; int routerServiceVersion = 1; TransportRecord transportRecord; diff --git a/android/sdl_android/src/main/java/com/smartdevicelink/transport/utl/SdlDeviceListener.java b/android/sdl_android/src/main/java/com/smartdevicelink/transport/utl/SdlDeviceListener.java index b9bd8bb12..3be6bec30 100644 --- a/android/sdl_android/src/main/java/com/smartdevicelink/transport/utl/SdlDeviceListener.java +++ b/android/sdl_android/src/main/java/com/smartdevicelink/transport/utl/SdlDeviceListener.java @@ -196,7 +196,7 @@ public class SdlDeviceListener { } SharedPreferences.Editor editor = preferences.edit(); editor.putBoolean(address, hasSDLConnected); - editor.commit(); + editor.apply(); } } } |