usbuis/usbuinotif/src/usbnotifier.cpp
changeset 52 831068540b07
parent 3 47c263f7e521
child 71 173beb545395
equal deleted inserted replaced
51:e7f64b6bf69e 52:831068540b07
     1 /*
     1 /*
     2  * Copyright (c) 2005-2009 Nokia Corporation and/or its subsidiary(-ies).
     2  * Copyright (c) 2005-2010 Nokia Corporation and/or its subsidiary(-ies).
     3  * All rights reserved.
     3  * All rights reserved.
     4  * This component and the accompanying materials are made available
     4  * This component and the accompanying materials are made available
     5  * under the terms of "Eclipse Public License v1.0"
     5  * under the terms of "Eclipse Public License v1.0"
     6  * which accompanies this distribution, and is available
     6  * which accompanies this distribution, and is available
     7  * at the URL "http://www.eclipse.org/legal/epl-v10.html".
     7  * at the URL "http://www.eclipse.org/legal/epl-v10.html".
    14  * Description:  Declares USB UI notifiers base class.
    14  * Description:  Declares USB UI notifiers base class.
    15  *
    15  *
    16  */
    16  */
    17 
    17 
    18 // INCLUDE FILES
    18 // INCLUDE FILES
    19 #include <eikenv.h>          // Eikon environment
    19 
    20 #include <bautils.h>         // BAFL utils (for language file)
    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> 
    21 #include <data_caging_path_literals.hrh> 
    25 #include <featmgr.h>
       
    26 #include <AknNotiferAppServerApplication.h>
    22 #include <AknNotiferAppServerApplication.h>
       
    23 #include <hb/hbcore/hbtextresolversymbian.h>
    27 
    24 
    28 #include "usbnotifier.h"     // Own class 
    25 #include "usbnotifier.h"     // Own class 
    29 #include "usbuinotifdebug.h"
    26 #include "usbuinotifdebug.h"
    30 #include "aknkeylock.h" //RAknKeyLock
    27 
    31 // CONSTANTS
    28 // CONSTANTS
    32 
    29 
    33 // ================= MEMBER FUNCTIONS =========================================
    30 // ================= MEMBER FUNCTIONS =========================================
    34 
    31 
    35 // ----------------------------------------------------------------------------
    32 // ----------------------------------------------------------------------------
    37 // C++ default constructor can NOT contain any code, that
    34 // C++ default constructor can NOT contain any code, that
    38 // might leave. Sets the AOs priority and puts
    35 // might leave. Sets the AOs priority and puts
    39 // itself to the active scheduler stack.
    36 // itself to the active scheduler stack.
    40 // ----------------------------------------------------------------------------
    37 // ----------------------------------------------------------------------------
    41 //
    38 //
    42 CUSBUINotifierBase::CUSBUINotifierBase() :
    39 CUSBUINotifierBase::CUSBUINotifierBase() 
    43     CActive( EPriorityStandard )
       
    44     {
    40     {
    45         FLOG(_L("[USBUINOTIF]\t CUSBUINotifierBase::Default constructor()"));
    41         FLOG(_L("[USBUINOTIF]\t CUSBUINotifierBase::Default constructor()"));
    46     CActiveScheduler::Add( this );
       
    47     }
    42     }
    48 
    43 
    49 // ----------------------------------------------------------------------------
    44 // ----------------------------------------------------------------------------
    50 // CUSBUINotifierBase::ConstructL
    45 // CUSBUINotifierBase::ConstructL
    51 // Symbian 2nd phase constructor can leave.
    46 // Symbian 2nd phase constructor can leave.
    53 // ----------------------------------------------------------------------------
    48 // ----------------------------------------------------------------------------
    54 //
    49 //
    55 void CUSBUINotifierBase::ConstructL()
    50 void CUSBUINotifierBase::ConstructL()
    56     {
    51     {
    57     iEikEnv = CEikonEnv::Static();
    52     iEikEnv = CEikonEnv::Static();
    58     iAppsKeyBlocked = EFalse;
    53    
    59     iKeylockChanged = EFalse;
       
    60 
       
    61     FLOG(_L("[USBUINOTIF]\t CUSBUINotifierBase::ConstructL()"));
    54     FLOG(_L("[USBUINOTIF]\t CUSBUINotifierBase::ConstructL()"));
    62     TFileName filename;
    55         
    63 
    56     // use TLS as a boolean, set to EFalse
    64     const TDriveNumber KStoreDrive = EDriveZ;
    57     TBool initialized = EFalse;
    65     TDriveUnit driveUnit( KStoreDrive );
    58     TInt error;
    66     TDriveName drive = driveUnit.Name();
    59     error = Dll::SetTls((TAny* )initialized); 
    67     filename.Insert( 0, drive );
    60     error = error; // to suppress a compiler warning
    68 
    61     FTRACE(FPrint(_L("[USBUINOTIF]\t Dll:SetTls returned %d"), error ));       
    69     filename += KDC_RESOURCE_FILES_DIR; // From data_caging_path_literals.hrh
    62    
    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"));
    63     FLOG(_L("[USBUINOTIF]\t CUSBUINotifierBase::ConstructL() completed"));
    80     }
    64     }
    81 
    65 
    82 // ----------------------------------------------------------------------------
    66 // ----------------------------------------------------------------------------
    83 // Destructor.
    67 // Destructor.
    88     FLOG(_L("[USBUINOTIF]\t CUSBUINotifierBase::Destructor"));
    72     FLOG(_L("[USBUINOTIF]\t CUSBUINotifierBase::Destructor"));
    89     //Make sure that the request is completed. Note that inside the destructor,
    73     //Make sure that the request is completed. Note that inside the destructor,
    90     //this virtual function call is to the local CUSBUINotifierBase::Cancel, 
    74     //this virtual function call is to the local CUSBUINotifierBase::Cancel, 
    91     //not to any possibly derived class implementation. 
    75     //not to any possibly derived class implementation. 
    92     Cancel();
    76     Cancel();
    93     iEikEnv->DeleteResourceFile( iResourceFileFlag );
    77  
    94 
       
    95     // Complete the RMessage2 if needed
    78     // Complete the RMessage2 if needed
    96     //
    79     //
    97     CompleteMessage( KErrDied );
    80     CompleteMessage( KErrDied );
    98 
    81 
    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"));
    82     FLOG(_L("[USBUINOTIF]\t CUSBUINotifierBase::Destructor completed"));
   107     }
    83     }
   108 
    84 
   109 // ----------------------------------------------------------------------------
    85 // ----------------------------------------------------------------------------
   110 // CUSBUINotifierBase::Release
    86 // CUSBUINotifierBase::Release
   148 //
   124 //
   149 void CUSBUINotifierBase::StartL(const TDesC8& aBuffer, TInt aReplySlot,
   125 void CUSBUINotifierBase::StartL(const TDesC8& aBuffer, TInt aReplySlot,
   150         const RMessagePtr2& aMessage)
   126         const RMessagePtr2& aMessage)
   151     {
   127     {
   152     FLOG(_L("[USBUINOTIF]\t CUSBUINotifierBase::StartL()"));
   128     FLOG(_L("[USBUINOTIF]\t CUSBUINotifierBase::StartL()"));
   153     TRAPD( err, GetParamsL( aBuffer, aReplySlot, aMessage ));
   129     TRAPD( err, StartDialogL( aBuffer, aReplySlot, aMessage ));
   154     if (err)
   130     if (err)
   155         {
   131         {
   156         aMessage.Complete( err );
   132         aMessage.Complete( err );
   157         iNeedToCompleteMessage = EFalse;
   133         iNeedToCompleteMessage = EFalse;
   158         User::Leave( err );
   134         User::Leave( err );
   166 // ----------------------------------------------------------------------------
   142 // ----------------------------------------------------------------------------
   167 //
   143 //
   168 void CUSBUINotifierBase::Cancel()
   144 void CUSBUINotifierBase::Cancel()
   169     {
   145     {
   170     FLOG(_L("[USBUINOTIF]\t CUSBUINotifierBase::Cancel()"));
   146     FLOG(_L("[USBUINOTIF]\t CUSBUINotifierBase::Cancel()"));
   171     CActive::Cancel();
   147     //The message box closed callback gets not run in subclass cancel calls.
   172     FLOG(_L("[USBUINOTIF]\t CUSBUINotifierBase::Cancel completed()"));
   148     CompleteMessage(KErrCancel);
       
   149     FLOG(_L("[USBUINOTIF]\t CUSBUINotifierBase::Cancel completed"));
   173     }
   150     }
   174 
   151 
   175 // ----------------------------------------------------------------------------
   152 // ----------------------------------------------------------------------------
   176 // CUSBUINotifierBase::UpdateL
   153 // CUSBUINotifierBase::UpdateL
   177 // Notifier update. Not supported.
   154 // Notifier update. Not supported.
   179 //
   156 //
   180 TPtrC8 CUSBUINotifierBase::UpdateL(const TDesC8& /*aBuffer*/)
   157 TPtrC8 CUSBUINotifierBase::UpdateL(const TDesC8& /*aBuffer*/)
   181     {
   158     {
   182     TPtrC8 ret( KNullDesC8 );
   159     TPtrC8 ret( KNullDesC8 );
   183     return (ret);
   160     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     }
   161     }
   243 
   162 
   244 // ----------------------------------------------------------------------------
   163 // ----------------------------------------------------------------------------
   245 // CUSBUINotifierBase::CompleteMessage
   164 // CUSBUINotifierBase::CompleteMessage
   246 // Check if message needs to be completed and complete it. 
   165 // Check if message needs to be completed and complete it. 
   256         }
   175         }
   257     iReplySlot = 0;
   176     iReplySlot = 0;
   258     FLOG(_L("[USBUINOTIF]\t CUSBUINotifierBase::CompleteMessage() completed"));
   177     FLOG(_L("[USBUINOTIF]\t CUSBUINotifierBase::CompleteMessage() completed"));
   259     }
   178     }
   260 
   179 
   261 // ----------------------------------------------------------------------------
   180 void CUSBUINotifierBase::InitializeTextResolver()
   262 // CUSBUINotifierBase::DisableKeylock
   181     {
   263 // ----------------------------------------------------------------------------
   182     _LIT(KFileName, "usbdialogs_");
   264 // Turn off the keyguard if it was on.
   183     _LIT(KPath, "z:/resource/qt/translations/");         
   265 //
   184     TInt error;
   266 void CUSBUINotifierBase::DisableKeylock()
   185         
   267     {
   186     iTranslator = (TBool )Dll::Tls();
   268     FLOG(_L("[USBUINOTIF]\t CUSBUINotifierBase::DisableKeylock()"));
   187     
   269     RAknKeylock2 keylock;
   188     FTRACE(FPrint(_L("[USBUINOTIF]\t Dll:Tls returned %d"), iTranslator ));    
   270     iKeylockChanged = EFalse;
   189     
   271     if (KErrNone == keylock.Connect())
   190     if (!iTranslator)
   272         {
   191         {
   273         if (keylock.IsKeyLockEnabled()) //Check and save the keylock status
   192         iTranslator = HbTextResolverSymbian::Init(KFileName, KPath);
       
   193         FTRACE(FPrint(_L("[USBUINOTIF]\t HbTextResolverSymbian::Init returned %d"), iTranslator ));    
       
   194         if (iTranslator)
   274             {
   195             {
   275             keylock.DisableWithoutNote();// Unlock
   196             error = Dll::SetTls((TAny* )iTranslator);      
   276             iKeylockChanged = ETrue;
       
   277             }
   197             }
   278         keylock.Close();
   198         FTRACE(FPrint(_L("[USBUINOTIF]\t Dll:SetTls returned %d"), error ));    
   279         }
   199         }    
   280     else
   200        
   281         {
   201      error = error;   // to suppress a compiler warning
   282         FLOG( _L( "[USBUINOTIF]\t CUSBUINotifierBase::DisableKeylock() fail caused by RAknKeylock2::Connect()") );
   202      FTRACE( FPrint(
   283         }
   203         _L( "[USBUINOTIF]\t CUSBUINotifierBase::InitializeTextResolver result = %d" ),
   284 
   204         iTranslator ) );                     
   285     FLOG(_L("[USBUINOTIF]\t CUSBUINotifierBase::DisableKeylock() completed"));
   205         
   286     }
   206     }
   287 
   207 
   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 
   208 
   318 // End of File
   209 // End of File