widgets/widgetlauncher/src/WidgetLauncher.cpp
changeset 10 a359256acfc6
parent 1 7c90e6132015
child 25 0ed94ceaa377
equal deleted inserted replaced
5:10e98eab6f85 10:a359256acfc6
    27 #include <e32base.h>
    27 #include <e32base.h>
    28 #include <f32file.h>
    28 #include <f32file.h>
    29 #include <apgcli.h>
    29 #include <apgcli.h>
    30 #include <W32STD.H>
    30 #include <W32STD.H>
    31 #include <APGTASK.H>
    31 #include <APGTASK.H>
       
    32 #include <oommonitorsession.h>
       
    33 #include <e32property.h>
       
    34 #include <systemwarninglevels.hrh>
       
    35 #include "Browser_platform_variant.hrh"
    32 
    36 
    33 // CONSTANTS
    37 // CONSTANTS
       
    38 #define KUidWidgetOOMPlugin 0x10282855
       
    39 const TInt KMemoryToLaunchWidgetUi = 17*1024*1024;
       
    40 
    34 
    41 
    35 // LOCAL FUNCTION DEFINITIONS
    42 // LOCAL FUNCTION DEFINITIONS
    36 // RDesWriteStream
    43 // RDesWriteStream
    37 /** 
    44 /** 
    38 * Parse command line in order to launch the widget.
    45 * Parse command line in order to launch the widget.
    50 * Launch widget.
    57 * Launch widget.
    51 * @param aUid UID of the widget.
    58 * @param aUid UID of the widget.
    52 * @param aOperation Operation to perform.
    59 * @param aOperation Operation to perform.
    53 */
    60 */
    54 static void LaunchWidgetL( const TUid& aUid, TUint32 aOperation );
    61 static void LaunchWidgetL( const TUid& aUid, TUint32 aOperation );
       
    62 
       
    63 /** 
       
    64 * In case the widget cannot be launched because of OOM
       
    65 * Notify harvester and Clear event Queue
       
    66 * @return void
       
    67 */
       
    68 static void NotifyCommandAndCleanUp();
    55 
    69 
    56 /** 
    70 /** 
    57 * Launch new widget.
    71 * Launch new widget.
    58 *
    72 *
    59 * Launch new widget.
    73 * Launch new widget.
   145     __UHEAP_MARK;
   159     __UHEAP_MARK;
   146     
   160     
   147     TUid widgetAppUid( TUid::Uid( KWidgetAppUid ) );
   161     TUid widgetAppUid( TUid::Uid( KWidgetAppUid ) );
   148     
   162     
   149     RWsSession wsSession;
   163     RWsSession wsSession;
       
   164     ROomMonitorSession monitorSession;
   150     TApaTaskList taskList( wsSession );
   165     TApaTaskList taskList( wsSession );
   151     HBufC8* message( HBufC8::NewLC( KWidgetUiMaxMessageLength ) );
   166     HBufC8* message( HBufC8::NewLC( KWidgetUiMaxMessageLength ) );
   152     TPtr8 des( message->Des() );
   167     TPtr8 des( message->Des() );
       
   168     TInt err(KErrNone);
   153     RDesWriteStream stream( des );
   169     RDesWriteStream stream( des );
   154     
   170     
   155     CleanupClosePushL( stream );
   171     CleanupClosePushL( stream );
   156     
   172     
   157     // Make the message to be sent.
   173     // Make the message to be sent.
   161         
   177         
   162     CleanupStack::PopAndDestroy( &stream );
   178     CleanupStack::PopAndDestroy( &stream );
   163     
   179     
   164     // Create Window server session
   180     // Create Window server session
   165     User::LeaveIfError( wsSession.Connect() );
   181     User::LeaveIfError( wsSession.Connect() );
       
   182     User::LeaveIfError( monitorSession.Connect() );
   166     CleanupClosePushL( wsSession );
   183     CleanupClosePushL( wsSession );
   167 
   184 
   168     // Get the task list
   185     // Get the task list
   169     // Try to find out if stub ui is already running
   186     // Try to find out if stub ui is already running
   170     TApaTask task = taskList.FindApp( widgetAppUid );
   187     TApaTask task = taskList.FindApp( widgetAppUid );
   183     else
   200     else
   184         {
   201         {
   185         // TODO CONST
   202         // TODO CONST
   186         if ( aOperation == LaunchFullscreen ||
   203         if ( aOperation == LaunchFullscreen ||
   187              aOperation == LaunchMiniview ||
   204              aOperation == LaunchMiniview ||
   188              aOperation == WidgetSelect ) //WidgetUI has died -> re-launch
   205              aOperation == WidgetSelect ||
       
   206              aOperation == WidgetResume ||
       
   207              aOperation == WidgetRestart ) //WidgetUI has died -> re-launch
   189             {
   208             {
   190             LaunchWidgetUIL( widgetAppUid, *message, aOperation );
   209             TInt bytesAvailaible(0);
       
   210             if (aOperation != WidgetSelect && aOperation != LaunchFullscreen )
       
   211                 {
       
   212 #ifdef FF_OOM_MONITOR2_COMPONENT
       
   213                 err = monitorSession.RequestOptionalRam(KMemoryToLaunchWidgetUi, KMemoryToLaunchWidgetUi,KUidWidgetOOMPlugin, bytesAvailaible);
       
   214 #else
       
   215                    TMemoryInfoV1Buf info;
       
   216                    UserHal::MemoryInfo(info);
       
   217                    err = info().iFreeRamInBytes > KMemoryToLaunchWidgetUi +  KRAMGOODTHRESHOLD ? KErrNone : KErrNoMemory;
       
   218 #endif
       
   219                 if( err == KErrNone)
       
   220                     {
       
   221                     LaunchWidgetUIL( widgetAppUid, *message, aOperation );
       
   222                     }
       
   223                 }
       
   224             else
       
   225                 {
       
   226 				//The modification is related to the manual starting of WRT widgets from HS. After noticing an issue when
       
   227 				//the user taps manually a WRT widget from the HS. 
       
   228 				//If RAM is not available with RequestOptionalRam() API, the manual tapping does nothing
       
   229 				//and that is incorrect behaviour. Therefore if widgetSelect -event is sent to the launcher we are using RequestFreeMemory() instead of using RequestOptionalRam() API. 
       
   230 				//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
       
   231                 err = monitorSession.RequestFreeMemory( KMemoryToLaunchWidgetUi );
       
   232                 if( err == KErrNone)
       
   233                     {
       
   234                     LaunchWidgetUIL( widgetAppUid, *message, aOperation );
       
   235                     }
       
   236                 }
       
   237             if(err != KErrNone)
       
   238                 NotifyCommandAndCleanUp();
   191             }
   239             }
       
   240         else
       
   241             {
       
   242             NotifyCommandAndCleanUp();
       
   243             }
       
   244             
   192         }
   245         }
   193         
   246         
   194     CleanupStack::PopAndDestroy( 2, message );
   247     CleanupStack::PopAndDestroy( 2, message );
   195     
   248     monitorSession.Close();
   196     __UHEAP_MARKEND;
   249     __UHEAP_MARKEND;
   197     }
   250     }
   198 
   251 
   199 //===========================================================================
   252 //===========================================================================
   200 // Launch Widget UI.
   253 // Launch Widget UI.
   223         
   276         
   224     line->SetDocumentNameL( *document );
   277     line->SetDocumentNameL( *document );
   225     line->SetExecutableNameL( info.iFullName );
   278     line->SetExecutableNameL( info.iFullName );
   226         
   279         
   227     // TODO make const definitions.
   280     // TODO make const definitions.
   228     if ( aOperation == 1 )
   281     if ( aOperation == 1 || aOperation == 3 )
   229         {
   282         {
   230         line->SetCommandL( EApaCommandBackground );
   283         line->SetCommandL( EApaCommandBackground );
   231         }
   284         }
   232         
   285         
   233     session.StartApp( *line );
   286     session.StartApp( *line );
   234 
   287 
   235     CleanupStack::PopAndDestroy( 3, line );
   288     CleanupStack::PopAndDestroy( 3, line );
   236     }
   289     }
   237 
   290 
       
   291 void NotifyCommandAndCleanUp()
       
   292     {
       
   293     const TUid KMyPropertyCat = { 0x10282E5A };
       
   294     enum TMyPropertyKeys { EWidgetUIState = 109 };
       
   295     TInt state( 2 );
       
   296     RProperty::Set( KMyPropertyCat, EWidgetUIState , state );    
       
   297     }
       
   298     
   238 /*
   299 /*
   239 * E32Main: called by operating system to start the program
   300 * E32Main: called by operating system to start the program
   240 */
   301 */
   241 TInt E32Main(void)
   302 TInt E32Main(void)
   242     {
   303     {