syncmlfw/syncmlnotifier/src/SyncMLAppLaunchNotifier.cpp
branchRCL_3
changeset 9 57a65a3a658c
parent 0 b497e44ab2fc
child 58 4af31167ea77
equal deleted inserted replaced
5:3f7d9dbe57c8 9:57a65a3a658c
    25 #include <StringLoader.h>    // Localisation stringloader
    25 #include <StringLoader.h>    // Localisation stringloader
    26 #include <SyncMLClientDS.h>
    26 #include <SyncMLClientDS.h>
    27 #include <SyncMLClientDM.h>
    27 #include <SyncMLClientDM.h>
    28 #include <SyncMLClient.h>
    28 #include <SyncMLClient.h>
    29 #include <rconnmon.h>
    29 #include <rconnmon.h>
       
    30 #include <ecom/ecom.h>
    30 #include <centralrepository.h>
    31 #include <centralrepository.h>
    31 #include <SyncMLNotifierDomainCRKeys.h>
    32 #include <SyncMLNotifierDomainCRKeys.h>
    32 #include <SyncMLNotifier.rsg>           // Own resources
    33 #include <SyncMLNotifier.rsg>           // Own resources
    33 #include "SyncMLAppLaunchNotifier.h"    // Class declaration
    34 #include "SyncMLAppLaunchNotifier.h"    // Class declaration
    34 #include "SyncMLTimedMessageQuery.h"
    35 #include "SyncMLTimedMessageQuery.h"
    46 // medium type uids
    47 // medium type uids
    47 //const TUid KUidNSmlMediumTypeInternet  = { 0x101F99F0 };
    48 //const TUid KUidNSmlMediumTypeInternet  = { 0x101F99F0 };
    48 const TUid KUidNSmlMediumTypeBluetooth = { 0x101F99F1 };
    49 const TUid KUidNSmlMediumTypeBluetooth = { 0x101F99F1 };
    49 const TUid KUidNSmlMediumTypeUSB       = { 0x101F99F2 };
    50 const TUid KUidNSmlMediumTypeUSB       = { 0x101F99F2 };
    50 const TUid KUidNSmlMediumTypeIrDA      = { 0x101F99F3 };
    51 const TUid KUidNSmlMediumTypeIrDA      = { 0x101F99F3 };
       
    52 const TUid KUidSmlSyncApp              = { 0x101F6DE5 };
    51 
    53 
    52 
    54 
    53 enum TASpBearerType
    55 enum TASpBearerType
    54     {
    56     {
    55     EAspBearerInternet = 0,
    57     EAspBearerInternet = 0,
    96 // Destructor
    98 // Destructor
    97 // -----------------------------------------------------------------------------
    99 // -----------------------------------------------------------------------------
    98 //
   100 //
    99 CSyncMLAppLaunchNotifier::~CSyncMLAppLaunchNotifier()
   101 CSyncMLAppLaunchNotifier::~CSyncMLAppLaunchNotifier()
   100     {
   102     {
       
   103 	delete iObserver;
   101     delete iDMSyncService;
   104     delete iDMSyncService;
   102     delete iDSSyncService;
   105     delete iDSSyncService;
   103     Cancel();   // Free own resources
   106     Cancel();   // Free own resources
   104     }
   107     }
   105 
   108 
   224         
   227         
   225         aParam.iProfileId = iProfileId;
   228         aParam.iProfileId = iProfileId;
   226         aParam.iJobId = iJobId;
   229         aParam.iJobId = iJobId;
   227         aServerName = syncProfile.DisplayName();
   230         aServerName = syncProfile.DisplayName();
   228         aUserInteraction = syncProfile.SanUserInteraction();
   231         aUserInteraction = syncProfile.SanUserInteraction();
   229         
       
   230         // Check if always ask is selected as accesspoint
       
   231         RSyncMLConnection connection;
       
   232         TRAPD( iapError, connection.OpenL( syncProfile, KUidNSmlMediumTypeInternet.iUid ) );
       
   233         CleanupClosePushL( connection );
       
   234 
       
   235         if ( !iapError )
       
   236             {
       
   237             const TDesC8& iap = connection.GetPropertyL( KNSmlIAPId );
       
   238             if ( iap.Compare( KNSmlAlwaysAsk() ) == 0 )
       
   239                 {
       
   240                 iAlwaysAsk = ETrue;
       
   241                 }            
       
   242             }
       
   243 
       
   244         connection.Close();
       
   245         CleanupStack::Pop( &connection );
       
   246         
       
   247         syncProfile.Close();
   232         syncProfile.Close();
   248         CleanupStack::Pop( &syncProfile );
   233         CleanupStack::Pop( &syncProfile );
   249         }
   234         }
   250     else
   235     else
   251         {
   236         {
   426 //
   411 //
   427 void CSyncMLAppLaunchNotifier::RunL()
   412 void CSyncMLAppLaunchNotifier::RunL()
   428     {
   413     {
   429     FLOG(_L("[SmlNotif]\t CSyncMLAppLaunchNotifier::RunL()"));
   414     FLOG(_L("[SmlNotif]\t CSyncMLAppLaunchNotifier::RunL()"));
   430 		stringholder =NULL;
   415 		stringholder =NULL;
   431 		centrep = NULL;
   416 		
   432     TRAPD( err, centrep = CRepository::NewL( KCRUidDeviceManagementInternalKeys) );    
       
   433     if(err)
       
   434     {
       
   435     	centrep = NULL;
       
   436     }
       
   437 
       
   438     TLanguage language = User::Language();  
   417     TLanguage language = User::Language();  
   439     // Load the parameters and set the query text according to the session type.
   418     // Load the parameters and set the query text according to the session type.
   440     switch( iSmlProtocol )
   419     switch( iSmlProtocol )
   441         {
   420         {
   442         case ESyncMLSyncSession:
   421         case ESyncMLSyncSession:
   445 
   424 
   446             TBuf<KSyncMLMaxProfileNameLength> serverName;
   425             TBuf<KSyncMLMaxProfileNameLength> serverName;
   447             RetrieveSyncParamsL( param, serverName, uiAction );
   426             RetrieveSyncParamsL( param, serverName, uiAction );
   448             stringholder = StringLoader::LoadL( R_SML_INIT_DS_SERVER_PROMPT,
   427             stringholder = StringLoader::LoadL( R_SML_INIT_DS_SERVER_PROMPT,
   449                                                 serverName );
   428                                                 serverName );
       
   429             if(!stringholder)
       
   430                 return;
   450             }
   431             }
   451 			break;
   432 			break;
   452         case ESyncMLMgmtSession:
   433         case ESyncMLMgmtSession:
   453             {
   434             {
   454             	TBool status = HandleDMSessionL();
   435             	TBool status = HandleDMSessionL();
   463             return;
   444             return;
   464             }
   445             }
   465         }
   446         }
   466 
   447 
   467     CleanupStack::PushL( stringholder );
   448     CleanupStack::PushL( stringholder );
       
   449     	
       
   450    	centrep = NULL;
       
   451     TRAPD( err, centrep = CRepository::NewL( KCRUidDeviceManagementInternalKeys) );    
       
   452     if(err)
       
   453     {
       
   454     	centrep = NULL;
       
   455     }
   468 
   456 
   469     TInt keypress( 0 );
   457     TInt keypress( 0 );
   470     TBool  silent = EFalse;
   458     TBool  silent = EFalse;
   471 		TInt SanSupport( KErrNone ),Timeout( KErrNone),CustomNotes(KErrNone);;
   459 		TInt SanSupport( KErrNone ),Timeout( KErrNone),CustomNotes(KErrNone);;
   472     if(centrep)
   460     if(centrep)
   709 //------------------------------------------------------------------------------
   697 //------------------------------------------------------------------------------
   710 	
   698 	
   711 void CSyncMLAppLaunchNotifier::HandleCompleteMessageL(TInt &keypress, TBool &silent, TInt &SanSupport, TInt &Timeout, TInt &CustomNotes)
   699 void CSyncMLAppLaunchNotifier::HandleCompleteMessageL(TInt &keypress, TBool &silent, TInt &SanSupport, TInt &Timeout, TInt &CustomNotes)
   712 {
   700 {
   713 	TLanguage language = User::Language();
   701 	TLanguage language = User::Language();
       
   702 	TInt err = KErrNone;
       
   703 	_LIT_SECURITY_POLICY_S0(KWritePolicy,KUidSmlSyncApp.iUid);
       
   704 	_LIT_SECURITY_POLICY_C1( KReadPolicy, ECapabilityReadDeviceData );
       
   705 	                  
   714 	if( keypress == EAknSoftkeyYes || keypress == EAknSoftkeyOk || silent ) // User has accepted the dialog
   706 	if( keypress == EAknSoftkeyYes || keypress == EAknSoftkeyOk || silent ) // User has accepted the dialog
   715   {
   707   {
   716 		TInt retval = 1; // Default for ESyncMLSyncSession or silent
   708 		TInt retval = 1; // Default for ESyncMLSyncSession or silent
   717     if ( iSmlProtocol == ESyncMLMgmtSession && !silent )
       
   718     {
       
   719     	CRepository* cRepository=NULL;
       
   720 			TRAPD ( error, cRepository = CRepository::NewL ( KCRUidNSmlNotifierDomainKeys ) );
       
   721 		 	if ( error == KErrNone )
       
   722 			{
       
   723 				CleanupStack::PushL( cRepository );
       
   724 				TInt dmChargingNote(1);
       
   725 				cRepository->Get ( KNSmlDMChargingNote, dmChargingNote );
       
   726 				if(dmChargingNote==1)
       
   727 				{
       
   728 			    	stringholder = StringLoader::LoadLC( R_FOTA_CONF_QUERY_CONNECTION_IS_NEEDED );
       
   729 			    	CSyncMLTimedQueryDialog* dlg = CSyncMLTimedQueryDialog::NewL( *stringholder, Timeout );			    
       
   730 			    	dlg->PrepareLC( R_SML_CONFIRMATION_QUERY );
       
   731         		dlg->ButtonGroupContainer().SetCommandSetL( R_AVKON_SOFTKEYS_YES_NO );
       
   732        			keypress = dlg->RunLD();
       
   733          		if( keypress == EAknSoftkeyYes ||	keypress == EAknSoftkeyOk ) 
       
   734          			retval = 1;
       
   735          		else retval = 0;   
       
   736 			    	dlg = NULL;
       
   737 			    	CleanupStack::PopAndDestroy( stringholder );
       
   738         }
       
   739         CleanupStack::PopAndDestroy( cRepository );//cRepository
       
   740       }
       
   741     }
       
   742 	if( iSmlProtocol == ESyncMLMgmtSession && SanSupport == EON && silent && iUimode == ESANUserInformative )
   709 	if( iSmlProtocol == ESyncMLMgmtSession && SanSupport == EON && silent && iUimode == ESANUserInformative )
   743 	{
   710 	{
   744 		// Turn lights on and deactivate apps -key
   711 		// Turn lights on and deactivate apps -key
   745   	TurnLightsOn(); 	  
   712   	TurnLightsOn(); 	  
   746    	if(CustomNotes && IsLanguageSupportedL()) 
   713    	if(CustomNotes && IsLanguageSupportedL()) 
   768 	  {
   735 	  {
   769 	  	case ESyncMLSyncSession:
   736 	  	case ESyncMLSyncSession:
   770 	    					param.iServiceId = KDataSyncServiceStart;
   737 	    					param.iServiceId = KDataSyncServiceStart;
   771 	             	break;
   738 	             	break;
   772 	    case ESyncMLMgmtSession:
   739 	    case ESyncMLMgmtSession:
       
   740                 
       
   741                   //Define a property for Native Disclaimer 
       
   742                   
       
   743 	              err = RProperty::Define(KDisclaimerProperty, KDisclaimerInteger, RProperty::EInt, KReadPolicy, KWritePolicy);
       
   744 	              if (err != KErrAlreadyExists)
       
   745 	                  {
       
   746                       User::LeaveIfError(err);
       
   747 	                  }
   773 	              param.iServiceId = KDevManServiceStart;
   748 	              param.iServiceId = KDevManServiceStart;
   774 								if( SanSupport == EON )
   749 								if( SanSupport == EON )
   775 								{													
   750 								{													
   776 	              	param.iSilent = iUimode;	                    	                               
   751 	              	param.iSilent = iUimode;	                    	                               
   777 								}
   752 								}
   778 			          pckg.iSecureId = SyncServiceL( param.iServiceId )->StartSyncL( param );
   753 				iObserver = new (ELeave) CDMDisclaimerObserver();
       
   754 				pckg.iSecureId = SyncServiceL( param.iServiceId )->StartSyncL( param );
       
   755 				FLOG(_L("[SmlNotif]\t WaitonDisclaimerL called"));
       
   756 				iObserver->WaitOnDisclaimerL(this);
   779 	              break;
   757 	              break;
   780 	    default:
   758 	    default:
   781 	              // This branch should never be reached, since the option
   759 	              // This branch should never be reached, since the option
   782 	              // is handled in the previous switch statement.
   760 	              // is handled in the previous switch statement.
   783 	              User::Panic( KSmlNPanicCategory, KErrCorrupt );
   761 	              User::Panic( KSmlNPanicCategory, KErrCorrupt );
   784 	              break;
   762 	              break;
   785 	  }	
   763 	  }	
   786 	                
   764 	 iMessage.WriteL( iReplySlot, TPckgBuf<TSyncMLAppLaunchNotifRetVal>(pckg) );
   787 	  iMessage.WriteL( iReplySlot, TPckgBuf<TSyncMLAppLaunchNotifRetVal>(pckg) );
   765 	 if(iSmlProtocol == ESyncMLSyncSession)
   788 	  iMessage.Complete( KErrNone );
   766 	     {
       
   767          iMessage.Complete(KErrNone);
       
   768 
       
   769 	     }
   789 	 }
   770 	 }
   790 	 else
   771 	 else
   791 	 {
   772 	 {
   792 	  	// Complete the message with result code indicating that
   773 	  	// Complete the message with result code indicating that
   793 		  // the user cancelled the query.
   774 		  // the user cancelled the query.
   816  		   language == ELangTaiwanChinese ||language == ELangHongKongChinese || language == ELangPrcChinese)
   797  		   language == ELangTaiwanChinese ||language == ELangHongKongChinese || language == ELangPrcChinese)
   817  		   retVal = ETrue;
   798  		   retVal = ETrue;
   818  	FLOG(_L("[SmlNotif]\t CSyncMLAppLaunchNotifier::IsLanguageSupportedL ends"));
   799  	FLOG(_L("[SmlNotif]\t CSyncMLAppLaunchNotifier::IsLanguageSupportedL ends"));
   819  	return retVal;
   800  	return retVal;
   820 }
   801 }
       
   802 // -----------------------------------------------------------------------------
       
   803 // CSyncMLAppLaunchNotifier::CompleteMessageL
       
   804 // Completes the message according to whether Privacy Policy disclaimer is accepted
       
   805 // -----------------------------------------------------------------------------
       
   806 //
       
   807 void CSyncMLAppLaunchNotifier::CompleteMessageL(TInt aDisclaimerAccepted)
       
   808     {
       
   809     FLOG(_L("[SmlNotif]\t CSyncMLAppLaunchNotifier::CompleteMessageL begins"));
       
   810     if(aDisclaimerAccepted == 1)
       
   811         {
       
   812         iMessage.Complete(KErrNone);
       
   813         }
       
   814     else
       
   815         {
       
   816         iMessage.Complete(KErrCancel);
       
   817         }
       
   818     FLOG(_L("[SmlNotif]\t CSyncMLAppLaunchNotifier::CompleteMessageL Ends"));
       
   819     }
       
   820 
       
   821 //---------------------------------------------------------------------------------
       
   822 // CDMDisclaimerObserver::CDMDisclaimerObserver
       
   823 // Constructor
       
   824 //---------------------------------------------------------------------------------
       
   825 CDMDisclaimerObserver::CDMDisclaimerObserver()
       
   826 : CActive(0)
       
   827     {
       
   828     CActiveScheduler::Add(this);
       
   829     }
       
   830 
       
   831 //---------------------------------------------------------------------------------
       
   832 // CDMDisclaimerObserver::~CDMDisclaimerObserver
       
   833 // Destructor
       
   834 //---------------------------------------------------------------------------------
       
   835 CDMDisclaimerObserver::~CDMDisclaimerObserver()
       
   836     {
       
   837     Cancel();
       
   838     iDisclaimerProperty.Close();
       
   839     }
       
   840 
       
   841 //---------------------------------------------------------------------------------
       
   842 // CDMDisclaimerObserver::WaitOnDisclaimerL
       
   843 // Subscribes to Property set when Privacy policy disclaimer is accepted
       
   844 //---------------------------------------------------------------------------------
       
   845 void CDMDisclaimerObserver::WaitOnDisclaimerL( CSyncMLAppLaunchNotifier* aPtr)
       
   846     {    
       
   847     FLOG(_L("[SmlNotif]\t CDMDisclaimerObserver::WaitOnDisclaimerL begins"));
       
   848     iNot = aPtr;
       
   849     // subscribe;
       
   850 	if(!IsActive())
       
   851 		{
       
   852 		TInt err= iDisclaimerProperty.Attach(KDisclaimerProperty, KDisclaimerInteger, EOwnerThread);		
       
   853         //User::LeaveIfError(err);
       
   854 		iStatus=KRequestPending;
       
   855 		iDisclaimerProperty.Subscribe(iStatus);
       
   856         SetActive();
       
   857 		}            
       
   858 	FLOG(_L("[SmlNotif]\t CDMDisclaimerObserver::WaitOnDisclaimerL ends"));
       
   859     }
       
   860 
       
   861 // --------------------------------------------------------------------------
       
   862 // CDMDisclaimerObserver::DoCancel()
       
   863 // From base class
       
   864 // --------------------------------------------------------------------------
       
   865 //
       
   866 void CDMDisclaimerObserver::DoCancel()
       
   867     {
       
   868 	 if( iStatus == KRequestPending )
       
   869     	{	    	
       
   870     	TRequestStatus* status = &iStatus;
       
   871     	User::RequestComplete( status, KErrCancel );
       
   872     	}
       
   873     }    
       
   874 // --------------------------------------------------------------------------
       
   875 // CDMDisclaimerObserver::RunL()
       
   876 // Calls CompleteMessageL 
       
   877 // --------------------------------------------------------------------------
       
   878 //
       
   879 void CDMDisclaimerObserver::RunL()
       
   880     {
       
   881     FLOG(_L("[SmlNotif]\t CDMDisclaimerObserver::RunL begins"));
       
   882     iDisclaimerProperty.Get(iPropertyVal);
       
   883      
       
   884     iNot->CompleteMessageL(iPropertyVal);
       
   885         
       
   886     FLOG(_L("[SmlNotif]\t CDMDisclaimerObserver::RunL End"));
       
   887     }
       
   888 
       
   889 // --------------------------------------------------------------------------
       
   890 // CDMDisclaimerObserver::RunError()
       
   891 // --------------------------------------------------------------------------
       
   892 //
       
   893 TInt CDMDisclaimerObserver::RunError(TInt aError)
       
   894     {
       
   895     FTRACE( FPrint( _L("[SmlNotif]\t CDMDisclaimerObserver::RunError() Error = %d"), aError ) );
       
   896     return aError;
       
   897     }
       
   898     
   821 //  End of File  
   899 //  End of File