usbuis/usbuinotif/src/usbnotifier.cpp
changeset 0 1e05558e2206
child 3 47c263f7e521
equal deleted inserted replaced
-1:000000000000 0:1e05558e2206
       
     1 /*
       
     2  * Copyright (c) 2005-2009 Nokia Corporation and/or its subsidiary(-ies).
       
     3  * All rights reserved.
       
     4  * This component and the accompanying materials are made available
       
     5  * under the terms of "Eclipse Public License v1.0"
       
     6  * which accompanies this distribution, and is available
       
     7  * at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     8  *
       
     9  * Initial Contributors:
       
    10  * Nokia Corporation - initial contribution.
       
    11  *
       
    12  * Contributors:
       
    13  *
       
    14  * Description:  Declares USB UI notifiers base class.
       
    15  *
       
    16  */
       
    17 
       
    18 // INCLUDE FILES
       
    19 #include <eikenv.h>          // Eikon environment
       
    20 #include <bautils.h>         // BAFL utils (for language file)
       
    21 #include <stringloader.h>    // Localisation stringloader
       
    22 #include <centralrepository.h> 
       
    23 #include <coreapplicationuisdomainpskeys.h>
       
    24 #include <data_caging_path_literals.hrh> 
       
    25 #include <featmgr.h>
       
    26 #include <AknNotiferAppServerApplication.h>
       
    27 
       
    28 #include "usbnotifier.h"     // Own class 
       
    29 #include "usbuinotifdebug.h"
       
    30 #include "AknKeyLock.h" //RAknKeyLock
       
    31 // CONSTANTS
       
    32 
       
    33 // ================= MEMBER FUNCTIONS =========================================
       
    34 
       
    35 // ----------------------------------------------------------------------------
       
    36 // CUSBUINotifierBase::CBTNotifierBase
       
    37 // C++ default constructor can NOT contain any code, that
       
    38 // might leave. Sets the AOs priority and puts
       
    39 // itself to the active scheduler stack.
       
    40 // ----------------------------------------------------------------------------
       
    41 //
       
    42 CUSBUINotifierBase::CUSBUINotifierBase() :
       
    43     CActive( EPriorityStandard )
       
    44     {
       
    45         FLOG(_L("[USBUINOTIF]\t CUSBUINotifierBase::Default constructor()"));
       
    46     CActiveScheduler::Add( this );
       
    47     }
       
    48 
       
    49 // ----------------------------------------------------------------------------
       
    50 // CUSBUINotifierBase::ConstructL
       
    51 // Symbian 2nd phase constructor can leave.
       
    52 // Create registry object and open resource file.
       
    53 // ----------------------------------------------------------------------------
       
    54 //
       
    55 void CUSBUINotifierBase::ConstructL()
       
    56     {
       
    57     iEikEnv = CEikonEnv::Static();
       
    58     iAppsKeyBlocked = EFalse;
       
    59     iKeylockChanged = EFalse;
       
    60 
       
    61     FLOG(_L("[USBUINOTIF]\t CUSBUINotifierBase::ConstructL()"));
       
    62     TFileName filename;
       
    63 
       
    64     const TDriveNumber KStoreDrive = EDriveZ;
       
    65     TDriveUnit driveUnit( KStoreDrive );
       
    66     TDriveName drive = driveUnit.Name();
       
    67     filename.Insert( 0, drive );
       
    68 
       
    69     filename += KDC_RESOURCE_FILES_DIR; // From data_caging_path_literals.hrh
       
    70     filename += KResourceFileName;
       
    71     BaflUtils::NearestLanguageFile( iEikEnv->FsSession(), filename );
       
    72     iResourceFileFlag = iEikEnv->AddResourceFileL( filename );
       
    73 
       
    74     FeatureManager::InitializeLibL();
       
    75     iCoverDisplaySupported = FeatureManager::FeatureSupported(
       
    76             KFeatureIdCoverDisplay );
       
    77     FeatureManager::UnInitializeLib();
       
    78 
       
    79     FLOG(_L("[USBUINOTIF]\t CUSBUINotifierBase::ConstructL() completed"));
       
    80     }
       
    81 
       
    82 // ----------------------------------------------------------------------------
       
    83 // Destructor.
       
    84 // ----------------------------------------------------------------------------
       
    85 //
       
    86 CUSBUINotifierBase::~CUSBUINotifierBase()
       
    87     {
       
    88     FLOG(_L("[USBUINOTIF]\t CUSBUINotifierBase::Destructor"));
       
    89     //Make sure that the request is completed. Note that inside the destructor,
       
    90     //this virtual function call is to the local CUSBUINotifierBase::Cancel, 
       
    91     //not to any possibly derived class implementation. 
       
    92     Cancel();
       
    93     iEikEnv->DeleteResourceFile( iResourceFileFlag );
       
    94 
       
    95     // Complete the RMessage2 if needed
       
    96     //
       
    97     CompleteMessage( KErrDied );
       
    98 
       
    99     // Activate apps -key again (if not previously activated yet)
       
   100     SuppressAppSwitching( EFalse );
       
   101 
       
   102     // Restore the keylock if not restored before (caused by Leave).
       
   103     // If the Keylock is restored already, the function does nothing.
       
   104     RestoreKeylock();
       
   105 
       
   106     FLOG(_L("[USBUINOTIF]\t CUSBUINotifierBase::Destructor completed"));
       
   107     }
       
   108 
       
   109 // ----------------------------------------------------------------------------
       
   110 // CUSBUINotifierBase::Release
       
   111 // Release itself. Call to destructor.
       
   112 // ----------------------------------------------------------------------------
       
   113 //
       
   114 void CUSBUINotifierBase::Release()
       
   115     {
       
   116     FLOG(_L("[USBUINOTIF]\t CUSBUINotifierBase::Release()"));
       
   117     delete this;
       
   118     }
       
   119 
       
   120 // ----------------------------------------------------------------------------
       
   121 // CUSBUINotifierBase::Info
       
   122 // Return registered information.
       
   123 // ----------------------------------------------------------------------------
       
   124 //
       
   125 CUSBUINotifierBase::TNotifierInfo CUSBUINotifierBase::Info() const
       
   126     {
       
   127     FTRACE(FPrint(_L("[USBUINOTIF]\t CUSBUINotifierBase::Info() id %d channel %d priority %d"), iInfo.iUid, iInfo.iChannel, iInfo.iPriority ));
       
   128     return iInfo;
       
   129     }
       
   130 
       
   131 // ----------------------------------------------------------------------------
       
   132 // CUSBUINotifierBase::StartL
       
   133 // Synchronic notifier launch. Does nothing
       
   134 // ----------------------------------------------------------------------------
       
   135 //
       
   136 TPtrC8 CUSBUINotifierBase::StartL(const TDesC8& /*aBuffer*/)
       
   137     {
       
   138     FLOG(_L("[USBUINOTIF]\t CUSBUINotifierBase::StartL()"));
       
   139 
       
   140     TPtrC8 ret( KNullDesC8 );
       
   141     return (ret);
       
   142     }
       
   143 
       
   144 // ----------------------------------------------------------------------------
       
   145 // CUSBUINotifierBase::StartL
       
   146 // Asynchronic notifier launch.
       
   147 // ----------------------------------------------------------------------------
       
   148 //
       
   149 void CUSBUINotifierBase::StartL(const TDesC8& aBuffer, TInt aReplySlot,
       
   150         const RMessagePtr2& aMessage)
       
   151     {
       
   152     FLOG(_L("[USBUINOTIF]\t CUSBUINotifierBase::StartL()"));
       
   153     TRAPD( err, GetParamsL( aBuffer, aReplySlot, aMessage ));
       
   154     if (err)
       
   155         {
       
   156         aMessage.Complete( err );
       
   157         iNeedToCompleteMessage = EFalse;
       
   158         User::Leave( err );
       
   159         }
       
   160     FLOG(_L("[USBUINOTIF]\t CUSBUINotifierBase::StartL completed()"));
       
   161     }
       
   162 
       
   163 // ----------------------------------------------------------------------------
       
   164 // CUSBUINotifierBase::Cancel
       
   165 // Cancelling method.
       
   166 // ----------------------------------------------------------------------------
       
   167 //
       
   168 void CUSBUINotifierBase::Cancel()
       
   169     {
       
   170     FLOG(_L("[USBUINOTIF]\t CUSBUINotifierBase::Cancel()"));
       
   171     CActive::Cancel();
       
   172     FLOG(_L("[USBUINOTIF]\t CUSBUINotifierBase::Cancel completed()"));
       
   173     }
       
   174 
       
   175 // ----------------------------------------------------------------------------
       
   176 // CUSBUINotifierBase::UpdateL
       
   177 // Notifier update. Not supported.
       
   178 // ----------------------------------------------------------------------------
       
   179 //
       
   180 TPtrC8 CUSBUINotifierBase::UpdateL(const TDesC8& /*aBuffer*/)
       
   181     {
       
   182     TPtrC8 ret( KNullDesC8 );
       
   183     return (ret);
       
   184     }
       
   185 
       
   186 // ----------------------------------------------------------------------------
       
   187 // CUSBUINotifierBase::DoCancel
       
   188 // This method will be called by framework (CActive)
       
   189 // if active object is still active.
       
   190 // Does nothing here.
       
   191 // ----------------------------------------------------------------------------
       
   192 //
       
   193 void CUSBUINotifierBase::DoCancel()
       
   194     {
       
   195     FLOG(_L("[USBUINOTIF]\t CUSBUINotifierBase::DoCancel()"));
       
   196     }
       
   197 
       
   198 // ----------------------------------------------------------------------------
       
   199 // CUSBUINotifierBase::RunError
       
   200 // This method is called if any leaving has been occured
       
   201 // during RunL. Optional method for CActive derived objects.
       
   202 // ----------------------------------------------------------------------------
       
   203 //
       
   204 TInt CUSBUINotifierBase::RunError(TInt aError)
       
   205     {
       
   206     FLOG(_L("[USBUINOTIF]\t CUSBUINotifierBase::RunError()"));
       
   207 
       
   208     // Activate apps -key again (if not previously activated yet)
       
   209     //
       
   210     SuppressAppSwitching( EFalse );
       
   211 
       
   212     // Write error message to caller
       
   213     //
       
   214     CompleteMessage( aError );
       
   215 
       
   216     FLOG(_L("[USBUINOTIF]\t CUSBUINotifierBase::RunError() completed"));
       
   217 
       
   218     return aError;
       
   219     }
       
   220 
       
   221 // ----------------------------------------------------------------------------
       
   222 // CUSBUINotifierBase::SuppressAppSwitching
       
   223 // 
       
   224 // ----------------------------------------------------------------------------
       
   225 //
       
   226 void CUSBUINotifierBase::SuppressAppSwitching(TBool aEnable)
       
   227     {
       
   228     FTRACE(FPrint(_L("[USBUINOTIF]\t CUSBUINotifierBase::SuppressAppSwitching() %d"), aEnable));
       
   229 
       
   230     if (iAppsKeyBlocked != aEnable)
       
   231         {
       
   232         TInt err = iAknServer.ConnectAndSendAppsKeySuppress( aEnable ); // error is stored only for logging purposes
       
   233         iAppsKeyBlocked = aEnable;
       
   234         FTRACE(FPrint(_L("[USBUINOTIF]\t CUSBUINotifierBase::SuppressAppSwitching() ConnectAndSendAppsKeySuppress returned %d"), err ));
       
   235         }
       
   236 
       
   237     if (!iAppsKeyBlocked)
       
   238         {
       
   239         iAknServer.Close(); // close the connection once we have re-enabled swithcing
       
   240         }
       
   241     FLOG(_L("[USBUINOTIF]\t CUSBUINotifierBase::SuppressAppSwitching() completed"));
       
   242     }
       
   243 
       
   244 // ----------------------------------------------------------------------------
       
   245 // CUSBUINotifierBase::CompleteMessage
       
   246 // Check if message needs to be completed and complete it. 
       
   247 // ----------------------------------------------------------------------------
       
   248 //
       
   249 void CUSBUINotifierBase::CompleteMessage(TInt aReason)
       
   250     {
       
   251     FLOG(_L("[USBUINOTIF]\t CUSBUINotifierBase::CompleteMessage()"));
       
   252     if (iNeedToCompleteMessage)
       
   253         {
       
   254         iMessage.Complete( aReason );
       
   255         iNeedToCompleteMessage = EFalse;
       
   256         }
       
   257     iReplySlot = 0;
       
   258     FLOG(_L("[USBUINOTIF]\t CUSBUINotifierBase::CompleteMessage() completed"));
       
   259     }
       
   260 
       
   261 // ----------------------------------------------------------------------------
       
   262 // CUSBUINotifierBase::DisableKeylock
       
   263 // ----------------------------------------------------------------------------
       
   264 // Turn off the keyguard if it was on.
       
   265 //
       
   266 void CUSBUINotifierBase::DisableKeylock()
       
   267     {
       
   268     FLOG(_L("[USBUINOTIF]\t CUSBUINotifierBase::DisableKeylock()"));
       
   269     RAknKeylock2 keylock;
       
   270     iKeylockChanged = EFalse;
       
   271     if (KErrNone == keylock.Connect())
       
   272         {
       
   273         if (keylock.IsKeyLockEnabled()) //Check and save the keylock status
       
   274             {
       
   275             keylock.DisableWithoutNote();// Unlock
       
   276             iKeylockChanged = ETrue;
       
   277             }
       
   278         keylock.Close();
       
   279         }
       
   280     else
       
   281         {
       
   282         FLOG( _L( "[USBUINOTIF]\t CUSBUINotifierBase::DisableKeylock() fail caused by RAknKeylock2::Connect()") );
       
   283         }
       
   284 
       
   285     FLOG(_L("[USBUINOTIF]\t CUSBUINotifierBase::DisableKeylock() completed"));
       
   286     }
       
   287 
       
   288 // ----------------------------------------------------------------------------
       
   289 // CUSBUINotifierBase::RestoreKeylock
       
   290 // ----------------------------------------------------------------------------
       
   291 // Restore the keyguard on.
       
   292 //
       
   293 void CUSBUINotifierBase::RestoreKeylock()
       
   294     {
       
   295     FLOG(_L("[USBUINOTIF]\t CUSBUINotifierBase::RestoreKeylock()"));
       
   296     if (iKeylockChanged)
       
   297         {
       
   298         FLOG(_L("[USBUINOTIF]\t CUSBUINotifierBase::RestoreKeylock(): iKeylockChanged true"));
       
   299         RAknKeylock2 keylock;
       
   300         FLOG(_L("[USBUINOTIF]\t CUSBUINotifierBase::RestoreKeylock(): RAknKeyLock2 initialized"));
       
   301         if (KErrNone == keylock.Connect())
       
   302             {
       
   303             FLOG(_L("[USBUINOTIF]\t CUSBUINotifierBase::RestoreKeylock(): RAknKeyLock2::Connect() complete"));
       
   304             keylock.EnableWithoutNote();// Lock back
       
   305             FLOG(_L("[USBUINOTIF]\t CUSBUINotifierBase::RestoreKeylock(): RAknKeyLock2::EnableWithoutNote() complete"));
       
   306             keylock.Close();
       
   307             FLOG(_L("[USBUINOTIF]\t CUSBUINotifierBase::RestoreKeylock(): RAknKeyLock2::Close() complete"));
       
   308             iKeylockChanged = EFalse;
       
   309             }
       
   310         else
       
   311             {
       
   312             FLOG( _L( "[USBUINOTIF]\t CUSBUINotifierBase::RestoreKeylock() fail caused by RAknKeylock2::Connect()") );
       
   313             }
       
   314         }
       
   315     FLOG(_L("[USBUINOTIF]\t CUSBUINotifierBase::RestoreKeylock() completed"));
       
   316     }
       
   317 
       
   318 // End of File