contentstorage/cahandler/app/src/cauninstalloperation.cpp
changeset 61 8e5041d13c84
child 66 32469d7d46ff
equal deleted inserted replaced
60:f62f87b200ec 61:8e5041d13c84
       
     1 /*
       
     2  * Copyright (c) 2008 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:  ?Description
       
    15  *
       
    16  */
       
    17 
       
    18 #include <apgcli.h>
       
    19 #include <swi/sisregistrysession.h>
       
    20 #include <swi/sisregistryentry.h>
       
    21 #include "cautils.h"
       
    22 #include "cadef.h"
       
    23 #include "cainnerentry.h"
       
    24 #include "cauninstalloperation.h"
       
    25 _LIT8(KAppMimeType, "x-epoc/x-sisx-app");
       
    26 
       
    27 // ================= MEMBER FUNCTIONS =======================
       
    28 
       
    29 // ---------------------------------------------------------------------------
       
    30 // CCaUninstallOperation::~CCaUninstallOperation
       
    31 // ---------------------------------------------------------------------------
       
    32 //
       
    33 CCaUninstallOperation::~CCaUninstallOperation()
       
    34 {
       
    35     Cancel();
       
    36     iUninstaller.Close();
       
    37 }
       
    38 
       
    39 // ---------------------------------------------------------------------------
       
    40 // CCaUninstallOperation::NewL
       
    41 // ---------------------------------------------------------------------------
       
    42 //
       
    43 CCaUninstallOperation *CCaUninstallOperation::NewL(CCaInnerEntry &aEntry,
       
    44         TInt aPriority)
       
    45 {
       
    46     CCaUninstallOperation *self;
       
    47 
       
    48     self = new(ELeave) CCaUninstallOperation(aEntry, aPriority);
       
    49     CleanupStack::PushL(self);
       
    50     self->ConstructL(aEntry);
       
    51     CleanupStack::Pop(self);
       
    52     return self;
       
    53 }
       
    54 
       
    55 // ---------------------------------------------------------------------------
       
    56 // CCaUninstallOperation::CCaUninstallOperation
       
    57 // ---------------------------------------------------------------------------
       
    58 //
       
    59 CCaUninstallOperation::CCaUninstallOperation(CCaInnerEntry &aEntry,
       
    60         TInt aPriority) :
       
    61     CActive(aPriority), iEntry(aEntry), iUninstaller(), iId(0)
       
    62 {
       
    63     CActiveScheduler::Add(this);
       
    64 }
       
    65 
       
    66 // ---------------------------------------------------------------------------
       
    67 // CCaUninstallOperation::ConstructL
       
    68 // ---------------------------------------------------------------------------
       
    69 //
       
    70 void CCaUninstallOperation::ConstructL(CCaInnerEntry &aEntry)
       
    71 {
       
    72     TBuf<KCaMaxAttrValueLen> uidAttr;
       
    73     TUint uid = aEntry.GetUid();
       
    74 
       
    75     TUid packageUid = KNullUid;
       
    76     TPtrC8 mimeType;
       
    77 
       
    78     if (!(aEntry.GetFlags() & ERemovable)) {
       
    79         User::Leave(KErrAccessDenied);
       
    80     }
       
    81 
       
    82     User::LeaveIfError(iUninstaller.Connect());
       
    83     iId = aEntry.GetId();
       
    84     if (aEntry.GetEntryTypeName() == KCaTypeWidget()) {
       
    85         TBuf<KMaxUidName> uidDesc;
       
    86         aEntry.FindAttribute(KCaPackageUid, uidDesc);
       
    87         TLex uidLex(uidDesc);
       
    88         TUint32 uidValue;
       
    89         User::LeaveIfError(uidLex.Val(uidValue, EHex));
       
    90 
       
    91         packageUid.iUid = static_cast<TInt32>(uidValue);
       
    92         mimeType.Set(KAppMimeType);
       
    93     } else {
       
    94         AppInfoL(TUid::Uid(uid), mimeType, packageUid);
       
    95     }
       
    96 
       
    97     // Commence the uninstallations
       
    98     iUninstaller.Uninstall(iStatus, packageUid, mimeType);
       
    99     SetActive();
       
   100 }
       
   101 
       
   102 // ---------------------------------------------------------------------------
       
   103 // CCaUninstallOperation::AppInfo
       
   104 // ---------------------------------------------------------------------------
       
   105 //
       
   106 void CCaUninstallOperation::AppInfoL(const TUid &aAppUid,
       
   107                                      TPtrC8 &aMimeType, TUid &aPackageUid)
       
   108 {
       
   109     RApaLsSession apaLsSession;
       
   110 
       
   111     User::LeaveIfError(apaLsSession.Connect());
       
   112     CleanupClosePushL(apaLsSession);
       
   113     User::LeaveIfError(apaLsSession.GetAllApps());
       
   114 
       
   115     TApaAppInfo appInfo;
       
   116     User::LeaveIfError(apaLsSession.GetAppInfo(appInfo, aAppUid));
       
   117     if (!GetInstallPkgUidL(appInfo.iFullName, aPackageUid)) {
       
   118         aPackageUid = aAppUid;
       
   119     }
       
   120     aMimeType.Set(KAppMimeType);
       
   121 
       
   122     CleanupStack::PopAndDestroy(&apaLsSession);
       
   123 }
       
   124 
       
   125 // ---------------------------------------------------------------------------
       
   126 // CCaUninstallOperation::GetInstallPkgUidL
       
   127 // ---------------------------------------------------------------------------
       
   128 //
       
   129 TBool CCaUninstallOperation::GetInstallPkgUidL(const TDesC &aAppFullName,
       
   130         TUid &aPackageUid)
       
   131 {
       
   132     // Search for the full name of the application amongst every file name in
       
   133     // every installed packages.
       
   134     TBool found = EFalse;
       
   135     Swi::RSisRegistrySession iSisRegSession;
       
   136 
       
   137     // Get the array of ids of every installed packages
       
   138     if (KErrNone != iSisRegSession.Connect()) {
       
   139         return found;
       
   140     }
       
   141     CleanupClosePushL(iSisRegSession);
       
   142 
       
   143     RArray<TUid> packageIds;
       
   144     CleanupClosePushL(packageIds);
       
   145 
       
   146     iSisRegSession.InstalledUidsL(packageIds);
       
   147 
       
   148     RPointerArray<HBufC> packageFiles;
       
   149     CleanupClosePushL(packageFiles);
       
   150 
       
   151     for (TInt i = 0; i < packageIds.Count() && !found; ++i) {
       
   152         const TUid packageId = packageIds[i];
       
   153         Swi::RSisRegistryEntry packageEntry;
       
   154 
       
   155         // Get the array of file names in the current install package and look
       
   156         // if there is one suggesting that the application was installed from
       
   157         // the package.
       
   158         if (KErrNone == packageEntry.Open(iSisRegSession, packageId)) {
       
   159             CleanupClosePushL(packageEntry);
       
   160             packageEntry.FilesL(packageFiles);
       
   161             for (TInt pf = 0; pf < packageFiles.Count() && !found; ++pf) {
       
   162                 if (packageFiles[pf]->FindC(aAppFullName) == 0) {
       
   163                     aPackageUid = packageId;
       
   164                     found = ETrue;
       
   165                 }
       
   166             }
       
   167             packageFiles.ResetAndDestroy();
       
   168             CleanupStack::PopAndDestroy(&packageEntry);
       
   169         }
       
   170     }
       
   171 
       
   172     CleanupStack::PopAndDestroy(&packageFiles);
       
   173     CleanupStack::PopAndDestroy(&packageIds);
       
   174     CleanupStack::PopAndDestroy(&iSisRegSession);
       
   175 
       
   176     return found;
       
   177 }
       
   178 
       
   179 // ---------------------------------------------------------------------------
       
   180 // CCaUninstallOperation::RunL
       
   181 // ---------------------------------------------------------------------------
       
   182 //
       
   183 void CCaUninstallOperation::RunL()
       
   184 {
       
   185     iUninstaller.Close();
       
   186 }
       
   187 
       
   188 // ---------------------------------------------------------------------------
       
   189 // CCaUninstallOperation::DoCancel
       
   190 // ---------------------------------------------------------------------------
       
   191 //
       
   192 void CCaUninstallOperation::DoCancel()
       
   193 {
       
   194     iUninstaller.CancelAsyncRequest(SwiUI::ERequestUninstall);
       
   195 }
       
   196 
       
   197 // ---------------------------------------------------------------------------
       
   198 // CCaUninstallOperation::RunError
       
   199 // ---------------------------------------------------------------------------
       
   200 //
       
   201 TInt CCaUninstallOperation::RunError(TInt /* aError */)
       
   202 {
       
   203     return KErrNone;
       
   204 }