Skip to content

Commit b1bf822

Browse files
Merge pull request #1759 from smartdevicelink/bugfix/issue_1756
Menu Manager won't send submenu cell images on RPC versions >= 5.0 && < 7.0
2 parents 93280da + a627e9e commit b1bf822

4 files changed

Lines changed: 155 additions & 40 deletions

File tree

android/sdl_android/src/androidTest/java/com/smartdevicelink/managers/screen/menu/MenuManagerTests.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -261,12 +261,15 @@ public void testSettingNonUniqueCells() {
261261

262262
@Test
263263
public void testUpdatingOldWay() {
264+
ISdl internalInterface = mock(ISdl.class);
265+
when(internalInterface.getSdlMsgVersion()).thenReturn(new SdlMsgVersion(new Version(8, 0, 0)));
266+
264267
// Force Menu Manager to use the old way of deleting / sending all
265268
menuManager.setDynamicUpdatesMode(DynamicMenuUpdatesMode.FORCE_OFF);
266269
assertEquals(menuManager.dynamicMenuUpdatesMode, DynamicMenuUpdatesMode.FORCE_OFF);
267270
// when we only send one command to update, we should only be returned one add command
268271
List<MenuCell> newArray = Arrays.asList(mainCell1, mainCell4);
269-
assertEquals(MenuReplaceUtilities.allCommandsForCells(newArray, menuManager.fileManager.get(), menuManager.windowCapability, MenuLayout.LIST).size(), 4); // 1 root cells, 1 sub menu root cell, 2 sub menu cells
272+
assertEquals(MenuReplaceUtilities.allCommandsForCells(internalInterface, newArray, menuManager.fileManager.get(), menuManager.windowCapability, MenuLayout.LIST).size(), 4); // 1 root cells, 1 sub menu root cell, 2 sub menu cells
270273
menuManager.currentHMILevel = HMILevel.HMI_FULL;
271274
menuManager.setMenuCells(newArray);
272275

android/sdl_android/src/androidTest/java/com/smartdevicelink/managers/screen/menu/MenuReplaceUtilitiesTests.java

Lines changed: 89 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -34,13 +34,16 @@
3434

3535
import androidx.test.ext.junit.runners.AndroidJUnit4;
3636

37+
import com.smartdevicelink.managers.ISdl;
3738
import com.smartdevicelink.managers.file.FileManager;
3839
import com.smartdevicelink.managers.file.filetypes.SdlArtwork;
3940
import com.smartdevicelink.proxy.rpc.ImageField;
41+
import com.smartdevicelink.proxy.rpc.SdlMsgVersion;
4042
import com.smartdevicelink.proxy.rpc.WindowCapability;
4143
import com.smartdevicelink.proxy.rpc.enums.ImageFieldName;
4244
import com.smartdevicelink.proxy.rpc.enums.MenuLayout;
4345
import com.smartdevicelink.test.TestValues;
46+
import com.smartdevicelink.util.Version;
4447

4548
import org.junit.Before;
4649
import org.junit.Test;
@@ -209,8 +212,89 @@ public void testAddMenuRequestWithCommandId() {
209212
assertEquals(1, actualMenuCellList.get(4).getSubCells().get(1).getSubCells().size());
210213
}
211214

215+
@Test
216+
public void testWindowCapabilitySupportsPrimaryImage() {
217+
WindowCapability windowCapability;
218+
ISdl internalInterface = mock(ISdl.class);
219+
MenuCell menuCell = mock(MenuCell.class);
220+
221+
// Test case 0
222+
windowCapability = createWindowCapability(false, true);
223+
when(menuCell.isSubMenuCell()).thenReturn(true);
224+
when(internalInterface.getSdlMsgVersion()).thenReturn(new SdlMsgVersion(new Version(4, 9, 0)));
225+
assertTrue(MenuReplaceUtilities.windowCapabilitySupportsPrimaryImage(internalInterface, windowCapability, menuCell));
226+
227+
// Test case 1
228+
windowCapability = createWindowCapability(false, false);
229+
when(menuCell.isSubMenuCell()).thenReturn(true);
230+
when(internalInterface.getSdlMsgVersion()).thenReturn(new SdlMsgVersion(new Version(4, 9, 0)));
231+
assertFalse(MenuReplaceUtilities.windowCapabilitySupportsPrimaryImage(internalInterface, windowCapability, menuCell));
232+
233+
// Test case 2
234+
windowCapability = createWindowCapability(false, false);
235+
when(menuCell.isSubMenuCell()).thenReturn(true);
236+
when(internalInterface.getSdlMsgVersion()).thenReturn(new SdlMsgVersion(new Version(5, 0, 0)));
237+
assertFalse(MenuReplaceUtilities.windowCapabilitySupportsPrimaryImage(internalInterface, windowCapability, menuCell));
238+
239+
// Test case 3
240+
windowCapability = createWindowCapability(true, false);
241+
when(menuCell.isSubMenuCell()).thenReturn(true);
242+
when(internalInterface.getSdlMsgVersion()).thenReturn(new SdlMsgVersion(new Version(5, 0, 0)));
243+
assertTrue(MenuReplaceUtilities.windowCapabilitySupportsPrimaryImage(internalInterface, windowCapability, menuCell));
244+
245+
// Test case 4
246+
windowCapability = createWindowCapability(false, false);
247+
when(menuCell.isSubMenuCell()).thenReturn(true);
248+
when(internalInterface.getSdlMsgVersion()).thenReturn(new SdlMsgVersion(new Version(6, 0, 0)));
249+
assertFalse(MenuReplaceUtilities.windowCapabilitySupportsPrimaryImage(internalInterface, windowCapability, menuCell));
250+
251+
// Test case 5
252+
windowCapability = createWindowCapability(true, false);
253+
when(menuCell.isSubMenuCell()).thenReturn(true);
254+
when(internalInterface.getSdlMsgVersion()).thenReturn(new SdlMsgVersion(new Version(6, 0, 0)));
255+
assertTrue(MenuReplaceUtilities.windowCapabilitySupportsPrimaryImage(internalInterface, windowCapability, menuCell));
256+
257+
// Test case 6
258+
windowCapability = createWindowCapability(false, false);
259+
when(menuCell.isSubMenuCell()).thenReturn(true);
260+
when(internalInterface.getSdlMsgVersion()).thenReturn(new SdlMsgVersion(new Version(7, 0, 0)));
261+
assertFalse(MenuReplaceUtilities.windowCapabilitySupportsPrimaryImage(internalInterface, windowCapability, menuCell));
262+
263+
// Test case 7
264+
windowCapability = createWindowCapability(false, false);
265+
when(menuCell.isSubMenuCell()).thenReturn(true);
266+
when(internalInterface.getSdlMsgVersion()).thenReturn(new SdlMsgVersion(new Version(7, 1, 0)));
267+
assertFalse(MenuReplaceUtilities.windowCapabilitySupportsPrimaryImage(internalInterface, windowCapability, menuCell));
268+
269+
// Test case 8
270+
windowCapability = createWindowCapability(false, false);
271+
when(menuCell.isSubMenuCell()).thenReturn(true);
272+
when(internalInterface.getSdlMsgVersion()).thenReturn(new SdlMsgVersion(new Version(8, 0, 0)));
273+
assertFalse(MenuReplaceUtilities.windowCapabilitySupportsPrimaryImage(internalInterface, windowCapability, menuCell));
274+
275+
// Test case 9
276+
windowCapability = createWindowCapability(false, true);
277+
when(menuCell.isSubMenuCell()).thenReturn(true);
278+
when(internalInterface.getSdlMsgVersion()).thenReturn(new SdlMsgVersion(new Version(8, 0, 0)));
279+
assertTrue(MenuReplaceUtilities.windowCapabilitySupportsPrimaryImage(internalInterface, windowCapability, menuCell));
280+
281+
// Test case 10
282+
windowCapability = createWindowCapability(false, false);
283+
when(menuCell.isSubMenuCell()).thenReturn(false);
284+
when(internalInterface.getSdlMsgVersion()).thenReturn(new SdlMsgVersion(new Version(8, 0, 0)));
285+
assertFalse(MenuReplaceUtilities.windowCapabilitySupportsPrimaryImage(internalInterface, windowCapability, menuCell));
286+
287+
// Test case 11
288+
windowCapability = createWindowCapability(true, false);
289+
when(menuCell.isSubMenuCell()).thenReturn(false);
290+
when(internalInterface.getSdlMsgVersion()).thenReturn(new SdlMsgVersion(new Version(8, 0, 0)));
291+
assertTrue(MenuReplaceUtilities.windowCapabilitySupportsPrimaryImage(internalInterface, windowCapability, menuCell));
292+
}
293+
212294
@Test
213295
public void testShouldCellIncludeImage() {
296+
ISdl internalInterface = mock(ISdl.class);
297+
when(internalInterface.getSdlMsgVersion()).thenReturn(new SdlMsgVersion(new Version(8, 0, 0)));
214298
MenuCell menuCell;
215299
WindowCapability windowCapability;
216300
FileManager fileManager;
@@ -220,31 +304,31 @@ public void testShouldCellIncludeImage() {
220304
menuCell = new MenuCell(TestValues.GENERAL_STRING, TestValues.GENERAL_ARTWORK, voiceCommands, null);
221305
windowCapability = createWindowCapability(true, true);
222306
fileManager = createMockFileManager(true);
223-
assertTrue(MenuReplaceUtilities.shouldCellIncludePrimaryImageFromCell(menuCell, fileManager, windowCapability));
307+
assertTrue(MenuReplaceUtilities.shouldCellIncludePrimaryImageFromCell(internalInterface, menuCell, fileManager, windowCapability));
224308

225309
// Case 2 - Image are not supported
226310
menuCell = new MenuCell(TestValues.GENERAL_STRING, TestValues.GENERAL_ARTWORK, voiceCommands, null);
227311
windowCapability = createWindowCapability(false, false);
228312
fileManager = createMockFileManager(true);
229-
assertFalse(MenuReplaceUtilities.shouldCellIncludePrimaryImageFromCell(menuCell, fileManager, windowCapability));
313+
assertFalse(MenuReplaceUtilities.shouldCellIncludePrimaryImageFromCell(internalInterface, menuCell, fileManager, windowCapability));
230314

231315
// Case 3 - Artwork is null
232316
menuCell = new MenuCell(TestValues.GENERAL_STRING, null, voiceCommands, null);
233317
windowCapability = createWindowCapability(true, true);
234318
fileManager = createMockFileManager(true);
235-
assertFalse(MenuReplaceUtilities.shouldCellIncludePrimaryImageFromCell(menuCell, fileManager, windowCapability));
319+
assertFalse(MenuReplaceUtilities.shouldCellIncludePrimaryImageFromCell(internalInterface, menuCell, fileManager, windowCapability));
236320

237321
// Case 4 - Artwork has not been uploaded
238322
menuCell = new MenuCell(TestValues.GENERAL_STRING, TestValues.GENERAL_ARTWORK, voiceCommands, null);
239323
windowCapability = createWindowCapability(true, true);
240324
fileManager = createMockFileManager(false);
241-
assertFalse(MenuReplaceUtilities.shouldCellIncludePrimaryImageFromCell(menuCell, fileManager, windowCapability));
325+
assertFalse(MenuReplaceUtilities.shouldCellIncludePrimaryImageFromCell(internalInterface, menuCell, fileManager, windowCapability));
242326

243327
// Case 5 - Artwork is static icon
244328
menuCell = new MenuCell(TestValues.GENERAL_STRING, TestValues.GENERAL_ARTWORK_STATIC, voiceCommands, null);
245329
windowCapability = createWindowCapability(true, true);
246330
fileManager = createMockFileManager(false);
247-
assertTrue(MenuReplaceUtilities.shouldCellIncludePrimaryImageFromCell(menuCell, fileManager, windowCapability));
331+
assertTrue(MenuReplaceUtilities.shouldCellIncludePrimaryImageFromCell(internalInterface, menuCell, fileManager, windowCapability));
248332
}
249333

250334
private WindowCapability createWindowCapability (boolean supportsCmdIcon, boolean supportsSubMenuIcon) {

base/src/main/java/com/smartdevicelink/managers/screen/menu/MenuReplaceOperation.java

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,8 @@
4848
import static com.smartdevicelink.managers.screen.menu.MenuReplaceUtilities.subMenuCommandsForCells;
4949
import static com.smartdevicelink.managers.screen.menu.MenuReplaceUtilities.transferCellIDsFromCells;
5050
import static com.smartdevicelink.managers.screen.menu.MenuReplaceUtilities.transferCellListenersFromCells;
51+
import static com.smartdevicelink.managers.screen.menu.MenuReplaceUtilities.windowCapabilitySupportsPrimaryImage;
52+
import static com.smartdevicelink.managers.screen.menu.MenuReplaceUtilities.windowCapabilitySupportsSecondaryImage;
5153

5254
import com.livio.taskmaster.Task;
5355
import com.smartdevicelink.managers.CompletionListener;
@@ -198,7 +200,7 @@ public void onComplete(boolean success) {
198200
}
199201

200202
private void uploadMenuArtworks(final CompletionListener listener) {
201-
List<SdlArtwork> artworksToBeUploaded = new ArrayList<>(findAllArtworksToBeUploadedFromCells(updatedMenu, fileManager.get(), windowCapability));
203+
List<SdlArtwork> artworksToBeUploaded = new ArrayList<>(findAllArtworksToBeUploadedFromCells(internalInterface.get(), updatedMenu, fileManager.get(), windowCapability));
202204
if (artworksToBeUploaded.isEmpty()) {
203205
listener.onComplete(true);
204206
return;
@@ -373,10 +375,10 @@ private void sendAddMenuCells(final List<MenuCell> addMenuCells, final List<Menu
373375
MenuLayout defaultSubmenuLayout = menuConfiguration != null ? menuConfiguration.getSubMenuLayout() : null;
374376

375377
// RPCs for cells on the main menu level. They could be AddCommands or AddSubMenus depending on whether the cell has child cells or not.
376-
final List<RPCRequest> mainMenuCommands = mainMenuCommandsForCells(addMenuCells, fileManager.get(), fullMenu, windowCapability, defaultSubmenuLayout);
378+
final List<RPCRequest> mainMenuCommands = mainMenuCommandsForCells(internalInterface.get(), addMenuCells, fileManager.get(), fullMenu, windowCapability, defaultSubmenuLayout);
377379

378380
// RPCs for cells on the second menu level (one level deep). They could be AddCommands or AddSubMenus.
379-
final List<RPCRequest> subMenuCommands = subMenuCommandsForCells(addMenuCells, fileManager.get(), windowCapability, defaultSubmenuLayout);
381+
final List<RPCRequest> subMenuCommands = subMenuCommandsForCells(internalInterface.get(), addMenuCells, fileManager.get(), windowCapability, defaultSubmenuLayout);
380382

381383
sendRPCs(mainMenuCommands, internalInterface.get(), new SendingRPCsCompletionListener() {
382384
@Override
@@ -465,12 +467,14 @@ List<MenuCell> cellsWithRemovedPropertiesFromCells(List<MenuCell> cells, WindowC
465467
// Strip away fields that cannot be used to determine uniqueness visually including fields not supported by the HMI
466468
cell.setVoiceCommands(null);
467469

468-
// Don't check ImageFieldName.subMenuIcon because it was added in 7.0 when the feature was added in 5.0.
469-
// Just assume that if cmdIcon is not available, the submenu icon is not either.
470-
if (!hasImageFieldOfName(windowCapability, ImageFieldName.cmdIcon)) {
470+
if (!windowCapabilitySupportsPrimaryImage(internalInterface.get(), windowCapability, cell)) {
471471
cell.setIcon(null);
472472
}
473473

474+
if (!windowCapabilitySupportsSecondaryImage(windowCapability, cell)) {
475+
cell.setSecondaryArtwork(null);
476+
}
477+
474478
// Check for subMenu fields supported
475479
if (cell.isSubMenuCell()) {
476480
if (!hasTextFieldOfName(windowCapability, TextFieldName.menuSubMenuSecondaryText)) {
@@ -479,9 +483,6 @@ List<MenuCell> cellsWithRemovedPropertiesFromCells(List<MenuCell> cells, WindowC
479483
if (!hasTextFieldOfName(windowCapability, TextFieldName.menuSubMenuTertiaryText)) {
480484
cell.setTertiaryText(null);
481485
}
482-
if (!hasImageFieldOfName(windowCapability, ImageFieldName.menuSubMenuSecondaryImage)) {
483-
cell.setSecondaryArtwork(null);
484-
}
485486
cell.setSubCells(cellsWithRemovedPropertiesFromCells(cell.getSubCells(), windowCapability));
486487
} else {
487488
if (!hasTextFieldOfName(windowCapability, TextFieldName.menuCommandSecondaryText)) {
@@ -490,9 +491,6 @@ List<MenuCell> cellsWithRemovedPropertiesFromCells(List<MenuCell> cells, WindowC
490491
if (!hasTextFieldOfName(windowCapability, TextFieldName.menuCommandTertiaryText)) {
491492
cell.setTertiaryText(null);
492493
}
493-
if (!hasImageFieldOfName(windowCapability, ImageFieldName.menuCommandSecondaryImage)) {
494-
cell.setSecondaryArtwork(null);
495-
}
496494
}
497495
}
498496
return removePropertiesClone;

0 commit comments

Comments
 (0)