htiui/HtiServicePlugins/HtiAppServicePlugin/src/HtiAppControl.cpp
changeset 0 d6fe6244b863
child 3 2703485a934c
equal deleted inserted replaced
-1:000000000000 0:d6fe6244b863
       
     1 /*
       
     2 * Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies).
       
     3 * All rights reserved.
       
     4 * This component and the accompanying materials are made available
       
     5 * under the terms of "Eclipse Public License v1.0"
       
     6 * which accompanies this distribution, and is available
       
     7 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     8 *
       
     9 * Initial Contributors:
       
    10 * Nokia Corporation - initial contribution.
       
    11 *
       
    12 * Contributors:
       
    13 *
       
    14 * Description:  HtiAppControl implementation
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 // INCLUDE FILES
       
    20 #include "../../../symbian_version.hrh"
       
    21 
       
    22 #include <apacmdln.h>
       
    23 #include <apgtask.h>
       
    24 #include <apgwgnam.h>
       
    25 #include <apmstd.h>
       
    26 
       
    27 #include <badesca.h>
       
    28 #include <f32file.h>
       
    29 
       
    30 #include "HtiAppControl.h"
       
    31 #include <HtiDispatcherInterface.h>
       
    32 #include <HTILogging.h>
       
    33 
       
    34 #include <swinstapi.h>
       
    35 #include <swi/sisregistrysession.h>
       
    36 #include <swi/sisregistrypackage.h>
       
    37 #if ( SYMBIAN_VERSION_SUPPORT < SYMBIAN_4 )
       
    38     #include <javaregistryincludes.h>
       
    39 #endif
       
    40 #include <widgetregistryclient.h>
       
    41 
       
    42 #if ( SYMBIAN_VERSION_SUPPORT < SYMBIAN_4 )
       
    43     using namespace Java;
       
    44 #endif
       
    45 
       
    46 // CONSTANTS
       
    47 const static TUid KAppServiceUid = { 0x1020DEC7 }; //This is Uid of AppServiceOS
       
    48 
       
    49 //error descriptions
       
    50 _LIT8( KErrDescrNoMemory, "No memory" );
       
    51 _LIT8( KErrDescrInvalidCmd, "Invalid command" );
       
    52 _LIT8( KErrDescrInvalidArguments, "Invalid arguments" );
       
    53 _LIT8( KErrDescrFailedCreateProcess, "Failed create process" );
       
    54 _LIT8( KErrDescrNotSupported, "Command not supported" );
       
    55 
       
    56 _LIT8( KErrDescrFailedStartApp, "Failed start app" );
       
    57 _LIT8( KErrDescrInvalidUid, "Invalid application uid" );
       
    58 _LIT8( KErrDescrFailedFindApp, "Failed find app" );
       
    59 
       
    60 _LIT8( KErrDescrFailedConnectSilentInstaller, "Failed to connect to silent installer" );
       
    61 _LIT8( KErrDescrFailedInstall, "Failed to install" );
       
    62 _LIT8( KErrDescrFailedUnInstall, "Failed to uninstall" );
       
    63 _LIT8( KErrDescrFailedFindPackage, "Failed to find the package" );
       
    64 
       
    65 _LIT8( KErrDescrFailedListInstApps, "Failed to list installed apps" );
       
    66 
       
    67 const static TUint8 KUnicodeMask = 0x01;
       
    68 const static TInt KTerminateReason = 0;
       
    69 const static TInt KTUintLength = sizeof(TUint);
       
    70 const static TInt KCloseTaskDelay = 250000; // microseconds
       
    71 
       
    72 // MACROS
       
    73 
       
    74 // LOCAL CONSTANTS AND MACROS
       
    75 
       
    76 // MODULE DATA STRUCTURES
       
    77 
       
    78 // LOCAL FUNCTION PROTOTYPES
       
    79 
       
    80 // FORWARD DECLARATIONS
       
    81 
       
    82 // ============================ MEMBER FUNCTIONS ===============================
       
    83 CHtiAppControl* CHtiAppControl::NewL()
       
    84     {
       
    85     CHtiAppControl* self = new ( ELeave ) CHtiAppControl;
       
    86     CleanupStack::PushL( self );
       
    87     self->ConstructL();
       
    88     CleanupStack::Pop();
       
    89     return self;
       
    90     }
       
    91 
       
    92 // Constructor
       
    93 CHtiAppControl::CHtiAppControl():iIsAppCmdsSupported( EFalse )
       
    94     {
       
    95     }
       
    96 
       
    97 EXPORT_C CHtiAppControl* NewHtiAppControl()
       
    98     {
       
    99     return CHtiAppControl::NewL();
       
   100     }
       
   101 
       
   102 CHtiAppControl::~CHtiAppControl()
       
   103     {
       
   104     HTI_LOG_FUNC_IN( "~CHtiAppControl" );
       
   105 
       
   106     for ( TInt i = 0; i < iProcessHandleArray.Count(); i++ )
       
   107         {
       
   108         iProcessHandleArray[i].Close();
       
   109         }
       
   110     iProcessHandleArray.Close();
       
   111 
       
   112     iAppServer.Close();
       
   113     iWs.Close();
       
   114 
       
   115     if ( iMimeTypes )
       
   116         {
       
   117         iMimeTypes->Reset();
       
   118         delete iMimeTypes;
       
   119         }
       
   120 
       
   121     iAugmentations.ResetAndDestroy();
       
   122 
       
   123     HTI_LOG_FUNC_OUT( "~CHtiAppControl" );
       
   124     }
       
   125 
       
   126 // Second phase construction.
       
   127 void CHtiAppControl::ConstructL()
       
   128     {
       
   129     HTI_LOG_FUNC_IN( "CHtiAppControl::ConstructL" );
       
   130     iMimeTypes = new (ELeave) CDesC8ArrayFlat( 8 );
       
   131     iMimeTypes->AppendL( SwiUI::KSisxMimeType() );
       
   132     iMimeTypes->AppendL( SwiUI::KSisMimeType() );
       
   133     iMimeTypes->AppendL( SwiUI::KPipMimeType() );
       
   134     iMimeTypes->AppendL( SwiUI::KJadMIMEType() );
       
   135     iMimeTypes->AppendL( SwiUI::KJarMIMEType() );
       
   136     iMimeTypes->AppendL( SwiUI::KJavaMIMEType() );
       
   137     iMimeTypes->AppendL( SwiUI::KJarxMIMEType() );
       
   138     iMimeTypes->AppendL( KWidgetMime() ); // from widgetregistryconstants.h
       
   139     iAugmentationIndex = 0;
       
   140 
       
   141     TInt err = iAppServer.Connect();
       
   142     if ( err == KErrNone )
       
   143         {
       
   144         err = iWs.Connect();
       
   145         }
       
   146     if ( err == KErrNone )
       
   147         {
       
   148         iIsAppCmdsSupported = ETrue;
       
   149         }
       
   150     else
       
   151         {
       
   152         iAppServer.Close();
       
   153         }
       
   154     HTI_LOG_FUNC_OUT( "CHtiAppControl::ConstructL" );
       
   155     }
       
   156 
       
   157 TInt CHtiAppControl::ParseString( const TDesC8& aRequest,
       
   158                                         TInt anOffset,
       
   159                                         TBool aUnicode,
       
   160                                         TDes& aResult )
       
   161     {
       
   162     HTI_LOG_FUNC_IN( "CHtiAppControl::ParseString" );
       
   163     //validate parameters
       
   164     //if offset outside the string return empty string
       
   165     if ( anOffset >= aRequest.Size() )
       
   166         {
       
   167         return anOffset;
       
   168         }
       
   169 
       
   170     TInt len = aRequest[anOffset];
       
   171     HTI_LOG_FORMAT( "length %d", len );
       
   172 
       
   173     if ( len > aResult.MaxLength() )
       
   174         {
       
   175         return KErrBadDescriptor;
       
   176         }
       
   177 
       
   178     TInt nextOffset = ( aUnicode ? len * 2 : len ) + anOffset + 1;
       
   179     HTI_LOG_FORMAT( "nextOffset %d", nextOffset );
       
   180     HTI_LOG_FORMAT( "reqSize %d", aRequest.Size() );
       
   181     if ( nextOffset > aRequest.Size() )
       
   182         {
       
   183         return KErrArgument;
       
   184         }
       
   185 
       
   186     if ( aUnicode )
       
   187         {
       
   188         const TPtrC8 aFrom( aRequest.Mid( anOffset + 1, len * 2 ) );
       
   189         aResult.SetLength( len );
       
   190         for ( TInt i = 0; i < len; ++i )
       
   191             {
       
   192             aResult[i] = ( TUint16 ) aFrom[i << 1] +
       
   193                 ( ( ( TUint16 ) aFrom[( i << 1 ) + 1] ) << 8 );
       
   194             }
       
   195         }
       
   196     else
       
   197         {
       
   198         aResult.Copy( aRequest.Mid( anOffset + 1, len ) );
       
   199         }
       
   200 
       
   201     HTI_LOG_FUNC_OUT( "CHtiAppControl::ParseString" );
       
   202     return nextOffset;
       
   203     }
       
   204 
       
   205 void CHtiAppControl::ProcessMessageL( const TDesC8& aMessage,
       
   206                 THtiMessagePriority /*aPriority*/ )
       
   207     {
       
   208     HTI_LOG_FUNC_IN( "CHtiAppControl::ProcessMessage" );
       
   209     if ( aMessage.Length() < 1 )
       
   210         {
       
   211         // no command
       
   212         SendErrorMsg( KErrArgument, KErrDescrInvalidCmd );
       
   213         return;
       
   214         }
       
   215 
       
   216     if ( aMessage.Length() < 2 &&
       
   217          aMessage[0] !=  EListInstalledApps &&
       
   218          aMessage[0] !=  EListInstalledApps_u)
       
   219         {
       
   220          // parameter is required with all commands except
       
   221          // listing processes or installed applications
       
   222         SendErrorMsg( KErrArgument, KErrDescrInvalidCmd );
       
   223         return;
       
   224         }
       
   225 
       
   226     HTI_LOG_FORMAT( "cmd %d", aMessage[0] );
       
   227 
       
   228     if ( aMessage[0] > EProcessLastCommand &&
       
   229               aMessage[0] < EAppLastCommand)
       
   230         {
       
   231         if ( iIsAppCmdsSupported )
       
   232             {
       
   233             HandleAppControlL( aMessage );
       
   234             }
       
   235         else
       
   236             {
       
   237             SendErrorMsg( KErrNotSupported, KErrDescrNotSupported );
       
   238             }
       
   239         }
       
   240     else if ( aMessage[0] > EAppLastCommand &&
       
   241               aMessage[0] < ESisLastCommand )
       
   242         {
       
   243         HandleInstallerControlL( aMessage );
       
   244         }
       
   245     else
       
   246         {
       
   247         SendErrorMsg( KErrArgument, KErrDescrInvalidCmd );
       
   248         }
       
   249     HTI_LOG_FUNC_OUT( "CHtiAppControl::ProcessMessage" );
       
   250     }
       
   251 
       
   252 void CHtiAppControl::HandleAppControlL( const TDesC8& aMessage )
       
   253     {
       
   254     HTI_LOG_FUNC_IN( "CHtiAppControl::HandleAppControl" );
       
   255 
       
   256     TBool unicode = aMessage[0] & KUnicodeMask;
       
   257 
       
   258     HTI_LOG_FORMAT( "unicode %d", unicode );
       
   259 
       
   260     TApaAppInfo appInfo;
       
   261     TFileName appName;
       
   262     TFileName docName;
       
   263 
       
   264     switch ( aMessage[0] )
       
   265         {
       
   266         case EStartApp_uid:
       
   267         case EStartApp_uid_u:
       
   268             {
       
   269             TPtrC8 parameters = aMessage.Mid( 1 );
       
   270             if ( parameters.Length() >= 4 )
       
   271                 {
       
   272                 TInt32 uid = Parse32<TInt32>( parameters );
       
   273 
       
   274                 TInt offset = ParseString( parameters, 4, unicode, docName );
       
   275                 if ( offset >= 0)
       
   276                     {
       
   277                     if ( FindAppL( appInfo, uid ) )
       
   278                         {
       
   279                         HandleStartAppL( appInfo, docName );
       
   280                         }
       
   281                     }
       
   282                 else
       
   283                     {
       
   284                     SendErrorMsg( offset , KErrDescrInvalidArguments );
       
   285                     }
       
   286                 }
       
   287             else
       
   288                 {
       
   289                 SendErrorMsg( KErrArgument , KErrDescrInvalidUid );
       
   290                 }
       
   291             }
       
   292             break;
       
   293         case EStartApp:
       
   294         case EStartApp_u:
       
   295             {
       
   296             TInt offset = ParseString( aMessage, 1, unicode, appName );
       
   297             if ( offset >= 0 )
       
   298                 {
       
   299                 offset = ParseString( aMessage, offset, unicode, docName );
       
   300                 if ( offset >= 0 )
       
   301                     {
       
   302                     //find appInfo by app full name
       
   303                     if ( FindAppL( appInfo, appName ) )
       
   304                         {
       
   305                         HTI_LOG_TEXT( "call HandleStartAppL" );
       
   306                         HandleStartAppL( appInfo, docName );
       
   307                         }
       
   308                     }
       
   309                 }
       
   310 
       
   311             if ( offset < 0 )
       
   312                 {
       
   313                 SendErrorMsg( offset , KErrDescrInvalidArguments );
       
   314                 }
       
   315             }
       
   316             break;
       
   317         case EStartDoc:
       
   318         case EStartDoc_u:
       
   319             {
       
   320             TInt offset = ParseString( aMessage, 1, unicode, docName );
       
   321             if ( offset >= 0 )
       
   322                 {
       
   323                 HandleStartAppL( appInfo, docName ); //appInfo is empty
       
   324                 }
       
   325             else
       
   326                 {
       
   327                 SendErrorMsg( offset , KErrDescrInvalidArguments );
       
   328                 }
       
   329             }
       
   330             break;
       
   331         case EStatusApp_uid:
       
   332             {
       
   333             TPtrC8 appUid8 = aMessage.Mid( 1 );
       
   334             if ( appUid8.Length() == 4 )
       
   335                 {
       
   336                 TApaTaskList tl( iWs );
       
   337                 TInt32 appUid = Parse32<TInt32>( appUid8 );
       
   338                 TApaTask task = tl.FindApp( TUid::Uid( appUid ) );
       
   339                 if ( task.Exists() )
       
   340                     {
       
   341                     SendMessageL( ERunning );
       
   342                     }
       
   343                 else
       
   344                     {
       
   345                     SendMessageL( ENotFound );
       
   346                     }
       
   347                 }
       
   348             else
       
   349                 {
       
   350                 SendErrorMsg( KErrArgument, KErrDescrInvalidUid );
       
   351                 }
       
   352             }
       
   353             break;
       
   354         case EStatusApp:
       
   355         case EStatusApp_u:
       
   356             {
       
   357             TInt offset = ParseString( aMessage, 1, unicode, appName );
       
   358             if ( offset >= 0 )
       
   359                 {
       
   360                 TApaTaskList tl( iWs );
       
   361                 TApaTask task = tl.FindApp( appName );
       
   362                 if ( task.Exists() )
       
   363                     {
       
   364                     SendMessageL( ERunning );
       
   365                     break; // we are done
       
   366                     }
       
   367 
       
   368                 // Maybe the user gave path or filename instead of caption
       
   369                 if ( FindAppL( appInfo, appName ) )
       
   370                     {
       
   371                     TApaTask task2 = tl.FindApp( appInfo.iUid );
       
   372                     if ( task2.Exists() )
       
   373                         {
       
   374                         SendMessageL( ERunning );
       
   375                         }
       
   376                     else
       
   377                         {
       
   378                         SendMessageL( ENotFound );
       
   379                         }
       
   380                     }
       
   381                 // If app was not found by FindAppL method, a response message
       
   382                 // has already been sent there - no need to send anything here.
       
   383                 }
       
   384             else
       
   385                 {
       
   386                 SendErrorMsg( offset , KErrDescrInvalidArguments );
       
   387                 }
       
   388             }
       
   389             break;
       
   390         case EStatusDoc:
       
   391         case EStatusDoc_u:
       
   392             {
       
   393             TInt offset = ParseString( aMessage, 1, unicode, docName );
       
   394             if ( offset >= 0 )
       
   395                 {
       
   396                 TApaTaskList tl( iWs );
       
   397                 TApaTask task = tl.FindDoc( docName );
       
   398                 if ( task.Exists() )
       
   399                     {
       
   400                     SendMessageL( ERunning );
       
   401                     }
       
   402                 else
       
   403                     {
       
   404                     SendMessageL( ENotFound );
       
   405                     }
       
   406                 }
       
   407             else
       
   408                 {
       
   409                 SendErrorMsg( offset , KErrDescrInvalidArguments );
       
   410                 }
       
   411             }
       
   412             break;
       
   413         case EStopApp:
       
   414         case EStopApp_u:
       
   415             {
       
   416             TInt offset = ParseString( aMessage, 1, unicode, appName );
       
   417             if ( offset >= 0 )
       
   418                 {
       
   419                 TApaTaskList tl( iWs );
       
   420                 TApaTask task = tl.FindApp( appName );
       
   421                 if ( task.Exists() )
       
   422                     {
       
   423                     task.EndTask();
       
   424                     User::After( KCloseTaskDelay );
       
   425                     TApaTask task = tl.FindApp( appName );
       
   426                     if ( task.Exists() )
       
   427                         {
       
   428                         task.KillTask();
       
   429                         }
       
   430                     SendMessageL( EOk );
       
   431                     break; // we are done
       
   432                     }
       
   433 
       
   434                 // Maybe the user gave path or filename instead of caption
       
   435                 if ( FindAppL( appInfo, appName ) )
       
   436                     {
       
   437                     TApaTask task2 = tl.FindApp( appInfo.iUid );
       
   438                     if ( task2.Exists() )
       
   439                         {
       
   440                         task2.EndTask();
       
   441                         User::After( KCloseTaskDelay );
       
   442                         TApaTask task2 = tl.FindApp( appInfo.iUid );
       
   443                         if ( task2.Exists() )
       
   444                             {
       
   445                             task2.KillTask();
       
   446                             }
       
   447                         SendMessageL( EOk );
       
   448                         }
       
   449                     else
       
   450                         {
       
   451                         SendMessageL( ENotFound );
       
   452                         }
       
   453                     }
       
   454                 // If app was not found by FindAppL method, a response message
       
   455                 // has already been sent there - no need to send anything here.
       
   456                 }
       
   457             else
       
   458                 {
       
   459                 SendErrorMsg( offset , KErrDescrInvalidArguments );
       
   460                 }
       
   461             }
       
   462             break;
       
   463         case EStopDoc:
       
   464         case EStopDoc_u:
       
   465             {
       
   466             TInt offset = ParseString( aMessage, 1, unicode, docName );
       
   467             if ( offset >= 0 )
       
   468                 {
       
   469                 TApaTaskList tl( iWs );
       
   470                 TApaTask task = tl.FindDoc( docName );
       
   471                 if ( task.Exists() )
       
   472                     {
       
   473                     task.EndTask();
       
   474                     User::After( KCloseTaskDelay );
       
   475                     TApaTask task = tl.FindDoc( docName );
       
   476                     if ( task.Exists() )
       
   477                         {
       
   478                         task.KillTask();
       
   479                         }
       
   480                     SendMessageL( EOk );
       
   481                     }
       
   482                 else
       
   483                     {
       
   484                     SendMessageL( ENotFound );
       
   485                     }
       
   486                 }
       
   487             else
       
   488                 {
       
   489                 SendErrorMsg( offset , KErrDescrInvalidArguments );
       
   490                 }
       
   491             }
       
   492             break;
       
   493         case EStopApp_uid:
       
   494             {
       
   495             TPtrC8 appUid8 = aMessage.Mid( 1 );
       
   496             if ( appUid8.Length() == 4 )
       
   497                 {
       
   498                 TApaTaskList tl( iWs );
       
   499                 TInt32 appUid = Parse32<TInt32>( appUid8 );
       
   500                 TApaTask task = tl.FindApp( TUid::Uid( appUid ) );
       
   501                 if ( task.Exists() )
       
   502                     {
       
   503                     task.EndTask();
       
   504                     User::After(KCloseTaskDelay);
       
   505                     TApaTask task = tl.FindApp( TUid::Uid( appUid ) );
       
   506                     if ( task.Exists() )
       
   507                         {
       
   508                         task.KillTask();
       
   509                         }
       
   510                     SendMessageL( EOk );
       
   511                     }
       
   512                 else
       
   513                     {
       
   514                     SendMessageL( ENotFound );
       
   515                     }
       
   516                 }
       
   517             else
       
   518                 {
       
   519                 SendErrorMsg( KErrArgument , KErrDescrInvalidUid );
       
   520                 }
       
   521             }
       
   522             break;
       
   523         case EListApps:
       
   524         case EListApps_u:
       
   525             {
       
   526             if ( aMessage.Length() != 3 )
       
   527                 {
       
   528                 SendErrorMsg( KErrArgument, KErrDescrInvalidArguments );
       
   529                 }
       
   530             else
       
   531                 {
       
   532                 HandleListAppsL( aMessage[1], aMessage[2], unicode );
       
   533                 }
       
   534             }
       
   535             break;
       
   536         case EListInstalledApps:
       
   537         case EListInstalledApps_u:
       
   538             {
       
   539             if ( aMessage.Length() != 1 )
       
   540                 {
       
   541                 SendErrorMsg( KErrArgument, KErrDescrInvalidArguments );
       
   542                 }
       
   543             else
       
   544                 {
       
   545                 HandleListInstalledAppsL( unicode );
       
   546                 }
       
   547             }
       
   548             break;
       
   549         default:
       
   550             {
       
   551             SendErrorMsg( KErrArgument, KErrDescrInvalidCmd );
       
   552             }
       
   553         }
       
   554 
       
   555     HTI_LOG_FUNC_OUT("CHtiAppControl::HandleAppControl");
       
   556     }
       
   557 
       
   558 void CHtiAppControl::HandleInstallerControlL( const TDesC8& aMessage )
       
   559     {
       
   560     HTI_LOG_FUNC_IN( "CHtiAppControl::HandleInstallerControlL" );
       
   561 
       
   562     if ( aMessage.Length() < 2 )
       
   563         {
       
   564         HTI_LOG_TEXT( "Command parameters missing" );
       
   565         SendErrorMsg( KErrArgument , KErrDescrInvalidCmd );
       
   566         return;
       
   567         }
       
   568 
       
   569     TBool unicode = aMessage[0] & KUnicodeMask;
       
   570     HTI_LOG_FORMAT( "Unicode flag: %d", unicode );
       
   571 
       
   572     TFileName path;
       
   573     TBuf<SwiUI::KSWInstMaxPasswordLength> login;
       
   574     TBuf<SwiUI::KSWInstMaxPasswordLength> password;
       
   575 
       
   576     switch ( aMessage[0] )
       
   577         {
       
   578         case EInstall:
       
   579         case EInstall_u:
       
   580             {
       
   581             TPtrC8 parameters = aMessage.Mid( 1 );
       
   582             if ( ValidateInstallParams( parameters, unicode ) )
       
   583                 {
       
   584                 TInt offset = ParseString( parameters, 0, unicode, path );
       
   585 
       
   586                 HTI_LOG_TEXT( "Parsed path to install package:" );
       
   587                 HTI_LOG_DES( path )
       
   588 
       
   589                 if ( offset >= 0)
       
   590                     {
       
   591                     iInstOpts = SwiUI::TInstallOptions();
       
   592 
       
   593                     iInstOpts.iUpgrade =            ConvertToPolicy( parameters[offset] ); offset++;
       
   594                     iInstOpts.iOptionalItems =      ConvertToPolicy( parameters[offset] ); offset++;
       
   595                     iInstOpts.iOCSP =               ConvertToPolicy( parameters[offset] ); offset++;
       
   596                     iInstOpts.iIgnoreOCSPWarnings = ConvertToPolicy( parameters[offset] ); offset++;
       
   597                     iInstOpts.iUntrusted =          ConvertToPolicy( parameters[offset] ); offset++;
       
   598                     iInstOpts.iPackageInfo =        ConvertToPolicy( parameters[offset] ); offset++;
       
   599                     iInstOpts.iCapabilities =       ConvertToPolicy( parameters[offset] ); offset++;
       
   600                     iInstOpts.iKillApp =            ConvertToPolicy( parameters[offset] ); offset++;
       
   601                     iInstOpts.iOverwrite =          ConvertToPolicy( parameters[offset] ); offset++;
       
   602                     iInstOpts.iDownload =           ConvertToPolicy( parameters[offset] ); offset++;
       
   603 
       
   604                     HTI_LOG_FORMAT( "iUpgrade: %d",            iInstOpts.iUpgrade );
       
   605                     HTI_LOG_FORMAT( "iOptionalItems: %d",      iInstOpts.iOptionalItems );
       
   606                     HTI_LOG_FORMAT( "iOCSP: %d",               iInstOpts.iOCSP );
       
   607                     HTI_LOG_FORMAT( "iIgnoreOCSPWarnings: %d", iInstOpts.iIgnoreOCSPWarnings );
       
   608                     HTI_LOG_FORMAT( "iUntrusted: %d",          iInstOpts.iUntrusted );
       
   609                     HTI_LOG_FORMAT( "iPackageInfo: %d",        iInstOpts.iPackageInfo );
       
   610                     HTI_LOG_FORMAT( "iCapabilities: %d",       iInstOpts.iCapabilities );
       
   611                     HTI_LOG_FORMAT( "iKillApp: %d",            iInstOpts.iKillApp );
       
   612                     HTI_LOG_FORMAT( "iOverwrite: %d",          iInstOpts.iOverwrite );
       
   613                     HTI_LOG_FORMAT( "iDownload: %d",           iInstOpts.iDownload );
       
   614 
       
   615                     offset = ParseString( parameters, offset, unicode, login );
       
   616                     iInstOpts.iLogin.Copy( login );
       
   617                     HTI_LOG_TEXT( "Parsed login:" );
       
   618                     HTI_LOG_DES( login )
       
   619 
       
   620                     offset = ParseString( parameters, offset, unicode, password );
       
   621                     iInstOpts.iPassword.Copy( password );
       
   622                     HTI_LOG_TEXT( "Parsed password:" );
       
   623                     HTI_LOG_DES( password )
       
   624 
       
   625                     iInstOpts.iDrive =        (TChar) parameters[offset]; offset++;
       
   626                     iInstOpts.iLang =         (TLanguage) parameters[offset]; offset++;
       
   627                     iInstOpts.iUsePhoneLang = (TBool) parameters[offset]; offset++;
       
   628                     iInstOpts.iUpgradeData =  ConvertToPolicy( parameters[offset] );
       
   629 
       
   630                     HTI_LOG_FORMAT( "iDrive: %c",        iInstOpts.iDrive.GetLowerCase() );
       
   631                     HTI_LOG_FORMAT( "iLang: %d",         iInstOpts.iLang );
       
   632                     HTI_LOG_FORMAT( "iUsePhoneLang: %d", iInstOpts.iUsePhoneLang );
       
   633                     HTI_LOG_FORMAT( "iUpgradeData: %d",  iInstOpts.iUpgradeData );
       
   634 
       
   635                     iInstOptsPckg = iInstOpts;
       
   636 
       
   637                     // Connect to silent installer
       
   638                     SwiUI::RSWInstSilentLauncher launcher;
       
   639                     TInt err = launcher.Connect();
       
   640                     if ( err )
       
   641                         {
       
   642                         HTI_LOG_FORMAT( "Error connecting to silent installer, err: %d", err );
       
   643                         SendErrorMsg( err , KErrDescrFailedConnectSilentInstaller );
       
   644                         break;
       
   645                         }
       
   646 
       
   647                     err = launcher.SilentInstall( path, iInstOptsPckg );
       
   648                     if ( err )
       
   649                         {
       
   650                         HTI_LOG_FORMAT( "Error installing software, err: %d", err );
       
   651                         launcher.Close();
       
   652                         SendErrorMsg( err , KErrDescrFailedInstall );
       
   653                         break;
       
   654                         }
       
   655 
       
   656                     launcher.Close();
       
   657                     SendMessageL( EOk );
       
   658                     }
       
   659                 else
       
   660                     {
       
   661                     HTI_LOG_TEXT( "Error parsing path" );
       
   662                     SendErrorMsg( offset , KErrDescrInvalidArguments );
       
   663                     }
       
   664                 }
       
   665             else
       
   666                 {
       
   667                 SendErrorMsg( KErrArgument, KErrDescrInvalidCmd );
       
   668                 }
       
   669             }
       
   670             break;
       
   671 
       
   672         case EUnInstall:
       
   673         case EUnInstallName:
       
   674         case EUnInstallName_u:
       
   675             {
       
   676             TPtrC8 parameters = aMessage.Mid( 1 );
       
   677             if ( ( aMessage[0] == EUnInstall && parameters.Length() != 7 ) ||
       
   678                  ( aMessage[0] == EUnInstallName &&
       
   679                    parameters.Length() != parameters[0] + 4 ) ||
       
   680                  ( aMessage[0] == EUnInstallName_u &&
       
   681                    parameters.Length() != parameters[0] * 2 + 4 ) )
       
   682                 {
       
   683                 HTI_LOG_FORMAT( "Invalid command length: %d",
       
   684                     parameters.Length() );
       
   685                 SendErrorMsg( KErrArgument, KErrDescrInvalidCmd );
       
   686                 break;
       
   687                 }
       
   688 
       
   689             TInt offset = 0;
       
   690             TInt32 uid = KErrNotFound;
       
   691             HBufC* packageName = NULL;
       
   692             if ( aMessage[0] == EUnInstall )
       
   693                 {
       
   694                 uid = Parse32<TInt32>( parameters );
       
   695                 offset += 4;
       
   696                 HTI_LOG_FORMAT( "Uninstall by uid: %d", uid );
       
   697                 }
       
   698             else
       
   699                 {
       
   700                 packageName = HBufC::NewLC( parameters[offset] );
       
   701                 TPtr namePtr = packageName->Des();
       
   702                 offset = ParseString( parameters, offset, unicode, namePtr );
       
   703                 HTI_LOG_FORMAT( "Uninstall by name: %S", packageName );
       
   704                 }
       
   705             iUnInstOpts = SwiUI::TUninstallOptions();
       
   706             iUnInstOpts.iKillApp = ConvertToPolicy( parameters[offset] );
       
   707             offset++;
       
   708             iUnInstOpts.iBreakDependency = ConvertToPolicy( parameters[offset] );
       
   709             offset++;
       
   710             HTI_LOG_FORMAT( "iKillApp: %d",         iUnInstOpts.iKillApp );
       
   711             HTI_LOG_FORMAT( "iBreakDependency: %d", iUnInstOpts.iBreakDependency );
       
   712 
       
   713             TInt mimeIndex = parameters[offset];
       
   714             if ( mimeIndex > iMimeTypes->Count() - 1 )
       
   715                 {
       
   716                 HTI_LOG_FORMAT( "Invalid mime type: %d", mimeIndex );
       
   717                 SendErrorMsg( KErrArgument, KErrDescrInvalidCmd );
       
   718                 break;
       
   719                 }
       
   720 
       
   721             HTI_LOG_TEXT( "Uninstall mime type:" );
       
   722             HTI_LOG_DES( (*iMimeTypes)[mimeIndex] );
       
   723 
       
   724             TInt err = KErrNone;
       
   725             iAugmentationIndex = 0;
       
   726             if ( packageName )
       
   727                 {
       
   728                 TRAP( err, uid = GetPackageUidL( *packageName, mimeIndex ) );
       
   729                 CleanupStack::PopAndDestroy(); // packageName
       
   730                 iAugmentations.ResetAndDestroy();
       
   731                 if ( err != KErrNone )
       
   732                     {
       
   733                     SendErrorMsg( err, KErrDescrFailedFindPackage );
       
   734                     break;
       
   735                     }
       
   736                 }
       
   737             HTI_LOG_FORMAT( "UID = %d", uid );
       
   738 
       
   739             iUnInstOptsPckg = iUnInstOpts;
       
   740 
       
   741             // Connect to silent installer
       
   742             SwiUI::RSWInstSilentLauncher launcher;
       
   743             err = launcher.Connect();
       
   744             if ( err )
       
   745                 {
       
   746                 HTI_LOG_FORMAT( "Error connecting to silent installer, err: %d", err );
       
   747                 SendErrorMsg( err , KErrDescrFailedConnectSilentInstaller );
       
   748                 break;
       
   749                 }
       
   750 
       
   751             if ( iAugmentationIndex > 0 )
       
   752                 {
       
   753                 SwiUI::TOpUninstallIndexParam params;
       
   754                 params.iUid = TUid::Uid( uid );
       
   755                 params.iIndex = iAugmentationIndex;
       
   756                 SwiUI::TOpUninstallIndexParamPckg paramPckg( params );
       
   757                 SwiUI::TOperation operation( SwiUI::EOperationUninstallIndex );
       
   758                 err = launcher.SilentCustomUninstall( operation, iUnInstOptsPckg,
       
   759                     paramPckg, (*iMimeTypes)[mimeIndex] );
       
   760                 }
       
   761             else
       
   762                 {
       
   763                 err = launcher.SilentUninstall( TUid::Uid( uid ), iUnInstOptsPckg,
       
   764                         (*iMimeTypes)[mimeIndex] );
       
   765                 }
       
   766 
       
   767             if ( err )
       
   768                 {
       
   769                 HTI_LOG_FORMAT( "Error uninstalling software, err: %d", err );
       
   770                 launcher.Close();
       
   771                 SendErrorMsg( err , KErrDescrFailedUnInstall );
       
   772                 break;
       
   773                 }
       
   774 
       
   775             launcher.Close();
       
   776             SendMessageL( EOk );
       
   777             }
       
   778             break;
       
   779 
       
   780         default:
       
   781             {
       
   782             SendErrorMsg( KErrArgument, KErrDescrInvalidCmd );
       
   783             }
       
   784         }
       
   785 
       
   786     HTI_LOG_FUNC_OUT( "CHtiAppControl::HandleInstallerControlL" );
       
   787     }
       
   788 
       
   789 
       
   790 void CHtiAppControl::HandleStartProcessL( const TDesC& aProgramName,
       
   791                                                 const TDesC& aCmdLine,
       
   792                                                 TBool aStoreProcessHandle )
       
   793     {
       
   794     HTI_LOG_FUNC_IN( "CHtiAppControl::HandleStartProcessL" );
       
   795     HTI_LOG_FORMAT( "progr name %d", aProgramName.Length() );
       
   796     HTI_LOG_DES( aProgramName );
       
   797 
       
   798     RProcess process;
       
   799     TInt err = process.Create( aProgramName, aCmdLine ); // command parameters
       
   800 
       
   801     if ( err == KErrNone )
       
   802         {
       
   803         CleanupClosePushL( process );
       
   804 
       
   805         //convert process id to binary des
       
   806         TUint processId = process.Id();
       
   807         HTI_LOG_FORMAT( "process id %d", processId );
       
   808 
       
   809         TBuf8<KTUintLength> processIdDes;
       
   810         processIdDes.Append(
       
   811                 ( TUint8* )( &processId ), KTUintLength );
       
   812 
       
   813         SendMessageL( EOk, processIdDes );
       
   814 
       
   815         process.Resume();
       
   816 
       
   817         if ( aStoreProcessHandle )
       
   818             {
       
   819             HTI_LOG_TEXT( "Storing the process handle" );
       
   820             iProcessHandleArray.Append( process );
       
   821             CleanupStack::Pop();
       
   822             }
       
   823         else
       
   824             {
       
   825             CleanupStack::PopAndDestroy();
       
   826             }
       
   827         }
       
   828     else if ( err == KErrNotFound )
       
   829         {
       
   830         SendMessageL( ENotFound );
       
   831         }
       
   832     else
       
   833         {
       
   834         SendErrorMsg( err ,KErrDescrFailedCreateProcess );
       
   835         }
       
   836 
       
   837     HTI_LOG_FUNC_OUT( "CHtiAppControl::HandleStartProcessL" );
       
   838     }
       
   839 
       
   840 void CHtiAppControl::HandleStopProcessL( RProcess& aProcess )
       
   841     {
       
   842     if ( aProcess.ExitType() == EExitPending )
       
   843         {
       
   844         aProcess.Kill( KTerminateReason );
       
   845         SendMessageL( EOk );
       
   846         }
       
   847     else
       
   848         {
       
   849         SendMessageL( EAlreadyStopped );
       
   850         }
       
   851     }
       
   852 
       
   853 void CHtiAppControl::HandleStatusProcessL( RProcess& aProcess )
       
   854     {
       
   855     TExitType exT = aProcess.ExitType();
       
   856 
       
   857     switch ( exT )
       
   858         {
       
   859         case EExitPending:
       
   860             {
       
   861             SendMessageL( ERunning );
       
   862             }
       
   863             break;
       
   864         case EExitKill:
       
   865         case EExitTerminate:
       
   866             {
       
   867             SendMessageL( EKilled );
       
   868             }
       
   869             break;
       
   870         case EExitPanic:
       
   871             {
       
   872             SendMessageL( EPanic );
       
   873             }
       
   874             break;
       
   875         };
       
   876     }
       
   877 
       
   878 
       
   879 void CHtiAppControl::HandleListProcessesL( const TDesC& aMatch )
       
   880     {
       
   881     HTI_LOG_FUNC_IN( "CHtiAppControl::HandleListProcessesL" );
       
   882 
       
   883     RProcess process;
       
   884     TFullName processName;
       
   885     TUint processId;
       
   886     TBuf8<KTUintLength> processIdDes;
       
   887     TExitType exitType;
       
   888 
       
   889     TBuf8<128> buf;
       
   890     CBufFlat* processListBuf = NULL;
       
   891     TRAPD( err, processListBuf = CBufFlat::NewL( 128 ) );
       
   892     if ( err )
       
   893         {
       
   894         SendErrorMsg( err ,KErrDescrNoMemory );
       
   895         return;
       
   896         }
       
   897 
       
   898     CleanupStack::PushL( processListBuf );
       
   899 
       
   900     // The default match pattern is the single character *
       
   901     TFindProcess finder;
       
   902 
       
   903     // if some real match pattern is defined, use it
       
   904     if ( aMatch.Length() > 0 )
       
   905         {
       
   906         HTI_LOG_TEXT( "Match pattern was given:" );
       
   907         HTI_LOG_DES( aMatch );
       
   908         finder.Find( aMatch );
       
   909         }
       
   910 
       
   911     TInt pos = 0;
       
   912     TUint numberOfEntries = 0;
       
   913 
       
   914     while ( finder.Next( processName ) == KErrNone )
       
   915         {
       
   916         err = process.Open( finder );
       
   917 
       
   918         //convert process id to binary des
       
   919         processId = process.Id();
       
   920         processIdDes.Append( ( TUint8* ) ( &processId ), KTUintLength );
       
   921         buf.Append( processIdDes );
       
   922 
       
   923         // status
       
   924         exitType = process.ExitType();
       
   925         switch ( exitType )
       
   926             {
       
   927             case EExitPending:
       
   928                 {
       
   929                 buf.Append( ERunning );
       
   930                 }
       
   931                 break;
       
   932             case EExitKill:
       
   933             case EExitTerminate:
       
   934                 {
       
   935                 buf.Append( EKilled );
       
   936                 }
       
   937                 break;
       
   938             case EExitPanic:
       
   939                 {
       
   940                 buf.Append( EPanic );
       
   941                 }
       
   942                 break;
       
   943             };
       
   944 
       
   945         // name length
       
   946         buf.Append( processName.Length() );
       
   947 
       
   948         // name
       
   949         buf.Append( processName );
       
   950 
       
   951         process.Close();
       
   952 
       
   953         TRAP( err, processListBuf->ExpandL( pos, buf.Length() ) );
       
   954         if ( err )
       
   955             {
       
   956             SendErrorMsg( err , KErrDescrNoMemory );
       
   957             delete processListBuf;
       
   958             return;
       
   959             }
       
   960         processListBuf->Write( pos, buf, buf.Length() );
       
   961 
       
   962         pos += buf.Length();
       
   963         buf.Zero();
       
   964         processIdDes.Zero();
       
   965         numberOfEntries++;
       
   966         }
       
   967 
       
   968     // insert the number of entries in the beginning
       
   969     TBuf8<2> entries;
       
   970     entries.Append( ( TUint8* ) ( &numberOfEntries ), 2 );
       
   971     processListBuf->ExpandL( 0, 2 );
       
   972     processListBuf->Write( 0, entries, 2 );
       
   973 
       
   974     SendMessageL( EOk, processListBuf->Ptr( 0 ) );
       
   975 
       
   976     CleanupStack::PopAndDestroy( processListBuf );
       
   977 
       
   978     HTI_LOG_FUNC_OUT( "CHtiAppControl::HandleListProcessesL" );
       
   979     }
       
   980 
       
   981 
       
   982 void CHtiAppControl::HandleStartAppL( TApaAppInfo &aAppInfo,
       
   983                                             const TDesC& aDocName )
       
   984     {
       
   985     HTI_LOG_FUNC_IN( "CHtiAppControl::HandleStartAppL" );
       
   986 
       
   987     // Check if app is running as a root app (not embedded)
       
   988     TApaTask task = FindRunningRootApp( aAppInfo.iUid );
       
   989     if ( task.Exists() )
       
   990         {
       
   991         User::ResetInactivityTime();
       
   992         task.BringToForeground();
       
   993         SendMessageL( EAlreadyRunning );
       
   994         }
       
   995     else
       
   996         {
       
   997         TThreadId threadId;
       
   998         TInt err = KErrNone;
       
   999         if ( aAppInfo.iUid != TUid::Null() )
       
  1000             {
       
  1001             TApaAppCapabilityBuf capBuf;
       
  1002             err = iAppServer.GetAppCapability( capBuf, aAppInfo.iUid );
       
  1003             TApaAppCapability& caps = capBuf();
       
  1004             CApaCommandLine* cmdLine = CApaCommandLine::NewLC();
       
  1005             cmdLine->SetExecutableNameL( aAppInfo.iFullName );
       
  1006             if ( caps.iLaunchInBackground )
       
  1007                 {
       
  1008                 cmdLine->SetCommandL( EApaCommandBackground );
       
  1009                 HTI_LOG_TEXT( "Launching in background" );
       
  1010                 }
       
  1011             else
       
  1012                 {
       
  1013                 if ( aDocName != KNullDesC )
       
  1014                     {
       
  1015                     cmdLine->SetCommandL( EApaCommandOpen );
       
  1016                     cmdLine->SetDocumentNameL( aDocName );
       
  1017                     HTI_LOG_TEXT( "Launching with document" );
       
  1018                     }
       
  1019                 else
       
  1020                     {
       
  1021                     cmdLine->SetCommandL( EApaCommandRun );
       
  1022                     HTI_LOG_TEXT( "Launching without document" );
       
  1023                     }
       
  1024                 }
       
  1025             err = iAppServer.StartApp( *cmdLine, threadId );
       
  1026             CleanupStack::PopAndDestroy( cmdLine );
       
  1027             }
       
  1028         else if ( aDocName != KNullDesC )
       
  1029             {
       
  1030             HTI_LOG_TEXT( "Launching a document" );
       
  1031             /*
       
  1032              * If the app that should handle the doc is already running, we
       
  1033              * try to switch the open file and bring it to foreground. Whether
       
  1034              * switching the file works depends on the application: It must
       
  1035              * implement CEikAppUi::OpenFileL() or CAknAppUi::OpenFileL() in S60.
       
  1036              */
       
  1037             TUid appUid;
       
  1038             TDataType dataType;
       
  1039             err = iAppServer.AppForDocument( aDocName, appUid, dataType );
       
  1040             if ( err == KErrNone )
       
  1041                 {
       
  1042                 TApaTask task = FindRunningRootApp( appUid );
       
  1043                 if ( task.Exists() )
       
  1044                     {
       
  1045                     HTI_LOG_TEXT( "App for doc already running, switch file" );
       
  1046                     err = task.SwitchOpenFile( aDocName );
       
  1047                     task.BringToForeground();
       
  1048                     }
       
  1049                 else
       
  1050                     {
       
  1051                     err = iAppServer.StartDocument( aDocName, threadId );
       
  1052                     }
       
  1053                 }
       
  1054             }
       
  1055         else
       
  1056             {
       
  1057             User::Leave( KErrArgument );
       
  1058             }
       
  1059 
       
  1060         if ( err == KErrNone )
       
  1061             {
       
  1062             User::ResetInactivityTime();
       
  1063             //convert thread id to string
       
  1064             TUint threadIdUint = threadId; //cast to UInt
       
  1065             TBuf8<KTUintLength> threadIdDes;
       
  1066             threadIdDes.Append( ( TUint8* )( &threadIdUint ), KTUintLength );
       
  1067             SendMessageL( EOk, threadIdDes );
       
  1068             }
       
  1069         else if ( err == KErrNotFound )
       
  1070             {
       
  1071             SendMessageL( ENotFound );
       
  1072             }
       
  1073         else
       
  1074             {
       
  1075             SendErrorMsg( err, KErrDescrFailedStartApp );
       
  1076             }
       
  1077         }
       
  1078     HTI_LOG_FUNC_OUT( "CHtiAppControl::HandleStartAppL" );
       
  1079     }
       
  1080 
       
  1081 void CHtiAppControl::HandleListInstalledAppsL( TBool aUnicode )
       
  1082     {
       
  1083     HTI_LOG_FUNC_IN( "CHtiAppControl::HandleListInstalledAppsL" );
       
  1084 
       
  1085     // max file name + max caption + max short caption + 7 constant bytes
       
  1086     TInt bufSize = KMaxFileName + 2 * KApaMaxAppCaption + 7;
       
  1087     if ( aUnicode )
       
  1088         {
       
  1089         bufSize *= 2;
       
  1090         }
       
  1091 
       
  1092     CBufFlat* appListBuf = CBufFlat::NewL( bufSize );
       
  1093     CleanupStack::PushL( appListBuf );
       
  1094 
       
  1095     HBufC8* appsArray = HBufC8::NewLC( bufSize );
       
  1096     TPtr8 appsArrayPtr = appsArray->Des();
       
  1097 
       
  1098     TInt err = KErrNone;
       
  1099     err = iAppServer.GetAllApps();
       
  1100     if ( err != KErrNone )
       
  1101         {
       
  1102         SendErrorMsg( err, KErrDescrFailedListInstApps );
       
  1103         }
       
  1104     else
       
  1105         {
       
  1106         TApaAppInfo appInfo;
       
  1107         TInt pos( 0 );
       
  1108 
       
  1109         // Add application count
       
  1110         TInt numOfEntries = 0;
       
  1111         iAppServer.AppCount( numOfEntries );
       
  1112 
       
  1113         appsArrayPtr.Append( ( TUint8*) ( &numOfEntries ), 2 );
       
  1114 
       
  1115         while ( iAppServer.GetNextApp( appInfo ) == KErrNone )
       
  1116             {
       
  1117             TUint appUidUint = appInfo.iUid.iUid;
       
  1118             appsArrayPtr.Append( ( TUint8* ) &appUidUint, KTUintLength );
       
  1119 
       
  1120             // Add length of full name
       
  1121             appsArrayPtr.Append( appInfo.iFullName.Length() );
       
  1122             // Add full name if there is one
       
  1123             if ( appInfo.iFullName.Length() > 0 )
       
  1124                 {
       
  1125                 if ( aUnicode )
       
  1126                     {
       
  1127                     appsArrayPtr.Append( ( TUint8* ) appInfo.iFullName.Ptr(),
       
  1128                         appInfo.iFullName.Length() * 2 );
       
  1129                     }
       
  1130                 else
       
  1131                     {
       
  1132                     appsArrayPtr.Append( appInfo.iFullName );
       
  1133                     }
       
  1134                 }
       
  1135 
       
  1136             // Add length of caption
       
  1137             appsArrayPtr.Append( appInfo.iCaption.Length() );
       
  1138             // Add caption if there is one
       
  1139             if ( appInfo.iCaption.Length() > 0 )
       
  1140                 {
       
  1141                 if ( aUnicode )
       
  1142                     {
       
  1143                     appsArrayPtr.Append( ( TUint8* ) appInfo.iCaption.Ptr(),
       
  1144                         appInfo.iCaption.Length() * 2 );
       
  1145                     }
       
  1146                 else
       
  1147                     {
       
  1148                     appsArrayPtr.Append( appInfo.iCaption );
       
  1149                     }
       
  1150                 }
       
  1151 
       
  1152             // Add length of short caption
       
  1153             appsArrayPtr.Append( appInfo.iShortCaption.Length() );
       
  1154             // Add short caption if there is one
       
  1155             if ( appInfo.iShortCaption.Length() > 0 )
       
  1156                 {
       
  1157                 if ( aUnicode )
       
  1158                     {
       
  1159                     appsArrayPtr.Append( ( TUint8* ) appInfo.iShortCaption.Ptr(),
       
  1160                         appInfo.iCaption.Length() * 2 );
       
  1161                     }
       
  1162                 else
       
  1163                     {
       
  1164                     appsArrayPtr.Append( appInfo.iShortCaption );
       
  1165                     }
       
  1166                 }
       
  1167 
       
  1168             // Add app info to response buffer
       
  1169             appListBuf->ExpandL( pos, appsArray->Length() );
       
  1170             appListBuf->Write( pos, *appsArray, appsArray->Length() );
       
  1171 
       
  1172             pos += appsArray->Length();
       
  1173             appsArrayPtr.Zero();
       
  1174             }
       
  1175 
       
  1176         SendMessageL( EOk, appListBuf->Ptr( 0 ) );
       
  1177         }
       
  1178 
       
  1179     CleanupStack::PopAndDestroy( 2 ); //appListBuf, appsArray
       
  1180 
       
  1181     HTI_LOG_FUNC_IN( "CHtiAppControl::HandleListInstalledAppsL" );
       
  1182     }
       
  1183 
       
  1184 void CHtiAppControl::HandleListAppsL( TBool aIncludeHidden,
       
  1185                                             TBool aIncludeSystem,
       
  1186                                             TBool aUnicode )
       
  1187     {
       
  1188     HTI_LOG_FUNC_IN( "CHtiAppControl::HandleListAppsL" );
       
  1189 
       
  1190     RArray<RWsSession::TWindowGroupChainInfo>* wgChain = new ( ELeave )
       
  1191                             RArray<RWsSession::TWindowGroupChainInfo>( 12 );
       
  1192     CleanupDeletePushL( wgChain );
       
  1193     CleanupClosePushL( *wgChain );
       
  1194     User::LeaveIfError( iWs.WindowGroupList( 0, wgChain ) );
       
  1195     TInt wgCount = wgChain->Count();
       
  1196 
       
  1197     HTI_LOG_FORMAT( "%d Window Groups in the chain", wgCount );
       
  1198 
       
  1199     TInt bufSize = 2 * KMaxFileName + 11; // caption & document + 11 constant bytes
       
  1200     if ( aUnicode )
       
  1201         {
       
  1202         bufSize *= 2;
       
  1203         }
       
  1204     CBufFlat* appListBuf = CBufFlat::NewL( bufSize );
       
  1205     CleanupStack::PushL( appListBuf );
       
  1206     HBufC8* buf = HBufC8::NewLC( bufSize );
       
  1207     TPtr8 bufPtr = buf->Des();
       
  1208 
       
  1209     TInt pos = 0;
       
  1210     TInt numOfEntries = 0;
       
  1211 
       
  1212     for ( TInt i = 0; i < wgCount; i++ )
       
  1213         {
       
  1214         const RWsSession::TWindowGroupChainInfo& info = ( *wgChain )[i];
       
  1215         CApaWindowGroupName* wgName = CApaWindowGroupName::NewLC( iWs, info.iId );
       
  1216 
       
  1217         HTI_LOG_FORMAT( "WG ID: %d", info.iId );
       
  1218         HTI_LOG_DES( wgName->WindowGroupName() );
       
  1219 
       
  1220         // Info is returned only from root tasks and system and hidden tasks
       
  1221         // are included only if requested.
       
  1222         if ( info.iParentId <= 0 &&
       
  1223              ( !wgName->IsSystem() || aIncludeSystem ) &&
       
  1224              ( !wgName->Hidden() || aIncludeHidden ) )
       
  1225             {
       
  1226             // Add application UID
       
  1227             TUint appUidUint = wgName->AppUid().iUid;
       
  1228             bufPtr.Append( ( TUint8* ) &appUidUint, KTUintLength );
       
  1229 
       
  1230             // Add caption
       
  1231             TPtrC caption = wgName->Caption();
       
  1232             bufPtr.Append( caption.Length() );
       
  1233             if ( caption.Length() > 0 )
       
  1234                 {
       
  1235                 if ( aUnicode )
       
  1236                     {
       
  1237                     bufPtr.Append(
       
  1238                         ( TUint8* ) caption.Ptr(), caption.Length() * 2 );
       
  1239                     }
       
  1240                 else
       
  1241                     {
       
  1242                     bufPtr.Append( caption );
       
  1243                     }
       
  1244                 }
       
  1245 
       
  1246             // Add document name
       
  1247             TPtrC document = wgName->DocName();
       
  1248             bufPtr.Append( document.Length() );
       
  1249             if ( document.Length() > 0 )
       
  1250                 {
       
  1251                 if ( aUnicode )
       
  1252                     {
       
  1253                     bufPtr.Append(
       
  1254                         ( TUint8* ) document.Ptr(), document.Length() * 2 );
       
  1255                     }
       
  1256                 else
       
  1257                     {
       
  1258                     bufPtr.Append( document );
       
  1259                     }
       
  1260                 }
       
  1261 
       
  1262             // Add Hidden flag
       
  1263             if ( wgName->Hidden() )
       
  1264                 bufPtr.Append( 1 );
       
  1265             else
       
  1266                 bufPtr.Append( 0 );
       
  1267 
       
  1268             // Add System flag
       
  1269             if ( wgName->IsSystem() )
       
  1270                 bufPtr.Append( 1 );
       
  1271             else
       
  1272                 bufPtr.Append( 0 );
       
  1273 
       
  1274             // Add Ready flag
       
  1275             if ( wgName->IsAppReady() )
       
  1276                 bufPtr.Append( 1 );
       
  1277             else
       
  1278                 bufPtr.Append( 0 );
       
  1279 
       
  1280             // Add Busy flag
       
  1281             if ( wgName->IsBusy() )
       
  1282                 bufPtr.Append( 1 );
       
  1283             else
       
  1284                 bufPtr.Append( 0 );
       
  1285 
       
  1286             // Add Shutdown response flag
       
  1287             if ( wgName->RespondsToShutdownEvent() )
       
  1288                 bufPtr.Append( 1 );
       
  1289             else
       
  1290                 bufPtr.Append( 0 );
       
  1291 
       
  1292             // Add this task's info to response buffer
       
  1293             appListBuf->ExpandL( pos, buf->Length() );
       
  1294             appListBuf->Write( pos, *buf, buf->Length() );
       
  1295 
       
  1296             pos += buf->Length();
       
  1297             bufPtr.Zero();
       
  1298             numOfEntries++;
       
  1299             } // if
       
  1300         CleanupStack::PopAndDestroy(); // wgName
       
  1301         } // for
       
  1302 
       
  1303     CleanupStack::PopAndDestroy(); // buf
       
  1304 
       
  1305     // Add number of entries to the beginning of the response
       
  1306     TBuf8<2> entries;
       
  1307     entries.Append( ( TUint8* ) ( &numOfEntries ), 2 );
       
  1308     appListBuf->ExpandL( 0, 2 );
       
  1309     appListBuf->Write( 0, entries, 2 );
       
  1310 
       
  1311     SendMessageL( EOk, appListBuf->Ptr( 0 ) );
       
  1312 
       
  1313     CleanupStack::PopAndDestroy( 3 ); // appListBuf, wgChain Close, wgChain delete
       
  1314 
       
  1315     HTI_LOG_FUNC_OUT( "CHtiAppControl::HandleListAppsL" );
       
  1316     }
       
  1317 
       
  1318 TBool CHtiAppControl::FindAppL( TApaAppInfo& aAppInfo,
       
  1319                                     const TDesC& aAppFullName )
       
  1320     {
       
  1321     HTI_LOG_FUNC_IN( "CHtiAppControl::FindAppL name" );
       
  1322     TInt err = KErrNone;
       
  1323     err = iAppServer.GetAllApps();
       
  1324     if ( err != KErrNone )
       
  1325         {
       
  1326         SendErrorMsg( err, KErrDescrFailedFindApp );
       
  1327         return EFalse;
       
  1328         }
       
  1329 
       
  1330     TParse toFind;
       
  1331     err = toFind.SetNoWild( aAppFullName, NULL, NULL );
       
  1332     if ( err != KErrNone )
       
  1333         {
       
  1334         SendErrorMsg( err, KErrDescrFailedFindApp );
       
  1335         return EFalse;
       
  1336         }
       
  1337 
       
  1338     TBool isFullName = ( toFind.DrivePresent() && toFind.PathPresent() );
       
  1339 
       
  1340     while ( ( err = iAppServer.GetNextApp( aAppInfo) ) == KErrNone )
       
  1341         {
       
  1342         if ( isFullName )  // assume that full path has been given
       
  1343             {
       
  1344             if ( !aAppFullName.CompareF( aAppInfo.iFullName )  )
       
  1345                 {
       
  1346                 return ETrue;
       
  1347                 }
       
  1348             }
       
  1349         else // assume that only filename has been given
       
  1350             {
       
  1351             TParsePtrC current( aAppInfo.iFullName );
       
  1352 
       
  1353             // does the given filename contain extension
       
  1354             if ( toFind.ExtPresent() )
       
  1355                 {
       
  1356                 // compare with filename + extension
       
  1357                 if ( !toFind.NameAndExt().CompareF( current.NameAndExt() ) )
       
  1358                     {
       
  1359                     return ETrue;
       
  1360                     }
       
  1361                 }
       
  1362             else
       
  1363                 {
       
  1364                 // compare with filename only
       
  1365                 if ( !toFind.Name().CompareF( current.Name() ) )
       
  1366                     {
       
  1367                     return ETrue;
       
  1368                     }
       
  1369                 // Try to match the caption.
       
  1370                 // For Java MIDlets the full name is like C:\270194328.fakeapp
       
  1371                 // so we have to use caption to find MIDlets.
       
  1372                 if ( !toFind.Name().CompareF( aAppInfo.iCaption ) )
       
  1373                     {
       
  1374                     return ETrue;
       
  1375                     }
       
  1376                 }
       
  1377             }
       
  1378         }
       
  1379 
       
  1380     if ( err == RApaLsSession::ENoMoreAppsInList )
       
  1381         {
       
  1382         SendMessageL( ENotFound );
       
  1383         }
       
  1384     else if ( err != KErrNone )
       
  1385         {
       
  1386         SendErrorMsg( err,KErrDescrFailedFindApp );
       
  1387         }
       
  1388     HTI_LOG_FUNC_OUT( "CHtiAppControl::FindAppL name" );
       
  1389     return EFalse;
       
  1390     }
       
  1391 
       
  1392 TBool CHtiAppControl::FindAppL( TApaAppInfo &aAppInfo,
       
  1393                                      const TInt32 aUid )
       
  1394     {
       
  1395     HTI_LOG_FUNC_IN( "CHtiAppControl::FindAppL uid" );
       
  1396     TInt err = iAppServer.GetAppInfo( aAppInfo, TUid::Uid( aUid ) );
       
  1397     if ( err == KErrNone )
       
  1398         {
       
  1399         return ETrue;
       
  1400         }
       
  1401     else if ( err == KErrNotFound )
       
  1402         {
       
  1403         SendMessageL( ENotFound );
       
  1404         }
       
  1405     else
       
  1406         {
       
  1407         SendErrorMsg( err , KErrDescrFailedFindApp );
       
  1408         }
       
  1409     HTI_LOG_FUNC_OUT( "CHtiAppControl::FindAppL uid" );
       
  1410     return EFalse;
       
  1411     }
       
  1412 
       
  1413 TApaTask CHtiAppControl::FindRunningRootApp( TUid aAppUid )
       
  1414     {
       
  1415     HTI_LOG_FUNC_IN( "CHtiAppControl::FindRunningRootApp" );
       
  1416     TApaTask task( iWs );
       
  1417     task.SetWgId( 0 ); // initialize to empty task
       
  1418 
       
  1419     TInt wgId = 0; // on first call to FindByAppUid wgId must be zero
       
  1420     CApaWindowGroupName::FindByAppUid( aAppUid, iWs, wgId );
       
  1421     HTI_LOG_FORMAT( "FindByAppUid returned WG ID: %d", wgId );
       
  1422 
       
  1423     RArray<RWsSession::TWindowGroupChainInfo> wgs;
       
  1424     TInt err = KErrNone;
       
  1425     TInt wgCount = 0;
       
  1426     if ( wgId != KErrNotFound )
       
  1427         {
       
  1428         // Get a list of Window Group Chain Infos
       
  1429         err = iWs.WindowGroupList( 0, &wgs ); // get only priority 0 WGs
       
  1430         wgCount = wgs.Count();
       
  1431         HTI_LOG_FORMAT( "WindowGroupList returned %d WGs", wgCount );
       
  1432         }
       
  1433     while ( wgId != KErrNotFound && task.WgId() == 0 && err == KErrNone )
       
  1434         {
       
  1435         // App was found - check if it is root by looping through the
       
  1436         // WG chain infos to find the one with out wgId
       
  1437         TInt i = 0;
       
  1438         while ( task.WgId() == 0 && i < wgCount )
       
  1439             {
       
  1440             const RWsSession::TWindowGroupChainInfo& info = wgs[i];
       
  1441             if ( info.iId == wgId && info.iParentId <= 0 )
       
  1442                 {
       
  1443                 // This is the one and it is root (does not have parent)
       
  1444                 task.SetWgId( wgId );
       
  1445                 }
       
  1446             i++;
       
  1447             }
       
  1448         if ( task.WgId() == 0 )
       
  1449             {
       
  1450             // This was not root - check if there's more instances of the app
       
  1451             CApaWindowGroupName::FindByAppUid( aAppUid, iWs, wgId );
       
  1452             HTI_LOG_FORMAT( "FindByAppUid returned WG ID: %d", wgId );
       
  1453             }
       
  1454         }
       
  1455 
       
  1456     wgs.Close();
       
  1457     HTI_LOG_FORMAT( "Returning task with WG ID %d", task.WgId() );
       
  1458     HTI_LOG_FUNC_OUT( "CHtiAppControl::FindRunningRootApp" );
       
  1459     return task;
       
  1460     }
       
  1461 
       
  1462 TInt CHtiAppControl::OpenProcessL( RProcess& aProcess,
       
  1463                                          const TDesC& aMatch )
       
  1464     {
       
  1465     HTI_LOG_FUNC_IN( "CHtiAppControl::OpenProcessL" );
       
  1466     TFullName processName;
       
  1467     TInt err = KErrNone;
       
  1468     TFindProcess finder( aMatch );
       
  1469 
       
  1470     err = finder.Next( processName );
       
  1471     if ( err == KErrNone )
       
  1472         {
       
  1473         err = aProcess.Open( finder );
       
  1474         }
       
  1475 
       
  1476     HTI_LOG_FUNC_OUT( "CHtiAppControl::OpenProcessL" );
       
  1477     return err;
       
  1478     }
       
  1479 
       
  1480 template<class T> T CHtiAppControl::Parse32(
       
  1481                         const TDesC8& a32int )
       
  1482     {
       
  1483     //manually construct TUint or TInt32
       
  1484     return T( a32int[0] + ( a32int[1] << 8 ) +
       
  1485                       ( a32int[2] << 16) + ( a32int[3] << 24) );
       
  1486     }
       
  1487 
       
  1488 void CHtiAppControl::SendMessageL( TAppCommand aResponseCode,
       
  1489                                          const TDesC8& aMsg )
       
  1490     {
       
  1491     HTI_LOG_FORMAT( "SendMessage %d", aResponseCode );
       
  1492     HTI_LOG_FORMAT( "Message len %d", aMsg.Length() );
       
  1493     HBufC8* sendMsg = HBufC8::NewL( 1 + aMsg.Length() );
       
  1494     CleanupStack::PushL( sendMsg );
       
  1495     sendMsg->Des().Append( aResponseCode );
       
  1496     sendMsg->Des().Append( aMsg );
       
  1497 
       
  1498     User::LeaveIfError( iDispatcher->DispatchOutgoingMessage(
       
  1499                             sendMsg,
       
  1500                             KAppServiceUid ) );
       
  1501     CleanupStack::Pop();
       
  1502     }
       
  1503 
       
  1504 inline TInt CHtiAppControl::SendErrorMsg( TInt anError,
       
  1505                                                 const TDesC8& aMsg )
       
  1506     {
       
  1507     return iDispatcher->DispatchOutgoingErrorMessage( anError,
       
  1508                                                aMsg,
       
  1509                                                KAppServiceUid );
       
  1510     }
       
  1511 
       
  1512 SwiUI::TPolicy CHtiAppControl::ConvertToPolicy( const TInt8 aValue )
       
  1513     {
       
  1514     if ( aValue == 0 ) return SwiUI::EPolicyNotAllowed;
       
  1515 
       
  1516     return  SwiUI::EPolicyAllowed;
       
  1517     }
       
  1518 
       
  1519 TBool CHtiAppControl::ValidateInstallParams( const TDesC8& aParams, TBool aIsUnicode )
       
  1520     {
       
  1521     if ( aParams.Length() > 0 )
       
  1522         {
       
  1523         TInt offset = 0;
       
  1524         TInt length = aParams[offset]; // inst package path length;
       
  1525         if ( aIsUnicode ) length *= 2;
       
  1526         offset++;
       
  1527         if ( aParams.Length() < offset + length )
       
  1528             {
       
  1529             HTI_LOG_TEXT( "ValidateInstallParams: Failed, data missing in inst pkg path" );
       
  1530             return EFalse;
       
  1531             }
       
  1532 
       
  1533         offset += length; // skip over inst package path
       
  1534         offset += 10;     // skip over the following one byte params
       
  1535 
       
  1536         if ( aParams.Length() < offset )
       
  1537             {
       
  1538             HTI_LOG_TEXT( "ValidateInstallParams: Failed, data missing in one byte params" );
       
  1539             return EFalse;
       
  1540             }
       
  1541 
       
  1542         length = aParams[offset]; // login username length;
       
  1543         if ( aIsUnicode ) length *= 2;
       
  1544         offset++;
       
  1545         if ( aParams.Length() < offset + length )
       
  1546             {
       
  1547             HTI_LOG_TEXT( "ValidateInstallParams: Failed, data missing in username" );
       
  1548             return EFalse;
       
  1549             }
       
  1550 
       
  1551         offset += length; // skip over login username
       
  1552 
       
  1553         length = aParams[offset]; // password length;
       
  1554         if ( aIsUnicode ) length *= 2;
       
  1555         offset++;
       
  1556         if ( aParams.Length() < offset + length )
       
  1557             {
       
  1558             HTI_LOG_TEXT( "ValidateInstallParams: Failed, data missing in password" );
       
  1559             return EFalse;
       
  1560             }
       
  1561 
       
  1562         offset += length; // skip over password
       
  1563         offset += 4;      // the last one byte params
       
  1564 
       
  1565         if ( aParams.Length() != offset )
       
  1566             {
       
  1567             HTI_LOG_TEXT( "ValidateInstallParams: Failed, final length incorrect" );
       
  1568             return EFalse;
       
  1569             }
       
  1570 
       
  1571         return ETrue;
       
  1572         }
       
  1573 
       
  1574     return EFalse;
       
  1575     }
       
  1576 
       
  1577 TInt CHtiAppControl::GetPackageUidL( const TDesC& aPackageName,
       
  1578                                           TInt aMimeIndex )
       
  1579     {
       
  1580     HTI_LOG_FUNC_IN( "CHtiAppControl::GetPackageUidL" );
       
  1581 
       
  1582     if ( aMimeIndex >= 0 && aMimeIndex < 2 ) // SIS
       
  1583         {
       
  1584         Swi::RSisRegistrySession regSession;
       
  1585         User::LeaveIfError( regSession.Connect() );
       
  1586         CleanupClosePushL( regSession );
       
  1587 
       
  1588         RArray<TUid> uids;
       
  1589         CleanupClosePushL( uids );
       
  1590         regSession.InstalledUidsL( uids );
       
  1591         TInt count = uids.Count();
       
  1592         HTI_LOG_FORMAT( "Found %d SISx installations", count );
       
  1593         for ( TInt i = 0; i < count; i++ )
       
  1594             {
       
  1595             Swi::RSisRegistryEntry entry;
       
  1596             CleanupClosePushL( entry );
       
  1597             User::LeaveIfError( entry.Open( regSession, uids[i] ) );
       
  1598             if ( !entry.IsInRomL() && entry.IsPresentL() )
       
  1599                 {
       
  1600                 if ( aPackageName.Compare( *( entry.PackageNameL() ) ) == 0 )
       
  1601                     {
       
  1602                     HTI_LOG_TEXT( "Matching SIS package found" );
       
  1603                     TInt uid = entry.UidL().iUid;
       
  1604                     CleanupStack::PopAndDestroy( 3 ); // entry, uids, regSession
       
  1605                     return uid;
       
  1606                     }
       
  1607                 }
       
  1608             // Check augmentations of this entry
       
  1609             entry.AugmentationsL( iAugmentations );
       
  1610             TInt augCount = iAugmentations.Count();
       
  1611             for ( TInt j = 0; j < augCount; j++ )
       
  1612                 {
       
  1613                 Swi::RSisRegistryEntry augmentation;
       
  1614                 CleanupClosePushL( augmentation );
       
  1615                 augmentation.OpenL( regSession, *iAugmentations[j] );
       
  1616                 if ( aPackageName.Compare(
       
  1617                         *( augmentation.PackageNameL() ) ) == 0 )
       
  1618                     {
       
  1619                     if ( !augmentation.IsInRomL() && augmentation.IsPresentL() )
       
  1620                         {
       
  1621                         HTI_LOG_TEXT( "Matching SIS augmentation found" );
       
  1622                         TInt uid = augmentation.UidL().iUid;
       
  1623                         Swi::CSisRegistryPackage* pkg = augmentation.PackageL();
       
  1624                         iAugmentationIndex = pkg->Index();
       
  1625                         delete pkg;
       
  1626                         HTI_LOG_FORMAT( "Aug. index %d", iAugmentationIndex );
       
  1627                         CleanupStack::PopAndDestroy( 4 ); // augmentation, entry, uids, regSession
       
  1628                         return uid;
       
  1629                         }
       
  1630                     }
       
  1631                 CleanupStack::PopAndDestroy(); // augmentation
       
  1632                 } // for j
       
  1633             iAugmentations.ResetAndDestroy();
       
  1634             CleanupStack::PopAndDestroy(); // entry
       
  1635             } // for i
       
  1636         User::Leave( KErrNotFound );
       
  1637         }
       
  1638 
       
  1639     else if ( aMimeIndex > 2 && aMimeIndex < 7 ) // Java
       
  1640         {
       
  1641         #if ( SYMBIAN_VERSION_SUPPORT < SYMBIAN_4 )
       
  1642             RArray<TUid> uids;
       
  1643             CleanupClosePushL( uids );
       
  1644 
       
  1645             CJavaRegistry* javaRegistry = CJavaRegistry::NewLC();
       
  1646             javaRegistry->GetRegistryEntryUidsL( uids );
       
  1647 
       
  1648             TInt uid = KErrNotFound;
       
  1649             TInt count = uids.Count();
       
  1650             HTI_LOG_FORMAT( "Found %d Java installations", count );
       
  1651             for ( TInt i = 0; i < count; i++ )
       
  1652                 {
       
  1653                 CJavaRegistryEntry* entry = javaRegistry->RegistryEntryL( uids[i] );
       
  1654                 if ( entry )
       
  1655                     {
       
  1656                     CleanupStack::PushL( entry );
       
  1657                     if ( entry->Type() >= EGeneralPackage &&
       
  1658                             entry->Type() < EGeneralApplication )
       
  1659                         {
       
  1660                         // entry was a package (MIDlet suite)
       
  1661                         CJavaRegistryPackageEntry* packageEntry =
       
  1662                             ( CJavaRegistryPackageEntry* ) entry;
       
  1663                         if ( aPackageName.Compare( packageEntry->Name() ) == 0 )
       
  1664                             {
       
  1665                             HTI_LOG_TEXT( "Matching Java installation found" );
       
  1666                             uid = packageEntry->Uid().iUid;
       
  1667                             CleanupStack::PopAndDestroy( entry );
       
  1668                             break;
       
  1669                             }
       
  1670                         }
       
  1671                     CleanupStack::PopAndDestroy( entry );
       
  1672                     }
       
  1673                 }
       
  1674             CleanupStack::PopAndDestroy( javaRegistry );
       
  1675             CleanupStack::PopAndDestroy( &uids );
       
  1676             User::LeaveIfError( uid );
       
  1677             return uid;
       
  1678         #else
       
  1679             User::Leave( KErrNotSupported );
       
  1680         #endif
       
  1681         }
       
  1682 
       
  1683     else if ( aMimeIndex == 7 ) // Widget
       
  1684         {
       
  1685         RWidgetRegistryClientSession widgetRegistry;
       
  1686         User::LeaveIfError( widgetRegistry.Connect() );
       
  1687 
       
  1688         RWidgetInfoArray widgets;
       
  1689         TRAPD( err, widgetRegistry.InstalledWidgetsL( widgets ) );
       
  1690         if ( err != KErrNone )
       
  1691             {
       
  1692             HTI_LOG_FORMAT( "Failed to get installed widgets %d", err );
       
  1693             widgets.ResetAndDestroy();
       
  1694             widgetRegistry.Disconnect();
       
  1695             User::Leave( err );
       
  1696             }
       
  1697 
       
  1698         TInt uid = KErrNotFound;
       
  1699         TInt count = widgets.Count();
       
  1700         HTI_LOG_FORMAT( "Found %d Widget installations", count );
       
  1701         for ( TInt i = 0; i < count; i++ )
       
  1702             {
       
  1703             CWidgetInfo* widgetInfo = widgets[i];
       
  1704             HTI_LOG_DES( *( widgetInfo->iBundleName ) );
       
  1705             if ( aPackageName.Compare( *( widgetInfo->iBundleName ) ) == 0 )
       
  1706                 {
       
  1707                 HTI_LOG_TEXT( "Matching Widget installation found" );
       
  1708                 uid = widgetInfo->iUid.iUid;
       
  1709                 break;
       
  1710                 }
       
  1711             }
       
  1712         widgets.ResetAndDestroy();
       
  1713         widgetRegistry.Disconnect();
       
  1714         User::LeaveIfError( uid );
       
  1715         return uid;
       
  1716         }
       
  1717 
       
  1718     else  // invalid mime index
       
  1719         {
       
  1720         User::Leave( KErrArgument );
       
  1721         }
       
  1722 
       
  1723     return KErrNone; // never returns from here
       
  1724     }
       
  1725 
       
  1726 
       
  1727 // End of File