accessoryservices/accessoryserver/src/Server/AccSrvSettingsHandler.cpp
changeset 13 cef4ff1e6c4f
parent 0 4e1aa6a622a0
child 16 ef634fd8dac3
--- a/accessoryservices/accessoryserver/src/Server/AccSrvSettingsHandler.cpp	Fri Mar 19 09:58:42 2010 +0200
+++ b/accessoryservices/accessoryserver/src/Server/AccSrvSettingsHandler.cpp	Fri Apr 16 16:18:45 2010 +0300
@@ -73,10 +73,12 @@
 // -----------------------------------------------------------------------------
 //
 CAccSrvSettingsHandler::CAccSrvSettingsHandler( CAccSrvConnectionController* aConCtrl,
-                                                CAccSrvServerModel& aModel )
+                                                CAccSrvServerModel& aModel,
+                                                CAccPolAccessoryPolicy* aPolicy )
     : iConCtrl( aConCtrl ),
       iModel( aModel ),
-      iLightsOn( EAccSettingsLightsNotSet )
+      iLightsOn( EAccSettingsLightsNotSet ),
+      iPolicy( aPolicy )
     {
     COM_TRACE_( "[AccFW:AccServer] CAccSrvSettingsHandler::CAccSrvSettingsHandler()" );
 
@@ -122,13 +124,15 @@
 //
 CAccSrvSettingsHandler* CAccSrvSettingsHandler::NewL(
                                            CAccSrvConnectionController* aConCtrl,
-                                           CAccSrvServerModel& aModel )
+                                           CAccSrvServerModel& aModel,
+                                           CAccPolAccessoryPolicy* aPolicy )
     {
     COM_TRACE_( "[AccFW:AccServer] CAccSrvSettingsHandler::NewL()" );
 
     CAccSrvSettingsHandler* self = new( ELeave ) CAccSrvSettingsHandler(
                                                     aConCtrl,
-                                                    aModel );
+                                                    aModel,
+                                                    aPolicy );
     CleanupStack::PushL( self );
     self->ConstructL();
     CleanupStack::Pop( self );
@@ -285,7 +289,8 @@
 
     // Valid settings
     TUint32 settings = ResolveNewSettingsL( aSettings, aEnable, aForce );
-
+    TUint32 iOldDeviceType = iModel.DeviceType();
+    
     // Update model
     iModel.SetDeviceType( settings );
 
@@ -296,6 +301,99 @@
     delete repository;
     repository = NULL;
 
+        //Check default selection. The newly set device-type after the model update.
+        TInt defaultSelection( iModel.DeviceType() );
+        TInt iReplyValue = KASNoDevice;
+        TAccPolGenericID iGenericID;
+       
+        // get the last connected wired accessory
+        if(iModel.GetLastConnectedWiredAccessory(iGenericID))
+            {
+            // Device Type Supplied
+            if( iGenericID.DeviceTypeCaps(KDTHeadset) )
+                {       
+                // This is a Headset
+                if( iPolicy->IsCapabilityDefinedL(iGenericID, KAccIntegratedAudioInput) ) 
+                    {
+                    if(KASTTY == defaultSelection)
+                        {
+                        iReplyValue = defaultSelection;
+                        }
+                    else
+                        {
+                        iReplyValue = KASHeadset;
+                        }             
+                    }
+                // This is a Headphone
+                else 
+                    {
+                    if(KASMusicStand == defaultSelection) 
+                        {
+                        iReplyValue = defaultSelection;
+                        }
+                    else
+                        {
+                        iReplyValue = KASHeadphones;
+                        }
+                    }
+                }
+            else if( iGenericID.DeviceTypeCaps(KDTTTY) )
+                {
+                if( iPolicy->IsCapabilityDefinedL(iGenericID, KAccIntegratedAudioInput) )
+                    {
+                    if(KASHeadset == defaultSelection)
+                        {
+                        iReplyValue = defaultSelection;
+                        }
+                    else
+                        {
+                        iReplyValue = KASTTY;
+                        }
+                    }
+                }
+            else if( iGenericID.DeviceTypeCaps(KDTOffice) )
+                {
+                if(KASHeadphones == defaultSelection)
+                    {
+                    iReplyValue = defaultSelection;
+                    }
+                else
+                    {
+                    iReplyValue = KASMusicStand;
+                    }
+                }
+            // Device Type Not Supplied
+            else if( iGenericID.DeviceTypeCaps() == KASNoDevice )
+                {
+                iReplyValue = defaultSelection;
+                }
+
+            if( (KASNoDevice != iReplyValue) && (iReplyValue != iOldDeviceType) )
+                {
+                //update generic id
+                iPolicy->UpdateGenericIDL( iGenericID, iReplyValue);
+                // Update the "iConnectionArray" of CAccSrvServerModel, 
+                // to reflect the update on generic-id done earlier.
+                TAccPolGenericID oldGenericId; 
+                iModel.FindWithUniqueIDL( iGenericID.UniqueID(), oldGenericId );
+                
+                iConCtrl->HandleConnectionUpdateValidationL( 
+                            iGenericID, oldGenericId, this, KErrNone );
+        
+                TASYCommandParamRecord asyCommandParamRecord;
+                asyCommandParamRecord.iCmdValue   = 0;//Not used in update command
+                asyCommandParamRecord.iGenericID  = iGenericID;     
+
+                //Send request to ASY Proxy Handler
+                COM_TRACE_( "[AccFW:AccServer] CAccSrvConnectionHandler::RunL() - Send update request");
+                TInt trId = iConCtrl->HandleASYCommsL( ECmdAccessoryUpdated,
+                                                    asyCommandParamRecord );
+                
+                iConCtrl->HandleAccessoryModeChangedL();
+          
+                }            
+            }
+       
     COM_TRACE_( "[AccFW:AccServer] CAccSrvSettingsHandler::SetHWDeviceSettingsL() - return" );
     }