applicationmanagement/server/src/AMPreInstallApp.cpp
changeset 42 aa33c2cb9a50
child 62 03849bd79877
equal deleted inserted replaced
41:c742e1129640 42:aa33c2cb9a50
       
     1 /*
       
     2  * Copyright (c) 2000 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: Implementation of applicationmanagement components
       
    15  *
       
    16  */
       
    17 
       
    18 
       
    19 #include <pathinfo.h>
       
    20 #include <driveinfo.h>
       
    21 #include <apmstd.h>  //for KMaxDataTypeLength
       
    22 #include <sisregistrysession.h>
       
    23 #include <sisregistrypackage.h>
       
    24 #include <e32cmn.h> 
       
    25 #include <utf.h>
       
    26 #include <sisregistryentry.h>
       
    27 #include <caf/caf.h>
       
    28 #include <apgcli.h>
       
    29 #include <SWInstDefs.h>
       
    30 
       
    31 #include "AMPreInstallApp.h"
       
    32 #include "debug.h"
       
    33 
       
    34 using namespace NApplicationManagement;
       
    35 CAMPreInstallApp* CAMPreInstallApp::NewL()
       
    36     {
       
    37     CAMPreInstallApp* self = CAMPreInstallApp::NewLC();
       
    38     CleanupStack::Pop(self);
       
    39     return self;
       
    40 
       
    41     }
       
    42 
       
    43 
       
    44 CAMPreInstallApp* CAMPreInstallApp::NewLC()
       
    45     {
       
    46     CAMPreInstallApp *self = new (ELeave) CAMPreInstallApp();
       
    47     CleanupStack::PushL(self);
       
    48     self->ConstructL();
       
    49     return self;
       
    50 
       
    51     }
       
    52 CAMPreInstallApp::CAMPreInstallApp()
       
    53     {
       
    54     }
       
    55 CAMPreInstallApp::~CAMPreInstallApp()
       
    56     {
       
    57     delete iStorage;
       
    58     iFs.Close();
       
    59     #ifdef RD_MULTIPLE_DRIVE        
       
    60  		  delete iInstallDocPathArray;
       
    61     #endif    
       
    62     iPreInstalledAppParams.ResetAndDestroy();
       
    63     }
       
    64 void CAMPreInstallApp::ConstructL()
       
    65     {
       
    66     iStorage = CDeliveryComponentStorage::NewL();
       
    67     User::LeaveIfError(iFs.Connect() );
       
    68     TPtrC mmcDrive(TParsePtrC( PathInfo::MemoryCardRootPath() ).Drive());
       
    69       iPreInstallPath.Append(mmcDrive);
       
    70       iPreInstallPath.Append(KPreInstallPath);
       
    71     }
       
    72 void CAMPreInstallApp::GetPreInstalledAppsL(RPointerArray<
       
    73         TPreInstalledAppParams> &aPreInstalledAppParams)
       
    74     {
       
    75 
       
    76     MakeAllInstallPathsL();
       
    77     ListPreInstalledAppL();
       
    78     aPreInstalledAppParams = iPreInstalledAppParams;
       
    79     }
       
    80 
       
    81 
       
    82 void CAMPreInstallApp::ListPreInstalledAppL(const TDesC& installDocPath)
       
    83     {
       
    84 
       
    85     RDEBUG("Clist_PreInstallAppUi: ListPreInstalledApp: <<<<");
       
    86     CDir* dir= NULL;
       
    87     TInt err = iFs.GetDir(installDocPath, KEntryAttNormal, ESortByName, dir);
       
    88    // _LIT(KInstallpath,"C:\\private\\10202dce\\");
       
    89     //TInt err = iFs.GetDir(KInstallpath, KEntryAttNormal, ESortByName, dir);
       
    90     RDEBUG_2("Clist_PreInstallAppUi: ListPreInstalledApp: err in getting dir list : %d",err);
       
    91     
       
    92     if (err==KErrNone)
       
    93         {
       
    94         CleanupStack::PushL(dir);
       
    95         RDEBUG_2("Clist_PreInstallAppUi: ListPreInstalledApp: no of dir's : %d",dir->Count());
       
    96         for (TInt i(0); i < dir->Count(); i++)
       
    97             {
       
    98 
       
    99 	    RDEBUG_2("Clist_PreInstallAppUi: ListPreInstalledApp: <<<< dir entry %d", i);
       
   100             TEntry entry;
       
   101             entry = (*dir)[i];
       
   102             HBufC* pathAndName = HBufC::NewLC(installDocPath.Length()
       
   103                     + entry.iName.Length() );
       
   104             TPtr ptrPathAndName = pathAndName->Des();
       
   105             ptrPathAndName.Append(installDocPath);
       
   106             ptrPathAndName.Append(entry.iName);
       
   107 
       
   108             HBufC* mimeType = HBufC::NewLC(KMaxDataTypeLength);
       
   109             //Recognize     
       
   110             if (!RecognizeL(*pathAndName, mimeType))
       
   111                 {
       
   112                 CleanupStack::PopAndDestroy(mimeType);
       
   113                 CleanupStack::PopAndDestroy(pathAndName);
       
   114                 continue;
       
   115                 }
       
   116 
       
   117 #ifdef RD_MULTIPLE_DRIVE
       
   118             if (TParsePtrC(installDocPath).Path().CompareF(KPreInstallPath)
       
   119                     == 0)
       
   120 #else
       
   121             if (installDocPath.CompareF(iPreInstallPath) == 0)
       
   122 #endif
       
   123                 {
       
   124 
       
   125 		RDEBUG("Clist_PreInstallAppUi: ListPreInstalledApp: <<<< Entered installDocPath.CompareF(iPreInstallPath)");
       
   126                 Swi::RSisRegistrySession regSession;
       
   127                 CleanupClosePushL(regSession);
       
   128                 User::LeaveIfError(regSession.Connect() );
       
   129 
       
   130                 RArray<TUid> uids;
       
   131                 CleanupClosePushL(uids);
       
   132 
       
   133                 regSession.InstalledUidsL(uids);
       
   134 
       
   135                 RFile temp;
       
   136                 User::LeaveIfError(temp.Open(iFs, *pathAndName,
       
   137                         EFileShareReadersOnly | EFileRead) );
       
   138                 CleanupClosePushL(temp);
       
   139 
       
   140                 TUid appUid;
       
   141                 TInt uidLen = sizeof(TInt32);
       
   142                 TInt seekLen = sizeof(TInt32) + sizeof(TInt32);
       
   143 
       
   144                 User::LeaveIfError(temp.Seek(ESeekStart, seekLen));
       
   145 
       
   146                 TPckg<TInt32> uid1(appUid.iUid);
       
   147                 User::LeaveIfError(temp.Read(uid1, uidLen));
       
   148                 if (uid1.Length() != uidLen)
       
   149                     {
       
   150                     User::Leave(KErrUnderflow);
       
   151                     }
       
   152 
       
   153                 //checking whether this is installed or not
       
   154                 TBool installed = regSession.IsInstalledL(appUid);
       
   155                 Swi::RSisRegistryEntry registryEntry;
       
   156                 TInt regEntryError = registryEntry.Open(regSession, appUid);
       
   157 		RDEBUG_2("Clist_PreInstallAppUi: ListPreInstalledApp: RegEntryError : %d",regEntryError);
       
   158 
       
   159 		//User::LeaveIfError(regEntryError);
       
   160 		if (regEntryError == KErrNone)
       
   161 		    {
       
   162                 CleanupClosePushL(registryEntry);
       
   163                 TBool isPreInstalled = registryEntry.PreInstalledL();
       
   164                // TBool isPreInstalled = ETrue;
       
   165 
       
   166                 RDEBUG_4("Clist_PreInstallAppUi: ListPreInstalledApp: UID is : '0x%X', installed:, preinstalled %d  %d",appUid,installed,isPreInstalled);
       
   167 
       
   168                 for (TInt i(0); isPreInstalled && i < uids.Count(); i++)
       
   169                     {
       
   170                     if (appUid == uids[i])
       
   171                         {
       
   172 
       
   173 			RDEBUG("Clist_PreInstallAppUi: appUid == uids[i]");
       
   174                         Swi::CSisRegistryPackage* sisRegistry = NULL;
       
   175                         TRAPD( err, sisRegistry = regSession.SidToPackageL( uids[i] ) ) ;
       
   176                         //User::LeaveIfError(err);
       
   177 			if(err == KErrNone)
       
   178 			{
       
   179 
       
   180 			RDEBUG("Clist_PreInstallAppUi: err == KErrNone");
       
   181                         TPreInstalledAppParams *params =
       
   182                                 new (ELeave) TPreInstalledAppParams;
       
   183                         params->iPreInstalledAppame.Copy(sisRegistry->Name());
       
   184                         params->iPreInstalledAppVendorName.Copy(
       
   185                                 sisRegistry->Vendor());
       
   186                         params->iPreInstalledAppUid = sisRegistry->Uid();
       
   187                         params->iMimeType.Copy(*mimeType);
       
   188                         //Get version
       
   189                         TVersion version = registryEntry.VersionL();
       
   190                         TBuf8<KVersionLength> pkgDes;
       
   191                         pkgDes.AppendNum(version.iMajor);
       
   192                         pkgDes.Append(KLiteralPeriod);
       
   193                         pkgDes.AppendNum(version.iMinor);
       
   194                         params->iVersion.Copy(pkgDes);
       
   195 
       
   196                         iPreInstalledAppParams.Append(params);
       
   197 
       
   198                         RDEBUG_2("Clist_PreInstallAppUi: ListPreInstalledApp: Installed App UID is : '0x%X'",appUid);
       
   199                         RDEBUG_2("Clist_PreInstallAppUi: ListPreInstalledApp: Installed App Name is: %S",&(sisRegistry->Name()));
       
   200                         RDEBUG_2("Clist_PreInstallAppUi: ListPreInstalledApp: Installed App Vendor is: %S",&(sisRegistry->Vendor()));
       
   201                         RDEBUG_2("Clist_PreInstallAppUi: ListPreInstalledApp: Installed App UID is : '0x%X'",sisRegistry->Uid());
       
   202                         delete sisRegistry;
       
   203 			}
       
   204                         continue;
       
   205                         }
       
   206                     }
       
   207 
       
   208                 CleanupStack::PopAndDestroy(&registryEntry);
       
   209 		    }
       
   210                 CleanupStack::PopAndDestroy(&temp);
       
   211                 CleanupStack::PopAndDestroy(&uids);
       
   212                 CleanupStack::PopAndDestroy(&regSession);
       
   213                 CleanupStack::PopAndDestroy(mimeType);
       
   214                 CleanupStack::PopAndDestroy(pathAndName);
       
   215                 }
       
   216             }
       
   217          CleanupStack::PopAndDestroy(dir);
       
   218         }
       
   219     }
       
   220 void CAMPreInstallApp::ListPreInstalledAppL()
       
   221     {
       
   222     iPreInstalledAppParams.Reset();
       
   223 #ifdef RD_MULTIPLE_DRIVE
       
   224     TInt count = iInstallDocPathArray->Count();
       
   225     for ( TInt index(0); index < count; index++ )
       
   226         {
       
   227         if ( (*iInstallDocPathArray)[index].Length()> 0 )
       
   228             {
       
   229             ListPreInstalledAppL( (*iInstallDocPathArray)[index] );
       
   230             }
       
   231         }
       
   232 #else   
       
   233     if (iPreInstallDocumentPath.Length() > 0)
       
   234         {
       
   235         ListPreInstalledAppL(iPreInstallDocumentPath);
       
   236         //_LIT(KInstallpath,"C:\\private\\10202dce\\");
       
   237         //ListPreInstalledAppL(KInstallpath);
       
   238         }
       
   239 #endif
       
   240 
       
   241     }
       
   242     
       
   243 TBool CAMPreInstallApp::RecognizeL(TDesC& aPathAndName, HBufC* aMimeType)
       
   244     {
       
   245     TBool IsOK(ETrue);
       
   246     ContentAccess::CContent* pkgContent = ContentAccess::CContent::NewLC(
       
   247             aPathAndName, ContentAccess::EContentShareReadWrite);
       
   248     
       
   249     TPtr mimePtr(aMimeType->Des());
       
   250     pkgContent->GetStringAttribute(ContentAccess::EMimeType, mimePtr);
       
   251 
       
   252     HBufC8* tmpMime8 = HBufC8::NewLC(aMimeType->Length());
       
   253     tmpMime8->Des().Copy(*aMimeType);
       
   254     TPtr8 mimePtr8(tmpMime8->Des());
       
   255 
       
   256     if ((mimePtr8 != SwiUI::KSisxMimeType) && (mimePtr8
       
   257             != SwiUI::KSisMimeType) && (mimePtr8 != SwiUI::KPipMimeType))
       
   258         {
       
   259         IsOK = EFalse;
       
   260         }
       
   261     CleanupStack::PopAndDestroy(tmpMime8);
       
   262     CleanupStack::PopAndDestroy(pkgContent);
       
   263     return IsOK;
       
   264 
       
   265     }
       
   266 void CAMPreInstallApp::MakeAllInstallPathsL()
       
   267     {
       
   268 #ifdef RD_MULTIPLE_DRIVE        
       
   269     iInstallDocPathArray = new (ELeave) CDesCArrayFlat( 2 );
       
   270     TDriveList driveList;
       
   271     TInt driveCount = 0;
       
   272     //User::LeaveIfError(iFs.Connect() );
       
   273     User::LeaveIfError( DriveInfo::GetUserVisibleDrives(iFs, driveList,driveCount));
       
   274     TUint driveStatus = 0;
       
   275     for (TInt index(0); index < KMaxDrives; index++)
       
   276         {
       
   277         if (driveList[index])
       
   278             {
       
   279             User::LeaveIfError( DriveInfo::GetDriveStatus(iFs, index,
       
   280                     driveStatus));
       
   281             TFileName path;
       
   282             TDriveUnit driveUnit(index);
       
   283             if ( !(driveStatus & DriveInfo::EDriveRemote ))
       
   284                 {
       
   285                 if (driveStatus & DriveInfo::EDriveRemovable)
       
   286                     {
       
   287                     path.Zero();
       
   288                     path.Append(driveUnit.Name() );
       
   289                     path.Append(KPreInstallPath);
       
   290                     iInstallDocPathArray->AppendL(path);
       
   291                     }
       
   292                 }
       
   293             }
       
   294         }
       
   295     //iFs.Close();
       
   296 #else   
       
   297     TPtrC mmcDrive(TParsePtrC( PathInfo::MemoryCardRootPath() ).Drive());
       
   298     iPreInstallDocumentPath.Append(mmcDrive);
       
   299     iPreInstallDocumentPath.Append(KPreInstallPath);
       
   300 #endif //RD_MULTIPLE_DRIVE 
       
   301     }