appfw/apparchitecture/tef/t_sisfileinstaller.cpp
branchRCL_3
changeset 63 c2c61fdca848
parent 62 924385140d98
child 64 75184094ace1
child 66 9af619316cbf
equal deleted inserted replaced
62:924385140d98 63:c2c61fdca848
     1 // Copyright (c) 2010 Nokia Corporation and/or its subsidiary(-ies).
       
     2 // All rights reserved.
       
     3 // This component and the accompanying materials are made available
       
     4 // under the terms of "Eclipse Public License v1.0"
       
     5 // which accompanies this distribution, and is available
       
     6 // at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     7 //
       
     8 // Initial Contributors:
       
     9 // Nokia Corporation - initial contribution.
       
    10 //
       
    11 // Contributors:
       
    12 //
       
    13 // Description:
       
    14 // The following test case is used to test if apparctestserver 
       
    15 // can return app data for a specific app by caching that data when requested.
       
    16 // 
       
    17 //
       
    18 
       
    19 /**
       
    20  @file
       
    21  @internalComponent - Internal Symbian test code
       
    22 */
       
    23 
       
    24 #include <apgcli.h>
       
    25 #include "T_SisFileInstaller.h"
       
    26 #include <usif/scr/screntries.h>
       
    27 #include <usif/usiferror.h>
       
    28 
       
    29 using namespace Usif;
       
    30 
       
    31 CSisFileInstaller::CSisFileInstaller()
       
    32     {   
       
    33     }
       
    34 
       
    35 CSisFileInstaller::~CSisFileInstaller()
       
    36     {
       
    37     iSif.Close();
       
    38     }
       
    39 
       
    40 TInt CSisFileInstaller::InstallSisAndWaitForAppListUpdateL(const TDesC& aFileName)
       
    41 {
       
    42  RApaLsSession ls;
       
    43  User::LeaveIfError(ls.Connect());
       
    44  CleanupClosePushL(ls);
       
    45  TRequestStatus status;
       
    46  ls.SetNotify(EFalse, status);
       
    47  InstallSisL(aFileName);
       
    48  User::WaitForRequest(status);
       
    49  CleanupStack::PopAndDestroy();
       
    50  return KErrNone;
       
    51 }
       
    52 
       
    53 TInt CSisFileInstaller::UninstallSisAndWaitForAppListUpdateL(const TDesC& aComponentName)
       
    54 {
       
    55  RApaLsSession ls;
       
    56  User::LeaveIfError(ls.Connect());
       
    57  CleanupClosePushL(ls);
       
    58  TRequestStatus status;
       
    59  ls.SetNotify(EFalse, status);
       
    60  UninstallSisL(aComponentName);
       
    61  User::WaitForRequest(status);
       
    62  CleanupStack::PopAndDestroy();
       
    63  return KErrNone;
       
    64 }
       
    65 
       
    66 TInt CSisFileInstaller::InstallSisL(const TDesC& aFileName)
       
    67     {
       
    68     TBuf<256> buf;
       
    69     buf.Copy(aFileName);
       
    70     HBufC* as = buf.AllocL();        
       
    71     TPtr16 sisFileName = as->Des();
       
    72     CleanupStack::PushL(as);
       
    73     
       
    74     RFs fs;
       
    75     RFile file;
       
    76     User::LeaveIfError(fs.Connect());
       
    77     fs.ShareProtected();
       
    78     CleanupClosePushL(fs);
       
    79     User::LeaveIfError(file.Open(fs, sisFileName, EFileRead | EFileShareReadersOnly));
       
    80     CleanupClosePushL(file);
       
    81     User::LeaveIfError(iSif.Connect()); 
       
    82     CleanupClosePushL(iSif);  
       
    83     TInt err=KErrNone;
       
    84      do
       
    85          {
       
    86          iSif.Install(aFileName, iStatus, ETrue);
       
    87          User::WaitForRequest(iStatus);
       
    88          err=iStatus.Int();
       
    89          }
       
    90      while( err == KErrScrReadOperationInProgress);
       
    91      
       
    92     User::LeaveIfError(err);
       
    93      
       
    94     CleanupStack::PopAndDestroy(4, as);
       
    95     return KErrNone;
       
    96     }
       
    97 
       
    98 
       
    99 TInt CSisFileInstaller::UninstallSisL(const TDesC& aComponentName)
       
   100     {    
       
   101     _LIT(KSisComponentVendor, "Nokia India Pvt Ltd");   
       
   102     
       
   103     RFs fs;
       
   104     RFile file;
       
   105     User::LeaveIfError(fs.Connect());
       
   106     fs.ShareProtected();
       
   107     CleanupClosePushL(fs);     
       
   108 
       
   109     User::LeaveIfError(iSif.Connect());
       
   110     CleanupClosePushL(iSif);
       
   111     
       
   112     TBuf<256> buf;
       
   113     buf.Copy(aComponentName);
       
   114     HBufC* as1 = buf.AllocL();        
       
   115     TPtr16 componentName = as1->Des();
       
   116     HBufC* as2 = KSisComponentVendor().AllocL();
       
   117     TPtr16 componentVendor = as2->Des();
       
   118     iComponentId = FindComponentInScrL(componentName, componentVendor); 
       
   119 
       
   120     TInt err=KErrNone;
       
   121      do
       
   122          {
       
   123          iSif.Uninstall(iComponentId, iStatus, ETrue);
       
   124          User::WaitForRequest(iStatus);
       
   125          err=iStatus.Int();
       
   126          }
       
   127      while( err == KErrScrReadOperationInProgress);
       
   128      
       
   129     //Leave if sis file uninstllation failed.
       
   130     User::LeaveIfError(err);
       
   131     
       
   132     delete as1;
       
   133     delete as2;
       
   134     as1 = NULL;
       
   135     as2 = NULL;  
       
   136     CleanupStack::PopAndDestroy(2, &fs); 
       
   137     return KErrNone;
       
   138     }
       
   139 
       
   140 
       
   141 void CSisFileInstaller::CancelInstallation()
       
   142     {
       
   143     iSif.CancelOperation();
       
   144     }
       
   145 
       
   146 void CSisFileInstaller::Close()
       
   147     {
       
   148     iSif.Close();
       
   149     }
       
   150 
       
   151 TInt CSisFileInstaller::InstallSisAsynchronouslyL(const TDesC& aFileName, TRequestStatus& status)
       
   152 {
       
   153     TBuf<256> buf;
       
   154     buf.Copy(aFileName);
       
   155     HBufC* as = buf.AllocL();        
       
   156     TPtr16 sisFileName = as->Des();
       
   157     CleanupStack::PushL(as);
       
   158     
       
   159     RFs fs;
       
   160     RFile file;
       
   161     User::LeaveIfError(fs.Connect());
       
   162     fs.ShareProtected();
       
   163     CleanupClosePushL(fs);
       
   164     User::LeaveIfError(file.Open(fs, sisFileName, EFileRead | EFileShareReadersOnly));
       
   165     CleanupClosePushL(file);
       
   166     CleanupStack::PopAndDestroy(3, as);
       
   167     
       
   168     User::LeaveIfError(iSif.Connect()); 
       
   169     
       
   170     iSif.Install(aFileName, status, ETrue);
       
   171     return KErrNone;
       
   172 }
       
   173 
       
   174 TInt CSisFileInstaller::FindComponentInScrL(const TDesC& aComponentName, const TDesC& aVendor)
       
   175     {
       
   176     RSoftwareComponentRegistry scr;
       
   177     User::LeaveIfError(scr.Connect());
       
   178     CleanupClosePushL(scr);
       
   179 
       
   180     RSoftwareComponentRegistryView scrView;
       
   181     CComponentFilter* filter = CComponentFilter::NewLC();
       
   182     filter->SetNameL(aComponentName);
       
   183     filter->SetVendorL(aVendor);
       
   184 
       
   185     scrView.OpenViewL(scr, filter);
       
   186     CleanupClosePushL(scrView);
       
   187 
       
   188     CComponentEntry* component = scrView.NextComponentL();
       
   189     TInt componentId = 0;
       
   190     if (component != NULL)
       
   191         {
       
   192         componentId = component->ComponentId();
       
   193         delete component;
       
   194         }
       
   195 
       
   196     CleanupStack::PopAndDestroy(3, &scr);    
       
   197     return componentId; 
       
   198     }
       
   199