securitydialogs/simlockui/src/SimLockUIAppui.cpp
changeset 1 d5423fbb4f29
child 5 3b17fc5c9564
equal deleted inserted replaced
0:164170e6151a 1:d5423fbb4f29
       
     1 /*
       
     2  * ============================================================================
       
     3  *  Name        : SimLockUIAppUi.cpp
       
     4  *  Part of     : Sim Lock UI Application
       
     5  *  Description : Implementation of Sim Lock UI Application UI Methods
       
     6  *  Version     : 
       
     7  *  
       
     8 * Copyright (c) 2005-2010 Nokia Corporation and/or its subsidiary(-ies).
       
     9 * All rights reserved.
       
    10 * This component and the accompanying materials are made available
       
    11 * under the terms of "Eclipse Public License v1.0"
       
    12 * which accompanies this distribution, and is available
       
    13 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
    14 *
       
    15 * Initial Contributors:
       
    16 * Nokia Corporation - initial contribution.
       
    17 *
       
    18 * Contributors:
       
    19 *
       
    20 * Description:   Build info file for Ado domain appinstall 
       
    21 * ============================================================================
       
    22 */
       
    23 
       
    24 // Platform Includes
       
    25 #include <avkon.hrh>
       
    26 #include <aknnotewrappers.h>    // CAknNoteDialog
       
    27 #include <stringloader.h>       // StringLoader
       
    28 #include <exterror.h>           // KErrGsm0707OperationNotAllowed
       
    29 #include <eikspane.h>     // CEikStatusPane
       
    30 #include <aknmessagequerydialog.h> // CAknMessageQueryDialog
       
    31 #include <e32base.h>
       
    32 #include <e32property.h> //Rproperty
       
    33 // Local Includes
       
    34 #include "SimLockISAServerDefinitions.h"
       
    35 #include "SimLockUI.pan"
       
    36 #include "SimLockUIAppUi.h"
       
    37 #include "SimLockUIBackgroundControl.h"
       
    38 #include "SimLockUI.hrh"
       
    39 #include "SimLockDataHandlingDelegate.h"
       
    40 #include "SimLockTelephonyProxy.h"
       
    41 #include "SimLockUiKeys.h"
       
    42 
       
    43 // Resource Includes
       
    44 #include <SimLockUI.rsg>
       
    45 
       
    46 // ---------------------------------------------------------------------------
       
    47 // CSimLockUIAppUi::CSimLockUIAppUi
       
    48 // ---------------------------------------------------------------------------
       
    49 CSimLockUIAppUi::CSimLockUIAppUi(
       
    50         CSimLockDataHandlingDelegate& aSimLockDelegate) :
       
    51     iSimLockDelegate(aSimLockDelegate), iFirstRun(ETrue)
       
    52     {
       
    53     // no implementation required
       
    54     }
       
    55 
       
    56 // ---------------------------------------------------------------------------
       
    57 // CSimLockUIAppUi::ConstructL
       
    58 // ---------------------------------------------------------------------------
       
    59 void CSimLockUIAppUi::ConstructL()
       
    60     {
       
    61     BaseConstructL(EAknEnableSkin | EAknEnableMSK);
       
    62 
       
    63     // Used to get status of phone call
       
    64     iTelephonyProxy = CSimLockTelephonyProxy::NewL();
       
    65     //Define RProperty to Publish Keys for SimLockUi
       
    66     TInt ret = RProperty::Define(KSimLockProperty, ESimLockActiveStatus,
       
    67             RProperty::EInt);
       
    68     }
       
    69 
       
    70 // ---------------------------------------------------------------------------
       
    71 // CSimLockUIAppUi::~CSimLockUIAppUi
       
    72 // ---------------------------------------------------------------------------
       
    73 CSimLockUIAppUi::~CSimLockUIAppUi()
       
    74     {
       
    75 
       
    76     delete iTelephonyProxy;
       
    77 
       
    78     if (iBackgroundControl)
       
    79         {
       
    80         RemoveFromStack(iBackgroundControl);
       
    81         delete iBackgroundControl;
       
    82         }
       
    83     //Sets SimLock Ui P&S keys to show that SimLock Ui is exiting
       
    84     RProperty::Set(KSimLockProperty, ESimLockActiveStatus, KSimLockStatusDone);
       
    85 
       
    86     }
       
    87 
       
    88 // ---------------------------------------------------------------------------
       
    89 // CSimLockUIAppUi::HandleCommandL
       
    90 // ---------------------------------------------------------------------------
       
    91 void CSimLockUIAppUi::HandleCommandL(TInt aCommand)
       
    92     {
       
    93     switch (aCommand)
       
    94         {
       
    95         case EEikCmdExit:
       
    96         case EAknSoftkeyExit:
       
    97             Exit();
       
    98             break;
       
    99 
       
   100         default:
       
   101             Panic(ESimLockUIBasicUi);
       
   102             break;
       
   103         }
       
   104     }
       
   105 
       
   106 // ---------------------------------------------------------------------------
       
   107 // CSimLockUIAppUi::HandleForegroundEventL
       
   108 // ---------------------------------------------------------------------------
       
   109 void CSimLockUIAppUi::HandleForegroundEventL(TBool aForeground)
       
   110     {
       
   111     CAknAppUi::HandleForegroundEventL(aForeground);
       
   112 
       
   113     // When the app switches to the foreground for the first time, display
       
   114     // series of dialogs.
       
   115     if (aForeground && iFirstRun)
       
   116         {
       
   117         iFirstRun = EFalse;   
       
   118         ProcessSimUnlockDialogsL();
       
   119         PrepareToExit();
       
   120         Exit();
       
   121         }
       
   122     }
       
   123 
       
   124 // ---------------------------------------------------------------------------
       
   125 // CSimLockUIAppUi::ProcessSimUnlockDialogsL
       
   126 // ---------------------------------------------------------------------------
       
   127 TBool CSimLockUIAppUi::ProcessSimUnlockDialogsL()
       
   128     {
       
   129     TBool keepLooping = ETrue;
       
   130 
       
   131     TBuf<SEC_ATT_PASSWORD_MAX_BUFFER> password;
       
   132 
       
   133     // Loop until flag is set
       
   134     do
       
   135         {
       
   136         // Create background if not already there
       
   137         if (!iBackgroundControl)
       
   138             {
       
   139             CreateBackgroundControlL();
       
   140             }
       
   141         // Display Introduction Dialog/Prompt
       
   142         if (!DisplayIntroductionDialogL())
       
   143             {
       
   144             return EFalse;
       
   145             }
       
   146         // Prompt for password and attempt to unlock Sim
       
   147         if (!PromptForPasswordL(password))
       
   148             {
       
   149             // skip next iteration
       
   150             continue;
       
   151             }        
       
   152         // Set only if no dialogs are ever dismissed
       
   153          keepLooping = AttemptToUnlockSimL(password);
       
   154 
       
   155         // Continue to loop while indicated to start over and dialog
       
   156         // has not been dismissed
       
   157         }
       
   158     while (keepLooping);
       
   159     
       
   160   return keepLooping;
       
   161     }
       
   162 
       
   163 // ---------------------------------------------------------------------------
       
   164 // CSimLockUIAppUi::CreateBackgroundControlL
       
   165 // ---------------------------------------------------------------------------
       
   166 void CSimLockUIAppUi::CreateBackgroundControlL()
       
   167     {
       
   168     CEikStatusPane* statusPane = StatusPane();
       
   169 
       
   170     // Remove status pane
       
   171     // Crop background pane to reveal idle status pane
       
   172     TRect background = ClientRect();
       
   173     statusPane->ReduceRect(background);
       
   174     statusPane->SwitchLayoutL(R_AVKON_STATUS_PANE_LAYOUT_EMPTY);
       
   175 
       
   176     iBackgroundControl = CSimLockUIBackgroundControl::NewL(background);
       
   177     AddToStackL(iBackgroundControl);
       
   178     }
       
   179 
       
   180 // ---------------------------------------------------------------------------
       
   181 // CSimLockUIAppUi::DisplayIntroductionDialogL
       
   182 // ---------------------------------------------------------------------------
       
   183 TBool CSimLockUIAppUi::DisplayIntroductionDialogL()
       
   184     {
       
   185     SetBackgroundTextL(EBackgroundTextEmpty);
       
   186 
       
   187     HBufC* displayText = StringLoader::LoadLC(R_SIM_INFO_WELCOME_NOTE_TEXT);
       
   188     CAknMessageQueryDialog* query = new (ELeave) CAknMessageQueryDialog(
       
   189             CAknMessageQueryDialog::ENoTone);
       
   190     CleanupStack::PushL(query);
       
   191     query->SetMessageTextL(*displayText);
       
   192     TInt executeResult = query->ExecuteLD(R_SIM_INFO_WELCOME_NOTE);
       
   193     CleanupStack::Pop(query);
       
   194     CleanupStack::PopAndDestroy(displayText);
       
   195     return executeResult;
       
   196 
       
   197     }
       
   198 
       
   199 // ---------------------------------------------------------------------------
       
   200 // CSimLockUIAppUi::PromptForPasswordL
       
   201 // ---------------------------------------------------------------------------
       
   202 TBool CSimLockUIAppUi::PromptForPasswordL(TDes& aPassword)
       
   203     {
       
   204     TBuf<SEC_ATT_PASSWORD_MAX_BUFFER> newPassword;
       
   205 
       
   206     // Prompt for password twice.  Loop until passwords match.
       
   207     do
       
   208         {
       
   209         aPassword.Zero();
       
   210 
       
   211         // Ask for password
       
   212         CAknTextQueryDialog* dialog = CAknTextQueryDialog::NewL(aPassword);
       
   213        // dialog->SetMaxLength(SEC_ATT_PASSWORD_MAX_LENGTH);
       
   214 
       
   215         if (!dialog->ExecuteLD(R_SIM_INFO_ENTER_PASSWORD))
       
   216             {
       
   217             return EFalse;
       
   218             }
       
   219 
       
   220         // Ask to re-enter password and verify there is no call in progress
       
   221         if (!CompletePromptForPasswordL(aPassword, newPassword))
       
   222             {
       
   223             return EFalse;
       
   224             }
       
   225         }
       
   226     while (newPassword.Compare(aPassword));
       
   227 
       
   228     return ETrue;
       
   229     }
       
   230 
       
   231 // ---------------------------------------------------------------------------
       
   232 // CSimLockUIAppUi::CompletePromptForPasswordL
       
   233 // ---------------------------------------------------------------------------
       
   234 TBool CSimLockUIAppUi::CompletePromptForPasswordL(const TDesC& aPassword,
       
   235         TDes& aNewPassword)
       
   236     {
       
   237     TBool callInProgress = EFalse;
       
   238 
       
   239     aNewPassword.Zero();
       
   240 
       
   241     do // Loop until no call in progress
       
   242         {
       
   243         // Display dialog to ask to re-enter password
       
   244         CAknTextQueryDialog* dialog = CAknTextQueryDialog::NewL(aNewPassword);
       
   245         if (!dialog->ExecuteLD(R_SIM_INFO_REENTER_PASSWORD))
       
   246             {
       
   247              return EFalse;
       
   248             }
       
   249 
       
   250         // Check to see if passwords match
       
   251         if (aNewPassword.Compare(aPassword))
       
   252             {
       
   253             // Create message query dialog to indicate that codes do not match
       
   254             CAknMessageQueryDialog* query =
       
   255                     new (ELeave) CAknMessageQueryDialog(
       
   256                             CAknMessageQueryDialog::ENoTone);
       
   257             return query->ExecuteLD(R_SIM_INFO_CODES_NOT_MATCH);            
       
   258             }
       
   259 
       
   260         // If there is a call in progress, show note and return to "re-enter password" prompt
       
   261         if (!iTelephonyProxy->IsCallInProgress())
       
   262             {
       
   263             return ETrue;
       
   264             }
       
   265 
       
   266         // Do not allow Sim unlocking, return to password prompt
       
   267         ShowInformationNoteL(R_SIM_UNLOCK_MESSAGE_END_CALL);
       
   268         callInProgress = ETrue;
       
   269         }
       
   270     while (callInProgress);
       
   271 
       
   272     return ETrue;
       
   273     }
       
   274 
       
   275 // ---------------------------------------------------------------------------
       
   276 // CSimLockUIAppUi::AttemptToUnlockSimL
       
   277 // ---------------------------------------------------------------------------
       
   278 TBool CSimLockUIAppUi::AttemptToUnlockSimL(const TDesC& aPassword)
       
   279     {
       
   280     
       
   281 const TDesC& password =  aPassword;
       
   282 
       
   283 #ifdef __WINS__
       
   284     // In WINS (Emulator) builds, call to OpenSimLock will just time out
       
   285     TInt unlockResult = KErrGsm0707IncorrectPassword;
       
   286 #else
       
   287     // Attempt to unlock SIM
       
   288     TInt unlockResult = iSimLockDelegate.OpenSimLock( password );
       
   289 #endif
       
   290 
       
   291     CAknMessageQueryDialog* query = new (ELeave) CAknMessageQueryDialog(
       
   292             CAknMessageQueryDialog::ENoTone);
       
   293 
       
   294     switch (unlockResult)
       
   295         {
       
   296         case KErrAlreadyExists:
       
   297             // Should not happen!  This indicates that the phone was already unlocked,
       
   298             // which it shouldn't be if we got this far.
       
   299             ASSERT( 0 );
       
   300 
       
   301             // Fall Through
       
   302 
       
   303         case KErrNone:
       
   304             SetBackgroundTextL(EBackgroundTextUnlockComplete);
       
   305             ShowInformationNoteL(R_SIM_PHONE_UNLOCKED);
       
   306             return EFalse;
       
   307 
       
   308         default:
       
   309             // Oops, we missed one.
       
   310             ASSERT( 0 );
       
   311         case KErrGsm0707OperationNotAllowed:
       
   312         case KErrLocked:
       
   313             // Permanently locked
       
   314             SetBackgroundTextL(EBackgroundTextEmpty);
       
   315             query->ExecuteLD(R_SIM_UNLOCK_FINAL);
       
   316             return EFalse;
       
   317         case KErrTimedOut:
       
   318         case KErrGeneral:        
       
   319         case KErrArgument:
       
   320         case KErrGsm0707IncorrectPassword:
       
   321             // Not permanently locked
       
   322             return HandleUnlockFailedL();
       
   323 
       
   324 
       
   325         }//switch
       
   326     }
       
   327 // ---------------------------------------------------------------------------
       
   328 // CSimLockUIAppUi::HandleUnlockFailedL
       
   329 // ---------------------------------------------------------------------------
       
   330 TBool CSimLockUIAppUi::HandleUnlockFailedL()
       
   331     {
       
   332     TBuf<SEC_ATT_PASSWORD_MAX_BUFFER> password;
       
   333     // Otherwise, prompt user to try again
       
   334     SetBackgroundTextL(EBackgroundTextEmpty);
       
   335 
       
   336     // Show "Code Incorrect" and prompt user to continue or not
       
   337     CAknMessageQueryDialog* query = new (ELeave) CAknMessageQueryDialog(
       
   338             CAknMessageQueryDialog::ENoTone);
       
   339     if (query->ExecuteLD(R_SIM_INFO_CODE_INCORRECT))
       
   340         {
       
   341         if ( PromptForPasswordL(password) )
       
   342             {
       
   343             return AttemptToUnlockSimL(password);    
       
   344             }
       
   345         else
       
   346             {
       
   347             // Set flag indicating to keep looping            
       
   348             return ETrue;
       
   349             }
       
   350         }
       
   351     else
       
   352         {
       
   353         // display intro popup
       
   354         return ETrue;
       
   355         }
       
   356     }
       
   357 
       
   358 // ---------------------------------------------------------------------------
       
   359 // CSimLockUIAppUi::ShowInformationNoteL
       
   360 // ---------------------------------------------------------------------------
       
   361 TInt CSimLockUIAppUi::ShowInformationNoteL(TInt aResourceId) const
       
   362     {
       
   363     TInt executeResult;
       
   364 
       
   365     // Show note with the provided resource id
       
   366     HBufC* displayText = StringLoader::LoadLC(aResourceId);
       
   367 
       
   368     CAknInformationNote* dialog = new (ELeave) CAknInformationNote(ETrue);
       
   369     executeResult = dialog->ExecuteLD(*displayText);
       
   370     CleanupStack::PopAndDestroy(displayText);
       
   371     return executeResult;
       
   372     }
       
   373 
       
   374 // ---------------------------------------------------------------------------
       
   375 // CSimLockUIAppUi::SetBackgroundTextL
       
   376 // ---------------------------------------------------------------------------
       
   377 void CSimLockUIAppUi::SetBackgroundTextL(TBackgroundText aText)
       
   378     {
       
   379     HBufC* displayText = NULL;
       
   380 
       
   381     // Load resource and set text in background control based on provided info
       
   382     switch (aText)
       
   383         {
       
   384         case EBackgroundTextEmpty:
       
   385             displayText = KNullDesC().AllocL();
       
   386             break;
       
   387 
       
   388         case EBackgroundTextMain:
       
   389             displayText = StringLoader::LoadL(
       
   390                     R_SIMLOCK_UI_BACKGROUND_TEXT_MAIN);
       
   391             break;
       
   392 
       
   393         case EBackgroundTextUnlockComplete:
       
   394             displayText = StringLoader::LoadL(
       
   395                     R_SIMLOCK_UI_BACKGROUND_TEXT_UNLOCK_COMPLETE);
       
   396             break;
       
   397 
       
   398         case EBackgroundTextUnlockFailed:
       
   399             displayText = StringLoader::LoadL(
       
   400                     R_SIMLOCK_UI_BACKGROUND_TEXT_UNLOCK_FAILED);
       
   401             break;
       
   402 
       
   403         case EBackgroundTextUnlockIncorrect:
       
   404             displayText = StringLoader::LoadL(
       
   405                     R_SIMLOCK_UI_BACKGROUND_TEXT_UNLOCK_INCORRECT);
       
   406             break;
       
   407 
       
   408         default:
       
   409             ASSERT( 0 );
       
   410             break;
       
   411         }
       
   412 
       
   413     // Transfer ownership to iBackgroundControl
       
   414     iBackgroundControl->SetBackgroundText(displayText);
       
   415     }
       
   416 
       
   417 // End of file.