voipplugins/accountcreationplugin/src/accountcreationplugin.cpp
changeset 0 a4daefaec16c
child 8 7117cbf1600a
equal deleted inserted replaced
-1:000000000000 0:a4daefaec16c
       
     1 /*
       
     2 * Copyright (c) 2007-2009 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:  Source file for CAccountCreationPlugin
       
    15  *
       
    16 */
       
    17 
       
    18 #include <eikenv.h>
       
    19 #include <bautils.h>
       
    20 #include <pathinfo.h>
       
    21 #include <SWInstApi.h>
       
    22 #include <SWInstDefs.h>
       
    23 #include <aknViewAppUi.h>
       
    24 #include <AknQueryDialog.h> 
       
    25 #include <StringLoader.h>
       
    26 #include <accountcreationplugin.rsg>
       
    27 #include <data_caging_path_literals.hrh>
       
    28 
       
    29 #include "accountcreationplugin.h"
       
    30 #include "accountcreationpluginlogger.h"
       
    31 #include "acpproviderlistview.h"
       
    32 #include "accountcreationpluginconstants.h"
       
    33 #include "accountcreationplugin.hrh"
       
    34 
       
    35 const TUid KAIAppUid = { 0x102750F0 }; // active idle application uid        
       
    36 
       
    37 // ---------------------------------------------------------------------------
       
    38 // CAccountCreationPlugin::CAccountCreationPlugin
       
    39 // ---------------------------------------------------------------------------
       
    40 //
       
    41 CAccountCreationPlugin::CAccountCreationPlugin()
       
    42     {
       
    43     }
       
    44 
       
    45 // ---------------------------------------------------------------------------
       
    46 // CAccountCreationPlugin::ConstructL
       
    47 // ---------------------------------------------------------------------------
       
    48 //
       
    49 void CAccountCreationPlugin::ConstructL()
       
    50     {
       
    51     ACPLOG( "CAccountCreationPlugin::ConstructL begin" );
       
    52 
       
    53     // Load resource file to the memory.
       
    54     // This when going to ROM (PhoneMemoryRootPath is used only for testing).
       
    55     TFileName resourceFile = 
       
    56         TParsePtrC( PathInfo::RomRootPath() ).Drive();
       
    57 
       
    58     resourceFile.Append( KDC_RESOURCE_FILES_DIR );
       
    59     resourceFile.Append( KResourceFilename );
       
    60     BaflUtils::NearestLanguageFile( CCoeEnv::Static()->FsSession(), 
       
    61         resourceFile );
       
    62     iResourceOffset = CCoeEnv::Static()->AddResourceFileL( resourceFile );
       
    63 
       
    64     // Create handle to AIW Service Handler.
       
    65     iServiceHandler = CAiwServiceHandler::NewL();
       
    66 
       
    67     iEikEnv = CEikonEnv::Static();
       
    68 
       
    69     ACPLOG( "CAccountCreationPlugin::ConstructL end" );
       
    70     }
       
    71 
       
    72 // ---------------------------------------------------------------------------
       
    73 // CAccountCreationPlugin::NewL
       
    74 // ---------------------------------------------------------------------------
       
    75 //
       
    76 CAccountCreationPlugin* CAccountCreationPlugin::NewL()
       
    77     {
       
    78     CAccountCreationPlugin* self = new ( ELeave ) CAccountCreationPlugin;
       
    79     CleanupStack::PushL( self );
       
    80     self->ConstructL();
       
    81     CleanupStack::Pop( self );
       
    82     return self;
       
    83     }
       
    84 
       
    85 // ---------------------------------------------------------------------------
       
    86 // CAccountCreationPlugin::~CAccountCreationPlugin
       
    87 // ---------------------------------------------------------------------------
       
    88 //
       
    89 CAccountCreationPlugin::~CAccountCreationPlugin()
       
    90     {
       
    91     ACPLOG( "CAccountCreationPlugin::~CAccountCreationPlugin begin" );
       
    92 
       
    93     delete iServiceHandler;
       
    94 
       
    95     if ( iResourceOffset )
       
    96         {
       
    97         CCoeEnv::Static()->DeleteResourceFile( iResourceOffset );
       
    98         }
       
    99  
       
   100 	iEikEnv = NULL;
       
   101 
       
   102     ACPLOG( "CAccountCreationPlugin::~CAccountCreationPlugin end" );
       
   103     }
       
   104 
       
   105 // ---------------------------------------------------------------------------
       
   106 // CAccountCreationPlugin::SendInitializedCallbackL
       
   107 // Sends AIW service command when plugin initialization is completed. 
       
   108 // ---------------------------------------------------------------------------
       
   109 //
       
   110 void CAccountCreationPlugin::SendInitializedCallbackL() const
       
   111     {
       
   112     ACPLOG( "CAccountCreationPlugin::SendInitializedCallbackL begin" );
       
   113 
       
   114     MAiwNotifyCallback* callback = 
       
   115         const_cast<MAiwNotifyCallback*>( iNotifyCallback );
       
   116 
       
   117     // Uid of ACP.
       
   118     TAiwVariant variant( KAccountCreationPluginUid );
       
   119     TAiwGenericParam genericParamUid( EGenericParamError, variant );
       
   120     CAiwGenericParamList& paramList = iServiceHandler->InParamListL();
       
   121     paramList.AppendL( genericParamUid );
       
   122     variant.Reset();
       
   123 
       
   124     // Localized name of ACP.
       
   125     HBufC* localizedName = StringLoader::LoadLC( R_ACP_NAME_IN_CUSTOMER_APP );     
       
   126     variant.Set( localizedName->Des() );
       
   127     TAiwGenericParam genericParamName( EGenericParamError, variant );
       
   128     paramList.AppendL( genericParamName );
       
   129     CleanupStack::PopAndDestroy( localizedName );
       
   130     variant.Reset();
       
   131 
       
   132     // Place of ACP in customer application.
       
   133     TInt32 placing( 0 );
       
   134     variant.Set( placing );
       
   135     TAiwGenericParam genericParamPlace( EGenericParamError, variant );
       
   136     paramList.AppendL( genericParamPlace );
       
   137 
       
   138     // Send callback to the customer application.
       
   139     CAiwGenericParamList* nullList = NULL;
       
   140     callback->HandleNotifyL( 
       
   141         KAiwCmdCSCUiExtensionPlugins,
       
   142         KAiwEventStarted,
       
   143         *nullList,
       
   144         paramList );
       
   145 
       
   146     ACPLOG( "CAccountCreationPlugin::SendInitializedCallbackL end" );
       
   147     }
       
   148 
       
   149 // ---------------------------------------------------------------------------
       
   150 // CAccountCreationPlugin::SendCompletedCallbackL
       
   151 // Sends AIW service command when plugin is stopped its work.
       
   152 // ---------------------------------------------------------------------------
       
   153 //
       
   154 void CAccountCreationPlugin::SendCompletedCallbackL() const
       
   155     {
       
   156     ACPLOG( "CAccountCreationPlugin::SendCompletedCallbackL begin" );
       
   157 
       
   158     MAiwNotifyCallback* callback = 
       
   159         const_cast<MAiwNotifyCallback*>( iNotifyCallback );
       
   160 
       
   161     // Uid of ACP.
       
   162     TAiwVariant variant( KAccountCreationPluginUid );
       
   163     TAiwGenericParam genericParamUid( EGenericParamError, variant );
       
   164     CAiwGenericParamList& paramList = iServiceHandler->InParamListL();
       
   165     paramList.AppendL( genericParamUid );
       
   166 
       
   167     // Send callback to the customer application.
       
   168     CAiwGenericParamList* nullList = NULL;
       
   169     callback->HandleNotifyL( 
       
   170         KAiwCmdCSCUiExtensionPlugins,
       
   171         KAiwEventStopped,
       
   172         *nullList,
       
   173         paramList );
       
   174 
       
   175     ACPLOG( "CAccountCreationPlugin::SendCompletedCallbackL end" );
       
   176     }
       
   177 
       
   178 // ---------------------------------------------------------------------------
       
   179 // CAccountCreationPlugin::SendErrorCallbackL
       
   180 // Sends AIW service command when plugin error is reached.
       
   181 // ---------------------------------------------------------------------------
       
   182 //
       
   183 void CAccountCreationPlugin::SendErrorCallbackL() const
       
   184     {
       
   185     ACPLOG( "CAccountCreationPlugin::SendErrorCallbackL begin" );
       
   186 
       
   187     MAiwNotifyCallback* callback = 
       
   188         const_cast<MAiwNotifyCallback*>( iNotifyCallback );
       
   189 
       
   190     // UID of ACP.
       
   191     TAiwVariant variant( KAccountCreationPluginUid );
       
   192     TAiwGenericParam genericParamUid( EGenericParamError, variant );
       
   193     CAiwGenericParamList& paramList = iServiceHandler->InParamListL();
       
   194     paramList.AppendL( genericParamUid );
       
   195 
       
   196     // Send callback to the customer application.
       
   197     CAiwGenericParamList* nullList = NULL;
       
   198     callback->HandleNotifyL( 
       
   199         KAiwCmdCSCUiExtensionPlugins,
       
   200         KAiwEventError,
       
   201         *nullList,
       
   202         paramList );
       
   203 
       
   204     ACPLOG( "CAccountCreationPlugin::SendErrorCallbackL end" );
       
   205     }    
       
   206 
       
   207 // ---------------------------------------------------------------------------
       
   208 // CAccountCreationPlugin::CompareUids
       
   209 // Compares AIW service command connected uid to our plugin uid.
       
   210 // ---------------------------------------------------------------------------
       
   211 //
       
   212 TBool CAccountCreationPlugin::CompareUids( 
       
   213     const CAiwGenericParamList& aOutParamList ) const
       
   214     {
       
   215     TInt index = 0;
       
   216     TBool commandForUs( EFalse );
       
   217     if ( 0 < aOutParamList.Count() )
       
   218         {
       
   219         // Take out the first parameter which is uid of the target plugin.                   
       
   220         const TAiwGenericParam* genericParam = NULL; 
       
   221         genericParam = aOutParamList.FindFirst( index,
       
   222                                                 EGenericParamError,
       
   223                                                 EVariantTypeTUid );
       
   224         if ( genericParam )
       
   225             {
       
   226             if ( KAccountCreationPluginUid == genericParam->Value().AsTUid() )
       
   227                 {
       
   228                 commandForUs = ETrue; // Request is for us.
       
   229                 }
       
   230             }
       
   231         }
       
   232 
       
   233     ACPLOG2( "CAccountCreationPlugin::CompareUids: forUs=%d", commandForUs );
       
   234     return commandForUs;  
       
   235     }  
       
   236 
       
   237 // ---------------------------------------------------------------------------
       
   238 // CAccountCreationPlugin::LaunchPluginUiL
       
   239 // Launches ACP UI.
       
   240 // ---------------------------------------------------------------------------
       
   241 //
       
   242 void CAccountCreationPlugin::LaunchPluginUiL()
       
   243     {
       
   244     ACPLOG( "CAccountCreationPlugin::LaunchPluginUiL begin" );
       
   245  
       
   246         CAknViewAppUi* ui = 
       
   247             static_cast<CAknViewAppUi*> ( static_cast<CAknAppUi*>
       
   248                 ( iEikEnv->EikAppUi() ) );
       
   249 
       
   250 
       
   251     // Create provider list view and activate it.
       
   252     if ( NULL == iProviderListView )
       
   253         {
       
   254             iProviderListView = CAcpProviderListView::NewL( *this,
       
   255                                                             iLaunchedFromAI,
       
   256 															*iEikEnv );
       
   257         
       
   258         ui->AddViewL( iProviderListView ); // Ownership is transferred.
       
   259         }
       
   260     
       
   261     if ( iLaunchedFromAI )
       
   262         {
       
   263         TVwsViewId tvwsViewId( KAIAppUid, TUid::Uid( 1 ) );
       
   264         ui->ActivateViewL( tvwsViewId );
       
   265         }
       
   266     
       
   267     iProviderListView->DownloadProviderListL();
       
   268 
       
   269     ACPLOG( "CAccountCreationPlugin::LaunchPluginUiL end" );
       
   270     }
       
   271 
       
   272 // ---------------------------------------------------------------------------
       
   273 // CAccountCreationPlugin::HandleServiceCmdL
       
   274 // From class CAiwServiceIfBase.
       
   275 // Handles AIW service events from customer application.
       
   276 // ---------------------------------------------------------------------------
       
   277 //
       
   278 void CAccountCreationPlugin::HandleServiceCmdL( 
       
   279     const TInt& /*aCmdId*/,
       
   280     const CAiwGenericParamList& /*aInParamList*/,
       
   281     CAiwGenericParamList& aOutParamList,
       
   282     TUint aCmdOptions,
       
   283     const MAiwNotifyCallback* aCallback )
       
   284     {
       
   285     ACPLOG2( 
       
   286         "CAccountCreationPlugin::HandleServiceCmdL: cmd=%d", aCmdOptions );
       
   287     
       
   288       if ( aCallback )
       
   289         {
       
   290         iNotifyCallback = aCallback;
       
   291         }
       
   292     
       
   293     if ( aCmdOptions == ELaunchedFromAI )
       
   294         {
       
   295         iLaunchedFromAI = ETrue;
       
   296         aCmdOptions = EExecute; 
       
   297         }
       
   298     
       
   299     switch ( aCmdOptions )
       
   300         {
       
   301         case EInitialize: // Initialization.
       
   302             {
       
   303             SendInitializedCallbackL();
       
   304             break;
       
   305             }
       
   306         case EExecute: // Execution.
       
   307             {
       
   308             // Check that service event is meant to us and launch plugin.
       
   309             if ( CompareUids( aOutParamList ) )
       
   310                 {
       
   311                 LaunchPluginUiL();
       
   312                 }
       
   313             break;
       
   314             }
       
   315         default: // Not supported.
       
   316             {
       
   317             User::Leave( KErrNotSupported );
       
   318             break;    
       
   319             }
       
   320         }
       
   321     }
       
   322 
       
   323 // ---------------------------------------------------------------------------
       
   324 // CAccountCreationPlugin::InitialiseL
       
   325 // From class MAccountCreationPluginObserver.
       
   326 // ---------------------------------------------------------------------------
       
   327 //
       
   328 void CAccountCreationPlugin::InitialiseL( 
       
   329     MAiwNotifyCallback& /*aFrameworkCallback*/,
       
   330     const RCriteriaArray& /*aInterest*/ )
       
   331     {
       
   332     }
       
   333 
       
   334 // ---------------------------------------------------------------------------
       
   335 // CAccountCreationPlugin::NotifyAiwEventL
       
   336 // From class MAccountCreationPluginObserver.
       
   337 // ---------------------------------------------------------------------------
       
   338 //
       
   339 void CAccountCreationPlugin::NotifyAiwEventL( TInt aError )
       
   340     {
       
   341     ACPLOG2( "CAccountCreationPlugin::NotifyAiwEventL: error=%d", aError );
       
   342 
       
   343     // In case of error, send error callback to customer application.
       
   344     if ( aError )
       
   345         {
       
   346         SendErrorCallbackL();
       
   347         }
       
   348     // If successful event retrieved, send completed callback to customer.    
       
   349     else
       
   350         {
       
   351         SendCompletedCallbackL();
       
   352         }    
       
   353     }
       
   354 
       
   355 // ---------------------------------------------------------------------------
       
   356 // CAccountCreationPlugin::NotifySISDownloaded
       
   357 // From class MAccountCreationPluginObserver.
       
   358 // ---------------------------------------------------------------------------
       
   359 //
       
   360 void CAccountCreationPlugin::NotifySISDownloaded( TDesC& aFileName )
       
   361     {
       
   362     ACPLOG( "CAccountCreationPlugin::NotifySISDownloaded IN" );
       
   363     
       
   364     // Create the installer.
       
   365     SwiUI::RSWInstLauncher launcher; 
       
   366     SwiUI::TInstallOptions options;
       
   367     SwiUI::TInstallOptionsPckg optionsPckg;  
       
   368 
       
   369     // Set necessary options.
       
   370     options.iUpgrade = SwiUI::EPolicyNotAllowed;
       
   371     options.iOCSP = SwiUI::EPolicyNotAllowed;
       
   372     options.iUntrusted = SwiUI::EPolicyNotAllowed; 
       
   373     options.iCapabilities = SwiUI::EPolicyNotAllowed;               
       
   374     optionsPckg = options;  
       
   375 
       
   376     TInt err = launcher.Connect();
       
   377 
       
   378     // Check whether connected or not.
       
   379     if ( err == KErrNone )
       
   380         {           
       
   381         ACPLOG( "CAccountCreationPlugin::NotifySISDownloaded INSTALL 1" );
       
   382         
       
   383         // Launch the installer and install requested file on phone.
       
   384         launcher.Install( aFileName, optionsPckg );
       
   385         
       
   386         ACPLOG( "CAccountCreationPlugin::NotifySISDownloaded INSTALL 2" );
       
   387         }
       
   388     
       
   389     TRAP_IGNORE( SendCompletedCallbackL() );
       
   390     
       
   391     launcher.Close();
       
   392     
       
   393     ACPLOG( "CAccountCreationPlugin::NotifySISDownloaded OUT" );
       
   394     }
       
   395 
       
   396 // End of file.