@@ -43,6 +43,8 @@ import { SdlMsgVersion } from '../../rpc/structs/SdlMsgVersion.js';
4343import { FunctionID } from '../../rpc/enums/FunctionID.js' ;
4444import { _ServiceType } from '../../protocol/enums/_ServiceType.js' ;
4545import { SystemInfo } from '../../util/SystemInfo.js' ;
46+ import { AppHMIType } from '../../rpc/enums/AppHMIType.js' ;
47+ import { PredefinedLayout } from '../../rpc/enums/PredefinedLayout.js' ;
4648
4749/**
4850 * This class should also be marked private and behind the SdlManager API
@@ -93,6 +95,8 @@ class _LifecycleManager {
9395 this . _registerAppInterfaceResponse = null ;
9496
9597 this . _didCheckSystemInfo = false ;
98+ this . _lastDisplayLayoutRequestTemplate = null ;
99+ this . _initialMediaCapabilities = null ;
96100 }
97101
98102 /**
@@ -162,6 +166,7 @@ class _LifecycleManager {
162166 return ;
163167 }
164168
169+ this . fixIncorrectDisplayCapabilities ( rpcMessage ) ;
165170 const functionID = FunctionID . valueForKey ( rpcMessage . getFunctionId ( ) ) ; // this is the number value
166171 const listenerArray = this . _rpcListeners . get ( functionID ) ;
167172 if ( Array . isArray ( listenerArray ) ) {
@@ -315,6 +320,10 @@ class _LifecycleManager {
315320 if ( rpcMessage . getCorrelationId ( ) === null || rpcMessage . getCorrelationId ( ) === undefined ) {
316321 rpcMessage . setCorrelationId ( ++ this . _maxCorrelationId ) ;
317322 }
323+ // Ford Sync bug returning incorrect display capabilities (https://github.com/smartdevicelink/sdl_javascript_suite/issues/446). Save the next desired layout type to the update capabilities when the SetDisplayLayout response is received
324+ if ( rpcMessage . getFunctionId ( ) === FunctionID . keyForValue ( FunctionID . SetDisplayLayout ) ) {
325+ this . _lastDisplayLayoutRequestTemplate = rpcMessage . getDisplayLayout ( ) ;
326+ }
318327 this . addRpcListener ( FunctionID . valueForKey ( rpcMessage . getFunctionId ( ) ) , listener ) ;
319328 // listen for GenericResponse as well, in the case of interacting with older head units
320329 this . addRpcListener ( FunctionID . GenericResponse , listener ) ;
@@ -440,6 +449,18 @@ class _LifecycleManager {
440449 return true ;
441450 }
442451
452+ /**
453+ * When a SetDisplayLayout response is received and the desired layout type is MEDIA, use the initial media capabilities
454+ * See Ford Sync bug returning incorrect display capabilities (https://github.com/smartdevicelink/sdl_javascript_suite/issues/446).
455+ * @param {RpcMessage } rpc - an RPC Message
456+ */
457+ fixIncorrectDisplayCapabilities ( rpc ) {
458+ if ( MessageType . response === rpc . getMessageType ( ) && rpc . getFunctionId ( ) === FunctionID . keyForValue ( FunctionID . SetDisplayLayout ) &&
459+ this . _initialMediaCapabilities !== null && this . _lastDisplayLayoutRequestTemplate === PredefinedLayout . MEDIA ) {
460+ rpc . setDisplayCapabilities ( this . _initialMediaCapabilities ) ;
461+ }
462+ }
463+
443464
444465 /* *******************************************************************************************************
445466 ********************************** INTERNAL - RPC LISTENERS !! START !! *********************************
@@ -531,6 +552,9 @@ class _LifecycleManager {
531552 this . sendRpcResolve ( new UnregisterAppInterface ( ) ) ;
532553 this . _cleanProxy ( ) ;
533554 }
555+ if ( this . _lifecycleConfig . getAppTypes ( ) . includes ( AppHMIType . MEDIA ) ) {
556+ this . _initialMediaCapabilities = registerAppInterfaceResponse . getDisplayCapabilities ( ) ;
557+ }
534558 }
535559
536560 // parse RAI for system capabilities
0 commit comments