diff options
author | Bilal Alsharifi <bilal.alsharifi@gmail.com> | 2019-11-14 14:31:45 -0500 |
---|---|---|
committer | Bilal Alsharifi <bilal.alsharifi@gmail.com> | 2019-11-14 14:31:45 -0500 |
commit | 665b9842be192a3e8f57acad1feead4e0e908102 (patch) | |
tree | 15f862112cf794f3701b13b4729234c8621d4914 | |
parent | 93778656113f0023ec7025281b77e28000a1f5bd (diff) | |
download | sdl_android-665b9842be192a3e8f57acad1feead4e0e908102.tar.gz |
Fix some potential NPEs in SystemCapabilityManager
-rw-r--r-- | base/src/main/java/com/smartdevicelink/proxy/SystemCapabilityManager.java | 87 |
1 files changed, 48 insertions, 39 deletions
diff --git a/base/src/main/java/com/smartdevicelink/proxy/SystemCapabilityManager.java b/base/src/main/java/com/smartdevicelink/proxy/SystemCapabilityManager.java index febeb24ca..947f240e6 100644 --- a/base/src/main/java/com/smartdevicelink/proxy/SystemCapabilityManager.java +++ b/base/src/main/java/com/smartdevicelink/proxy/SystemCapabilityManager.java @@ -102,7 +102,13 @@ public class SystemCapabilityManager { WindowTypeCapabilities windowTypeCapabilities = new WindowTypeCapabilities(WindowType.MAIN, 1); DisplayCapability displayCapability = new DisplayCapability(); - displayCapability.setDisplayName(display != null ? display.getDisplayName() : display.getDisplayType().toString()); + if (display != null){ + if (display.getDisplayName() != null) { + displayCapability.setDisplayName(display.getDisplayName()); + } else if (display.getDisplayType() != null) { + displayCapability.setDisplayName(display.getDisplayType().toString()); + } + } displayCapability.setWindowTypeSupported(Collections.singletonList(windowTypeCapabilities)); // Create a window capability object for the default MAIN window @@ -290,7 +296,9 @@ public class SystemCapabilityManager { List<AppServiceCapability> appServicesCapabilitiesList = appServicesCapabilities.getAppServices(); AppServicesCapabilities cachedAppServicesCapabilities = (AppServicesCapabilities) cachedSystemCapabilities.get(systemCapabilityType); //Update the cached app services - cachedAppServicesCapabilities.updateAppServices(appServicesCapabilitiesList); + if (cachedAppServicesCapabilities != null) { + cachedAppServicesCapabilities.updateAppServices(appServicesCapabilitiesList); + } //Set the new capability object to the updated cached capabilities capability = cachedAppServicesCapabilities; } @@ -353,56 +361,57 @@ public class SystemCapabilityManager { * @return if that capability is supported with the current, connected module */ public boolean isCapabilitySupported(SystemCapabilityType type){ - if(cachedSystemCapabilities.get(type) != null){ + if (cachedSystemCapabilities.get(type) != null) { //The capability exists in the map and is not null return true; - }else if(cachedSystemCapabilities.containsKey(SystemCapabilityType.HMI)){ - HMICapabilities hmiCapabilities = ((HMICapabilities)cachedSystemCapabilities.get(SystemCapabilityType.HMI)); + } else if (cachedSystemCapabilities.containsKey(SystemCapabilityType.HMI)) { + HMICapabilities hmiCapabilities = ((HMICapabilities) cachedSystemCapabilities.get(SystemCapabilityType.HMI)); Version rpcVersion = null; if (callback != null) { SdlMsgVersion version = callback.getSdlMsgVersion(); - if(version != null){ + if (version != null) { rpcVersion = new Version(version.getMajorVersion(), version.getMinorVersion(), version.getPatchVersion()); } } - switch (type) { - case NAVIGATION: - return hmiCapabilities.isNavigationAvailable(); - case PHONE_CALL: - return hmiCapabilities.isPhoneCallAvailable(); - case VIDEO_STREAMING: - if(rpcVersion != null) { - if(rpcVersion.isBetween(new Version(3,0,0), new Version(4,4,0)) >= 0){ - //This was before the system capability feature was added so check if - // graphics are supported instead - DisplayCapabilities displayCapabilities = (DisplayCapabilities) getCapability(SystemCapabilityType.DISPLAY); - if(displayCapabilities != null){ - return displayCapabilities.getGraphicSupported() != null && displayCapabilities.getGraphicSupported(); + if (hmiCapabilities != null) { + switch (type) { + case NAVIGATION: + return hmiCapabilities.isNavigationAvailable(); + case PHONE_CALL: + return hmiCapabilities.isPhoneCallAvailable(); + case VIDEO_STREAMING: + if (rpcVersion != null) { + if (rpcVersion.isBetween(new Version(3, 0, 0), new Version(4, 4, 0)) >= 0) { + //This was before the system capability feature was added so check if + // graphics are supported instead + DisplayCapabilities displayCapabilities = (DisplayCapabilities) getCapability(SystemCapabilityType.DISPLAY); + if (displayCapabilities != null) { + return displayCapabilities.getGraphicSupported() != null && displayCapabilities.getGraphicSupported(); + } } } - } - return hmiCapabilities.isVideoStreamingAvailable(); - case REMOTE_CONTROL: - return hmiCapabilities.isRemoteControlAvailable(); - case APP_SERVICES: - if(rpcVersion != null){ - if(rpcVersion.getMajor() == 5 && rpcVersion.getMinor() == 1){ - //This is a corner case that the param was not available in 5.1.0, but - //the app services feature was available. - return true; + return hmiCapabilities.isVideoStreamingAvailable(); + case REMOTE_CONTROL: + return hmiCapabilities.isRemoteControlAvailable(); + case APP_SERVICES: + if (rpcVersion != null) { + if (rpcVersion.getMajor() == 5 && rpcVersion.getMinor() == 1) { + //This is a corner case that the param was not available in 5.1.0, but + //the app services feature was available. + return true; + } } - } - return hmiCapabilities.isAppServicesAvailable(); - case DISPLAYS: - return hmiCapabilities.isDisplaysCapabilityAvailable(); - case SEAT_LOCATION: - return hmiCapabilities.isSeatLocationAvailable(); - default: - return false; + return hmiCapabilities.isAppServicesAvailable(); + case DISPLAYS: + return hmiCapabilities.isDisplaysCapabilityAvailable(); + case SEAT_LOCATION: + return hmiCapabilities.isSeatLocationAvailable(); + default: + return false; + } } - }else{ - return false; } + return false; } /** * @param systemCapabilityType Type of capability desired |