securitydialogs/Autolock/src/AutolockAppUi.cpp
branchRCL_3
changeset 11 9971b621ef6c
parent 10 bbcfd14ce6a7
child 13 53af9c3d61e4
equal deleted inserted replaced
10:bbcfd14ce6a7 11:9971b621ef6c
    55 #include <apgwgnam.h>
    55 #include <apgwgnam.h>
    56 #include <aknlayoutscalable_avkon.cdl.h>
    56 #include <aknlayoutscalable_avkon.cdl.h>
    57 
    57 
    58 //  LOCAL CONSTANTS AND MACROS  
    58 //  LOCAL CONSTANTS AND MACROS  
    59 #define KSysApUid TUid::Uid(0x100058F3)
    59 #define KSysApUid TUid::Uid(0x100058F3)
       
    60 #define KPhoneAppUid TUid::Uid(0x100058B3)
    60 
    61 
    61 const TInt KTriesToConnectServer( 2 );
    62 const TInt KTriesToConnectServer( 2 );
    62 const TInt KTimeBeforeRetryingServerConnection( 50000 );
    63 const TInt KTimeBeforeRetryingServerConnection( 50000 );
    63 const TInt PhoneIndex( 0 );
    64 const TInt PhoneIndex( 0 );
    64 
    65 
    91 	iSideKey1 = 0;
    92 	iSideKey1 = 0;
    92 	iSideKey2 = 0;
    93 	iSideKey2 = 0;
    93 	iAppKey = 0;
    94 	iAppKey = 0;
    94 
    95 
    95 	aCallButtonRect = TRect (0,0,0,0);
    96 	aCallButtonRect = TRect (0,0,0,0);
       
    97 	iGotEventDownDuringCall = -1;
    96 	//connect to ETel
    98 	//connect to ETel
    97 
    99 
    98 	TInt err( KErrGeneral );
   100 	TInt err( KErrGeneral );
    99     TInt thisTry( 0 );
   101     TInt thisTry( 0 );
   100     
   102     
   163     
   165     
   164 	iWait->SetRequestType(EMobilePhoneGetLockInfo);
   166 	iWait->SetRequestType(EMobilePhoneGetLockInfo);
   165 	iPhone.GetLockInfo(iWait->iStatus, lockType, lockInfoPkg);
   167 	iPhone.GetLockInfo(iWait->iStatus, lockType, lockInfoPkg);
   166 	TInt res = iWait->WaitForRequestL();
   168 	TInt res = iWait->WaitForRequestL();
   167 	User::LeaveIfError(res);
   169 	User::LeaveIfError(res);
       
   170 	    
       
   171   // Eventhough we might lock the device on boot-up (systemLocked == ETrue), we
       
   172   // want to hide the app until the handshake is done. StartUp application will
       
   173   // active the app when it is finished.   
       
   174   TApaTask self(iCoeEnv->WsSession());
       
   175   self.SetWgId(iCoeEnv->RootWin().Identifier());
       
   176   self.SendToBackground();
       
   177   // flush
       
   178   iCoeEnv->WsSession().Flush();	    
       
   179 		    
   168     TInt lockValue = 0;
   180     TInt lockValue = 0;
   169     CRepository* repository = CRepository::NewL(KCRUidSecuritySettings);
   181     CRepository* repository = CRepository::NewL(KCRUidSecuritySettings);
   170     TInt cRresult = repository->Get(KSettingsAutolockStatus, lockValue);
   182     TInt cRresult = repository->Get(KSettingsAutolockStatus, lockValue);
   171     TBool hiddenReset = HiddenReset();
   183     TBool hiddenReset = HiddenReset();
   172     #if defined(_DEBUG)
   184     #if defined(_DEBUG)
   490 			// lock voice key 
   502 			// lock voice key 
   491 			LockSideKeyL();	
   503 			LockSideKeyL();	
   492 			CAknView* view = View(KAutoLockViewId);
   504 			CAknView* view = View(KAutoLockViewId);
   493 			if(view)
   505 			if(view)
   494 				{	
   506 				{	
   495 		  		TRect aCallRect;
   507 		  		TRect aInitialRect;
   496 				STATIC_CAST(CAutolockView*, view)->HandleCall(0x15, aCallRect);
   508 				STATIC_CAST(CAutolockView*, view)->HandleCall(0x15, aInitialRect);
   497 				}
   509 				}
   498 		
   510 		
   499 			}
   511 			}
   500 		else
   512 		else
   501 			{
   513 			{
   517 			{	
   529 			{	
   518 			// try put autolock back to foreground
   530 			// try put autolock back to foreground
   519 			CAknView* view = View(KAutoLockViewId);
   531 			CAknView* view = View(KAutoLockViewId);
   520 			if(view)
   532 			if(view)
   521 				{	
   533 				{	
   522 				TRect aCallRect;
   534 				TRect aInitialRect;
   523 				STATIC_CAST(CAutolockView*, view)->HandleCall(0x19, aCallRect);
   535 				STATIC_CAST(CAutolockView*, view)->HandleCall(0x19, aInitialRect);
   524 				}
   536 				}
   525 			TApaTask self(iCoeEnv->WsSession());
   537 			TApaTask self(iCoeEnv->WsSession());
   526 			self.SetWgId(iCoeEnv->RootWin().Identifier());
   538 			self.SetWgId(iCoeEnv->RootWin().Identifier());
   527 			self.BringToForeground();		
   539 			self.BringToForeground();		
   528 			}
   540 			}
   531 			// unlock voice key while there is active call
   543 			// unlock voice key while there is active call
   532 			UnLockSideKey();
   544 			UnLockSideKey();
   533 			CAknView* view = View(KAutoLockViewId);
   545 			CAknView* view = View(KAutoLockViewId);
   534 			if(view)
   546 			if(view)
   535 				{	
   547 				{	
   536 			  	TRect aCallRect;
   548 			  	TRect aInitialRect;
   537 				STATIC_CAST(CAutolockView*, view)->HandleCall(0x16, aCallRect);
   549 				STATIC_CAST(CAutolockView*, view)->HandleCall(0x16, aInitialRect);
   538 				}
   550 				}
   539 			}
   551 			}
   540 		}
   552 		}
   541 
   553 
   542 	CAknAppUi::HandleForegroundEventL(aForeground);
   554 	CAknAppUi::HandleForegroundEventL(aForeground);
   753 			{
   765 			{
   754 			iDeviceLockQueryStatus = ETrue;
   766 			iDeviceLockQueryStatus = ETrue;
   755 			TBool iAppKeyBelongedToBigClock=EFalse;
   767 			TBool iAppKeyBelongedToBigClock=EFalse;
   756 			if(!iAppKey)
   768 			if(!iAppKey)
   757 				{
   769 				{
   758 				RDebug::Printf( "%s %s (%u) stealing EStdKeyApplication0 from BigClock=%x", __FILE__, __PRETTY_FUNCTION__, __LINE__, 0 );
   770 				// RDebug::Printf( "%s %s (%u) stealing EStdKeyApplication0 from BigClock=%x", __FILE__, __PRETTY_FUNCTION__, __LINE__, 0 );
   759 				RWindowGroup& groupWin=iCoeEnv->RootWin();
   771 				RWindowGroup& groupWin=iCoeEnv->RootWin();
   760 				iAppKey = groupWin.CaptureKeyUpAndDowns(EStdKeyApplication0, 0, 0); // Capture app key now, in case that it was given to BigClock
   772 				iAppKey = groupWin.CaptureKeyUpAndDowns(EStdKeyApplication0, 0, 0); // Capture app key now, in case that it was given to BigClock
   761 				iAppKeyBelongedToBigClock=ETrue;
   773 				iAppKeyBelongedToBigClock=ETrue;
   762 				}
   774 				}
   763 			if(handler->AskSecCodeInAutoLockL())
   775 			if(handler->AskSecCodeInAutoLockL())
   771 				}
   783 				}
   772             else
   784             else
   773 				{  // make sure that we will be topmost still
   785 				{  // make sure that we will be topmost still
   774 					if(iAppKey && iAppKeyBelongedToBigClock)
   786 					if(iAppKey && iAppKeyBelongedToBigClock)
   775 						{
   787 						{
   776 						RDebug::Printf( "%s %s (%u) giving EStdKeyApplication0 to BigClock=%x", __FILE__, __PRETTY_FUNCTION__, __LINE__, 0 );
   788 						// RDebug::Printf( "%s %s (%u) giving EStdKeyApplication0 to BigClock=%x", __FILE__, __PRETTY_FUNCTION__, __LINE__, 0 );
   777 						RWindowGroup& groupWin=iCoeEnv->RootWin();
   789 						RWindowGroup& groupWin=iCoeEnv->RootWin();
   778 						groupWin.CancelCaptureKeyUpAndDowns(iAppKey);	// give S60-Application key back to BigClock
   790 						groupWin.CancelCaptureKeyUpAndDowns(iAppKey);	// give S60-Application key back to BigClock
   779 						iAppKey = 0;
   791 						iAppKey = 0;
   780 						}
   792 						}
   781 				    iDeviceLockQueryStatus = EFalse;
   793 				    iDeviceLockQueryStatus = EFalse;
   938 	// in case Telephone-app is topmost, then the user is confused because he sees but can't use it.
   950 	// in case Telephone-app is topmost, then the user is confused because he sees but can't use it.
   939 	// therefore it's required to hide it, by sending to background. ETMA-7M8A2Y 20090105
   951 	// therefore it's required to hide it, by sending to background. ETMA-7M8A2Y 20090105
   940 	if ( AknLayoutUtils::PenEnabled() )
   952 	if ( AknLayoutUtils::PenEnabled() )
   941      	{ 		
   953      	{ 		
   942    			TApaTaskList apaTaskList(CCoeEnv::Static()->WsSession());
   954    			TApaTaskList apaTaskList(CCoeEnv::Static()->WsSession());
   943    			#define KPhoneAppUid TUid::Uid(0x100058B3)
       
   944 
   955 
   945    			TApaTask apaTask = apaTaskList.FindApp(KPhoneAppUid);
   956    			TApaTask apaTask = apaTaskList.FindApp(KPhoneAppUid);
   946    			if (apaTask.Exists())
   957    			if (apaTask.Exists())
   947        	{
   958        	{
   948 			 		#if defined(_DEBUG)
   959 			 		#if defined(_DEBUG)
   961 	self.BringToForeground();
   972 	self.BringToForeground();
   962 	ActivateLocalViewL(KAutoLockViewId);
   973 	ActivateLocalViewL(KAutoLockViewId);
   963 	CAknView* view = View(KAutoLockViewId);
   974 	CAknView* view = View(KAutoLockViewId);
   964 	if(view)
   975 	if(view)
   965 	  {
   976 	  {
   966 	  TRect aCallRect;
   977 	  TRect aInitialRect;
   967       STATIC_CAST(CAutolockView*, view)->HandleCall(0x17, aCallRect);
   978       STATIC_CAST(CAutolockView*, view)->HandleCall(0x17, aInitialRect);
   968 	  STATIC_CAST(CAutolockView*, view)->MakeVisible(ETrue);
   979 	  STATIC_CAST(CAutolockView*, view)->MakeVisible(ETrue);
   969 	  }
   980 	  }
   970 	else
   981 	else
   971 	  {
   982 	  {
   972 	  #if defined(_DEBUG)
   983 	  #if defined(_DEBUG)
  1276 		    case KAknFullOrPartialForegroundGained: // partial or full fg gained
  1287 		    case KAknFullOrPartialForegroundGained: // partial or full fg gained
  1277 		    	if( iIncallBubble )
  1288 		    	if( iIncallBubble )
  1278 		           	{
  1289 		           	{
  1279 		             	#if defined(_DEBUG)
  1290 		             	#if defined(_DEBUG)
  1280 		    			RDebug::Print(_L("(AUTOLOCK)CAutolockAppUi::HandleWsEventL: ENABLE call bubble"));
  1291 		    			RDebug::Print(_L("(AUTOLOCK)CAutolockAppUi::HandleWsEventL: ENABLE call bubble"));
  1281 		    			#endif                      
  1292 		    			#endif
       
  1293    						CAknView* view = View(KAutoLockViewId);
       
  1294 							if(view)
       
  1295 								{	
       
  1296 								TRect aInitialRect;
       
  1297 								STATIC_CAST(CAutolockView*, view)->HandleCall(0x1A, aInitialRect);
       
  1298 								}
       
  1299 
  1282 		                iIncallBubble->SetIncallBubbleAllowedInIdleL( ETrue );
  1300 		                iIncallBubble->SetIncallBubbleAllowedInIdleL( ETrue );
  1283 		            }
  1301 		            }
  1284 		    	break;	
  1302 		    	break;	
  1285     	    case EEventWindowGroupListChanged:
  1303     	    case EEventWindowGroupListChanged:
  1286     	        HandleWindowGroupListChange();
  1304     	        HandleWindowGroupListChange();
  1288     	    case EEventPointer:
  1306     	    case EEventPointer:
  1289     	    case EEventDragDrop:
  1307     	    case EEventDragDrop:
  1290     	    		{
  1308     	    		{
  1291     	    		TInt callState = 0;
  1309     	    		TInt callState = 0;
  1292     	    		RProperty::Get( KPSUidCtsyCallInformation, KCTsyCallState, callState );
  1310     	    		RProperty::Get( KPSUidCtsyCallInformation, KCTsyCallState, callState );
  1293 			        if ( 1==1 || callState == EPSCTsyCallStateNone || callState == EPSCTsyCallStateUninitialized )
       
  1294 			        	{
       
  1295 	    	        TPointerEvent *pointer = aEvent.Pointer();
  1311 	    	        TPointerEvent *pointer = aEvent.Pointer();
  1296 	    	          CAknView* view = View(KAutoLockViewId);
  1312 	    	          CAknView* view = View(KAutoLockViewId);
  1297 								  if(view)
  1313 								  if(view)
  1298 								    {	
  1314 								    {	
  1299 								        STATIC_CAST(CAutolockView*, view)->ScreenDeviceChanged();
  1315 								        STATIC_CAST(CAutolockView*, view)->ScreenDeviceChanged();
  1300 								    	TRect aCallRect;
  1316 								    	TRect aInitialRect;
  1301 								        STATIC_CAST(CAutolockView*, view)->HandleCall(0x1, aCallRect);
  1317 								        STATIC_CAST(CAutolockView*, view)->HandleCall(0x1, aInitialRect);
  1302    								    	if(aCallButtonRect.iBr.iX==0)
  1318    								    	if(aCallButtonRect.iBr.iX==0)	// initialize if not done already
  1303    								    		aCallButtonRect = TRect (aCallRect);
  1319    								    		aCallButtonRect = TRect (aInitialRect);
  1304 								    }
  1320 								    }
       
  1321 			        if ( callState != EPSCTsyCallStateNone && callState != EPSCTsyCallStateUninitialized )
       
  1322 			        	{
       
  1323 	    	        if(pointer->iType==TPointerEvent::EButton1Down)
       
  1324 	    	        	{
       
  1325 		    	        TPoint iPosition = pointer->iPosition;
       
  1326 									if(aCallButtonRect.iBr.iX<iPosition.iX && iPosition.iX<aCallButtonRect.iBr.iX+aCallButtonRect.iTl.iX && iPosition.iY>400 )
       
  1327 	    		        	{
       
  1328 	    		        	iGotEventDownDuringCall=1;
       
  1329 	    		        	}
       
  1330 	    		        }
  1305 	    	        if(pointer->iType==TPointerEvent::EButton1Up)
  1331 	    	        if(pointer->iType==TPointerEvent::EButton1Up)
  1306 	    	        	{
  1332 	    	        	{
  1307 		    	        TPoint iPosition = pointer->iPosition;
  1333 		    	        TPoint iPosition = pointer->iPosition;
  1308 						if(aCallButtonRect.iBr.iX<iPosition.iX && iPosition.iX<aCallButtonRect.iBr.iX+aCallButtonRect.iTl.iX && iPosition.iY>400 )
  1334 		    	        // touching at any point inside and below the BigRedButton. This is to handle the case where another dialog overlaps
       
  1335 						if(iGotEventDownDuringCall==1 && aCallButtonRect.iBr.iX<iPosition.iX && iPosition.iX<aCallButtonRect.iBr.iX+aCallButtonRect.iTl.iX && iPosition.iY>400 )
  1309 	    		        	{
  1336 	    		        	{
  1310 	    		        		#define KPhoneAppUid1 TUid::Uid(0x100058B3)
       
  1311 	    		        		TApaTaskList tasklist( iCoeEnv->WsSession() );
  1337 	    		        		TApaTaskList tasklist( iCoeEnv->WsSession() );
  1312                       TApaTask phonetask = tasklist.FindApp( KPhoneAppUid1 );
  1338                       TApaTask phonetask = tasklist.FindApp( KPhoneAppUid );
  1313 	    		        		if ( phonetask.Exists() )
  1339 	    		        		if ( phonetask.Exists() )
  1314                         {
  1340                         {	// send End key to Telephony to end the call
  1315 										    TRawEvent event;
  1341 										    TRawEvent event;
  1316 										    event.Set(TRawEvent::EKeyDown, EStdKeyNo);
  1342 										    event.Set(TRawEvent::EKeyDown, EStdKeyNo);
  1317 										    iEikonEnv->WsSession().SimulateRawEvent(event);
  1343 										    iEikonEnv->WsSession().SimulateRawEvent(event);
  1318                         					User::After(1000);
  1344                         					User::After(1000);
  1319 										    event.Set(TRawEvent::EKeyUp, EStdKeyNo);
  1345 										    event.Set(TRawEvent::EKeyUp, EStdKeyNo);
  1320 										    iEikonEnv->WsSession().SimulateRawEvent(event);
  1346 										    iEikonEnv->WsSession().SimulateRawEvent(event);
  1321                         }
  1347                         }
  1322 	    		        	}
  1348 	    		        	}
       
  1349 	    		        iGotEventDownDuringCall=0;	// even if outside
  1323 	    		        }
  1350 	    		        }
  1324 	    		      }
  1351 	    		      }
  1325     		      }
  1352     		      }
  1326     	        break;
  1353     	        break;
  1327     	    case EEventKeyUp:	// on touch devices, this happens only for the switch-key, which should turn on the lights.
  1354     	    case EEventKeyUp:	// on touch devices, this happens only for the switch-key, which should turn on the lights.
  1329     	    case EEventKeyDown:
  1356     	    case EEventKeyDown:
  1330     		if(iLocked)
  1357     		if(iLocked)
  1331 	    	        SendMessageToSysAp( EEikSecurityQueryLights );
  1358 	    	        SendMessageToSysAp( EEikSecurityQueryLights );
  1332 	    	        break;
  1359 	    	        break;
  1333 		    default:
  1360 		    default:
       
  1361 		    	iGotEventDownDuringCall=0;	// any other event invalidates the Press inside the BigRedButton
  1334 		    	break;
  1362 		    	break;
  1335     	}
  1363     	}
  1336     	
  1364     	
  1337     	// All events are sent to base class.
  1365     	// All events are sent to base class.
  1338     	CAknViewAppUi::HandleWsEventL( aEvent, aDestination );
  1366     	CAknViewAppUi::HandleWsEventL( aEvent, aDestination );
  1377     else
  1405     else
  1378         {
  1406         {
  1379 		            CAknView* view = View(KAutoLockViewId);
  1407 		            CAknView* view = View(KAutoLockViewId);
  1380 								  if(view)
  1408 								  if(view)
  1381 								    {	
  1409 								    {	
  1382 								    	TRect aCallRect;
  1410 								    	TRect aInitialRect;
  1383 								        STATIC_CAST(CAutolockView*, view)->HandleCall(0x10, aCallRect);
  1411 								        STATIC_CAST(CAutolockView*, view)->HandleCall(0x10, aInitialRect);
  1384 												if(aCallButtonRect.iBr.iX==0)
  1412 												if(aCallButtonRect.iBr.iX==0)	// initialize if not done already
  1385    								    		aCallButtonRect = TRect (aCallRect);
  1413    								    		aCallButtonRect = TRect (aInitialRect);
  1386 								    }
  1414 								    }
  1387         // So now system is locked. When call is not ongoing, autolock should
  1415         // So now system is locked. When call is not ongoing, autolock should
  1388         // be on the foreground.
  1416         // be on the foreground.
  1389         TInt callState = 0;
  1417         TInt callState = 0;
  1390         RProperty::Get( KPSUidCtsyCallInformation, KCTsyCallState, callState );
  1418         RProperty::Get( KPSUidCtsyCallInformation, KCTsyCallState, callState );