syncmlfw/common/sosserver/src/nsmlsosthread.cpp
branchRCL_3
changeset 62 19bba8228ff0
parent 61 b183ec05bd8c
child 76 3cdbd92ee07b
--- a/syncmlfw/common/sosserver/src/nsmlsosthread.cpp	Tue Aug 31 16:04:06 2010 +0300
+++ b/syncmlfw/common/sosserver/src/nsmlsosthread.cpp	Wed Sep 01 12:27:42 2010 +0100
@@ -19,7 +19,7 @@
 #include <DevManInternalCRKeys.h>
 #include <centralrepository.h>
 #include <nsmldebug.h>
-#include "PnpLogger.h"
+
 #include "nsmlsosthread.h"
 #include <DataSyncInternalPSKeys.h>
 
@@ -27,27 +27,6 @@
 #include <centralrepository.h>
 #include "PMUtilInternalCRKeys.h"
 #include <featmgr.h>
-#include <e32property.h>
-#include <DevManInternalCRKeys.h>
-#include <nsmldmconst.h>
-
-
-enum TSyncmlHbNotifierKeys 
-		{
-
-     EHbSOSNotifierKeyStatus = 11, // status set will complete the client subscribe
-     EHbSOSNotifierKeyStatusReturn = 12, // Return the content of actual status value accepted from UI
-     
-     EHbDMSyncNotifierKeyStatus = 13,
-     EHbDMSyncNotifierKeyStatusReturn = 14
-		};
-		
- TUid sosserverpsuid =
-           {
-           0x101F99FB
-           };
-    	  
-  
 // --------------------------------------------------------------------------
 // EXPORT_C TInt ThreadFunction( TAny* )
 // --------------------------------------------------------------------------
@@ -91,7 +70,7 @@
 			{
 			//if not a silent mode behave as in a normal DM session
 			threadEngine->ForcedCertificateCheckL( EFalse );
-			threadEngine->VerifyJobFromNotifierL(ETrue);		
+			threadEngine->VerifyJobFromNotifierL();		
 			}
 		}
 	else
@@ -121,8 +100,7 @@
 	        CActiveScheduler::Start();                
 	        }	    
 	    }	
-	LOGSTRING("P&S is deleted");  
-	RProperty::Delete(KPSUidNSmlSOSServerKey,KNSmlDMSilentJob);
+	
 	delete scheduler;
 	
 	if ( endStatus == KErrNone )
@@ -169,7 +147,9 @@
 		FeatureManager::InitializeLibL();
 	iThreadParams.iThreadEngine = this;
 	iContentArray = new(ELeave) CArrayFixFlat<TNSmlContentSpecificSyncType>(1);
-	
+	// Fix for cancel not happening when cancel key is
+	// pressed .
+	iSyncCancelled = EFalse;
 	if ( iThreadParams.iCSArray )
 		{
 		for (TInt i = 0; i < iThreadParams.iCSArray->Count(); i++)
@@ -359,11 +339,63 @@
 	TInt status( KErrNone );			
 	if ( iThreadParams.iCurrentJob.UsageType() == ESmlDevMan )
 		{
+		CRepository* centrep = NULL;
+		TRAPD( err, centrep = CRepository::NewL(KCRUidDeviceManagementInternalKeys));  
+		TInt phoneLock(0);
+		TInt factoryProfileID(0);
+		if (err==KErrNone ) 
+		{
+			TInt err = centrep->Get( KLAWMOPhoneLock , phoneLock );
+			err = centrep->Get( KLAWMOfactoryDmProfileID , factoryProfileID );
+			delete centrep;
+			centrep = NULL;
+		}
+		if(phoneLock != 30)
+		{
+			_DBG_FILE("CNSmlThreadEngine phonelock != 30");
+			if(factoryProfileID>0)   
+			{   
+
+				TInt profileId = iThreadParams.iCurrentJob.ProfileId();    
+	
+				if(profileId!= factoryProfileID) 
+					{
+					   _DBG_FILE("CNSmlThreadEngine profid doesnt match with factory");
+					   TRequestStatus* stat = &iStatus;
+					   User::RequestComplete( stat, KErrNone );
+					   return;
+					}   
+			
+			}
+			else
+				{
+				    _DBG_FILE("CNSmlThreadEngine factoryprofileid<0");
+				    TRequestStatus* stat = &iStatus;
+					User::RequestComplete( stat, KErrNone );
+					return;	
+				}
+		}
+		_DBG_FILE("CNSmlThreadEngine startDMSessionL");
 		TRAP( status, StartDMSessionL() );
 		}
 	else
 		{
-		TRAP( status, StartDSSessionL() );	
+		// Scenario 1:
+		// Fix for cancel not happening when cancel key is
+		// pressed .
+        if(!iSyncCancelled)
+            {
+            TRAP( status, StartDSSessionL() );	
+            }
+        else
+            {
+			// Sync is cancelled from the UI before the
+			// the job session has started.
+			// Fix for cancel not happening when cancel key is
+			// pressed .
+            status = KErrCancel;
+            iSyncCancelled = EFalse;
+            }
 		}
 	
 	if ( status != KErrNone )
@@ -381,6 +413,11 @@
 //
 void CNSmlThreadEngine::CancelJob()
 	{
+	// Fix for cancel not happening when cancel key is
+	// pressed .
+    // job has been created but it is not running and from ui
+    // Cancel has been called
+    iSyncCancelled = ETrue;
 	if ( iCancelTimeout )
 	    {
 		iCancelTimeout->SetJobCancelled( iThreadParams.iCurrentJob.UsageType() );
@@ -431,7 +468,15 @@
 	
 	// Select correct sync method and start sync
 	TNSmlSyncInitiation syncInit = (TNSmlSyncInitiation)iThreadParams.iSyncInit;
-	
+	// Scenario 2:
+	// Fix for cancel not happening when cancel key is
+	// pressed .
+	if(iSyncCancelled)
+	    {
+	    iSyncCancelled = EFalse;
+        User::Leave( KErrCancel );
+	    }
+
     switch ( iThreadParams.iCurrentJob.JobType() )
         {
         case EDSJobProfile:
@@ -468,24 +513,19 @@
 // Launches notifier and waits for 
 // --------------------------------------------------------------------------
 //
-TInt CNSmlThreadEngine::VerifyJobFromNotifierL(TBool aServerInitiated)
-    {
-    LOGSTRING("CNSmlThreadEngine::VerifyJobFromNotifierL()");
-    LOGSTRING("CNSmlThreadEngine::VerifyJobFromNotifierL() : Begin");
-    LOGSTRING2("VerifyJobFromNotifierL before iCallerStatus == iStatus in Threadengine %d", iStatus.Int());
-    iNotifierObserver = new (ELeave) CNSmlNotifierObserver(iStatus,
-            iThreadParams);
-    SetActive();
-    LOGSTRING2("VerifyJobFromNotifierL before iCallerStatus == iStatus in Threadengine %d after setactive", iStatus.Int());
-    TSyncMLAppLaunchNotifParams params;
-    params.iSessionType = (iThreadParams.iCurrentJob.UsageType()
-            == ESmlDataSync) ? ESyncMLSyncSession : ESyncMLMgmtSession;
-    params.iJobId = iThreadParams.iCurrentJob.JobId();
-    params.iProfileId = iThreadParams.iCurrentJob.ProfileId();
-    params.iUimode = iThreadParams.iCurrentJob.iUimode;
-    iNotifierObserver->ConnectToNotifierL(params);
-    LOGSTRING2("iCallerStatus in iNotifierObserver->ConnectToNotifierL( params ); %d", iStatus.Int());
-    LOGSTRING("CNSmlThreadEngine::VerifyJobFromNotifierL() : End");
+TInt CNSmlThreadEngine::VerifyJobFromNotifierL()
+	{
+	_DBG_FILE("CNSmlThreadEngine::VerifyJobFromNotifierL() : Begin");
+	iNotifierObserver = new (ELeave) CNSmlNotifierObserver(iStatus, iThreadParams);
+	SetActive();
+	
+	TSyncMLAppLaunchNotifParams params;
+	params.iSessionType = ( iThreadParams.iCurrentJob.UsageType() == ESmlDataSync ) ? ESyncMLSyncSession : ESyncMLMgmtSession;
+	params.iJobId = iThreadParams.iCurrentJob.JobId();
+	params.iProfileId = iThreadParams.iCurrentJob.ProfileId();
+    params.iUimode = iThreadParams.iCurrentJob.iUimode;	
+	iNotifierObserver->ConnectToNotifierL( params );
+	_DBG_FILE("CNSmlThreadEngine::VerifyJobFromNotifierL() : End");
     return KErrNone;
 	}
 
@@ -784,20 +824,11 @@
 // Constructor
 // --------------------------------------------------------------------------
 //	
-CNSmlNotifierObserver::CNSmlNotifierObserver(TRequestStatus& aStatus,
-        CNSmlThreadParams& aParams) :
-    CActive(0), iCallerStatus(aStatus), iThreadParams(aParams)
-    {
-    LOGSTRING2("iCallerStatus in RunL %d", iCallerStatus.Int());
-    // If the current job is DM job then proceed to use Hb Notifiers
-    
-    if(aParams.iCurrentJob.UsageType() == ESmlDevMan)
-        {    
-        TRAP_IGNORE(iHbSyncmlNotifierEnabled = IsHbSyncmlNotifierEnabledL());
-        }
-    
-    CActiveScheduler::Add(this);
-    }
+CNSmlNotifierObserver::CNSmlNotifierObserver(TRequestStatus& aStatus, CNSmlThreadParams& aParams)
+: CActive(0), iCallerStatus(aStatus), iThreadParams(aParams)
+	{
+	CActiveScheduler::Add(this);
+	}
 
 // --------------------------------------------------------------------------
 // CNSmlNotifierObserver::~CNSmlNotifierObserver()
@@ -805,27 +836,17 @@
 // --------------------------------------------------------------------------
 //	
 CNSmlNotifierObserver::~CNSmlNotifierObserver()
-    {
-    LOGSTRING("~CNSmlNotifierObserver");
-    // StartNotifier called to avoid Notifier server panic, if 
-    // notifier does not exist anymore.
-    TBuf8<1> dummy;
-
-    if (!iHbSyncmlNotifierEnabled)
-        {
-//        iNotifier.StartNotifier(KNullUid, dummy, dummy); // KNullUid should do also..
-
-//        iNotifier.CancelNotifier(KUidNotifier);
-//        iNotifier.Close();
-        }
-    else
-        {
-        if(iDmDevdialog.Handle() )
-             iDmDevdialog.Close();
-        }
-
-    Cancel();
-    }
+	{
+	
+	// StartNotifier called to avoid Notifier server panic, if 
+	// notifier does not exist anymore.
+	TBuf8<1> dummy;	
+	iNotifier.StartNotifier(KNullUid, dummy, dummy); // KNullUid should do also..
+	
+	iNotifier.CancelNotifier( KUidNotifier );
+	iNotifier.Close();
+	Cancel();
+	}
 
 // --------------------------------------------------------------------------
 // CNSmlNotifierObserver::ConnectToNotifierL( const TSyncMLAppLaunchNotifParams& aParam )
@@ -834,74 +855,35 @@
 //		
 void CNSmlNotifierObserver::ConnectToNotifierL( const TSyncMLAppLaunchNotifParams& aParam )
 	{
-		_DBG_FILE( "CNSmlNotifierObserver::ConnectToNotifierL:Begin" );
-		iTimeOut = EFalse;
+	_DBG_FILE( "CNSmlNotifierObserver::ConnectToNotifierL:Begin" );
+	iTimeOut = EFalse;
+	
+	if ( !IsActive() )
+		{
+		SetActive();
+		}
+		
+	   
+    TSyncMLAppLaunchNotifParamsPckg data( aParam );
     
     if ( !KNSmlWaitNotifierForEver )
         {
         iNotifierTimeOut.LaunchNotifierTimer( this );
         }
-
-    if (!iHbSyncmlNotifierEnabled)
-    {
-    	LOGSTRING2( "CNSmlNotifierObserver::ConnectToNotifierL %d after connect, StartNotifierAndGetResponse and after setactive" , iStatus.Int());
-    }
-    else
-    {
-       iStatus = KRequestPending;
-       HbNotifierObserverL(aParam);
-    }
-    if ( !IsActive() )
-    {
-    	SetActive();
-    }      
-     _DBG_FILE("CNSmlNotifierObserver::ConnectToNotifierL:End");   
-	}
-
-// --------------------------------------------------------------------------
-// CNSmlNotifierObserver::IsHbNotifierEnabled()
-// Launch Hb Notifier Process
-// --------------------------------------------------------------------------
-//
-TBool CNSmlNotifierObserver::IsHbSyncmlNotifierEnabledL()
-    {
-    CRepository * rep =
-            CRepository::NewLC(KCRUidDeviceManagementInternalKeys);
-
-    TInt notifierenabled = KErrNone;
-
-    TInt err = rep->Get(KDevManEnableHbNotifier, notifierenabled);
-
-    CleanupStack::PopAndDestroy(rep);
-
-    if (err == KErrNone && notifierenabled)
+        
+    TInt err = iNotifier.Connect();
+    if ( err == KErrNone )
         {
-        return ETrue;
+        iNotifier.StartNotifierAndGetResponse( iStatus, KUidNotifier, data, iResBuf );                
         }
     else
         {
-        return EFalse;
+        // Stop job. Error connecting to notifier.
+        TRequestStatus* sStatus = &iStatus;
+		User::RequestComplete( sStatus, err );            
         }
-
-    }
-
-// --------------------------------------------------------------------------
-// CNSmlNotifierObserver::HbNotifierObserverL()
-// Launch Hb Notifier Process
-// --------------------------------------------------------------------------
-//
-void CNSmlNotifierObserver::HbNotifierObserverL(const TSyncMLAppLaunchNotifParams& aParam)
-    {
-
-    LOGSTRING2("iCallerStatus before HbNotifierObserverL creation %d", iCallerStatus.Int());
-   TInt err = iDmDevdialog.OpenL();
-   User::LeaveIfError(err);
-  iDmDevdialog.LaunchPkgZero(aParam.iProfileId,aParam.iJobId,aParam.iUimode,iResBuf,iStatus);
-     
-    LOGSTRING2("CNSmlNotifierObserver hb notifier %d after subscribe", iStatus.Int());
-
-    LOGSTRING2("iCallerStatus before HbNotifierObserverL creation %d", iCallerStatus.Int());
-    }
+     _DBG_FILE("CNSmlNotifierObserver::ConnectToNotifierL:End");   
+	}
 
 // --------------------------------------------------------------------------
 // CNSmlNotifierObserver::NotifierTimeOut()
@@ -909,23 +891,15 @@
 // --------------------------------------------------------------------------
 //
 void CNSmlNotifierObserver::NotifierTimeOut()
-    {
-    LOGSTRING("CNSmlNotifierObserver NotifierTimeOut ");
-    iTimeOut = ETrue;
-
-    // StartNotifier called to avoid Notifier server panic, if 
-    // notifier does not exist anymore.
-    if(!iHbSyncmlNotifierEnabled)
-        {
-        TBuf8<1> dummy;
-//        iNotifier.StartNotifier(KNullUid, dummy, dummy); // KNullUid should do also..
-//        iNotifier.CancelNotifier( KUidNotifier );
-        }
-    else
-        {
-        iProperty.Close();
-        }
-    }
+	{
+	iTimeOut = ETrue;
+	
+	// StartNotifier called to avoid Notifier server panic, if 
+	// notifier does not exist anymore.
+	TBuf8<1> dummy;
+	iNotifier.StartNotifier(KNullUid, dummy, dummy); // KNullUid should do also..
+	iNotifier.CancelNotifier( KUidNotifier );
+	}
 
 // --------------------------------------------------------------------------
 // CNSmlNotifierObserver::DoCancel()
@@ -942,12 +916,8 @@
 // --------------------------------------------------------------------------
 //	
 void CNSmlNotifierObserver::RunL()
-    {
-
-
-
-    LOGSTRING("CNSmlNotifierObserver RunL start");
-
+	{
+	    
     TInt ret = iStatus.Int();
     if ( ret == KErrCancel && iTimeOut )
     	{
@@ -957,7 +927,7 @@
     if ( ret == KErrNone )
     	{	   
         
-	  	TInt sid = iResBuf(); // read secure id from notifier.
+	  	TInt sid = iResBuf().iSecureId.iUid; // read secure id from notifier.
 	   	
 	    // Check the response and error code. If there is a fail, dump the job.        
 	    // Also compare sid to creator id saved for current job to secure that listener owns the job.