webengine/wrtharvester/src/wrtharvester.cpp
branchRCL_3
changeset 46 30342f40acbf
parent 41 4bd5176e1bc8
child 47 e1bea15f9a39
equal deleted inserted replaced
44:800203832575 46:30342f40acbf
    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"
    48 
    54 
    49 // CONSTANTS
    55 // CONSTANTS
    50 _LIT( KResourceFileName, "\\resource\\wrtharvester.rsc" );
    56 _LIT( KResourceFileName, "\\resource\\wrtharvester.rsc" );
    51 _LIT( KResourceDir, "Z:wrtharvester.rsc" );
    57 _LIT( KResourceDir, "Z:wrtharvester.rsc" );
    52 _LIT( KUid, "uid");
    58 _LIT( KUid, "uid");
    53 _LIT( K0x, "0x");
    59 _LIT( K0x, "0x");
    54 _LIT( KOpenPar, "(");
    60 _LIT( KOpenPar, "(");
    55 _LIT( KClosePar, ")");
    61 _LIT( KClosePar, ")");
    56 _LIT8( KWidgetIcon, "widget_icon");
    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 );
    57 
    95 
    58 /**
    96 /**
    59 * Utility class to show the prompt for platform security access.
    97 * Utility class to show the prompt for platform security access.
    60 *
    98 *
    61 * The class exists only to provide platform security access prompt
    99 * The class exists only to provide platform security access prompt
   134     
   172     
   135 // ----------------------------------------------------------------------------
   173 // ----------------------------------------------------------------------------
   136 // Returns the app full name
   174 // Returns the app full name
   137 // ----------------------------------------------------------------------------
   175 // ----------------------------------------------------------------------------
   138 //
   176 //
       
   177 /*
   139 static HBufC* GetAppNameLC( RApaLsSession& aSession, const TUid& aUid )
   178 static HBufC* GetAppNameLC( RApaLsSession& aSession, const TUid& aUid )
   140     {
   179     {
   141     TApaAppInfo info;
   180     TApaAppInfo info;
   142     User::LeaveIfError( aSession.GetAppInfo( info, aUid ) );
   181     User::LeaveIfError( aSession.GetAppInfo( info, aUid ) );
   143     
   182     
   144     return info.iFullName.AllocLC();
   183     return info.iFullName.AllocLC();
   145     }
   184     }
   146     
   185 */
   147     
   186     
   148 // ----------------------------------------------------------------------------
       
   149 // Sends the command to Widget launcher
       
   150 // ----------------------------------------------------------------------------
       
   151 //
       
   152 static void HandleWidgetCommandL( 
       
   153     RApaLsSession& aSession, 
       
   154     const TDesC& aWidget,
       
   155     const TUid& aUid,
       
   156     TUint32 aOperation )
       
   157     {
       
   158     const TInt size( 2* aWidget.Length() + 3*sizeof( TUint32 ) );
       
   159     
       
   160     // Message format is <filenameLength><unicode_filename><someintegervalue>
       
   161     CApaCommandLine* cmd( CApaCommandLine::NewLC() );
       
   162     HBufC8* opaque( HBufC8::NewLC( size ) );
       
   163     
       
   164     RDesWriteStream stream;
       
   165     TPtr8 des( opaque->Des() );
       
   166     
       
   167     stream.Open( des );
       
   168     CleanupClosePushL( stream );
       
   169     
       
   170     // Generate the command.
       
   171     stream.WriteUint32L( aUid.iUid );
       
   172     stream.WriteUint32L( aWidget.Length() );
       
   173     stream.WriteL( reinterpret_cast< const TUint8* >( aWidget.Ptr() ),
       
   174                    aWidget.Size() );
       
   175     
       
   176     stream.WriteInt32L( aOperation );
       
   177     
       
   178     CleanupStack::PopAndDestroy( &stream );
       
   179     
       
   180     // Generate command.
       
   181     cmd->SetCommandL( EApaCommandBackgroundAndWithoutViews );
       
   182     cmd->SetOpaqueDataL( *opaque );    
       
   183 
       
   184     CleanupStack::PopAndDestroy( opaque );
       
   185     
       
   186     cmd->SetExecutableNameL( KLauncherApp );
       
   187     
       
   188     User::LeaveIfError( aSession.StartApp( *cmd ) );
       
   189     CleanupStack::PopAndDestroy( cmd );
       
   190     }
       
   191 
       
   192 // Map the interface UIDs to implementation factory functions
   187 // Map the interface UIDs to implementation factory functions
   193 const TImplementationProxy ImplementationTable[] = 
   188 const TImplementationProxy ImplementationTable[] = 
   194     {
   189     {
   195     IMPLEMENTATION_PROXY_ENTRY( 0xA12345FE, CWrtHarvester::NewL )
   190     IMPLEMENTATION_PROXY_ENTRY( 0xA12345FE, CWrtHarvester::NewL )
   196     };
   191     };
   899 // 
   894 // 
   900 // ----------------------------------------------------------------------------
   895 // ----------------------------------------------------------------------------
   901 //
   896 //
   902 void CWrtHarvester::LaunchWidgetOperationL( SWidgetOperation aOperation )
   897 void CWrtHarvester::LaunchWidgetOperationL( SWidgetOperation aOperation )
   903     {
   898     {
   904     HBufC* widgetName( GetAppNameLC( iApaSession, aOperation.iUid) );
   899     LaunchWidgetL (aOperation.iUid, aOperation.iOperation );
   905     HandleWidgetCommandL( iApaSession, *widgetName, aOperation.iUid, aOperation.iOperation );
       
   906     CleanupStack::PopAndDestroy( widgetName );
       
   907     }
   900     }
   908 
   901 
   909 // ----------------------------------------------------------------------------
   902 // ----------------------------------------------------------------------------
   910 // 
   903 // 
   911 // ----------------------------------------------------------------------------
   904 // ----------------------------------------------------------------------------
  1158     iGlobalConfirmationQuery->ShowConfirmationQueryL
  1151     iGlobalConfirmationQuery->ShowConfirmationQueryL
  1159                                 (iStatus,
  1152                                 (iStatus,
  1160                                 aMessage,
  1153                                 aMessage,
  1161                                 aSoftkeys);
  1154                                 aSoftkeys);
  1162     }
  1155     }
  1163 
  1156 //======================================================================
       
  1157 // Launch widget.
       
  1158 //===========================================================================
       
  1159 //
       
  1160 void LaunchWidgetL( const TUid& aUid, TUint32 aOperation )
       
  1161     {
       
  1162     __UHEAP_MARK;
       
  1163     
       
  1164     TUid widgetAppUid( TUid::Uid( KWidgetAppUid ) );
       
  1165     
       
  1166     RWsSession wsSession;
       
  1167     ROomMonitorSession monitorSession;
       
  1168     TApaTaskList taskList( wsSession );
       
  1169     HBufC8* message( HBufC8::NewLC( KWidgetUiMaxMessageLength ) );
       
  1170     TPtr8 des( message->Des() );
       
  1171     TInt err(KErrNone);
       
  1172     RDesWriteStream stream( des );
       
  1173     
       
  1174     CleanupClosePushL( stream );
       
  1175     
       
  1176     // Make the message to be sent.
       
  1177     stream.WriteUint32L( 1 );
       
  1178     stream.WriteUint32L( aUid.iUid );
       
  1179     stream.WriteInt32L( aOperation );
       
  1180         
       
  1181     CleanupStack::PopAndDestroy( &stream );
       
  1182     
       
  1183     // Create Window server session
       
  1184     User::LeaveIfError( wsSession.Connect() );
       
  1185     User::LeaveIfError( monitorSession.Connect() );
       
  1186     CleanupClosePushL( wsSession );
       
  1187 
       
  1188     // Get the task list
       
  1189     // Try to find out if stub ui is already running
       
  1190     TApaTask task = taskList.FindApp( widgetAppUid );
       
  1191 
       
  1192     if ( task.Exists() )
       
  1193         {
       
  1194         // TODO make something here, or not...
       
  1195         widgetAppUid = TUid::Uid( 1 );
       
  1196         if ( aOperation == WidgetSelect )
       
  1197             {
       
  1198             task.BringToForeground();
       
  1199             }
       
  1200         task.SendMessage( widgetAppUid, des );
       
  1201         }
       
  1202     else
       
  1203         {
       
  1204         // TODO CONST
       
  1205         if ( aOperation == LaunchMiniview ||
       
  1206              aOperation == WidgetSelect ||
       
  1207              aOperation == WidgetResume ||
       
  1208              aOperation == WidgetRestart ) //WidgetUI has died -> re-launch
       
  1209             {
       
  1210             TInt bytesAvailaible(0);
       
  1211             if (aOperation != WidgetSelect )
       
  1212                 {
       
  1213 #ifdef BRDO_OOM_MONITOR2_COMPONENT_FF
       
  1214                 err = monitorSession.RequestOptionalRam(KMemoryToLaunchWidgetUi, KMemoryToLaunchWidgetUi,KUidWidgetOOMPlugin, bytesAvailaible);
       
  1215 #else
       
  1216                    TMemoryInfoV1Buf info;
       
  1217                    UserHal::MemoryInfo(info);
       
  1218                    err = info().iFreeRamInBytes > KMemoryToLaunchWidgetUi +  KRAMGOODTHRESHOLD ? KErrNone : KErrNoMemory;
       
  1219 #endif
       
  1220                 if( err == KErrNone)
       
  1221                     {
       
  1222                     LaunchWidgetUIL( widgetAppUid, *message, aOperation );
       
  1223                     }
       
  1224                 }
       
  1225             else
       
  1226                 {
       
  1227                 //The modification is related to the manual starting of WRT widgets from HS. After noticing an issue when
       
  1228                 //the user taps manually a WRT widget from the HS. 
       
  1229                 //If RAM is not available with RequestOptionalRam() API, the manual tapping does nothing
       
  1230                 //and that is incorrect behaviour. Therefore if widgetSelect -event is sent to the launcher we are using RequestFreeMemory() instead of using RequestOptionalRam() API. 
       
  1231                 //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
       
  1232                 err = monitorSession.RequestFreeMemory( KMemoryToLaunchWidgetUi );
       
  1233                 if( err == KErrNone)
       
  1234                     {
       
  1235                     LaunchWidgetUIL( widgetAppUid, *message, aOperation );
       
  1236                     }
       
  1237                 }
       
  1238             if(err != KErrNone)
       
  1239                 NotifyCommandAndCleanUp();
       
  1240             }
       
  1241         else
       
  1242             {
       
  1243             NotifyCommandAndCleanUp();
       
  1244             }
       
  1245             
       
  1246         }
       
  1247         
       
  1248     CleanupStack::PopAndDestroy( 2, message );
       
  1249     monitorSession.Close();
       
  1250     __UHEAP_MARKEND;
       
  1251     }
       
  1252 
       
  1253 //===========================================================================
       
  1254 // Launch Widget UI.
       
  1255 //===========================================================================
       
  1256 void LaunchWidgetUIL( 
       
  1257     const TUid& aUid, 
       
  1258     const TDesC8& aMessage, 
       
  1259     TUint32 aOperation )
       
  1260     {
       
  1261     HBufC* document( NULL );
       
  1262     CApaCommandLine* line( CApaCommandLine::NewLC() );
       
  1263     TApaAppInfo info;
       
  1264     RApaLsSession session;
       
  1265     
       
  1266     User::LeaveIfError( session.Connect() );
       
  1267     CleanupClosePushL( session );
       
  1268     
       
  1269     User::LeaveIfError( session.GetAppInfo( info, aUid ) );
       
  1270         
       
  1271     document = HBufC::NewMaxLC( TReal( TReal( aMessage.Length() )  / 2.0 ) + 0.5 );
       
  1272 
       
  1273     Mem::Copy( 
       
  1274         reinterpret_cast< TUint8* >( const_cast< TUint16* >( document->Ptr() ) ),
       
  1275         aMessage.Ptr(),
       
  1276         KWidgetUiMaxMessageLength );
       
  1277         
       
  1278     line->SetDocumentNameL( *document );
       
  1279     line->SetExecutableNameL( info.iFullName );
       
  1280         
       
  1281     // TODO make const definitions.
       
  1282     if ( aOperation == 1 || aOperation == 3 )
       
  1283         {
       
  1284         line->SetCommandL( EApaCommandBackground );
       
  1285         }
       
  1286         
       
  1287     session.StartApp( *line );
       
  1288 
       
  1289     CleanupStack::PopAndDestroy( 3, line );
       
  1290     }
       
  1291 
       
  1292 void NotifyCommandAndCleanUp()
       
  1293     {
       
  1294     const TUid KMyPropertyCat = { 0x10282E5A };
       
  1295     enum TMyPropertyKeys { EWidgetUIState = 109 };
       
  1296     TInt state( 2 );
       
  1297     RProperty::Set( KMyPropertyCat, EWidgetUIState , state );    
       
  1298     }
  1164  //  End of File
  1299  //  End of File