activityfw/storage/server/tsrc/t_server/t_installer.cpp
author Jaakko Haukipuro (Nokia-MS/Oulu) <Jaakko.Haukipuro@nokia.com>
Thu, 16 Sep 2010 12:11:40 +0100
changeset 117 c63ee96dbe5f
permissions -rw-r--r--
Missing activityfw and taskswitcher components - fix for Bug 3670

/*
 * Copyright (c) 2010 Nokia Corporation and/or its subsidiary(-ies).
 * All rights reserved.
 * This component and the accompanying materials are made available
 * under the terms of "Eclipse Public License v1.0"
 * which accompanies this distribution, and is available
 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
 *
 * Initial Contributors:
 * Nokia Corporation - initial contribution.
 *
 * Contributors:
 *
 * Description:  ?Description
 *
 */

#include <usif/usifcommon.h>
#include <usif/scr/screntries.h>

#include "t_installer.h"

using namespace Usif;

// ================= MEMBER FUNCTIONS =======================

// ---------------------------------------------------------------------------
// T_CaInstaller::~T_CaInstaller
// ---------------------------------------------------------------------------
//
T_Installer::~T_Installer()
    {
    Cancel();
    //iFs.Close();
    delete iArguments;
    delete iResults;
    iInstaller.Close();
    iSoftwareRegistry.Close();
    }

// ---------------------------------------------------------------------------
// T_CaInstaller::NewL
// ---------------------------------------------------------------------------
//
T_Installer *T_Installer::NewL(TInt aPriority)
    {
    T_Installer *self = new (ELeave) T_Installer(
            aPriority );
    CleanupStack::PushL( self );
    self->ConstructL();
    CleanupStack::Pop( self );
    return self;
    }

// ---------------------------------------------------------------------------
// T_CaInstaller::T_CaInstaller
// ---------------------------------------------------------------------------
//
T_Installer::T_Installer( TInt aPriority ) :
    CActive( aPriority ), iInstaller()
    {
    CActiveScheduler::Add( this );
    }

// ---------------------------------------------------------------------------
// T_CaInstaller::ConstructL
// ---------------------------------------------------------------------------
//
void T_Installer::ConstructL()
    {
    iArguments = COpaqueNamedParams::NewL();
    iResults = COpaqueNamedParams::NewL();
    
    iArguments->AddIntL( KSifInParam_InstallInactive, ETrue );
    iArguments->AddIntL( KSifInParam_InstallSilently, ETrue );
    
    User::LeaveIfError( iInstaller.Connect() );
    User::LeaveIfError( iSoftwareRegistry.Connect() );
    //User::LeaveIfError( iFs.Connect() ); 
    }

// ---------------------------------------------------------------------------
// T_CaInstallOperation::ConstructL
// ---------------------------------------------------------------------------
//
void T_Installer::InstallL( const TDesC& aFileName )
    {
    if (IsActive())
        {
        User::Leave(KErrInUse);
        }

    iInstaller.Install( aFileName, *iArguments, *iResults, iStatus );
    SetActive();
    iSchedulerWait.Start();
    User::LeaveIfError(iStatus.Int());

    }
    
// ---------------------------------------------------------------------------
// T_CaInstaller::UnistallL
// ---------------------------------------------------------------------------
//
void T_Installer::UninstallL(TComponentId aComponentId)
    {
    if (IsActive())
        {
        User::Leave( KErrInUse );
        }
    
    if (aComponentId >= 1) 
        {
        iInstaller.Uninstall( aComponentId, *iArguments, *iResults, iStatus );
        SetActive();
        iSchedulerWait.Start();
        User::LeaveIfError(iStatus.Int());
        }
    
    }

// ---------------------------------------------------------------------------
// T_CaInstaller::UnistallL
// ---------------------------------------------------------------------------
//
void T_Installer::UninstallL(const TDesC& aFileName)
    {    
        UninstallL( GetComponentIdL(aFileName) );    
    }

// ---------------------------------------------------------------------------
// T_CaInstaller::UnistallL
// ---------------------------------------------------------------------------
//
void T_Installer::UninstallL( TUint32 aUid )
    {
    UninstallL( GetComponentIdL( aUid ) );    
    }

TComponentId T_Installer::GetComponentIdL( const TDesC& aFileName )
    {
    CComponentFilter* const fileNameFilter = CComponentFilter::NewLC();
    fileNameFilter->SetFileL( aFileName );

    RArray<TComponentId> componentIds;
    CleanupClosePushL( componentIds );
    iSoftwareRegistry.GetComponentIdsL( componentIds, fileNameFilter );

    TComponentId componentId( 0 );
    
    if ( componentIds.Count() == 1 )
        {
        componentId = componentIds[0];    
        }
    else if ( componentIds.Count() >= 2 )
        {
        User::Leave( KErrGeneral );
        }
    
    CleanupStack::PopAndDestroy( &componentIds );
    CleanupStack::PopAndDestroy( fileNameFilter );
    
    return componentId;
    }


TComponentId T_Installer::GetComponentIdL( TInt32 aUid )
    {
    TUid uid;
    TComponentId componentId = iSoftwareRegistry.GetComponentIdForAppL(
            uid.Uid( aUid ) );;
    
    if ( componentId <= 0 )
        {
        User::Leave( KErrGeneral );  
        }
    return componentId;
    }
// ---------------------------------------------------------------------------
// T_CaInstaller::RunL
// ---------------------------------------------------------------------------
//
void T_Installer::RunL()
    {
    iSchedulerWait.AsyncStop();
    }

// ---------------------------------------------------------------------------
// T_CaInstaller::DoCancel
// ---------------------------------------------------------------------------
//
void T_Installer::DoCancel()
    {
    iInstaller.CancelOperation();
    iSchedulerWait.AsyncStop();
    }

// ---------------------------------------------------------------------------
// T_CaInstaller::RunError
// ---------------------------------------------------------------------------
//
TInt T_Installer::RunError(TInt /*aError*/)
    {
    return KErrNone;
    }