iaupdate/IAD/firmwareupdate/src/iaupdatefwfotamodel.cpp
changeset 0 ba25891c3a9e
child 15 98a43fae6e2b
equal deleted inserted replaced
-1:000000000000 0:ba25891c3a9e
       
     1 /*
       
     2 * Copyright (c) 2008 Nokia Corporation and/or its subsidiary(-ies).
       
     3 * All rights reserved.
       
     4 * This component and the accompanying materials are made available
       
     5 * under the terms of "Eclipse Public License v1.0"
       
     6 * which accompanies this distribution, and is available
       
     7 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     8 *
       
     9 * Initial Contributors:
       
    10 * Nokia Corporation - initial contribution.
       
    11 *
       
    12 * Contributors:
       
    13 *
       
    14 * Description:            
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 
       
    20 
       
    21 // INCLUDE FILES
       
    22 #include <sysutil.h>
       
    23 #include <centralrepository.h>
       
    24 #include <DevManInternalCRKeys.h>
       
    25 
       
    26 #include "iaupdatefwfotamodel.h"
       
    27 #include "iaupdatefwdebug.h"
       
    28 #include "iaupdatefwconst.h"
       
    29 #include "iaupdatefwnsmlcrkeys.h"
       
    30 
       
    31 // ============================ MEMBER FUNCTIONS ===============================
       
    32 
       
    33 // -----------------------------------------------------------------------------
       
    34 // CIAUpdateFWFotaModel::NewL
       
    35 // Two-phased constructor.
       
    36 // -----------------------------------------------------------------------------
       
    37 //
       
    38  CIAUpdateFWFotaModel* CIAUpdateFWFotaModel::NewL( /* KNST CNSCDocument* aDocument*/ )
       
    39     {
       
    40     CIAUpdateFWFotaModel* self = new( ELeave ) CIAUpdateFWFotaModel( /*KNST aDocument*/ );
       
    41     
       
    42     CleanupStack::PushL( self );
       
    43     self->ConstructL();
       
    44     CleanupStack::Pop();
       
    45 
       
    46     return self;
       
    47     }
       
    48 
       
    49     
       
    50 // Destructor
       
    51 CIAUpdateFWFotaModel::~CIAUpdateFWFotaModel()
       
    52     {
       
    53     FLOG( "[IAUPDATEFW] CIAUpdateFWFotaModel::~CIAUpdateFWFotaModel()" );
       
    54     //iFwUpdIdStateList.Close();
       
    55     iFotaEngine.Close();
       
    56     }
       
    57 
       
    58 
       
    59 // -----------------------------------------------------------------------------
       
    60 // CIAUpdateFWFotaModel::GetProfileName
       
    61 // Changes aProfileName to KNullDesC if the profile identifier is
       
    62 // not found.
       
    63 // -----------------------------------------------------------------------------
       
    64 //
       
    65 void CIAUpdateFWFotaModel::GetProfileNameL( const TInt   aProfileId,
       
    66                                               HBufC* aProfileName ) const
       
    67     {
       
    68     FLOG( "[IAUPDATEFW] CIAUpdateFWFotaModel::GetProfileNameL() - not implemented" );
       
    69 
       
    70 /*KNST
       
    71     TInt index( 0 );
       
    72     aProfileName->Des().Copy( KNullDesC );
       
    73     
       
    74     iDocument->RefreshProfileListL( ETrue ); // Include hidden profile
       
    75     CArrayFixFlat<TNSmlDMProfileItem>* profileList = iDocument->ProfileList( index );
       
    76     
       
    77     for ( index = 0; index < profileList->Count(); index++ )
       
    78         {
       
    79         if ( ( *profileList )[index].iProfileId == aProfileId )
       
    80             {
       
    81             aProfileName->Des().Copy( ( *profileList )[index].iProfileName );
       
    82             }
       
    83         }
       
    84 */
       
    85     FTRACE( FPrint( _L(
       
    86         "[IAUPDATEFW] CIAUpdateFWFotaModel::GetProfileNameL(): aProfileId = %d, ProfileName = \"%S\"" ),
       
    87          aProfileId, aProfileName ) );
       
    88     }
       
    89 
       
    90 // -----------------------------------------------------------------------------
       
    91 // CIAUpdateFWFotaModel::DefaultFotaProfileIdL
       
    92 // -----------------------------------------------------------------------------
       
    93 //
       
    94  TInt CIAUpdateFWFotaModel::DefaultFotaProfileIdL() const
       
    95     {
       
    96     FLOG( "[IAUPDATEFW] CIAUpdateFWFotaModel::DefaultFotaProfileIdL()" );
       
    97     
       
    98     TInt profileId( KErrNotFound );
       
    99     CRepository* centrep = NULL;
       
   100     TRAPD( err, centrep = CRepository::NewL( KCRUidNSmlDMSyncApp ) );
       
   101     FTRACE( FPrint( _L(
       
   102         "[IAUPDATEFW] CIAUpdateFWFotaModel::DefaultFotaProfileIdL(), opening cenrep returned %d" ),
       
   103         err ) );
       
   104 
       
   105     User::LeaveIfError( err );
       
   106     centrep->Get( KNSmlDMDefaultFotaProfileKey, profileId );
       
   107     delete centrep;
       
   108     
       
   109     FTRACE( FPrint( _L(
       
   110         "[IAUPDATEFW] CIAUpdateFWFotaModel::DefaultFotaProfileIdL() completed, profileId = %d" ),
       
   111         profileId ) );
       
   112     return profileId;
       
   113     }
       
   114 
       
   115 // -----------------------------------------------------------------------------
       
   116 // CIAUpdateFWFotaModel::SetDefaultFotaProfileIdL
       
   117 // -----------------------------------------------------------------------------
       
   118 //
       
   119 void CIAUpdateFWFotaModel::SetDefaultFotaProfileIdL( const TInt aProfileId )
       
   120     {
       
   121     FLOG( "[IAUPDATEFW] CIAUpdateFWFotaModel::SetDefaultFotaProfileIdL()" );
       
   122     
       
   123     CRepository* centrep = NULL;
       
   124     TRAPD( err, centrep = CRepository::NewL( KCRUidNSmlDMSyncApp ) );
       
   125     FTRACE( FPrint( _L(
       
   126         "[IAUPDATEFW] CIAUpdateFWFotaModel::SetDefaultFotaProfileIdL(), opening cenrep returned %d" ),
       
   127         err ) );
       
   128 
       
   129     User::LeaveIfError( err );
       
   130     centrep->Set( KNSmlDMDefaultFotaProfileKey, aProfileId );
       
   131     delete centrep;
       
   132     
       
   133     FLOG( "[IAUPDATEFW] CIAUpdateFWFotaModel::SetDefaultFotaProfileIdL() completed" );
       
   134     }
       
   135 
       
   136 // -----------------------------------------------------------------------------
       
   137 // CIAUpdateFWFotaModel::EnableFwUpdRequestL
       
   138 // -----------------------------------------------------------------------------
       
   139 //
       
   140  void CIAUpdateFWFotaModel::EnableFwUpdRequestL( const TInt aProfileId )
       
   141     {
       
   142     FLOG( "[IAUPDATEFW] CIAUpdateFWFotaModel::SetDefaultFotaProfileIdL()" );
       
   143     
       
   144     CRepository* centrep = NULL;
       
   145     TRAPD( err, centrep = CRepository::NewL( KCRUidDeviceManagementInternalKeys ) );
       
   146     FTRACE( FPrint( _L(
       
   147         "[IAUPDATEFW] CIAUpdateFWFotaModel::EnableFwUpdRequestL(), opening cenrep returned %d" ),
       
   148         err ) );
       
   149     User::LeaveIfError( err );
       
   150     centrep->Set( KDevManClientInitiatedFwUpdateId, aProfileId );
       
   151     delete centrep;
       
   152     
       
   153     FLOG( "[IAUPDATEFW] CIAUpdateFWFotaModel::SetDefaultFotaProfileIdL() completed" );
       
   154     }
       
   155 
       
   156 // -----------------------------------------------------------------------------
       
   157 // CIAUpdateFWFotaModel::ReadProfileListL
       
   158 // -----------------------------------------------------------------------------
       
   159 //
       
   160 void CIAUpdateFWFotaModel::ReadProfileListL( CDesCArray*          /*aItems*/,
       
   161                                          CArrayFixFlat<TInt>* /*aProfileIdList*/ )
       
   162     {
       
   163     FLOG( "[IAUPDATEFW] CIAUpdateFWFotaModel::ReadProfileListL() - not implemented" );
       
   164     //no implementation
       
   165     }
       
   166 
       
   167 // -----------------------------------------------------------------------------
       
   168 // CIAUpdateFWFotaModel::SelectDefaultProfileFromList
       
   169 // -----------------------------------------------------------------------------
       
   170 //
       
   171 TInt CIAUpdateFWFotaModel::SelectDefaultProfileFromList(
       
   172     const CArrayFixFlat<TInt>* /*aProfileIdList*/ ) const
       
   173     {
       
   174     FLOG( "[IAUPDATEFW] CIAUpdateFWFotaModel::SelectDefaultProfileFromList() - not implemented" );
       
   175     TInt retval( KErrNotFound );
       
   176     return retval;
       
   177     }
       
   178 
       
   179 // -----------------------------------------------------------------------------
       
   180 // CIAUpdateFWFotaModel::VerifyProfileL
       
   181 // -----------------------------------------------------------------------------
       
   182 //
       
   183 TBool CIAUpdateFWFotaModel::VerifyProfileL( const TInt /*aProfileId*/ ) const
       
   184     {
       
   185     TBool retval( EFalse );
       
   186     return retval;
       
   187     }
       
   188 
       
   189 // -----------------------------------------------------------------------------
       
   190 // CIAUpdateFWFotaModel::RetrieveFwUpdPkgIdListL
       
   191 // -----------------------------------------------------------------------------
       
   192 //
       
   193 RArray< TInt > CIAUpdateFWFotaModel::RetrieveFwUpdPkgIdListL()
       
   194     {
       
   195     const TInt maxNumOfProfiles = 32;
       
   196     
       
   197     TBuf16< maxNumOfProfiles > idListDescriptor;
       
   198     User::LeaveIfError( iFotaEngine.GetUpdatePackageIds( idListDescriptor ) );
       
   199     
       
   200     RArray< TInt > idList;
       
   201     
       
   202     TInt count = idListDescriptor.Length();
       
   203     for ( TInt i = 0; i < count; i++ )
       
   204         {
       
   205         idList.Append( idListDescriptor[ i ] );
       
   206         }
       
   207     
       
   208     return idList;
       
   209     }
       
   210 
       
   211 // -----------------------------------------------------------------------------
       
   212 // CIAUpdateFWFotaModel::FindFwUpdPkgWithStateL
       
   213 // -----------------------------------------------------------------------------
       
   214 //
       
   215  TInt CIAUpdateFWFotaModel::FindFwUpdPkgWithStateL(
       
   216     RFotaEngineSession::TState aState )
       
   217     {
       
   218     FTRACE( FPrint( _L(
       
   219         "[IAUPDATEFW] CIAUpdateFWFotaModel::FindFwUpdPkgWithStateL(): aState = %d" ),
       
   220          (TInt) aState ) );
       
   221 
       
   222     RArray< TInt > idList = RetrieveFwUpdPkgIdListL();
       
   223     TInt retval = KErrNotFound;
       
   224 
       
   225     TInt count = idList.Count();
       
   226     for ( TInt i = 0; (i < count) && (retval == KErrNotFound); i++ )
       
   227         {
       
   228         RFotaEngineSession::TState pkgState;
       
   229         pkgState = iFotaEngine.GetState( idList[ i ] );
       
   230         FTRACE( FPrint( _L(
       
   231             "[IAUPDATEFW] CIAUpdateFWFotaModel::FindFwUpdPkgWithStateL(): profileid = %d, pkgstate = %d" ),
       
   232              idList[i], (TInt) pkgState ) );
       
   233         if ( pkgState == aState )
       
   234             {
       
   235             retval = idList[ i ];
       
   236             }
       
   237         }
       
   238 
       
   239     FTRACE( FPrint( _L(
       
   240         "[IAUPDATEFW] CIAUpdateFWFotaModel::FindFwUpdPkgWithStateL(): completed, retval = %d" ),
       
   241          retval ) );
       
   242     idList.Close(); 
       
   243     
       
   244     return retval;
       
   245     }
       
   246 
       
   247 // -----------------------------------------------------------------------------
       
   248 // CIAUpdateFWFotaModel::InitiateFwUpdInstall
       
   249 // -----------------------------------------------------------------------------
       
   250 //
       
   251  TInt CIAUpdateFWFotaModel::InitiateFwUpdInstall( TInt aPkgId, TInt aProfileId )
       
   252     {
       
   253     FTRACE( FPrint( _L(
       
   254         "[IAUPDATEFW] CIAUpdateFWFotaModel::InitiateFwUpdInstall(): aPkgId = %d, aProfileId = %d" ),
       
   255         aPkgId, aProfileId ) );
       
   256 
       
   257     TInt retval = KErrGeneral;
       
   258     retval = iFotaEngine.Update( aPkgId, aProfileId, KNullDesC8, KNullDesC8 );
       
   259 
       
   260     FTRACE( FPrint( _L(
       
   261         "[IAUPDATEFW] CIAUpdateFWFotaModel::InitiateFwUpdInstall() completed, retval = %d" ),
       
   262         retval ) );
       
   263     return retval;
       
   264     }
       
   265 
       
   266 // -----------------------------------------------------------------------------
       
   267 // CIAUpdateFWFotaModel::CurrentFwVersionString
       
   268 // If the software version retrieval fails, the aVersionstring is not modified.
       
   269 // -----------------------------------------------------------------------------
       
   270 //
       
   271 TInt CIAUpdateFWFotaModel::CurrentFwVersionString( TDes& aVersionString )
       
   272     {
       
   273     FLOG( "[IAUPDATEFW] CIAUpdateFWFotaModel::CurrentFwVersionString()" );
       
   274     TBuf< KSysUtilVersionTextLength > buf;
       
   275 
       
   276     TInt err = SysUtil::GetSWVersion( buf );
       
   277     if ( err == KErrNone )
       
   278         {
       
   279         _LIT( separator, "\n" );
       
   280         TInt location = buf.Find( separator );
       
   281         if ( location != KErrNotFound)
       
   282             {
       
   283             // Delete the separator and the text after it. We are
       
   284             // only interested in the first section.
       
   285             buf.Delete( location, (buf.Length() - location) );
       
   286             }
       
   287 
       
   288         aVersionString.Copy( buf.Left( aVersionString.MaxLength() ) );
       
   289         }
       
   290     FTRACE( FPrint( _L(
       
   291         "[IAUPDATEFW] CIAUpdateFWFotaModel::CurrentFwVersionString() completed, err = %d, string = \"%S\"" ),
       
   292         err, &aVersionString ) );
       
   293 
       
   294     return err;
       
   295     }
       
   296 
       
   297 // -----------------------------------------------------------------------------
       
   298 // CIAUpdateFWFotaModel::LastUpdateTime
       
   299 // -----------------------------------------------------------------------------
       
   300 //
       
   301 TInt CIAUpdateFWFotaModel::LastUpdateTime( TTime& aTime )
       
   302     {
       
   303     FLOG( "[IAUPDATEFW] CIAUpdateFWFotaModel::LastUpdateTime()" );
       
   304     TInt retval = iFotaEngine.LastUpdate( aTime );
       
   305     FTRACE( FPrint( _L(
       
   306         "[IAUPDATEFW] CIAUpdateFWFotaModel::LastUpdateTime() completed, err = %d" ),
       
   307         retval ) );
       
   308     return retval;
       
   309     }
       
   310 
       
   311 // -----------------------------------------------------------------------------
       
   312 // CIAUpdateFWFotaModel::MarkFwUpdChangesStartL
       
   313 // -----------------------------------------------------------------------------
       
   314 //
       
   315  void CIAUpdateFWFotaModel::MarkFwUpdChangesStartL()
       
   316     {
       
   317     FLOG( "[IAUPDATEFW] CIAUpdateFWFotaModel::MarkFwUpdChangesStartL()" );    
       
   318     }
       
   319 
       
   320 // -----------------------------------------------------------------------------
       
   321 // CIAUpdateFWFotaModel::FwUpdStatesChangedL
       
   322 // The array is reseted at the end of the execution to save memory, since at
       
   323 // the moment the information is not needed multiple times.
       
   324 // -----------------------------------------------------------------------------
       
   325 //
       
   326  TBool CIAUpdateFWFotaModel::FwUpdStatesChangedL()
       
   327     {
       
   328     FLOG( "[IAUPDATEFW] CIAUpdateFWFotaModel::FwUpdStatesChangedL()" );
       
   329     
       
   330     TBool retval = EFalse;
       
   331 
       
   332     TInt configFlags( 0 );
       
   333         TInt SetGenValue(0);
       
   334         CRepository* centrep = NULL;
       
   335         TRAPD( err, centrep = CRepository::NewL( KCRUidDeviceManagementInternalKeys ) );
       
   336         if ( centrep )
       
   337             {
       
   338             centrep->Get( KDevManSessionType, configFlags );
       
   339             
       
   340             }
       
   341         if ( err != KErrNone ) 
       
   342             {
       
   343             User::Leave( err );
       
   344             }
       
   345         else
       
   346             {
       
   347             
       
   348             centrep->Set( KDevManSessionType, SetGenValue );
       
   349             }      
       
   350         if(centrep)    
       
   351            {
       
   352            delete centrep;
       
   353            }
       
   354         if ( configFlags == 1 )
       
   355 			{
       
   356 			retval = ETrue;
       
   357 			}           
       
   358         // configFlags=2 for FOTA Package not downloaded case ,1- successful download
       
   359     return retval;
       
   360     }
       
   361 
       
   362 // -----------------------------------------------------------------------------
       
   363 // CIAUpdateFWFotaModel::CIAUpdateFWFotaModel
       
   364 // C++ default constructor can NOT contain any code, that
       
   365 // might leave.
       
   366 // -----------------------------------------------------------------------------
       
   367 //
       
   368 CIAUpdateFWFotaModel::CIAUpdateFWFotaModel( /*CNSCDocument* aDocument*/ ) /*:
       
   369     iDocument( aDocument )*/
       
   370     {
       
   371     }
       
   372 
       
   373 // -----------------------------------------------------------------------------
       
   374 // CIAUpdateFWFotaModel::ConstructL
       
   375 // Symbian 2nd phase constructor can leave.
       
   376 // -----------------------------------------------------------------------------
       
   377 //
       
   378 void CIAUpdateFWFotaModel::ConstructL()
       
   379     {
       
   380     iFotaEngine.OpenL();
       
   381     }
       
   382 
       
   383 
       
   384 // -----------------------------------------------------------------------------
       
   385 // CIAUpdateFWFotaModel::ConstructL
       
   386 // Symbian 2nd phase constructor can leave.
       
   387 // -----------------------------------------------------------------------------
       
   388 //
       
   389 TBool CIAUpdateFWFotaModel::IsDMSupportAvailableL()
       
   390     {
       
   391     TInt packId = -1 ;
       
   392     TInt err = iFotaEngine.DeleteUpdatePackage( packId );
       
   393     if ( err == KErrAccessDenied )
       
   394         {
       
   395         return EFalse;
       
   396         }
       
   397     return ETrue;   
       
   398     }
       
   399 
       
   400 // -----------------------------------------------------------------------------
       
   401 // CIAUpdateFWFotaModel::GetCurrentFwUpdState
       
   402 // Fetches the state of last or current Fota operation
       
   403 // -----------------------------------------------------------------------------
       
   404 //
       
   405  RFotaEngineSession::TState CIAUpdateFWFotaModel::GetCurrentFwUpdState()
       
   406 	{
       
   407     FLOG( "[IAUPDATEFW] CIAUpdateFWFotaModel::GetCurrentFwUpdState()" );	
       
   408 	const TInt x = -1;
       
   409 	return iFotaEngine.GetState(x);
       
   410 	}
       
   411 
       
   412 //  End of File