From 049601364d18d2fef97cc47b976c23c8acca9fb4 Mon Sep 17 00:00:00 2001 From: Vladyslav Mustafin Date: Thu, 14 Jan 2021 01:24:33 +0200 Subject: [PATCH 01/11] 0293 oem exclusive app support --- lib/js/src/manager/SdlManager.js | 5 ++ lib/js/src/manager/SdlManagerListener.js | 25 ++++++++++ .../manager/lifecycle/_LifecycleManager.js | 39 ++++++++++++++- lib/js/src/protocol/_SdlProtocolBase.js | 49 +++++++++++++++++++ lib/js/src/protocol/_SdlProtocolListener.js | 27 +++++++++- .../src/protocol/enums/_ControlFrameTags.js | 8 ++- .../messages/RegisterAppInterfaceResponse.js | 23 ++++++++- lib/js/src/session/_SdlSession.js | 14 +++++- lib/js/src/session/_SdlSessionListener.js | 27 +++++++++- .../RegisterAppInterfaceResponseTests.js | 7 ++- 10 files changed, 217 insertions(+), 7 deletions(-) diff --git a/lib/js/src/manager/SdlManager.js b/lib/js/src/manager/SdlManager.js index b0343b04..45ab7e54 100644 --- a/lib/js/src/manager/SdlManager.js +++ b/lib/js/src/manager/SdlManager.js @@ -345,6 +345,11 @@ class SdlManager extends _SdlManagerBase { } this._lifecycleManager = new _LifecycleManager(this._lifecycleConfig, this._lifecycleListener); + if (this._managerListener) { + this._lifecycleManager.setOnVehicleTypeReceived( + this._managerListener.onVehicleTypeReceived.bind(this._managerListener) + ); + } /* FIXME: setSdlSecurity and related methods/classes do not exist if (this._sdlSecList.length > 0) { diff --git a/lib/js/src/manager/SdlManagerListener.js b/lib/js/src/manager/SdlManagerListener.js index ca27a450..1c62534d 100644 --- a/lib/js/src/manager/SdlManagerListener.js +++ b/lib/js/src/manager/SdlManagerListener.js @@ -42,6 +42,7 @@ class SdlManagerListener { this._managerShouldUpdateLifecycle = (language) => { return null; }; + this._onVehicleTypeReceived = null; } /** @@ -126,6 +127,30 @@ class SdlManagerListener { } return null; } + + /** + * Set the OnVehicleTypeReceived event callback function. + * @param {function} callback - A function to invoke when the event is triggered. + * @returns {SdlManagerListener} - A reference to this instance to support method chaining. + */ + setOnVehicleTypeReceived (callback) { + this._onVehicleTypeReceived = callback; + return this; + } + + /** + * Safely attempts to invoke the OnVehicleTypeReceived event callback function. + * @param {VehicleType} vehicleType - the type of vehicle that this session is currently active on. + * @param {String} systemSoftwareVersion - software version of the system. + * @param {String} systemHardwareVersion - hardware version of the system. + * @returns {Boolean} Return true if this session should continue, false if the session should end + */ + onVehicleTypeReceived (vehicleType, systemSoftwareVersion, systemHardwareVersion) { + if (typeof this._onVehicleTypeReceived === 'function') { + return !!this._onVehicleTypeReceived(vehicleType, systemSoftwareVersion, systemHardwareVersion); + } + return true; + } } export { SdlManagerListener }; diff --git a/lib/js/src/manager/lifecycle/_LifecycleManager.js b/lib/js/src/manager/lifecycle/_LifecycleManager.js index 72c454f5..f9328830 100644 --- a/lib/js/src/manager/lifecycle/_LifecycleManager.js +++ b/lib/js/src/manager/lifecycle/_LifecycleManager.js @@ -129,6 +129,8 @@ class _LifecycleManager { this._authToken = authToken; }); + sessionListener.setOnVehicleTypeReceived(this.onVehicleTypeReceived.bind(this)); + return sessionListener; } @@ -406,6 +408,30 @@ class _LifecycleManager { return registerAppInterface; } + /** + * Set the OnVehicleTypeReceived function callback. + * @param {function} listener - A function to be invoked when the event occurs. + * @returns {_LifecycleManager} - A reference to this instance to support method chaining. + */ + setOnVehicleTypeReceived (listener) { + this._onVehicleTypeReceived = listener; + return this; + } + + /** + * Safely attempts to invoke the onVehicleTypeReceived event. + * @param {VehicleType} vehicleType - the type of vehicle that this session is currently active on. + * @param {String} systemSoftwareVersion - software version of the system. + * @param {String} systemHardwareVersion - hardware version of the system. + * @returns {Boolean} Return true if this session should continue, false if the session should end + */ + onVehicleTypeReceived (vehicleType, systemSoftwareVersion, systemHardwareVersion) { + if (typeof this._onVehicleTypeReceived === 'function') { + return !!this._onVehicleTypeReceived(vehicleType, systemSoftwareVersion, systemHardwareVersion); + } + return true; + } + /* ******************************************************************************************************* ********************************** INTERNAL - RPC LISTENERS !! START !! ********************************* @@ -484,6 +510,17 @@ class _LifecycleManager { this._cleanProxy(); } + if (this._rpcSpecVersion.isNewerThan(new Version(7, 0, 0)) === 1) { + const vehicleType = registerAppInterfaceResponse.getVehicleType(); + const systemSoftwareVersion = registerAppInterfaceResponse.getSystemSoftwareVersion(); + const systemHardwareVersion = registerAppInterfaceResponse.getSystemHardwareVersion(); + if (!this.onVehicleTypeReceived(vehicleType, systemSoftwareVersion, systemHardwareVersion)) { + console.warn('(RAI) Disconnecting from head unit, the vehicle is not supported'); + this.sendRpcResolve(new UnregisterAppInterface()); + this._cleanProxy(); + } + } + // parse RAI for system capabilities this._systemCapabilityManager._parseRaiResponse(registerAppInterfaceResponse); } @@ -503,7 +540,7 @@ class _LifecycleManager { } } -_LifecycleManager.MAX_RPC_VERSION = new Version(7, 0, 0); +_LifecycleManager.MAX_RPC_VERSION = new Version(7, 1, 0); _LifecycleManager.REGISTER_APP_INTERFACE_CORRELATION_ID = 65529; _LifecycleManager.UNREGISTER_APP_INTERFACE_CORRELATION_ID = 65530; diff --git a/lib/js/src/protocol/_SdlProtocolBase.js b/lib/js/src/protocol/_SdlProtocolBase.js index 4fbbe6d4..24b9dacb 100644 --- a/lib/js/src/protocol/_SdlProtocolBase.js +++ b/lib/js/src/protocol/_SdlProtocolBase.js @@ -45,6 +45,8 @@ import { RpcCreator } from './../rpc/RpcCreator.js'; import { ImageResolution } from '../rpc/structs/ImageResolution.js'; import { VideoStreamingFormat } from '../rpc/structs/VideoStreamingFormat.js'; +import { VehicleType } from './../rpc/structs/VehicleType.js'; + /** * Base implementation of sdl protocol. * Should be able to handle basic control frames and be able to @@ -268,6 +270,36 @@ class _SdlProtocolBase { return this._messageID++; } + /** + * Gets the Vehicle details received in StartService ACK protocol message + * @returns {Number} - A new numeric message ID. + */ + _getVehicleType(sdlPacket) { + const make = sdlPacket.getTag(_ControlFrameTags.RPC.StartServiceACK.VEHICLE_MAKE); + if (!make) { + return null; + } + const model = sdlPacket.getTag(_ControlFrameTags.RPC.StartServiceACK.VEHICLE_MODEL); + const modelYear = sdlPacket.getTag(_ControlFrameTags.RPC.StartServiceACK.VEHICLE_MODEL_YEAR); + const trim = sdlPacket.getTag(_ControlFrameTags.RPC.StartServiceACK.VEHICLE_TRIM); + + const vehicleType = new VehicleType({ + make, + model, + modelYear, + trim, + }); + + const systemHardwareVersion = sdlPacket.getTag(_ControlFrameTags.RPC.StartServiceACK.VEHICLE_SYSTEM_HARDWARE_VERSION); + const systemSoftwareVersion = sdlPacket.getTag(_ControlFrameTags.RPC.StartServiceACK.VEHICLE_SYSTEM_SOFTWARE_VERSION); + + return { + vehicleType, + systemHardwareVersion, + systemSoftwareVersion, + } + } + /** * Takes an rpc message and sends a single or multi frame packets. * @param {RpcMessage} rpcMessage - Converts an RpcMessage into an _SdlPacket and sends it. @@ -406,6 +438,23 @@ class _SdlProtocolBase { const version = sdlPacket.getVersion(); const serviceType = sdlPacket.getServiceType(); if (version >= 5) { + const vehicleTypeFromPacket = this._getVehicleType(sdlPacket); + if ( + vehicleTypeFromPacket + && this._sdlProtocolListener !== null + && typeof this._sdlProtocolListener.onVehicleTypeReceived === 'function' + ) { + const {vehicleType, systemSoftwareVersion, systemHardwareVersion } = vehicleTypeFromPacket; + if (!this._sdlProtocolListener.onVehicleTypeReceived(vehicleType, systemSoftwareVersion, systemHardwareVersion)) { + console.warn('Disconnecting from head unit, the vehicle is not supported (ACK)'); + this.endService(serviceType, sdlPacket.getSessionID()); + if (serviceType === _ServiceType.RPC && this._transportManager !== null) { + this._transportManager.stop(); + } + return; + } + } + let mtuTag = null; if (serviceType === _ServiceType.RPC) { mtuTag = _ControlFrameTags.RPC.StartServiceACK.MTU; diff --git a/lib/js/src/protocol/_SdlProtocolListener.js b/lib/js/src/protocol/_SdlProtocolListener.js index 09a6499c..4f6f90fe 100644 --- a/lib/js/src/protocol/_SdlProtocolListener.js +++ b/lib/js/src/protocol/_SdlProtocolListener.js @@ -57,6 +57,7 @@ class _SdlProtocolListener { this._onProtocolSessionEnded = null; this._onProtocolSessionEndedNACKed = null; this._onAuthTokenReceived = null; + this._onVehicleTypeReceived = null; this._getSessionId = null; this._onTransportConnected = null; } @@ -189,6 +190,30 @@ class _SdlProtocolListener { } } + /** + * Set the OnVehicleTypeReceived function callback. + * @param {function} listener - A function to be invoked when the event occurs. + * @returns {_SdlProtocolListener} - A reference to this instance to support method chaining. + */ + setOnVehicleTypeReceived (listener) { + this._onVehicleTypeReceived = listener; + return this; + } + + /** + * Safely attempts to invoke the onVehicleTypeReceived event. + * @param {VehicleType} vehicleType - the type of vehicle that this session is currently active on. + * @param {String} systemSoftwareVersion - software version of the system. + * @param {String} systemHardwareVersion - hardware version of the system. + * @returns {Boolean} Return true if this session should continue, false if the session should end + */ + onVehicleTypeReceived (vehicleType, systemSoftwareVersion, systemHardwareVersion) { + if (typeof this._onVehicleTypeReceived === 'function') { + return !!this._onVehicleTypeReceived(vehicleType, systemSoftwareVersion, systemHardwareVersion); + } + return true; + } + /** * Set the GetSessionId function. * @param {function} getter - A function to be invoked to retrieve the session ID. @@ -254,4 +279,4 @@ class _SdlProtocolListener { } } -export { _SdlProtocolListener }; \ No newline at end of file +export { _SdlProtocolListener }; diff --git a/lib/js/src/protocol/enums/_ControlFrameTags.js b/lib/js/src/protocol/enums/_ControlFrameTags.js index 8e921135..31f69f17 100644 --- a/lib/js/src/protocol/enums/_ControlFrameTags.js +++ b/lib/js/src/protocol/enums/_ControlFrameTags.js @@ -72,6 +72,12 @@ _ControlFrameTags.RPC = Object.freeze({ VIDEO_SERVICE_TRANSPORTS: 'videoServiceTransports', /** Auth token to be used for log in into services **/ AUTH_TOKEN: 'authToken', + VEHICLE_MAKE: 'make', + VEHICLE_MODEL: 'model', + VEHICLE_MODEL_YEAR: 'modelYear', + VEHICLE_TRIM: 'trim', + VEHICLE_SYSTEM_SOFTWARE_VERSION: 'systemSoftwareVersion', + VEHICLE_SYSTEM_HARDWARE_VERSION: 'systemHardwareVersion', }, StartServiceACKBase, StartServiceProtocolVersion, StartServiceHashId), StartServiceNAK: NAKBase, @@ -128,4 +134,4 @@ _ControlFrameTags.Video = Object.freeze({ EndServiceNAK: NAKBase, }); -export { _ControlFrameTags }; \ No newline at end of file +export { _ControlFrameTags }; diff --git a/lib/js/src/rpc/messages/RegisterAppInterfaceResponse.js b/lib/js/src/rpc/messages/RegisterAppInterfaceResponse.js index 1d57b8a1..b84fdd28 100644 --- a/lib/js/src/rpc/messages/RegisterAppInterfaceResponse.js +++ b/lib/js/src/rpc/messages/RegisterAppInterfaceResponse.js @@ -1,6 +1,6 @@ /* eslint-disable camelcase */ /* -* Copyright (c) 2020, SmartDeviceLink Consortium, Inc. +* Copyright (c) 2021, SmartDeviceLink Consortium, Inc. * All rights reserved. * * Redistribution and use in source and binary forms, with or without @@ -431,6 +431,26 @@ class RegisterAppInterfaceResponse extends RpcResponse { return this.getParameter(RegisterAppInterfaceResponse.KEY_SYSTEM_SOFTWARE_VERSION); } + /** + * Set the SystemHardwareVersion + * @since SmartDeviceLink 7.1.0 + * @param {String} version - The hardware version of the system - The desired SystemHardwareVersion. + * {'string_min_length': 1, 'string_max_length': 500} + * @returns {RegisterAppInterfaceResponse} - The class instance for method chaining. + */ + setSystemHardwareVersion (version) { + this.setParameter(RegisterAppInterfaceResponse.KEY_SYSTEM_HARDWARE_VERSION, version); + return this; + } + + /** + * Get the SystemHardwareVersion + * @returns {String} - the KEY_SYSTEM_HARDWARE_VERSION value + */ + getSystemHardwareVersion () { + return this.getParameter(RegisterAppInterfaceResponse.KEY_SYSTEM_HARDWARE_VERSION); + } + /** * Set the IconResumed * @since SmartDeviceLink 5.0.0 @@ -469,6 +489,7 @@ RegisterAppInterfaceResponse.KEY_SUPPORTED_DIAG_MODES = 'supportedDiagModes'; RegisterAppInterfaceResponse.KEY_HMI_CAPABILITIES = 'hmiCapabilities'; RegisterAppInterfaceResponse.KEY_SDL_VERSION = 'sdlVersion'; RegisterAppInterfaceResponse.KEY_SYSTEM_SOFTWARE_VERSION = 'systemSoftwareVersion'; +RegisterAppInterfaceResponse.KEY_SYSTEM_HARDWARE_VERSION = 'systemHardwareVersion'; RegisterAppInterfaceResponse.KEY_ICON_RESUMED = 'iconResumed'; export { RegisterAppInterfaceResponse }; \ No newline at end of file diff --git a/lib/js/src/session/_SdlSession.js b/lib/js/src/session/_SdlSession.js index a282056b..63ae85d4 100644 --- a/lib/js/src/session/_SdlSession.js +++ b/lib/js/src/session/_SdlSession.js @@ -77,6 +77,7 @@ class _SdlSession { sdlProtocolListener.setOnRpcMessageReceived(this.onRpcMessageReceived.bind(this)); sdlProtocolListener.setOnTransportConnected(this.onTransportConnected.bind(this)); sdlProtocolListener.setOnAuthTokenReceived(this.onAuthTokenReceived.bind(this)); + sdlProtocolListener.setOnVehicleTypeReceived(this.onVehicleTypeReceived.bind(this)); sdlProtocolListener.setGetDesiredVideoParams(this.getDesiredVideoParams.bind(this)); sdlProtocolListener.setSetAcceptedVideoParams(this.setAcceptedVideoParams.bind(this)); @@ -168,6 +169,17 @@ class _SdlSession { this._sdlSessionListener.onAuthTokenReceived(authToken, this._sessionId); } + /** + * A way to determine if this SDL session should continue to be active while + * connected to the determined vehicle type. + * @param {VehicleType} vehicleType - the type of vehicle that this session is currently active on. + * @param {String} systemSoftwareVersion - software version of the system. + * @param {String} systemHardwareVersion - hardware version of the system. + * @returns {Boolean} Return true if this session should continue, false if the session should end + */ + onVehicleTypeReceived (vehicleType, systemSoftwareVersion, systemHardwareVersion) { + return this._sdlSessionListener.onVehicleTypeReceived(vehicleType, systemSoftwareVersion, systemHardwareVersion); + } /** ********************************************************************************************************************************************************************** * END: _SdlProtocolListener implemented methods @@ -324,4 +336,4 @@ class _SdlSession { } } -export { _SdlSession }; \ No newline at end of file +export { _SdlSession }; diff --git a/lib/js/src/session/_SdlSessionListener.js b/lib/js/src/session/_SdlSessionListener.js index 41d85572..f78b3b49 100644 --- a/lib/js/src/session/_SdlSessionListener.js +++ b/lib/js/src/session/_SdlSessionListener.js @@ -47,6 +47,7 @@ class _SdlSessionListener { this._onRpcMessageReceived = null; this._onTransportConnected = null; this._onAuthTokenReceived = null; + this._onVehicleTypeReceived = null; } /** @@ -159,6 +160,30 @@ class _SdlSessionListener { } } + /** + * Set the onVehicleTypeReceived function. + * @param {function} listener - A function to be invoked when the event occurs. + * @returns {_SdlSessionListener} - A reference to this instance to allow method chaining. + */ + setOnVehicleTypeReceived (listener) { + this._onVehicleTypeReceived = listener; + return this; + } + + /** + * Safely attempts to invoke the onVehicleTypeReceived event. + * @param {VehicleType} vehicleType - the type of vehicle that this session is currently active on. + * @param {String} systemSoftwareVersion - software version of the system. + * @param {String} systemHardwareVersion - hardware version of the system. + * @returns {Boolean} Return true if this session should continue, false if the session should end + */ + onVehicleTypeReceived (vehicleType, systemSoftwareVersion, systemHardwareVersion) { + if (typeof this._onVehicleTypeReceived === 'function') { + return !!this._onVehicleTypeReceived(vehicleType, systemSoftwareVersion, systemHardwareVersion); + } + return true; + } + /** * Safely attempts to invoke the onRpcMessageReceived event. * @param {RpcMessage} rpcMessage - An RpcMessage. @@ -179,4 +204,4 @@ class _SdlSessionListener { } } -export { _SdlSessionListener }; \ No newline at end of file +export { _SdlSessionListener }; diff --git a/tests/node/rpc/messages/RegisterAppInterfaceResponseTests.js b/tests/node/rpc/messages/RegisterAppInterfaceResponseTests.js index 72d753e8..50a195d8 100644 --- a/tests/node/rpc/messages/RegisterAppInterfaceResponseTests.js +++ b/tests/node/rpc/messages/RegisterAppInterfaceResponseTests.js @@ -32,6 +32,7 @@ describe('RegisterAppInterfaceResponseTests', function () { // TODO sdlVersion https://github.com/smartdevicelink/rpc_spec/blob/version/6_0_0/MOBILE_API.xml#L4663 unused? msg.setSystemSoftwareVersion(Test.GENERAL_STRING); msg.setIconResumed(Test.GENERAL_BOOLEAN); + msg.setSystemHardwareVersion(Test.GENERAL_STRING); return msg; }; @@ -57,6 +58,7 @@ describe('RegisterAppInterfaceResponseTests', function () { expectedParameters[RegisterAppInterfaceResponse.KEY_HMI_CAPABILITIES] = Test.GENERAL_HMICAPABILITIES.getParameters(); expectedParameters[RegisterAppInterfaceResponse.KEY_SYSTEM_SOFTWARE_VERSION] = Test.GENERAL_STRING; expectedParameters[RegisterAppInterfaceResponse.KEY_ICON_RESUMED] = Test.GENERAL_BOOLEAN; + expectedParameters[RegisterAppInterfaceResponse.KEY_SYSTEM_HARDWARE_VERSION] = Test.GENERAL_STRING; return expectedParameters; }; @@ -94,6 +96,7 @@ describe('RegisterAppInterfaceResponseTests', function () { const testHmiCapabilities = msg.getHmiCapabilities(); const testSystemSoftwareVersion = msg.getSystemSoftwareVersion(); const testIconResumed = msg.getIconResumed(); + const testSystemHardwareVersion = msg.getSystemHardwareVersion(); // Valid Tests Validator.validateSdlMsgVersion(Test.GENERAL_SDLMSGVERSION, testMsgVersion); @@ -114,6 +117,7 @@ describe('RegisterAppInterfaceResponseTests', function () { Validator.validateHMICapabilities(Test.GENERAL_HMICAPABILITIES, testHmiCapabilities); Validator.assertEquals(Test.GENERAL_STRING, testSystemSoftwareVersion); Validator.assertEquals(Test.GENERAL_BOOLEAN, testIconResumed); + Validator.assertEquals(Test.GENERAL_STRING, testSystemHardwareVersion); // Invalid/Null Tests msg = new RegisterAppInterfaceResponse(); @@ -141,8 +145,9 @@ describe('RegisterAppInterfaceResponseTests', function () { Validator.assertNullOrUndefined(msg.getHmiCapabilities()); Validator.assertNullOrUndefined(msg.getSystemSoftwareVersion()); Validator.assertNullOrUndefined(msg.getIconResumed()); + Validator.assertNullOrUndefined(msg.getSystemHardwareVersion()); done(); }); -}); \ No newline at end of file +}); From 0497c8003c5fc49a51663aa38b2aa2a4df7dd69b Mon Sep 17 00:00:00 2001 From: Vladyslav Mustafin Date: Fri, 22 Jan 2021 09:25:01 +0200 Subject: [PATCH 02/11] * reverted system[Hardware|Software]Version parameters in onVehicleTypeReceived and adjust the code to match the current 0293 proposal state * added didReceiveVehicleType flag, to avoid double firing onVehicleTypeReceived in RAI response --- lib/js/src/manager/SdlManagerListener.js | 6 +-- lib/js/src/manager/_SdlManagerBase.js | 2 +- .../manager/lifecycle/_LifecycleManager.js | 15 ++++--- lib/js/src/protocol/_SdlProtocolBase.js | 41 +++++++++---------- lib/js/src/protocol/_SdlProtocolListener.js | 6 +-- .../messages/RegisterAppInterfaceResponse.js | 23 +---------- lib/js/src/session/_SdlSession.js | 17 ++++++-- lib/js/src/session/_SdlSessionListener.js | 6 +-- .../RegisterAppInterfaceResponseTests.js | 7 +--- 9 files changed, 48 insertions(+), 75 deletions(-) diff --git a/lib/js/src/manager/SdlManagerListener.js b/lib/js/src/manager/SdlManagerListener.js index 1c62534d..ad87cda3 100644 --- a/lib/js/src/manager/SdlManagerListener.js +++ b/lib/js/src/manager/SdlManagerListener.js @@ -141,13 +141,11 @@ class SdlManagerListener { /** * Safely attempts to invoke the OnVehicleTypeReceived event callback function. * @param {VehicleType} vehicleType - the type of vehicle that this session is currently active on. - * @param {String} systemSoftwareVersion - software version of the system. - * @param {String} systemHardwareVersion - hardware version of the system. * @returns {Boolean} Return true if this session should continue, false if the session should end */ - onVehicleTypeReceived (vehicleType, systemSoftwareVersion, systemHardwareVersion) { + onVehicleTypeReceived (vehicleType) { if (typeof this._onVehicleTypeReceived === 'function') { - return !!this._onVehicleTypeReceived(vehicleType, systemSoftwareVersion, systemHardwareVersion); + return !!this._onVehicleTypeReceived(vehicleType); } return true; } diff --git a/lib/js/src/manager/_SdlManagerBase.js b/lib/js/src/manager/_SdlManagerBase.js index 88574350..f27b715a 100644 --- a/lib/js/src/manager/_SdlManagerBase.js +++ b/lib/js/src/manager/_SdlManagerBase.js @@ -39,7 +39,7 @@ class _SdlManagerBase { * @class * @private * @param {AppConfig} appConfig - An instance of AppConfig describing the application's metadata and desired transport - * @param {ManagerListener} managerListener - An instance of ManagerListener to be used to listen for manager events + * @param {SdlManagerListener} managerListener - An instance of ManagerListener to be used to listen for manager events */ constructor (appConfig = null, managerListener = null) { this._state = -1; diff --git a/lib/js/src/manager/lifecycle/_LifecycleManager.js b/lib/js/src/manager/lifecycle/_LifecycleManager.js index f9328830..af5e4d3a 100644 --- a/lib/js/src/manager/lifecycle/_LifecycleManager.js +++ b/lib/js/src/manager/lifecycle/_LifecycleManager.js @@ -421,13 +421,11 @@ class _LifecycleManager { /** * Safely attempts to invoke the onVehicleTypeReceived event. * @param {VehicleType} vehicleType - the type of vehicle that this session is currently active on. - * @param {String} systemSoftwareVersion - software version of the system. - * @param {String} systemHardwareVersion - hardware version of the system. * @returns {Boolean} Return true if this session should continue, false if the session should end */ - onVehicleTypeReceived (vehicleType, systemSoftwareVersion, systemHardwareVersion) { + onVehicleTypeReceived (vehicleType) { if (typeof this._onVehicleTypeReceived === 'function') { - return !!this._onVehicleTypeReceived(vehicleType, systemSoftwareVersion, systemHardwareVersion); + return !!this._onVehicleTypeReceived(vehicleType); } return true; } @@ -510,11 +508,12 @@ class _LifecycleManager { this._cleanProxy(); } - if (this._rpcSpecVersion.isNewerThan(new Version(7, 0, 0)) === 1) { + // to avoid double firing the onVehicleTypeReceived event + // try to define vehicleType and fire onVehicleTypeReceived here + // only if that was not received from SdlSession before + if (!this._sdlSession.didReceiveVehicleType()) { const vehicleType = registerAppInterfaceResponse.getVehicleType(); - const systemSoftwareVersion = registerAppInterfaceResponse.getSystemSoftwareVersion(); - const systemHardwareVersion = registerAppInterfaceResponse.getSystemHardwareVersion(); - if (!this.onVehicleTypeReceived(vehicleType, systemSoftwareVersion, systemHardwareVersion)) { + if (!this.onVehicleTypeReceived(vehicleType)) { console.warn('(RAI) Disconnecting from head unit, the vehicle is not supported'); this.sendRpcResolve(new UnregisterAppInterface()); this._cleanProxy(); diff --git a/lib/js/src/protocol/_SdlProtocolBase.js b/lib/js/src/protocol/_SdlProtocolBase.js index 24b9dacb..155a9683 100644 --- a/lib/js/src/protocol/_SdlProtocolBase.js +++ b/lib/js/src/protocol/_SdlProtocolBase.js @@ -38,14 +38,14 @@ import { _FrameType } from './enums/_FrameType.js'; import { _MessageFrameAssembler } from './_MessageFrameAssembler.js'; import { _SdlPacket } from './_SdlPacket.js'; import { _ControlFrameTags } from './enums/_ControlFrameTags.js'; -import { _BitConverter } from './../util/_BitConverter.js'; +import { _BitConverter } from '../util/_BitConverter'; import { _SdlPacketFactory } from './_SdlPacketFactory.js'; -import { RpcCreator } from './../rpc/RpcCreator.js'; +import { RpcCreator } from '../rpc/RpcCreator'; import { ImageResolution } from '../rpc/structs/ImageResolution.js'; import { VideoStreamingFormat } from '../rpc/structs/VideoStreamingFormat.js'; -import { VehicleType } from './../rpc/structs/VehicleType.js'; +import { VehicleType } from '../rpc/structs/VehicleType'; /** * Base implementation of sdl protocol. @@ -272,32 +272,29 @@ class _SdlProtocolBase { /** * Gets the Vehicle details received in StartService ACK protocol message - * @returns {Number} - A new numeric message ID. + * @returns {VehicleType|null} - A RPC VehicleType struct received from the packet if exists null otherwise. */ _getVehicleType(sdlPacket) { const make = sdlPacket.getTag(_ControlFrameTags.RPC.StartServiceACK.VEHICLE_MAKE); - if (!make) { - return null; - } const model = sdlPacket.getTag(_ControlFrameTags.RPC.StartServiceACK.VEHICLE_MODEL); const modelYear = sdlPacket.getTag(_ControlFrameTags.RPC.StartServiceACK.VEHICLE_MODEL_YEAR); const trim = sdlPacket.getTag(_ControlFrameTags.RPC.StartServiceACK.VEHICLE_TRIM); - const vehicleType = new VehicleType({ + // TODO: awaiting 0293 revisions to process those fields + const systemHardwareVersion = sdlPacket.getTag(_ControlFrameTags.RPC.StartServiceACK.VEHICLE_SYSTEM_HARDWARE_VERSION); + const systemSoftwareVersion = sdlPacket.getTag(_ControlFrameTags.RPC.StartServiceACK.VEHICLE_SYSTEM_SOFTWARE_VERSION); + + // if no any VehicleType tags in the packet just return null + if (!make && !model && !modelYear && !trim) { + return null; + } + + return new VehicleType({ make, model, modelYear, trim, }); - - const systemHardwareVersion = sdlPacket.getTag(_ControlFrameTags.RPC.StartServiceACK.VEHICLE_SYSTEM_HARDWARE_VERSION); - const systemSoftwareVersion = sdlPacket.getTag(_ControlFrameTags.RPC.StartServiceACK.VEHICLE_SYSTEM_SOFTWARE_VERSION); - - return { - vehicleType, - systemHardwareVersion, - systemSoftwareVersion, - } } /** @@ -438,15 +435,15 @@ class _SdlProtocolBase { const version = sdlPacket.getVersion(); const serviceType = sdlPacket.getServiceType(); if (version >= 5) { - const vehicleTypeFromPacket = this._getVehicleType(sdlPacket); + // check if vehicleType data exists then fire onVehicleTypeReceived protocol listener event + const vehicleType = this._getVehicleType(sdlPacket); if ( - vehicleTypeFromPacket + vehicleType && this._sdlProtocolListener !== null && typeof this._sdlProtocolListener.onVehicleTypeReceived === 'function' ) { - const {vehicleType, systemSoftwareVersion, systemHardwareVersion } = vehicleTypeFromPacket; - if (!this._sdlProtocolListener.onVehicleTypeReceived(vehicleType, systemSoftwareVersion, systemHardwareVersion)) { - console.warn('Disconnecting from head unit, the vehicle is not supported (ACK)'); + if (!this._sdlProtocolListener.onVehicleTypeReceived(vehicleType)) { + console.warn('(ACK) Disconnecting from head unit, the vehicle is not supported'); this.endService(serviceType, sdlPacket.getSessionID()); if (serviceType === _ServiceType.RPC && this._transportManager !== null) { this._transportManager.stop(); diff --git a/lib/js/src/protocol/_SdlProtocolListener.js b/lib/js/src/protocol/_SdlProtocolListener.js index 4f6f90fe..81c2629c 100644 --- a/lib/js/src/protocol/_SdlProtocolListener.js +++ b/lib/js/src/protocol/_SdlProtocolListener.js @@ -203,13 +203,11 @@ class _SdlProtocolListener { /** * Safely attempts to invoke the onVehicleTypeReceived event. * @param {VehicleType} vehicleType - the type of vehicle that this session is currently active on. - * @param {String} systemSoftwareVersion - software version of the system. - * @param {String} systemHardwareVersion - hardware version of the system. * @returns {Boolean} Return true if this session should continue, false if the session should end */ - onVehicleTypeReceived (vehicleType, systemSoftwareVersion, systemHardwareVersion) { + onVehicleTypeReceived (vehicleType) { if (typeof this._onVehicleTypeReceived === 'function') { - return !!this._onVehicleTypeReceived(vehicleType, systemSoftwareVersion, systemHardwareVersion); + return !!this._onVehicleTypeReceived(vehicleType); } return true; } diff --git a/lib/js/src/rpc/messages/RegisterAppInterfaceResponse.js b/lib/js/src/rpc/messages/RegisterAppInterfaceResponse.js index b84fdd28..1d57b8a1 100644 --- a/lib/js/src/rpc/messages/RegisterAppInterfaceResponse.js +++ b/lib/js/src/rpc/messages/RegisterAppInterfaceResponse.js @@ -1,6 +1,6 @@ /* eslint-disable camelcase */ /* -* Copyright (c) 2021, SmartDeviceLink Consortium, Inc. +* Copyright (c) 2020, SmartDeviceLink Consortium, Inc. * All rights reserved. * * Redistribution and use in source and binary forms, with or without @@ -431,26 +431,6 @@ class RegisterAppInterfaceResponse extends RpcResponse { return this.getParameter(RegisterAppInterfaceResponse.KEY_SYSTEM_SOFTWARE_VERSION); } - /** - * Set the SystemHardwareVersion - * @since SmartDeviceLink 7.1.0 - * @param {String} version - The hardware version of the system - The desired SystemHardwareVersion. - * {'string_min_length': 1, 'string_max_length': 500} - * @returns {RegisterAppInterfaceResponse} - The class instance for method chaining. - */ - setSystemHardwareVersion (version) { - this.setParameter(RegisterAppInterfaceResponse.KEY_SYSTEM_HARDWARE_VERSION, version); - return this; - } - - /** - * Get the SystemHardwareVersion - * @returns {String} - the KEY_SYSTEM_HARDWARE_VERSION value - */ - getSystemHardwareVersion () { - return this.getParameter(RegisterAppInterfaceResponse.KEY_SYSTEM_HARDWARE_VERSION); - } - /** * Set the IconResumed * @since SmartDeviceLink 5.0.0 @@ -489,7 +469,6 @@ RegisterAppInterfaceResponse.KEY_SUPPORTED_DIAG_MODES = 'supportedDiagModes'; RegisterAppInterfaceResponse.KEY_HMI_CAPABILITIES = 'hmiCapabilities'; RegisterAppInterfaceResponse.KEY_SDL_VERSION = 'sdlVersion'; RegisterAppInterfaceResponse.KEY_SYSTEM_SOFTWARE_VERSION = 'systemSoftwareVersion'; -RegisterAppInterfaceResponse.KEY_SYSTEM_HARDWARE_VERSION = 'systemHardwareVersion'; RegisterAppInterfaceResponse.KEY_ICON_RESUMED = 'iconResumed'; export { RegisterAppInterfaceResponse }; \ No newline at end of file diff --git a/lib/js/src/session/_SdlSession.js b/lib/js/src/session/_SdlSession.js index 63ae85d4..4da3704f 100644 --- a/lib/js/src/session/_SdlSession.js +++ b/lib/js/src/session/_SdlSession.js @@ -61,6 +61,7 @@ class _SdlSession { this._sdlProtocolListener = this._setupSdlProtocolListener(); this._sdlProtocol = new _SdlProtocol(baseTransportConfig, this._sdlProtocolListener); + this._didReceiveVehicleType = false; } /** @@ -169,16 +170,24 @@ class _SdlSession { this._sdlSessionListener.onAuthTokenReceived(authToken, this._sessionId); } + /** + * A way to determine if VehicleType already received + * @returns {Boolean} Return true if received + */ + didReceiveVehicleType() { + return this._didReceiveVehicleType; + } + /** * A way to determine if this SDL session should continue to be active while * connected to the determined vehicle type. * @param {VehicleType} vehicleType - the type of vehicle that this session is currently active on. - * @param {String} systemSoftwareVersion - software version of the system. - * @param {String} systemHardwareVersion - hardware version of the system. * @returns {Boolean} Return true if this session should continue, false if the session should end */ - onVehicleTypeReceived (vehicleType, systemSoftwareVersion, systemHardwareVersion) { - return this._sdlSessionListener.onVehicleTypeReceived(vehicleType, systemSoftwareVersion, systemHardwareVersion); + onVehicleTypeReceived (vehicleType) { + // set the flag as this event fires only once if VehicleType was received + this._didReceiveVehicleType = true; + return this._sdlSessionListener.onVehicleTypeReceived(vehicleType); } /** ********************************************************************************************************************************************************************** diff --git a/lib/js/src/session/_SdlSessionListener.js b/lib/js/src/session/_SdlSessionListener.js index f78b3b49..8887d58a 100644 --- a/lib/js/src/session/_SdlSessionListener.js +++ b/lib/js/src/session/_SdlSessionListener.js @@ -173,13 +173,11 @@ class _SdlSessionListener { /** * Safely attempts to invoke the onVehicleTypeReceived event. * @param {VehicleType} vehicleType - the type of vehicle that this session is currently active on. - * @param {String} systemSoftwareVersion - software version of the system. - * @param {String} systemHardwareVersion - hardware version of the system. * @returns {Boolean} Return true if this session should continue, false if the session should end */ - onVehicleTypeReceived (vehicleType, systemSoftwareVersion, systemHardwareVersion) { + onVehicleTypeReceived (vehicleType) { if (typeof this._onVehicleTypeReceived === 'function') { - return !!this._onVehicleTypeReceived(vehicleType, systemSoftwareVersion, systemHardwareVersion); + return !!this._onVehicleTypeReceived(vehicleType); } return true; } diff --git a/tests/node/rpc/messages/RegisterAppInterfaceResponseTests.js b/tests/node/rpc/messages/RegisterAppInterfaceResponseTests.js index 50a195d8..72d753e8 100644 --- a/tests/node/rpc/messages/RegisterAppInterfaceResponseTests.js +++ b/tests/node/rpc/messages/RegisterAppInterfaceResponseTests.js @@ -32,7 +32,6 @@ describe('RegisterAppInterfaceResponseTests', function () { // TODO sdlVersion https://github.com/smartdevicelink/rpc_spec/blob/version/6_0_0/MOBILE_API.xml#L4663 unused? msg.setSystemSoftwareVersion(Test.GENERAL_STRING); msg.setIconResumed(Test.GENERAL_BOOLEAN); - msg.setSystemHardwareVersion(Test.GENERAL_STRING); return msg; }; @@ -58,7 +57,6 @@ describe('RegisterAppInterfaceResponseTests', function () { expectedParameters[RegisterAppInterfaceResponse.KEY_HMI_CAPABILITIES] = Test.GENERAL_HMICAPABILITIES.getParameters(); expectedParameters[RegisterAppInterfaceResponse.KEY_SYSTEM_SOFTWARE_VERSION] = Test.GENERAL_STRING; expectedParameters[RegisterAppInterfaceResponse.KEY_ICON_RESUMED] = Test.GENERAL_BOOLEAN; - expectedParameters[RegisterAppInterfaceResponse.KEY_SYSTEM_HARDWARE_VERSION] = Test.GENERAL_STRING; return expectedParameters; }; @@ -96,7 +94,6 @@ describe('RegisterAppInterfaceResponseTests', function () { const testHmiCapabilities = msg.getHmiCapabilities(); const testSystemSoftwareVersion = msg.getSystemSoftwareVersion(); const testIconResumed = msg.getIconResumed(); - const testSystemHardwareVersion = msg.getSystemHardwareVersion(); // Valid Tests Validator.validateSdlMsgVersion(Test.GENERAL_SDLMSGVERSION, testMsgVersion); @@ -117,7 +114,6 @@ describe('RegisterAppInterfaceResponseTests', function () { Validator.validateHMICapabilities(Test.GENERAL_HMICAPABILITIES, testHmiCapabilities); Validator.assertEquals(Test.GENERAL_STRING, testSystemSoftwareVersion); Validator.assertEquals(Test.GENERAL_BOOLEAN, testIconResumed); - Validator.assertEquals(Test.GENERAL_STRING, testSystemHardwareVersion); // Invalid/Null Tests msg = new RegisterAppInterfaceResponse(); @@ -145,9 +141,8 @@ describe('RegisterAppInterfaceResponseTests', function () { Validator.assertNullOrUndefined(msg.getHmiCapabilities()); Validator.assertNullOrUndefined(msg.getSystemSoftwareVersion()); Validator.assertNullOrUndefined(msg.getIconResumed()); - Validator.assertNullOrUndefined(msg.getSystemHardwareVersion()); done(); }); -}); +}); \ No newline at end of file From a2d7ab13d2510f0502db281ba0c841393b5af46d Mon Sep 17 00:00:00 2001 From: Vladyslav Mustafin Date: Fri, 22 Jan 2021 09:27:52 +0200 Subject: [PATCH 03/11] minor fixes --- lib/js/src/protocol/_SdlProtocolBase.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/lib/js/src/protocol/_SdlProtocolBase.js b/lib/js/src/protocol/_SdlProtocolBase.js index 155a9683..59120283 100644 --- a/lib/js/src/protocol/_SdlProtocolBase.js +++ b/lib/js/src/protocol/_SdlProtocolBase.js @@ -38,14 +38,14 @@ import { _FrameType } from './enums/_FrameType.js'; import { _MessageFrameAssembler } from './_MessageFrameAssembler.js'; import { _SdlPacket } from './_SdlPacket.js'; import { _ControlFrameTags } from './enums/_ControlFrameTags.js'; -import { _BitConverter } from '../util/_BitConverter'; +import { _BitConverter } from '../util/_BitConverter.js'; import { _SdlPacketFactory } from './_SdlPacketFactory.js'; -import { RpcCreator } from '../rpc/RpcCreator'; +import { RpcCreator } from '../rpc/RpcCreator.js'; import { ImageResolution } from '../rpc/structs/ImageResolution.js'; import { VideoStreamingFormat } from '../rpc/structs/VideoStreamingFormat.js'; -import { VehicleType } from '../rpc/structs/VehicleType'; +import { VehicleType } from '../rpc/structs/VehicleType.js'; /** * Base implementation of sdl protocol. From af981f89441510eaee149e7cb8b351dc64fc5c84 Mon Sep 17 00:00:00 2001 From: Yehor Malovanyi Date: Fri, 22 Jan 2021 15:25:29 +0200 Subject: [PATCH 04/11] Update tests for LifecycleManagerTests.js --- .../managers/lifecycle/LifecycleManagerTests.js | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/tests/managers/lifecycle/LifecycleManagerTests.js b/tests/managers/lifecycle/LifecycleManagerTests.js index 3727636e..1522c922 100644 --- a/tests/managers/lifecycle/LifecycleManagerTests.js +++ b/tests/managers/lifecycle/LifecycleManagerTests.js @@ -52,5 +52,21 @@ module.exports = function (appClient) { Validator.assertNotNullUndefined(version.getPatchVersion()); done(); }); + it('testOnVehicleTypeReceived', function (done) { + const mockVehicleType = {}; + const defaultResult = true; + let actualResult = sdlManager.getFileManager()._lifecycleManager.onVehicleTypeReceived(mockVehicleType); + Validator.assertEquals(actualResult, defaultResult); + + const testResult = false; + const testListener = function (vehicleType) { + return testResult; + }; + sdlManager.getFileManager()._lifecycleManager.setOnVehicleTypeReceived(testListener); + actualResult = sdlManager.getFileManager()._lifecycleManager.onVehicleTypeReceived(mockVehicleType); + Validator.assertEquals(actualResult, testResult); + + done(); + }); }); }; \ No newline at end of file From 8f4069d78f444a847eae467fbbd9e37ae9b610ed Mon Sep 17 00:00:00 2001 From: Yehor Malovanyi Date: Thu, 28 Jan 2021 17:02:59 +0200 Subject: [PATCH 05/11] Fix linter warnings --- lib/js/src/protocol/_SdlProtocolBase.js | 9 +++++---- lib/js/src/session/_SdlSession.js | 2 +- tests/managers/lifecycle/LifecycleManagerTests.js | 6 +++--- 3 files changed, 9 insertions(+), 8 deletions(-) diff --git a/lib/js/src/protocol/_SdlProtocolBase.js b/lib/js/src/protocol/_SdlProtocolBase.js index 59120283..c4b033c2 100644 --- a/lib/js/src/protocol/_SdlProtocolBase.js +++ b/lib/js/src/protocol/_SdlProtocolBase.js @@ -272,9 +272,10 @@ class _SdlProtocolBase { /** * Gets the Vehicle details received in StartService ACK protocol message + * @param {_SdlPacket} sdlPacket - The _SdlPacket to send. * @returns {VehicleType|null} - A RPC VehicleType struct received from the packet if exists null otherwise. */ - _getVehicleType(sdlPacket) { + _getVehicleType (sdlPacket) { const make = sdlPacket.getTag(_ControlFrameTags.RPC.StartServiceACK.VEHICLE_MAKE); const model = sdlPacket.getTag(_ControlFrameTags.RPC.StartServiceACK.VEHICLE_MODEL); const modelYear = sdlPacket.getTag(_ControlFrameTags.RPC.StartServiceACK.VEHICLE_MODEL_YEAR); @@ -438,9 +439,9 @@ class _SdlProtocolBase { // check if vehicleType data exists then fire onVehicleTypeReceived protocol listener event const vehicleType = this._getVehicleType(sdlPacket); if ( - vehicleType - && this._sdlProtocolListener !== null - && typeof this._sdlProtocolListener.onVehicleTypeReceived === 'function' + vehicleType + && this._sdlProtocolListener !== null + && typeof this._sdlProtocolListener.onVehicleTypeReceived === 'function' ) { if (!this._sdlProtocolListener.onVehicleTypeReceived(vehicleType)) { console.warn('(ACK) Disconnecting from head unit, the vehicle is not supported'); diff --git a/lib/js/src/session/_SdlSession.js b/lib/js/src/session/_SdlSession.js index 4da3704f..4a57f56b 100644 --- a/lib/js/src/session/_SdlSession.js +++ b/lib/js/src/session/_SdlSession.js @@ -174,7 +174,7 @@ class _SdlSession { * A way to determine if VehicleType already received * @returns {Boolean} Return true if received */ - didReceiveVehicleType() { + didReceiveVehicleType () { return this._didReceiveVehicleType; } diff --git a/tests/managers/lifecycle/LifecycleManagerTests.js b/tests/managers/lifecycle/LifecycleManagerTests.js index 1522c922..fecef44c 100644 --- a/tests/managers/lifecycle/LifecycleManagerTests.js +++ b/tests/managers/lifecycle/LifecycleManagerTests.js @@ -55,15 +55,15 @@ module.exports = function (appClient) { it('testOnVehicleTypeReceived', function (done) { const mockVehicleType = {}; const defaultResult = true; - let actualResult = sdlManager.getFileManager()._lifecycleManager.onVehicleTypeReceived(mockVehicleType); + let actualResult = sdlManager._lifecycleManager.onVehicleTypeReceived(mockVehicleType); Validator.assertEquals(actualResult, defaultResult); const testResult = false; const testListener = function (vehicleType) { return testResult; }; - sdlManager.getFileManager()._lifecycleManager.setOnVehicleTypeReceived(testListener); - actualResult = sdlManager.getFileManager()._lifecycleManager.onVehicleTypeReceived(mockVehicleType); + sdlManager._lifecycleManager.setOnVehicleTypeReceived(testListener); + actualResult = sdlManager._lifecycleManager.onVehicleTypeReceived(mockVehicleType); Validator.assertEquals(actualResult, testResult); done(); From f855ca473b61c9cf54be08ab7ea2a88d19e4d652 Mon Sep 17 00:00:00 2001 From: Bogdan Mykolaichuk Date: Fri, 29 Jan 2021 20:01:28 +0200 Subject: [PATCH 06/11] [SDL-0293] New revision adjustments --- lib/js/src/manager/SdlManager.js | 4 +- lib/js/src/manager/SdlManagerListener.js | 22 ++-- .../manager/lifecycle/_LifecycleManager.js | 31 ++--- lib/js/src/protocol/_SdlProtocolBase.js | 20 ++-- lib/js/src/protocol/_SdlProtocolListener.js | 18 +-- .../messages/RegisterAppInterfaceResponse.js | 4 +- lib/js/src/session/_SdlSession.js | 18 +-- lib/js/src/session/_SdlSessionListener.js | 18 +-- lib/js/src/util/SystemInfo.js | 106 ++++++++++++++++++ .../lifecycle/LifecycleManagerTests.js | 12 +- 10 files changed, 181 insertions(+), 72 deletions(-) create mode 100644 lib/js/src/util/SystemInfo.js diff --git a/lib/js/src/manager/SdlManager.js b/lib/js/src/manager/SdlManager.js index 45ab7e54..ee1a1405 100644 --- a/lib/js/src/manager/SdlManager.js +++ b/lib/js/src/manager/SdlManager.js @@ -346,8 +346,8 @@ class SdlManager extends _SdlManagerBase { this._lifecycleManager = new _LifecycleManager(this._lifecycleConfig, this._lifecycleListener); if (this._managerListener) { - this._lifecycleManager.setOnVehicleTypeReceived( - this._managerListener.onVehicleTypeReceived.bind(this._managerListener) + this._lifecycleManager.setOnSystemInfoReceived( + this._managerListener.onSystemInfoReceived.bind(this._managerListener) ); } diff --git a/lib/js/src/manager/SdlManagerListener.js b/lib/js/src/manager/SdlManagerListener.js index ad87cda3..043a884d 100644 --- a/lib/js/src/manager/SdlManagerListener.js +++ b/lib/js/src/manager/SdlManagerListener.js @@ -42,7 +42,7 @@ class SdlManagerListener { this._managerShouldUpdateLifecycle = (language) => { return null; }; - this._onVehicleTypeReceived = null; + this._onSystemInfoReceived = null; } /** @@ -129,23 +129,23 @@ class SdlManagerListener { } /** - * Set the OnVehicleTypeReceived event callback function. - * @param {function} callback - A function to invoke when the event is triggered. - * @returns {SdlManagerListener} - A reference to this instance to support method chaining. + * Set the onSystemInfoReceived function. + * @param {function} listener - A function to be invoked when the event occurs. + * @returns {SdlManagerListener} - A reference to this instance to allow method chaining. */ - setOnVehicleTypeReceived (callback) { - this._onVehicleTypeReceived = callback; + setOnSystemInfoReceived (listener) { + this._onSystemInfoReceived = listener; return this; } /** - * Safely attempts to invoke the OnVehicleTypeReceived event callback function. - * @param {VehicleType} vehicleType - the type of vehicle that this session is currently active on. + * Safely attempts to invoke the onSystemInfoReceived event. + * @param {SystemInfo} systemInfo - the system info of vehicle that this session is currently active on. * @returns {Boolean} Return true if this session should continue, false if the session should end */ - onVehicleTypeReceived (vehicleType) { - if (typeof this._onVehicleTypeReceived === 'function') { - return !!this._onVehicleTypeReceived(vehicleType); + onSystemInfoReceived (systemInfo) { + if (typeof this._onSystemInfoReceived === 'function') { + return !!this._onSystemInfoReceived(systemInfo); } return true; } diff --git a/lib/js/src/manager/lifecycle/_LifecycleManager.js b/lib/js/src/manager/lifecycle/_LifecycleManager.js index af5e4d3a..394ce04b 100644 --- a/lib/js/src/manager/lifecycle/_LifecycleManager.js +++ b/lib/js/src/manager/lifecycle/_LifecycleManager.js @@ -42,6 +42,7 @@ import { _ArrayTools } from '../../util/_ArrayTools.js'; import { SdlMsgVersion } from '../../rpc/structs/SdlMsgVersion.js'; import { FunctionID } from '../../rpc/enums/FunctionID.js'; import { _ServiceType } from '../../protocol/enums/_ServiceType.js'; +import { SystemInfo } from '../../util/SystemInfo.js'; /** * This class should also be marked private and behind the SdlManager API @@ -129,7 +130,7 @@ class _LifecycleManager { this._authToken = authToken; }); - sessionListener.setOnVehicleTypeReceived(this.onVehicleTypeReceived.bind(this)); + sessionListener.setOnSystemInfoReceived(this.onSystemInfoReceived.bind(this)); return sessionListener; } @@ -409,23 +410,23 @@ class _LifecycleManager { } /** - * Set the OnVehicleTypeReceived function callback. + * Set the onSystemInfoReceived function. * @param {function} listener - A function to be invoked when the event occurs. - * @returns {_LifecycleManager} - A reference to this instance to support method chaining. + * @returns {_LifecycleManager} - A reference to this instance to allow method chaining. */ - setOnVehicleTypeReceived (listener) { - this._onVehicleTypeReceived = listener; + setOnSystemInfoReceived (listener) { + this._onSystemInfoReceived = listener; return this; } /** - * Safely attempts to invoke the onVehicleTypeReceived event. - * @param {VehicleType} vehicleType - the type of vehicle that this session is currently active on. + * Safely attempts to invoke the onSystemInfoReceived event. + * @param {SystemInfo} systemInfo - the system info of vehicle that this session is currently active on. * @returns {Boolean} Return true if this session should continue, false if the session should end */ - onVehicleTypeReceived (vehicleType) { - if (typeof this._onVehicleTypeReceived === 'function') { - return !!this._onVehicleTypeReceived(vehicleType); + onSystemInfoReceived (systemInfo) { + if (typeof this._onSystemInfoReceived === 'function') { + return !!this._onSystemInfoReceived(systemInfo); } return true; } @@ -508,12 +509,12 @@ class _LifecycleManager { this._cleanProxy(); } - // to avoid double firing the onVehicleTypeReceived event - // try to define vehicleType and fire onVehicleTypeReceived here + // to avoid double firing the onSystemInfoReceived event + // try to define systemInfo and fire onSystemInfoReceived here // only if that was not received from SdlSession before - if (!this._sdlSession.didReceiveVehicleType()) { - const vehicleType = registerAppInterfaceResponse.getVehicleType(); - if (!this.onVehicleTypeReceived(vehicleType)) { + if (!this._sdlSession.didReceiveSystemInfo()) { + const systemInfo = new SystemInfo(registerAppInterfaceResponse.getVehicleType(), registerAppInterfaceResponse.getSystemSoftwareVersion()) ; + if (!this.onSystemInfoReceived(systemInfo)) { console.warn('(RAI) Disconnecting from head unit, the vehicle is not supported'); this.sendRpcResolve(new UnregisterAppInterface()); this._cleanProxy(); diff --git a/lib/js/src/protocol/_SdlProtocolBase.js b/lib/js/src/protocol/_SdlProtocolBase.js index c4b033c2..38cb0dbd 100644 --- a/lib/js/src/protocol/_SdlProtocolBase.js +++ b/lib/js/src/protocol/_SdlProtocolBase.js @@ -46,6 +46,7 @@ import { ImageResolution } from '../rpc/structs/ImageResolution.js'; import { VideoStreamingFormat } from '../rpc/structs/VideoStreamingFormat.js'; import { VehicleType } from '../rpc/structs/VehicleType.js'; +import { SystemInfo } from '../util/SystemInfo.js'; /** * Base implementation of sdl protocol. @@ -275,27 +276,26 @@ class _SdlProtocolBase { * @param {_SdlPacket} sdlPacket - The _SdlPacket to send. * @returns {VehicleType|null} - A RPC VehicleType struct received from the packet if exists null otherwise. */ - _getVehicleType (sdlPacket) { + _getSystemInfo (sdlPacket) { const make = sdlPacket.getTag(_ControlFrameTags.RPC.StartServiceACK.VEHICLE_MAKE); const model = sdlPacket.getTag(_ControlFrameTags.RPC.StartServiceACK.VEHICLE_MODEL); const modelYear = sdlPacket.getTag(_ControlFrameTags.RPC.StartServiceACK.VEHICLE_MODEL_YEAR); const trim = sdlPacket.getTag(_ControlFrameTags.RPC.StartServiceACK.VEHICLE_TRIM); - // TODO: awaiting 0293 revisions to process those fields const systemHardwareVersion = sdlPacket.getTag(_ControlFrameTags.RPC.StartServiceACK.VEHICLE_SYSTEM_HARDWARE_VERSION); const systemSoftwareVersion = sdlPacket.getTag(_ControlFrameTags.RPC.StartServiceACK.VEHICLE_SYSTEM_SOFTWARE_VERSION); // if no any VehicleType tags in the packet just return null - if (!make && !model && !modelYear && !trim) { + if (!make && !model && !modelYear && !trim && !systemSoftwareVersion && !systemHardwareVersion) { return null; } - return new VehicleType({ + return new SystemInfo(new VehicleType({ make, model, modelYear, trim, - }); + }), systemSoftwareVersion, systemHardwareVersion); } /** @@ -436,14 +436,14 @@ class _SdlProtocolBase { const version = sdlPacket.getVersion(); const serviceType = sdlPacket.getServiceType(); if (version >= 5) { - // check if vehicleType data exists then fire onVehicleTypeReceived protocol listener event - const vehicleType = this._getVehicleType(sdlPacket); + // check if systemInfo data exists then fire onSystemInfoReceived protocol listener event + const systemInfo = this._getSystemInfo(sdlPacket); if ( - vehicleType + systemInfo && this._sdlProtocolListener !== null - && typeof this._sdlProtocolListener.onVehicleTypeReceived === 'function' + && typeof this._sdlProtocolListener.onSystemInfoReceived === 'function' ) { - if (!this._sdlProtocolListener.onVehicleTypeReceived(vehicleType)) { + if (!this._sdlProtocolListener.onSystemInfoReceived(systemInfo)) { console.warn('(ACK) Disconnecting from head unit, the vehicle is not supported'); this.endService(serviceType, sdlPacket.getSessionID()); if (serviceType === _ServiceType.RPC && this._transportManager !== null) { diff --git a/lib/js/src/protocol/_SdlProtocolListener.js b/lib/js/src/protocol/_SdlProtocolListener.js index 81c2629c..96480443 100644 --- a/lib/js/src/protocol/_SdlProtocolListener.js +++ b/lib/js/src/protocol/_SdlProtocolListener.js @@ -57,7 +57,7 @@ class _SdlProtocolListener { this._onProtocolSessionEnded = null; this._onProtocolSessionEndedNACKed = null; this._onAuthTokenReceived = null; - this._onVehicleTypeReceived = null; + this._onSystemInfoReceived = null; this._getSessionId = null; this._onTransportConnected = null; } @@ -191,23 +191,23 @@ class _SdlProtocolListener { } /** - * Set the OnVehicleTypeReceived function callback. + * Set the OnSystemInfoReceived function callback. * @param {function} listener - A function to be invoked when the event occurs. * @returns {_SdlProtocolListener} - A reference to this instance to support method chaining. */ - setOnVehicleTypeReceived (listener) { - this._onVehicleTypeReceived = listener; + setOnSystemInfoReceived (listener) { + this._onSystemInfoReceived = listener; return this; } /** - * Safely attempts to invoke the onVehicleTypeReceived event. - * @param {VehicleType} vehicleType - the type of vehicle that this session is currently active on. + * Safely attempts to invoke the onSystemInfoReceived event. + * @param {SystemInfo} systemInfo - the system info of vehicle that this session is currently active on. * @returns {Boolean} Return true if this session should continue, false if the session should end */ - onVehicleTypeReceived (vehicleType) { - if (typeof this._onVehicleTypeReceived === 'function') { - return !!this._onVehicleTypeReceived(vehicleType); + onSystemInfoReceived (systemInfo) { + if (typeof this._onSystemInfoReceived === 'function') { + return !!this._onSystemInfoReceived(systemInfo); } return true; } diff --git a/lib/js/src/rpc/messages/RegisterAppInterfaceResponse.js b/lib/js/src/rpc/messages/RegisterAppInterfaceResponse.js index 1d57b8a1..0216eb5c 100644 --- a/lib/js/src/rpc/messages/RegisterAppInterfaceResponse.js +++ b/lib/js/src/rpc/messages/RegisterAppInterfaceResponse.js @@ -1,6 +1,6 @@ /* eslint-disable camelcase */ /* -* Copyright (c) 2020, SmartDeviceLink Consortium, Inc. +* Copyright (c) 2021, SmartDeviceLink Consortium, Inc. * All rights reserved. * * Redistribution and use in source and binary forms, with or without @@ -334,6 +334,7 @@ class RegisterAppInterfaceResponse extends RpcResponse { /** * Set the VehicleType * @since SmartDeviceLink 2.0.0 + * @deprecated in SmartDeviceLink 7.1.0 * @param {VehicleType} type - Specifies the vehicle's type. See VehicleType. - The desired VehicleType. * @returns {RegisterAppInterfaceResponse} - The class instance for method chaining. */ @@ -414,6 +415,7 @@ class RegisterAppInterfaceResponse extends RpcResponse { /** * Set the SystemSoftwareVersion * @since SmartDeviceLink 3.0.0 + * @deprecated in SmartDeviceLink 7.1.0 * @param {String} version - The software version of the system that implements the SmartDeviceLink core. - The desired SystemSoftwareVersion. * {'string_min_length': 1, 'string_max_length': 100} * @returns {RegisterAppInterfaceResponse} - The class instance for method chaining. diff --git a/lib/js/src/session/_SdlSession.js b/lib/js/src/session/_SdlSession.js index 4a57f56b..f5d2e34a 100644 --- a/lib/js/src/session/_SdlSession.js +++ b/lib/js/src/session/_SdlSession.js @@ -61,7 +61,7 @@ class _SdlSession { this._sdlProtocolListener = this._setupSdlProtocolListener(); this._sdlProtocol = new _SdlProtocol(baseTransportConfig, this._sdlProtocolListener); - this._didReceiveVehicleType = false; + this._didReceiveSystemInfo = false; } /** @@ -78,7 +78,7 @@ class _SdlSession { sdlProtocolListener.setOnRpcMessageReceived(this.onRpcMessageReceived.bind(this)); sdlProtocolListener.setOnTransportConnected(this.onTransportConnected.bind(this)); sdlProtocolListener.setOnAuthTokenReceived(this.onAuthTokenReceived.bind(this)); - sdlProtocolListener.setOnVehicleTypeReceived(this.onVehicleTypeReceived.bind(this)); + sdlProtocolListener.setOnSystemInfoReceived(this.onSystemInfoReceived.bind(this)); sdlProtocolListener.setGetDesiredVideoParams(this.getDesiredVideoParams.bind(this)); sdlProtocolListener.setSetAcceptedVideoParams(this.setAcceptedVideoParams.bind(this)); @@ -171,23 +171,23 @@ class _SdlSession { } /** - * A way to determine if VehicleType already received + * A way to determine if SystemInfo already received * @returns {Boolean} Return true if received */ - didReceiveVehicleType () { - return this._didReceiveVehicleType; + didReceiveSystemInfo () { + return this._didReceiveSystemInfo; } /** * A way to determine if this SDL session should continue to be active while * connected to the determined vehicle type. - * @param {VehicleType} vehicleType - the type of vehicle that this session is currently active on. + * @param {SystemInfo} systemInfo - the type of vehicle that this session is currently active on. * @returns {Boolean} Return true if this session should continue, false if the session should end */ - onVehicleTypeReceived (vehicleType) { + onSystemInfoReceived (systemInfo) { // set the flag as this event fires only once if VehicleType was received - this._didReceiveVehicleType = true; - return this._sdlSessionListener.onVehicleTypeReceived(vehicleType); + this._didReceiveSystemInfo = true; + return this._sdlSessionListener.setOnSystemInfoReceived(systemInfo); } /** ********************************************************************************************************************************************************************** diff --git a/lib/js/src/session/_SdlSessionListener.js b/lib/js/src/session/_SdlSessionListener.js index 8887d58a..6fff7215 100644 --- a/lib/js/src/session/_SdlSessionListener.js +++ b/lib/js/src/session/_SdlSessionListener.js @@ -47,7 +47,7 @@ class _SdlSessionListener { this._onRpcMessageReceived = null; this._onTransportConnected = null; this._onAuthTokenReceived = null; - this._onVehicleTypeReceived = null; + this._onSystemInfoReceived = null; } /** @@ -161,23 +161,23 @@ class _SdlSessionListener { } /** - * Set the onVehicleTypeReceived function. + * Set the onSystemInfoReceived function. * @param {function} listener - A function to be invoked when the event occurs. * @returns {_SdlSessionListener} - A reference to this instance to allow method chaining. */ - setOnVehicleTypeReceived (listener) { - this._onVehicleTypeReceived = listener; + setOnSystemInfoReceived (listener) { + this._onSystemInfoReceived = listener; return this; } /** - * Safely attempts to invoke the onVehicleTypeReceived event. - * @param {VehicleType} vehicleType - the type of vehicle that this session is currently active on. + * Safely attempts to invoke the onSystemInfoReceived event. + * @param {SystemInfo} systemInfo - the system info of vehicle that this session is currently active on. * @returns {Boolean} Return true if this session should continue, false if the session should end */ - onVehicleTypeReceived (vehicleType) { - if (typeof this._onVehicleTypeReceived === 'function') { - return !!this._onVehicleTypeReceived(vehicleType); + onSystemInfoReceived (systemInfo) { + if (typeof this._onSystemInfoReceived === 'function') { + return !!this._onSystemInfoReceived(systemInfo); } return true; } diff --git a/lib/js/src/util/SystemInfo.js b/lib/js/src/util/SystemInfo.js new file mode 100644 index 00000000..26dc72dc --- /dev/null +++ b/lib/js/src/util/SystemInfo.js @@ -0,0 +1,106 @@ +/* + * Copyright (c) 2021, SmartDeviceLink Consortium, Inc. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * Redistributions of source code must retain the above copyright notice, this + * list of conditions and the following disclaimer. + * + * Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following + * disclaimer in the documentation and/or other materials provided with the + * distribution. + * + * Neither the name of the SmartDeviceLink Consortium Inc. nor the names of + * its contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +class SystemInfo { + /** + * Initializes an instance of SystemInfo. + * @class + * @param {VehicleType} vehicleType - the type of vehicle + * @param {String} systemSoftwareVersion - the software version of the vehicle system + * @param {String} systemHardwareVersion - the hardware version of the vehicle system + */ + constructor ( + vehicleType = null, + systemSoftwareVersion = null, + systemHardwareVersion = null + ) { + this.setVehicleType(vehicleType); + this.setSystemSoftwareVersion(systemSoftwareVersion); + this.setSystemHardwareVersion(systemHardwareVersion); + } + + /** + * Set the type of vehicle. + * @param {VehicleType} vehicleType - The type of vehicle. + * @returns {SystemInfo} - A reference to the class instance for method chaining. + */ + setVehicleType (vehicleType) { + this._vehicleType = vehicleType; + return this; + } + + /** + * Get the type of vehicle + * @returns {VehicleType} - The type of vehicle. + */ + getVehicleType () { + return this._vehicleType; + } + + /** + * Set the software version of the vehicle system. + * @param {String} systemSoftwareVersion - The software version of the vehicle system. + * @returns {SystemInfo} - A reference to the class instance for method chaining. + */ + setSystemSoftwareVersion (systemSoftwareVersion) { + this._systemSoftwareVersion = systemSoftwareVersion; + return this; + } + + /** + * Get the software version of the vehicle system + * @returns {String} - The software version of the vehicle system. + */ + getSystemSoftwareVersion () { + return this._systemSoftwareVersion; + } + + /** + * Set the hardware version of the vehicle system. + * @param {String} systemHardwareVersion - The hardware version of the vehicle system. + * @returns {SystemInfo} - A reference to the class instance for method chaining. + */ + setSystemHardwareVersion (systemHardwareVersion) { + this._systemHardwareVersion = systemHardwareVersion; + return this; + } + + /** + * Get the hardware version of the vehicle system + * @returns {String} - The hardware version of the vehicle system. + */ + getSystemHardwareVersion () { + return this._systemHardwareVersion; + } +} + +export { SystemInfo }; \ No newline at end of file diff --git a/tests/managers/lifecycle/LifecycleManagerTests.js b/tests/managers/lifecycle/LifecycleManagerTests.js index fecef44c..36b1aae2 100644 --- a/tests/managers/lifecycle/LifecycleManagerTests.js +++ b/tests/managers/lifecycle/LifecycleManagerTests.js @@ -52,18 +52,18 @@ module.exports = function (appClient) { Validator.assertNotNullUndefined(version.getPatchVersion()); done(); }); - it('testOnVehicleTypeReceived', function (done) { - const mockVehicleType = {}; + it('testOnSystemInfoReceived', function (done) { + const mockSystemInfo = {}; const defaultResult = true; - let actualResult = sdlManager._lifecycleManager.onVehicleTypeReceived(mockVehicleType); + let actualResult = sdlManager._lifecycleManager.onSystemInfoReceived(mockSystemInfo); Validator.assertEquals(actualResult, defaultResult); const testResult = false; - const testListener = function (vehicleType) { + const testListener = function (mockSystemInfo) { return testResult; }; - sdlManager._lifecycleManager.setOnVehicleTypeReceived(testListener); - actualResult = sdlManager._lifecycleManager.onVehicleTypeReceived(mockVehicleType); + sdlManager._lifecycleManager.setInSystemInfoReceived(testListener); + actualResult = sdlManager._lifecycleManager.onSystemInfoReceived(mockSystemInfo); Validator.assertEquals(actualResult, testResult); done(); From 76c53506929991c83bd7037b2823e2f38eb03bad Mon Sep 17 00:00:00 2001 From: Vladyslav Mustafin Date: Fri, 29 Jan 2021 20:37:54 +0200 Subject: [PATCH 07/11] [SDL-0293] - minor fix --- lib/js/src/protocol/_SdlProtocolBase.js | 2 +- lib/js/src/session/_SdlSession.js | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/js/src/protocol/_SdlProtocolBase.js b/lib/js/src/protocol/_SdlProtocolBase.js index 38cb0dbd..d798477a 100644 --- a/lib/js/src/protocol/_SdlProtocolBase.js +++ b/lib/js/src/protocol/_SdlProtocolBase.js @@ -274,7 +274,7 @@ class _SdlProtocolBase { /** * Gets the Vehicle details received in StartService ACK protocol message * @param {_SdlPacket} sdlPacket - The _SdlPacket to send. - * @returns {VehicleType|null} - A RPC VehicleType struct received from the packet if exists null otherwise. + * @returns {SystemInfo|null} - A RPC VehicleType struct received from the packet if exists null otherwise. */ _getSystemInfo (sdlPacket) { const make = sdlPacket.getTag(_ControlFrameTags.RPC.StartServiceACK.VEHICLE_MAKE); diff --git a/lib/js/src/session/_SdlSession.js b/lib/js/src/session/_SdlSession.js index f5d2e34a..40c74494 100644 --- a/lib/js/src/session/_SdlSession.js +++ b/lib/js/src/session/_SdlSession.js @@ -187,7 +187,7 @@ class _SdlSession { onSystemInfoReceived (systemInfo) { // set the flag as this event fires only once if VehicleType was received this._didReceiveSystemInfo = true; - return this._sdlSessionListener.setOnSystemInfoReceived(systemInfo); + return this._sdlSessionListener.onSystemInfoReceived(systemInfo); } /** ********************************************************************************************************************************************************************** From 8317fb6469a1ac1bf332b42611b632264199ac31 Mon Sep 17 00:00:00 2001 From: Vladyslav Mustafin Date: Thu, 11 Feb 2021 01:55:28 +0200 Subject: [PATCH 08/11] Alignment with Java suite implementation --- .../manager/lifecycle/_LifecycleManager.js | 6 +- lib/js/src/protocol/_SdlProtocolBase.js | 75 ++++++++++--------- .../src/protocol/enums/_ControlFrameTags.js | 18 +++-- lib/js/src/session/_SdlSession.js | 10 +-- 4 files changed, 59 insertions(+), 50 deletions(-) diff --git a/lib/js/src/manager/lifecycle/_LifecycleManager.js b/lib/js/src/manager/lifecycle/_LifecycleManager.js index 394ce04b..d2aa6394 100644 --- a/lib/js/src/manager/lifecycle/_LifecycleManager.js +++ b/lib/js/src/manager/lifecycle/_LifecycleManager.js @@ -511,11 +511,11 @@ class _LifecycleManager { // to avoid double firing the onSystemInfoReceived event // try to define systemInfo and fire onSystemInfoReceived here - // only if that was not received from SdlSession before - if (!this._sdlSession.didReceiveSystemInfo()) { + // only if that was not checked in SdlSession before + if (!this._sdlSession.didCheckSystemInfo()) { const systemInfo = new SystemInfo(registerAppInterfaceResponse.getVehicleType(), registerAppInterfaceResponse.getSystemSoftwareVersion()) ; if (!this.onSystemInfoReceived(systemInfo)) { - console.warn('(RAI) Disconnecting from head unit, the vehicle is not supported'); + console.warn('Disconnecting from head unit, the system info was not accepted.'); this.sendRpcResolve(new UnregisterAppInterface()); this._cleanProxy(); } diff --git a/lib/js/src/protocol/_SdlProtocolBase.js b/lib/js/src/protocol/_SdlProtocolBase.js index d798477a..2897e911 100644 --- a/lib/js/src/protocol/_SdlProtocolBase.js +++ b/lib/js/src/protocol/_SdlProtocolBase.js @@ -219,7 +219,7 @@ class _SdlProtocolBase { */ _setVersion (version) { if (version > 5) { - this._protocolVersion = new Version('5.1.0'); // protect for future, proxy only supports v5 or lower + this._protocolVersion = new Version('5.4.0'); // protect for future, proxy only supports v5 or lower this.headerSize = this.constructor.V2_HEADER_SIZE; this._mtus[_ServiceType.RPC] = this.constructor.V3_V4_MTU_SIZE; } else if (version === 5) { @@ -272,30 +272,34 @@ class _SdlProtocolBase { } /** - * Gets the Vehicle details received in StartService ACK protocol message - * @param {_SdlPacket} sdlPacket - The _SdlPacket to send. - * @returns {SystemInfo|null} - A RPC VehicleType struct received from the packet if exists null otherwise. + * Extracts the SystemInfo out of a packet + * @param {_SdlPacket} sdlPacket - should be a StartServiceACK for the RPC service. + * @returns {SystemInfo|null} - an instance of SystemInfo if the information is available, null otherwise. */ - _getSystemInfo (sdlPacket) { - const make = sdlPacket.getTag(_ControlFrameTags.RPC.StartServiceACK.VEHICLE_MAKE); - const model = sdlPacket.getTag(_ControlFrameTags.RPC.StartServiceACK.VEHICLE_MODEL); - const modelYear = sdlPacket.getTag(_ControlFrameTags.RPC.StartServiceACK.VEHICLE_MODEL_YEAR); - const trim = sdlPacket.getTag(_ControlFrameTags.RPC.StartServiceACK.VEHICLE_TRIM); + _extractSystemInfo (sdlPacket) { + const make = sdlPacket.getTag(_ControlFrameTags.RPC.StartServiceACK.MAKE); + const model = sdlPacket.getTag(_ControlFrameTags.RPC.StartServiceACK.MODEL); + const modelYear = sdlPacket.getTag(_ControlFrameTags.RPC.StartServiceACK.MODEL_YEAR); + const trim = sdlPacket.getTag(_ControlFrameTags.RPC.StartServiceACK.TRIM); - const systemHardwareVersion = sdlPacket.getTag(_ControlFrameTags.RPC.StartServiceACK.VEHICLE_SYSTEM_HARDWARE_VERSION); - const systemSoftwareVersion = sdlPacket.getTag(_ControlFrameTags.RPC.StartServiceACK.VEHICLE_SYSTEM_SOFTWARE_VERSION); + const systemHardwareVersion = sdlPacket.getTag(_ControlFrameTags.RPC.StartServiceACK.SYSTEM_HARDWARE_VERSION); + const systemSoftwareVersion = sdlPacket.getTag(_ControlFrameTags.RPC.StartServiceACK.SYSTEM_SOFTWARE_VERSION); // if no any VehicleType tags in the packet just return null - if (!make && !model && !modelYear && !trim && !systemSoftwareVersion && !systemHardwareVersion) { + let vehicleType = null; + if (make || model || modelYear || trim) { + vehicleType = new VehicleType({ + make, + model, + modelYear, + trim, + }); + } + if (!vehicleType && !systemSoftwareVersion && !systemHardwareVersion) { return null; } - return new SystemInfo(new VehicleType({ - make, - model, - modelYear, - trim, - }), systemSoftwareVersion, systemHardwareVersion); + return new SystemInfo(vehicleType, systemSoftwareVersion, systemHardwareVersion); } /** @@ -436,23 +440,6 @@ class _SdlProtocolBase { const version = sdlPacket.getVersion(); const serviceType = sdlPacket.getServiceType(); if (version >= 5) { - // check if systemInfo data exists then fire onSystemInfoReceived protocol listener event - const systemInfo = this._getSystemInfo(sdlPacket); - if ( - systemInfo - && this._sdlProtocolListener !== null - && typeof this._sdlProtocolListener.onSystemInfoReceived === 'function' - ) { - if (!this._sdlProtocolListener.onSystemInfoReceived(systemInfo)) { - console.warn('(ACK) Disconnecting from head unit, the vehicle is not supported'); - this.endService(serviceType, sdlPacket.getSessionID()); - if (serviceType === _ServiceType.RPC && this._transportManager !== null) { - this._transportManager.stop(); - } - return; - } - } - let mtuTag = null; if (serviceType === _ServiceType.RPC) { mtuTag = _ControlFrameTags.RPC.StartServiceACK.MTU; @@ -483,6 +470,22 @@ class _SdlProtocolBase { sdlPacket.getTag(_ControlFrameTags.RPC.StartServiceACK.AUTH_TOKEN) ); } + + if ((this._protocolVersion.isNewerThan(new Version(5, 4, 0)) >= 0)) { + // check if systemInfo data exists then fire onSystemInfoReceived protocol listener event + const systemInfo = this._extractSystemInfo(sdlPacket); + if ( + systemInfo + && this._sdlProtocolListener !== null + && typeof this._sdlProtocolListener.onSystemInfoReceived === 'function' + ) { + if (!this._sdlProtocolListener.onSystemInfoReceived(systemInfo)) { + console.warn('Disconnecting from head unit, the system info was not accepted.'); + this.endSession(); + return; + } + } + } } else if (serviceType === _ServiceType.VIDEO) { if (this._sdlProtocolListener !== null) { const acceptedResolution = new ImageResolution(); @@ -635,6 +638,6 @@ _SdlProtocolBase.V3_V4_MTU_SIZE = 131072; /** * Max supported protocol version in this release of the library */ -_SdlProtocolBase.MAX_PROTOCOL_VERSION = new Version(5, 3, 0); +_SdlProtocolBase.MAX_PROTOCOL_VERSION = new Version(5, 4, 0); export { _SdlProtocolBase }; diff --git a/lib/js/src/protocol/enums/_ControlFrameTags.js b/lib/js/src/protocol/enums/_ControlFrameTags.js index 31f69f17..51e2b6ed 100644 --- a/lib/js/src/protocol/enums/_ControlFrameTags.js +++ b/lib/js/src/protocol/enums/_ControlFrameTags.js @@ -72,12 +72,18 @@ _ControlFrameTags.RPC = Object.freeze({ VIDEO_SERVICE_TRANSPORTS: 'videoServiceTransports', /** Auth token to be used for log in into services **/ AUTH_TOKEN: 'authToken', - VEHICLE_MAKE: 'make', - VEHICLE_MODEL: 'model', - VEHICLE_MODEL_YEAR: 'modelYear', - VEHICLE_TRIM: 'trim', - VEHICLE_SYSTEM_SOFTWARE_VERSION: 'systemSoftwareVersion', - VEHICLE_SYSTEM_HARDWARE_VERSION: 'systemHardwareVersion', + /** + * Vehicle info to describe connected device + */ + MAKE: 'make', + MODEL: 'model', + MODEL_YEAR: 'modelYear', + TRIM: 'trim', + /** + * System specifics for hardware and software versions of connected device + */ + SYSTEM_SOFTWARE_VERSION: 'systemSoftwareVersion', + SYSTEM_HARDWARE_VERSION: 'systemHardwareVersion', }, StartServiceACKBase, StartServiceProtocolVersion, StartServiceHashId), StartServiceNAK: NAKBase, diff --git a/lib/js/src/session/_SdlSession.js b/lib/js/src/session/_SdlSession.js index 40c74494..09ed97a2 100644 --- a/lib/js/src/session/_SdlSession.js +++ b/lib/js/src/session/_SdlSession.js @@ -61,7 +61,7 @@ class _SdlSession { this._sdlProtocolListener = this._setupSdlProtocolListener(); this._sdlProtocol = new _SdlProtocol(baseTransportConfig, this._sdlProtocolListener); - this._didReceiveSystemInfo = false; + this._didCheckSystemInfo = false; } /** @@ -171,11 +171,11 @@ class _SdlSession { } /** - * A way to determine if SystemInfo already received + * A way to determine if SystemInfo already checked * @returns {Boolean} Return true if received */ - didReceiveSystemInfo () { - return this._didReceiveSystemInfo; + didCheckSystemInfo () { + return this._didCheckSystemInfo; } /** @@ -186,7 +186,7 @@ class _SdlSession { */ onSystemInfoReceived (systemInfo) { // set the flag as this event fires only once if VehicleType was received - this._didReceiveSystemInfo = true; + this._didCheckSystemInfo = true; return this._sdlSessionListener.onSystemInfoReceived(systemInfo); } From b874414c87602f4b59155f140b842c8a9d2470ba Mon Sep 17 00:00:00 2001 From: Vladyslav Mustafin Date: Fri, 12 Feb 2021 09:18:03 +0200 Subject: [PATCH 09/11] Alignment with Java suite implementation --- .../manager/lifecycle/_LifecycleManager.js | 19 ++++-- lib/js/src/protocol/_SdlProtocolBase.js | 52 +-------------- lib/js/src/protocol/_SdlProtocolListener.js | 34 ++-------- lib/js/src/session/_SdlSession.js | 65 ++++++++++++------- lib/js/src/session/_SdlSessionListener.js | 34 ++-------- .../lifecycle/LifecycleManagerTests.js | 3 +- 6 files changed, 71 insertions(+), 136 deletions(-) diff --git a/lib/js/src/manager/lifecycle/_LifecycleManager.js b/lib/js/src/manager/lifecycle/_LifecycleManager.js index d2aa6394..10610a0b 100644 --- a/lib/js/src/manager/lifecycle/_LifecycleManager.js +++ b/lib/js/src/manager/lifecycle/_LifecycleManager.js @@ -91,6 +91,8 @@ class _LifecycleManager { this._systemCapabilityManager = new SystemCapabilityManager(this); this._encryptionLifecycleManager = null; this._registerAppInterfaceResponse = null; + + this._didCheckSystemInfo = false; } /** @@ -100,7 +102,7 @@ class _LifecycleManager { */ _createSessionListener () { const sessionListener = new _SdlSessionListener(); - sessionListener.setOnProtocolSessionStarted((serviceType, sessionID, version, correlationID, hashID, isEncrypted) => { + sessionListener.setOnProtocolSessionStarted((serviceType, sessionID, version, correlationID, hashID, isEncrypted, systemInfo) => { // Session has been started if (this._minimumProtocolVersion !== null && this._minimumProtocolVersion.isNewerThan(this.getProtocolVersion()) === 1) { console.warn(`Disconnecting from head unit, the configured minimum protocol version ${this._minimumProtocolVersion} is greater than the supported protocol version ${this.getProtocolVersion()}`); @@ -108,6 +110,15 @@ class _LifecycleManager { return this._cleanProxy(); } + if (systemInfo && !this._didCheckSystemInfo) { + this._didCheckSystemInfo = true; + if (!this._onSystemInfoReceived(systemInfo)) { + console.warn('Disconnecting from head unit, the system info was not accepted.'); + this._sdlSession.endService(serviceType, this._sdlSession.getSessionId()); + return this._cleanProxy(); + } + } + if (serviceType === _ServiceType.RPC) { if (this._lifecycleConfig !== null && this._lifecycleConfig !== undefined) { this.sendRpcResolve(this._createRegisterAppInterface()); @@ -509,10 +520,8 @@ class _LifecycleManager { this._cleanProxy(); } - // to avoid double firing the onSystemInfoReceived event - // try to define systemInfo and fire onSystemInfoReceived here - // only if that was not checked in SdlSession before - if (!this._sdlSession.didCheckSystemInfo()) { + if (!this._didCheckSystemInfo) { + this._didCheckSystemInfo = true; const systemInfo = new SystemInfo(registerAppInterfaceResponse.getVehicleType(), registerAppInterfaceResponse.getSystemSoftwareVersion()) ; if (!this.onSystemInfoReceived(systemInfo)) { console.warn('Disconnecting from head unit, the system info was not accepted.'); diff --git a/lib/js/src/protocol/_SdlProtocolBase.js b/lib/js/src/protocol/_SdlProtocolBase.js index 2897e911..3879cb55 100644 --- a/lib/js/src/protocol/_SdlProtocolBase.js +++ b/lib/js/src/protocol/_SdlProtocolBase.js @@ -45,9 +45,6 @@ import { RpcCreator } from '../rpc/RpcCreator.js'; import { ImageResolution } from '../rpc/structs/ImageResolution.js'; import { VideoStreamingFormat } from '../rpc/structs/VideoStreamingFormat.js'; -import { VehicleType } from '../rpc/structs/VehicleType.js'; -import { SystemInfo } from '../util/SystemInfo.js'; - /** * Base implementation of sdl protocol. * Should be able to handle basic control frames and be able to @@ -271,37 +268,6 @@ class _SdlProtocolBase { return this._messageID++; } - /** - * Extracts the SystemInfo out of a packet - * @param {_SdlPacket} sdlPacket - should be a StartServiceACK for the RPC service. - * @returns {SystemInfo|null} - an instance of SystemInfo if the information is available, null otherwise. - */ - _extractSystemInfo (sdlPacket) { - const make = sdlPacket.getTag(_ControlFrameTags.RPC.StartServiceACK.MAKE); - const model = sdlPacket.getTag(_ControlFrameTags.RPC.StartServiceACK.MODEL); - const modelYear = sdlPacket.getTag(_ControlFrameTags.RPC.StartServiceACK.MODEL_YEAR); - const trim = sdlPacket.getTag(_ControlFrameTags.RPC.StartServiceACK.TRIM); - - const systemHardwareVersion = sdlPacket.getTag(_ControlFrameTags.RPC.StartServiceACK.SYSTEM_HARDWARE_VERSION); - const systemSoftwareVersion = sdlPacket.getTag(_ControlFrameTags.RPC.StartServiceACK.SYSTEM_SOFTWARE_VERSION); - - // if no any VehicleType tags in the packet just return null - let vehicleType = null; - if (make || model || modelYear || trim) { - vehicleType = new VehicleType({ - make, - model, - modelYear, - trim, - }); - } - if (!vehicleType && !systemSoftwareVersion && !systemHardwareVersion) { - return null; - } - - return new SystemInfo(vehicleType, systemSoftwareVersion, systemHardwareVersion); - } - /** * Takes an rpc message and sends a single or multi frame packets. * @param {RpcMessage} rpcMessage - Converts an RpcMessage into an _SdlPacket and sends it. @@ -470,22 +436,6 @@ class _SdlProtocolBase { sdlPacket.getTag(_ControlFrameTags.RPC.StartServiceACK.AUTH_TOKEN) ); } - - if ((this._protocolVersion.isNewerThan(new Version(5, 4, 0)) >= 0)) { - // check if systemInfo data exists then fire onSystemInfoReceived protocol listener event - const systemInfo = this._extractSystemInfo(sdlPacket); - if ( - systemInfo - && this._sdlProtocolListener !== null - && typeof this._sdlProtocolListener.onSystemInfoReceived === 'function' - ) { - if (!this._sdlProtocolListener.onSystemInfoReceived(systemInfo)) { - console.warn('Disconnecting from head unit, the system info was not accepted.'); - this.endSession(); - return; - } - } - } } else if (serviceType === _ServiceType.VIDEO) { if (this._sdlProtocolListener !== null) { const acceptedResolution = new ImageResolution(); @@ -512,7 +462,7 @@ class _SdlProtocolBase { } this._sdlProtocolListener.onProtocolSessionStarted(serviceType, - sdlPacket.getSessionID(), this._protocolVersion.getMajor(), '', this._hashID, sdlPacket.getEncryption()); + sdlPacket.getSessionID(), this._protocolVersion.getMajor(), '', this._hashID, sdlPacket.getEncryption(), sdlPacket); } /** diff --git a/lib/js/src/protocol/_SdlProtocolListener.js b/lib/js/src/protocol/_SdlProtocolListener.js index 96480443..4c0cac2a 100644 --- a/lib/js/src/protocol/_SdlProtocolListener.js +++ b/lib/js/src/protocol/_SdlProtocolListener.js @@ -57,7 +57,6 @@ class _SdlProtocolListener { this._onProtocolSessionEnded = null; this._onProtocolSessionEndedNACKed = null; this._onAuthTokenReceived = null; - this._onSystemInfoReceived = null; this._getSessionId = null; this._onTransportConnected = null; } @@ -113,16 +112,17 @@ class _SdlProtocolListener { /** * Safely attempts to invoke the event listener. - * @param {ServiceType} serviceType - A ServiceType enum value. + * @param {_ServiceType} serviceType - A ServiceType enum value. * @param {Number} sessionId - A session ID. * @param {Number} version - A numeric version. * @param {String} correlationId - A correlation ID. * @param {Number} hashId - A hash ID. * @param {Boolean} isEncrypted - Whether or not it is encrypted. + * @param {_SdlPacket} sdlPacket - An _SdlPacket. */ - onProtocolSessionStarted (serviceType, sessionId, version, correlationId, hashId, isEncrypted) { + onProtocolSessionStarted (serviceType, sessionId, version, correlationId, hashId, isEncrypted, sdlPacket) { if (typeof this._onProtocolSessionStarted === 'function') { - this._onProtocolSessionStarted(serviceType, sessionId, version, correlationId, hashId, isEncrypted); + this._onProtocolSessionStarted(serviceType, sessionId, version, correlationId, hashId, isEncrypted, sdlPacket); } } @@ -138,7 +138,7 @@ class _SdlProtocolListener { /** * Safely attempts to invoke the event listener. - * @param {ServiceType} serviceType - A ServiceType enum value. + * @param {_ServiceType} serviceType - A ServiceType enum value. * @param {Number} sessionId - A Session ID. * @param {String} correlationId - A correlation ID. */ @@ -160,7 +160,7 @@ class _SdlProtocolListener { /** * Safely attempts to invoke the event listener. - * @param {ServiceType} serviceType - A ServiceType enum value. + * @param {_ServiceType} serviceType - A ServiceType enum value. * @param {Number} sessionId - A Session ID. * @param {String} correlationId - A correlation ID. */ @@ -190,28 +190,6 @@ class _SdlProtocolListener { } } - /** - * Set the OnSystemInfoReceived function callback. - * @param {function} listener - A function to be invoked when the event occurs. - * @returns {_SdlProtocolListener} - A reference to this instance to support method chaining. - */ - setOnSystemInfoReceived (listener) { - this._onSystemInfoReceived = listener; - return this; - } - - /** - * Safely attempts to invoke the onSystemInfoReceived event. - * @param {SystemInfo} systemInfo - the system info of vehicle that this session is currently active on. - * @returns {Boolean} Return true if this session should continue, false if the session should end - */ - onSystemInfoReceived (systemInfo) { - if (typeof this._onSystemInfoReceived === 'function') { - return !!this._onSystemInfoReceived(systemInfo); - } - return true; - } - /** * Set the GetSessionId function. * @param {function} getter - A function to be invoked to retrieve the session ID. diff --git a/lib/js/src/session/_SdlSession.js b/lib/js/src/session/_SdlSession.js index 09ed97a2..cee99c1b 100644 --- a/lib/js/src/session/_SdlSession.js +++ b/lib/js/src/session/_SdlSession.js @@ -35,6 +35,10 @@ import { _SdlProtocol } from '../protocol/_SdlProtocol.js'; import { _ServiceType } from '../protocol/enums/_ServiceType.js'; import { _ServiceListenerMap } from './_ServiceListenerMap.js'; import { _VideoStreamingParameters } from '../streaming/video/_VideoStreamingParameters.js'; +import { _ControlFrameTags } from '../protocol/enums/_ControlFrameTags.js'; +import { VehicleType } from '../rpc/structs/VehicleType.js'; +import { SystemInfo } from '../util/SystemInfo.js'; +import { Version } from '../util/Version.js'; /** @@ -61,7 +65,6 @@ class _SdlSession { this._sdlProtocolListener = this._setupSdlProtocolListener(); this._sdlProtocol = new _SdlProtocol(baseTransportConfig, this._sdlProtocolListener); - this._didCheckSystemInfo = false; } /** @@ -78,7 +81,6 @@ class _SdlSession { sdlProtocolListener.setOnRpcMessageReceived(this.onRpcMessageReceived.bind(this)); sdlProtocolListener.setOnTransportConnected(this.onTransportConnected.bind(this)); sdlProtocolListener.setOnAuthTokenReceived(this.onAuthTokenReceived.bind(this)); - sdlProtocolListener.setOnSystemInfoReceived(this.onSystemInfoReceived.bind(this)); sdlProtocolListener.setGetDesiredVideoParams(this.getDesiredVideoParams.bind(this)); sdlProtocolListener.setSetAcceptedVideoParams(this.setAcceptedVideoParams.bind(this)); @@ -86,6 +88,36 @@ class _SdlSession { return sdlProtocolListener; } + /** + * Extracts the SystemInfo out of a packet + * @param {_SdlPacket} sdlPacket - should be a StartServiceACK for the RPC service. + * @returns {SystemInfo|null} - an instance of SystemInfo if the information is available, null otherwise. + */ + _extractSystemInfo (sdlPacket) { + const make = sdlPacket.getTag(_ControlFrameTags.RPC.StartServiceACK.MAKE); + const model = sdlPacket.getTag(_ControlFrameTags.RPC.StartServiceACK.MODEL); + const modelYear = sdlPacket.getTag(_ControlFrameTags.RPC.StartServiceACK.MODEL_YEAR); + const trim = sdlPacket.getTag(_ControlFrameTags.RPC.StartServiceACK.TRIM); + + const systemHardwareVersion = sdlPacket.getTag(_ControlFrameTags.RPC.StartServiceACK.SYSTEM_HARDWARE_VERSION); + const systemSoftwareVersion = sdlPacket.getTag(_ControlFrameTags.RPC.StartServiceACK.SYSTEM_SOFTWARE_VERSION); + + let vehicleType = null; + if (make || model || modelYear || trim) { + vehicleType = new VehicleType({ + make, + model, + modelYear, + trim, + }); + } + if (!vehicleType && !systemSoftwareVersion && !systemHardwareVersion) { + return null; + } + + return new SystemInfo(vehicleType, systemSoftwareVersion, systemHardwareVersion); + } + /** * Starts up the SDL protocol class. It will kick off the transport manager and underlying transport. */ @@ -120,15 +152,21 @@ class _SdlSession { * @param {String} correlationId - A correlationID. * @param {Number} hashId - A hash ID. * @param {Boolean} isEncrypted - Whether or not it is encrypted. + * @param {_SdlPacket} sdlPacket - An _SdlPacket. */ - onProtocolSessionStarted (serviceType, sessionId, version, correlationId, hashId, isEncrypted) { + onProtocolSessionStarted (serviceType, sessionId, version, correlationId, hashId, isEncrypted, sdlPacket) { this._sessionId = sessionId; if (serviceType === _ServiceType.RPC) { this._sessionHashId = hashId; } - this._sdlSessionListener.onProtocolSessionStarted(serviceType, sessionId, version, correlationId, hashId, isEncrypted); + let systemInfo = null; + if (version && (this.getProtocolVersion().isNewerThan(new Version(5, 4, 0)) >= 0)) { + systemInfo = this._extractSystemInfo(sdlPacket); + } + + this._sdlSessionListener.onProtocolSessionStarted(serviceType, sessionId, version, correlationId, hashId, isEncrypted, systemInfo); this._serviceListeners.sendEventServiceStarted(this, serviceType, isEncrypted); } @@ -170,25 +208,6 @@ class _SdlSession { this._sdlSessionListener.onAuthTokenReceived(authToken, this._sessionId); } - /** - * A way to determine if SystemInfo already checked - * @returns {Boolean} Return true if received - */ - didCheckSystemInfo () { - return this._didCheckSystemInfo; - } - - /** - * A way to determine if this SDL session should continue to be active while - * connected to the determined vehicle type. - * @param {SystemInfo} systemInfo - the type of vehicle that this session is currently active on. - * @returns {Boolean} Return true if this session should continue, false if the session should end - */ - onSystemInfoReceived (systemInfo) { - // set the flag as this event fires only once if VehicleType was received - this._didCheckSystemInfo = true; - return this._sdlSessionListener.onSystemInfoReceived(systemInfo); - } /** ********************************************************************************************************************************************************************** * END: _SdlProtocolListener implemented methods diff --git a/lib/js/src/session/_SdlSessionListener.js b/lib/js/src/session/_SdlSessionListener.js index 6fff7215..c6fdb30a 100644 --- a/lib/js/src/session/_SdlSessionListener.js +++ b/lib/js/src/session/_SdlSessionListener.js @@ -47,7 +47,6 @@ class _SdlSessionListener { this._onRpcMessageReceived = null; this._onTransportConnected = null; this._onAuthTokenReceived = null; - this._onSystemInfoReceived = null; } /** @@ -102,22 +101,23 @@ class _SdlSessionListener { /** * Safely attempts to invoke the onProtocolSessionStarted event. - * @param {ServiceType} serviceType - The ServiceType. + * @param {_ServiceType} serviceType - The ServiceType. * @param {Number} sessionID - represents a byte * @param {Number} version - represents a byte * @param {String} correlationID - The correlationID. * @param {Number} hashID - The hash ID. * @param {Boolean} isEncrypted - Whether or not it is encrypted. + * @param {SystemInfo} systemInfo - the system info of vehicle that this session is currently active on. */ - onProtocolSessionStarted (serviceType, sessionID, version, correlationID, hashID, isEncrypted) { + onProtocolSessionStarted (serviceType, sessionID, version, correlationID, hashID, isEncrypted, systemInfo) { if (typeof this._onProtocolSessionStarted === 'function') { - this._onProtocolSessionStarted(serviceType, sessionID, version, correlationID, hashID, isEncrypted); + this._onProtocolSessionStarted(serviceType, sessionID, version, correlationID, hashID, isEncrypted, systemInfo); } } /** * Safely attempts to invoke the onProtocolSessionEnded event. - * @param {ServiceType} serviceType - The ServiceType. + * @param {_ServiceType} serviceType - The ServiceType. * @param {Number} sessionID - represents a byte * @param {String} correlationID - The correlationID. */ @@ -129,7 +129,7 @@ class _SdlSessionListener { /** * Safely attempts to invoke the onProtocolSessionEndedNACKed event. - * @param {ServiceType} serviceType - The ServiceType. + * @param {_ServiceType} serviceType - The ServiceType. * @param {Number} sessionID - represents a byte * @param {String} correlationID - The correlationID. */ @@ -160,28 +160,6 @@ class _SdlSessionListener { } } - /** - * Set the onSystemInfoReceived function. - * @param {function} listener - A function to be invoked when the event occurs. - * @returns {_SdlSessionListener} - A reference to this instance to allow method chaining. - */ - setOnSystemInfoReceived (listener) { - this._onSystemInfoReceived = listener; - return this; - } - - /** - * Safely attempts to invoke the onSystemInfoReceived event. - * @param {SystemInfo} systemInfo - the system info of vehicle that this session is currently active on. - * @returns {Boolean} Return true if this session should continue, false if the session should end - */ - onSystemInfoReceived (systemInfo) { - if (typeof this._onSystemInfoReceived === 'function') { - return !!this._onSystemInfoReceived(systemInfo); - } - return true; - } - /** * Safely attempts to invoke the onRpcMessageReceived event. * @param {RpcMessage} rpcMessage - An RpcMessage. diff --git a/tests/managers/lifecycle/LifecycleManagerTests.js b/tests/managers/lifecycle/LifecycleManagerTests.js index 36b1aae2..630a1d1e 100644 --- a/tests/managers/lifecycle/LifecycleManagerTests.js +++ b/tests/managers/lifecycle/LifecycleManagerTests.js @@ -52,6 +52,7 @@ module.exports = function (appClient) { Validator.assertNotNullUndefined(version.getPatchVersion()); done(); }); + it('testOnSystemInfoReceived', function (done) { const mockSystemInfo = {}; const defaultResult = true; @@ -62,7 +63,7 @@ module.exports = function (appClient) { const testListener = function (mockSystemInfo) { return testResult; }; - sdlManager._lifecycleManager.setInSystemInfoReceived(testListener); + sdlManager._lifecycleManager.setOnSystemInfoReceived(testListener); actualResult = sdlManager._lifecycleManager.onSystemInfoReceived(mockSystemInfo); Validator.assertEquals(actualResult, testResult); From a0a9ed0bc56c0e4b40a5bdaab4ea01351e222ae1 Mon Sep 17 00:00:00 2001 From: Vladyslav Mustafin Date: Fri, 12 Feb 2021 09:21:13 +0200 Subject: [PATCH 10/11] Alignment with Java suite implementation - fixes --- lib/js/src/manager/lifecycle/_LifecycleManager.js | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/lib/js/src/manager/lifecycle/_LifecycleManager.js b/lib/js/src/manager/lifecycle/_LifecycleManager.js index 10610a0b..c7cf7229 100644 --- a/lib/js/src/manager/lifecycle/_LifecycleManager.js +++ b/lib/js/src/manager/lifecycle/_LifecycleManager.js @@ -112,7 +112,7 @@ class _LifecycleManager { if (systemInfo && !this._didCheckSystemInfo) { this._didCheckSystemInfo = true; - if (!this._onSystemInfoReceived(systemInfo)) { + if (!this.onSystemInfoReceived(systemInfo)) { console.warn('Disconnecting from head unit, the system info was not accepted.'); this._sdlSession.endService(serviceType, this._sdlSession.getSessionId()); return this._cleanProxy(); @@ -141,8 +141,6 @@ class _LifecycleManager { this._authToken = authToken; }); - sessionListener.setOnSystemInfoReceived(this.onSystemInfoReceived.bind(this)); - return sessionListener; } From 66edef5dead0ab0b63860fecb934193a1bff8bd0 Mon Sep 17 00:00:00 2001 From: Vladyslav Mustafin Date: Wed, 17 Feb 2021 09:10:19 +0200 Subject: [PATCH 11/11] Review changes --- lib/js/src/manager/lifecycle/_LifecycleManager.js | 9 +++++++-- lib/js/src/protocol/_SdlProtocolBase.js | 2 +- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/lib/js/src/manager/lifecycle/_LifecycleManager.js b/lib/js/src/manager/lifecycle/_LifecycleManager.js index c7cf7229..f919b881 100644 --- a/lib/js/src/manager/lifecycle/_LifecycleManager.js +++ b/lib/js/src/manager/lifecycle/_LifecycleManager.js @@ -520,8 +520,13 @@ class _LifecycleManager { if (!this._didCheckSystemInfo) { this._didCheckSystemInfo = true; - const systemInfo = new SystemInfo(registerAppInterfaceResponse.getVehicleType(), registerAppInterfaceResponse.getSystemSoftwareVersion()) ; - if (!this.onSystemInfoReceived(systemInfo)) { + const vehicleType = registerAppInterfaceResponse.getVehicleType(); + const systemSoftwareVersion = registerAppInterfaceResponse.getSystemSoftwareVersion(); + let systemInfo = null; + if (vehicleType || systemSoftwareVersion) { + systemInfo = new SystemInfo(vehicleType, systemSoftwareVersion); + } + if (systemInfo && !this.onSystemInfoReceived(systemInfo)) { console.warn('Disconnecting from head unit, the system info was not accepted.'); this.sendRpcResolve(new UnregisterAppInterface()); this._cleanProxy(); diff --git a/lib/js/src/protocol/_SdlProtocolBase.js b/lib/js/src/protocol/_SdlProtocolBase.js index 3879cb55..65c7d1ed 100644 --- a/lib/js/src/protocol/_SdlProtocolBase.js +++ b/lib/js/src/protocol/_SdlProtocolBase.js @@ -216,7 +216,7 @@ class _SdlProtocolBase { */ _setVersion (version) { if (version > 5) { - this._protocolVersion = new Version('5.4.0'); // protect for future, proxy only supports v5 or lower + this._protocolVersion = new Version('5.1.0'); // protect for future, proxy only supports v5 or lower this.headerSize = this.constructor.V2_HEADER_SIZE; this._mtus[_ServiceType.RPC] = this.constructor.V3_V4_MTU_SIZE; } else if (version === 5) {