Revision: 201023 RCL_3
authorDremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
Mon, 21 Jun 2010 15:51:07 +0300
branchRCL_3
changeset 47 312d2b433792
parent 39 469fa8a78de7
child 50 49762640db60
child 57 5e7d68cc22e0
Revision: 201023 Kit: 2010125
appfw/apparchitecture/apgrfx/apgrecog.cpp
appfw/apparchitecture/apserv/APSSES.CPP
appfw/apparchitecture/apserv/APSSES.H
contextframework/cfw/conf/contextframework.confml
contextframework/cfw/conf/contextframework_10282BCD.crml
contextframework/cfw/src/cfserver/cfphasebase.cpp
coreapplicationuis/SysAp/Group/SysAp.mmp
coreapplicationuis/SysAp/Inc/sysapremconobserver.h
coreapplicationuis/SysAp/Src/SysApAppUi.cpp
coreapplicationuis/SysAp/Src/SysApLightsController.cpp
coreapplicationuis/SysAp/Src/SysApPubSubObserver.cpp
coreapplicationuis/SysAp/Src/sysapremconobserver.cpp
coreapplicationuis/advancedtspcontroller/data/keyevent.rul
coreapplicationuis/advancedtspcontroller/group/RemConTspController.mmp
coreapplicationuis/advancedtspcontroller/inc/remcontspcontroller.h
coreapplicationuis/advancedtspcontroller/inc/tsptriggerevents.h
coreapplicationuis/advancedtspcontroller/src/remcontspcontroller.cpp
coreapplicationuis/advancedtspcontroller/src/tsptriggerevents.cpp
systemsettings/gssensorplugin/conf/sensorplugin_10282DF0.crml
tzservices/tzloc/src/TzLocalizationDbAccessor.cpp
--- a/appfw/apparchitecture/apgrfx/apgrecog.cpp	Wed Jun 09 09:52:12 2010 +0300
+++ b/appfw/apparchitecture/apgrfx/apgrecog.cpp	Mon Jun 21 15:51:07 2010 +0300
@@ -1,4 +1,4 @@
-// Copyright (c) 1997-2009 Nokia Corporation and/or its subsidiary(-ies).
+// Copyright (c) 1997-2010 Nokia Corporation and/or its subsidiary(-ies).
 // All rights reserved.
 // This component and the accompanying materials are made available
 // under the terms of "Eclipse Public License v1.0"
@@ -403,11 +403,15 @@
 
 /** Gets the data (MIME) type of data passed by buffer.
 
-@param aBuffer A buffer containing data 
+@param aBuffer A buffer containing data; Provide preferred size of buffer. 
+If MIME type could not be recognized using this buffer, provide a buffer of 
+larger size.
 @param aDataType On return, contains the result of the attempt to recognize 
 data. 
 @return KErrNone, if successful; otherwise one of the other system-wide error 
 codes. 
+
+@see RApaLsSession::GetPreferredBufSize()
 */
 EXPORT_C TInt RApaLsSession::RecognizeData(const TDesC8& aBuffer, TDataRecognitionResult& aDataType) const
     {
@@ -417,12 +421,15 @@
 /** Gets the data (MIME) type for data taken from a file with a specified name.
 
 @param aName The full filename, including drive and path, of the file containing the data.
-@param aBuffer A buffer containing data taken from the specified file; typically 
-the data is read from the beginning of the file.
+@param aBuffer A buffer containing data taken from the specified file; Provide preferred size of buffer 
+from beginning of the file. If MIME type could not be recognized using this buffer, provide a buffer of 
+larger size.
 @param aDataType On return, contains the result of the attempt to recognize 
 data. 
 @return KErrNone, if successful; otherwise one of the other system-wide error 
 codes. 
+
+@see RApaLsSession::GetPreferredBufSize()
 */
 EXPORT_C TInt RApaLsSession::RecognizeData(const TDesC& aName, const TDesC8& aBuffer, TDataRecognitionResult& aDataType) const
 	{
@@ -453,15 +460,18 @@
 
 
 /** Tests whether data taken from a named file has the specified 
-data (MIME) type.
+ * data (MIME) type.
 
 @param aName The name of the file containing the data.
-@param aBuffer A buffer containing data taken from the specified file; typically 
-the data is read from the beginning of the file.
+@param aBuffer A buffer containing data taken from the specified file; Provide preferred size of buffer 
+from beginning of the file. If MIME type could not be recognized using this buffer, provide a buffer of 
+larger size.
 @param aDataType The data (MIME) type.
 @param aResult On return, contains the result of the test.
 @return KErrNone, if successful; otherwise one of the other system-wide error 
 codes. 
+
+@see RApaLsSession::GetPreferredBufSize()
 */
 EXPORT_C TInt RApaLsSession::RecognizeSpecificData(const TDesC& aName, const TDesC8& aBuffer, const TDataType& aDataType, TBool& aResult) const
 	{
--- a/appfw/apparchitecture/apserv/APSSES.CPP	Wed Jun 09 09:52:12 2010 +0300
+++ b/appfw/apparchitecture/apserv/APSSES.CPP	Mon Jun 21 15:51:07 2010 +0300
@@ -1,4 +1,4 @@
-// Copyright (c) 1997-2009 Nokia Corporation and/or its subsidiary(-ies).
+// Copyright (c) 1997-2010 Nokia Corporation and/or its subsidiary(-ies).
 // All rights reserved.
 // This component and the accompanying materials are made available
 // under the terms of "Eclipse Public License v1.0"
@@ -1206,28 +1206,57 @@
 	aInfo.iShortCaption = app->ShortCaption();
 	}
 	
-void CApaAppArcServSession::DoRecognizeUnpackLC(HBufC*& aName, HBufC8*& aBuffer, const RMessage2& aMessage)
+TPtrC8 CApaAppArcServSession::DoRecognizeUnpackLC(HBufC*& aName, RChunk& aLocalChunk, const RMessage2& aMessage)
 	{
-	ASSERT(aName==NULL);
-	ASSERT(aBuffer==NULL);
-	aName=HBufC::NewLC(User::LeaveIfError(aMessage.GetDesLength(1)));
-	TPtr name(aName->Des());
-	aMessage.ReadL(1, name);
-	aBuffer=HBufC8::NewLC(User::LeaveIfError(aMessage.GetDesLength(2)));
-	TPtr8 buffer(aBuffer->Des());
-	aMessage.ReadL(2, buffer);
+    ASSERT(aName==NULL);
+    
+    aName=HBufC::NewLC(User::LeaveIfError(aMessage.GetDesLength(1)));
+    TPtr name(aName->Des());
+    aMessage.ReadL(1, name);
+    
+    HBufC8* buffer=NULL;
+    TInt error=KErrNone;
+    TInt bufferSize= aMessage.GetDesLength(2);
+    User::LeaveIfError(bufferSize);
+    //Allocate memory in apparc's process heap.
+    TRAP(error, buffer=HBufC8::NewL(bufferSize));
+
+    if(error==KErrNone)
+        {
+        CleanupStack::PushL(buffer);
+        TPtr8 bufPtr(buffer->Des());
+        aMessage.ReadL(2, bufPtr);   
+        return bufPtr;
+        }
+    else if(error==KErrNoMemory)
+        {
+        //If memory is not available in apparc's process heap, then allocate in kernel heap
+        User::LeaveIfError(aLocalChunk.CreateLocal(bufferSize,bufferSize));
+        CleanupClosePushL(aLocalChunk);
+        TPtr8 bufPtr(aLocalChunk.Base(), bufferSize);
+        aMessage.ReadL(2, bufPtr); 
+        return bufPtr;        
+        }
+    else
+        {
+        User::Leave(error);
+        }
+    
+    TPtrC8 bufPtr(NULL,0); //Never executed. To make compiler happy
+    return bufPtr;
 	}
 
 void CApaAppArcServSession::RecognizeDataL(const RMessage2& aMessage)
 // Recognize the data type of an object
 	{
 	HBufC* name=NULL;
-	HBufC8* buffer=NULL;
-	DoRecognizeUnpackLC(name,buffer,aMessage);
+    RChunk localChunk;
+    
+	TPtrC8 bufPtr=DoRecognizeUnpackLC(name, localChunk, aMessage);
 
-	const TDataRecognitionResult result = iServ.RecognizeDataL(*name, *buffer);
+	const TDataRecognitionResult result = iServ.RecognizeDataL(*name, bufPtr);
 
-	CleanupStack::PopAndDestroy(2); // name & buffer
+	CleanupStack::PopAndDestroy(2); // name & buffer or localChunk
 	aMessage.WriteL(0,TPckgC<TDataRecognitionResult>(result));
 	}
 
@@ -1506,13 +1535,14 @@
 // Determine whether an object is of a specific data type
 	{
 	HBufC* name=NULL;
-	HBufC8* buffer=NULL;
-	DoRecognizeUnpackLC(name,buffer,aMessage);
+	RChunk localChunk;
+	
+	TPtrC8 bufPtr=DoRecognizeUnpackLC(name, localChunk, aMessage);
 	TDataType dataType;
 	{TPckg<TDataType> dataType_asDescriptor(dataType);
 	aMessage.ReadL(0, dataType_asDescriptor);}
-	aMessage.Complete(iServ.RecognizeDataL(*name,*buffer,dataType));
-	CleanupStack::PopAndDestroy(2); // name & buffer
+	aMessage.Complete(iServ.RecognizeDataL(*name,bufPtr,dataType));
+	CleanupStack::PopAndDestroy(2); // name & buffer or localChunk
 	}
 
 void CApaAppArcServSession::RecognizeSpecificDataPassedByFileHandleL(const RMessage2& aMessage)
--- a/appfw/apparchitecture/apserv/APSSES.H	Wed Jun 09 09:52:12 2010 +0300
+++ b/appfw/apparchitecture/apserv/APSSES.H	Mon Jun 21 15:51:07 2010 +0300
@@ -1,4 +1,4 @@
-// Copyright (c) 1997-2009 Nokia Corporation and/or its subsidiary(-ies).
+// Copyright (c) 1997-2010 Nokia Corporation and/or its subsidiary(-ies).
 // All rights reserved.
 // This component and the accompanying materials are made available
 // under the terms of "Eclipse Public License v1.0"
@@ -157,7 +157,7 @@
 	void RecognizeDataPassedByFileHandleL(const RMessage2& aMessage);
 	void RecognizeSpecificDataL(const RMessage2& aMessage);
 	void RecognizeSpecificDataPassedByFileHandleL(const RMessage2& aMessage);
-	static void DoRecognizeUnpackLC(HBufC*& aName, HBufC8*& aBuffer, const RMessage2& aMessage);
+	static TPtrC8 DoRecognizeUnpackLC(HBufC*& aName, RChunk& aLocalChunk, const RMessage2& aMessage);
 
 	void AppForDataTypeL(const RMessage2& aMessage);
 	TUid AppForDataTypeL(const TDataType& aDataType, const TUid* aServiceUid);
Binary file contextframework/cfw/conf/contextframework.confml has changed
Binary file contextframework/cfw/conf/contextframework_10282BCD.crml has changed
--- a/contextframework/cfw/src/cfserver/cfphasebase.cpp	Wed Jun 09 09:52:12 2010 +0300
+++ b/contextframework/cfw/src/cfserver/cfphasebase.cpp	Mon Jun 21 15:51:07 2010 +0300
@@ -95,8 +95,10 @@
     FUNC_LOG;
 
     __ASSERT_DEBUG( iStarterRequest, Panic( ENoRequestToComplete ) );
-    
-    User::RequestComplete( iStarterRequest, KErrCancel );
+    if ( iStarterRequest )
+		{
+		User::RequestComplete( iStarterRequest, KErrCancel );
+		}
     }
 
 //-----------------------------------------------------------------------------
--- a/coreapplicationuis/SysAp/Group/SysAp.mmp	Wed Jun 09 09:52:12 2010 +0300
+++ b/coreapplicationuis/SysAp/Group/SysAp.mmp	Mon Jun 21 15:51:07 2010 +0300
@@ -1,5 +1,5 @@
 /*
-* Copyright (c) 2005-2009 Nokia Corporation and/or its subsidiary(-ies). 
+* Copyright (c) 2005-2010 Nokia Corporation and/or its subsidiary(-ies). 
 * All rights reserved.
 * This component and the accompanying materials are made available
 * under the terms of "Eclipse Public License v1.0"
@@ -83,6 +83,7 @@
 SOURCE SysApSimChanged.cpp
 LIBRARY logcli.lib
 
+LIBRARY hal.lib
 SOURCE SysApAccessoryObserver.cpp
 LIBRARY AccClient.lib
 
--- a/coreapplicationuis/SysAp/Inc/sysapremconobserver.h	Wed Jun 09 09:52:12 2010 +0300
+++ b/coreapplicationuis/SysAp/Inc/sysapremconobserver.h	Mon Jun 21 15:51:07 2010 +0300
@@ -1,5 +1,5 @@
 /*
-* Copyright (c) 2007 Nokia Corporation and/or its subsidiary(-ies). 
+* Copyright (c) 2007-2010 Nokia Corporation and/or its subsidiary(-ies). 
 * All rights reserved.
 * This component and the accompanying materials are made available
 * under the terms of "Eclipse Public License v1.0"
@@ -54,7 +54,16 @@
         * Destructor.
         */
         virtual ~CSysApRemConObserver();
-
+        
+        /**
+         * Open remcon interface and reserve the volume keys
+         */
+        void StartRemconInterface();
+        
+        /**
+         * close the remcon interface and release the volume keys
+         */
+        void StopRemconInterface();
     protected: // Functions from base classes
 
         /**
--- a/coreapplicationuis/SysAp/Src/SysApAppUi.cpp	Wed Jun 09 09:52:12 2010 +0300
+++ b/coreapplicationuis/SysAp/Src/SysApAppUi.cpp	Mon Jun 21 15:51:07 2010 +0300
@@ -737,13 +737,26 @@
             TRACES( RDebug::Print( _L( "CSysApAppUi::HandleKeyEventL(): aType == EEventKeyUp, PowerKeyIsLockKey = %d, iLastPowerKeyWasShort = %d, iPowerKeyPopupMenuActive = %d, iCharging = %d" ), iSysApFeatureManager->PowerKeyIsLockKey(), iLastPowerKeyWasShort, iPowerKeyPopupMenuActive, iCharging ) );
             if ( iSysApFeatureManager->PowerKeyIsLockKey()
                  && iLastPowerKeyWasShort 
-				 				 && !iPowerKeyPopupMenuActive
+				 && !iPowerKeyPopupMenuActive
                  && !haveStatusPane  
                  && ( aKeyEvent.iScanCode == EStdKeyDevice2 ) )
                 {
                 //if the power key is the lock key && the last keypress was short && the power menu is not active
                 //then lock the phone
-                KeyLock().EnableWithoutNote();
+                TInt alarmState=0, securityQueryState=0;
+         		TInt errorCode = RProperty::Get( KPSUidCoreApplicationUIs, KCoreAppUIsDisableKeyguard, alarmState );
+				TInt errorCode2 = RProperty::Get( KPSUidStartup, KStartupSecurityCodeQueryStatus, securityQueryState);
+            	TRACES( RDebug::Print( _L( "CSysApAppUi::HandleKeyEventL(): Reading value of KCoreAppUIsDisableKeyguard - State Value: %d"),alarmState));
+            	TRACES( RDebug::Print( _L( "CSysApAppUi::HandleKeyEventL(): Reading value of KStartupSecurityCodeQueryStatus - State Value: %d"),securityQueryState));
+				//Disable keylock if Alarm is active or if a Security code query is active on the display
+				if ( alarmState == ECoreAppUIsDisableKeyguard || securityQueryState == ESecurityQueryActive )
+                 	{
+					KeyLock().DisableWithoutNote();               	
+                 	}
+			    else
+         		 	{
+         			KeyLock().EnableWithoutNote();
+         			}
                 }
             else
                 {
@@ -1688,16 +1701,16 @@
         {
         TRACES( RDebug::Print( _L("SysAp: charger removed") ) );
         iSysApLightsController->ChargerConnectedL( EFalse );    
-        iSysApUsbChargerDetector.Reset();
-        
+                
         if ( !iSysApUsbChargerDetector.HostOnlyUsbChargingUsed() &&
              iSysApFeatureManager->Supported( KSysApFeatureIdChargerReminderNotes ) )
             {
-		if(showNote)
+			if(showNote)
                 {
                 ShowUiNoteL( EUnplugChargerNote );
                 }
             }
+		iSysApUsbChargerDetector.Reset();
         }
     else if ( aValue == EChargingStatusNotCharging )
         {
--- a/coreapplicationuis/SysAp/Src/SysApLightsController.cpp	Wed Jun 09 09:52:12 2010 +0300
+++ b/coreapplicationuis/SysAp/Src/SysApLightsController.cpp	Mon Jun 21 15:51:07 2010 +0300
@@ -30,6 +30,7 @@
 
 #include "SysApFeatureManager.h"
 #include "startupdomainpskeys.h"
+#include <hal.h>
 
 // CONSTANTS
 
@@ -995,6 +996,8 @@
 		{
 		TRAP(err, iLight->LightOffL(CHWRMLight::ESystemTarget));
 		iSysApAppUi.StopChargingBatteryL();
+		//To switch off the display 
+		TInt result = HAL::Set( HALData::EDisplayState, 0 );
 		}            
     // Ignore unreserved in use warnings.
     if ( err != KErrNone && err != KErrInUse )
@@ -1101,6 +1104,8 @@
     		if ( error == KErrNone && state == ESwStateCharging ) 
 				{
 				iSysApAppUi.StartChargingBatteryL();
+				//To switch on the display 
+				TInt result = HAL::Set( HALData::EDisplayState, 1 );
 				}	
             }
         else
--- a/coreapplicationuis/SysAp/Src/SysApPubSubObserver.cpp	Wed Jun 09 09:52:12 2010 +0300
+++ b/coreapplicationuis/SysAp/Src/SysApPubSubObserver.cpp	Mon Jun 21 15:51:07 2010 +0300
@@ -1,5 +1,5 @@
 /*
-* Copyright (c) 2005-2009 Nokia Corporation and/or its subsidiary(-ies). 
+* Copyright (c) 2005-2010 Nokia Corporation and/or its subsidiary(-ies). 
 * All rights reserved.
 * This component and the accompanying materials are made available
 * under the terms of "Eclipse Public License v1.0"
@@ -712,7 +712,24 @@
                 break;                
                             
             }
-            
+        
+        if ( aValue == EFmTxStateActive )
+            {
+            if(iFmTxRemConObserver)
+                {
+                //Open Remcon and reserve the volume keys
+                iFmTxRemConObserver->StartRemconInterface();
+                }
+            }
+        else 
+            {
+            if(iFmTxRemConObserver)
+                {
+                //Disconnect from Remcon and release keys for other apps like phone app during call
+                iFmTxRemConObserver->StopRemconInterface();
+                }
+            }
+        
         if ( isFmTxTurnedOn )
             {
             if ( !iFmTxRemConObserver )
--- a/coreapplicationuis/SysAp/Src/sysapremconobserver.cpp	Wed Jun 09 09:52:12 2010 +0300
+++ b/coreapplicationuis/SysAp/Src/sysapremconobserver.cpp	Mon Jun 21 15:51:07 2010 +0300
@@ -1,5 +1,5 @@
 /*
-* Copyright (c) 2007 Nokia Corporation and/or its subsidiary(-ies). 
+* Copyright (c) 2007-2010 Nokia Corporation and/or its subsidiary(-ies). 
 * All rights reserved.
 * This component and the accompanying materials are made available
 * under the terms of "Eclipse Public License v1.0"
@@ -47,12 +47,6 @@
 void CSysApRemConObserver::ConstructL()
     {
     TRACES( RDebug::Print( _L("CSysApRemConObserver::ConstructL") ) );  
-    
-    iInterfaceSelector = CRemConInterfaceSelector::NewL();
-    
-    iCoreTarget = CRemConCoreApiTarget::NewL( *iInterfaceSelector, *this );
-    
-    iInterfaceSelector->OpenTargetL();
     }
 
 // -----------------------------------------------------------------------------
@@ -81,7 +75,6 @@
 CSysApRemConObserver::~CSysApRemConObserver()
     {
     TRACES( RDebug::Print( _L("CSysApRemConObserver::~CSysApRemConObserver") ) );
-    delete iInterfaceSelector; // Internally deletes iCoreTarget 
     }
     
 // -----------------------------------------------------------------------------
@@ -112,4 +105,31 @@
 	    }
 	}
 
+/**
+ * Reserve the volume keys
+ */
+void CSysApRemConObserver::StartRemconInterface()
+    {
+    TRACES( RDebug::Print( _L("CSysApRemConObserver::BlockKeys")));
+    if(!iInterfaceSelector)
+        {
+        iInterfaceSelector = CRemConInterfaceSelector::NewL();
+        iCoreTarget = CRemConCoreApiTarget::NewL( *iInterfaceSelector, *this );
+        iInterfaceSelector->OpenTargetL();
+        }
+    }
+
+/**
+ * Release the volume keys for other application like phone app during call
+ */
+void CSysApRemConObserver::StopRemconInterface()
+    {
+    TRACES( RDebug::Print( _L("CSysApRemConObserver::UnBlockKeys")));
+    if(iInterfaceSelector)
+        {
+        delete iInterfaceSelector;
+        iInterfaceSelector = NULL;
+        }
+    }
+
 //  End of File 
--- a/coreapplicationuis/advancedtspcontroller/data/keyevent.rul	Wed Jun 09 09:52:12 2010 +0300
+++ b/coreapplicationuis/advancedtspcontroller/data/keyevent.rul	Mon Jun 21 15:51:07 2010 +0300
@@ -22,9 +22,9 @@
             />
             
             <Tsp
-            routingTable='01'            
+            routingTable='01'           
+	    ruleActiveAudio='00' 
             ruleForeground='01'
-            ruleActiveAudio='00'
             ruleLastPlayedAudio='03'
             ruleDefaultApp='02'
             defaultApplicationPhone='100058B3'
@@ -113,9 +113,8 @@
             ruleActiveAudio='00'
             ruleLastPlayedAudio='03'
             ruleForeground='01' 
-            ruleDefaultApp='02'
-            defaultApplicationPhone='100058B3'
-            transparentApplicationBTAudioMan='10208971'
+	    ruleLaunchDefaultApp='04'
+            defaultLaunchApp='102072C3'
             />
             
             <Tsp
@@ -130,7 +129,6 @@
             ruleLastPlayedAudio='03'
             ruleDefaultApp='02'
             defaultApplicationPhone='100058B3'
-            transparentApplicationBTAudioMan='10208971'
 	    />
             
             <Tsp
--- a/coreapplicationuis/advancedtspcontroller/group/RemConTspController.mmp	Wed Jun 09 09:52:12 2010 +0300
+++ b/coreapplicationuis/advancedtspcontroller/group/RemConTspController.mmp	Mon Jun 21 15:51:07 2010 +0300
@@ -29,7 +29,8 @@
 SOURCE          remcontspcontrollermain.cpp
 SOURCE          remcontspcontroller.cpp
 SOURCE          remconidlelistener.cpp
-SOURCE          remconeventtable.cpp
+SOURCE          remconeventtable.cpp 
+SOURCE          tsptriggerevents.cpp
 
 START RESOURCE  ../data/10282CD5.rss
 target          AdvancedTspController.rsc
--- a/coreapplicationuis/advancedtspcontroller/inc/remcontspcontroller.h	Wed Jun 09 09:52:12 2010 +0300
+++ b/coreapplicationuis/advancedtspcontroller/inc/remcontspcontroller.h	Mon Jun 21 15:51:07 2010 +0300
@@ -29,9 +29,10 @@
 #include <cfclient.h>
 #include <cflistener.h>
 #include <AudioClientsListPSData.h>
+#include <remcon/clientinfo.h>
 #include "remconidlelistener.h"
 #include "remconeventtable.h"
-
+#include "tsptriggerevents.h"
 // CONSTANTS
 
 // MACROS
@@ -57,7 +58,10 @@
 class CRemConTspController : public CRemConTargetSelectorPlugin,
                  public MRemConTargetSelectorPluginInterfaceV2,
                  public MRemConTargetSelectorPluginInterfaceV3,
-			     public MCFListener
+                 public MRemConTargetSelectorPluginInterfaceV4,
+                 public MRemConTargetSelectorPluginInterfaceV5,
+			     public MCFListener,
+                 public MTspRulesTriggerObserver
 	{
 	public:		// Constructors and destructor
 		
@@ -243,6 +247,85 @@
                 const TClientInfo& aSender,
                 const TRemConAddress& aConnection);
         
+        /**
+        Called by RemCon to get the TSP to permit an incoming command. This is called
+        if the bearer has provided a target client for the command.  
+        
+        The implementor should decide if they wish to allow this command and then call
+        IncomingCommandPermitted on the observer with a suitable error. 
+        
+        @param aInterfaceUid The UID of the client interface.
+        @param aOperationId The operation ID of the command.
+        @param aClient a TClientInfo referring to the selected client
+        */
+        virtual void PermitIncomingCommand(
+            TUid aInterfaceUid,
+            TUint aOperationId, 
+            const TClientInfo& aClient);
+        
+        /**
+        Called by RemCon to get the TSP to permit an incoming Notify. This is called
+        if the bearer has provided a target client for the Notify.  
+        
+        The implementor should decide if they wish to allow this Notify and then call
+        IncomingNotifyPermitted on the observer with a suitable error. 
+        
+        @param aInterfaceUid The UID of the client interface.
+        @param aOperationId The operation ID of the Notify.
+        @param aClient a TClientInfo referring to the selected client
+        */
+        virtual void PermitIncomingNotify(
+            TUid aInterfaceUid,
+            TUint aOperationId, 
+            const TClientInfo& aClient);
+
+        /** 
+        Called by RemCon when a bearer that can address commands wishes to
+        inform the system that there has been a remote user action to 
+        select a different addressed client.
+        
+        The bearer will then route addressed commands to this client until
+        such time as SetRemoteAddressedClient is called again or the TSP
+        calls SetLocalAddressedClient.
+        
+        @param aBearerUid The bearer that has changed its addressed client
+        @param aClient The RemCon client that is now selected by the bearer
+        */
+        virtual void SetRemoteAddressedClient(const TUid& aBearerUid, 
+                const TClientInfo& aClient);
+        /** Called by RemCon when a new target client has connected.
+         
+         @aClientInfo The information about the new client.
+         */
+        void TargetClientAvailable(const TClientInfo& aClientInfo);
+        
+        /** Called by RemCon when a target client has disconnected. 
+         
+         @aClientInfo The information about the client that has disconnected.
+         */
+        void TargetClientUnavailable(const TClientInfo& aClientInfo);
+        
+        /** Called by RemCon when a bearer wishes to begin being informed when
+        the locally addressed player changes.  Once this function has been called
+        the TSP should inform RemCon via SetLocalAddressedPlayer each time the
+        player to which incoming commands from aBearer would be routed changes.
+        This might occur for example if a new application is launched, or if the
+        foreground application changes, depending on what the TSP's rules are
+        for deciding the target of the incoming message.  These updates should
+        occur until UnregisterLocalAddressedClientObserver is called.
+        
+        @param aBearerUid The bearer that wishes to be informed of updates
+        */
+        TInt RegisterLocalAddressedClientObserver(const TUid& aBearerUid);
+
+        /** Called by RemCon when a bearer wishes to stop being informed of 
+        changes to the local addresse client.
+        
+        @param aBearerUid The bearer that no longer wishes to be informed of updates
+        */
+        TInt UnregisterLocalAddressedClientObserver(const TUid& aBearerUid);
+
+        
 	    // From MCFListener
 	    
 	    /**
@@ -291,6 +374,8 @@
             const TDesC& aSource,
             const TDesC& aType );
             
+        // from MTspRulesTriggerObserver
+        void MtrtoEvaluateRoutingRules();
         /**
         * Gets the foreground application.
         * 
@@ -329,8 +414,9 @@
 	    void GetCorrectClientL(
             TUid aInterfaceUid,
         	TUint aKeyEvent,
-        	TSglQue<TClientInfo>& aClients );
-        
+        	TSglQue<TClientInfo>& aClients,
+        	TBool aLaunchingNewApplicationAllowed);
+
         void SetKeyEventTableL( const CCFActionIndication& aActionToExecute );        
 
         void ActivateApplicationL( const TUid aUid ) const;
@@ -352,12 +438,26 @@
         */
         TBool DeviceLocked() const;
 
-	private:    // Data
-	    
-	    // owned
-		CRemConIdleListener* iIdle;
-		
-		// Interface to P&S key that returns call state
+        /**
+         * Decide if locally addressed client should be updated.
+         */
+        TClientInfo* GetLocalAddressedClient();
+
+private:
+        NONSHARABLE_STRUCT(TClientObserver)
+            {
+        public:
+            TClientObserver(TUid aBearerUid) : iBearerUid(aBearerUid) {};
+        public:
+            TUid iBearerUid;
+            TSglQueLink iClientObserverQueLink;
+            };
+
+private:    // Data
+        // owned
+        CRemConIdleListener* iIdle;
+
+        // Interface to P&S key that returns call state
         RProperty iProperty;
         
         CCFClient* iCFClient;
@@ -371,6 +471,16 @@
         TProcessId iProcessIdActive;
 
         RPointerArray<CRemConEventTable> iArrayOfStoredTables;
+        
+        TSglQue<TClientObserver> iClientObservers;
+        
+        TSglQue<TClientInfo> iAvailableTargets;
+        
+        TSglQue<TClientInfo> iTargetsForAddressing;
+        
+        TClientInfo* iLocalAddressedClient;
+        
+        CTspTriggerEventsWatcher* iTriggerEventsWatcher;
 	
 	public:     // Friend classes
 	
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/coreapplicationuis/advancedtspcontroller/inc/tsptriggerevents.h	Mon Jun 21 15:51:07 2010 +0300
@@ -0,0 +1,104 @@
+/*
+* Copyright (c) 2010 Nokia Corporation and/or its subsidiary(-ies). 
+* All rights reserved.
+* This component and the accompanying materials are made available
+* under the terms of "Eclipse Public License v1.0"
+* which accompanies this distribution, and is available
+* at the URL "http://www.eclipse.org/legal/epl-v10.html".
+*
+* Initial Contributors:
+* Nokia Corporation - initial contribution.
+*
+* Contributors:
+*
+* Description: Observes changes in the default player that should be used for a bearer
+*/
+
+#include <e32base.h>
+#include <e32property.h>
+#include <w32std.h>
+
+
+NONSHARABLE_CLASS(MTspRulesTriggerObserver)
+    {
+public:
+    virtual void MtrtoEvaluateRoutingRules() = 0;
+    };
+
+NONSHARABLE_CLASS(CActiveAudioClientObserver) : public CActive
+    {
+public:
+    static CActiveAudioClientObserver* NewL(MTspRulesTriggerObserver& aObserver);
+    ~CActiveAudioClientObserver();
+
+private:
+    // from CActive
+    void RunL();
+    void DoCancel();
+    
+    CActiveAudioClientObserver(MTspRulesTriggerObserver& aObserver);
+    void ConstructL();
+
+private:
+    MTspRulesTriggerObserver& iObserver;
+    RProperty iAudioApplication;
+    };
+
+NONSHARABLE_CLASS(CTspClientMapperObserver) : public CActive
+    {
+public:
+    static CTspClientMapperObserver* NewL(MTspRulesTriggerObserver& aObserver);
+    ~CTspClientMapperObserver();
+
+private:
+    // from CActive
+    void RunL();
+    void DoCancel();
+    
+    CTspClientMapperObserver(MTspRulesTriggerObserver& aObserver);
+    void ConstructL();
+
+private:
+    MTspRulesTriggerObserver& iObserver;
+    RProperty iPlayingClients;
+    };
+
+NONSHARABLE_CLASS(CWsEventsObserver) : public CActive
+    {
+public:
+    static CWsEventsObserver* NewL(MTspRulesTriggerObserver& aObserver);
+    ~CWsEventsObserver();
+    
+private:
+    // from CActive
+    void RunL();
+    void DoCancel();
+    
+    CWsEventsObserver(MTspRulesTriggerObserver& aObserver);
+    void ConstructL();
+    
+private:
+    MTspRulesTriggerObserver& iObserver;
+    RWsSession iWsSession;
+    RWindowGroup iWindowGroup;
+    };
+
+NONSHARABLE_CLASS(CTspTriggerEventsWatcher) : public CBase
+    {
+public:
+    static CTspTriggerEventsWatcher* NewL(MTspRulesTriggerObserver& aObserver);
+    ~CTspTriggerEventsWatcher();
+    TInt AddBearer(TUid& aBearerUid);
+    TInt RemoveBearer(TUid& aBearerUid);
+
+private:
+    CTspTriggerEventsWatcher(MTspRulesTriggerObserver& aObserver);
+    void ConstructL();
+
+private:
+    MTspRulesTriggerObserver& iObserver;
+    CActiveAudioClientObserver* iAudioClientObserver;
+    CWsEventsObserver* iWsEventsObserver;
+    CTspClientMapperObserver* iClientMapperObserver;
+    };
+
--- a/coreapplicationuis/advancedtspcontroller/src/remcontspcontroller.cpp	Wed Jun 09 09:52:12 2010 +0300
+++ b/coreapplicationuis/advancedtspcontroller/src/remcontspcontroller.cpp	Mon Jun 21 15:51:07 2010 +0300
@@ -61,6 +61,8 @@
 // LOCAL CONSTANTS AND MACROS
 
 const TUint32 KUid3MusicPlayer = 0x102072C3;
+const TUint32 KUid3PhoneApp = 0x100058B3; 
+const TUint32 KUid3VoiceCmdApp = 0x102818e7;
 
 //#define __MODULE_TEST__
 
@@ -108,9 +110,11 @@
 // -----------------------------------------------------------------------------
 //
 
-CRemConTspController::CRemConTspController( 
-								MRemConTargetSelectorPluginObserver& aObserver )
-:	CRemConTargetSelectorPlugin( aObserver )
+CRemConTspController::CRemConTspController(MRemConTargetSelectorPluginObserver& aObserver )
+    : CRemConTargetSelectorPlugin( aObserver )
+    , iClientObservers(_FOFF(TClientObserver, iClientObserverQueLink))
+    , iAvailableTargets(_FOFF(TClientInfo, iLink))
+    , iTargetsForAddressing(_FOFF(TClientInfo, iLink2))
 	{
 	}
     
@@ -154,6 +158,24 @@
 	    }
     iArrayOfTables.ResetAndDestroy();
     iArrayOfStoredTables.ResetAndDestroy();
+    
+    TClientInfo* clientInfo;
+    while(!iAvailableTargets.IsEmpty())
+        {
+        clientInfo = iAvailableTargets.First();
+        iAvailableTargets.Remove(*clientInfo);
+        delete clientInfo;
+        }
+
+    TClientObserver* clientObserver;
+    while(!iClientObservers.IsEmpty())
+        {
+        clientObserver = iClientObservers.First();
+        iClientObservers.Remove(*clientObserver);
+        delete clientObserver;
+        }
+    iTargetsForAddressing.Reset(); 
+    delete iTriggerEventsWatcher;
 	COM_TRACE_( "[REMCONTSPCONTROLLER] CRemConTspController::~CRemConTspController() - return" );
 	}
 
@@ -186,6 +208,16 @@
 		ret = reinterpret_cast<TAny*>(
 			static_cast<MRemConTargetSelectorPluginInterfaceV3*>(this) );
 		}
+    else if ( aUid == TUid::Uid(KRemConTargetSelectorInterface4) )
+        {
+        ret = reinterpret_cast<TAny*>(
+            static_cast<MRemConTargetSelectorPluginInterfaceV4*>(this) );
+        }
+    else if ( aUid == TUid::Uid(KRemConTargetSelectorInterface5) )
+        {
+        ret = reinterpret_cast<TAny*>(
+            static_cast<MRemConTargetSelectorPluginInterfaceV5*>(this) );
+        }
 	COM_TRACE_1( "[REMCONTSPCONTROLLER] CRemConTspController::GetInterface() this=%d", ret );
 	return ret;
 	}
@@ -338,9 +370,7 @@
 #ifdef _DEBUG	
 	TraceRemconTargets( aClients );
 #endif
-	
-	TRAPD( err, GetCorrectClientL( aInterfaceUid, aOperationId, aClients ) );
-	
+	TRAPD( err, GetCorrectClientL( aInterfaceUid, aOperationId, aClients, ETrue ) );
 	Observer().IncomingCommandAddressed( err );
 	
 	COM_TRACE_( "[REMCONTSPCONTROLLER] CRemConTspController::AddressIncomingCommand() ends" );
@@ -397,6 +427,228 @@
     }
 
 // -----------------------------------------------------------------------------
+// CRemConTspController::PermitIncomingCommand
+// By default, permit all incoming addressed commands.  Check if the command
+// comes from the AVRCP bearer an if so launch the music player.
+// -----------------------------------------------------------------------------
+void CRemConTspController::PermitIncomingCommand(
+    TUid aInterfaceUid,
+    TUint aOperationId, 
+    const TClientInfo& aClient)
+    {
+	(void) aClient;  // Not used. 
+    // Here we need to check the incoming command.  If it is an AVRCP play
+    // command and there is no sensible handler running we should launch the
+    // MPX Music Player.  This is the same as for AddressIncomingCommand.
+    // Check if appropriate handler running
+    if ((aInterfaceUid != TUid::Uid(KRemConCoreApiUid)) ||
+         (aOperationId != ERemConCoreApiPlay) ||
+         GetLocalAddressedClient())
+        {
+        // no action needed, allow commmand
+        Observer().IncomingCommandPermitted(ETrue);
+        }
+     else 
+        {
+        // Launch an appropriate player in playing state. 
+        TRAPD(err, ActivateApplicationL(TUid::Uid(KUid3MusicPlayer)))
+        if(err != KErrNone)
+            {
+
+            }
+
+        //deny this command
+        Observer().IncomingCommandPermitted(EFalse);
+
+        // We will be informed when the MPX music player connects its client 
+        // session.  That will trigger a rules evaluation which will result in
+        // us informing interested bearers of the new local addressed player.
+        }
+    }
+
+// -----------------------------------------------------------------------------
+// CRemConTspController::PermitIncomingNotify
+// By default, permit all incoming addressed commands.  Check if the command
+// comes from the AVRCP bearer an if so launch the music player.
+// -----------------------------------------------------------------------------
+void CRemConTspController::PermitIncomingNotify(
+    TUid /*aInterfaceUid*/,
+    TUint /*aOperationId*/, 
+    const TClientInfo& /*aClient*/)
+    {
+    // No reason to stop these, just allow all
+    Observer().IncomingNotifyPermitted(ETrue);
+    }
+
+// -----------------------------------------------------------------------------
+// CRemConTspController::SetRemoteAddressedClient
+// Ignore this event.  We don't use what the remote has selected to influence
+// our routing policy.
+// -----------------------------------------------------------------------------
+void CRemConTspController::SetRemoteAddressedClient(const TUid& /*aBearerUid*/, 
+        const TClientInfo& /*aClient*/)
+    {
+    }
+
+// -----------------------------------------------------------------------------
+// CRemConTspController::TargetClientAvailable
+// A new client has connected.  Trigger a rule evaluation to see if we want to switch
+// to this client.
+// -----------------------------------------------------------------------------
+void CRemConTspController::TargetClientAvailable(const TClientInfo& aClientInfo)
+    {
+    COM_TRACE_1("[REMCONTSPCONTROLLER] CRemConTspController::TargetClientAvailable aClientInfo.SecureId=0x%x", aClientInfo.SecureId().iId);
+
+    TClientInfo* clientInfo;
+    TSglQueIter<TClientInfo> iter(iAvailableTargets);
+    
+    while((clientInfo = iter++) != NULL)
+        {
+        if(clientInfo->SecureId() == aClientInfo.SecureId())
+            {
+            // Found a client and clientInfo points to that now. 
+            break; 
+            }
+        }
+    
+    // If clientInfo was not found, create it and add to the available targets queue. 
+    if(!clientInfo)
+        {
+        TClientInfo* newTarget = new TClientInfo();
+        if(newTarget)
+            {
+            newTarget->ProcessId() = aClientInfo.ProcessId();
+            newTarget->SecureId() = aClientInfo.SecureId();
+            
+            // Add to our list of available targets
+            iAvailableTargets.AddLast(*newTarget);
+            }
+        }
+
+    // Re-evaluate what the default addressed player should be if someone is interested to know 
+    if(!iClientObservers.IsEmpty())
+        {
+        MtrtoEvaluateRoutingRules();
+        }
+    }
+
+// -----------------------------------------------------------------------------
+// CRemConTspController::TargetClientUnavailable
+// A client has disconnected.  Trigger a rule evaluation to see if our default
+// player has changed.
+// -----------------------------------------------------------------------------
+void CRemConTspController::TargetClientUnavailable(const TClientInfo& aClientInfo)
+    {
+    COM_TRACE_1("[REMCONTSPCONTROLLER] CRemConTspController::TargetClientUnavailable aClientInfo.SecureId=0x%x", aClientInfo.SecureId().iId);
+
+    // Remove this from our list of available targets
+    if(!iAvailableTargets.IsEmpty())
+        {
+        TClientInfo* clientInfo;
+        TSglQueIter<TClientInfo> iter(iAvailableTargets);
+        while((clientInfo = iter++) != NULL)
+            {
+            if(clientInfo->SecureId() == aClientInfo.SecureId())
+                {
+                iAvailableTargets.Remove(*clientInfo);
+                delete clientInfo;
+                break;
+                }
+            }
+        }
+
+    if(!iClientObservers.IsEmpty())
+        {
+        // Re-evaluate what the default addressed player should be if someone is listening. 
+        MtrtoEvaluateRoutingRules();
+        }
+    }
+
+// -----------------------------------------------------------------------------
+// CRemConTspController::RegisterLocalAddressedClientObserver
+// A bearer is interested in what the local addressed player is.  Start observing.
+// -----------------------------------------------------------------------------
+TInt CRemConTspController::RegisterLocalAddressedClientObserver(const TUid& aBearerUid)
+    {
+    COM_TRACE_1("[REMCONTSPCONTROLLER] CRemConTspController::RegisterLocalAddressedClientObserver aBearerUid.SecureId=0x%x", aBearerUid.iUid);
+    TInt err = KErrNone;
+    // Add this to our list of bearers interested in the default addressed player
+    TClientObserver* clientObserver = new TClientObserver(aBearerUid);
+
+    if(!clientObserver)
+        {
+        err = KErrNoMemory; 
+        }
+
+    // If this is our first interested bearer kick off the trigger events watcher.
+    // This will let us know if any event occurs that should trigger us to re-evaluate
+    // our addressing rules
+    if(!iTriggerEventsWatcher && err == KErrNone)
+        {
+        TRAP(err, iTriggerEventsWatcher = CTspTriggerEventsWatcher::NewL(*this));
+        if(err != KErrNone)
+            {
+            // If we couldn't create the events watcher the client Observer is not needed either.
+            delete clientObserver;
+            }
+        }
+
+    if(err == KErrNone)
+        {
+        // Finally add the observer to the queue if it's not there yet. 
+        TSglQueIter<TClientObserver> iter(iClientObservers);
+        TClientObserver* obsInQueue;
+        while((obsInQueue = iter++) != NULL)
+            {
+            if(obsInQueue->iBearerUid == aBearerUid)
+                {
+                err = KErrAlreadyExists; 
+                break;
+                }
+            }
+
+        if(!obsInQueue)
+            {
+            iClientObservers.AddLast(*clientObserver);
+            MtrtoEvaluateRoutingRules();
+            }
+        }
+
+    return err;
+    }
+
+// -----------------------------------------------------------------------------
+// CRemConTspController::UnregisterLocalAddressedClientObserver
+// The bearer is no longer interested in observering default client changes.
+// -----------------------------------------------------------------------------
+TInt CRemConTspController::UnregisterLocalAddressedClientObserver(const TUid& aBearerUid)
+    {
+    COM_TRACE_1("[REMCONTSPCONTROLLER] CRemConTspController::UnregisterLocalAddressedClientObserver aBearerUid.SecureId=0x%x", aBearerUid.iUid);
+    // Remove this from our list of bearers interested in the default addressed player.
+    // If there are no interested bearers left then we can stop watching for rules
+    // triggers.
+    TSglQueIter<TClientObserver> iter(iClientObservers);
+    TClientObserver* clientObserver;
+    while((clientObserver = iter++) != NULL)
+        {
+        if(clientObserver->iBearerUid == aBearerUid)
+            {
+            iClientObservers.Remove(*clientObserver);
+	    delete clientObserver;
+            break;
+            }
+        }
+    
+    if(iClientObservers.IsEmpty())
+        {
+        delete iTriggerEventsWatcher;
+        iTriggerEventsWatcher = NULL;
+        }
+    
+    return KErrNone;
+    }
+
+// -----------------------------------------------------------------------------
 // CRemConTspController::GetCorrectClientL
 // Defines remote targets to which command will be sent.
 // (other items were commented in a header).
@@ -405,10 +657,12 @@
 void CRemConTspController::GetCorrectClientL(
     TUid aInterfaceUid,
 	TUint aKeyEvent,
-	TSglQue<TClientInfo>& aClients )
+	TSglQue<TClientInfo>& aClients,
+	TBool aLaunchingNewApplicationAllowed)
 	{
 	COM_TRACE_1( "[REMCONTSPCONTROLLER] CRemConTspController::GetCorrectClientL() Start aInterfaceUid %d", aInterfaceUid );
 	COM_TRACE_1( "[REMCONTSPCONTROLLER] CRemConTspController::GetCorrectClientL() Start aKeyEvent %d", aKeyEvent );
+
     TInt numOfTables = iArrayOfTables.Count();
     RArray<TInt> rulesArray;
     CleanupClosePushL( rulesArray );
@@ -513,6 +767,7 @@
             	    TProcessId processId = target->ProcessId();
             	    if( iProcessIdForeground == processId )
             	        {
+                        COM_TRACE_( "[REMCONTSPCONTROLLER] CRemConTspController::GetCorrectClientL() Foreground client found" );
             	        aClients.Reset();
             	        aClients.AddFirst( *target );
             	        found = ETrue;
@@ -613,7 +868,7 @@
             case CRemConEventTable::ELaunchDefaultApp:
                 {
                 COM_TRACE_( "[REMCONTSPCONTROLLER] CRemConTspController::GetCorrectClientL() Launch default application" );                
-                if ( !DeviceLocked() )
+                if ( !DeviceLocked() && aLaunchingNewApplicationAllowed )
                     {
                     TUid defaultLaunchAppUid;
                     
@@ -648,6 +903,9 @@
         else if( rulesArray.Count() - 1 == i )
             {
             COM_TRACE_( "[REMCONTSPCONTROLLER] CRemConTspController::GetCorrectClientL() No client found");
+            // Reset the list to reflect the fact that no clients were found. 
+            // The possible transparent clients will be added still. 
+            aClients.Reset();
             }
         }
 
@@ -657,7 +915,8 @@
         TClientInfo* target = transparentClients[ i ];
         if ( !FindRemconConnection( target->SecureId(), aClients ) ) // Add client only if not already found
             {
-            aClients.AddFirst( *target );
+            // Add to the end of the list, any other client should take priority over the transparent clients. 
+            aClients.AddLast( *target );  
             COM_TRACE_1( "[REMCONTSPCONTROLLER] CRemConTspController::GetCorrectClientL() transparent client 0x%x added", target->SecureId().iId );
             }
         }
@@ -1059,6 +1318,40 @@
     }
 
 // -----------------------------------------------------------------------------
+// CRemConTspController::MtrtoEvaluateRoutingRules
+// Evaluates the TSP's routing rules to determine if the local addressed player
+// has changed, and if so informs interested bearers
+// -----------------------------------------------------------------------------
+void CRemConTspController::MtrtoEvaluateRoutingRules()
+    {
+    COM_TRACE_( "[REMCONTSPCONTROLLER] CRemConTspController::MtrtoEvaluateRoutingRules() - Enter" ); 
+    TClientInfo* localAddressedClient = GetLocalAddressedClient();
+
+    if(!localAddressedClient)
+        {
+        // If there's no suitable client, then there's nothing to do here.   
+        COM_TRACE_( "[REMCONTSPCONTROLLER] CRemConTspController::MtrtoEvaluateRoutingRules() No local addressed client found" ); 
+        return; 
+        }
+
+    if(!iLocalAddressedClient || (localAddressedClient->SecureId() != iLocalAddressedClient->SecureId()))
+        {
+        // Local addressed player has changed (or wasn't set before).  
+        iLocalAddressedClient = localAddressedClient;
+        COM_TRACE_( "[REMCONTSPCONTROLLER] CRemConTspController::MtrtoEvaluateRoutingRules() Local addressed client has changed" ); 
+        TSglQueIter<TClientObserver> iter(iClientObservers);
+        TClientObserver* clientObserver;
+        while((clientObserver = iter++) != NULL)
+            {
+            COM_TRACE_( "[REMCONTSPCONTROLLER] CRemConTspController::MtrtoEvaluateRoutingRules() - informing observer" ); 
+            Observer().SetLocalAddressedClient(clientObserver->iBearerUid, *iLocalAddressedClient);
+            }
+        }
+    COM_TRACE_1( "[REMCONTSPCONTROLLER] CRemConTspController::MtrtoEvaluateRoutingRules() Local addressed client SID = 0x%x",  iLocalAddressedClient->SecureId().iId);
+    COM_TRACE_( "[REMCONTSPCONTROLLER] CRemConTspController::MtrtoEvaluateRoutingRules() - Return" ); 
+    }
+
+// -----------------------------------------------------------------------------
 // CRemConTspController::CreateAfterIdleL
 // Define the contexts when idle state has been loaded.
 // (other items were commented in a header).
@@ -1485,4 +1778,50 @@
     return EFalse;
     }
 
+//----------------------------------------------------------------------------------
+// CRemConTspController::GetLocalAddressedClient
+// Uses TSP rules to determine what local addressed client should be.
+//-----------------------------------------------------------------------------------
+TClientInfo* CRemConTspController::GetLocalAddressedClient()
+    {
+    COM_TRACE_( "[REMCONTSPCONTROLLER] CRemConTspController::GetLocalAddressedClient() Entry");
+    // Create list of available clients to allow re-use of existing rule 
+    // evaluation function, GetCorrectClientL
+    iTargetsForAddressing.Reset();
+    TSglQueIter<TClientInfo> iter(iAvailableTargets);
+    TClientInfo* clientInfo;
+    while((clientInfo = iter++) != NULL)
+        {
+        iTargetsForAddressing.AddLast(*clientInfo);
+        }
+    
+#ifdef _DEBUG   
+    TraceRemconTargets( iTargetsForAddressing );
+#endif
+    
+    TRAPD(err, GetCorrectClientL(TUid::Uid(KRemConCoreApiUid), ERemConCoreApiPlay, iTargetsForAddressing, EFalse));
+    if(iTargetsForAddressing.IsEmpty() || err)
+        {
+        clientInfo = NULL;
+        COM_TRACE_( "[REMCONTSPCONTROLLER] CRemConTspController::GetLocalAddressedClient() No target Found");
+        }
+    else
+        {
+        // We don't want to set the phone application or voice command handler as local addressed client. 
+        // So choose the first item that is neither of those. The clientInfo may be NULL in the end. 
+        TSglQueIter<TClientInfo> localAddressedIter(iTargetsForAddressing);
+        while((clientInfo = localAddressedIter++) != NULL)
+            {
+            if( clientInfo->SecureId() != TSecureId(KUid3PhoneApp) || 
+                clientInfo->SecureId() != TSecureId(KUid3VoiceCmdApp) )
+                {
+                COM_TRACE_1( "[REMCONTSPCONTROLLER] CRemConTspController::GetLocalAddressedClient() Local addressed client SID = %08x",  clientInfo->SecureId().iId);
+                break;
+                }
+            }
+        }
+
+    return clientInfo;
+    }
+
 // End of file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/coreapplicationuis/advancedtspcontroller/src/tsptriggerevents.cpp	Mon Jun 21 15:51:07 2010 +0300
@@ -0,0 +1,212 @@
+/*
+* Copyright (c) 2010 Nokia Corporation and/or its subsidiary(-ies). 
+* All rights reserved.
+* This component and the accompanying materials are made available
+* under the terms of "Eclipse Public License v1.0"
+* which accompanies this distribution, and is available
+* at the URL "http://www.eclipse.org/legal/epl-v10.html".
+*
+* Initial Contributors:
+* Nokia Corporation - initial contribution.
+*
+* Contributors:
+*
+* Description: Observes changes in the default player that should be used for a bearer
+*/
+
+#include <AudioClientsListPSKeys.h>
+#include "tsptriggerevents.h"
+#include "RemConDebug.h"
+//-----------------------------------------------------------------------
+// CTspTriggerEventsWatcher
+//-----------------------------------------------------------------------
+CTspTriggerEventsWatcher* CTspTriggerEventsWatcher::NewL(MTspRulesTriggerObserver& aObserver)
+    {
+    CTspTriggerEventsWatcher* self = new(ELeave)CTspTriggerEventsWatcher(aObserver);
+    CleanupStack::PushL(self);
+    self->ConstructL();
+    CleanupStack::Pop(self);
+    return self;
+    }
+
+CTspTriggerEventsWatcher::CTspTriggerEventsWatcher(MTspRulesTriggerObserver& aObserver)
+    : iObserver(aObserver)
+    {
+    }
+
+void CTspTriggerEventsWatcher::ConstructL()
+    {
+    // Create WServ event watcher
+    iWsEventsObserver = CWsEventsObserver::NewL(iObserver);
+    
+    // Create observer for audio routing
+    iAudioClientObserver = CActiveAudioClientObserver::NewL(iObserver);
+    
+    // Create observer for TSP client mapper
+    iClientMapperObserver = CTspClientMapperObserver::NewL(iObserver);
+    }
+
+CTspTriggerEventsWatcher::~CTspTriggerEventsWatcher()
+    {
+    delete iAudioClientObserver;
+    delete iWsEventsObserver;
+    delete iClientMapperObserver;
+    }
+
+//-----------------------------------------------------------------------
+// CWsEventsObserver
+//-----------------------------------------------------------------------
+CWsEventsObserver* CWsEventsObserver::NewL(MTspRulesTriggerObserver& aObserver)
+    {
+    CWsEventsObserver* self = new(ELeave)CWsEventsObserver(aObserver);
+    CleanupStack::PushL(self);
+    self->ConstructL();
+    CleanupStack::Pop(self);
+    return self;
+    }
+
+CWsEventsObserver::~CWsEventsObserver()
+    {
+    Cancel(); 
+    iWindowGroup.Close(); 
+    iWsSession.Close();
+    }
+
+CWsEventsObserver::CWsEventsObserver(MTspRulesTriggerObserver& aObserver)
+    : CActive(CActive::EPriorityStandard), iObserver(aObserver), iWsSession(), iWindowGroup(iWsSession)
+    {
+    }
+
+void CWsEventsObserver::ConstructL()
+    {
+    // Register to recieve WServ events
+    CActiveScheduler::Add(this);    
+    User::LeaveIfError(iWsSession.Connect());
+    iWindowGroup = RWindowGroup(iWsSession); 
+    User::LeaveIfError(iWindowGroup.Construct(reinterpret_cast<TUint32>(this), EFalse));
+    iWindowGroup.SetOrdinalPosition(-1); 
+    iWindowGroup.DefaultOwningWindow(); 
+    iWindowGroup.EnableReceiptOfFocus(EFalse);    
+    iWindowGroup.EnableGroupListChangeEvents(); // For changes in z-order 
+    iWsSession.EventReady(&iStatus);
+    SetActive(); 
+    }
+
+
+void CWsEventsObserver::RunL()
+    {
+    COM_TRACE_( "[REMCONTSPCONTROLLER] CWsEventsObserver::RunL" );
+    TWsEvent event;
+    iWsSession.GetEvent(event);
+    iWsSession.EventReady(&iStatus);
+    SetActive(); 
+    if(event.Type() == EEventWindowGroupListChanged)
+        {
+        COM_TRACE_( "[REMCONTSPCONTROLLER] CWsEventsObserver::RunL - EEventWindowGroupListChanged" );
+        iObserver.MtrtoEvaluateRoutingRules();
+        }
+    }
+
+void CWsEventsObserver::DoCancel()
+    {
+    iWsSession.EventReadyCancel();
+    }
+
+//-----------------------------------------------------------------------
+// CActiveAudioClientObserver
+//-----------------------------------------------------------------------
+CActiveAudioClientObserver* CActiveAudioClientObserver::NewL(MTspRulesTriggerObserver& aObserver)
+    {
+    CActiveAudioClientObserver* self = new(ELeave)CActiveAudioClientObserver(aObserver);
+    CleanupStack::PushL(self);
+    self->ConstructL();
+    CleanupStack::Pop(self);
+    return self;
+    }
+
+CActiveAudioClientObserver::~CActiveAudioClientObserver()
+    {
+    Cancel(); 
+    iAudioApplication.Close();
+    }
+
+CActiveAudioClientObserver::CActiveAudioClientObserver(MTspRulesTriggerObserver& aObserver)
+    : CActive(CActive::EPriorityStandard), iObserver(aObserver)
+    {
+    }
+
+void CActiveAudioClientObserver::ConstructL()
+    {
+    User::LeaveIfError(iAudioApplication.Attach(KPSUidMMFAudioServer, KAudioPolicyApplicationAudioStatePlaying));
+    CActiveScheduler::Add(this);    
+    iAudioApplication.Subscribe(iStatus);
+    SetActive(); 
+    }
+
+
+void CActiveAudioClientObserver::RunL()
+    {
+    // Doesn't matter what the value is - that'll be checked when evaluation
+    // the TSP target rules.  Inform the TSP of the value change and 
+    // re-subscribe.
+    COM_TRACE_( "[REMCONTSPCONTROLLER] CWsEventsObserver::RunL" );
+    iAudioApplication.Subscribe(iStatus);
+    SetActive(); 
+    iObserver.MtrtoEvaluateRoutingRules();
+    }
+
+void CActiveAudioClientObserver::DoCancel()
+    {
+    iAudioApplication.Cancel();
+    }
+
+//-----------------------------------------------------------------------
+// CTspClientMapperObserver
+//-----------------------------------------------------------------------
+CTspClientMapperObserver* CTspClientMapperObserver::NewL(MTspRulesTriggerObserver& aObserver)
+    {
+    CTspClientMapperObserver* self = new(ELeave)CTspClientMapperObserver(aObserver);
+    CleanupStack::PushL(self);
+    self->ConstructL();
+    CleanupStack::Pop(self);
+    return self;
+    }
+
+CTspClientMapperObserver::~CTspClientMapperObserver()
+    {
+    Cancel(); 
+    }
+
+CTspClientMapperObserver::CTspClientMapperObserver(MTspRulesTriggerObserver& aObserver)
+    : CActive(CActive::EPriorityStandard), iObserver(aObserver)
+    {
+    }
+
+void CTspClientMapperObserver::ConstructL()
+    {
+    const TUid KTspClientMapperProperty = { 0x10200C70 };
+    const TUint32 KTspClientMapperKeyPlaying = 0x00000001;
+    User::LeaveIfError(iPlayingClients.Attach(KTspClientMapperProperty, KTspClientMapperKeyPlaying));
+    CActiveScheduler::Add(this);    
+    iPlayingClients.Subscribe(iStatus);
+    SetActive(); 
+    }
+
+
+void CTspClientMapperObserver::RunL()
+    {
+    // Doesn't matter what the value is - that'll be checked when evaluating
+    // the TSP target rules.  Inform the TSP of the value change and 
+    // re-subscribe.
+    COM_TRACE_( "[REMCONTSPCONTROLLER] CWsEventsObserver::RunL" );
+    iPlayingClients.Subscribe(iStatus);
+    SetActive(); 
+    iObserver.MtrtoEvaluateRoutingRules();
+    }
+
+void CTspClientMapperObserver::DoCancel()
+    {
+    iPlayingClients.Cancel();
+    }
+
+
Binary file systemsettings/gssensorplugin/conf/sensorplugin_10282DF0.crml has changed
--- a/tzservices/tzloc/src/TzLocalizationDbAccessor.cpp	Wed Jun 09 09:52:12 2010 +0300
+++ b/tzservices/tzloc/src/TzLocalizationDbAccessor.cpp	Mon Jun 21 15:51:07 2010 +0300
@@ -1,4 +1,4 @@
-// Copyright (c) 2004-2009 Nokia Corporation and/or its subsidiary(-ies).
+// Copyright (c) 2004-2010 Nokia Corporation and/or its subsidiary(-ies).
 // All rights reserved.
 // This component and the accompanying materials are made available
 // under the terms of "Eclipse Public License v1.0"
@@ -111,12 +111,15 @@
 		}
 	User::LeaveIfError(error);
 	// Check if both tables are created.
-	TRAP(error, iLocalizedTimeZoneDb.ColSetL(KCZTableName));
+	CDbColSet *colSet = NULL;
+	TRAP(error, colSet = iLocalizedTimeZoneDb.ColSetL(KCZTableName));
+	delete colSet;
 	if (error)
 		{
 		User::LeaveIfError(CreateFrequentlyUsedZoneTableL());
 		}
-	TRAP(error, iLocalizedTimeZoneDb.ColSetL(KUCTableName));
+	TRAP(error, colSet = iLocalizedTimeZoneDb.ColSetL(KUCTableName));
+	delete colSet;
 	if (error)
 	        {
 		User::LeaveIfError(CreateUserCityTableL());