Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
f54a7ca
Checkpoint
crokita Oct 26, 2021
56f83de
Merge pull request #513 from smartdevicelink/master
crokita Oct 27, 2021
0a6e0a6
Library alignment
crokita Nov 12, 2021
bd98f41
Alignment and bug fixes
crokita Nov 15, 2021
55aabbd
Remove unused parameter in menu utility method
crokita Nov 17, 2021
6fb5664
Check for null before attempting to call a method
crokita Nov 18, 2021
ebe1360
Merge pull request #514 from smartdevicelink/bugfix/menu-manager-vers…
crokita Nov 19, 2021
deb5732
Handle language and hmi display language separately on registration
renonick87 Dec 13, 2021
8f4310c
Merge pull request #517 from smartdevicelink/feature/set_language_sep…
renonick87 Dec 14, 2021
fdea868
Explicitly add the null check condition
crokita Dec 15, 2021
62bf611
Merge pull request #516 from smartdevicelink/bugfix/null-access-softb…
crokita Jan 5, 2022
c2ec280
Fix Issue 520
theresalech Feb 15, 2022
525bb61
Merge pull request #521 from smartdevicelink/bugfix/issue-520-typos
theresalech Feb 22, 2022
4a0af4a
update rpc file copyright years to 2022
renonick87 Mar 14, 2022
47eed97
Merge pull request #522 from smartdevicelink/update-copyright-2022
renonick87 Mar 14, 2022
d2f9e40
Update vulnerable packages and fix lint issues
crokita Mar 15, 2022
5972529
Merge pull request #523 from smartdevicelink/bugfix/security-vulnerab…
crokita Mar 15, 2022
c88631c
1.6.0
renonick87 Mar 28, 2022
615b3f4
Merge pull request #525 from smartdevicelink/bugfix/version-1.6
renonick87 Mar 29, 2022
add5cc6
Bump minimist from 1.2.5 to 1.2.6
dependabot[bot] Mar 29, 2022
0bf5cdb
Merge pull request #524 from smartdevicelink/dependabot/npm_and_yarn/…
crokita Mar 29, 2022
9c76ff5
Fix null access error
crokita Mar 30, 2022
89f3a88
Add warnings for invalid voice command strings
crokita Mar 30, 2022
5382a90
Merge pull request #530 from smartdevicelink/bugfix/invalid-voice-com…
crokita Apr 1, 2022
f541e2f
Merge pull request #528 from smartdevicelink/bugfix/present-alert-op-…
crokita Apr 8, 2022
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
Prev Previous commit
Next Next commit
Alignment and bug fixes
  • Loading branch information
crokita committed Nov 15, 2021
commit bd98f41bab8cbcf8374e6c3aae79c7cd68e9ecbb
1 change: 0 additions & 1 deletion lib/js/src/manager/screen/menu/_MenuReplaceOperation.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@ import { _DynamicMenuUpdateAlgorithm } from './_DynamicMenuUpdateAlgorithm';
import { _MenuReplaceUtilities } from './_MenuReplaceUtilities';
import { _MenuCellState } from './enums/_MenuCellState';
import { _ManagerUtility } from '../../_ManagerUtility.js';
import { ImageFieldName } from '../../../rpc/enums/ImageFieldName.js';
import { TextFieldName } from '../../../rpc/enums/TextFieldName.js';
import { _MenuManagerBase } from './_MenuManagerBase';

Expand Down
34 changes: 26 additions & 8 deletions lib/js/src/manager/screen/menu/_MenuReplaceUtilities.js
Original file line number Diff line number Diff line change
Expand Up @@ -157,19 +157,37 @@ class _MenuReplaceUtilities {
* @returns {Boolean} - Whether the capability is supported
*/
static windowCapabilitySupportsPrimaryImage (lifecycleManager = null, windowCapability, cell) {
let supportsImage;
if (cell.isSubMenuCell() && lifecycleManager !== null && lifecycleManager.getSdlMsgVersion() !== null) {
const headUnitRpcVersion = new Version(lifecycleManager.getSdlMsgVersion());
const minRpcVersion = new Version(5, 0, 0);
const maxRpcVersion = new Version(7, 1, 0);
// If RPC version is >= 5.0 && < 7.1
if (headUnitRpcVersion.isNewerThan(minRpcVersion) === 0 || headUnitRpcVersion.isBetween(minRpcVersion, maxRpcVersion) === 1) {
return true;
if (_MenuReplaceUtilities.isRpcVersionBetween5And7(lifecycleManager) && _ManagerUtility.hasImageFieldOfName(windowCapability, ImageFieldName.cmdIcon)) {
supportsImage = true;
} else {
return _ManagerUtility.hasImageFieldOfName(windowCapability, ImageFieldName.subMenuIcon);
supportsImage = _ManagerUtility.hasImageFieldOfName(windowCapability, ImageFieldName.subMenuIcon);
}
} else {
return _ManagerUtility.hasImageFieldOfName(windowCapability, ImageFieldName.cmdIcon);
supportsImage = _ManagerUtility.hasImageFieldOfName(windowCapability, ImageFieldName.cmdIcon);
}
return supportsImage;
}

/**
* Checks whether the version is between 5.0.0 and 7.0.0
* @param {_LifecycleManager} lifecycleManager - A _LifecycleManager instance
* @returns {Boolean} - Whether the version is within bounds
*/
static isRpcVersionBetween5And7 (lifecycleManager = null) {
if (lifecycleManager === null) {
return false;
}
const headUnitRpcVersion = new Version()
.setMajor(lifecycleManager.getSdlMsgVersion().getMajorVersion())
.setMinor(lifecycleManager.getSdlMsgVersion().getMinorVersion())
.setPatch(lifecycleManager.getSdlMsgVersion().getPatchVersion());

const minRpcVersion = new Version(5, 0, 0);
const maxRpcVersion = new Version(7, 0, 0);
// If RPC version is >= 5.0 && < 7.0
return (headUnitRpcVersion.isNewerThan(minRpcVersion) === 0 || headUnitRpcVersion.isBetween(minRpcVersion, maxRpcVersion) === 1);
}

/**
Expand Down
2 changes: 1 addition & 1 deletion tests/managers/screen/menu/MenuManagerTests.js
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ module.exports = function (appClient) {
Validator.assertEquals(mm._dynamicMenuUpdatesMode, SDL.manager.screen.menu.enums.DynamicMenuUpdatesMode.FORCE_OFF);
// when we only send one command to update, we should only be returned one add command
const newArray = [mainCell1, mainCell4];
Validator.assertEquals(SDL.manager.screen.menu._MenuReplaceUtilities.allCommandsForCells(newArray, mm._fileManager, mm._windowCapability, SDL.rpc.enums.MenuLayout.LIST).length, 4);
Validator.assertEquals(SDL.manager.screen.menu._MenuReplaceUtilities.allCommandsForCells(sdlManager._lifecycleManager, newArray, mm._fileManager, mm._windowCapability, SDL.rpc.enums.MenuLayout.LIST).length, 4);
mm._currentHmiLevel = SDL.rpc.enums.HMILevel.HMI_FULL;
mm._setMenuCells(newArray);

Expand Down
83 changes: 78 additions & 5 deletions tests/managers/screen/menu/MenuReplaceUtilitiesTests.js
Original file line number Diff line number Diff line change
Expand Up @@ -145,47 +145,98 @@ module.exports = function (appClient) {
Validator.assertEquals(1, actualMenuCellList[4].getSubCells()[1].getSubCells().length);
});


it('testAddMenuRequestWithCommandId', async function () {
let windowCapability;
let menuCell;
let lcm;
const windowCapFn = SDL.manager.screen.menu._MenuReplaceUtilities.windowCapabilitySupportsPrimaryImage;

// Test cases
const tests = [
{ capOne: false, capTwo: true, isSub: true, version: createSdlMsgVersion(4, 9, 0), assert: true },
{ capOne: false, capTwo: false, isSub: true, version: createSdlMsgVersion(4, 9, 0), assert: false },
{ capOne: false, capTwo: false, isSub: true, version: createSdlMsgVersion(5, 0, 0), assert: false },
{ capOne: true, capTwo: false, isSub: true, version: createSdlMsgVersion(5, 0, 0), assert: true },
{ capOne: false, capTwo: false, isSub: true, version: createSdlMsgVersion(6, 0, 0), assert: false },
{ capOne: true, capTwo: false, isSub: true, version: createSdlMsgVersion(6, 0, 0), assert: true },
{ capOne: false, capTwo: false, isSub: true, version: createSdlMsgVersion(7, 0, 0), assert: false },
{ capOne: false, capTwo: false, isSub: true, version: createSdlMsgVersion(7, 1, 0), assert: false },
{ capOne: false, capTwo: false, isSub: true, version: createSdlMsgVersion(8, 0, 0), assert: false },
{ capOne: false, capTwo: true, isSub: true, version: createSdlMsgVersion(8, 0, 0), assert: true },
{ capOne: false, capTwo: false, isSub: false, version: createSdlMsgVersion(8, 0, 0), assert: false },
{ capOne: true, capTwo: false, isSub: false, version: createSdlMsgVersion(8, 0, 0), assert: true },
];

tests.forEach(test => {
windowCapability = createWindowCapability(test.capOne, test.capTwo);
menuCell = createMockMenuCell(test.isSub);
lcm = createMockLifecycleManager(test.version);
Validator.assertEquals(windowCapFn(lcm, windowCapability, menuCell), test.assert);
});
});

it('testShouldCellIncludeImage', async function () {
let menuCell;
let windowCapability;
let fileManager;
let lcm;
const shouldCellIncludePrimaryImageFromCell = SDL.manager.screen.menu._MenuReplaceUtilities.shouldCellIncludePrimaryImageFromCell;

// Case 1
menuCell = new SDL.manager.screen.menu.MenuCell(Test.GENERAL_STRING)
.setIcon(Test.GENERAL_ARTWORK);
windowCapability = createWindowCapability(true, true);
fileManager = createMockFileManager(true);
Validator.assertTrue(shouldCellIncludePrimaryImageFromCell(menuCell, fileManager, windowCapability));
lcm = createMockLifecycleManager(createSdlMsgVersion(8, 0, 0));
Validator.assertTrue(shouldCellIncludePrimaryImageFromCell(lcm, menuCell, fileManager, windowCapability));

// Case 2 - Image are not supported
menuCell = new SDL.manager.screen.menu.MenuCell(Test.GENERAL_STRING)
.setIcon(Test.GENERAL_ARTWORK);
windowCapability = createWindowCapability(false, false);
fileManager = createMockFileManager(true);
Validator.assertTrue(!shouldCellIncludePrimaryImageFromCell(menuCell, fileManager, windowCapability));
lcm = createMockLifecycleManager(createSdlMsgVersion(8, 0, 0));
Validator.assertTrue(!shouldCellIncludePrimaryImageFromCell(lcm, menuCell, fileManager, windowCapability));

// Case 3 - Artwork is null
menuCell = new SDL.manager.screen.menu.MenuCell(Test.GENERAL_STRING);
windowCapability = createWindowCapability(true, true);
fileManager = createMockFileManager(true);
Validator.assertTrue(!shouldCellIncludePrimaryImageFromCell(menuCell, fileManager, windowCapability));
lcm = createMockLifecycleManager(createSdlMsgVersion(8, 0, 0));
Validator.assertTrue(!shouldCellIncludePrimaryImageFromCell(lcm, menuCell, fileManager, windowCapability));

// Case 4 - Artwork has not been uploaded
menuCell = new SDL.manager.screen.menu.MenuCell(Test.GENERAL_STRING)
.setIcon(Test.GENERAL_ARTWORK);
windowCapability = createWindowCapability(true, true);
fileManager = createMockFileManager(false);
Validator.assertTrue(!shouldCellIncludePrimaryImageFromCell(menuCell, fileManager, windowCapability));
lcm = createMockLifecycleManager(createSdlMsgVersion(8, 0, 0));
Validator.assertTrue(!shouldCellIncludePrimaryImageFromCell(lcm, menuCell, fileManager, windowCapability));

// Case 5 - Artwork is static icon
menuCell = new SDL.manager.screen.menu.MenuCell(Test.GENERAL_STRING)
.setIcon(Test.GENERAL_ARTWORK_STATIC);
windowCapability = createWindowCapability(true, true);
fileManager = createMockFileManager(false);
Validator.assertTrue(shouldCellIncludePrimaryImageFromCell(menuCell, fileManager, windowCapability));
lcm = createMockLifecycleManager(createSdlMsgVersion(8, 0, 0));
Validator.assertTrue(shouldCellIncludePrimaryImageFromCell(lcm, menuCell, fileManager, windowCapability));
});

/**
* Constructs an SdlMsgVersion object
* @param {number} major - The major version
* @param {number} minor - The minor version
* @param {number} patch - The patch version
* @returns {SdlMsgVersion} - A SdlMsgVersion object
*/
function createSdlMsgVersion (major, minor, patch) {
return new SDL.rpc.structs.SdlMsgVersion()
.setMajorVersion(major)
.setMinorVersion(minor)
.setPatchVersion(patch);
}

/**
* Makes a fake file manager object with hasUploadedFile returning a specific boolean
* @param {boolean} hasUploadedFile - The boolean to return when hasUploadedFile is invoked
Expand All @@ -197,6 +248,28 @@ module.exports = function (appClient) {
};
}

/**
* Makes a fake lifecycle manager object with getSdlMsgVersion defined
* @param {SdlMsgVersion} version - The version to return when invoked
* @returns {Object} - A basic object with getSdlMsgVersion implemented
*/
function createMockLifecycleManager (version) {
return {
getSdlMsgVersion: () => version,
};
}

/**
* Makes a fake MenuCell object with isSubMenuCell defined
* @param {boolean} isSubMenu - The boolean to return when isSubMenuCell is invoked
* @returns {Object} - A basic object with isSubMenuCell implemented
*/
function createMockMenuCell (isSubMenu) {
return {
isSubMenuCell: () => isSubMenu,
};
}

/**
* Makes a copy of the menu cell without sub cells
* @param {MenuCell} menuCell - The menu cell to clone
Expand Down