webengine/wrtharvester/src/wrtharvester.cpp
branchRCL_3
changeset 48 79859ed3eea9
parent 47 e1bea15f9a39
child 49 919f36ff910f
equal deleted inserted replaced
47:e1bea15f9a39 48:79859ed3eea9
    21 #include "wrtharvesterregistryaccess.h"
    21 #include "wrtharvesterregistryaccess.h"
    22 #include "wrtharvesterpsnotifier.h"
    22 #include "wrtharvesterpsnotifier.h"
    23 #include "wrtharvesterpublisherobserver.h"
    23 #include "wrtharvesterpublisherobserver.h"
    24 
    24 
    25 #include "wrtharvesterconst.h"
    25 #include "wrtharvesterconst.h"
    26 #include <widgetregistryconstants.h>
    26 #include <WidgetRegistryConstants.h>
    27 #include <wrtharvester.rsg>
    27 #include <wrtharvester.rsg>
    28 #include <startupdomainpskeys.h>
    28 
    29 #include <ecom/implementationproxy.h>
    29 #include <implementationproxy.h>
    30 
    30 
    31 #include <LiwServiceHandler.h>
    31 #include <liwservicehandler.h>
    32 #include <LiwVariant.h>
    32 #include <liwvariant.h>
    33 #include <LiwGenericParam.h>
    33 #include <liwgenericparam.h>
    34 #include <e32property.h>    //Publish & Subscribe
    34 #include <e32property.h>    //Publish & Subscribe
    35 #include <AknTaskList.h>
    35 #include <AknTaskList.h>
    36 #include <apaid.h>
    36 #include <apaid.h>
    37 #include <apacmdln.h>
    37 #include <apacmdln.h>
    38 #include <s32mem.h>
    38 #include <s32mem.h>
    39 #include <APGTASK.H>
    39 #include <apgtask.h>
    40 #include <coemain.h>
    40 #include <coemain.h>
    41 #include <bautils.h>
    41 #include <bautils.h>
    42 #include <f32file.h>
    42 #include <f32file.h>
    43 #include <e32std.h>
    43 #include <e32std.h>
    44 #include <AknNotify.h>
    44 #include <AknNotify.h>
    45 #include <aknglobalconfirmationquery.h>
    45 #include <AknGlobalConfirmationQuery.h>
    46 #include <StringLoader.h>
    46 #include <StringLoader.h>
    47 #include <data_caging_path_literals.hrh>
    47 #include <data_caging_path_literals.hrh>
    48 #include <oommonitorsession.h>
       
    49 
       
    50 #ifndef BRDO_OOM_MONITOR2_COMPONENT_FF 
       
    51 #include <systemwarninglevels.hrh>
       
    52 #endif
       
    53 #include "browser_platform_variant.hrh"
       
    54 
    48 
    55 // CONSTANTS
    49 // CONSTANTS
    56 _LIT( KResourceFileName, "\\resource\\wrtharvester.rsc" );
    50 _LIT( KResourceFileName, "\\resource\\wrtharvester.rsc" );
    57 _LIT( KResourceDir, "Z:wrtharvester.rsc" );
    51 _LIT( KResourceDir, "Z:wrtharvester.rsc" );
    58 _LIT( KUid, "uid");
       
    59 _LIT( K0x, "0x");
       
    60 _LIT( KOpenPar, "(");
       
    61 _LIT( KClosePar, ")");
       
    62 _LIT8( KWidgetIcon, "widget_icon");
       
    63 #define KUidWidgetOOMPlugin 0x10282855
       
    64 const TInt KMemoryToLaunchWidgetUi = 17*1024*1024;
       
    65 
       
    66 
       
    67 
       
    68 /** 
       
    69 * Launch or bring foreground the asked widget.
       
    70 *
       
    71 * Launch widget.
       
    72 * @param aUid UID of the widget.
       
    73 * @param aOperation Operation to perform.
       
    74 */
       
    75 static void LaunchWidgetL( const TUid& aUid, TUint32 aOperation );
       
    76 
       
    77 /** 
       
    78 * In case the widget cannot be launched because of OOM
       
    79 * Notify harvester and Clear event Queue
       
    80 * @return void
       
    81 */
       
    82 static void NotifyCommandAndCleanUp();
       
    83 
       
    84 /** 
       
    85 * Launch new widget.
       
    86 *
       
    87 * Launch new widget.
       
    88 * @param aUid UID of the widget.
       
    89 * @param aOperation Operation to perform.
       
    90 */
       
    91 static void LaunchWidgetUIL( 
       
    92     const TUid& aUid, 
       
    93     const TDesC8& aMessage, 
       
    94     TUint32 aOperation );
       
    95 
    52 
    96 /**
    53 /**
    97 * Utility class to show the prompt for platform security access.
    54 * Utility class to show the prompt for platform security access.
    98 *
    55 *
    99 * The class exists only to provide platform security access prompt
    56 * The class exists only to provide platform security access prompt
   172     
   129     
   173 // ----------------------------------------------------------------------------
   130 // ----------------------------------------------------------------------------
   174 // Returns the app full name
   131 // Returns the app full name
   175 // ----------------------------------------------------------------------------
   132 // ----------------------------------------------------------------------------
   176 //
   133 //
   177 /*
       
   178 static HBufC* GetAppNameLC( RApaLsSession& aSession, const TUid& aUid )
   134 static HBufC* GetAppNameLC( RApaLsSession& aSession, const TUid& aUid )
   179     {
   135     {
   180     TApaAppInfo info;
   136     TApaAppInfo info;
   181     User::LeaveIfError( aSession.GetAppInfo( info, aUid ) );
   137     User::LeaveIfError( aSession.GetAppInfo( info, aUid ) );
   182     
   138     
   183     return info.iFullName.AllocLC();
   139     return info.iFullName.AllocLC();
   184     }
   140     }
   185 */
   141     
   186     
   142     
       
   143 // ----------------------------------------------------------------------------
       
   144 // Sends the command to Widget launcher
       
   145 // ----------------------------------------------------------------------------
       
   146 //
       
   147 static void HandleWidgetCommandL( 
       
   148     RApaLsSession& aSession, 
       
   149     const TDesC& aWidget,
       
   150     const TUid& aUid,
       
   151     TUint32 aOperation )
       
   152     {
       
   153     const TInt size( 2* aWidget.Length() + 3*sizeof( TUint32 ) );
       
   154     
       
   155     // Message format is <filenameLength><unicode_filename><someintegervalue>
       
   156     CApaCommandLine* cmd( CApaCommandLine::NewLC() );
       
   157     HBufC8* opaque( HBufC8::NewLC( size ) );
       
   158     
       
   159     RDesWriteStream stream;
       
   160     TPtr8 des( opaque->Des() );
       
   161     
       
   162     stream.Open( des );
       
   163     CleanupClosePushL( stream );
       
   164     
       
   165     // Generate the command.
       
   166     stream.WriteUint32L( aUid.iUid );
       
   167     stream.WriteUint32L( aWidget.Length() );
       
   168     stream.WriteL( reinterpret_cast< const TUint8* >( aWidget.Ptr() ),
       
   169                    aWidget.Size() );
       
   170     
       
   171     stream.WriteInt32L( aOperation );
       
   172     
       
   173     CleanupStack::PopAndDestroy( &stream );
       
   174     
       
   175     // Generate command.
       
   176     cmd->SetCommandL( EApaCommandBackgroundAndWithoutViews );
       
   177     cmd->SetOpaqueDataL( *opaque );    
       
   178 
       
   179     CleanupStack::PopAndDestroy( opaque );
       
   180     
       
   181     cmd->SetExecutableNameL( KLauncherApp );
       
   182     
       
   183     User::LeaveIfError( aSession.StartApp( *cmd ) );
       
   184     CleanupStack::PopAndDestroy( cmd );
       
   185     }
       
   186 
   187 // Map the interface UIDs to implementation factory functions
   187 // Map the interface UIDs to implementation factory functions
   188 const TImplementationProxy ImplementationTable[] = 
   188 const TImplementationProxy ImplementationTable[] = 
   189     {
   189     {
   190     IMPLEMENTATION_PROXY_ENTRY( 0xA12345FE, CWrtHarvester::NewL )
   190     IMPLEMENTATION_PROXY_ENTRY( 0xA12345FE, CWrtHarvester::NewL )
   191     };
   191     };
   218 // ----------------------------------------------------------------------------
   218 // ----------------------------------------------------------------------------
   219 //
   219 //
   220 void CWrtHarvester::ConstructL()
   220 void CWrtHarvester::ConstructL()
   221     {
   221     {
   222     User::LeaveIfError( iApaSession.Connect() );
   222     User::LeaveIfError( iApaSession.Connect() );
   223     	
       
   224     iSystemShutdown = EFalse;
       
   225     iWidgetUIListener = CWrtHarvesterPSNotifier::NewL( this, EWidgetUIState );
   223     iWidgetUIListener = CWrtHarvesterPSNotifier::NewL( this, EWidgetUIState );
   226     iWidgetRegListener = CWrtHarvesterPSNotifier::NewL( this, EWidgetRegAltered );
   224     iWidgetRegListener = CWrtHarvesterPSNotifier::NewL( this, EWidgetRegAltered );
   227     iWidgetSystemShutdownListener = CWrtHarvesterPSNotifier::NewL( this, EWidgetSystemShutdown );
       
   228     iMsModeListener = CWrtHarvesterPSNotifier::NewL( this, EWidgetMassStorageMode );
       
   229     
   225     
   230     User::LeaveIfError( iFs.Connect() );
   226     User::LeaveIfError( iFs.Connect() );
   231     
   227     iWidgetUsbListener = CWrtUsbHandler::NewL( this, iFs );
       
   228     
       
   229     iWidgetUsbListener->Start();
   232     SetMSMode(0);
   230     SetMSMode(0);
   233     
   231     
   234     iCanAccessRegistry = ETrue;    
       
   235 	iReinstallingWidget = EFalse;
       
   236 	
       
   237 	    
       
   238     TFileName resourceFileName;  
   232     TFileName resourceFileName;  
   239     TParse parse;    
   233     TParse parse;    
   240     Dll::FileName (resourceFileName);           
   234     Dll::FileName (resourceFileName);           
   241     parse.Set(KResourceFileName, &resourceFileName, NULL); 
   235     parse.Set(KResourceFileName, &resourceFileName, NULL); 
   242     resourceFileName = parse.FullName(); 
   236     resourceFileName = parse.FullName(); 
   278         CCoeEnv::Static()->DeleteResourceFile( iResourceFileOffset );
   272         CCoeEnv::Static()->DeleteResourceFile( iResourceFileOffset );
   279         }
   273         }
   280     iObservers.ResetAll();
   274     iObservers.ResetAll();
   281     iWidgetInfo.ResetAll();
   275     iWidgetInfo.ResetAll();
   282     iWidgetStateArray.ResetAll();
   276     iWidgetStateArray.ResetAll();
   283     
       
   284     delete iWidgetUIListener;
   277     delete iWidgetUIListener;
   285     delete iWidgetRegListener;    
   278     delete iWidgetRegListener;
   286     delete iMsModeListener;    
   279     delete iWidgetMMCListener;
   287     delete iWidgetSystemShutdownListener;
   280     delete iWidgetUsbListener;
   288     
       
   289     if(iAsyncCallBack)
       
   290         {
       
   291         iAsyncCallBack->Cancel();       
       
   292         }
       
   293     delete iAsyncCallBack;
       
   294     iAsyncCallBack = NULL;
       
   295     iUid.Close();
       
   296     iWidgetOperations.Close();
   281     iWidgetOperations.Close();
   297     iHSWidgets.ResetAndDestroy();
   282     iHSWidgets.ResetAndDestroy();
   298     iApaSession.Close();
   283     iApaSession.Close();
   299     }
   284     }
   300     
   285     
   313 //  
   298 //  
   314 void CWrtHarvester::HandlePublisherNotificationL( const TDesC& aContentId, const TDesC8& aTrigger )
   299 void CWrtHarvester::HandlePublisherNotificationL( const TDesC& aContentId, const TDesC8& aTrigger )
   315     {
   300     {
   316     
   301     
   317     //Do not send the Operations to the Widgets when in Mass storage mode.. . .  
   302     //Do not send the Operations to the Widgets when in Mass storage mode.. . .  
       
   303     if( IsInMSMode() == 1 )
       
   304         {
       
   305          if(aTrigger == KDeActive)
       
   306          RemovePublisherAndObserverL(aContentId);
       
   307          return;              
       
   308         }
       
   309    
   318     TUid uid( WidgetUid( aContentId ) );
   310     TUid uid( WidgetUid( aContentId ) );
   319     
       
   320     
       
   321     if(iSystemShutdown && aTrigger == KDeActive )
       
   322     	{
       
   323     	return ;
       
   324     	}
       
   325     if( IsInMSMode() == 1 )
       
   326       {
       
   327       if( aTrigger == KDeActive && !iSystemShutdown )
       
   328           {
       
   329           RemovePublisherAndObserverL(aContentId);
       
   330           RWidgetRegistryClientSession session;
       
   331           CleanupClosePushL( session );
       
   332           User::LeaveIfError( session.Connect() );
       
   333           session.SetBlanketPermissionL( uid, EBlanketUnknown );
       
   334           CleanupStack::PopAndDestroy( &session );
       
   335           }
       
   336       return; 
       
   337       }
       
   338       
       
   339 	if(!iCanAccessRegistry)
       
   340 		return;             
       
   341 		
       
   342     TWidgetOperations operation( Uninitialized );
   311     TWidgetOperations operation( Uninitialized );
   343     if( aTrigger == KActive )
   312     if( aTrigger == KActive )
   344         {
   313         {
   345         HBufC* temp = aContentId.Alloc();
   314         HBufC* temp = aContentId.Alloc();
   346         iHSWidgets.Append( temp );
   315         iHSWidgets.Append( temp );
   370             {
   339             {
   371             iHSWidgets.Remove(i);
   340             iHSWidgets.Remove(i);
   372             break;
   341             break;
   373             }
   342             }
   374           }
   343           }
   375         delete temp;
   344         delete temp;        
   376         
   345         }
   377         // Removing . Miniview, shall remove full view as well. For blanket permissions
       
   378         // will be revoked for miniview
       
   379          
       
   380       	if(!iSystemShutdown)
       
   381       	    {        
       
   382             RWidgetRegistryClientSession session;
       
   383             CleanupClosePushL( session );
       
   384             User::LeaveIfError( session.Connect() );
       
   385             session.SetBlanketPermissionL( uid, EBlanketUnknown );
       
   386             CleanupStack::PopAndDestroy( &session );
       
   387             }
       
   388       }
       
   389     else if( aTrigger == KSuspend )
   346     else if( aTrigger == KSuspend )
   390         {
   347         {
   391         operation = WidgetSuspend;
   348         operation = WidgetSuspend;
   392         }
   349         }
   393     else if( aTrigger == KResume )
   350     else if( aTrigger == KResume )
   426 // 
   383 // 
   427 // ----------------------------------------------------------------------------
   384 // ----------------------------------------------------------------------------
   428 //
   385 //
   429 void CWrtHarvester::UpdatePublishersL() 
   386 void CWrtHarvester::UpdatePublishersL() 
   430     {
   387     {
   431     if(iReinstallingWidget)
       
   432         {        
       
   433         iReinstallingWidget = EFalse;
       
   434         return;
       
   435         }
       
   436     iRegistryAccess.WidgetInfosL( iWidgetInfo );
   388     iRegistryAccess.WidgetInfosL( iWidgetInfo );
   437     RemoveObsoletePublishersL();
   389     RemoveObsoletePublishersL();
   438     
   390     
   439     for( TInt i = iWidgetInfo.Count() - 1; i >= 0; --i )
   391     for( TInt i = iWidgetInfo.Count() - 1; i >= 0; --i )
   440         {
   392         {
   527             variant.Reset();
   479             variant.Reset();
   528              
   480              
   529             if( publisherMap && publisherMap->FindL( KContentId , variant ))
   481             if( publisherMap && publisherMap->FindL( KContentId , variant ))
   530                 {
   482                 {
   531                  HBufC* bundleId = variant.AsDes().AllocLC();
   483                  HBufC* bundleId = variant.AsDes().AllocLC();
   532                  variant.Reset();
   484                  publishers.AppendL( bundleId );
   533                  TBool isNokiaWidget = EFalse;
   485                  CleanupStack::Pop( bundleId );
   534                  if ( publisherMap->FindL( KDataMap, variant) )
       
   535                      {
       
   536                      CLiwDefaultMap* dataMap = CLiwDefaultMap::NewLC();
       
   537                      variant.Get( *dataMap );
       
   538                      variant.Reset();
       
   539                      if ( dataMap->FindL( KWidgetInfo, variant ) )
       
   540                          {
       
   541                          CLiwDefaultMap* widgetInfoMap = CLiwDefaultMap::NewLC();
       
   542                          variant.Get( *widgetInfoMap );
       
   543                          if ( widgetInfoMap->FindL( KWidgetType, variant ) )
       
   544                              {
       
   545                              if ( KS60Widget == variant.AsTInt32())
       
   546                                  {
       
   547                                  isNokiaWidget = ETrue;
       
   548                                  }
       
   549                              }
       
   550                          CleanupStack::PopAndDestroy( widgetInfoMap );
       
   551                          }
       
   552                      CleanupStack::PopAndDestroy( dataMap );
       
   553                      }
       
   554                  
       
   555                  if (isNokiaWidget )
       
   556                      {
       
   557                      publishers.AppendL( bundleId );
       
   558                      CleanupStack::Pop( bundleId );
       
   559                      }
       
   560                  else
       
   561                      {
       
   562                      CleanupStack::PopAndDestroy( bundleId );
       
   563                      }
       
   564                  }
   486                  }
   565              CleanupStack::PopAndDestroy( publisherMap );     
   487              CleanupStack::PopAndDestroy( publisherMap );     
   566              }
   488              }
   567             
   489             
   568         variant.Reset();
   490         variant.Reset();
   579     TBool networkAccess = CheckNetworkAccessL( wrtInfo.iUid );
   501     TBool networkAccess = CheckNetworkAccessL( wrtInfo.iUid );
   580     
   502     
   581     __UHEAP_MARK;
   503     __UHEAP_MARK;
   582     TInt id( KErrNotFound );
   504     TInt id( KErrNotFound );
   583     if( iCPSInterface )
   505     if( iCPSInterface )
   584         {
   506         {   
   585         TBuf<10> uid(wrtInfo.iUid.Name());  // [12345678]
       
   586         uid.Delete(0,1);                    // 12345678]
       
   587         uid.Delete( uid.Length()-1, 1);     // 12345678
       
   588         TBuf<50> wrtuid;
       
   589         wrtuid.Append(KUid);                // uid
       
   590         wrtuid.Append(KOpenPar);            // uid(
       
   591         wrtuid.Append(K0x);                 // uid(0x
       
   592         wrtuid.Append(uid );			  // uid(0x12345678
       
   593         wrtuid.Append(KClosePar);           // uid(0x12345678)
       
   594    
       
   595         CLiwGenericParamList* inparam( CLiwGenericParamList::NewLC() );
   507         CLiwGenericParamList* inparam( CLiwGenericParamList::NewLC() );
   596         CLiwGenericParamList* outparam( CLiwGenericParamList::NewLC() );
   508         CLiwGenericParamList* outparam( CLiwGenericParamList::NewLC() );
   597 
   509 
   598         TLiwGenericParam type( KType, TLiwVariant( KPubData ));
   510         TLiwGenericParam type( KType, TLiwVariant( KPubData ));
   599         inparam->AppendL( type );
   511         inparam->AppendL( type );
   603 
   515 
   604         // Create the data map for publisher registry
   516         // Create the data map for publisher registry
   605         cpdatamap->InsertL( KPublisherId, TLiwVariant( KWRTPublisher ));
   517         cpdatamap->InsertL( KPublisherId, TLiwVariant( KWRTPublisher ));
   606         cpdatamap->InsertL( KContentType, TLiwVariant( KTemplatedWidget ));
   518         cpdatamap->InsertL( KContentType, TLiwVariant( KTemplatedWidget ));
   607         cpdatamap->InsertL( KContentId, TLiwVariant( wrtInfo.iBundleId ));
   519         cpdatamap->InsertL( KContentId, TLiwVariant( wrtInfo.iBundleId ));
   608         
       
   609         // Widget info map
   520         // Widget info map
   610     	  CLiwDefaultMap* widgetInfo = CLiwDefaultMap::NewLC();
   521     	CLiwDefaultMap* widgetInfo = CLiwDefaultMap::NewLC();
   611 		    widgetInfo->InsertL( KTemplateType, TLiwVariant( KTemplateName ));
   522 		widgetInfo->InsertL( KTemplateType, TLiwVariant( KTemplateName ));
   612 		    widgetInfo->InsertL( KWidgetName, TLiwVariant( wrtInfo.iDisplayName ));
   523 		widgetInfo->InsertL( KWidgetName, TLiwVariant( wrtInfo.iDisplayName ));
   613 		    widgetInfo->InsertL( KWidgetIcon, TLiwVariant( wrtuid));  // uid(0x12345678) This is the expected format 
   524 		datamap->InsertL( KWidgetInfo , TLiwVariant( widgetInfo ));
   614             widgetInfo->InsertL( KWidgetType, TLiwVariant( TInt32 (wrtInfo.iType ) ));
   525 		CleanupStack::PopAndDestroy( widgetInfo );
   615 
   526         
   616 		    datamap->InsertL( KWidgetInfo , TLiwVariant( widgetInfo ));
   527 		// Take dynamic menu items into use
   617 		    CleanupStack::PopAndDestroy( widgetInfo );
   528 		if (networkAccess)
   618         
   529 		    {
   619 		    // Take dynamic menu items into use
   530 		    CLiwDefaultMap* mapMenu = CLiwDefaultMap::NewLC();
   620 		    if (networkAccess)
   531 		    mapMenu->InsertL( KItemOnlineOffline, TLiwVariant( KMyActionName ));
   621 		        {
   532 		    datamap->InsertL( KMenuItems, TLiwVariant( mapMenu ));
   622 		        CLiwDefaultMap* mapMenu = CLiwDefaultMap::NewLC();
   533 		    CleanupStack::PopAndDestroy(mapMenu);
   623 		        mapMenu->InsertL( KItemOnlineOffline, TLiwVariant( KMyActionName ));
   534 		    }
   624 		        datamap->InsertL( KMenuItems, TLiwVariant( mapMenu ));
       
   625 		        CleanupStack::PopAndDestroy(mapMenu);
       
   626 		        }
       
   627 
   535 
   628         cpdatamap->InsertL( KDataMap, TLiwVariant(datamap) );
   536         cpdatamap->InsertL( KDataMap, TLiwVariant(datamap) );
   629         
   537         
   630         // Create the action map for publisher registry
   538         // Create the action map for publisher registry
   631         actionmap = CLiwDefaultMap::NewLC();
   539         actionmap = CLiwDefaultMap::NewLC();
   770 // ----------------------------------------------------------------------------
   678 // ----------------------------------------------------------------------------
   771 //
   679 //
   772 void CWrtHarvester::QueueOperationL( TWidgetOperations aOperation, TUid aUid )
   680 void CWrtHarvester::QueueOperationL( TWidgetOperations aOperation, TUid aUid )
   773     {
   681     {
   774     //Hack to find out if WidgetUi exist as Queue keeps filling up
   682     //Hack to find out if WidgetUi exist as Queue keeps filling up
   775     SWidgetOperation op = { aOperation, aUid };
   683     if((iHSCount*3 <= iWidgetOperations.Count() && !CheckTaskExistsL()) || (aOperation == WidgetSelect))
   776     
   684         {
   777     TInt value = KErrNone;
       
   778     TInt error = iWidgetUIListener->GetValue(value);
       
   779     
       
   780     if((iHSCount*3 <= iWidgetOperations.Count() && !CheckTaskExistsL() ) || (aOperation == WidgetSelect && !CheckTaskExistsL() && value ) )
       
   781         {        
       
   782         ClearAllOperations();
   685         ClearAllOperations();
   783         iWidgetUIListener->SetValue(1);
   686         iWidgetUIListener->SetValue(1);
   784         } 
   687         }        
   785     
   688     SWidgetOperation op = { aOperation, aUid };
   786     TBool queued (EFalse);
   689     iWidgetOperations.Append( op );
   787     for(TInt i =0; i < iWidgetOperations.Count() && (aOperation == WidgetResume || aOperation == WidgetSuspend ) ; i++)
       
   788         {
       
   789         SWidgetOperation opInQueue = iWidgetOperations[i];
       
   790         //we get resume but we already have suspend in Queue
       
   791         //make Resume as Suspend    
       
   792         if(op.iOperation == WidgetResume && opInQueue.iUid == op.iUid && opInQueue.iOperation == WidgetSuspend )
       
   793             {            
       
   794             iWidgetOperations[i].iOperation = WidgetResume;
       
   795             queued = ETrue;
       
   796             break;
       
   797             }            
       
   798         //we get suspend but we already have resume in Queue
       
   799         //make Suspend as Resume    
       
   800         if(op.iOperation == WidgetSuspend  && opInQueue.iUid == op.iUid && opInQueue.iOperation == WidgetResume )
       
   801             {            
       
   802             iWidgetOperations[i].iOperation = WidgetSuspend;
       
   803             queued = ETrue;
       
   804             break;
       
   805             }    
       
   806         }
       
   807             
       
   808     if(!queued)
       
   809         iWidgetOperations.Append( op );
       
   810             
       
   811     TryLaunchNextOperationL();
   690     TryLaunchNextOperationL();
   812     }
   691     }
   813 
   692 
   814 // ----------------------------------------------------------------------------
   693 // ----------------------------------------------------------------------------
   815 // 
   694 // 
   835 //
   714 //
   836 void CWrtHarvester::TryLaunchNextOperationL()
   715 void CWrtHarvester::TryLaunchNextOperationL()
   837     {
   716     {
   838     TInt value = KErrNone;
   717     TInt value = KErrNone;
   839     TInt error = iWidgetUIListener->GetValue(value);
   718     TInt error = iWidgetUIListener->GetValue(value);
   840     if( error == KErrNone && value == 1 && iWidgetOperations.Count() != 0 && iCanAccessRegistry )
   719     if( error == KErrNone && value == 1 && iWidgetOperations.Count() != 0 )
   841         {
   720         {
   842         // Set value to 0 so that next widget is not launched before Widget App sets value to 1.
   721         // Set value to 0 so that next widget is not launched before Widget App sets value to 1.
   843         iWidgetUIListener->SetValue( 0 );
   722         iWidgetUIListener->SetValue( 0 );
   844         //Always launch the first in operation
   723         //Always launch the first in operation
   845         LaunchWidgetOperationL( iWidgetOperations[0] );
   724         LaunchWidgetOperationL( iWidgetOperations[0] );
   846         
   725         iWidgetOperations.Remove( 0 );
   847         if(iWidgetOperations[0].iOperation == WidgetSelect)
       
   848         	ClearAllOperations();        
       
   849         else
       
   850         	iWidgetOperations.Remove( 0 );
       
   851         }
   726         }
   852     }
   727     }
   853 
   728 
   854 void CWrtHarvester::ClearAllOperations()
   729 void CWrtHarvester::ClearAllOperations()
   855     {
   730     {
   904 // 
   779 // 
   905 // ----------------------------------------------------------------------------
   780 // ----------------------------------------------------------------------------
   906 //
   781 //
   907 void CWrtHarvester::LaunchWidgetOperationL( SWidgetOperation aOperation )
   782 void CWrtHarvester::LaunchWidgetOperationL( SWidgetOperation aOperation )
   908     {
   783     {
   909     LaunchWidgetL (aOperation.iUid, aOperation.iOperation );
   784     HBufC* widgetName( GetAppNameLC( iApaSession, aOperation.iUid) );
       
   785     HandleWidgetCommandL( iApaSession, *widgetName, aOperation.iUid, aOperation.iOperation );
       
   786     CleanupStack::PopAndDestroy( widgetName );
   910     }
   787     }
   911 
   788 
   912 // ----------------------------------------------------------------------------
   789 // ----------------------------------------------------------------------------
   913 // 
   790 // 
   914 // ----------------------------------------------------------------------------
   791 // ----------------------------------------------------------------------------
   916 void CWrtHarvester::QueueResumeL( TUid& aUid )
   793 void CWrtHarvester::QueueResumeL( TUid& aUid )
   917     {
   794     {
   918     RWidgetRegistryClientSession session;
   795     RWidgetRegistryClientSession session;
   919     CleanupClosePushL( session );
   796     CleanupClosePushL( session );
   920     User::LeaveIfError( session.Connect() );
   797     User::LeaveIfError( session.Connect() );
   921 
   798     if ( session.IsBlanketPermGranted ( aUid ) == EBlanketUnknown && !iDialogShown )
   922     CWidgetPropertyValue* property = session.GetWidgetPropertyValueL( aUid, EPreInstalled );
       
   923     TBool preInstalled = property && *(property);
       
   924     delete property;
       
   925 
       
   926     // Set blanket permission to true for pre-installed widgets
       
   927     if ( preInstalled )
       
   928         {
       
   929         session.SetBlanketPermissionL( aUid, EBlanketTrue );
       
   930         }
       
   931     
       
   932     if ( session.IsBlanketPermGranted ( aUid ) == EBlanketUnknown && !iDialogShown 
       
   933          &&  iCanAccessRegistry  )
       
   934         {
   799         {
   935         iDialogShown = ETrue;            
   800         iDialogShown = ETrue;            
   936         AllowPlatformAccessL( aUid );
   801         AllowPlatformAccessL( aUid );
   937         }
   802         }
   938     else if(session.IsBlanketPermGranted ( aUid ) == EBlanketUnknown)
   803     else if(!iDialogShown)
   939         {
       
   940         iUid.Append(aUid);
       
   941         }
       
   942     else
       
   943         {
   804         {
   944         QueueOperationL( WidgetResume, aUid );
   805         QueueOperationL( WidgetResume, aUid );
   945         }        
   806         }        
   946     CleanupStack::PopAndDestroy( &session );
   807     CleanupStack::PopAndDestroy( &session );
   947     }
   808     }
  1011 TBool CWrtHarvester::CheckNetworkAccessL( TUid& aUid )
   872 TBool CWrtHarvester::CheckNetworkAccessL( TUid& aUid )
  1012     {
   873     {
  1013     RWidgetRegistryClientSession session;
   874     RWidgetRegistryClientSession session;
  1014     CleanupClosePushL( session );
   875     CleanupClosePushL( session );
  1015     User::LeaveIfError( session.Connect() );
   876     User::LeaveIfError( session.Connect() );
  1016 
   877     TBool networkAccess = *(session.GetWidgetPropertyValueL( aUid, EAllowNetworkAccess ) );
  1017     CWidgetPropertyValue* value = session.GetWidgetPropertyValueL( aUid, EAllowNetworkAccess );
       
  1018     TBool networkAccess = value && *(value);
       
  1019     delete value;
       
  1020 
       
  1021     CleanupStack::PopAndDestroy( &session );
   878     CleanupStack::PopAndDestroy( &session );
  1022     
   879     
  1023     return networkAccess;
   880     return networkAccess;
  1024     }
       
  1025 // ----------------------------------------------------------------------------
       
  1026 // 
       
  1027 // ----------------------------------------------------------------------------
       
  1028 //
       
  1029 TInt CWrtHarvester::DeleteCallback(TAny* aPtr)
       
  1030     {
       
  1031     CWrtHarvester* self = (CWrtHarvester*)aPtr;    
       
  1032     self->QueueResumeL(self->iUid[0]);
       
  1033     self->iUid.Remove(0);    
       
  1034     delete self->iAsyncCallBack;
       
  1035     self->iAsyncCallBack = NULL;
       
  1036     return 0;
       
  1037     }
       
  1038 
       
  1039 // ----------------------------------------------------------------------------
       
  1040 // 
       
  1041 // ----------------------------------------------------------------------------
       
  1042 //
       
  1043 void CWrtHarvester::DialogShown()
       
  1044     {
       
  1045     iDialogShown = EFalse;
       
  1046     if(iUid.Count())
       
  1047         {
       
  1048         iAsyncCallBack = new (ELeave) CAsyncCallBack(TCallBack(DeleteCallback,this),CActive::EPriorityUserInput);
       
  1049         iAsyncCallBack->CallBack(); 
       
  1050         }
       
  1051     }
   881     }
  1052 
   882 
  1053 // ----------------------------------------------------------------------------
   883 // ----------------------------------------------------------------------------
  1054 // 
   884 // 
  1055 // ----------------------------------------------------------------------------
   885 // ----------------------------------------------------------------------------
  1161     iGlobalConfirmationQuery->ShowConfirmationQueryL
   991     iGlobalConfirmationQuery->ShowConfirmationQueryL
  1162                                 (iStatus,
   992                                 (iStatus,
  1163                                 aMessage,
   993                                 aMessage,
  1164                                 aSoftkeys);
   994                                 aSoftkeys);
  1165     }
   995     }
  1166 //======================================================================
   996 
  1167 // Launch widget.
       
  1168 //===========================================================================
       
  1169 //
       
  1170 void LaunchWidgetL( const TUid& aUid, TUint32 aOperation )
       
  1171     {
       
  1172     __UHEAP_MARK;
       
  1173     
       
  1174     TUid widgetAppUid( TUid::Uid( KWidgetAppUid ) );
       
  1175     
       
  1176     RWsSession wsSession;
       
  1177     ROomMonitorSession monitorSession;
       
  1178     TApaTaskList taskList( wsSession );
       
  1179     HBufC8* message( HBufC8::NewLC( KWidgetUiMaxMessageLength ) );
       
  1180     TPtr8 des( message->Des() );
       
  1181     TInt err(KErrNone);
       
  1182     RDesWriteStream stream( des );
       
  1183     
       
  1184     CleanupClosePushL( stream );
       
  1185     
       
  1186     // Make the message to be sent.
       
  1187     stream.WriteUint32L( 1 );
       
  1188     stream.WriteUint32L( aUid.iUid );
       
  1189     stream.WriteInt32L( aOperation );
       
  1190         
       
  1191     CleanupStack::PopAndDestroy( &stream );
       
  1192     
       
  1193     // Create Window server session
       
  1194     User::LeaveIfError( wsSession.Connect() );
       
  1195     User::LeaveIfError( monitorSession.Connect() );
       
  1196     CleanupClosePushL( wsSession );
       
  1197 
       
  1198     // Get the task list
       
  1199     // Try to find out if stub ui is already running
       
  1200     TApaTask task = taskList.FindApp( widgetAppUid );
       
  1201 
       
  1202     if ( task.Exists() )
       
  1203         {
       
  1204         // TODO make something here, or not...
       
  1205         widgetAppUid = TUid::Uid( 1 );
       
  1206         if ( aOperation == WidgetSelect )
       
  1207             {
       
  1208             task.BringToForeground();
       
  1209             }
       
  1210         task.SendMessage( widgetAppUid, des );
       
  1211         }
       
  1212     else
       
  1213         {
       
  1214         // TODO CONST
       
  1215         if ( aOperation == LaunchMiniview ||
       
  1216              aOperation == WidgetSelect ||
       
  1217              aOperation == WidgetResume ||
       
  1218              aOperation == WidgetRestart ) //WidgetUI has died -> re-launch
       
  1219             {
       
  1220             TInt bytesAvailaible(0);
       
  1221             if (aOperation != WidgetSelect )
       
  1222                 {
       
  1223 #ifdef BRDO_OOM_MONITOR2_COMPONENT_FF
       
  1224                 err = monitorSession.RequestOptionalRam(KMemoryToLaunchWidgetUi, KMemoryToLaunchWidgetUi,KUidWidgetOOMPlugin, bytesAvailaible);
       
  1225 #else
       
  1226                    TMemoryInfoV1Buf info;
       
  1227                    UserHal::MemoryInfo(info);
       
  1228                    err = info().iFreeRamInBytes > KMemoryToLaunchWidgetUi +  KRAMGOODTHRESHOLD ? KErrNone : KErrNoMemory;
       
  1229 #endif
       
  1230                 if( err == KErrNone)
       
  1231                     {
       
  1232                     LaunchWidgetUIL( widgetAppUid, *message, aOperation );
       
  1233                     }
       
  1234                 }
       
  1235             else
       
  1236                 {
       
  1237                 //The modification is related to the manual starting of WRT widgets from HS. After noticing an issue when
       
  1238                 //the user taps manually a WRT widget from the HS. 
       
  1239                 //If RAM is not available with RequestOptionalRam() API, the manual tapping does nothing
       
  1240                 //and that is incorrect behaviour. Therefore if widgetSelect -event is sent to the launcher we are using RequestFreeMemory() instead of using RequestOptionalRam() API. 
       
  1241                 //This means that we apply mandatory RAM allocation when a widget is started manually from HS in order to make sure that RAM is released properly
       
  1242                 err = monitorSession.RequestFreeMemory( KMemoryToLaunchWidgetUi );
       
  1243                 if( err == KErrNone)
       
  1244                     {
       
  1245                     LaunchWidgetUIL( widgetAppUid, *message, aOperation );
       
  1246                     }
       
  1247                 }
       
  1248             if(err != KErrNone)
       
  1249                 NotifyCommandAndCleanUp();
       
  1250             }
       
  1251         else
       
  1252             {
       
  1253             NotifyCommandAndCleanUp();
       
  1254             }
       
  1255             
       
  1256         }
       
  1257         
       
  1258     CleanupStack::PopAndDestroy( 2, message );
       
  1259     monitorSession.Close();
       
  1260     __UHEAP_MARKEND;
       
  1261     }
       
  1262 
       
  1263 //===========================================================================
       
  1264 // Launch Widget UI.
       
  1265 //===========================================================================
       
  1266 void LaunchWidgetUIL( 
       
  1267     const TUid& aUid, 
       
  1268     const TDesC8& aMessage, 
       
  1269     TUint32 aOperation )
       
  1270     {
       
  1271     HBufC* document( NULL );
       
  1272     CApaCommandLine* line( CApaCommandLine::NewLC() );
       
  1273     TApaAppInfo info;
       
  1274     RApaLsSession session;
       
  1275     
       
  1276     User::LeaveIfError( session.Connect() );
       
  1277     CleanupClosePushL( session );
       
  1278     
       
  1279     User::LeaveIfError( session.GetAppInfo( info, aUid ) );
       
  1280         
       
  1281     document = HBufC::NewMaxLC( TReal( TReal( aMessage.Length() )  / 2.0 ) + 0.5 );
       
  1282 
       
  1283     Mem::Copy( 
       
  1284         reinterpret_cast< TUint8* >( const_cast< TUint16* >( document->Ptr() ) ),
       
  1285         aMessage.Ptr(),
       
  1286         KWidgetUiMaxMessageLength );
       
  1287         
       
  1288     line->SetDocumentNameL( *document );
       
  1289     line->SetExecutableNameL( info.iFullName );
       
  1290         
       
  1291     // TODO make const definitions.
       
  1292     if ( aOperation == 1 || aOperation == 3 )
       
  1293         {
       
  1294         line->SetCommandL( EApaCommandBackground );
       
  1295         }
       
  1296         
       
  1297     session.StartApp( *line );
       
  1298 
       
  1299     CleanupStack::PopAndDestroy( 3, line );
       
  1300     }
       
  1301 
       
  1302 void NotifyCommandAndCleanUp()
       
  1303     {
       
  1304     const TUid KMyPropertyCat = { 0x10282E5A };
       
  1305     enum TMyPropertyKeys { EWidgetUIState = 109 };
       
  1306     TInt state( 2 );
       
  1307     RProperty::Set( KMyPropertyCat, EWidgetUIState , state );    
       
  1308     }
       
  1309  //  End of File
   997  //  End of File