startupservices/startupanimation/sanimctrl/src/sanimstartupctrl.cpp
changeset 0 2e3d3ce01487
child 3 096dad6e50a9
equal deleted inserted replaced
-1:000000000000 0:2e3d3ce01487
       
     1 /*
       
     2 * Copyright (c) 2007,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:  Implementation of CSAnimStartupCtrl class
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 #include <aknappui.h>
       
    20 #include <aknsoundsystem.h>
       
    21 #include <centralrepository.h>
       
    22 #include <featmgr.h>
       
    23 #include <MediatorDomainUIDs.h>
       
    24 #include <Profile.hrh>
       
    25 #include <ProfileEngineSDKCRKeys.h>
       
    26 #include "sanimengine.h"
       
    27 #include <SecondaryDisplay/SecondaryDisplayStartupAPI.h>
       
    28 
       
    29 #include "sanimstartupctrl.h"
       
    30 #include "trace.h"
       
    31 
       
    32 const TInt KMinVolume( 0 );  /** Minimum allowed volume level. */
       
    33 const TInt KMaxVolume( 10 ); /** Maximum allowed volume level. */
       
    34 
       
    35 const TInt KDefaultRepeatCount( 1 ); /** Default repeat count for animation and tone. */
       
    36 const TInt KDefaultVolumeRamp( 0 );  /** Default volume ramp value in microseconds. */
       
    37 
       
    38 static const TInt KMediatorTimeout( 1000000 ); /** Default timeout for Mediator commands. */
       
    39 
       
    40 // ======== LOCAL FUNCTIONS ========
       
    41 
       
    42 // ---------------------------------------------------------------------------
       
    43 // FileExists
       
    44 //
       
    45 // ---------------------------------------------------------------------------
       
    46 //
       
    47 static TBool FileExists( RFs& aFs, const TDesC& aPath )
       
    48     {
       
    49     FUNC_LOG;
       
    50     INFO_1( "File name: %S", &aPath );
       
    51 
       
    52     if ( aPath.Length() > 0 )
       
    53         {
       
    54         RFile file;
       
    55         TInt errorCode = file.Open( aFs, aPath, EFileRead | EFileShareReadersOnly );
       
    56         ERROR( errorCode, "File open failed" );
       
    57 
       
    58         file.Close();
       
    59         return ( errorCode == KErrNone );
       
    60         }
       
    61 
       
    62     return EFalse;
       
    63     }
       
    64 
       
    65 
       
    66 // ---------------------------------------------------------------------------
       
    67 // IsSilentL
       
    68 //
       
    69 // ---------------------------------------------------------------------------
       
    70 //
       
    71 static TBool IsSilentL()
       
    72     {
       
    73     FUNC_LOG;
       
    74 
       
    75     TBool retVal = ETrue;
       
    76     CRepository* repository = CRepository::NewLC( KCRUidProfileEngine );
       
    77 
       
    78     TInt type( EProfileRingingTypeSilent );
       
    79     User::LeaveIfError( repository->Get( KProEngActiveRingingType, type ) );
       
    80 
       
    81     INFO_1( "Ringing type: %d", type );
       
    82 
       
    83     if ( type != EProfileRingingTypeSilent )
       
    84         {
       
    85         TInt volume( 0 );
       
    86         User::LeaveIfError(
       
    87             repository->Get( KProEngActiveRingingVolume, volume ) );
       
    88 
       
    89         INFO_1( "Ringing volume: %d", volume );
       
    90 
       
    91         if ( volume != 0 && volume != EProfileRingingVolumeLevel1 )
       
    92             {
       
    93             retVal = EFalse;
       
    94             }
       
    95         }
       
    96 
       
    97     CleanupStack::PopAndDestroy( repository );
       
    98 
       
    99     INFO_1( "Is silent: %d", retVal );
       
   100 
       
   101     return retVal;
       
   102     }
       
   103 
       
   104 
       
   105 // ======== MEMBER FUNCTIONS ========
       
   106 
       
   107 // ---------------------------------------------------------------------------
       
   108 // CSAnimStartupCtrl::NewL
       
   109 //
       
   110 // ---------------------------------------------------------------------------
       
   111 //
       
   112 EXPORT_C CSAnimStartupCtrl* CSAnimStartupCtrl::NewL(
       
   113     const TRect& aRect,
       
   114     const CCoeControl& aContainer )
       
   115     {
       
   116     FUNC_LOG;
       
   117 
       
   118     CSAnimStartupCtrl* self = new( ELeave ) CSAnimStartupCtrl;
       
   119     CleanupStack::PushL( self );
       
   120     self->ConstructL( aRect, aContainer );
       
   121     CleanupStack::Pop( self );
       
   122     return self;
       
   123     }
       
   124 
       
   125 
       
   126 // ---------------------------------------------------------------------------
       
   127 // CSAnimStartupCtrl::~CSAnimStartupCtrl
       
   128 //
       
   129 // ---------------------------------------------------------------------------
       
   130 //
       
   131 CSAnimStartupCtrl::~CSAnimStartupCtrl()
       
   132     {
       
   133     FUNC_LOG;
       
   134 
       
   135     delete iCommandResponder;
       
   136     delete iCommandInitiator;
       
   137     }
       
   138 
       
   139 
       
   140 // ---------------------------------------------------------------------------
       
   141 // CSAnimStartupCtrl::HasContent
       
   142 //
       
   143 // ---------------------------------------------------------------------------
       
   144 //
       
   145 TBool CSAnimStartupCtrl::HasContent() const
       
   146     {
       
   147     FUNC_LOG;
       
   148 
       
   149     return iHasContent;
       
   150     }
       
   151 
       
   152 
       
   153 // ---------------------------------------------------------------------------
       
   154 // CSAnimStartupCtrl::Load
       
   155 //
       
   156 // ---------------------------------------------------------------------------
       
   157 //
       
   158 void CSAnimStartupCtrl::Load(
       
   159     const TAnimationParams& aParams,
       
   160     const TBool aPlayDefaultBeep,
       
   161     const TInt aSyncCommand,
       
   162     TRequestStatus& aStatus )
       
   163     {
       
   164     FUNC_LOG;
       
   165 
       
   166     iPlayDefaultBeep = aPlayDefaultBeep;
       
   167     iSyncCommand = aSyncCommand;
       
   168 
       
   169     TRAPD( errorCode, LoadL( aParams, aStatus ) );
       
   170     ERROR( errorCode, "Failed to load" );
       
   171     if ( errorCode != KErrNone )
       
   172         {
       
   173         TRequestStatus* status = &aStatus;
       
   174         User::RequestComplete( status, errorCode );
       
   175         }
       
   176     }
       
   177 
       
   178 
       
   179 // ---------------------------------------------------------------------------
       
   180 // CSAnimStartupCtrl::Start
       
   181 //
       
   182 // ---------------------------------------------------------------------------
       
   183 //
       
   184 void CSAnimStartupCtrl::Start( TRequestStatus& aStatus )
       
   185     {
       
   186     FUNC_LOG;
       
   187 
       
   188     aStatus = KRequestPending;
       
   189 
       
   190     if ( !iClientStatus )
       
   191         {
       
   192         if ( !HasContent() )
       
   193             {
       
   194             TRequestStatus* status = &aStatus;
       
   195             User::RequestComplete( status, KErrNone );
       
   196             }
       
   197         else if ( iCommandInitiator )
       
   198             {
       
   199             INFO_1( "Secondary display data: %d", iSyncCommand );
       
   200 
       
   201             iClientStatus = &aStatus;
       
   202             iWaitingForSyncResponse = ETrue;
       
   203             TInt errorCode = iCommandInitiator->IssueCommand(
       
   204                 KMediatorSecondaryDisplayDomain,
       
   205                 SecondaryDisplay::KCatStartup,
       
   206                 SecondaryDisplay::ECmdStartupSync,
       
   207                 TVersion( 0, 0, 0 ),
       
   208                 TPckgBuf<TInt>( iSyncCommand ) );
       
   209             if ( errorCode != KErrNone )
       
   210                 {
       
   211                 ERROR( errorCode, "Failed issue command" );
       
   212 
       
   213                 iClientStatus = &aStatus;
       
   214                 StartAnimation();
       
   215                 }
       
   216             }
       
   217         else
       
   218             {
       
   219             iClientStatus = &aStatus;
       
   220             StartAnimation();
       
   221             }
       
   222         }
       
   223     else
       
   224         {
       
   225         TRequestStatus* status = &aStatus;
       
   226         User::RequestComplete( status, KErrNotReady );
       
   227         }
       
   228     }
       
   229 
       
   230 
       
   231 // ---------------------------------------------------------------------------
       
   232 // CSAnimStartupCtrl::HandlePointerEventL
       
   233 //
       
   234 // ---------------------------------------------------------------------------
       
   235 void CSAnimStartupCtrl::HandlePointerEventL( const TPointerEvent& aPointerEvent )
       
   236     {
       
   237     FUNC_LOG;
       
   238 
       
   239     if ( aPointerEvent.iType == TPointerEvent::EButton1Down ||
       
   240          aPointerEvent.iType == TPointerEvent::EButton2Down ||
       
   241          aPointerEvent.iType == TPointerEvent::EButton3Down )
       
   242         {
       
   243         INFO( "Pointer event -> cancel animation" );
       
   244 
       
   245         Cancel();
       
   246         }
       
   247 
       
   248     CCoeControl::HandlePointerEventL( aPointerEvent );
       
   249     }
       
   250 
       
   251 
       
   252 // ----------------------------------------------------------------------------
       
   253 // CSAnimStartupCtrl::MediatorCommandL
       
   254 //
       
   255 // ----------------------------------------------------------------------------
       
   256 //
       
   257 void CSAnimStartupCtrl::MediatorCommandL(
       
   258     TUid aDomain,
       
   259     TUid aCategory,
       
   260     TInt aCommandId,
       
   261     TVersion /*aVersion*/,
       
   262     const TDesC8& /*aData*/ )
       
   263     {
       
   264     FUNC_LOG;
       
   265 
       
   266     if ( aCommandId == SecondaryDisplay::ECmdStartupPhaseSkip )
       
   267         {
       
   268         INFO( "Command ECmdStartupPhaseSkip -> cancel animation" );
       
   269 
       
   270         Cancel();
       
   271         }
       
   272 
       
   273     if ( iCommandResponder )
       
   274         {
       
   275         iCommandResponder->IssueResponse(
       
   276             aDomain, aCategory, aCommandId, KErrNone, TPckgBuf<TInt>( 0 ) );
       
   277         }
       
   278     }
       
   279 
       
   280 
       
   281 // ----------------------------------------------------------------------------
       
   282 // CSAnimStartupCtrl::CancelMediatorCommand
       
   283 //
       
   284 // ----------------------------------------------------------------------------
       
   285 //
       
   286 void CSAnimStartupCtrl::CancelMediatorCommand(
       
   287     TUid /*aDomain*/,
       
   288     TUid /*aCategory*/,
       
   289     TInt /*aCommandId*/ )
       
   290     {
       
   291     FUNC_LOG;
       
   292     }
       
   293 
       
   294 
       
   295 // ----------------------------------------------------------------------------
       
   296 // CSAnimStartupCtrl::CommandResponseL
       
   297 //
       
   298 // ----------------------------------------------------------------------------
       
   299 //
       
   300 void CSAnimStartupCtrl::CommandResponseL(
       
   301     TUid aDomain,
       
   302     TUid aCategory,
       
   303     TInt aCommandId,
       
   304     TInt /*aStatus*/,
       
   305     const TDesC8& /*aData*/ )
       
   306     {
       
   307     FUNC_LOG;
       
   308     INFO_3( "Domain: 0x%08x, category: 0x%08x, %d", aDomain.iUid, aCategory.iUid, aCommandId );
       
   309 
       
   310     if ( aDomain == KMediatorSecondaryDisplayDomain &&
       
   311          aCategory == SecondaryDisplay::KCatStartup &&
       
   312          aCommandId == SecondaryDisplay::ECmdStartupSync &&
       
   313          iWaitingForSyncResponse )
       
   314         {
       
   315         iWaitingForSyncResponse = EFalse;
       
   316         StartAnimation();
       
   317         }
       
   318     }
       
   319 
       
   320 
       
   321 // ---------------------------------------------------------------------------
       
   322 // CSAnimStartupCtrl::CSAnimStartupCtrl
       
   323 //
       
   324 // ---------------------------------------------------------------------------
       
   325 //
       
   326 EXPORT_C CSAnimStartupCtrl::CSAnimStartupCtrl()
       
   327   : iPlayDefaultBeep( EFalse ),
       
   328     iSyncCommand( 0 ),
       
   329     iHasContent( EFalse ),
       
   330     iWaitingForSyncResponse( EFalse )
       
   331     {
       
   332     FUNC_LOG;
       
   333     }
       
   334 
       
   335 
       
   336 // ---------------------------------------------------------------------------
       
   337 // CSAnimStartupCtrl::ConstructL
       
   338 //
       
   339 // ---------------------------------------------------------------------------
       
   340 //
       
   341 EXPORT_C void CSAnimStartupCtrl::ConstructL(
       
   342     const TRect& aRect,
       
   343     const CCoeControl& aContainer )
       
   344     {
       
   345     FUNC_LOG;
       
   346 
       
   347     FeatureManager::InitializeLibL();
       
   348     TBool secondaryDisplaySupported =
       
   349         FeatureManager::FeatureSupported( KFeatureIdCoverDisplay );
       
   350     FeatureManager::UnInitializeLib();
       
   351 
       
   352     if ( secondaryDisplaySupported )
       
   353         {
       
   354         iCommandInitiator = CMediatorCommandInitiator::NewL( this );
       
   355         iCommandResponder = CMediatorCommandResponder::NewL( this );
       
   356 
       
   357         TInt errorCode = iCommandResponder->RegisterCommand(
       
   358             KMediatorSecondaryDisplayDomain,
       
   359             SecondaryDisplay::KCatStartup,
       
   360             SecondaryDisplay::ECmdStartupPhaseSkip,
       
   361             TVersion( 0, 0, 0 ),
       
   362             ECapabilitySwEvent,
       
   363             KMediatorTimeout );
       
   364         ERROR( errorCode, "Failed to register command ECmdStartupPhaseSkip with mediator" );
       
   365         User::LeaveIfError( errorCode );
       
   366         }
       
   367 
       
   368     CSAnimCtrl::BaseConstructL( aRect, aContainer );
       
   369     }
       
   370 
       
   371 
       
   372 // ---------------------------------------------------------------------------
       
   373 // CSAnimStartupCtrl::LoadL
       
   374 //
       
   375 // ---------------------------------------------------------------------------
       
   376 //
       
   377 void CSAnimStartupCtrl::LoadL(
       
   378     const TAnimationParams& aParams,
       
   379     TRequestStatus& aStatus )
       
   380     {
       
   381     FUNC_LOG;
       
   382 
       
   383     CRepository* repository = CRepository::NewLC( aParams.iRepositoryUid );
       
   384 
       
   385     TPath img;
       
   386     ReadFileNameL(
       
   387         iCoeEnv->FsSession(), *repository, aParams.iAnimationPathKey, img );
       
   388     TTimeIntervalMicroSeconds32 frameDelay( 0 );
       
   389     TInt scaling( 0 );
       
   390     if ( img.Length() > 0 )
       
   391         {
       
   392         frameDelay = ReadIntValue( *repository, aParams.iFrameDelayKey );
       
   393         scaling = ReadIntValue( *repository, aParams.iEnableScalingKey );
       
   394         }
       
   395 
       
   396     TPath tone;
       
   397     TInt volume = ReadVolume( *repository, aParams.iVolumeKey );
       
   398     if ( volume > 0 )
       
   399         {
       
   400         ReadFileNameL(
       
   401             iCoeEnv->FsSession(), *repository, aParams.iTonePathKey, tone );
       
   402 
       
   403         iPlayDefaultBeep = iPlayDefaultBeep && tone.Length() <= 0;
       
   404         }
       
   405 
       
   406     iHasContent = ( img.Length() > 0 || tone.Length() > 0 );
       
   407 
       
   408     CleanupStack::PopAndDestroy( repository );
       
   409 
       
   410     CSAnimCtrl::Load(
       
   411         img, frameDelay, scaling, KDefaultRepeatCount,
       
   412         tone, volume, KDefaultVolumeRamp, KDefaultRepeatCount,
       
   413         aStatus );
       
   414     }
       
   415 
       
   416 
       
   417 // ---------------------------------------------------------------------------
       
   418 // CSAnimStartupCtrl::ReadFileNameL
       
   419 //
       
   420 // ---------------------------------------------------------------------------
       
   421 //
       
   422 void CSAnimStartupCtrl::ReadFileNameL(
       
   423     RFs& aFs,
       
   424     CRepository& aRepository,
       
   425     const TUint32 aKey,
       
   426     TDes& aBuf )
       
   427     {
       
   428     FUNC_LOG;
       
   429 
       
   430     TInt errorCode = aRepository.Get( aKey, aBuf );
       
   431     ERROR_1( errorCode, "Failed to read value of key %d", aKey );
       
   432     if ( errorCode != KErrNone || !FileExists( aFs, aBuf ) )
       
   433         {
       
   434         aBuf = KNullDesC;
       
   435         }
       
   436     }
       
   437 
       
   438 
       
   439 // ---------------------------------------------------------------------------
       
   440 // CSAnimStartupCtrl::ReadVolume
       
   441 //
       
   442 // ---------------------------------------------------------------------------
       
   443 //
       
   444 TInt CSAnimStartupCtrl::ReadVolume(
       
   445     CRepository& aRepository,
       
   446     const TUint32 aKey )
       
   447     {
       
   448     FUNC_LOG;
       
   449 
       
   450     TInt volume( 0 );
       
   451     TInt errorCode = aRepository.Get( aKey, volume );
       
   452     ERROR( errorCode, "Failed to get volume level from central repository" );
       
   453 
       
   454     if ( volume > 0 )
       
   455         {
       
   456         TBool isSilent = ETrue;
       
   457         TRAPD_ERR( errorCode, isSilent = IsSilentL() );
       
   458         ERROR( errorCode, "Failed to silent info" );
       
   459         if ( isSilent )
       
   460             {
       
   461             volume = 0;
       
   462             }
       
   463         }
       
   464 
       
   465     TInt retVal = Max( KMinVolume, Min( volume, KMaxVolume ) );
       
   466 
       
   467     INFO_1( "Volume: %d", retVal );
       
   468 
       
   469     return retVal;
       
   470     }
       
   471 
       
   472 
       
   473 // ---------------------------------------------------------------------------
       
   474 // CSAnimStartupCtrl::ReadIntValue
       
   475 //
       
   476 // ---------------------------------------------------------------------------
       
   477 //
       
   478 TInt CSAnimStartupCtrl::ReadIntValue(
       
   479     CRepository& aRepository,
       
   480     const TUint32 aKey )
       
   481     {
       
   482     FUNC_LOG;
       
   483 
       
   484     TInt value( 0 );
       
   485     TInt errorCode = aRepository.Get( aKey, value );
       
   486     ERROR_1( errorCode, "Failed to read value of key 0x%08x from central repository", aKey );
       
   487     return value;
       
   488     }
       
   489 
       
   490 
       
   491 // ---------------------------------------------------------------------------
       
   492 // CSAnimStartupCtrl::StartAnimation
       
   493 //
       
   494 // ---------------------------------------------------------------------------
       
   495 //
       
   496 void CSAnimStartupCtrl::StartAnimation()
       
   497     {
       
   498     FUNC_LOG;
       
   499 
       
   500     if ( iClientStatus )
       
   501         {
       
   502         iBackgroundColour = iEngine->BackroundColour();
       
   503 
       
   504         if ( iPlayDefaultBeep )
       
   505             {
       
   506             INFO( "Default startup beep requested" );
       
   507 
       
   508             CAknAppUi* appUi = static_cast<CAknAppUi*>( iEikonEnv->EikAppUi() );
       
   509             if ( appUi )
       
   510                 {
       
   511                 INFO( "Playing default startup beep" );
       
   512 
       
   513                 appUi->KeySounds()->PlaySound( EAvkonSIDPowerOnTone );
       
   514                 }
       
   515             }
       
   516 
       
   517         iEngine->Start( *iClientStatus );
       
   518         iClientStatus = NULL;
       
   519         }
       
   520     }
       
   521