smartinstaller/adm/src/ADMAppUi.cpp
branchADM
changeset 48 364021cecc90
equal deleted inserted replaced
47:3f419852be07 48:364021cecc90
       
     1 /*
       
     2 * Copyright (c) 2009-2010 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: 
       
    15 *     CADMAppUi implementation
       
    16 *
       
    17 *
       
    18 */
       
    19 
       
    20 
       
    21 // INCLUDE FILES
       
    22 #include <ADM.rsg>
       
    23 #include <ADM.mbg>
       
    24 #include <bacline.h>
       
    25 #include <COEUTILS.H>
       
    26 #include <mmtsy_names.h>    // Phone information
       
    27 #include <hal.h>            // Hal::GetData()
       
    28 #include <PathInfo.h>       // PathInfo::
       
    29 #include <sysutil.h>        // SysUtil::DiskSpaceBelowCriticalLevel(), GetSWVersion()
       
    30 #include <stringloader.h>   // StringLoader::LoadLC()
       
    31 #include <aknquerydialog.h>
       
    32 #include <aknnotewrappers.h>
       
    33 #include <avkon.rsg>        // Default dialogs
       
    34 #include <BAUTILS.H>
       
    35 #include <rconnmon.h>
       
    36 #include "ADM.hrh"
       
    37 #include "ADM.pan"
       
    38 #include "ADMApplication.h"
       
    39 #include "ADMAppUi.h"
       
    40 #include "ADMStateMachine.h"
       
    41 #include "ADMXmlParser.h"
       
    42 #include "ADMSisParser.h"
       
    43 #include "ADMPackageInfo.h"
       
    44 #include "ADMDownloadHandler.h"
       
    45 #include "ADMInstallManager.h"
       
    46 #include "networkstatuslistener.h"
       
    47 
       
    48 #include "debug.h"
       
    49 #include "globals.h"
       
    50 #include "config.h"
       
    51 #include "macros.h"
       
    52 #include "utils.h"
       
    53 
       
    54 #ifdef USE_LOGFILE
       
    55 _LIT(KADMLogDir, "ADM");
       
    56 _LIT(KADMLogFileName, "log.txt" );
       
    57 _LIT(KADMLogFile, "?:\\logs\\ADM\\log.txt");
       
    58 #endif
       
    59 
       
    60 /**
       
    61  * Download path for dependency packages
       
    62  */
       
    63 _LIT(KADMFolderPath,"?:\\system\\adm\\");
       
    64 
       
    65 // ============================ MEMBER FUNCTIONS ===============================
       
    66 void CADMAppUi::ConstructL()
       
    67 	{
       
    68 	LOG( "+ CADMAppUi::ConstructL()" );
       
    69 
       
    70 	// Hide from application task list
       
    71 	HideApplicationFromFSW();
       
    72 
       
    73 	// Initialise app UI with standard value.
       
    74 	BaseConstructL( ENoScreenFurniture /*CAknAppUi::EAknEnableSkin*/);
       
    75 	StatusPane()->MakeVisible(EFalse);
       
    76 
       
    77 	// Set download path
       
    78 	TChar systemDrive;
       
    79 	RFs::DriveToChar(RFs::GetSystemDrive(), systemDrive);
       
    80 	HBufC* downloadPath = KADMFolderPath().AllocLC();
       
    81 	downloadPath->Des()[0] = systemDrive;
       
    82 
       
    83 	// Create the state machine
       
    84 	iStateMachine = CStateMachine::NewL(*this, *downloadPath);
       
    85 
       
    86 	iRfs = iEikonEnv->FsSession();
       
    87 
       
    88 	iOviStoreRunning = CUtils::OviStoreRunning();
       
    89 
       
    90 	// Process command line arguments
       
    91 	ProcessCommandLineArgsL();
       
    92 
       
    93 	iProgress = CProgressDialog::NewL(*this);
       
    94 
       
    95 	// If we don't have exit reason set, we can show the progress already
       
    96 	if (iExitReason == EExitNoError)
       
    97 		{
       
    98 		// Show progress bar with little progress already early on
       
    99 		const TInt waitNoteRes = iResumingInstallation
       
   100 				? R_ADM_CONTINUING_INST_TEXT
       
   101 				: R_ADM_VERIFYING_SW_TEXT;
       
   102 		ShowGlobalProgressL( waitNoteRes, 1, 10 );
       
   103 		}
       
   104 
       
   105 	iSwVersion = HBufC::NewL(KSysUtilVersionTextLength);
       
   106 
       
   107 	// Initialize the telephone server
       
   108 	User::LeaveIfError( iTelServer.Connect() );
       
   109 	User::LeaveIfError( iTelServer.LoadPhoneModule( KMmTsyModuleName ) );
       
   110 	User::LeaveIfError( iPhone.Open( iTelServer, KMmTsyPhoneName ) );
       
   111 
       
   112 	// Get device information
       
   113 	User::LeaveIfError( GetPhoneInformation() );
       
   114 
       
   115 	// Ignore the return code. Default URL will be used if error happens (leaves if no memory)
       
   116 	ReadConfigurationL();
       
   117 
       
   118 	ReadStaticResourcesL();
       
   119 
       
   120 	// Kick the state machine running
       
   121 	iStateMachine->Start();
       
   122 
       
   123 	CleanupStack::PopAndDestroy(downloadPath);
       
   124 
       
   125 	LOG( "- CADMAppUi::ConstructL()" );
       
   126 	}
       
   127 
       
   128 // -----------------------------------------------------------------------------
       
   129 // CADMAppUi::CADMAppUi()
       
   130 // C++ default constructor can NOT contain any code, that might leave.
       
   131 // -----------------------------------------------------------------------------
       
   132 //
       
   133 CADMAppUi::CADMAppUi() :
       
   134 		iExitReason(EExitNoError),
       
   135 		iIAP(KInvalidIapId),
       
   136 		iIsResumeRequired(ETrue)
       
   137 	{
       
   138 	// disable possible transition effects
       
   139 	SetFullScreenApp(EFalse);
       
   140 	INIT_DEBUG_LOG( KADMLogFile(), KADMLogDir, KADMLogFileName );
       
   141 	LOG( "CADMAppUi::CADMAppUi()" );
       
   142 	// Restore our thread priority to normal, we have been launched
       
   143 	// with EPriorityBackground
       
   144 //	RThread().SetPriority(EPriorityNormal);
       
   145 	}
       
   146 
       
   147 // -----------------------------------------------------------------------------
       
   148 // CADMAppUi::~CADMAppUi()
       
   149 // Destructor.
       
   150 // -----------------------------------------------------------------------------
       
   151 //
       
   152 CADMAppUi::~CADMAppUi()
       
   153 	{
       
   154 	LOG( "CADMAppUi::~CADMAppUi()" );
       
   155 
       
   156 	// Stop the state machine
       
   157 	iStateMachine->Stop();
       
   158 
       
   159 	// Just be make sure that all global stuff is out from the screen
       
   160 	CancelProgressBar();
       
   161 	CancelWaitNote();
       
   162 
       
   163 	iPhone.Close();
       
   164 	iTelServer.Close();
       
   165 
       
   166 	DELETE_IF_NONNULL( iQueryMessage            );
       
   167 	DELETE_IF_NONNULL( iGlobalConfirmationQuery );
       
   168 	DELETE_IF_NONNULL( iGlobalQueryObserver     );
       
   169 	delete iAppIconFilename;
       
   170 	delete iMainAppName;
       
   171 	delete iConfigUrl;
       
   172 	delete iSwVersion;
       
   173 	delete iProgress;
       
   174 	delete iDepFileName;
       
   175 	delete iSisFileName;
       
   176 	delete iStateMachine;
       
   177 
       
   178 	CLOSE_DEBUG_LOG;
       
   179 	}
       
   180 
       
   181 // -----------------------------------------------------------------------------
       
   182 // Processes the command line parameters and sets state machine initial
       
   183 // state according to the parameters.
       
   184 //
       
   185 // Requires that the state machine has been instantiated (iStateMachine).
       
   186 // -----------------------------------------------------------------------------
       
   187 //
       
   188 void CADMAppUi::ProcessCommandLineArgsL()
       
   189 	{
       
   190 	LOG( "+ ProcessCommandLineArgsL()" );
       
   191 	CCommandLineArguments* args = CCommandLineArguments::NewLC();
       
   192 	const TInt count = args->Count();
       
   193 
       
   194 #ifdef FEATURE_INSTALL_RESUME
       
   195 	// If ADM is launched from the menu, we don't get any command line parameters
       
   196 	// Need to read the info from the resume info file, if it exists.
       
   197 	if (count == 1)
       
   198 		{
       
   199 		CleanupStack::PopAndDestroy(args);
       
   200 		const TInt ret = ReadResumeInfoL();
       
   201 		if (ret != KErrNone)
       
   202 			{
       
   203 			ShowGlobalNoteL(EAknGlobalErrorNote, R_ADM_ERR_NO_PENDING_INSTALLATIONS_TEXT);
       
   204 			ExitApp();
       
   205 			}
       
   206 		iResumingInstallation = ETrue;
       
   207 		return;
       
   208 		}
       
   209 #else
       
   210 	if (count == 1)
       
   211 		{
       
   212 		User::Leave( KErrNotSupported );
       
   213 		}
       
   214 #endif // FEATURE_INSTALL_RESUME
       
   215 
       
   216 	// index to the command line args, starting at 1 (0 = executable name)
       
   217 	TInt index = 1;
       
   218 
       
   219 #ifdef DO_LOG
       
   220 	for (int i = 0; i < count; i++)
       
   221 		{
       
   222 		LOG3( "Arg[%d]='%S'", i, &(args->Arg(i)) );
       
   223 		}
       
   224 #endif
       
   225 
       
   226 	TPtrC arg = args->Arg(index++);
       
   227 	TLex lex(arg);
       
   228 	TUint32 protocolVerRaw = 0;
       
   229 	TUint32 protocolVer = 0;
       
   230 	TUint32 tmp;
       
   231 	if ( lex.Val(protocolVerRaw, EDecimal) == 0)
       
   232 		{
       
   233 		LOG3( "(cmd) pVer(raw) = %d (%03x)", protocolVerRaw, protocolVerRaw );
       
   234 		protocolVer = (protocolVerRaw & KCmdLineBitProtocolVerMask);
       
   235 		}
       
   236 	else
       
   237 		{
       
   238 		LOG( "Invalid P/BVersion, PANIC" );
       
   239 		Panic(EPanicAdmCmdLineArgs);
       
   240 		}
       
   241 
       
   242 	if (protocolVer < 15)
       
   243 		{
       
   244 		// assume it's old version without the bit field support
       
   245 		LOG2( "Using old args %d", protocolVer );
       
   246 
       
   247 		// Following are the command line args passed in the old version of Bootstrap:
       
   248 		// arg 0 - ADM.exe
       
   249 		// arg 1 - Bootstrap Version
       
   250 		// arg 2 - WrapperUid
       
   251 		// arg 3 - IAP
       
   252 		// arg 4 - Sisfilename
       
   253 		// arg 5 - Depfilename (optional)
       
   254 
       
   255 		// Get the Bootstrap version
       
   256 		iBootstrapVersion = protocolVer;
       
   257 		LOG2("(cmd) BVersion: %x", iBootstrapVersion);
       
   258 
       
   259 		// Get the Wrapper uid
       
   260 		TPtrC uidPtr = args->Arg(index++);
       
   261 		lex.Assign(uidPtr);
       
   262 		TUint32 uid = 0;
       
   263 		if ( lex.Val(uid, EDecimal ) == 0)
       
   264 			{
       
   265 			LOG2("(cmd) Wrapper Uid: 0x%x", uid);
       
   266 
       
   267 			iWrapperPackageUid = TUid::Uid(uid);
       
   268 			}
       
   269 
       
   270 		// See if at least the minimum options required are provided
       
   271 		if (count < 5)
       
   272 			{
       
   273 			LOG2( "Incorrect # of arguments (%d) passed from bootstrap, PANIC", count );
       
   274 			Panic(EPanicAdmCmdLineArgs);
       
   275 			}
       
   276 
       
   277 		// Get Iap
       
   278 		TPtrC iapPtr = args->Arg(index++);
       
   279 		lex.Assign(iapPtr);
       
   280 		if ( lex.Val(iIAP, EDecimal) == 0 )
       
   281 			{
       
   282 			LOG2("(cmd) IAP: %d", iIAP);
       
   283 			iStateMachine->SetIAP(iIAP);
       
   284 			}
       
   285 
       
   286 		switch (iBootstrapVersion)
       
   287 			{
       
   288 			case 1:
       
   289 			case 2:
       
   290 				{
       
   291 				if ( count != 6 )
       
   292 					{
       
   293 					LOG2( "Incorrect # of arguments (%d) passed from bootstrap, PANIC", count );
       
   294 					Panic(EPanicAdmCmdLineArgs);
       
   295 					}
       
   296 				iDepFileName = args->Arg(index++).AllocL();
       
   297 				LOG2( "(cmd) DepFile: '%S'", iDepFileName);
       
   298 
       
   299 				iSisFileName = args->Arg(index++).AllocL();
       
   300 				LOG2( "(cmd) AppSis: '%S'", iSisFileName);
       
   301 				break;
       
   302 				}
       
   303 			case 3:
       
   304 				{
       
   305 				iDepFileName = args->Arg(index++).AllocL();
       
   306 				LOG2( "(cmd) DepFile: '%S'", iDepFileName);
       
   307 				break;
       
   308 				}
       
   309 			case 4:
       
   310 				{
       
   311 				iSisFileName = args->Arg(index++).AllocL();
       
   312 				LOG2( "(cmd) AppSis: '%S'", iSisFileName);
       
   313 				break;
       
   314 				}
       
   315 			default:
       
   316 				LOG2( "Invalid BVersion %d, PANIC", iBootstrapVersion );
       
   317 				Panic(EPanicAdmCmdLineArgs);
       
   318 				break;
       
   319 			}
       
   320 		}
       
   321 	else if (protocolVer == 15)
       
   322 		{
       
   323 		LOG( "Using new args" );
       
   324 
       
   325 		// Command line arguments, version 15 specification:
       
   326 		//
       
   327 		//31               9  8  7  6  5  4  3  2  1  0
       
   328 		// +-------------+--+--+--+--+--+--+--+--+--+--+
       
   329 		// | reserved    |  |  |  |  |  |  |           |
       
   330 		// +-------------+--+--+--+--+--+--+--+--+--+--+
       
   331 		//
       
   332 		//      value
       
   333 		// bits range description
       
   334 		//  0-3  0-15 Command line parameter protocol version:
       
   335 		//             0 = not supported
       
   336 		//             1 = ADM.exe 1 <wrapper_uid> <iap> <depfile> <sisfile>
       
   337 		//             2 = ADM.exe 2 <wrapper_uid> <iap> <depfile> <sisfile>
       
   338 		//             3 = ADM.exe 3 <wrapper_uid> <iap> <depfile>
       
   339 		//             4 = ADM.exe 4 <wrapper_uid> <iap> <sisfile> (this was used in beta1, beta2)
       
   340 		//            15 = ADM.exe 15 [parameters as specified by other bits]
       
   341 		//
       
   342 		//         since
       
   343 		//  bit  version type command line parameter present
       
   344 		//    4      4     N  Bootstrap version number
       
   345 		//    5      4     N  Wrapper UID
       
   346 		//    6      4     N  IAP
       
   347 		//    7      4     N  ADM launch condition code:
       
   348 		//                    KCmdLineCancelAdm: ADM needs to cancel installation
       
   349 		//                    KCmdLineLaunchAdm: ADM starts normally
       
   350 		//    8      4     S  Full path to dependency XML file
       
   351 		//    9      4     S  Full path to application SIS file
       
   352 		//
       
   353 		// Types:
       
   354 		//  N  Natural decimal number (range 0 - 2^32-1, fits to TUint32)
       
   355 		//  S  UTF-8 string, must NOT contains spaces or other whitespaces
       
   356 		//
       
   357 		// Command line parameters appear in the order of the bits set, i.e.
       
   358 		// if bits 4, 8, 9 are set the command line parameters are:
       
   359 		// ADM.exe 784 <bootstrap_version> <dep_file> <sis_file>
       
   360 		//
       
   361 		// If command line protocol version is less than 15, it is assumed that
       
   362 		// old version command line parameter format is used.
       
   363 		//
       
   364 
       
   365 		// new version. bit fields define which parameters are present
       
   366 		// these has to be processed in the right order: from LSB to MSB
       
   367 		if (protocolVerRaw & KCmdLineBitBootstrapVersion)
       
   368 			{
       
   369 			TPtrC arg = args->Arg(index++);
       
   370 			lex.Assign(arg);
       
   371 			if ( lex.Val(iBootstrapVersion) == 0 )
       
   372 				{
       
   373 				LOG2( "(cmd) BVersion: %x", iBootstrapVersion );
       
   374 				}
       
   375 			else
       
   376 				{
       
   377 				LOG( "Invalid BVersion" );
       
   378 				Panic(EPanicAdmCmdInvalidBootstrap);
       
   379 				}
       
   380 			}
       
   381 		if (protocolVerRaw & KCmdLineBitWrapperUid)
       
   382 			{
       
   383 			TPtrC arg = args->Arg(index++);
       
   384 			lex.Assign(arg);
       
   385 			if ( lex.Val(tmp, EDecimal) == 0 )
       
   386 				{
       
   387 				LOG2("(cmd) Wrapper Uid: 0x%x", tmp);
       
   388 				iWrapperPackageUid = TUid::Uid(tmp);
       
   389 				}
       
   390 			else
       
   391 				{
       
   392 				LOG( "Invalid wrapper package UID" );
       
   393 				Panic(EPanicAdmCmdInvalidWrapperUid);
       
   394 				}
       
   395 			}
       
   396 		if (protocolVerRaw & KCmdLineBitIAP)
       
   397 			{
       
   398 			TPtrC arg = args->Arg(index++);
       
   399 			lex.Assign(arg);
       
   400 			if ( lex.Val(iIAP, EDecimal) == 0 )
       
   401 				{
       
   402 				LOG2("(cmd) IAP: %d", iIAP);
       
   403 				iStateMachine->SetIAP(iIAP);
       
   404 				}
       
   405 			else
       
   406 				{
       
   407 				LOG( "Invalid IAP" );
       
   408 				Panic(EPanicAdmCmdInvalidIAP);
       
   409 				}
       
   410 			}
       
   411 		if (protocolVerRaw & KCmdLineBitADMLaunchControl)
       
   412 			{
       
   413 			TPtrC arg = args->Arg(index++);
       
   414 			lex.Assign(arg);
       
   415 			if ( lex.Val(tmp, EDecimal) == 0 )
       
   416 				{
       
   417 				LOG2("(cmd) LState %d", tmp);
       
   418 				switch (tmp)
       
   419 					{
       
   420 				case KCmdLineLaunchAdm:
       
   421 					// this is valid, nothing needs to be done
       
   422 					break;
       
   423 				case KCmdLineCancelAdmNoResume:
       
   424 					iIsResumeRequired = EFalse;
       
   425 					// fall-through
       
   426 				case KCmdLineCancelAdm:
       
   427 					iStateMachine->SetStartState(CStateFactory::EStatePrepareExitWithError);
       
   428 					iStateMachine->SetFailureReason(EUserCancelled);
       
   429 					break;
       
   430 				default:
       
   431 					LOG2( "Invalid LState %d, PANIC", tmp );
       
   432 					Panic(EPanicAdmCmdInvalidLaunchState2);
       
   433 					break;
       
   434 					} // switch
       
   435 				}
       
   436 			else
       
   437 				{
       
   438 				LOG( "Invalid LState, PANIC" );
       
   439 				Panic(EPanicAdmCmdInvalidLaunchState);
       
   440 				}
       
   441 			}
       
   442 		if (protocolVerRaw & KCmdLineBitFileDep)
       
   443 			{
       
   444 			iDepFileName = args->Arg(index++).AllocL();
       
   445 			LOG2( "(cmd) DepFile: '%S'", iDepFileName);
       
   446 			}
       
   447 		if (protocolVerRaw & KCmdLineBitFileSis)
       
   448 			{
       
   449 			iSisFileName = args->Arg(index++).AllocL();
       
   450 			LOG2( "(cmd) SisFile: '%S'", iSisFileName);
       
   451 			}
       
   452 		}
       
   453 	else
       
   454 		{
       
   455 		LOG2( "Invalid PVersion %d, PANIC", protocolVer );
       
   456 		Panic(EPanicAdmCmdInvalidProtocol);
       
   457 		}
       
   458 	CleanupStack::PopAndDestroy(args);
       
   459 
       
   460 	LOG3( "- ProcessCommandLineArgsL(): %d->%d", count, index );
       
   461 	}
       
   462 
       
   463 // -----------------------------------------------------------------------------
       
   464 // Read the information from the resume info file, if launched from the menu.
       
   465 // -----------------------------------------------------------------------------
       
   466 //
       
   467 TInt CADMAppUi::ReadResumeInfoL()
       
   468 	{
       
   469 	LOG( "+ ReadResumeInfo()" );
       
   470 	RArray< TPtrC > lineBuffer;
       
   471 	TInt err = 0;
       
   472 	HBufC* buffer = ReadConfigFile( iRfs, KADMResumeInfoFile, lineBuffer, err );
       
   473 
       
   474 	if ( buffer && err == KErrNone )
       
   475 		{
       
   476 		// Read the main application name
       
   477 		TPtrC namePtr = GetConfigValue( KRFieldAppName, lineBuffer, err );
       
   478 		if ( err == KErrNone )
       
   479 			{
       
   480 			iMainAppName = namePtr.AllocL();
       
   481 			LOG2( "Resuming '%S'", iMainAppName );
       
   482 			}
       
   483 
       
   484 		// Get BootstrapVersion from the resume info file
       
   485 		TPtrC bootstrapVersionLine = GetConfigValue( KRFieldBootstrap, lineBuffer, err );
       
   486 		if ( err == KErrNone )
       
   487 			{
       
   488 			TLex lex(bootstrapVersionLine);
       
   489 			if ( lex.Val(iBootstrapVersion) == 0 )
       
   490 				{
       
   491 				LOG2( "(resume) Version: %d", iBootstrapVersion );
       
   492 				}
       
   493 			else
       
   494 				{
       
   495 				// TODO: Error: Can this ever happen?!
       
   496 				//LOG( "Incorrect version in the resume info" );
       
   497 				return KErrNotSupported;
       
   498 				}
       
   499 			}
       
   500 		else
       
   501 			{
       
   502 			LOG2( "Failed to read version from the resume info (%d)", err );
       
   503 			return err;
       
   504 			}
       
   505 		}
       
   506 	else
       
   507 		{
       
   508 		LOG( "! No resume information, cannot continue" );
       
   509 		// Resume information file doesn't exist
       
   510 		return err;
       
   511 		}
       
   512 
       
   513 	// Get the Wrapper uid
       
   514 	TPtrC uidPtr = GetConfigValue( KRFieldWrapperPkgUid, lineBuffer, err );
       
   515 	if ( err == KErrNone )
       
   516 		{
       
   517 		TLex lex(uidPtr);
       
   518 		TUint32 uid = 0;
       
   519 		if ( lex.Val(uid, EDecimal ) == 0)
       
   520 			{
       
   521 			LOG2( "Wrapper Uid: 0x%x", uid );
       
   522 			iWrapperPackageUid = TUid::Uid(uid);
       
   523 			}
       
   524 		else
       
   525 			{
       
   526 			//LOG( "Incorrect wrapper UID in resume info" );
       
   527 			return KErrNotSupported;
       
   528 			}
       
   529 		}
       
   530 	else
       
   531 		{
       
   532 		LOG2( "Failed to read wrapper UID from the resume info (%d)", err );
       
   533 		return err;
       
   534 		}
       
   535 
       
   536 	switch (iBootstrapVersion)
       
   537 		{
       
   538 		case 1:
       
   539 		case 2:
       
   540 		case 3:
       
   541 			{
       
   542 			// Get AppFileName from the resume information file
       
   543 			TPtrC depFileNameLine = GetConfigValue( KRFieldDepFileName, lineBuffer, err );
       
   544 			if ( err == KErrNone )
       
   545 				{
       
   546 				iDepFileName = depFileNameLine.AllocL();
       
   547 
       
   548 				LOG2( "(resume) DepFileName = '%S'", iDepFileName );
       
   549 
       
   550 				if ( !BaflUtils::FileExists(iRfs, *iDepFileName) )
       
   551 					{
       
   552 					LOG2( "(resume) DepFile '%S' missing, cannot continue!", iDepFileName );
       
   553 					return KErrNotFound;
       
   554 					}
       
   555 				}
       
   556 			else
       
   557 				{
       
   558 				LOG2( "Failed to read from the resume info (%d)", err );
       
   559 				return err;
       
   560 				}
       
   561 			}
       
   562 			break;
       
   563 		case 4:
       
   564 		default:
       
   565 			break;
       
   566 		}
       
   567 
       
   568 	switch (iBootstrapVersion)
       
   569 		{
       
   570 		case 1:
       
   571 		case 2:
       
   572 		case 4:
       
   573 			{
       
   574 			// Get AppFileName from the resume info file
       
   575 			TPtrC appFileNameLine = GetConfigValue( KRFieldAppFileName, lineBuffer, err );
       
   576 			if ( err == KErrNone )
       
   577 				{
       
   578 				iSisFileName = appFileNameLine.AllocL();
       
   579 
       
   580 				LOG2( "(resume) AppSis = '%S'", iSisFileName );
       
   581 
       
   582 				if ( !BaflUtils::FileExists(iRfs, *iSisFileName) )
       
   583 					{
       
   584 					LOG2( "(resume) AppSis '%S' missing, cannot continue!", iSisFileName );
       
   585 					return KErrNotFound;
       
   586 					}
       
   587 				}
       
   588 			else
       
   589 				{
       
   590 				LOG2( "Failed to read from the resume info (%d)", err );
       
   591 				return err;
       
   592 				}
       
   593 			}
       
   594 			break;
       
   595 		case 3:
       
   596 		default:
       
   597 			break;
       
   598 		}
       
   599 	LOG2( "- ReadResumeInfo(): ret=%d", err );
       
   600 	return err;
       
   601 	}
       
   602 
       
   603 // -----------------------------------------------------------------------------
       
   604 // Handles WindowServer events. Used to catch 'End Call' key.
       
   605 // -----------------------------------------------------------------------------
       
   606 //
       
   607 void CADMAppUi::HandleWsEventL( const TWsEvent& aEvent, CCoeControl* aDestination )
       
   608 	{
       
   609 	if ( aEvent.Key()->iCode == EKeyPhoneEnd )
       
   610 		{
       
   611 		iStateMachine->HandleUserResponse( EKeyPhoneEnd );
       
   612 		}
       
   613 	else
       
   614 		{
       
   615 		CEikAppUi::HandleWsEventL( aEvent, aDestination );
       
   616 		}
       
   617 	}
       
   618 
       
   619 // -----------------------------------------------------------------------------
       
   620 // CADMAppUi::HandleCommandL()
       
   621 // Takes care of command handling.
       
   622 // -----------------------------------------------------------------------------
       
   623 //
       
   624 void CADMAppUi::HandleCommandL(TInt aCommand)
       
   625 	{
       
   626 	switch (aCommand)
       
   627 		{
       
   628 		case EEikCmdExit:
       
   629 		case EAknSoftkeyExit:
       
   630 			Exit();
       
   631 			break;
       
   632 
       
   633 		default:
       
   634 			Panic(EPanicAdmUi);
       
   635 			break;
       
   636 		}
       
   637 	}
       
   638 
       
   639 // -----------------------------------------------------------------------------
       
   640 // Callback CGlobalWaitNote
       
   641 //
       
   642 // Called when global wait note was cancelled
       
   643 // -----------------------------------------------------------------------------
       
   644 //
       
   645 void CADMAppUi::WaitNoteCancelled()
       
   646 	{
       
   647 	LOG2( "! Wait note cancelled (%d)", iStateMachine->StateIndex() );
       
   648 	iStateMachine->HandleUserResponse( EAknSoftkeyCancel );
       
   649 	}
       
   650 
       
   651 // -----------------------------------------------------------------------------
       
   652 // Callback CProgressDialog
       
   653 //
       
   654 // Called when progress dialog was cancelled
       
   655 // -----------------------------------------------------------------------------
       
   656 //
       
   657 void CADMAppUi::ProgressDialogCancelled()
       
   658 	{
       
   659 	LOG2( "! Progress dialog cancelled (%d)", iStateMachine->StateIndex() );
       
   660 	iStateMachine->HandleUserResponse( EAknSoftkeyCancel );
       
   661 	}
       
   662 
       
   663 // -----------------------------------------------------------------------------
       
   664 //
       
   665 // -----------------------------------------------------------------------------
       
   666 //
       
   667 void CADMAppUi::HandleGlobalQueryResponseL(const TInt aResponse)
       
   668 	{
       
   669 	LOG2( "+ HandleGlobalQueryResponseL(): %d", aResponse );
       
   670 	iStateMachine->HandleUserResponse( aResponse );
       
   671 	}
       
   672 
       
   673 // -----------------------------------------------------------------------------
       
   674 //
       
   675 // -----------------------------------------------------------------------------
       
   676 //
       
   677 void CADMAppUi::ShowDownloadQueryL(const TInt aResourceId, const TInt aInfoResourceId)
       
   678 	{
       
   679 	const TInt KMaxDownloadSizeMsg = 32;
       
   680 
       
   681 	if ( iGlobalQueryObserver )
       
   682 		{
       
   683 		iGlobalQueryObserver->Cancel();
       
   684 		delete iGlobalQueryObserver;
       
   685 		iGlobalQueryObserver = NULL;
       
   686 		}
       
   687 	iGlobalQueryObserver = CGlobalQueryObserver::NewL(this, EFalse);
       
   688 
       
   689 	DELETE_IF_NONNULL( iGlobalConfirmationQuery );
       
   690 	DELETE_IF_NONNULL( iQueryMessage );
       
   691 	iGlobalConfirmationQuery = CAknGlobalConfirmationQuery::NewL();
       
   692 
       
   693 	TBuf<KMaxDownloadSizeMsg> dlSizeDescr;
       
   694 	PrettyPrint( iStateMachine->TotalDownloadSize(), dlSizeDescr );
       
   695 
       
   696 	CDesCArrayFlat* strings = new (ELeave) CDesCArrayFlat(3);
       
   697 	CleanupStack::PushL(strings);
       
   698 	HBufC* msg = StringLoader::LoadLC( R_ADM_SW_UPDATE_REQUIRED_TEXT, iEikonEnv );
       
   699 	HBufC* info;
       
   700 	if (aInfoResourceId != -1)
       
   701 		{
       
   702 		info = StringLoader::LoadLC( aInfoResourceId, iEikonEnv );
       
   703 		}
       
   704 	else
       
   705 		{
       
   706 		info = KNullDesC().AllocLC();
       
   707 		}
       
   708 	strings->AppendL(*msg);
       
   709 	strings->AppendL(*info);
       
   710 	strings->AppendL(dlSizeDescr);
       
   711 	iQueryMessage = StringLoader::LoadL( aResourceId, *strings, iEikonEnv );
       
   712 	CleanupStack::PopAndDestroy(3, strings); // strings, msg, info
       
   713 
       
   714 	// Cancel the progress dialog just before querying the user to reduce flicker
       
   715 	CancelProgressBar();
       
   716 
       
   717 	iGlobalConfirmationQuery->ShowConfirmationQueryL(
       
   718 		iGlobalQueryObserver->iStatus,
       
   719 		*iQueryMessage,
       
   720 		0
       
   721 		);
       
   722 	iGlobalQueryObserver->Start();
       
   723 #if 0
       
   724 	const TInt KMaxDownloadSizeMsg = 32;
       
   725 	TBuf<KMaxDownloadSizeMsg> dlSizeDescr;
       
   726 	PrettyPrint( iDepTree->GetTotalDownloadSize(), dlSizeDescr );
       
   727 	HBufC* string = StringLoader::LoadLC( aResourceId, dlSizeDescr, iEikonEnv );
       
   728 
       
   729 	CAknQueryDialog* dlg = CAknQueryDialog::NewL();
       
   730 	const TInt ret = dlg->ExecuteLD( R_AVKON_DIALOG_EMPTY_MENUBAR, *string );
       
   731 
       
   732 	CleanupStack::PopAndDestroy(); // string
       
   733 
       
   734 	return ret;
       
   735 #endif
       
   736 	}
       
   737 
       
   738 // -----------------------------------------------------------------------------
       
   739 // Shows the application launch query dialog
       
   740 // @param aAppName Application name, caption, to be shown to the user
       
   741 // @param aIconFilename Full path to the application icon, KNullDesC if none.
       
   742 // -----------------------------------------------------------------------------
       
   743 //
       
   744 void CADMAppUi::ShowLaunchPromptL(const TDesC& aAppName, const TDesC& aIconFilename)
       
   745 	{
       
   746 	if ( iGlobalQueryObserver )
       
   747 		{
       
   748 		iGlobalQueryObserver->Cancel();
       
   749 		delete iGlobalQueryObserver;
       
   750 		iGlobalQueryObserver = NULL;
       
   751 		}
       
   752 	iGlobalQueryObserver = CGlobalQueryObserver::NewL(this, EFalse);
       
   753 
       
   754 	DELETE_IF_NONNULL( iGlobalConfirmationQuery );
       
   755 	DELETE_IF_NONNULL( iQueryMessage );
       
   756 	iGlobalConfirmationQuery = CAknGlobalConfirmationQuery::NewL();
       
   757 	iQueryMessage = StringLoader::LoadL( R_ADM_LAUNCH_APP_TEXT, aAppName, iEikonEnv );
       
   758 	iGlobalConfirmationQuery->ShowConfirmationQueryL(
       
   759 		iGlobalQueryObserver->iStatus,
       
   760 		*iQueryMessage,
       
   761 		0, // Softkeys
       
   762 		0, // Animation
       
   763 		aIconFilename,
       
   764 		EMbmAdmAdm,      // BitmapId
       
   765 		EMbmAdmAdm_mask  // MaskId
       
   766 		);
       
   767 	iGlobalQueryObserver->Start();
       
   768 	// Cancel the progress dialog and notes after creating the note to reduce flicker
       
   769 	CancelProgressBar();
       
   770 	CancelWaitNote();
       
   771 	}
       
   772 
       
   773 // -----------------------------------------------------------------------------
       
   774 // @param aType Global note type.
       
   775 // @param aResourceId Resource ID to text to be displayed.
       
   776 // -----------------------------------------------------------------------------
       
   777 //
       
   778 TInt CADMAppUi::ShowGlobalNoteL( const TAknGlobalNoteType aType, const TInt aResourceId )
       
   779 	{
       
   780 	// Allocate TBuf with constant length.
       
   781 	TBuf<KMaxMsgSize> text( NULL );
       
   782 
       
   783 	// Do we have a valid resource ID for the note?
       
   784 	if (aResourceId != -1)
       
   785 		{
       
   786 		// Reads a resource into a descriptor.
       
   787 		iEikonEnv->ReadResourceL( text, aResourceId );
       
   788 
       
   789 		if ( iStateMachine->FailedState() == CStateFactory::EStateLast &&
       
   790 				iExitReason != EExitNoError)
       
   791 			{
       
   792 			const TInt error = iStateMachine->FailedState() * 100 + iExitReason;
       
   793 			text.Append('\n');
       
   794 			text.AppendNum( error );
       
   795 			}
       
   796 
       
   797 		// Cancel any progress dialog
       
   798 		CancelProgressBar();
       
   799 		// Cancel any wait notes
       
   800 		CancelWaitNote();
       
   801 
       
   802 		if (aType == EAknGlobalErrorNote )
       
   803 			{
       
   804 			CAknQueryDialog* dlg = CAknQueryDialog::NewL( CAknQueryDialog::EErrorTone );
       
   805 			return dlg->ExecuteLD( R_ADM_EXIT_QUERY, text );
       
   806 			}
       
   807 		else
       
   808 			{
       
   809 			// Create new CAknGlobalNote instance.
       
   810 			CAknGlobalNote* globalNote = CAknGlobalNote::NewLC();
       
   811 			globalNote->ShowNoteL( aType, text );
       
   812 			CleanupStack::PopAndDestroy(globalNote);
       
   813 			}
       
   814 		}
       
   815 	return KErrNone;
       
   816 	}
       
   817 
       
   818 // -----------------------------------------------------------------------------
       
   819 // Shows the exit note with information, how the interrupted/cancelled installation
       
   820 // can be continued.
       
   821 // -----------------------------------------------------------------------------
       
   822 //
       
   823 TInt CADMAppUi::ShowExitNoteL()
       
   824 	{
       
   825 	TInt ret = KErrNone;
       
   826 	// The order of this table must match TExitReason order
       
   827 	static const TInt errorNotes[ELastExitState] = {
       
   828 /* EExitNoError           0 */  -1,
       
   829 /* EUserCancelled         1 */  -1, //R_ADM_INST_CAN_BE_RESUMED_TEXT,
       
   830 /* EDownloadFailed        2 */  R_ADM_ERR_DOWNLOAD_FAILED_TEXT,
       
   831 /* EInsufficientMemory    3 */  R_ADM_ERR_INSTALLATION_NOT_ENOUGH_SPACE_TEXT,
       
   832 /* EDeviceNotSupported    4 */  R_ADM_ERR_INSTALLATION_UNSUPPORTED_DEVICE_TEXT,
       
   833 /* EInstallationFailed    5 */  R_ADM_ERR_INSTALLATION_FAILED_TEXT,
       
   834 /* ERootInstallationFailed  */  -1
       
   835 	};
       
   836 
       
   837 	// First, show an error note describing what went wrong
       
   838 	if (errorNotes[iExitReason] > 0)
       
   839 		{
       
   840 		CAknErrorNote* note = new (ELeave) CAknErrorNote( ETrue );
       
   841 		HBufC* msg = StringLoader::LoadLC( errorNotes[iExitReason], iEikonEnv );
       
   842 		note->ExecuteLD( *msg );
       
   843 		CleanupStack::PopAndDestroy(); // msg
       
   844 		}
       
   845 
       
   846 	if (iExitReason != EDeviceNotSupported)
       
   847 		{
       
   848 		// Then show the "installation can be continued later" information
       
   849 		// but only if the device is a supported one.
       
   850 		CAknQueryDialog* dlg = CAknQueryDialog::NewL( CAknQueryDialog::EErrorTone );
       
   851 		HBufC* oviMsg = NULL;
       
   852 		if (iOviStoreRunning)
       
   853 			{
       
   854 			// TODO: Change ADM so root node would always contain the main application sis information
       
   855 			HBufC* caption = iStateMachine->LaunchCaption();
       
   856 			if (!caption)
       
   857 				{
       
   858 				caption = KNullDesC().AllocL();
       
   859 				}
       
   860 			oviMsg = StringLoader::LoadLC(
       
   861 					R_ADM_INST_CAN_BE_RESUMED_OVI_TEXT,
       
   862 					*caption,
       
   863 					iEikonEnv
       
   864 					);
       
   865 			}
       
   866 		else
       
   867 			{
       
   868 			oviMsg = KNullDesC().AllocLC();
       
   869 			}
       
   870 		HBufC* mainMsg = StringLoader::LoadLC(
       
   871 				R_ADM_INST_CAN_BE_RESUMED_TEXT,
       
   872 				*oviMsg,
       
   873 				iEikonEnv
       
   874 				);
       
   875 		ret = dlg->ExecuteLD( R_ADM_EXIT_QUERY, *mainMsg );
       
   876 		CleanupStack::PopAndDestroy(2, oviMsg);
       
   877 		}
       
   878 	return ret;
       
   879 	}
       
   880 
       
   881 // -----------------------------------------------------------------------------
       
   882 // Creates a wait note displaying given resource ID.
       
   883 // @param aResourceId Resource ID to be shown
       
   884 // @param aCancellable ETrue, if wait note is cancellable
       
   885 // @param aDetailedResourceId Additional resource ID to be shown, -1 if none
       
   886 // -----------------------------------------------------------------------------
       
   887 //
       
   888 void CADMAppUi::ShowWaitNoteL( const TInt aResourceId,
       
   889 		const TBool aCancellable,
       
   890 		const TInt aDetailedResourceId
       
   891 		)
       
   892 	{
       
   893 	TBuf<KMaxMsgSize> resourceMsg;
       
   894 	CancelWaitNote();
       
   895 
       
   896 	if (aDetailedResourceId != -1)
       
   897 		{
       
   898 		iEikonEnv->ReadResourceL( resourceMsg, aDetailedResourceId );
       
   899 		HBufC* msg = StringLoader::LoadL( aResourceId, resourceMsg, iEikonEnv );
       
   900 		resourceMsg.Copy( *msg );
       
   901 		delete msg;
       
   902 		}
       
   903 	else
       
   904 		{
       
   905 		iEikonEnv->ReadResourceL( resourceMsg, aResourceId );
       
   906 		}
       
   907 
       
   908 	iWaitNote = CGlobalWaitNote::NewL(*this, aCancellable );
       
   909 	iWaitNote->ShowNoteL( resourceMsg );
       
   910 	}
       
   911 
       
   912 // -----------------------------------------------------------------------------
       
   913 //
       
   914 // -----------------------------------------------------------------------------
       
   915 //
       
   916 void CADMAppUi::ShowWaitNoteNumL( const TInt aResourceId, const TInt aCurrent, const TInt aLast)
       
   917 	{
       
   918 	CancelWaitNote();
       
   919 
       
   920 	CArrayFix<TInt>* vals = new (ELeave) CArrayFixFlat<TInt>(2);
       
   921 	CleanupStack::PushL(vals);
       
   922 	vals->AppendL(aCurrent);
       
   923 	vals->AppendL(aLast);
       
   924 	HBufC* msg = StringLoader::LoadLC( aResourceId, *vals, iEikonEnv );
       
   925 
       
   926 	iWaitNote = CGlobalWaitNote::NewL( *this, ETrue );
       
   927 	iWaitNote->ShowNoteL( *msg );
       
   928 
       
   929 	CleanupStack::PopAndDestroy(2, vals);
       
   930 	}
       
   931 
       
   932 // -----------------------------------------------------------------------------
       
   933 // Removes currently shown wait note.
       
   934 // -----------------------------------------------------------------------------//
       
   935 //
       
   936 void CADMAppUi::CancelWaitNote()
       
   937 	{
       
   938 	if ( iWaitNote )
       
   939 		{
       
   940 		TRAP_IGNORE( iWaitNote->CancelNoteL() );
       
   941 		delete iWaitNote;
       
   942 		iWaitNote = NULL;
       
   943 		}
       
   944 	}
       
   945 
       
   946 // -----------------------------------------------------------------------------
       
   947 // Removes currently shown progress bar.
       
   948 // -----------------------------------------------------------------------------//
       
   949 //
       
   950 void CADMAppUi::CancelProgressBar()
       
   951 	{
       
   952 	if ( iProgress )
       
   953 		{
       
   954 		iProgress->Cancel();
       
   955 		}
       
   956 	}
       
   957 
       
   958 // -----------------------------------------------------------------------------
       
   959 // ShowGlobalProgressL()
       
   960 //
       
   961 // aResourceId  Resource ID of the text to be shown on the progress bar
       
   962 // aStartValue  Progress bar start value
       
   963 // aEndValue    Progress bar end value
       
   964 // aCurrent     Resource string value0
       
   965 // aLast        Resource string value1
       
   966 // -----------------------------------------------------------------------------
       
   967 //
       
   968 void CADMAppUi::ShowGlobalProgressL(const TInt aResourceId,
       
   969 		const TInt aStartValue, const TInt aEndValue,
       
   970 		const TInt aCurrent, const TInt aLast)
       
   971 	{
       
   972 	HBufC *msg = NULL;
       
   973 	CArrayFix<TInt>* vals = new (ELeave) CArrayFixFlat<TInt>(2);
       
   974 	CleanupStack::PushL(vals);
       
   975 
       
   976 	if (aCurrent != -1)
       
   977 		{
       
   978 		vals->AppendL(aCurrent);
       
   979 		vals->AppendL(aLast);
       
   980 
       
   981 		// Read the resource
       
   982 		msg = StringLoader::LoadLC( aResourceId, *vals, iEikonEnv );
       
   983 		}
       
   984 	else
       
   985 		{
       
   986 		// Read the resource
       
   987 		msg = iEikonEnv->AllocReadResourceLC( aResourceId );
       
   988 
       
   989 		// Special case: append the application name to the string
       
   990 		if (aResourceId == R_ADM_CONTINUING_INST_TEXT)
       
   991 			{
       
   992 			if (iMainAppName && iMainAppName->Length() > 0)
       
   993 				{
       
   994 				HBufC* newmsg = HBufC::NewL(msg->Length() + iMainAppName->Length() + 3);
       
   995 				newmsg->Des().Copy(*msg);
       
   996 				newmsg->Des().Append('\n');
       
   997 				newmsg->Des().Append('\'');
       
   998 				newmsg->Des().Append(*iMainAppName);
       
   999 				newmsg->Des().Append('\'');
       
  1000 				CleanupStack::PopAndDestroy(msg);
       
  1001 				msg = newmsg;
       
  1002 				CleanupStack::PushL(msg);
       
  1003 				}
       
  1004 			}
       
  1005 		}
       
  1006 
       
  1007 	iProgress->Cancel();
       
  1008 	iProgress->StartL( *msg, aEndValue );
       
  1009 	iProgress->Update(aStartValue, aEndValue);
       
  1010 
       
  1011 	CleanupStack::PopAndDestroy(2, vals); // msg, vals
       
  1012 	}
       
  1013 
       
  1014 // -----------------------------------------------------------------------------
       
  1015 // Shows a proper wait note before the cleanup starts.
       
  1016 //
       
  1017 // This function MUST NOT LEAVE.
       
  1018 // -----------------------------------------------------------------------------
       
  1019 //
       
  1020 void CADMAppUi::HandleFailure()
       
  1021 	{
       
  1022 	LOG3( "+ CADMAppUi::HandleFailure(): %d. err=%d", iStateMachine->StateIndex(), iExitReason);
       
  1023 	// Disable wait note and progress bar, if any
       
  1024 	CancelProgressBar();
       
  1025 	CancelWaitNote();
       
  1026 
       
  1027 	// Delete the dep file
       
  1028 	if ( iDepFileName )
       
  1029 		{
       
  1030 		// We need to ignore, if delete leaves as we are currently already
       
  1031 		// handling an error case.
       
  1032 		// TODO: Remove if(), DeleteFile() copes with NULL filenames.
       
  1033 		DeleteFile( *iDepFileName );
       
  1034 		// TODO: Should we 'delete iDepFileName;' and set it to NULL?
       
  1035 		}
       
  1036 	TInt err = KErrNone;
       
  1037 	TInt waitNoteResource;
       
  1038 	TInt detailedInfoResource = -1;
       
  1039 
       
  1040 	switch (iExitReason)
       
  1041 		{
       
  1042 		case EDownloadFailed:
       
  1043 			waitNoteResource = R_ADM_DETAILED_CANCELLING_INSTALLATION_WAIT_TEXT;
       
  1044 			detailedInfoResource = R_ADM_ERR_CONN_LOST_TEXT;
       
  1045 			break;
       
  1046 		case EUserCancelled:
       
  1047 		case EInstallationFailed:
       
  1048 			waitNoteResource = R_ADM_CANCELLING_INSTALLATION_WAIT_TEXT;
       
  1049 			break;
       
  1050 		default:
       
  1051 			waitNoteResource = R_ADM_REVERTING_CHANGES_WAIT_TEXT;
       
  1052 			break;
       
  1053 		}
       
  1054 
       
  1055 	// Do the cleanup depending on the state that experienced failure
       
  1056 	if ( iStateMachine->FailedState() >= CStateFactory::EStateDownloadChangesFile )
       
  1057 		{
       
  1058 		TRAP(err, ShowWaitNoteL( waitNoteResource, EFalse, detailedInfoResource ));
       
  1059 		}
       
  1060 
       
  1061 	LOG2( "- CADMAppUi::HandleFailure(): %d", err );
       
  1062 	}
       
  1063 
       
  1064 // -----------------------------------------------------------------------------
       
  1065 // Shows the final error message and exits application
       
  1066 // -----------------------------------------------------------------------------
       
  1067 //
       
  1068 void CADMAppUi::ExitApp()
       
  1069 	{
       
  1070 	LOG3( "+ CADMAppUi::ExitApp(): %d, %d", iExitReason, iAppLaunch );
       
  1071 
       
  1072 	// Remove any progress bar
       
  1073 	CancelProgressBar();
       
  1074 	// Remove any wait note
       
  1075 	CancelWaitNote();
       
  1076 
       
  1077 	// Just checking that iExitReason is in the proper range
       
  1078 	if ( iExitReason >= 0 && iExitReason < ELastExitState )
       
  1079 		{
       
  1080 		// If we have an additional note to display, show it. We need to
       
  1081 		// trap any leaves.
       
  1082 		TRAP_IGNORE(
       
  1083 				{
       
  1084 				if ( iSilentInstallationOk && iExitReason == EExitNoError )
       
  1085 					{
       
  1086 					// If we used non-silent installation, the "Installation complete" note
       
  1087 					// was already shown by S60 Installer. Don't show it here again.
       
  1088 					// If the user has launched the application, don't show the note
       
  1089 					if (!iNonSilentInstallation && !iAppLaunch)
       
  1090 						{
       
  1091 						ShowGlobalNoteL( EAknGlobalConfirmationNote, R_ADM_INSTALLATION_OK_TEXT );
       
  1092 						// We need to wait 350ms to show the note as the call to Exit() below would kill
       
  1093 						// the AppUi and also the note.
       
  1094 						User::After(350000);
       
  1095 						}
       
  1096 					}
       
  1097 				else
       
  1098 					{
       
  1099 					if (!iNonSilentInstallation)
       
  1100 						{
       
  1101 						// Show ADM again in task list. This is because we're using
       
  1102 						// CAknQueryDialog: we don't want that to get hidden.
       
  1103 						HideApplicationFromFSW(EFalse);
       
  1104 						// This call returns after user has dismissed the error dialog
       
  1105 						ShowExitNoteL();
       
  1106 						}
       
  1107 					}
       
  1108 				}
       
  1109 			);
       
  1110 		}
       
  1111 #ifdef _DEBUG
       
  1112 	else
       
  1113 		{
       
  1114 		LOG2( "Invalid exit reason %d", iExitReason );
       
  1115 		User::Invariant();
       
  1116 		}
       
  1117 #endif
       
  1118 
       
  1119 	// Set the ADM icon hidden, if everything went smoothly or any resume info file exists.
       
  1120 	const TBool hideAdm = !( (iExitReason != EExitNoError || iExitReason == EDeviceNotSupported) && iIsResumeRequired );
       
  1121 	const TInt err = CUtils::HideApplicationFromMenu( KUidADMApp.iUid, hideAdm );
       
  1122 	LOG3( "ADM icon hidden: %d (%d)", hideAdm, err );
       
  1123 
       
  1124 	RunAppShutter();
       
  1125 	Exit();
       
  1126 
       
  1127 	LOG( "- CADMAppUi::ExitApp()" );
       
  1128 	}
       
  1129 
       
  1130 // -----------------------------------------------------------------------------
       
  1131 // Delete a file pointed by aFilename.
       
  1132 // -----------------------------------------------------------------------------
       
  1133 //
       
  1134 void CADMAppUi::DeleteFile(const TDesC& aFilename)
       
  1135 	{
       
  1136 	iRfs.Delete(aFilename);
       
  1137 	}
       
  1138 
       
  1139 // -----------------------------------------------------------------------------
       
  1140 // Pretty prints number as text string using KiB, MiB and GiB prefixes when needed.
       
  1141 //
       
  1142 // aSize    Number to pretty print. Only positive integers supported.
       
  1143 // aDescr   Descriptor holding the pretty printed number string.
       
  1144 // -----------------------------------------------------------------------------
       
  1145 //
       
  1146 void CADMAppUi::PrettyPrint(const TUint32 aSize, TDes& aDescr)
       
  1147 	{
       
  1148 	_LIT(KFmtDecimals,  "%02d");
       
  1149 	TLocale locale;
       
  1150 	TUint32 size = aSize, rem;
       
  1151 	TPtrC sizePrefix( iPrefixKb );
       
  1152 
       
  1153 	// We don't pretty print bytes because "bytes" would a new string
       
  1154 	// to localize. This is just to minimize that work.
       
  1155 	if (aSize < 1024*1024)
       
  1156 		{
       
  1157 		size /= 1024;
       
  1158 		rem = (aSize * 100 / 1024) % 100;
       
  1159 		}
       
  1160 	else if (aSize < 1024*1024*1024)
       
  1161 		{
       
  1162 		size /= 1024*1024;
       
  1163 		rem = (aSize * 100 / (1024*1024)) % 100;
       
  1164 		sizePrefix.Set( iPrefixMb );
       
  1165 		}
       
  1166 	else
       
  1167 		{
       
  1168 		// TInt64 is needed, because aSize*100 will overflow on big values of aSize
       
  1169 		TInt64 remBig( aSize );
       
  1170 		remBig = ((remBig * 100) / (1024*1024*1024)) % 100;
       
  1171 		rem = remBig;
       
  1172 		size /= 1024*1024*1024;
       
  1173 		sizePrefix.Set( iPrefixGb );
       
  1174 		}
       
  1175 
       
  1176 	aDescr.Num(size);
       
  1177 	// Add decimals only if they != .00
       
  1178 	if (rem)
       
  1179 		{
       
  1180 		aDescr.Append(locale.DecimalSeparator());
       
  1181 		aDescr.AppendFormat(KFmtDecimals, rem);
       
  1182 		}
       
  1183 //    if (aSize > 999)
       
  1184 //        aDescr.Insert(aDescr.Length() - 6, iLocale.ThousandsSeparator());
       
  1185 	aDescr.Append(sizePrefix);
       
  1186 }
       
  1187 
       
  1188 // -----------------------------------------------------------------------------
       
  1189 // Gets detailed phone information and stores it internally.
       
  1190 //
       
  1191 // Returns KErrNone, if fetching of machine UID was succesful
       
  1192 // -----------------------------------------------------------------------------
       
  1193 //
       
  1194 TInt CADMAppUi::GetPhoneInformation()
       
  1195 	{
       
  1196 	LOG( "+ GetPhoneInformation()" );
       
  1197 
       
  1198 	//TODO: Remove unnecessary information, currently MachineUid is only needed
       
  1199 	TInt r = HAL::Get(HALData::EMachineUid, iMachineUid);
       
  1200 #if _DEBUG
       
  1201 	HAL::Get(HALData::EManufacturer, iManufacturer);
       
  1202 	HAL::Get(HALData::EManufacturerHardwareRev, iHardwareRev);
       
  1203 	HAL::Get(HALData::EManufacturerSoftwareRev, iSoftwareRev);
       
  1204 	HAL::Get(HALData::EModel, iModel);
       
  1205 	HAL::Get(HALData::EDeviceFamily, iDeviceFamily);
       
  1206 	HAL::Get(HALData::EDeviceFamilyRev, iDeviceFamilyRev);
       
  1207 	HAL::Get(HALData::ECPUArch, iCpuArch);
       
  1208 	HAL::Get(HALData::ECPUABI, iCpuABI );
       
  1209 	HAL::Get(HALData::ECPUSpeed, iCpuSpeed );
       
  1210 #endif
       
  1211 	TPtr swVer(iSwVersion->Des());
       
  1212 	SysUtil::GetSWVersion(swVer);
       
  1213 
       
  1214 	LOG8_2( "  machine uid = 0x%08x",       iMachineUid);
       
  1215 #if _DEBUG
       
  1216 	LOG8_2( "  model = 0x%08x",             iModel);
       
  1217 	LOG8_2(	"  manufacturer	= %d",			iManufacturer);
       
  1218 	LOG8_2(	"  hardware	rev	= %d",			iHardwareRev);
       
  1219 	LOG8_2(	"  software	rev	= %d",			iSoftwareRev);
       
  1220 	LOG8_2(	"  device family = %d",			iDeviceFamily);
       
  1221 	LOG8_2(	"  device family rev = %d",		iDeviceFamilyRev);
       
  1222 	LOG8_2(	"  CPU architecture	= 0x%08x",	iCpuArch);
       
  1223 	LOG8_2(	"  CPU ABI = %d",				iCpuABI);
       
  1224 	LOG8_2(	"  CPU speed = %d",				iCpuSpeed);
       
  1225 #endif
       
  1226 	LOG2("	Sw Ver = %S",					iSwVersion);
       
  1227 
       
  1228 	LOG8_2( "- GetPhoneInformation (%d)", r);
       
  1229 
       
  1230 	return r;
       
  1231 	}
       
  1232 
       
  1233 // -----------------------------------------------------------------------------
       
  1234 // Returns true if the phone is roaming
       
  1235 // -----------------------------------------------------------------------------
       
  1236 //
       
  1237 TBool CADMAppUi::RegisteredRoaming()
       
  1238 	{
       
  1239 	LOG( "+ RegisteredRoaming()" );
       
  1240 	// Get registeration status
       
  1241 	TRequestStatus status;
       
  1242 	TInt ret = EFalse; // Default to not roaming
       
  1243 
       
  1244 	RMobilePhone::TMobilePhoneRegistrationStatus regStatus(
       
  1245 		RMobilePhone::ERegistrationUnknown );
       
  1246 	iPhone.GetNetworkRegistrationStatus( status, regStatus );
       
  1247 	User::WaitForRequest( status );
       
  1248 
       
  1249 	if ( RMobilePhone::ERegisteredRoaming == regStatus )
       
  1250 		{
       
  1251 		ret = ETrue;
       
  1252 		}
       
  1253 
       
  1254 	LOG2( "- RegisteredRoaming: %d", ret );
       
  1255 
       
  1256 	return ret;
       
  1257 	}
       
  1258 #if 0
       
  1259 // ---------------------------------------------------------------------------
       
  1260 // CADMAppUi::PhoneMemoryDrive
       
  1261 //
       
  1262 // @return Drive number for phone memory.
       
  1263 // ---------------------------------------------------------------------------
       
  1264 //
       
  1265 TInt CADMAppUi::PhoneMemoryDrive()
       
  1266 	{
       
  1267 	TInt res = 0;
       
  1268 	TInt err = RFs::CharToDrive( PathInfo::PhoneMemoryRootPath()[0], res );
       
  1269 	__ASSERT_ALWAYS( !err, Panic( EPanicAdmFileSystemAccess ) );
       
  1270 
       
  1271 	return res;
       
  1272 	}
       
  1273 
       
  1274 // ---------------------------------------------------------------------------
       
  1275 // CADMAppUi::MemoryCardDrive
       
  1276 //
       
  1277 // @return Drive number for memory card.
       
  1278 // ---------------------------------------------------------------------------
       
  1279 //
       
  1280 TInt CADMAppUi::MemoryCardDrive()
       
  1281 	{
       
  1282 	TInt res = 0;
       
  1283 	TInt err = RFs::CharToDrive( PathInfo::MemoryCardRootPath()[0], res );
       
  1284 	__ASSERT_ALWAYS( !err, Panic( EPanicAdmFileSystemAccess ) );
       
  1285 
       
  1286 	return res;
       
  1287 	}
       
  1288 #endif
       
  1289 // ---------------------------------------------------------------------------
       
  1290 // CADMAppUi::ReadStaticResourcesL
       
  1291 //
       
  1292 // @return KErrNone if configuration was read correctly, error code otherwise
       
  1293 // ---------------------------------------------------------------------------
       
  1294 //
       
  1295 void CADMAppUi::ReadStaticResourcesL()
       
  1296 	{
       
  1297 	iEikonEnv->ReadResourceL( iPrefixKb, R_KB );
       
  1298 	iEikonEnv->ReadResourceL( iPrefixMb, R_MB );
       
  1299 	iEikonEnv->ReadResourceL( iPrefixGb, R_GB );
       
  1300 	}
       
  1301 
       
  1302 // ---------------------------------------------------------------------------
       
  1303 // CADMAppUi::UsingWLAN
       
  1304 //
       
  1305 // @return ETrue, if selected bearer is WLAN
       
  1306 // ---------------------------------------------------------------------------
       
  1307 //
       
  1308 TBool CADMAppUi::UsingWLAN()
       
  1309 	{
       
  1310 	return BearerType() == EBearerWLAN;
       
  1311 	}
       
  1312 
       
  1313 // ---------------------------------------------------------------------------
       
  1314 // CADMAppUi::CheckBearerTypeL
       
  1315 //
       
  1316 // @return Bearer type
       
  1317 // ---------------------------------------------------------------------------
       
  1318 //
       
  1319 TInt CADMAppUi::BearerType()
       
  1320 	{
       
  1321 	LOG2( "+ BearerType(): IAP=%d", iIAP );
       
  1322 	RConnectionMonitor monitor;
       
  1323 	TRequestStatus status = KRequestPending;
       
  1324 	TUint iapId(0);
       
  1325 	TInt bearer( 0 );
       
  1326 	TUint count;
       
  1327 	TUint ids[ 15 ];
       
  1328 
       
  1329 	TRAPD( err, monitor.ConnectL() );
       
  1330 	if (err != KErrNone )
       
  1331 		{
       
  1332 		LOG2( "BearerType: Connect to RConnMon failed. %d", err );
       
  1333 		return err;
       
  1334 		}
       
  1335 
       
  1336 	// Get the connection count
       
  1337 	monitor.GetConnectionCount( count, status );
       
  1338 	User::WaitForRequest( status );
       
  1339 	if ( status.Int() != KErrNone )
       
  1340 		{
       
  1341 		LOG2( "GetConnCount failed. %d", status.Int() );
       
  1342 		monitor.Close();
       
  1343 		return status.Int();
       
  1344 		}
       
  1345 #ifdef DO_LOG
       
  1346 	else
       
  1347 		{
       
  1348 		LOG2( "BearerType: %d connections:", count);
       
  1349 		}
       
  1350 #endif
       
  1351 
       
  1352 	// Get the connection info for each connection
       
  1353 	TUint numSubConnections;
       
  1354 	TInt i;
       
  1355 
       
  1356 	for ( i = 1; i <= count; i++ )
       
  1357 		{
       
  1358 		TInt ret = monitor.GetConnectionInfo( i, ids[ i-1 ], numSubConnections );
       
  1359 		if ( ret == KErrNone )
       
  1360 			{
       
  1361 			LOG3( "BearerType: ConnID[%d] = %d" , i, ids[ i-1 ] );
       
  1362 			// Get the IAP Id of the connection
       
  1363 			monitor.GetUintAttribute( ids[ i-1 ], 0, KIAPId, iapId, status );
       
  1364 			User::WaitForRequest( status );
       
  1365 			if ( status.Int() != KErrNone )
       
  1366 				{
       
  1367 				LOG2( "GetIapId failed. %d", status.Int() );
       
  1368 				// try next connection
       
  1369 				continue;
       
  1370 				}
       
  1371 #ifdef DO_LOG
       
  1372 			else
       
  1373 				{
       
  1374 				LOG3( "BearerType: IapId = %d, IAP = %d", iapId, iIAP );
       
  1375 				}
       
  1376 #endif
       
  1377 			// If the IAP matches with the one set in ADM
       
  1378 			// iIAP is initialized to KInvalidIapId
       
  1379 			if ( iapId == iIAP || iIAP == KInvalidIapId )
       
  1380 				{
       
  1381 #ifdef DO_LOG
       
  1382 				LOG2( "BearerType: Getting bearer for IapId %d", iapId );
       
  1383 #endif
       
  1384 				// Get the Bearer of the IAP Id.
       
  1385 				monitor.GetIntAttribute( ids[ i-1 ], 0, KBearer, bearer, status );
       
  1386 				User::WaitForRequest( status );
       
  1387 				if ( status.Int() != KErrNone )
       
  1388 					{
       
  1389 					LOG2( "BearerType: GetBearerType failed. %d", status.Int() );
       
  1390 					// try next connection
       
  1391 					continue;
       
  1392 					}
       
  1393 #ifdef DO_LOG
       
  1394 				else
       
  1395 					{
       
  1396 					LOG3( "BearerType: IapId %d: bearer = %d", iapId, bearer );
       
  1397 					}
       
  1398 #endif
       
  1399 				// we found matching IAP ID, break out of the loop
       
  1400 				break;
       
  1401 				}
       
  1402 			}
       
  1403 		else
       
  1404 			{
       
  1405 			LOG2( "GetConnInfo failed. %d", ret );
       
  1406 			return ret;
       
  1407 			}
       
  1408 		}
       
  1409 	TBuf<KConnMonMaxStringAttributeLength> iapName;
       
  1410 
       
  1411 	// Get the string attrib of the IAP Id
       
  1412 	monitor.GetStringAttribute( ids[ i-1 ], 0, KIAPName, iapName, status );
       
  1413 	User::WaitForRequest( status );
       
  1414 	if ( status.Int() != KErrNone )
       
  1415 		{
       
  1416 		LOG2( "BearerType: GetStrAttr failed. %d", status.Int() );
       
  1417 		}
       
  1418 	else
       
  1419 		{
       
  1420 		LOG5( "* Selected IAP %d (%d), conn %d '%S'", iapId, bearer, ids[i-1], &iapName );
       
  1421 		}
       
  1422 
       
  1423 	// Close the RConnMon object
       
  1424 	monitor.Close();
       
  1425 
       
  1426 	LOG2( "- BearerType(): %d", bearer );
       
  1427 
       
  1428 	return bearer;
       
  1429 	}
       
  1430 
       
  1431 // ---------------------------------------------------------------------------
       
  1432 // CADMAppUi::ReadConfiguration
       
  1433 //
       
  1434 // @return KErrNone if configuration was read correctly, error code otherwise
       
  1435 // ---------------------------------------------------------------------------
       
  1436 //
       
  1437 TInt CADMAppUi::ReadConfigurationL()
       
  1438 	{
       
  1439 	TFileName configFile;
       
  1440 	RArray< TPtrC > lineBuffer;
       
  1441 	TInt ret( KErrNone );
       
  1442 
       
  1443 	// Find the configuration file from the private directory
       
  1444 	ret = iRfs.PrivatePath(configFile);
       
  1445 	if (ret == KErrNone)
       
  1446 		{
       
  1447 		TBuf<2> appDrive;
       
  1448 		// Insert the drive of the running application
       
  1449 		appDrive.Copy(Application()->AppFullName().Left(2));
       
  1450 		configFile.Insert(0, appDrive);
       
  1451 		// Append the configuration file name
       
  1452 		configFile.Append(KConfigFile);
       
  1453 
       
  1454 		LOG2( "configFile = %S", &configFile );
       
  1455 
       
  1456 		HBufC* buffer = ReadConfigFile(iRfs, configFile, lineBuffer, ret );
       
  1457 
       
  1458 		if ( buffer && ret == KErrNone )
       
  1459 			{
       
  1460 			TPtrC line = GetConfigValue( KCfgTagUrl, lineBuffer, ret );
       
  1461 			if ( ret == KErrNone )
       
  1462 				{
       
  1463 				iConfigUrl = HBufC8::NewL(line.Length());
       
  1464 				iConfigUrl->Des().Copy(line);
       
  1465 				LOG8_2( "configUrl = %S", iConfigUrl );
       
  1466 				}
       
  1467 			delete buffer;
       
  1468 			}
       
  1469 		}
       
  1470 		if ( !iConfigUrl )
       
  1471 			{
       
  1472 			// Error occured while reading the configuration, use default URL
       
  1473 			iConfigUrl = HBufC8::NewL(KDefaultDepServerUrl().Length());
       
  1474 			*iConfigUrl = KDefaultDepServerUrl;
       
  1475 			LOG8_2( "configUrl = %S (default)", iConfigUrl );
       
  1476 			}
       
  1477 
       
  1478 	lineBuffer.Close();
       
  1479 
       
  1480 	return ret;
       
  1481 	}
       
  1482 
       
  1483 // End of File