usbuis/usbuinotif/src/usbnotifier.cpp
branchRCL_3
changeset 79 25fce757be94
parent 33 d895b6d953c9
child 80 e02eb84a14d2
equal deleted inserted replaced
77:5b2a402e96ac 79:25fce757be94
    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>
    22 #include <hb/hbcore/hbtextresolversymbian.h>
    26 #include <AknNotiferAppServerApplication.h>
       
    27 
    23 
    28 #include "usbnotifier.h"     // Own class 
    24 #include "usbnotifier.h"     // Own class 
    29 #include "usbuinotifdebug.h"
    25 #include "usbuinotifdebug.h"
    30 #include "aknkeylock.h" //RAknKeyLock
    26 
    31 // CONSTANTS
    27 // CONSTANTS
    32 
    28 
    33 // ================= MEMBER FUNCTIONS =========================================
    29 // ================= MEMBER FUNCTIONS =========================================
    34 
    30 
    35 // ----------------------------------------------------------------------------
    31 // ----------------------------------------------------------------------------
    37 // C++ default constructor can NOT contain any code, that
    33 // C++ default constructor can NOT contain any code, that
    38 // might leave. Sets the AOs priority and puts
    34 // might leave. Sets the AOs priority and puts
    39 // itself to the active scheduler stack.
    35 // itself to the active scheduler stack.
    40 // ----------------------------------------------------------------------------
    36 // ----------------------------------------------------------------------------
    41 //
    37 //
    42 CUSBUINotifierBase::CUSBUINotifierBase() :
    38 CUSBUINotifierBase::CUSBUINotifierBase() 
    43     CActive( EPriorityStandard )
       
    44     {
    39     {
    45         FLOG(_L("[USBUINOTIF]\t CUSBUINotifierBase::Default constructor()"));
    40         FLOG(_L("[USBUINOTIF]\t CUSBUINotifierBase::Default constructor()"));
    46     CActiveScheduler::Add( this );
       
    47     }
    41     }
    48 
    42 
    49 // ----------------------------------------------------------------------------
    43 // ----------------------------------------------------------------------------
    50 // CUSBUINotifierBase::ConstructL
    44 // CUSBUINotifierBase::ConstructL
    51 // Symbian 2nd phase constructor can leave.
    45 // Symbian 2nd phase constructor can leave.
    53 // ----------------------------------------------------------------------------
    47 // ----------------------------------------------------------------------------
    54 //
    48 //
    55 void CUSBUINotifierBase::ConstructL()
    49 void CUSBUINotifierBase::ConstructL()
    56     {
    50     {
    57     iEikEnv = CEikonEnv::Static();
    51     iEikEnv = CEikonEnv::Static();
    58     iAppsKeyBlocked = EFalse;
    52    
    59     iKeylockChanged = EFalse;
       
    60 
       
    61     FLOG(_L("[USBUINOTIF]\t CUSBUINotifierBase::ConstructL()"));
    53     FLOG(_L("[USBUINOTIF]\t CUSBUINotifierBase::ConstructL()"));
    62     TFileName filename;
    54         
    63 
    55     // use TLS as a boolean, set to EFalse
    64     const TDriveNumber KStoreDrive = EDriveZ;
    56     TBool initialized = EFalse;
    65     TDriveUnit driveUnit( KStoreDrive );
    57     TInt error;
    66     TDriveName drive = driveUnit.Name();
    58     error = Dll::SetTls((TAny* )initialized); 
    67     filename.Insert( 0, drive );
    59     error = error; // to suppress a compiler warning
    68 
    60     FTRACE(FPrint(_L("[USBUINOTIF]\t Dll:SetTls returned %d"), error ));       
    69     filename += KDC_RESOURCE_FILES_DIR; // From data_caging_path_literals.hrh
    61    
    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"));
    62     FLOG(_L("[USBUINOTIF]\t CUSBUINotifierBase::ConstructL() completed"));
    80     }
    63     }
    81 
    64 
    82 // ----------------------------------------------------------------------------
    65 // ----------------------------------------------------------------------------
    83 // Destructor.
    66 // Destructor.
    88     FLOG(_L("[USBUINOTIF]\t CUSBUINotifierBase::Destructor"));
    71     FLOG(_L("[USBUINOTIF]\t CUSBUINotifierBase::Destructor"));
    89     //Make sure that the request is completed. Note that inside the destructor,
    72     //Make sure that the request is completed. Note that inside the destructor,
    90     //this virtual function call is to the local CUSBUINotifierBase::Cancel, 
    73     //this virtual function call is to the local CUSBUINotifierBase::Cancel, 
    91     //not to any possibly derived class implementation. 
    74     //not to any possibly derived class implementation. 
    92     Cancel();
    75     Cancel();
    93     iEikEnv->DeleteResourceFile( iResourceFileFlag );
    76  
    94 
       
    95     // Complete the RMessage2 if needed
    77     // Complete the RMessage2 if needed
    96     //
    78     //
    97     CompleteMessage( KErrDied );
    79     CompleteMessage( KErrDied );
    98 
    80 
    99     // Activate apps -key again (if not previously activated yet)
       
   100     SuppressAppSwitching( EFalse );
       
   101 
       
   102     //Don't call RestoreKeylock here. It's up to specific note notfier logic. 
       
   103     //If failed to RestoreKeylock there, it doesn't matter to leave keylock open.
       
   104 
       
   105     FLOG(_L("[USBUINOTIF]\t CUSBUINotifierBase::Destructor completed"));
    81     FLOG(_L("[USBUINOTIF]\t CUSBUINotifierBase::Destructor completed"));
   106     }
    82     }
   107 
    83 
   108 // ----------------------------------------------------------------------------
    84 // ----------------------------------------------------------------------------
   109 // CUSBUINotifierBase::Release
    85 // CUSBUINotifierBase::Release
   147 //
   123 //
   148 void CUSBUINotifierBase::StartL(const TDesC8& aBuffer, TInt aReplySlot,
   124 void CUSBUINotifierBase::StartL(const TDesC8& aBuffer, TInt aReplySlot,
   149         const RMessagePtr2& aMessage)
   125         const RMessagePtr2& aMessage)
   150     {
   126     {
   151     FLOG(_L("[USBUINOTIF]\t CUSBUINotifierBase::StartL()"));
   127     FLOG(_L("[USBUINOTIF]\t CUSBUINotifierBase::StartL()"));
   152     TRAPD( err, GetParamsL( aBuffer, aReplySlot, aMessage ));
   128     TRAPD( err, StartDialogL( aBuffer, aReplySlot, aMessage ));
   153     if (err)
   129     if (err)
   154         {
   130         {
   155         aMessage.Complete( err );
   131         aMessage.Complete( err );
   156         iNeedToCompleteMessage = EFalse;
   132         iNeedToCompleteMessage = EFalse;
   157         User::Leave( err );
   133         User::Leave( err );
   165 // ----------------------------------------------------------------------------
   141 // ----------------------------------------------------------------------------
   166 //
   142 //
   167 void CUSBUINotifierBase::Cancel()
   143 void CUSBUINotifierBase::Cancel()
   168     {
   144     {
   169     FLOG(_L("[USBUINOTIF]\t CUSBUINotifierBase::Cancel()"));
   145     FLOG(_L("[USBUINOTIF]\t CUSBUINotifierBase::Cancel()"));
   170     CActive::Cancel();
   146     //The message box closed callback gets not run in subclass cancel calls.
   171     FLOG(_L("[USBUINOTIF]\t CUSBUINotifierBase::Cancel completed()"));
   147     CompleteMessage(KErrCancel);
       
   148     FLOG(_L("[USBUINOTIF]\t CUSBUINotifierBase::Cancel completed"));
   172     }
   149     }
   173 
   150 
   174 // ----------------------------------------------------------------------------
   151 // ----------------------------------------------------------------------------
   175 // CUSBUINotifierBase::UpdateL
   152 // CUSBUINotifierBase::UpdateL
   176 // Notifier update. Not supported.
   153 // Notifier update. Not supported.
   178 //
   155 //
   179 TPtrC8 CUSBUINotifierBase::UpdateL(const TDesC8& /*aBuffer*/)
   156 TPtrC8 CUSBUINotifierBase::UpdateL(const TDesC8& /*aBuffer*/)
   180     {
   157     {
   181     TPtrC8 ret( KNullDesC8 );
   158     TPtrC8 ret( KNullDesC8 );
   182     return (ret);
   159     return (ret);
   183     }
       
   184 
       
   185 // ----------------------------------------------------------------------------
       
   186 // CUSBUINotifierBase::DoCancel
       
   187 // This method will be called by framework (CActive)
       
   188 // if active object is still active.
       
   189 // Does nothing here.
       
   190 // ----------------------------------------------------------------------------
       
   191 //
       
   192 void CUSBUINotifierBase::DoCancel()
       
   193     {
       
   194     FLOG(_L("[USBUINOTIF]\t CUSBUINotifierBase::DoCancel()"));
       
   195     }
       
   196 
       
   197 // ----------------------------------------------------------------------------
       
   198 // CUSBUINotifierBase::RunError
       
   199 // This method is called if any leaving has been occured
       
   200 // during RunL. Optional method for CActive derived objects.
       
   201 // ----------------------------------------------------------------------------
       
   202 //
       
   203 TInt CUSBUINotifierBase::RunError(TInt aError)
       
   204     {
       
   205     FLOG(_L("[USBUINOTIF]\t CUSBUINotifierBase::RunError()"));
       
   206 
       
   207     // Activate apps -key again (if not previously activated yet)
       
   208     //
       
   209     SuppressAppSwitching( EFalse );
       
   210 
       
   211     // Write error message to caller
       
   212     //
       
   213     CompleteMessage( aError );
       
   214 
       
   215     FLOG(_L("[USBUINOTIF]\t CUSBUINotifierBase::RunError() completed"));
       
   216 
       
   217     return aError;
       
   218     }
       
   219 
       
   220 // ----------------------------------------------------------------------------
       
   221 // CUSBUINotifierBase::SuppressAppSwitching
       
   222 // 
       
   223 // ----------------------------------------------------------------------------
       
   224 //
       
   225 void CUSBUINotifierBase::SuppressAppSwitching(TBool aEnable)
       
   226     {
       
   227     FTRACE(FPrint(_L("[USBUINOTIF]\t CUSBUINotifierBase::SuppressAppSwitching() %d"), aEnable));
       
   228 
       
   229     if (iAppsKeyBlocked != aEnable)
       
   230         {
       
   231         TInt err = iAknServer.ConnectAndSendAppsKeySuppress( aEnable ); // error is stored only for logging purposes
       
   232         iAppsKeyBlocked = aEnable;
       
   233         FTRACE(FPrint(_L("[USBUINOTIF]\t CUSBUINotifierBase::SuppressAppSwitching() ConnectAndSendAppsKeySuppress returned %d"), err ));
       
   234         }
       
   235 
       
   236     if (!iAppsKeyBlocked)
       
   237         {
       
   238         iAknServer.Close(); // close the connection once we have re-enabled swithcing
       
   239         }
       
   240     FLOG(_L("[USBUINOTIF]\t CUSBUINotifierBase::SuppressAppSwitching() completed"));
       
   241     }
   160     }
   242 
   161 
   243 // ----------------------------------------------------------------------------
   162 // ----------------------------------------------------------------------------
   244 // CUSBUINotifierBase::CompleteMessage
   163 // CUSBUINotifierBase::CompleteMessage
   245 // Check if message needs to be completed and complete it. 
   164 // Check if message needs to be completed and complete it. 
   255         }
   174         }
   256     iReplySlot = 0;
   175     iReplySlot = 0;
   257     FLOG(_L("[USBUINOTIF]\t CUSBUINotifierBase::CompleteMessage() completed"));
   176     FLOG(_L("[USBUINOTIF]\t CUSBUINotifierBase::CompleteMessage() completed"));
   258     }
   177     }
   259 
   178 
   260 // ----------------------------------------------------------------------------
   179 void CUSBUINotifierBase::InitializeTextResolver()
   261 // CUSBUINotifierBase::DisableKeylock
   180     {
   262 // ----------------------------------------------------------------------------
   181     _LIT(KFileName, "usbdialogs_");
   263 // Turn off the keyguard if it was on.
   182     _LIT(KPath, "z:/resource/qt/translations/");         
   264 //
   183     TInt error = KErrNone;
   265 void CUSBUINotifierBase::DisableKeylock()
   184         
   266     {
   185     iTranslator = (TBool )Dll::Tls();
   267     FLOG(_L("[USBUINOTIF]\t CUSBUINotifierBase::DisableKeylock()"));
   186     
   268     RAknKeylock2 keylock;
   187     FTRACE(FPrint(_L("[USBUINOTIF]\t Dll:Tls returned %d"), iTranslator ));    
   269     iKeylockChanged = EFalse;
   188     
   270     if (KErrNone == keylock.Connect())
   189     if (!iTranslator)
   271         {
   190         {
   272         if (keylock.IsKeyLockEnabled()) //Check and save the keylock status
   191         iTranslator = HbTextResolverSymbian::Init(KFileName, KPath);
       
   192         FTRACE(FPrint(_L("[USBUINOTIF]\t HbTextResolverSymbian::Init returned %d"), iTranslator ));    
       
   193         if (iTranslator)
   273             {
   194             {
   274             keylock.DisableWithoutNote();// Unlock
   195             error = Dll::SetTls((TAny* )iTranslator);      
   275             iKeylockChanged = ETrue;
       
   276             }
   196             }
   277         keylock.Close();
   197         FTRACE(FPrint(_L("[USBUINOTIF]\t Dll:SetTls returned %d"), error ));    
   278         }
   198         }    
   279     else
   199        
   280         {
   200      error = error;   // to suppress a compiler warning
   281         FLOG( _L( "[USBUINOTIF]\t CUSBUINotifierBase::DisableKeylock() fail caused by RAknKeylock2::Connect()") );
   201      FTRACE( FPrint(
   282         }
   202         _L( "[USBUINOTIF]\t CUSBUINotifierBase::InitializeTextResolver result = %d" ),
   283 
   203         iTranslator ) );                     
   284     FLOG(_L("[USBUINOTIF]\t CUSBUINotifierBase::DisableKeylock() completed"));
   204         
   285     }
   205     }
   286 
   206 
   287 // ----------------------------------------------------------------------------
       
   288 // CUSBUINotifierBase::RestoreKeylock
       
   289 // ----------------------------------------------------------------------------
       
   290 // Restore the keyguard on.
       
   291 //
       
   292 void CUSBUINotifierBase::RestoreKeylock()
       
   293     {
       
   294     FLOG(_L("[USBUINOTIF]\t CUSBUINotifierBase::RestoreKeylock()"));
       
   295     if (iKeylockChanged)
       
   296         {
       
   297         FLOG(_L("[USBUINOTIF]\t CUSBUINotifierBase::RestoreKeylock(): iKeylockChanged true"));
       
   298         RAknKeylock2 keylock;
       
   299         FLOG(_L("[USBUINOTIF]\t CUSBUINotifierBase::RestoreKeylock(): RAknKeyLock2 initialized"));
       
   300         if (KErrNone == keylock.Connect())
       
   301             {
       
   302             FLOG(_L("[USBUINOTIF]\t CUSBUINotifierBase::RestoreKeylock(): RAknKeyLock2::Connect() complete"));
       
   303             keylock.EnableWithoutNote();// Lock back
       
   304             FLOG(_L("[USBUINOTIF]\t CUSBUINotifierBase::RestoreKeylock(): RAknKeyLock2::EnableWithoutNote() complete"));
       
   305             keylock.Close();
       
   306             FLOG(_L("[USBUINOTIF]\t CUSBUINotifierBase::RestoreKeylock(): RAknKeyLock2::Close() complete"));
       
   307             iKeylockChanged = EFalse;
       
   308             }
       
   309         else
       
   310             {
       
   311             FLOG( _L( "[USBUINOTIF]\t CUSBUINotifierBase::RestoreKeylock() fail caused by RAknKeylock2::Connect()") );
       
   312             }
       
   313         }
       
   314     FLOG(_L("[USBUINOTIF]\t CUSBUINotifierBase::RestoreKeylock() completed"));
       
   315     }
       
   316 
   207 
   317 // End of File
   208 // End of File