Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix NPE in SystemCapabilityManager #1734

Merged
merged 4 commits into from
Sep 27, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
import com.smartdevicelink.proxy.rpc.SetDisplayLayoutResponse;
import com.smartdevicelink.proxy.rpc.SoftButtonCapabilities;
import com.smartdevicelink.proxy.rpc.SystemCapability;
import com.smartdevicelink.proxy.rpc.TextField;
import com.smartdevicelink.proxy.rpc.VideoStreamingCapability;
import com.smartdevicelink.proxy.rpc.WindowCapability;
import com.smartdevicelink.proxy.rpc.WindowTypeCapabilities;
Expand All @@ -52,6 +53,7 @@
import com.smartdevicelink.proxy.rpc.enums.SpeechCapabilities;
import com.smartdevicelink.proxy.rpc.enums.SystemCapabilityType;
import com.smartdevicelink.proxy.rpc.enums.SystemContext;
import com.smartdevicelink.proxy.rpc.enums.TextFieldName;
import com.smartdevicelink.proxy.rpc.enums.WindowType;
import com.smartdevicelink.proxy.rpc.listeners.OnMultipleRequestListener;
import com.smartdevicelink.proxy.rpc.listeners.OnRPCListener;
Expand Down Expand Up @@ -689,6 +691,35 @@ public void testGetAndAddListenerForDisplaysCapability() {
verify(internalInterface, times(0)).sendRPC(any(GetSystemCapability.class));
}

/**
* Test to verify that we can get null for templatesAvailable without hitting an NPE and
* test media field conversion for NON_MEDIA to NON-MEDIA for Sync bug.
*/
@Test
public void testMediaFieldConversion() {
SystemCapabilityManager systemCapabilityManager = new SystemCapabilityManager(new InternalSDLInterface());

RegisterAppInterfaceResponse raiResponse = new RegisterAppInterfaceResponse();
DisplayCapabilities displayCapabilities = new DisplayCapabilities();
displayCapabilities.setGraphicSupported(false);
TextField textField = new TextField();
textField.setName(TextFieldName.mainField1);
displayCapabilities.setTextFields(Collections.singletonList(textField));
raiResponse.setDisplayCapabilities(displayCapabilities);
raiResponse.setSuccess(true);
systemCapabilityManager.parseRAIResponse(raiResponse);

WindowCapability windowCapability = systemCapabilityManager.getDefaultMainWindowCapability();
assertNull(windowCapability.getTemplatesAvailable());

List<String> templates = new ArrayList<>();
templates.add("NON_MEDIA");
displayCapabilities.setTemplatesAvailable(templates);
systemCapabilityManager.parseRAIResponse(raiResponse);
windowCapability = systemCapabilityManager.getDefaultMainWindowCapability();
assertTrue(windowCapability.getTemplatesAvailable().contains("NON-MEDIA"));
}

@Test
public void testListConversion() {
SystemCapabilityManager systemCapabilityManager = createSampleManager();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -135,12 +135,15 @@ private List<DisplayCapability> createDisplayCapabilityList(DisplayCapabilities

// HAX: Issue #1705, Ford Sync bug returning incorrect template name for "NON-MEDIA" (https://github.com/smartdevicelink/sdl_java_suite/issues/1705).
List<String> templatesAvailable = display.getTemplatesAvailable();
for (int i = 0; i < templatesAvailable.size(); i++) {
if (templatesAvailable.get(i).equals("NON_MEDIA")) {
templatesAvailable.set(i, "NON-MEDIA");
break;
if (templatesAvailable != null) {
for (int i = 0; i < templatesAvailable.size(); i++) {
if ("NON_MEDIA".equals(templatesAvailable.get(i))) {
templatesAvailable.set(i, "NON-MEDIA");
break;
}
}
}

// copy all available display capabilities
defaultWindowCapability.setTemplatesAvailable(templatesAvailable);
defaultWindowCapability.setNumCustomPresetsAvailable(display.getNumCustomPresetsAvailable());
Expand Down