sysstatemgmt/systemstatereferenceplugins/custcmd/src/ssmsecuritychecknotifier.cpp
changeset 0 4e1aa6a622a0
child 7 1a73e8f1b64d
equal deleted inserted replaced
-1:000000000000 0:4e1aa6a622a0
       
     1 // Copyright (c) 2007-2009 Nokia Corporation and/or its subsidiary(-ies).
       
     2 // All rights reserved.
       
     3 // This component and the accompanying materials are made available
       
     4 // under the terms of "Eclipse Public License v1.0"
       
     5 // which accompanies this distribution, and is available
       
     6 // at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     7 //
       
     8 // Initial Contributors:
       
     9 // Nokia Corporation - initial contribution.
       
    10 //
       
    11 // Contributors:
       
    12 //
       
    13 // Description:
       
    14 // Name        : strtsecuritynote.cpp
       
    15 // Part of     : System Startup / Starter
       
    16 // Implementation of CStrtSecurityNote class.
       
    17 // Version     : %version: 4 %
       
    18 // This material, including documentation and any related computer
       
    19 // programs, is protected by copyright controlled by Nokia.  All
       
    20 // rights are reserved.  Copying, including reproducing, storing,
       
    21 // adapting or translating, any or all of this material requires the
       
    22 // prior written consent of Nokia.  This material also contains
       
    23 // confidential information which may not be disclosed to others
       
    24 // without the prior written consent of Nokia.
       
    25 // Template version: 4.1
       
    26 // Nokia Core OS *
       
    27 // File renamed from strtsecuritynote.cpp to ssmsecuritychecknotifier.cpp as part of Core OS transfer.
       
    28 //
       
    29 
       
    30 
       
    31 
       
    32 
       
    33 /**
       
    34  @file
       
    35  @internalComponent
       
    36  @released
       
    37 */
       
    38 
       
    39 #include "ssmsecuritychecknotifier.h"
       
    40 #include "ssmdebug.h"
       
    41 #include "ssmuiproviderdll.h"
       
    42 #include <ssm/ssmstateawaresession.h>
       
    43 #include <e32def.h>
       
    44 #include <startupdomaindefs.h>
       
    45 #include <etelmm.h> 
       
    46 
       
    47 static TBool NoteTypeToEvent(
       
    48     TInt& aEventCode, const TStrtSecurityNoteType aNoteType )
       
    49     {
       
    50     TBool result( ETrue );
       
    51     switch( aNoteType )
       
    52         {
       
    53         case ESecCodePIN1:
       
    54             {
       
    55             aEventCode = RMobilePhone::EPin1Required;
       
    56             break;
       
    57             }
       
    58         case ESecCodePIN2:
       
    59             {
       
    60             aEventCode = RMobilePhone::EPin2Required;
       
    61             break;
       
    62             }
       
    63         case ESecCodeUPIN:
       
    64             {
       
    65             aEventCode = RMobilePhone::EUniversalPinRequired;
       
    66             break;
       
    67             }
       
    68         case ESecCodePUK1:
       
    69             {
       
    70             aEventCode = RMobilePhone::EPuk1Required;
       
    71             break;
       
    72             }
       
    73         case ESecCodePUK2:
       
    74             {
       
    75             aEventCode = RMobilePhone::EPuk2Required;
       
    76             break;
       
    77             }
       
    78         case ESecCodeUPUK:
       
    79             {
       
    80             aEventCode = RMobilePhone::EUniversalPukRequired;
       
    81             break;
       
    82             }
       
    83         case ESecCodePasswd:
       
    84             {
       
    85             aEventCode = RMobilePhone::EPhonePasswordRequired;
       
    86             break;
       
    87             }
       
    88         case ESecCodeAppPIN1:
       
    89             {
       
    90             aEventCode = RMobilePhone::EUSIMAppPinRequired;
       
    91             break;
       
    92             }
       
    93         case ESecCodeAppPIN2:
       
    94             {
       
    95             aEventCode = RMobilePhone::ESecondUSIMAppPinRequired;
       
    96             break;
       
    97             }
       
    98         case ESecInfoSimLockRestrOn:
       
    99             {
       
   100             aEventCode = RMobilePhone::EICCTerminated;
       
   101             break;
       
   102             }
       
   103         case ESecInfoSimInvalid:
       
   104             {
       
   105             //aEventCode = RMobilePhone::ESIMInvalid;
       
   106             result = EFalse;
       
   107             break;
       
   108             }
       
   109         default:
       
   110             {
       
   111             result = EFalse;
       
   112             break;
       
   113             }
       
   114         }
       
   115     return result;
       
   116     }
       
   117 
       
   118 CSsmSecurityCheckNotifier* CSsmSecurityCheckNotifier::NewL()
       
   119 	{
       
   120 	CSsmSecurityCheckNotifier* self = new (ELeave) CSsmSecurityCheckNotifier();
       
   121 	CleanupStack::PushL(self);
       
   122 	self->ConstructL();
       
   123 	CleanupStack::Pop();
       
   124 	return self;
       
   125 	}
       
   126 CSsmSecurityCheckNotifier* CSsmSecurityCheckNotifier::NewL(TStrtSecurityNoteType aNoteType)
       
   127 	{
       
   128 	CSsmSecurityCheckNotifier* self = new (ELeave) CSsmSecurityCheckNotifier(aNoteType);
       
   129 	CleanupStack::PushL(self);
       
   130 	self->ConstructL();
       
   131 	CleanupStack::Pop();
       
   132 	return self;
       
   133 	}
       
   134 
       
   135 
       
   136 CSsmSecurityCheckNotifier::CSsmSecurityCheckNotifier(TStrtSecurityNoteType aNoteType)
       
   137 	: CActive( EPriorityStandard),
       
   138 	iNoteType (aNoteType),
       
   139 	iCodeOk(EFalse)
       
   140 	{
       
   141 	}
       
   142 
       
   143 CSsmSecurityCheckNotifier::CSsmSecurityCheckNotifier()
       
   144 	: CActive( EPriorityStandard),
       
   145 	iCodeOk(EFalse)
       
   146 	{
       
   147 	}
       
   148 
       
   149 /**
       
   150 @panic EInvalidUid if the UID is invalid
       
   151 */
       
   152 void CSsmSecurityCheckNotifier::ConstructL()
       
   153 	{
       
   154 	//Initialise the state to idle
       
   155 	iCmdState = EIdle;
       
   156 
       
   157 	//Connect to notifier
       
   158 	User::LeaveIfError(iSecurityPinNotifier.Connect());
       
   159 
       
   160 	iSecurityPinNotifierUid = CSsmUiSpecific::SecurityPinNotifierUid();
       
   161     __ASSERT_ALWAYS(0 != iSecurityPinNotifierUid.iUid, User::Panic(KPanicSecurityCheckNotifier, EInvalidUid));
       
   162 
       
   163 	//Attach to the emergency call property
       
   164 	User::LeaveIfError(iSsmEmergencyCallProperty.Attach(CSsmUiSpecific::EmergencyCallPropertyCategory(), CSsmUiSpecific::EmergencyCallPropertyKey(), EOwnerThread));
       
   165 
       
   166 	//Add this active object to active scheduler
       
   167 	CActiveScheduler::Add(this);
       
   168 	}
       
   169 
       
   170 CSsmSecurityCheckNotifier::~CSsmSecurityCheckNotifier()
       
   171 	{
       
   172 	//Cancel any asynchronous request before destroying
       
   173 	Cancel();
       
   174 
       
   175 	//Close the notifier
       
   176 	iSecurityPinNotifier.Close();
       
   177 
       
   178 	//Close the emergency call property
       
   179 	iSsmEmergencyCallProperty.Close();
       
   180 	}
       
   181 
       
   182 void CSsmSecurityCheckNotifier::ShowNoteL(TStrtSecurityNoteType aNoteType, TRequestStatus& aRequest)
       
   183 	{
       
   184 	iNoteType = aNoteType;
       
   185 	ShowNoteL(aRequest);
       
   186 	}
       
   187 
       
   188 void CSsmSecurityCheckNotifier::ShowNoteL(TRequestStatus& aRequest)
       
   189 	{
       
   190 	//Set the user request to KRequestPending
       
   191 	aRequest = KRequestPending;
       
   192 	iExecuteRequest = &aRequest;
       
   193 
       
   194 	iCodeOk = EFalse;
       
   195 
       
   196 	//Check whether notifier is cancellable by the user or not
       
   197 	iIsDlgCancellable = IsDlgCancellableL();
       
   198 
       
   199 	StartNotifier();
       
   200 	}
       
   201 
       
   202 TBool CSsmSecurityCheckNotifier::IsDlgCancellableL()
       
   203 	{
       
   204 	RSsmStateAwareSession ssmStateAwareSession;
       
   205 
       
   206 	//Use the domain id of UI applications
       
   207 	TDmDomainId dmId = KSM2UiServicesDomain3;
       
   208 
       
   209 	//Connect to state aware session
       
   210 	User::LeaveIfError(ssmStateAwareSession.Connect(dmId));
       
   211 
       
   212 	//Get the current state of the system
       
   213 	TSsmState currentState = ssmStateAwareSession.State();
       
   214 
       
   215 	TBool isDlgCancellable;
       
   216 
       
   217 	//Is system in start up state
       
   218 	
       
   219 	iAfterStartup = (currentState.MainState() == ESsmStartup) ? EFalse : ETrue;
       
   220 	
       
   221 	//Close the state aware session
       
   222 	ssmStateAwareSession.Close();
       
   223 
       
   224 	//Notifier dialogue is not cancellable if system is in startup state and
       
   225 	//requested for PUK1 or PUK2 or UPUK code
       
   226     isDlgCancellable = (iAfterStartup &&
       
   227 						iNoteType != ESecCodePUK1 &&
       
   228 						iNoteType != ESecCodePUK2 &&
       
   229 						iNoteType != ESecCodeUPUK);
       
   230 	return isDlgCancellable;
       
   231 	}
       
   232 
       
   233 void CSsmSecurityCheckNotifier::RunL()
       
   234 	{
       
   235 	if (iCmdState == ENotifierIsActive &&
       
   236          !iIsDlgCancellable &&
       
   237          iPinResult() == KErrCancel)
       
   238         {
       
   239         // User activated an emergency call from the security note dialog.
       
   240         // Wait for the call to finish and then show the note again.
       
   241         iCmdState = EEmergencyCallIsActive;
       
   242 
       
   243 		//Subscribe to the emergency call swp
       
   244 		iSsmEmergencyCallProperty.Subscribe(iStatus);
       
   245 
       
   246 		DEBUGPRINT1A("Pin cancelled and ECall Started");
       
   247 		SetActive();
       
   248         }
       
   249     else if (iCmdState == EEmergencyCallIsActive && iStatus.Int() != KErrCancel)
       
   250         {
       
   251         // Emergency call activated from the security note dialog has
       
   252         // finished. Show the note again.
       
   253         DEBUGPRINT1A("ECall Ended and restarting pin notifier");
       
   254         StartNotifier();
       
   255         }
       
   256     else
       
   257         {
       
   258         //Reset the state to initial start
       
   259         iCmdState = EIdle;
       
   260         DEBUGPRINT1A("Pin notifier closed");
       
   261 
       
   262         //Check whether the entered code is correct or not
       
   263         if (iStatus == KErrNone && iPinResult() == KErrNone)
       
   264         	{
       
   265         	iCodeOk = ETrue;
       
   266 			}
       
   267 
       
   268 		//Complete the user request
       
   269         if (iExecuteRequest)
       
   270             {
       
   271             User::RequestComplete(iExecuteRequest, iStatus.Int());
       
   272             }
       
   273         }
       
   274 	}
       
   275 
       
   276 void CSsmSecurityCheckNotifier::StartNotifier()
       
   277 	{
       
   278 	TInt eventCode = 0;
       
   279 	
       
   280 	//Change the state to notifier active state
       
   281 	iCmdState = ENotifierIsActive;
       
   282 
       
   283 	if ( NoteTypeToEvent( eventCode, iNoteType ) )
       
   284 		{
       
   285 		DEBUGPRINT3A( "CSsmSecurityCheckNotifier: Security code %d handled as event %d",
       
   286 					iNoteType, eventCode );
       
   287         iParams().iEvent = eventCode;
       
   288         iParams().iStartup = !iAfterStartup;
       
   289 
       
   290     	//Start the notifier
       
   291     	iSecurityPinNotifier.StartNotifierAndGetResponse(
       
   292     			iStatus, iSecurityPinNotifierUid, iParams, iPinResult);
       
   293 		}
       
   294 	else
       
   295 		{
       
   296         DEBUGPRINT3A("CSsmSecurityCheckNotifier: Security code %d not handled as event %d", 
       
   297         			iNoteType, eventCode);
       
   298         iStatus = KRequestPending;
       
   299         TRequestStatus* status = &iStatus;
       
   300         User::RequestComplete(status, KErrNone);
       
   301 		}
       
   302 	SetActive();
       
   303 	}
       
   304 
       
   305 TInt CSsmSecurityCheckNotifier::RunError(TInt aError)
       
   306 	{
       
   307 	//Do the cleanup in case of an error
       
   308 	CleanupAndCancel(aError);
       
   309 	return KErrNone;
       
   310 	}
       
   311 
       
   312 void CSsmSecurityCheckNotifier::DoCancel()
       
   313 	{
       
   314 	//Do the cleanup in case of cancel
       
   315 	CleanupAndCancel(KErrCancel);
       
   316 	}
       
   317 
       
   318 void CSsmSecurityCheckNotifier::CleanupAndCancel(TInt aError)
       
   319 	{
       
   320 	//Cancel if notifier is stil active
       
   321 	iSecurityPinNotifier.CancelNotifier(iSecurityPinNotifierUid);
       
   322 
       
   323 	//Cancel the request if there is any
       
   324 	iSsmEmergencyCallProperty.Cancel();
       
   325 
       
   326 	//Complete user request with the result code given
       
   327 	if(iExecuteRequest)
       
   328 		{
       
   329 		if (iExecuteRequest->Int() == KRequestPending)
       
   330 			{
       
   331 			User::RequestComplete(iExecuteRequest, aError);
       
   332 			}
       
   333 		}
       
   334 	}
       
   335 
       
   336 TBool CSsmSecurityCheckNotifier::IsCodeAccepted()
       
   337 	{
       
   338 	//Return whether code entered is correct or not
       
   339 	return iCodeOk;
       
   340 	}
       
   341 
       
   342 TInt CSsmSecurityCheckNotifier::SecurityCheckResult() const
       
   343     {
       
   344     return iPinResult();
       
   345     }