contentstorage/cahandler/app/src/cauninstalloperation.cpp
changeset 80 397d00875918
parent 73 4bc7b118b3df
child 83 156f692b1687
equal deleted inserted replaced
73:4bc7b118b3df 80:397d00875918
     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 
       
    22 #include "cautils.h"
       
    23 #include "cadef.h"
       
    24 #include "cainnerentry.h"
       
    25 #include "cauninstalloperation.h"
       
    26 _LIT8(KAppMimeType, "x-epoc/x-sisx-app");
       
    27 
       
    28 // ================= MEMBER FUNCTIONS =======================
       
    29 
       
    30 // ---------------------------------------------------------------------------
       
    31 // CCaUninstallOperation::~CCaUninstallOperation
       
    32 // ---------------------------------------------------------------------------
       
    33 //
       
    34 CCaUninstallOperation::~CCaUninstallOperation()
       
    35 {
       
    36     Cancel();
       
    37     iUninstaller.Close();
       
    38 }
       
    39 
       
    40 // ---------------------------------------------------------------------------
       
    41 // CCaUninstallOperation::NewL
       
    42 // ---------------------------------------------------------------------------
       
    43 //
       
    44 CCaUninstallOperation *CCaUninstallOperation::NewL(CCaInnerEntry &aEntry,
       
    45         TInt aPriority)
       
    46 {
       
    47     CCaUninstallOperation *self;
       
    48 
       
    49     self = new(ELeave) CCaUninstallOperation(aEntry, aPriority);
       
    50     CleanupStack::PushL(self);
       
    51     self->ConstructL(aEntry);
       
    52     CleanupStack::Pop(self);
       
    53     return self;
       
    54 }
       
    55 
       
    56 // ---------------------------------------------------------------------------
       
    57 // CCaUninstallOperation::CCaUninstallOperation
       
    58 // ---------------------------------------------------------------------------
       
    59 //
       
    60 CCaUninstallOperation::CCaUninstallOperation(CCaInnerEntry &aEntry,
       
    61         TInt aPriority) :
       
    62     CActive(aPriority), iEntry(aEntry), iUninstaller(), iId(0)
       
    63 {
       
    64     CActiveScheduler::Add(this);
       
    65 }
       
    66 
       
    67 // ---------------------------------------------------------------------------
       
    68 // CCaUninstallOperation::ConstructL
       
    69 // ---------------------------------------------------------------------------
       
    70 //
       
    71 void CCaUninstallOperation::ConstructL(CCaInnerEntry &aEntry)
       
    72 {
       
    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 size is greater then 1024 bytes
       
   116     // so its instances should not be created on the stack.
       
   117     TApaAppInfo* appInfo = new(ELeave) TApaAppInfo();
       
   118     CleanupStack::PushL(appInfo);
       
   119     User::LeaveIfError(apaLsSession.GetAppInfo(*appInfo, aAppUid));
       
   120     if (!GetInstallPkgUidL(appInfo->iFullName, aPackageUid)) {
       
   121         aPackageUid = aAppUid;
       
   122     }
       
   123     CleanupStack::PopAndDestroy(appInfo);
       
   124     aMimeType.Set(KAppMimeType);
       
   125 
       
   126     CleanupStack::PopAndDestroy(&apaLsSession);
       
   127 }
       
   128 
       
   129 // ---------------------------------------------------------------------------
       
   130 // CCaUninstallOperation::GetInstallPkgUidL
       
   131 // ---------------------------------------------------------------------------
       
   132 //
       
   133 TBool CCaUninstallOperation::GetInstallPkgUidL(const TDesC &aAppFullName,
       
   134         TUid &aPackageUid)
       
   135 {
       
   136     // Search for the full name of the application amongst every file name in
       
   137     // every installed packages.
       
   138     TBool found = EFalse;
       
   139     Swi::RSisRegistrySession iSisRegSession;
       
   140 
       
   141     // Get the array of ids of every installed packages
       
   142     if (KErrNone != iSisRegSession.Connect()) {
       
   143         return found;
       
   144     }
       
   145     CleanupClosePushL(iSisRegSession);
       
   146 
       
   147     RArray<TUid> packageIds;
       
   148     CleanupClosePushL(packageIds);
       
   149 
       
   150     iSisRegSession.InstalledUidsL(packageIds);
       
   151 
       
   152     RPointerArray<HBufC> packageFiles;
       
   153     CleanupClosePushL(packageFiles);
       
   154 
       
   155     for (TInt i = 0; i < packageIds.Count() && !found; ++i) {
       
   156         const TUid packageId = packageIds[i];
       
   157         Swi::RSisRegistryEntry packageEntry;
       
   158 
       
   159         // Get the array of file names in the current install package and look
       
   160         // if there is one suggesting that the application was installed from
       
   161         // the package.
       
   162         if (KErrNone == packageEntry.Open(iSisRegSession, packageId)) {
       
   163             CleanupClosePushL(packageEntry);
       
   164             packageEntry.FilesL(packageFiles);
       
   165             for (TInt pf = 0; pf < packageFiles.Count() && !found; ++pf) {
       
   166                 if (packageFiles[pf]->FindC(aAppFullName) == 0) {
       
   167                     aPackageUid = packageId;
       
   168                     found = ETrue;
       
   169                 }
       
   170             }
       
   171             packageFiles.ResetAndDestroy();
       
   172             CleanupStack::PopAndDestroy(&packageEntry);
       
   173         }
       
   174     }
       
   175 
       
   176     CleanupStack::PopAndDestroy(&packageFiles);
       
   177     CleanupStack::PopAndDestroy(&packageIds);
       
   178     CleanupStack::PopAndDestroy(&iSisRegSession);
       
   179 
       
   180     return found;
       
   181 }
       
   182 
       
   183 // ---------------------------------------------------------------------------
       
   184 // CCaUninstallOperation::RunL
       
   185 // ---------------------------------------------------------------------------
       
   186 //
       
   187 void CCaUninstallOperation::RunL()
       
   188 {
       
   189     iUninstaller.Close();
       
   190 }
       
   191 
       
   192 // ---------------------------------------------------------------------------
       
   193 // CCaUninstallOperation::DoCancel
       
   194 // ---------------------------------------------------------------------------
       
   195 //
       
   196 void CCaUninstallOperation::DoCancel()
       
   197 {
       
   198     iUninstaller.CancelAsyncRequest(SwiUI::ERequestUninstall);
       
   199 }
       
   200 
       
   201 // ---------------------------------------------------------------------------
       
   202 // CCaUninstallOperation::RunError
       
   203 // ---------------------------------------------------------------------------
       
   204 //
       
   205 TInt CCaUninstallOperation::RunError(TInt /* aError */)
       
   206 {
       
   207     return KErrNone;
       
   208 }