telephonyserverplugins/simtsy/src/CSimPhoneUSimApp.cpp
changeset 0 3553901f7fa8
child 19 630d2f34d719
equal deleted inserted replaced
-1:000000000000 0:3553901f7fa8
       
     1 // Copyright (c) 2002-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 // Implements the Phone USim applications' manipulation code.
       
    15 // 
       
    16 //
       
    17 
       
    18 /**
       
    19  @file
       
    20 */
       
    21 
       
    22 #include "CSimPhone.h"
       
    23 #include "Simlog.h"
       
    24 #include <testconfigfileparser.h>
       
    25 
       
    26 /**
       
    27 Standard factory method for two phase construction of a USim
       
    28 applications object.  The USim applications object simulates the
       
    29 possible operations for manipulating applications residing on the UICC.
       
    30 
       
    31 @param aPhone The phone object from which the Phone USim
       
    32               applications was opened.
       
    33 @return A pointer to a new USim applications object.
       
    34 */
       
    35 CSimPhoneUSimApp* CSimPhoneUSimApp::NewL(CSimPhone* aPhone)
       
    36 	{
       
    37 	CSimPhoneUSimApp* obj=new(ELeave) CSimPhoneUSimApp(aPhone);
       
    38 	CleanupStack::PushL(obj);
       
    39 	obj->ConstructL();
       
    40 	CleanupStack::Pop();
       
    41 	return obj;
       
    42 	}
       
    43 
       
    44 /**
       
    45 Trivial first phase constructor.
       
    46 
       
    47 @param aPhone The phone object from which this Phone USimApp was opened.
       
    48 */
       
    49 CSimPhoneUSimApp::CSimPhoneUSimApp(CSimPhone* aPhone)
       
    50 : iPhone(aPhone), iCurrentSelection(RMobilePhone::EUSimSelectionAutomatic),
       
    51 	iFoundUSimAppTags(EFalse)
       
    52 /**
       
    53  * Trivial first phase constructor.
       
    54  * @param aPhone	The phone object from which this Phone USimApp was opened.
       
    55  */
       
    56 	{}
       
    57 
       
    58 void CSimPhoneUSimApp::Init()
       
    59 	{
       
    60 	}
       
    61 
       
    62 /**
       
    63 Second phase constructor for allocating memory to the USim applications
       
    64 specified in the SimTsy configuration file.
       
    65 */
       
    66 void CSimPhoneUSimApp::ConstructL()
       
    67 	{
       
    68 	LOGPHONE1("Starting to parse PhoneUSim applications additional config parameters...");
       
    69 	
       
    70 	const CTestConfigItem* item=NULL;
       
    71 	TInt ret=KErrNone;
       
    72 	TInt i;
       
    73 	TPtrC8 aid, label;
       
    74 	RMobilePhone::TUSimApplicationInfoV2 appInfo;
       
    75 
       
    76 	TRAP_IGNORE(iTimer=CSimTimer::NewL(iPhone));
       
    77 	iUSimAppInfo=new(ELeave) CArrayFixFlat<RMobilePhone::TUSimApplicationInfoV2>(KMaxUSimApps+1);
       
    78 	TInt count=CfgFile()->ItemCount(KUSIMAppInfo);
       
    79 	
       
    80 	LOGPHONE1("Starting to Load and Parse USim Application Info");
       
    81 
       
    82 	for(i=0;i<count;i++)
       
    83 		{
       
    84 		item=CfgFile()->Item(KUSIMAppInfo,i);
       
    85 		if(!item)
       
    86 			break;
       
    87 		
       
    88 		ret=CTestConfig::GetElement(item->Value(),KStdDelimiter,0, aid);
       
    89 		if(ret!=KErrNone)
       
    90 			{
       
    91 			LOGPARSERR("aid",ret,0,&KUSIMAppInfo);
       
    92 			continue;
       
    93 			}
       
    94 		else
       
    95 			{
       
    96 			appInfo.iAID.Copy(aid);
       
    97 			if(i==0)
       
    98 				iActiveAID.Copy(aid);
       
    99 			}
       
   100 		ret=CTestConfig::GetElement(item->Value(),KStdDelimiter,1, label);
       
   101 		if(ret!=KErrNone)
       
   102 			{
       
   103 			LOGPARSERR("label",ret,1,&KUSIMAppInfo);
       
   104 			continue;
       
   105 			}
       
   106 		else 
       
   107 			appInfo.iLabel.Copy(label);
       
   108 
       
   109 		iUSimAppInfo->AppendL(appInfo);
       
   110 		iFoundUSimAppTags = ETrue;
       
   111 		}
       
   112 	
       
   113 	iUSimAppEventList=new(ELeave) CArrayFixFlat<TUSimAppEvent>(10);
       
   114 	TUSimAppEvent appEvent;
       
   115 	TInt duration;
       
   116 
       
   117 	count=CfgFile()->ItemCount(KUSIMAppSwitching);
       
   118 	
       
   119 	LOGPHONE1("Starting to Load and Parse USim Application Info");
       
   120 
       
   121 	for(i=0;i<count;i++)
       
   122 		{
       
   123 		item=CfgFile()->Item(KUSIMAppSwitching,i);
       
   124 		if(!item)
       
   125 			break;
       
   126 
       
   127 		ret=CTestConfig::GetElement(item->Value(),KStdDelimiter,0, duration);
       
   128 		if(ret!=KErrNone)
       
   129 			{
       
   130 			LOGPARSERR("duration",ret,0,&KUSIMAppSwitching);
       
   131 			continue;
       
   132 			}
       
   133 		else
       
   134 			appEvent.iDuration=duration;
       
   135 
       
   136 		ret=CTestConfig::GetElement(item->Value(),KStdDelimiter,1, aid);
       
   137 		if(ret!=KErrNone)
       
   138 			{
       
   139 			LOGPARSERR("aid",ret,1,&KUSIMAppSwitching);
       
   140 			continue;
       
   141 			}
       
   142 		else 
       
   143 			appEvent.iAid.Copy(aid);
       
   144 
       
   145 		iUSimAppEventList->AppendL(appEvent);
       
   146 		}
       
   147 	}
       
   148 
       
   149 /**
       
   150 Standard destructor.  Any objects created by the ::ConstructL() function
       
   151 will be destroyed here.
       
   152 */
       
   153 CSimPhoneUSimApp::~CSimPhoneUSimApp()
       
   154 	{
       
   155 	delete iTimer;
       
   156 	if(iUSimAppEventList)
       
   157 		{
       
   158 		iUSimAppEventList->Delete(0, iUSimAppEventList->Count());
       
   159 		delete iUSimAppEventList;
       
   160 		}
       
   161 	if(iUSimAppInfo)
       
   162 		{
       
   163 		iUSimAppInfo->Delete(0, iUSimAppInfo->Count());
       
   164 		delete iUSimAppInfo;
       
   165 		}
       
   166 	}
       
   167 
       
   168 /**
       
   169 Dispatch function for all USim application requests.
       
   170 
       
   171 @param aReqHandle The TSY request handle for this request.
       
   172 @param aIpc The IPC number of this request.
       
   173 @param aPckg The parameter packaged data related to this request.
       
   174 @return A system wide error code indicating the status of the request.
       
   175 */
       
   176 TInt CSimPhoneUSimApp::ExtFunc(const TTsyReqHandle aTsyReqHandle,const TInt aIpc, const TDataPackage& aPckg)
       
   177 	{
       
   178 	TAny* dataPtr = aPckg.Ptr1();
       
   179 	TAny* dataPtr2 = aPckg.Ptr2();
       
   180 
       
   181 // The following requests can be completed even if the completion of another request is pending.
       
   182 	switch(aIpc)
       
   183 		{
       
   184 
       
   185 	case EMobilePhoneEnumerateUSimApplications:
       
   186 		return EnumerateUSimApplications(aTsyReqHandle, 
       
   187 			reinterpret_cast<TInt*> (dataPtr),
       
   188 			reinterpret_cast<RMobilePhone::TAID*> (dataPtr2));
       
   189 
       
   190 	case EMobilePhoneSetUSimApplicationStatus:
       
   191 		return SetUSimApplicationStatus(aTsyReqHandle,
       
   192 			reinterpret_cast<RMobilePhone::TAID*> (dataPtr),
       
   193 			reinterpret_cast<RMobilePhone::TUSimAppAction*> (dataPtr2));
       
   194 
       
   195 	case EMobilePhoneGetUSimApplicationsInfo:
       
   196 		return GetUSimApplicationInfo(aTsyReqHandle, 
       
   197 			reinterpret_cast<TInt*> (dataPtr),
       
   198 			aPckg.Des2n());
       
   199 
       
   200 	case EMobilePhoneNotifyUSimApplicationsInfoChange:
       
   201 		return NotifyUSimApplicationsInfoChange(aTsyReqHandle, 
       
   202 			reinterpret_cast<TInt*> (dataPtr),
       
   203 			reinterpret_cast<RMobilePhone::TAID*> (dataPtr2));
       
   204 
       
   205 	case EMobilePhoneGetUSimAppsSelectionMode:
       
   206 		return GetUSimAppsSelectionMode(aTsyReqHandle,
       
   207 			reinterpret_cast<RMobilePhone::TUSimSelectionMode*> (dataPtr));
       
   208 
       
   209 	case EMobilePhoneSetUSimAppsSelectionMode:
       
   210 		return SetUSimAppsSelectionMode(aTsyReqHandle,
       
   211 			reinterpret_cast<RMobilePhone::TUSimSelectionMode*> (dataPtr));
       
   212 
       
   213 	case EMobilePhoneNotifyUSimAppsSelectionModeChange:
       
   214 		return NotifyUSIMAppsSelectionModeChange(aTsyReqHandle, 
       
   215 			reinterpret_cast<RMobilePhone::TUSimSelectionMode*> (dataPtr));
       
   216 
       
   217 	default:
       
   218 		break;
       
   219 		}
       
   220 	return KErrNotSupported;
       
   221 	}
       
   222 
       
   223 /**
       
   224 The API does not support any objects that could be opened from this one.
       
   225 */
       
   226 CTelObject* CSimPhoneUSimApp::OpenNewObjectByNameL(const TDesC& /*aName*/)
       
   227 	{
       
   228 	User::Leave(KErrNotSupported);
       
   229 	return NULL;
       
   230 	}
       
   231 
       
   232 /**
       
   233 The API does not support any objects that could be opened from this one.
       
   234 */
       
   235 CTelObject* CSimPhoneUSimApp::OpenNewObjectL(TDes&)
       
   236 	{
       
   237 	User::Leave(KErrNotSupported);
       
   238 	return NULL;
       
   239 	}
       
   240 
       
   241 /**
       
   242 This function returns the Request Mode for the request with the passed
       
   243 IPC value.
       
   244 
       
   245 @param aIpc The IPC number of the request.
       
   246 @return TReqMode The request mode.
       
   247 */
       
   248 CTelObject::TReqMode CSimPhoneUSimApp::ReqModeL(const TInt aIpc)
       
   249 	{
       
   250 	CTelObject::TReqMode ret=0;	
       
   251 
       
   252 	switch(aIpc)
       
   253 		{
       
   254 	case EMobilePhoneEnumerateUSimApplications:
       
   255 	case EMobilePhoneSetUSimApplicationStatus:
       
   256 	case EMobilePhoneGetUSimApplicationsInfo:
       
   257 	case EMobilePhoneGetUSimAppsSelectionMode:
       
   258 	case EMobilePhoneSetUSimAppsSelectionMode:
       
   259 		break;
       
   260 
       
   261 	case EMobilePhoneNotifyUSimAppsSelectionModeChange:
       
   262 	case EMobilePhoneNotifyUSimApplicationsInfoChange:
       
   263 		ret=KReqModeMultipleCompletionEnabled | KReqModeRePostImmediately;
       
   264 		break;
       
   265 
       
   266 	default:
       
   267 		User::Leave(KErrNotSupported);
       
   268 		break;
       
   269 		}
       
   270 
       
   271 	return ret;
       
   272 	}
       
   273 
       
   274 /**
       
   275 The ETel Server calls this function when the first client makes a notification
       
   276 request.  If supported by the underlying protocol controlling the
       
   277 signalling stack, this can be used to start requesting updates for the relevant
       
   278 service.
       
   279 */
       
   280 TInt CSimPhoneUSimApp::RegisterNotification(const TInt /*aIpc*/)
       
   281 	{
       
   282 	return KErrNone;
       
   283 	}
       
   284 
       
   285 /**
       
   286 The ETel Server calls this function when the last client that had previously
       
   287 made a notification request closes its ETel Server handle.  If supported by
       
   288 the underlying protocol controlling the	signalling stack, this can be used
       
   289 to stop requesting updates for the relevant service.
       
   290 */
       
   291 TInt CSimPhoneUSimApp::DeregisterNotification(const TInt /*aIpc*/)
       
   292 	{
       
   293 	return KErrNone;
       
   294 	}
       
   295 
       
   296 /**
       
   297 Return the number of slots that the ETel Server should allocate for
       
   298 buffering requests of the given IPC number.
       
   299 */
       
   300 TInt CSimPhoneUSimApp::NumberOfSlotsL(const TInt aIpc)
       
   301 	{
       
   302 	switch(aIpc)
       
   303 		{
       
   304 	case EMobilePhoneNotifyUSimAppsSelectionModeChange:
       
   305 	case EMobilePhoneNotifyUSimApplicationsInfoChange:
       
   306 		return KDefaultNumberOfSlots;
       
   307 
       
   308 	default:
       
   309 		LOGPHONE1("CSimPhoneUSimApp: Number of Slots error, unknown IPC");
       
   310 		User::Leave(KErrNotSupported);
       
   311 		break;
       
   312 		}
       
   313 	return KDefaultNumberOfSlots;
       
   314 	}
       
   315 
       
   316 /**
       
   317 Cancels an outstanding client request.
       
   318 
       
   319 @param aIpc The IPC number of the request that is to be cancelled.
       
   320 @param aTsyReqHandle The TSY request handle of the request that is to
       
   321                      be cancelled.
       
   322 @return A system wide error code indicating the status of the request
       
   323         on cancellation.
       
   324 */
       
   325 TInt CSimPhoneUSimApp::CancelService(const TInt aIpc,const TTsyReqHandle aTsyReqHandle)
       
   326 	{
       
   327 	switch(aIpc)
       
   328 		{
       
   329 	case EMobilePhoneEnumerateUSimApplications:
       
   330 		return EnumerateUSimApplicationsCancel(aTsyReqHandle);
       
   331 
       
   332 	case EMobilePhoneSetUSimApplicationStatus:
       
   333 		return SetUSimApplicationStatusCancel(aTsyReqHandle);
       
   334 	
       
   335 	case EMobilePhoneGetUSimApplicationsInfo:
       
   336 		return GetUSimApplicationInfoCancel(aTsyReqHandle);
       
   337 
       
   338 	case EMobilePhoneNotifyUSimApplicationsInfoChange:
       
   339 		return NotifyUSimApplicationsInfoChangeCancel(aTsyReqHandle);
       
   340 	
       
   341 	case EMobilePhoneNotifyUSimAppsSelectionModeChange:
       
   342 		return NotifyUSIMAppsSelectionModeChangeCancel(aTsyReqHandle);
       
   343 
       
   344 	default:
       
   345 		break;
       
   346 		}
       
   347 	return KErrNone;
       
   348 	}
       
   349 
       
   350 /**
       
   351 Returns a pointer to the SimTsy configuration file section.
       
   352 
       
   353 @return A CTestConfigSection pointer, which contains a section of the
       
   354         parsed information in the config file.
       
   355 */
       
   356 const CTestConfigSection* CSimPhoneUSimApp::CfgFile()
       
   357 	{
       
   358 	LOGPHONE1(">>CSimPhoneUSimApp::CfgFile");
       
   359 	return iPhone->CfgFile();
       
   360 	}
       
   361 
       
   362 /**
       
   363 Timer callback function.  When the timer's delay ends, it will call
       
   364 back into this function for completion of the pending request.
       
   365 Currently, this call back is only used to complete a notify info change
       
   366 request on a specific application (NotifyUSimApplicationsInfoChange).
       
   367 
       
   368 @param aTsyReqHandle A handle belonging to the client that created the
       
   369                      session with this TSY server.
       
   370 @param aId an id identifying which timer callback is being called
       
   371 */	
       
   372 void CSimPhoneUSimApp::TimerCallBack(TInt /*aId*/)
       
   373 	{
       
   374 	if(iNotifyInfo.iNotifyPending)
       
   375 		{
       
   376 		TUSimAppEvent event=iUSimAppEventList->At(iEventPointer);
       
   377 		*(RMobilePhone::TAID*)iNotifyInfo.iNotifyData=event.iAid;
       
   378 		*((TInt*)iNotifyInfo.iNotifyDataXtra)=iUSimAppInfo->Count();
       
   379 		iActiveAID.Copy(event.iAid);
       
   380 		iNotifyInfo.iNotifyPending=EFalse;
       
   381 		iEventPointer++;
       
   382 		iPhone->ReqCompleted(iNotifyInfo.iNotifyHandle,KErrNone);
       
   383 		}
       
   384 	}
       
   385 	
       
   386 TBool CSimPhoneUSimApp::FoundUSimAppTags()
       
   387 /**
       
   388 * Returns a value to indicate whether USim App tags were found in the Config file
       
   389 *
       
   390 */
       
   391 	{
       
   392 	return iFoundUSimAppTags;
       
   393 	}
       
   394 
       
   395 /**
       
   396 Enumerates the number of USim applications in the UICC and returns the
       
   397 AID of the active application.
       
   398 
       
   399 @param aTsyReqHandle A handle belonging to the client that created the
       
   400                      session with this TSY server.
       
   401 @param aCount Returns the number of USim applications.
       
   402 @param aActiveAID Returns the AID of the currently active application.
       
   403 @return KErrNone.
       
   404 */
       
   405 TInt CSimPhoneUSimApp::EnumerateUSimApplications(TTsyReqHandle aTsyReqHandle, TInt* aCount, RMobilePhone::TAID* aActiveAID)
       
   406 	{
       
   407 	*aCount=iUSimAppInfo->Count();
       
   408 	aActiveAID->Copy(iActiveAID);
       
   409 	iPhone->ReqCompleted(aTsyReqHandle, KErrNone);
       
   410 	return KErrNone;
       
   411 	}
       
   412 
       
   413 /**
       
   414 Attempts to cancel a pending EnumerateUSimApplications request
       
   415 (unsuccesfully).
       
   416 
       
   417 @param aTsyReqHandle A handle belonging to the client that created the
       
   418                      session with this TSY server.
       
   419 */
       
   420 TInt CSimPhoneUSimApp::EnumerateUSimApplicationsCancel(TTsyReqHandle aTsyReqHandle)
       
   421 	{
       
   422 	iPhone->ReqCompleted(aTsyReqHandle, KErrNone);
       
   423 	return KErrNone;
       
   424 	}
       
   425 
       
   426 /**
       
   427 Retrieves information for a specified USim application
       
   428 
       
   429 @param aTsyReqHandle A handle belonging to the client that created the
       
   430                      session with this TSY server.
       
   431 @param aUSimAppIndex Used to specify the index of the application.
       
   432 @param aInfo Returns the information of the specified appplication.
       
   433 @return KErrNone.
       
   434 */
       
   435 TInt CSimPhoneUSimApp::GetUSimApplicationInfo(TTsyReqHandle aTsyReqHandle, TInt* aUSimAppIndex, TDes8* aInfo)
       
   436 	{
       
   437 	if(*aUSimAppIndex>=iUSimAppInfo->Count())
       
   438 		{
       
   439 		iPhone->ReqCompleted(aTsyReqHandle, KErrNotFound);
       
   440 		return KErrNone;
       
   441 		}
       
   442 	else
       
   443 		{
       
   444 		TPckg<RMobilePhone::TUSimApplicationInfoV2>* infoPckg = (TPckg<RMobilePhone::TUSimApplicationInfoV2>*)aInfo;
       
   445 		RMobilePhone::TUSimApplicationInfoV2& info = (*infoPckg)();
       
   446 
       
   447 		// Check that the data structure is supported by the simulated TSY version
       
   448 		TInt err = iPhone->CheckSimTsyVersion(info);
       
   449 		if(err != KErrNone)
       
   450 			{
       
   451 			iPhone->ReqCompleted(aTsyReqHandle, err);
       
   452 			return KErrNone;
       
   453 			}
       
   454 
       
   455 		info=iUSimAppInfo->At(*aUSimAppIndex);
       
   456 		iPhone->ReqCompleted(aTsyReqHandle, KErrNone);
       
   457 		}
       
   458 	
       
   459 	return KErrNone;
       
   460 	}
       
   461 
       
   462 /**
       
   463 Attempts to cancel a pending GetUSimApplicationInfo request
       
   464 (unsuccesfully).
       
   465 
       
   466 @param aTsyReqHandle A handle belonging to the client that created the
       
   467                      session with this TSY server.
       
   468 */
       
   469 TInt CSimPhoneUSimApp::GetUSimApplicationInfoCancel(TTsyReqHandle aTsyReqHandle)
       
   470 	{
       
   471 	iPhone->ReqCompleted(aTsyReqHandle, KErrNone);
       
   472 	return KErrNone;
       
   473 	}
       
   474 
       
   475 /**
       
   476 Notifies the client when the specified USim application's information
       
   477 changes.
       
   478 
       
   479 @param aTsyReqHandle A handle belonging to the client that created the
       
   480                      session with this TSY server.
       
   481 @param aCount Returns the total number of USim applications when the
       
   482               request completes.
       
   483 @param aActiveAID The application's AID whose infromation change will
       
   484                   be notified to the client.
       
   485 @return KErrNone.
       
   486 */
       
   487 TInt CSimPhoneUSimApp::NotifyUSimApplicationsInfoChange(TTsyReqHandle aTsyReqHandle, TInt* aCount, RMobilePhone::TAID* aActiveAID)
       
   488 	{
       
   489 	__ASSERT_ALWAYS(!iNotifyInfo.iNotifyPending,SimPanic(ENotificationReqAlreadyOutstanding));
       
   490 
       
   491 	TInt count=iUSimAppEventList->Count();
       
   492 
       
   493 	iNotifyInfo.iNotifyPending=ETrue;
       
   494 	iNotifyInfo.iNotifyHandle=aTsyReqHandle;
       
   495 	iNotifyInfo.iNotifyData=aActiveAID;
       
   496 	iNotifyInfo.iNotifyDataXtra=aCount;
       
   497 
       
   498 	if(iEventPointer<count)
       
   499 		{
       
   500 		if(iTimerStarted)
       
   501 			{
       
   502 			delete iTimer;
       
   503 			iTimer = NULL;
       
   504 			TRAP_IGNORE(iTimer=CSimTimer::NewL(iPhone));
       
   505 			}
       
   506 
       
   507 		TUSimAppEvent event=iUSimAppEventList->At(iEventPointer);
       
   508 
       
   509 		if (iTimer != NULL)
       
   510 			{
       
   511 			iTimer->Start(event.iDuration,this);
       
   512 			iTimerStarted = ETrue;
       
   513 			}
       
   514 		}
       
   515 
       
   516 	return KErrNone;
       
   517 	}
       
   518 
       
   519 /**
       
   520 Attempts to cancel a pending NotifyUSimApplicationsInfoChange request.
       
   521 
       
   522 @param aTsyReqHandle A handle belonging to the client that created the
       
   523                      session with this TSY server.
       
   524 */
       
   525 TInt CSimPhoneUSimApp::NotifyUSimApplicationsInfoChangeCancel(TTsyReqHandle aTsyReqHandle)
       
   526 	{
       
   527 	if(iNotifyInfo.iNotifyPending)
       
   528 		{
       
   529 		iNotifyInfo.iNotifyPending=EFalse;
       
   530 		iPhone->ReqCompleted(aTsyReqHandle,KErrCancel);
       
   531 		return KErrNone;
       
   532 		}
       
   533 	iPhone->ReqCompleted(aTsyReqHandle,KErrNone);
       
   534 	return KErrNone;
       
   535 	}
       
   536 
       
   537 /**
       
   538 Sets the Selection mode for USim applications.
       
   539 
       
   540 @param aTsyReqHandle A handle belonging to the client that created the
       
   541                      session with this TSY server.
       
   542 @param aUSimSelectionMode Used to specify the new selection mode for
       
   543                           applications.
       
   544 @return KErrNone.
       
   545 */
       
   546 TInt CSimPhoneUSimApp::SetUSimAppsSelectionMode(TTsyReqHandle aTsyReqHandle, RMobilePhone::TUSimSelectionMode* aUSimSelectionMode)
       
   547 	{
       
   548 	iCurrentSelection=*aUSimSelectionMode;
       
   549 	if(iNotifyMode.iNotifyPending)
       
   550 		{
       
   551 		iNotifyMode.iNotifyPending=EFalse;
       
   552 		*(RMobilePhone::TUSimSelectionMode*)iNotifyMode.iNotifyData=iCurrentSelection;
       
   553 		iPhone->ReqCompleted(iNotifyMode.iNotifyHandle,KErrNone);
       
   554 		}
       
   555 	iPhone->ReqCompleted(aTsyReqHandle, KErrNone);
       
   556 	return KErrNone;
       
   557 	}
       
   558 
       
   559 /**
       
   560 Requests the selection mode of a particular USim applications.
       
   561 
       
   562 @param aTsyReqHandle A handle belonging to the client that created the
       
   563                      session with this TSY server.
       
   564 @param aUSimSelectionMode Returns the selection mode for applications.
       
   565 @return KErrNone.
       
   566 */
       
   567 TInt CSimPhoneUSimApp::GetUSimAppsSelectionMode(TTsyReqHandle aTsyReqHandle, RMobilePhone::TUSimSelectionMode* aUSimSelectionMode)
       
   568 	{
       
   569 	*aUSimSelectionMode=iCurrentSelection;
       
   570 	iPhone->ReqCompleted(aTsyReqHandle, KErrNone);
       
   571 	return KErrNone;
       
   572 	}
       
   573 
       
   574 /**
       
   575 Notifies the client on a selection mode change of USim applications.
       
   576 
       
   577 @param aTsyReqHandle A handle belonging to the client that created the
       
   578                      session with this TSY server.
       
   579 @param aUSimSelectionMode Returns the new selection mode for applications.
       
   580 @return KErrNone.
       
   581 */
       
   582 TInt CSimPhoneUSimApp::NotifyUSIMAppsSelectionModeChange(TTsyReqHandle aTsyReqHandle, RMobilePhone::TUSimSelectionMode* aUSimSelectionMode)
       
   583 	{
       
   584 	__ASSERT_ALWAYS(!iNotifyMode.iNotifyPending,SimPanic(ENotificationReqAlreadyOutstanding));
       
   585 	iNotifyMode.iNotifyPending=ETrue;
       
   586 	iNotifyMode.iNotifyHandle=aTsyReqHandle;
       
   587 	iNotifyMode.iNotifyData=aUSimSelectionMode;
       
   588 	return KErrNone;
       
   589 	}
       
   590 
       
   591 /**
       
   592 Attempts to cancel a pending NotifyUSIMAppsSelectionModeChange request.
       
   593 
       
   594 @param aTsyReqHandle A handle belonging to the client that created the
       
   595                      session with this TSY server.
       
   596 */
       
   597 TInt CSimPhoneUSimApp::NotifyUSIMAppsSelectionModeChangeCancel(TTsyReqHandle aTsyReqHandle)
       
   598 	{
       
   599 	if(iNotifyMode.iNotifyPending)
       
   600 		{
       
   601 		iNotifyMode.iNotifyPending=EFalse;
       
   602 		iPhone->ReqCompleted(aTsyReqHandle,KErrCancel);
       
   603 		return KErrNone;
       
   604 		}
       
   605 	iPhone->ReqCompleted(aTsyReqHandle,KErrNone);
       
   606 	return KErrNone;
       
   607 	}
       
   608 
       
   609 /**
       
   610 Attempts to set the status of a specific USim application.
       
   611 
       
   612 @param aTsyReqHandle A handle belonging to the client that created the
       
   613                      session with this TSY server.
       
   614 @param aAID The specific application's ID whose status is to be set.
       
   615 @param aUsimAppAction The status to apply to the application identified
       
   616                       by aAID.
       
   617 @return KErrNone on completion of request, unless the aAID given is not
       
   618         identifiable, in which case KErrArgument is returned.
       
   619 */
       
   620 TInt CSimPhoneUSimApp::SetUSimApplicationStatus(TTsyReqHandle aTsyReqHandle, RMobilePhone::TAID* aAID, RMobilePhone::TUSimAppAction* aUsimAppAction)
       
   621 	{
       
   622 	TInt count=iUSimAppInfo->Count();
       
   623 	for(TInt i=0;i<count;i++)
       
   624 		{
       
   625 		RMobilePhone::TUSimApplicationInfoV2 info=iUSimAppInfo->At(i);
       
   626 
       
   627 		// Check that the data structure is supported by the simulated TSY version
       
   628 		TInt err = iPhone->CheckSimTsyVersion(info);
       
   629 		if(err != KErrNone)
       
   630 			{
       
   631 			iPhone->ReqCompleted(aTsyReqHandle, err);
       
   632 			return KErrNone;
       
   633 			}
       
   634 		
       
   635 			if(info.iAID.Compare(*aAID)==0)
       
   636 				{
       
   637 				if(*aUsimAppAction==RMobilePhone::EUSimActivate)
       
   638 					{
       
   639 					iActiveAID=*aAID;
       
   640 					if(iNotifyInfo.iNotifyPending)
       
   641 						{
       
   642 						iNotifyInfo.iNotifyPending=EFalse;
       
   643 						iNotifyInfo.iNotifyData=&iActiveAID;
       
   644 						*(TInt*)iNotifyInfo.iNotifyDataXtra=iUSimAppInfo->Count();
       
   645 						iPhone->ReqCompleted(iNotifyInfo.iNotifyHandle,KErrNone);
       
   646 						}
       
   647 					iPhone->ReqCompleted(aTsyReqHandle,KErrNone);
       
   648 					return KErrNone;
       
   649 					}
       
   650 				else if((*aUsimAppAction==RMobilePhone::EUSimTerminate) &&
       
   651 						(iActiveAID.Compare(*aAID)==0))
       
   652 					{
       
   653 						//if the active is the last one
       
   654 						if(i==KMaxUSimApps-1)
       
   655 							info=iUSimAppInfo->At(0);
       
   656 						else
       
   657 							info=iUSimAppInfo->At(i+1);
       
   658 						iActiveAID=info.iAID;
       
   659 
       
   660 						if(iNotifyInfo.iNotifyPending)
       
   661 						{
       
   662 						iNotifyInfo.iNotifyPending=EFalse;
       
   663 						iNotifyInfo.iNotifyData=&iActiveAID;
       
   664 						*(TInt*)iNotifyInfo.iNotifyDataXtra=iUSimAppInfo->Count();
       
   665 						iPhone->ReqCompleted(iNotifyInfo.iNotifyHandle,KErrNone);
       
   666 						}
       
   667 					iPhone->ReqCompleted(aTsyReqHandle,KErrNone);
       
   668 					return KErrNone;
       
   669 					}
       
   670 					else if((*aUsimAppAction==RMobilePhone::EUSimTerminate) &&
       
   671 					(iActiveAID.Compare(*aAID)!=0))
       
   672 						{
       
   673 						iPhone->ReqCompleted(aTsyReqHandle,KErrArgument);
       
   674 						return KErrArgument;
       
   675 						}
       
   676 				}
       
   677 		}
       
   678 	iPhone->ReqCompleted(aTsyReqHandle,KErrNotFound);
       
   679 	return KErrNone;
       
   680 	}
       
   681 
       
   682 /**
       
   683 Attempts to cancel a pending SetUSimApplicationStatus request
       
   684 (unsuccesfully).
       
   685 
       
   686 @param aTsyReqHandle A handle belonging to the client that created the
       
   687                      session with this TSY server.
       
   688 @return KErrNone.
       
   689 */
       
   690 TInt CSimPhoneUSimApp::SetUSimApplicationStatusCancel(TTsyReqHandle aTsyReqHandle)
       
   691 	{
       
   692 	iPhone->ReqCompleted(aTsyReqHandle, KErrNone);
       
   693 	return KErrNone;
       
   694 	}
       
   695 
       
   696 /**
       
   697 Returns the active application's aid (internally).
       
   698 */
       
   699 RMobilePhone::TAID CSimPhoneUSimApp::GetActiveUSim()
       
   700 	{
       
   701 	return iActiveAID;
       
   702 	}