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