Exemplo n.º 1
0
void CPolicyTest::ConstructL(const TTestActionSpec& aTestActionSpec)
	{
	CTestAction::ConstructL(aTestActionSpec);
	iExpectedResult = KErrNone;

	User::LeaveIfError(iFs.Connect());

	RProcess thisProcess;
	User::LeaveIfError(thisProcess.Open(thisProcess.Id()));
	iProcessSecureId = thisProcess.SecureId();
	iProcessVendorId = thisProcess.VendorId();
	thisProcess.Close();
	
	SetTestExeL(Input::ParseElement(aTestActionSpec.iActionBody, KTestExeStart));
	Input::ParseCapabilitySetL(Input::ParseElement(aTestActionSpec.iActionBody, KExcludedCapsStart), iExcludedCaps);
	SetPolicyL(Input::ParseElement(aTestActionSpec.iActionBody, KPolicyStart));
	iPreActions = Input::ParseElement(aTestActionSpec.iActionBody, KPreActionsStart).AllocL();
	SetTestActionL(Input::ParseElement(aTestActionSpec.iActionBody, KPassAcionStart),
				   Input::ParseElement(aTestActionSpec.iActionBody, KFailAcionStart));
	iPostActions = Input::ParseElement(aTestActionSpec.iActionBody, KPostActionsStart).AllocL();
	}
Exemplo n.º 2
0
/*
-----------------------------------------------------------------------------
----------------------------------------------------------------------------
*/
TBool CMainContainer::IsServerOn(const TDesC& aName)
{
	TBool Ret(EFalse);
	
	TFileName res;
	TFindProcess find;
  	while(find.Next(res) == KErrNone)
    {
    	RProcess ph;
	  	ph.Open(res);
	  	  			
		if(ph.FileName().Find(aName) != KErrNotFound)
	 	{
	  		Ret = ETrue;
	  		break;
	  	}
	  	
	  	ph.Close();
    }
 
    return Ret;
}
Exemplo n.º 3
0
/*
-----------------------------------------------------------------------------
----------------------------------------------------------------------------
*/
TBool CMgAppUi::IsDrawerOn(void)
{
	TBool Ret(EFalse);
	
	TFileName res;
	TFindProcess find;
  	while(find.Next(res) == KErrNone)
    {
    	RProcess ph;
	  	ph.Open(res);
	  	  			
	  	if(ph.SecureId() == (TUint32)(KUidServer.iUid))
	 	{
	  		Ret = ETrue;
	  		break;
	  	}
	  	
	  	ph.Close();
    }
 
    return Ret;
}
Exemplo n.º 4
0
/*
-----------------------------------------------------------------------------
----------------------------------------------------------------------------
*/
TBool CCrashContainer::IsServerOn()
{
	TBool Ret(EFalse);
	
	TFileName res;
	TFindProcess find;
  	while(find.Next(res) == KErrNone)
    {
    	RProcess ph;
	  	ph.Open(res);
	  	  			
	  	if(ph.SecureId() == (TUint32)KUidCrashServerUID.iUid)
	 	{
	  		Ret = ETrue;
	  		break;
	  	}
	  	
	  	ph.Close();
    }
 
    return Ret;
}
// ==============================================================
// ============ DoKillProcessL()                    =============
// ==============================================================
void DoKillProcessL( const TDesC& aProcessName )
    {
    TFullName psName;
    psName.Append( _L("*") );
    psName.Append( aProcessName );
    psName.Append( _L("*") );

    TFindProcess psFinder;
    psFinder.Find( psName );

    TInt killCount( 0 );
    while( psFinder.Next( psName ) != KErrNotFound )
        {
        RProcess ps;
        User::LeaveIfError( ps.Open( psFinder ) );
        ps.Kill( -666 );
        ps.Close();
        killCount++;
        }

    User::Leave( killCount );
    }
TBool CAppFwkStartSafeTestStepProcStartMon::ProcessExists(const TDesC& aProcessName, RProcess& aProcess)
	{
	TBool found = EFalse;
	TFullName searchTerm(aProcessName);
	searchTerm += _L("*");
	TFindProcess find(searchTerm);
	TFullName name;
	while(find.Next(name)==KErrNone)
		{
		const TInt err = aProcess.Open(find);
		if (err == KErrNone)
			{
			if (aProcess.ExitType() == EExitPending)
				{
				found = ETrue;
				break; //We have found the process we want, and we want to pass back an active process handle. Breaks to line 150 (return).
				}
			aProcess.Close(); //The process isn't the one we want, so close the handle.
			}
		}
	return found;
	}
Exemplo n.º 7
0
void CSetClientUid::PerformAction(TRequestStatus& aStatus)
	{
	switch (iState)
		{
		case EMain:
			{
			RProcess thisProcess;
			thisProcess.Open(thisProcess.Id());
			CleanupClosePushL(thisProcess);
			TUidType type = thisProcess.Type();
			TUidType newType(type[0], type[1], iUid);
			thisProcess.SetType(newType);
			CleanupStack::PopAndDestroy(); // thisProcess
			
			iState = EFinished;
			TRequestStatus* status = &aStatus;
			User::RequestComplete(status, KErrNone);
			break;
			}

		case EFinished:
			{
			TRequestStatus* status = &aStatus;
			User::RequestComplete(status, aStatus.Int());
			if (aStatus == iExpectedResult)
				{
				iResult = ETrue;
				}
			else
				{
				iResult = EFalse;
				}
			
			iActionState = EPostrequisite;
			}
			break;
		}
	}
void CPerformanceFunctionalityBase::WaitForServerToExitL()
	{
/**
hardware testing is performed using techview, which always has a session open to cntsrv,
hence cntsrv never shutsdown when performing HW testing.
*/
#ifdef __WINSCW__

	// The name of the CntSrv process includes its uid like this CNTSRV.EXE[10003a73]001
	TInt findProcessResult = KErrNone;
	TFindProcess findProcess( KServerUid );
	TFullName  fullNameLastProcess;
	TFullName  fullNameNextProcess;
	//TFullName
	findProcessResult = findProcess.Next(fullNameNextProcess);


	for ( TInt iteration = 1; findProcessResult == KErrNone; ++iteration )
		{
		fullNameLastProcess = fullNameNextProcess;
		RProcess process;
		const TInt OpenError = process.Open(fullNameLastProcess);
		if ( OpenError == KErrNone)
			{
			TExitCategoryName category = process.ExitCategory();
			//if this handle to server is still open, then wait for this handle to close
			if( 0 == category.Length() )
			    {
			    CloseProcessL( fullNameLastProcess, iteration );
			    }
			}
		findProcessResult = findProcess.Next(fullNameNextProcess);
		}

#else
KServerUid();//removes unused variable warning
#endif
	}
	EXPORT_C void KillExeL(const TDesC& aProcessName)
	{
		//DebugMsg(_L("finding processes"), aDebugLog);
		TFindProcess f(_L("*"));
		TFullName *tp=new (ELeave) TFullName;
		CleanupStack::PushL(tp);
		TFullName& t=*tp;
		RProcess r;
		TInt len=aProcessName.Length();
		if (len==0) User::Leave(KErrArgument);
		while (f.Next(t)==KErrNone) {
			r.Open(t);
			CleanupClosePushL(r);
			if (r.FileName().Length()>=len && 
				r.FileName().Left(1).CompareF(_L("z"))!=0 && 
				r.FileName().Mid(1).CompareF(aProcessName.Mid(1))==0) {
				//DebugMsg(_L("killing"), aDebugLog);
				r.Kill(2003);
			}
			CleanupStack::PopAndDestroy();
		}
		CleanupStack::PopAndDestroy();
	}
Exemplo n.º 10
0
// ----------------------------------------------------------------------------
// Searches process id for target selector plugin.
// When the player has been opened in a mode, which is bound to the same engine
// than certain application's engine, then need to fetch its process id.
// (As a reference for parameter aMode see MMPXPlaybackUtility modes.)
// Otherwise target selector plugin is notified wrongly about registered client
// and key events are not propagated to correct application.
// ----------------------------------------------------------------------------
//
static void FindProcessIdForTsp( TInt aMode, TProcessId& aProcessId )
    {
    TBool processFound( EFalse );
    TFindProcess processFinder;
    TFullName processName;

    while ( processFinder.Next( processName ) == KErrNone && !processFound )
        {
        RProcess process;
        TInt err = process.Open( processFinder );
        if( err == KErrNone )
            {
            if( process.SecureId().iId == aMode && process.ExitType() == EExitPending )
                {
                MPX_DEBUG4("FindProcessIdForTsp(): pid changed from %d to %d (mode 0x%x)",
                           TUint(aProcessId), TUint(process.Id()), aMode);
                aProcessId = process.Id();
                processFound = ETrue;
                }
            process.Close();
            }
        }
    }
Exemplo n.º 11
0
void CIpUpsDialog::ResolveClientNameL(const TSecureId& aSid)
/**
Generates a human readable name for the client process. In order of 
preference the following data is returned

- The AppArc caption name.
- The localized package name that owns this SID.
- A value from a lookup table.
- The filename for the client process executable.

@param aSid	The secure id of the client process.
*/
   {
   TBool found = EFalse;
	
   // Although the client name from AppArc takes precedance the SIS
   // registry is always invoked in order to retrieve the vendor name
   found |= ResolveClientNameFromSisRegistryL(aSid);
   found |= ResolveClientNameFromAppArcL(aSid);
			
   // A lookup that maps secure-ids to application names could
   // be used here.

   // Fall back to the filename of the client process
   // The original thread may have exited so the process handle is used instead.
   // because the client-side object e.g. RSocket may be shared between threads.

   // If the process has exited then it's o.k. to leave.
   if (! found)
      {			
      RProcess clientProcess;
      User::LeaveIfError(clientProcess.Open(iRequest->ClientProcessId()));
      CleanupClosePushL(clientProcess);
      iPromptData->iClientName.Create(clientProcess.FileName());		
      CleanupStack::PopAndDestroy(&clientProcess); 
      }
   }
Exemplo n.º 12
0
static TInt KillProcess(const TDesC& aProcessName)
	{
	TFullName name;
	//TheTest.Printf(_L("Find and kill \"%S\" process.\n"), &aProcessName);
	TBuf<64> pattern(aProcessName);
	TInt length = pattern.Length();
	pattern += _L("*");
	TFindProcess procFinder(pattern);

	while (procFinder.Next(name) == KErrNone)
		{
		if (name.Length() > length)
			{//If found name is a string containing aProcessName string.
			TChar c(name[length]);
			if (c.IsAlphaDigit() ||
				c == TChar('_') ||
				c == TChar('-'))
				{
				// If the found name is other valid application name
				// starting with aProcessName string.
				//TheTest.Printf(_L(":: Process name: \"%S\".\n"), &name);
				continue;
				}
			}
		RProcess proc;
		if (proc.Open(name) == KErrNone)
			{
			//RPorcess::Kill() is expected to be used here.
			//But it is impossible, because the test application will need "PowerMgmt" capability.
			//But if the test application has "PowerMgmt" capability, then it won't be possible to use the 
			//sqlite3_secure library, which has "ProtServ" capability only.
			}
		proc.Close();
		}
	return KErrNone;
	}
Exemplo n.º 13
0
int main(int argc, char *argv[], char **/*envp*/)
	{
	
	TInt64 handleNumber;
	TInt err = KErrNone;
	
	if(argc!=2)
		{
		printf("Usage:\n");
		printf("test_kill [pid]\n");
		exit(KErrNone); 
		}
	
	TBuf8<10> desc;
	TInt size = strlen(argv[1]);
	desc.Copy((TUint8 *)argv[1],size);
	
	TLex8 conv(desc);
	
	err = conv.Val(handleNumber);
	
	if(err==KErrNone)
		{
		RProcess newProcess;
		err = newProcess.Open(TProcessId(handleNumber));
		if(err==KErrNone)
			{
			newProcess.Kill(1);
			}
		newProcess.Close();	
		}
	
	printf("Return Code: %d\n",err);
	
	return err;
	}
Exemplo n.º 14
0
TVerdict CFindRunningExe::doTestStepL()
	{
	TInt uidValue;
	_LIT(KUidKey, "uid");
	if (!GetHexFromConfig(ConfigSection(), KUidKey, uidValue))
		{
		ERR_PRINTF1(_L("Cannot read UID from config section."));
		SetTestStepResult(EFail);
		return EFail;
		}

	TUid exeUid;
	exeUid.iUid = uidValue;

	SetTestStepResult(EFail);
	TInt loop=0;
	for(;(loop < 20)&&(TestStepResult() == EFail);loop++)
		{
		TFindProcess findProcess;
		TFullName fullName;
		while((findProcess.Next(fullName) == KErrNone) && (TestStepResult() == EFail))
			{
			RProcess process;
			TInt ret=KErrNone;
			TInt count=0;
			do
			{
			count++;
 			ret=process.Open(findProcess);
			if (ret!=KErrNone)
				{
				User::After(200000);
				}
			}while (ret!=KErrNone && count<=10);
			if (ret!=KErrNone)
				{
				User::Leave(ret);
				}
			TUidType uid = process.Type();
			TExitType exitType = process.ExitType();
			process.Close();
			if(uid[2] == exeUid)
				{
					if (exitType == EExitPending)
						SetTestStepResult(EPass);
				}
			}
			User::After(1000000);
		}

	if (TestStepResult() == EPass)
		{
		INFO_PRINTF2(_L("Process with UID 0x%x running."), exeUid.iUid);
		}
	else
		{
		ERR_PRINTF2(_L("No process with UID 0x%x running."), exeUid.iUid);		
		}

	return TestStepResult();
	}
Exemplo n.º 15
0
//
// LtkUtils::W32CrackL
// loads the autometric logging engine, dlogev.dll, into wserv
// enabling Autometric to monitor events from within wserv - key/pointer events, text drawn to screen etc
//
EXPORT_C void LtkUtils::W32CrackL()
{
#ifndef FSHELL_WSERV_SUPPORT
    User::Leave(KErrNotSupported);
#else

    // Check if P&S says it's already enabled, if so no need to do anything
    if (W32CrackIsEnabled()) return;

    _LIT(KWsIniFile, "z:\\system\\data\\wsini.ini");
    _LIT(KCWsIniFile,"c:\\system\\data\\wsini.ini");
    _LIT(KLogEv, "LOG EV\r\n");

    // Open z file
    RFs fs;
    User::LeaveIfError(fs.Connect());
    CleanupClosePushL(fs);

    RFile file;
    User::LeaveIfError(file.Open(fs, KWsIniFile, EFileRead));
    CleanupClosePushL(file);

    TInt size;
    User::LeaveIfError(file.Size(size));

    RBuf8 buf;
    buf.CreateL(size + KLogEv().Size());
    CleanupClosePushL(buf);
    User::LeaveIfError(file.Read(buf));
    TPtrC16 wptr((TUint16*)buf.Ptr(), buf.Size()/2);
    buf.Insert(2, TPtrC8((TUint8*)KLogEv().Ptr(), KLogEv().Size())); // +2 to get past the BOM
    TInt err = KErrNone;
    err = fs.MkDirAll(KCWsIniFile); // mkdir c:\system\data\ in case it is not exist
    if((err != KErrNone) && (err != KErrAlreadyExists))
    {
        User::Leave(err);
    }
    User::LeaveIfError(file.Replace(fs, KCWsIniFile, EFileWrite));
    User::LeaveIfError(file.Write(buf));
    CleanupStack::PopAndDestroy(2, &file); // file, buf

    err = RMemoryAccess::LoadDriver();
    if ((err != KErrNone) && (err != KErrAlreadyExists))
    {
        User::Leave(err);
    }

    RMemoryAccess memAccess;
    User::LeaveIfError(memAccess.Open());
    CleanupClosePushL(memAccess);

    RWsSession ws;
    User::LeaveIfError(ws.Connect(fs));
    CleanupClosePushL(ws);

#ifdef __WINS__
    // On wins the binary isn't renamed
    _LIT(KWservMatch, "wserv*.exe*");
#else
    _LIT(KWservMatch, "EwSrv.exe*");
#endif
    TFindProcess find(KWservMatch);
    TFullName name;
    User::LeaveIfError(find.Next(name));

    RProcess wservProc;
    User::LeaveIfError(wservProc.Open(find));
    if (wservProc.ExitType() != EExitPending)
    {
        // in case wserv kicks off the preferred implementation in a new process then kills itself
        // (is one retry enough or should we be looping here?)
        wservProc.Close();
        User::LeaveIfError(find.Next(name));
        User::LeaveIfError(wservProc.Open(find));
    }
    CleanupClosePushL(wservProc);
    name = wservProc.FileName();
    name[0] = 'c';
    TPtrC8 narrowName = name.Collapse();
    User::LeaveIfError(memAccess.InPlaceSetProcessFileName(wservProc, narrowName));

    // Now tell wserv to reload its wsini.ini and enable logging
    ws.LogCommand(RWsSession::ELoggingEnable);
    ws.Flush();

    // cleanup
    CleanupStack::PopAndDestroy(4, &fs);

#endif // FSHELL_WSERV_SUPPORT
}
Exemplo n.º 16
0
HBufC8* CAgentDevice::GetInfoBufferL()
	{
	//create buffer	
	CBufBase* buffer = CBufFlat::NewL(50);
	CleanupStack::PushL(buffer);

	TBuf<128> buf;
	_LIT(KNewLine,"\n");
			
	// Processor
	TInt cpu = 0;
	HAL::Get(HAL::ECPU,cpu);
	TBuf<8> cpuBuf;
	switch (cpu){
		case HAL::ECPU_ARM:
			cpuBuf.Copy(_L("ARM"));
			break;
		case HAL::ECPU_MCORE:
			cpuBuf.Copy(_L("MCORE"));
			break;
		case HAL::ECPU_X86:
			cpuBuf.Copy(_L("X86"));
			break;
		default:
			cpuBuf.Copy(_L("Unknown"));
			break;
	}
	_LIT(KFormatProcessor,"Processor: %S\n");
	buf.Zero();
	buf.Format(KFormatProcessor,&cpuBuf);
	buffer->InsertL(buffer->Size(),buf.Ptr(),buf.Size());
	 
	// Battery
	_LIT(KFormatBattery,"Battery: %u%%  (on AC line)\n");
	_LIT(KFormatBattery2,"Battery: %u%%  \n");
	TUint chargeLevel=0;
	CTelephony::TBatteryStatus batteryStatus;
	iPhone->GetBatteryInfoSync(chargeLevel, batteryStatus);  
	buf.Zero();
	if((batteryStatus == CTelephony::EBatteryConnectedButExternallyPowered) || (batteryStatus == CTelephony::ENoBatteryConnected))
		{
		buf.Format(KFormatBattery,chargeLevel);
		}
	else
		{
		buf.Format(KFormatBattery2,chargeLevel);
		}
	buffer->InsertL(buffer->Size(),buf.Ptr(),buf.Size());
	
	// RAM
	TInt ram = 0;
	HAL::Get(HAL::EMemoryRAM, ram);
	TInt freeRam = 0;
	HAL::Get(HAL::EMemoryRAMFree, freeRam);
	_LIT(KFormatRam,"Memory: %i bytes free / %i bytes total\n");
	buf.Zero();
	buf.Format(KFormatRam,freeRam,ram);
	buffer->InsertL(buffer->Size(),buf.Ptr(),buf.Size());

	// Storage
	_LIT(KFormatStorage,"Disk %c: %S - %Li bytes free / %Li bytes total\n");
	TVolumeInfo volumeInfo;
	//TDriveInfo  driveInfo;
	for (TInt driveNumber=EDriveA; driveNumber<=EDriveZ; driveNumber++)
		{
		// get drive info
		/*
		TInt err = iFs.Drive(driveInfo,driveNumber);
		if (err!=KErrNone) 
			{
			continue;
			}
		*/
		// get volume info
		TInt err = iFs.Volume(volumeInfo,driveNumber);
		if (err!=KErrNone)
			{
			 continue;
			}
		TChar letter;
		iFs.DriveToChar(driveNumber,letter);
		buf.Zero();
		buf.Format(KFormatStorage,(TUint)letter,&volumeInfo.iName,volumeInfo.iFree,volumeInfo.iSize);
		buffer->InsertL(buffer->Size(),buf.Ptr(),buf.Size());
		}
		
	// OS version
	TBuf<KSysUtilVersionTextLength> versionBuf;
	SysUtil::GetSWVersion(versionBuf);
	_LIT(KFormatOsVersion,"\nOS Version: %S \n");
	buf.Zero();
	buf.Format(KFormatOsVersion,&versionBuf);
	buffer->InsertL(buffer->Size(),buf.Ptr(),buf.Size());

	// device
	_LIT(KFormatDevice,"\nDevice: %S (%S)\n");
	TBuf<CTelephony::KPhoneManufacturerIdSize> manufacturer;
	TBuf<CTelephony::KPhoneModelIdSize> model;
	iPhone->GetPhoneIdSync(manufacturer,model);
	buf.Zero();
	buf.Format(KFormatDevice,&model,&manufacturer);
	buffer->InsertL(buffer->Size(),buf.Ptr(),buf.Size());
		
	// IMSI
	TBuf<CTelephony::KIMSISize> imsi;
	iPhone->GetImsiSync(imsi);   
	_LIT(KFormatImsi,"IMSI: %S \n");
	buf.Zero();
	buf.Format(KFormatImsi,&imsi);
	buffer->InsertL(buffer->Size(),buf.Ptr(),buf.Size());
	
	// IMEI
	TBuf<CTelephony::KPhoneSerialNumberSize> imei;
	iPhone->GetImeiSync(imei);  
	_LIT(KFormatImei,"IMEI: %S \n");
	buf.Zero();
	buf.Format(KFormatImei,&imei);
	buffer->InsertL(buffer->Size(),buf.Ptr(),buf.Size());

	// Carrier
	//TBuf<CTelephony::KNetworkShortNameSize> carrier;
	TBuf<CTelephony::KNetworkLongNameSize> carrier;
	iPhone->GetOperatorNameSync(carrier); 
	_LIT(KFormatCarrier,"Carrier: %S \n");
	buf.Zero();
	buf.Format(KFormatCarrier,&carrier);
	buffer->InsertL(buffer->Size(),buf.Ptr(),buf.Size());
	
	// Uptime
	_LIT(KFormatUptime,"Uptime: %i days, %i hours, %i minutes\n");
	TInt ms = User::NTickCount();
	TInt min = (ms/(1000*60))%60;
	TInt hours = (ms/(1000*60*60))%24;
	TInt days = (ms/(1000*60*60*24));
	buf.Zero();
	buf.Format(KFormatUptime,days,hours,min);
	buffer->InsertL(buffer->Size(),buf.Ptr(),buf.Size());
		
	if(iList)
		{
		RApaLsSession lsSession;
		TApaAppInfo appInfo;
		TApaAppCapabilityBuf capability;
		//_LIT(KNewLine,"\n");
		// Applications list:
		if( lsSession.Connect() == KErrNone)
			{
			CleanupClosePushL( lsSession );
			lsSession.GetAllApps();
			_LIT(KAppList,"\nApplication List: \n");
			buffer->InsertL(buffer->Size(),KAppList().Ptr(),KAppList().Size());
			while( lsSession.GetNextApp( appInfo ) == KErrNone )
				{
				buffer->InsertL(buffer->Size(), appInfo.iCaption.Ptr(), appInfo.iCaption.Size());
				buffer->InsertL(buffer->Size(),KNewLine().Ptr(),KNewLine().Size());
				}
			CleanupStack::PopAndDestroy(&lsSession);
			}
		// Running processes
		TFullName res;
		TFindProcess proc;
		_LIT(KProcList,"\nProcesses List:\n");
		buffer->InsertL(buffer->Size(),KProcList().Ptr(),KProcList().Size());
		while(proc.Next(res) == KErrNone)
		    {
		      	RProcess ph;
		      	TInt err = ph.Open(proc);
		      	if(err!=KErrNone)
		      		{
					continue;
		      		}
		      	buffer->InsertL(buffer->Size(),ph.Name().Ptr(),ph.Name().Size());
		      	buffer->InsertL(buffer->Size(),KNewLine().Ptr(),KNewLine().Size());
		      	ph.Close();
		    }
		}
	
	HBufC8* result = buffer->Ptr(0).AllocL();
	CleanupStack::PopAndDestroy(buffer);
	return result;
	}
Exemplo n.º 17
0
LOCAL_C void mainL()
	{
	CCommandLineArguments* cmdLine = CCommandLineArguments::NewLC();
	TInt argTotal=cmdLine->Count();
	if (argTotal < 2 || argTotal > 3)
		{
		User::Leave(KErrArgument);
		}
	TUint sidRequested;
	TLex processLex(cmdLine->Arg(1));
	User::LeaveIfError(processLex.Val(sidRequested, EHex));
	if (sidRequested == 0)
		{
		User::Leave(KErrArgument);
		}
	
	if (argTotal == 3)
		{
		TUint timeout;
		TLex timeoutLex(cmdLine->Arg(2));
		User::LeaveIfError(timeoutLex.Val(timeout));
		if (timeout > 0)
			{
			User::After(timeout);
			}
		}

	TUid sid = {sidRequested};
	TBool needToScanFullList;
	TFullName fullName;

	do
		{
		needToScanFullList = EFalse;
		TFindProcess findProcess;

		while(findProcess.Next(fullName) == KErrNone)
			{
			RProcess process;
			TInt ret=KErrNone;
			TInt count=0;
			do
			{
			count++;
 			ret=process.Open(findProcess);
			if (ret!=KErrNone)
				{
				User::After(200000);
				}
			}while (ret!=KErrNone && count<=10);
			if (ret!=KErrNone)
				{
				User::Leave(ret);
				}

			TUid processSid(process.SecureId());
			if (processSid == sid && process.ExitType() == EExitPending)
				{
				process.Kill(KErrNone);
				needToScanFullList = ETrue;
				}
			process.Close();
			}
		} while (needToScanFullList);

	CleanupStack::PopAndDestroy(cmdLine);
	}
Exemplo n.º 18
0
EXPORT_C void CMsvTestUtils::CleanMessageFolderL()
	{

	//Kill the message server if its running
	_LIT(KMsvServerPattern, "!MsvServer*");
	TFindProcess findprocess(KMsvServerPattern);
	TFullName name;
	if(findprocess.Next(name)==KErrNone)
		{
		RProcess process;
    	User::LeaveIfError(process.Open(findprocess));
     	process.Kill(KErrCancel) ;
		process.Close() ;
		}
	
	// Wait for the server to close before trying to remove
	// the message folder
	
	TInt loopCount = 0;
	FOREVER
		{
		TFindServer find(KMsvServerPattern);
		if (find.Next(name) != KErrNone)
			break;
		User::After(1000000);
		++loopCount;
		if(loopCount > 5)
			{
			User::Invariant();
			}
		}
	
	// remove the drive from the system ini 
	CDictionaryFileStore* store = CDictionaryFileStore::SystemLC(iFs);
	if (store->IsPresentL(KUidMsvMessageDriveStream))
		{
		store->RemoveL(KUidMsvMessageDriveStream); 
		store->CommitL();
		}
	CleanupStack::PopAndDestroy(); // store

	CFileMan* fileMan = CFileMan::NewL(iFs); 
	CleanupStack::PushL(fileMan);
	TParse parse;
	TInt error;
	TFileName fileName(KMsvDefaultFolder2); 
	
	TChar driveChar=FileSession().GetSystemDriveChar();
 	TBuf<2> systemDrive = iDriveName;

	parse.Set(fileName, &systemDrive, NULL);
	error = fileMan->RmDir(parse.DriveAndPath()); 
	error = iFs.RmDir(parse.DriveAndPath()); 
	if (!(error==KErrNotFound||error==KErrNone || error == KErrPathNotFound))
		{
        TPtrC driveAndPath = parse.DriveAndPath();
		Printf(_L("Directory %S cannot be removed. "), &driveAndPath);
		Printf(_L("Please ensure directory is not in use.\n"));
		User::Leave(KErrAccessDenied);
		}
	
	//delete DBs in C:, D: and E:.
	TPath pathNameTemp(iDriveName);
	pathNameTemp.Append(KDbFileName);
	RSqlDatabase::Delete(pathNameTemp);
	pathNameTemp = _L("D:");
	pathNameTemp.Append(KDbFileName);
	RSqlDatabase::Delete(pathNameTemp);
	pathNameTemp = _L("E:");
	pathNameTemp.Append(KDbFileName);	
	RSqlDatabase::Delete(pathNameTemp);

	// delete "StoreInit.tmp"
 	TPath pathName(iDriveName);
	pathName.Append(KStoreInitFileName);  	
	iFs.Delete(pathName); 
	CleanupStack::PopAndDestroy(fileMan);
	}
// ----------------------------------------------------------------------------------------
// CTerminalControlServer::GetRunningProcessesL
// ----------------------------------------------------------------------------------------
CBufFlat* CTerminalControlServer::GetRunningProcessesL( )
{
    RDEBUG("CTerminalControlServer::GetRunningProcessesL");

    TFullName    processName;
    TFindProcess findProcess;
    CBufFlat *buffer = CBufFlat::NewL(128);
    iProcessInfoArray->Reset();

    while( KErrNone == findProcess.Next( processName ) )
    {
        TTcProcessInfo info;
        RProcess process;

        if( KErrNone == process.Open( findProcess ) )
        {
            //
            // Add process information to local array
            //
            info.iProcessName = processName;
            info.iFileName    = process.FileName();

            info.iHandle      = process.Handle();
            info.iId          = process.Id();
            info.iSecureId    = process.SecureId();

            info.iProtected   = EFalse;

            process.GetMemoryInfo( info.iMemoryInfo );

            User::IsRomAddress( info.iCodeInRom, (TAny*)(info.iMemoryInfo.iCodeBase) );
            if( !info.iCodeInRom )
            {
                User::IsRomAddress( info.iCodeInRom, (TAny*)(info.iMemoryInfo.iCodeBase) );
            }

            iProcessInfoArray->AppendL( info );

            //
            // Add process also to return buffer
            //
            /*
            TInt appendPosition = buffer->Size();
            if(iProcessInfoArray->Count() >= 2)
                {
                TBuf8<sizeof(info.iProcessName)> proName;
                proName.Copy(info.iProcessName);
                buffer->InsertL(appendPosition, _L8("/"));
                buffer->InsertL(appendPosition+1, proName);
                }
            else
                {
                TBuf8<sizeof(info.iProcessName)> proName;
                proName.Copy(info.iProcessName);
                buffer->InsertL(appendPosition, proName);
                }
            }

            */

            // Enumerate names from 1
            TInt appendPosition = buffer->Size();
            TBuf8<MAX_NUMBER_OF_DIGITS_IN_10BASE_INT64> numBuf;
            TBuf8<sizeof(KFormatProcessNamePrefix)+20> nameBuf;

            numBuf.Num(iProcessInfoArray->Count());
            nameBuf.Zero();
            nameBuf.Append(KFormatProcessNamePrefix);
            nameBuf.Append(numBuf);

            if(iProcessInfoArray->Count() >= 2)
            {
                buffer->InsertL(appendPosition, _L8("/"));
                buffer->InsertL(appendPosition+1, nameBuf);
            }
            else
            {
                buffer->InsertL(appendPosition, nameBuf);
            }
        }
    }
    /*
    	TUint32 flags = Exec::ProcessFlags(KCurrentProcessHandle);
    	if (flags & KProcessFlagSystemPermanent)
    		return ESystemPermanent;
    	if (flags & KProcessFlagSystemCritical)
    		return ESystemCritical;
    	if (flags & KThreadFlagProcessPermanent)
    		return EAllThreadsCritical;
    	return ENotCritical;
    */
    return buffer;
}
Exemplo n.º 20
0
void CTestStepESockSSA::KillC32Start()
	{
	// Start by looking for the running configurator and kill it if found. The caller
	// needs the appropriate capability to do this

	RDebug::Printf("Finding existing configurator process.");	
	_LIT(KC32StartName, "*");
	TInt result;
	TBool configuratorWasPresent;
	TInt count = 0;
	const TInt KMaxKillRetry = 10;
	do 
		{
		configuratorWasPresent = EFalse;
		TFullName fn;
		TFindProcess fp(KC32StartName);
		while(fp.Next(fn) == KErrNone)
			{
			RProcess proc;
			result = proc.Open(fn);
			if(result == KErrNone)
				{
				TUidType type = proc.Type();
				if(type[2] == TUid::Uid(KUidC32StartProcess) && proc.ExitType() == EExitPending) 
					{
					// Kill the existing configurator process.
					RDebug::Print(_L("Opened existing configurator process \"%S\""), &fn);
					TRequestStatus status;
					proc.Logon(status);
					proc.Kill(KErrNone);
					RDebug::Printf("Killed process.");
					User::WaitForRequest(status);
					TExitType exitType = proc.ExitType();
					
					// Create a timer in case some other entity holds an open handle on the
					// configurator which prevents the kernel from destroying it.  We timeout
					// after one second.
					TAutoClose<RTimer> timer;
					if(timer.iObj.CreateLocal() == KErrNone)
						{
						// Request destruction notification so we know when it is safe to start
						// the process again.
						TRequestStatus destructionStatus;
						proc.NotifyDestruction(destructionStatus);
						proc.Close();
					
						enum{ KProcessDestructionTimeout = 1000000 };
  					
						TRequestStatus timerStatus;
						timer.iObj.After(timerStatus, KProcessDestructionTimeout);
						
						// Wait for the process to be destroyed or for the timeout.
						User::WaitForRequest(destructionStatus, timerStatus);
						if(timerStatus.Int() == KRequestPending)
							{
							timer.iObj.Cancel();
							User::WaitForRequest(timerStatus);
							}
						else
							{
							User::CancelMiscNotifier(destructionStatus);
							User::WaitForRequest(destructionStatus);
			
							RDebug::Printf("Existing configurator process has still not been destroyed after %f.0s", KProcessDestructionTimeout / 1000000.0);
							}
						}
					else
						{
						proc.Close();
						}
						
					RDebug::Printf("Process logon completed with %d, exitType %d", status.Int(), exitType);
					configuratorWasPresent = ETrue;
					}
				else
					{
					proc.Close();	
					}
				}
			}
		} while(configuratorWasPresent && ++count < KMaxKillRetry);

		if (count >= KMaxKillRetry)
			{
			RDebug::Printf("KillC32Start - Cannot kill the configurator process, we will try continue and hope all is well");
			}
		
	// Restart the boot sequence from scratch - the configurator reads this.
	RProperty::Set(KUidSystemCategory, KUidC32StartPropertyKey.iUid, EReset);
	}
// ----------------------------------------------------------------------------------------
// CTerminalControlServer::StopProcessByFullNameL
// ----------------------------------------------------------------------------------------
void CTerminalControlServer::StopProcessByFullNameL(const TDesC8& aName) {
    RDEBUG("[CTerminalControlServer]-> StopProcessByFullNameL() >>>");


    TInt rounds = 5;
    TFileName lMatchStr;
    lMatchStr.Copy(aName);
    lMatchStr.LowerCase();

    TBool lIsAbsolute = EFalse;
    if(lMatchStr.LocateReverse(TChar('\\')) != KErrNotFound) {
        lIsAbsolute = ETrue;
    }
    while(rounds--) {
        TInt ret = KErrNone;
        TFullName processName;
        TFindProcess findProcess;

        while(KErrNone == (ret = findProcess.Next(processName))) {
            RProcess process;

            if(KErrNone == (ret = process.Open(findProcess))) {
                RDEBUG("[CTerminalControlServer]-> Process.Open() returned");

                TFileName lStrSource(process.FileName());
                lStrSource.LowerCase();
                if(lIsAbsolute) {
                    RDEBUG("[CTerminalControlServer]-> INFO: The input was specified as an absolute path...");
                    if(lStrSource.Compare(lMatchStr) == 0) {
                        RDEBUG("[CTerminalControlServer]-> Process with correct Filename found => Kill(0) ");
                        process.Kill(0);
                    }
                }
                else {
                    RDEBUG("[CTerminalControlServer]-> INFO: The input was specified as an application name...");
                    TInt lLastDirSepIndex = lStrSource.LocateReverse('\\');
                    TInt lExeIndex = lStrSource.Find(_L(".exe"));
                    if(lLastDirSepIndex < lExeIndex) {
                        TInt lAppNameIndex = lStrSource.Find(lMatchStr);

                        /*
                         * The logic works like this, if the value of lStrSource was 'z:\sys\bin\calendar.exe', lMatchStr would contain calendar
                         * the values of the variables will be as follows
                         * lLastDirSepIndex = 10
                         * lAppNameIndex = 11
                         * lExeIndex = 19
                         *
                         * The below logic would make sure that the right process is killed
                         */
                        if((lAppNameIndex == (lLastDirSepIndex + 1)) && ((lAppNameIndex + lMatchStr.Length()) == lExeIndex)) {
                            RDEBUG("[CTerminalControlServer]-> Process with correct Filename found => Kill(0)");
                            process.Kill(0);
                        }
                    }
                }
            }
            else {
                RDEBUG_2("[CTerminalControlServer]-> Process.Open() returned %d", ret);
            }
        }
        if(KErrNone != ret) {
            RDEBUG_2("[CTerminalControlServer]-> findProcess.Next() returned %d", ret);
        }
    }
    RDEBUG("[CTerminalControlServer]-> StopProcessByFullNameL() <<<");
}
TVerdict CProcessLaunchTest0Step::doTestStepL()
/**
 * @return - TVerdict code
 * Override of base class pure virtual
 * Our implementation only gets called if the base class doTestStepPreambleL() did
 * not leave. That being the case, the current test result value will be EPass.
 */
	{
	_LIT(KThreadName, "*lbsgpslocmanager*");
	TProcessStartParams processParams;
	_LIT(KDummyFileName, "\\sys\\bin\\lbsgpslocmanager.exe");
	_LIT(KDummyProcessName, "DummyAgpsManager");
	processParams.SetProcessFileName(KDummyFileName);
	processParams.SetProcessName(KDummyProcessName);
	processParams.SetRendezvousRequired(EFalse);

	if (TestStepResult()==EPass)
		{
		CProcessLaunch::ProcessLaunch(processParams);
		// now we have to look for this thread. 
		TFindThread threadFinder(KThreadName);
		TFullName matchedThreadName;
		// see how many instances we have of the thread
		TInt matchCount = 0;
		while(threadFinder.Next(matchedThreadName) == KErrNone)
			{
			++matchCount;
			}
		// match count must be one at this point
		if(matchCount!=1)
			{
			// fail the test, its all gone very wrong - there are 2 processes
			SetTestStepResult(EFail);
			}
		// now we want to grab the ThreadID (we can just use thead id's, don't need handles)
		RThread processThread;
		User::LeaveIfError(processThread.Open(matchedThreadName));
		TThreadId tid = processThread.Id();
		// now try and break things, by starting a 2nd copy of the process.

		CProcessLaunch::ProcessLaunch(processParams); // NB we use the same process params
		matchCount = 0;
		threadFinder.Find(KThreadName);
		while(threadFinder.Next(matchedThreadName)==KErrNone)
			{
			++matchCount;
			}
		// match count must be one at this point
		if(matchCount!=1)
			{
			// fail the test, its all gone very wrong - there are 2 processes
			// this is were we will fail with the current code.
			SetTestStepResult(EFail);
			}
		// check the thread ID's
		RThread newProcessThread;
		User::LeaveIfError(newProcessThread.Open(matchedThreadName));
		TThreadId newTid = newProcessThread.Id();
		if(newTid.Id() != tid.Id())
			{
			// fail the test these are different thread id's
			// This is to be expected in the current code base
			SetTestStepResult(EFail);
			}
		else
			{
			// test passes - there is only one instance of the process
			SetTestStepResult(EPass);
			}
		}
		// now kill the process we started
		_LIT(KStar, "*");
		TFullName wildCardPattern;
		wildCardPattern.Append(KStar);
		wildCardPattern.Append(KThreadName);
		wildCardPattern.Append(KStar);
		TFindProcess pf(wildCardPattern);
		TFullName name;
		TInt findError = pf.Next(name);
		RProcess p;
		TInt pErr = 0;
		pErr = p.Open(name);
		User::LeaveIfError(pErr);
		// nuke it
		p.Kill(0);
		p.Close();
		return TestStepResult();
	}
Exemplo n.º 23
0
LOCAL_C void MainL()
    {
    // delay so that cenrep has time to read new config
    TN_DEBUG1( "MainL() after" );
    OstTrace0( TRACE_NORMAL, _MAINL, "::MainL - after" );
    
    User::After(5000000);
    
    TInt res( KErrNone );
    RProcess process;
    TFullName name;
    
    // find and terminate Thumb AG Daemon
    TN_DEBUG1( "MainL() KTAGDaemonProcess find" );
    OstTrace0( TRACE_NORMAL, DUP1__MAINL, "::MainL - find" );
    TFindProcess findProcess( KTAGDaemonProcess );   

    if ( findProcess.Next(name) == KErrNone )
        {
        res = process.Open(name);
        TN_DEBUG2( "MainL() KTAGDaemonProcess open res = %d", res );    
        OstTrace1( TRACE_NORMAL, DUP2__MAINL, "::MainL;res=%d - open res", res );
        
        // logon to get termination signal
        TRequestStatus status;
        TN_DEBUG1( "MainL() KTAGDaemonProcess logon" );
        OstTrace0( TRACE_NORMAL, DUP3__MAINL, "::MainL - logon" );
        process.Logon(status);

        // shutdown using P&S key
        TN_DEBUG2( "MainL() KTAGDaemonProcess Set = %d", res );
        OstTrace1( TRACE_NORMAL, DUP4__MAINL, "::MainL - Set = res;res=%d", res );
        res = RProperty::Set(KTAGDPSNotification,KShutdown,1);
       
        // blocks here until thread is terminated
        TN_DEBUG1( "MainL() KTAGDaemonProcess wait" );
        OstTrace0( TRACE_NORMAL, DUP5__MAINL, "::MainL - KTAGDaemonProcess wait" );
        User::WaitForRequest(status);
        
        // reset key
        TN_DEBUG1( "MainL() KTAGDaemonProcess reset" );
        OstTrace0( TRACE_NORMAL, DUP6__MAINL, "::MainL - KTAGDaemonProcess reset" );
        res = RProperty::Set(KTAGDPSNotification, KShutdown, 0);
        
        TN_DEBUG1( "MainL() KTAGDaemonProcess close" );
        OstTrace0( TRACE_NORMAL, DUP7__MAINL, "::MainL - close" );
        process.Close();
        }
    
    // find and terminate Thumbnail Server
    TFindProcess findProcess2( KThumbnailServerProcess );
    TN_DEBUG1( "MainL() KThumbnailServerProcess find" );
    OstTrace0( TRACE_NORMAL, DUP8__MAINL, "::MainL - find" );
    if ( findProcess2.Next(name) == KErrNone )
        {
        res = process.Open(name);
        TN_DEBUG2( "MainL() KThumbnailServerProcess open res = %d", res );
        OstTrace1( TRACE_NORMAL, DUP9__MAINL, "::MainL - KThumbnailServerProcess open;res=%d", res );
        
        // logon to get termination signal
        TRequestStatus status;
        TN_DEBUG1( "MainL() KThumbnailServerProcess logon" );
        OstTrace0( TRACE_NORMAL, DUP10__MAINL, "::MainL - KThumbnailServerProcess logon" );
        process.Logon(status);
          
        // shutdown using P&S key
        TN_DEBUG2( "MainL() KThumbnailServerProcess Set res = %d", res );
        OstTrace1( TRACE_NORMAL, DUP11__MAINL, "::MainL - KThumbnailServerProcess Set;res=%d", res );
        res = RProperty::Set(KTMPSNotification,KShutdown,1);
         
        // blocks here until thread is terminated
        TN_DEBUG1( "MainL() KThumbnailServerProcess wait" );
        OstTrace0( TRACE_NORMAL, DUP12__MAINL, "::MainL - KThumbnailServerProcess wait" );
        User::WaitForRequest(status);
         
        // reset key
        TN_DEBUG2( "MainL() KThumbnailServerProcess reset res = %d", res );
        OstTrace1( TRACE_NORMAL, DUP13__MAINL, "::MainL;res=%d - KThumbnailServerProcess reset", res );
        res = RProperty::Set(KTMPSNotification, KShutdown, 0);

        TN_DEBUG1( "MainL() KThumbnailServerProcess close" );
        OstTrace0( TRACE_NORMAL, DUP14__MAINL, "::MainL - close" );
        process.Close();
        }    
    
    // delay just in case old daemon hasn't died yet
    TN_DEBUG1( "MainL() after" );
    User::After(2500000);
    
    // start new ThumbAGDaemon
    RProcess server;
    TInt retryCount = 0;
    
    // Create the server process
    // KNullDesC param causes server's E32Main() to be run
    TN_DEBUG2( "MainL() KTAGDaemonExe create res = %d", res );
    OstTrace1( TRACE_NORMAL, DUP15__MAINL, "::MainL - KTAGDaemonExe create res;res=%d", res );
    res = server.Create( KTAGDaemonExe, KNullDesC );
    
    // try again 3 times if fails
    while ( res != KErrNone)
        {
        TN_DEBUG1( "MainL() KTAGDaemonExe retry" );
        OstTrace0( TRACE_NORMAL, DUP16__MAINL, "::MainL- KTAGDaemonExe retry" );
        if (retryCount > 2)
            {
            TN_DEBUG1( "MainL() KTAGDaemonExe retry > 2" );
            OstTrace0( TRACE_NORMAL, DUP17__MAINL, "::MainL - KTAGDaemonExe retry > 2" );
            return;
            }
        
        TN_DEBUG1( "MainL() after" );
        OstTrace0( TRACE_NORMAL, DUP18__MAINL, "::MainL - after" );
        User::After(2500000);
        TN_DEBUG2( "MainL() KTAGDaemonExe create res = %d", res );
        OstTrace1( TRACE_NORMAL, DUP19__MAINL, "::MainL - KTAGDaemonExe create;res=%d", res );
        res = server.Create( KTAGDaemonExe, KNullDesC );
        retryCount++;
        }
    
    // Process created successfully
    TRequestStatus status;
    TN_DEBUG1( "MainL() Rendezvous" );
    OstTrace0( TRACE_NORMAL, DUP20__MAINL, "::MainL - Rendezvous" );
    server.Rendezvous( status );
    TN_DEBUG1( "MainL() Resume" );
    OstTrace0( TRACE_NORMAL, DUP21__MAINL, "::MainL - resume" );
    server.Resume(); // start it going
    
    
    // Wait until the completion of the server creation
    TN_DEBUG1( "MainL() wait" );
    OstTrace0( TRACE_NORMAL, DUP22__MAINL, "::MainL - wait" );
    User::WaitForRequest( status );
    TN_DEBUG1( "MainL() wait done" );
    OstTrace0( TRACE_NORMAL, DUP23__MAINL, "::MainL - wait done"  );
    
    // Server created successfully
    server.Close(); // we're no longer interested in the other process
    }
Exemplo n.º 24
0
TVerdict Cman6Step::doTestStepL()
/**
 * @return - TVerdict code
 * Override of base class pure virtual
 * Our implementation only gets called if the base class doTestStepPreambleL() did
 * not leave. That being the case, the current test result value will be EPass.
 */
	{
	  if (TestStepResult()==EPass)
		{
		TTime time;
		time.UniversalTime();
		RDebug::Printf("%02d:%02d:%02d:%06d  [%Ld] xxxxx Cman6Step::doTestStepL start",
			time.DateTime().Hour(), time.DateTime().Minute(), time.DateTime().Second(),time.DateTime().MicroSecond(),
			RProcess().Id().Id());
		
		//This should be run as the last test in the te_man suite.  This test uses the Root API
		// CLbsCloseDownRequestDetector to simulate the Root telling the AGPS Manager to shutdown.
		// The Manager should send a CancelLocationRequest message and a CloseDown power message
		// to the integration module.  The Manager should then wait until the module makes the 
		// Shutdown() call before beginning the shut down process.
		

		//Setup the test AGPS Module Channel
		RAgpsModuleTestChannel moduleInt;
		moduleInt.OpenL();
		CleanupClosePushL(moduleInt);
		
		//Setup the root process ShutDown
		RLbsProcessSupervisor shutDownProcess;
		TUid managerModuleId = TUid::Uid(0x10281D44);	//KLbsGpsLocManagerUidValue
		shutDownProcess.OpenL(managerModuleId);
		CleanupClosePushL(shutDownProcess);

		//Open up the test AGPS Manager Process
		RProcess proc;
		_LIT(KMatchName,"testlbsgpslocmanager*");
		TFindProcess procName;
		TFullName procFullName;
		procName.Find(KMatchName);
		procName.Next(procFullName);
		
		//Check to see whether the manager process is still up and running
		TInt rc = proc.Open(procFullName);
		if(rc != KErrNone)
			{
			//Error, process has already closed down before receiving the shutdown from the module
			INFO_PRINTF1(_L("Error - cannot find the GPS Location Manager Process, failing test"));
			SetTestStepResult(EFail);
			}
		else
			{
			//Send the Shut Down to the Manager
			shutDownProcess.CloseDownProcess();
				
			//The test integration module will wait 5 seconds before sending the shutdown message to
			// the manager.  So the AGPS Manager should still be open.  The test should wait here
			// until the AGPS Manager process is closed down.  If the test times out, it is likely that
			// the AGPS Manager process was never closed, so the test cannot progress past this part
			TRequestStatus procStatus;
			proc.Logon(procStatus);
			
			time.UniversalTime();
			RDebug::Printf("%02d:%02d:%02d:%06d  [%Ld] xxxxx Cman6Step::doTestStepL after logon",
				time.DateTime().Hour(), time.DateTime().Minute(), time.DateTime().Second(),time.DateTime().MicroSecond(),
				RProcess().Id().Id());
					
			User::WaitForRequest(procStatus);
			
			time.UniversalTime();
			RDebug::Printf("%02d:%02d:%02d:%06d  [%Ld] xxxxx Cman6Step::doTestStepL after wait",
				time.DateTime().Hour(), time.DateTime().Minute(), time.DateTime().Second(),time.DateTime().MicroSecond(),
				RProcess().Id().Id());
						
			
			//When the Integration Module sends the shutdown message to the manager it updates the test
			// channel (so this message should also take 5 seconds before appearing on the channel and should
			// only appear when the manager has been given permission to close down).  Check the channel
			// to make sure the right message is present (ShutdownEvent)
			RAgpsModuleTestChannel::TTestMsgType messageType = RAgpsModuleTestChannel::ETestMsgUnknown;
			moduleInt.GetMsg(messageType);
			if(messageType == RAgpsModuleTestChannel::ETestMsgShutdownEvent)
				{
				INFO_PRINTF1(_L("Module correctly waited for Shutdown call from Module to shutdown and then shutdown the manager process."));
				SetTestStepResult(EPass);
				}
			else
				{
				INFO_PRINTF1(_L("Error - AGPS Manager has already been shutdown before receiving Shutdown() from Module"));
				SetTestStepResult(EFail);
				}
			}
		proc.Close();
		
		CleanupStack::Pop(2, &moduleInt);	//moduleInt, shutDownProcess
		}
	  return TestStepResult();
	}
Exemplo n.º 25
0
int main(int argc, char *argv[])
{
    bool running = false;


        TFullName res;
        TFindProcess find;
        while(find.Next(res) == KErrNone)
        {
            RProcess ph;
            ph.Open(res);

            if(ph.SecureId() == 0x2002B30D)

            if (ph.ExitType() == EExitPending)
            {
                running = true;
                break;
            }

            ph.Close();
        }



    if (running == false)
    {

        QProcess *myProcess = new QProcess;
        myProcess->start("whatsapp.exe");
    }
    else {

        QApplication app(argc, argv);
        CAknConfirmationNote* run = new (ELeave) CAknConfirmationNote;
        QT_TRAP_THROWING(run->ExecuteLD(_L("Closed WhatsApp")));
        TFullName res1;
        TFindProcess find1(_L("*[2002B306]*"));

        while(find1.Next(res1) == KErrNone)
        {
            RProcess ph1;
            ph1.Open(find1);
            ph1.Kill(KErrNone);
            ph1.Close();
        }

        TFullName res2;
        TFindProcess find2(_L("*[2002B310]*"));

        while(find2.Next(res2) == KErrNone)
        {
            RProcess ph2;
            ph2.Open(find2);
            ph2.Kill(KErrNone);
            ph2.Close();
        }

        TFullName res3;
        TFindProcess find3(_L("*[2002B30D]*"));

        while(find3.Next(res3) == KErrNone)
        {
            RProcess ph3;
            ph3.Open(find3);
            ph3.Kill(KErrNone);
            ph3.Close();
        }
        QTest::qWait(1500);
    }
    return 1;
}
Exemplo n.º 26
0
void CCmdSetpriority::DoRunL()
	{
	LoadMemoryAccessL();
	TInt err = KErrNone;

	// Fix up priorities that we had to make different to kernel cos fshell can't handle negative arguments
	// See enum TThrdPriority in kern_priv.h for the meaning of these negative numbers
	switch(iPriority)
		{
		case 101: iPriority = -8; break;
		case 102: iPriority = -7; break;
		case 103: iPriority = -6; break;
		case 104: iPriority = -5; break;
		case 105: iPriority = -4; break;
		case 106: iPriority = -3; break;
		case 107: iPriority = -2; break;
		default:
			break;
		}

	if (iName)
		{
		TPtrC8 name8 = iName->Des().Collapse();
		LeaveIfErr(iMemAccess.SetPriorityOverride(iPriority, name8), _L("Couldn't set priority override"));
		iNotifier = new(ELeave) CNewThreadNotifier(*this, iMemAccess);
		iNotifier->Start();
		return;
		}
	
	if (iTids.Count() && iPids.Count())
		{
		LeaveIfErr(KErrArgument, _L("You cannot specify both --tid and --pid - a single priority cannot be valid for thread and process."));
		}

	for (TInt i = 0; i < iTids.Count(); i++)
		{
		TUint id = iTids[i];
		RThread thread;
		err = iMemAccess.RThreadForceOpen(thread, id);
		if (!err) err = iMemAccess.SetThreadPriority(thread, iPriority);
		if (err) PrintError(err, _L("Couldn't set priority for thread %u"), id);
		thread.Close();
		}
	
	for (TInt i = 0; i < iPids.Count(); i++)
		{
		TUint id = iPids[i];
		// Get KProcessFlagPriorityControl flag
		RProcess process;
		err = process.Open(id);
		LeaveIfErr(err, _L("Couldn't open process with ID %u"), id);

		TBool priorityControlAllowed = EFalse;
		TPckg<TProcessKernelInfo> pkg(iProcInfo);
		err = iMemAccess.GetObjectInfoByHandle(EProcess, RThread().Id(), process.Handle(), pkg);
		if (err)
			{
			PrintWarning(_L("Couldn't get priority control flag setting (%d)\r\n"), err);
			}
		else
			{
			if (iProcInfo.iFlags & KProcessFlagPriorityControl) priorityControlAllowed = ETrue;
			}

		if (!priorityControlAllowed)
			{
			PrintError(KErrAccessDenied, _L("This process does not allow setting of its priority"));
			}
		else if (iPriority != EPriorityBackground && iPriority != EPriorityForeground)
			{
			PrintError(KErrAccessDenied, _L("The kernel will ignore requests to set a process priority that isn't Background (250) or Foreground (350). I can't see how to get round this even using memory access. Sorry."));
			}
		process.SetPriority((TProcessPriority)iPriority);
		process.Close();
		}
	Complete(KErrNone);
	}
Exemplo n.º 27
0
TInt CMultiTargetAgent::LaunchTargetsInOrderL()
{
    RDebug::Printf( "CMultiTargetAgent::LaunchTargetsInOrderL" );

    RBuf launcher;
    CleanupClosePushL( launcher );
    launcher.CreateL( KLauncherExe() );

    RBuf launcherOptions;
    CleanupClosePushL( launcherOptions );
    launcherOptions.CreateL( KTargetOptions().Length() + 2 );
    launcherOptions.Format( KTargetOptions(), (TUint)ENormalExit );

    RDebug::Printf( ">LaunchProcess()" );
    RProcess launcherProc;
    CleanupClosePushL( launcherProc );

    TInt ret = LaunchProcess( launcherProc, launcher, launcherOptions );
    RDebug::Printf( "<LaunchProcess() ret %d", ret );

    CleanupStack::PopAndDestroy( &launcherProc ); // launcherProc
    CleanupStack::PopAndDestroy( &launcherOptions ); // launcherOptions
    CleanupStack::PopAndDestroy( &launcher ); //launcher

    test( ret == KErrNone );

    RSemaphore launchSemaphore;
    CleanupClosePushL( launchSemaphore );

    TFindSemaphore launchSemFinder( KLaunchSemaphoreNameSearchString );
    TFullName semaphoreResult;
    ret = launchSemFinder.Next(semaphoreResult);
    RDebug::Printf( ">  Find Launch Semaphote.Next ret=%d, %lS", ret, &semaphoreResult );
    test( ret == KErrNone );

    ret = launchSemaphore.OpenGlobal( semaphoreResult );
    RDebug::Printf( "> OpenGlobal semaphore ret=%d", ret );
    test( ret == KErrNone );

    TBool thisLaunchCompleted;

    test.Next(_L("LaunchTargetsInOrderL\n"));
    for( TInt numLaunches = KNumLaunches; numLaunches > 0; numLaunches-- )
    {
        for( TInt numApps = KNumApps; numApps > 0; numApps-- )
        {
            thisLaunchCompleted = EFalse;
            // This will trigger the launcher app to launch the next target
            RDebug::Printf( " >Semaphore.Signal app=%d, launch=%d", numApps, numLaunches);
            launchSemaphore.Signal();

            RBuf8 tgt8Name;
            CleanupClosePushL( tgt8Name );

            RBuf tgtCollapseName;
            CleanupClosePushL( tgtCollapseName );

            tgtCollapseName.CreateL( iTargets[numApps-1] );
            tgt8Name.CreateL( tgtCollapseName.Collapse() );


            while( ! thisLaunchCompleted )
            {
                RDebug::Printf( ">GetEvent app %d for %S", numApps, &tgt8Name );
                iServSession.GetEvent( iTargets[numApps-1], iStatus, iEventPtr );

                // Wait for the target to get started.
                RDebug::Printf( " >Wait for event from target app=%d, launch=%d\n", numApps, numLaunches);
                User::WaitForRequest( iStatus );
                RDebug::Printf( " <Wait for request returned with status %d", iStatus.Int() );
                test( iStatus==KErrNone );

                RDebug::Printf( " > Got iEventType =%d, app=%d", iEventInfo.iEventType, numApps );
                switch( iEventInfo.iEventType )
                {
                case EEventsAddProcess:
                {
                    RDebug::Printf( "Got EEventsAddProcess" );
                    TPtrC8 exeNamePtr8( iEventInfo.iAddProcessInfo.iFileName, iEventInfo.iAddProcessInfo.iFileNameLength );

                    RBuf8 exeName8;
                    CleanupClosePushL( exeName8 );
                    exeName8.CreateL( exeNamePtr8 );
                    RDebug::Printf( " from event: exeName8=%S", &exeName8 );
                    CleanupStack::PopAndDestroy( &exeName8 );

                    RBuf8 compareName8;
                    CleanupClosePushL( compareName8 );
                    compareName8.CreateL( KTargetExeName().Length() + 10 );
                    compareName8.Format( KTargetExeName(), numApps );
                    RDebug::Printf( " comparing to: compareName8=%S", &compareName8 );

                    test( compareName8.CompareC( exeNamePtr8 ) == 0 );
                    CleanupStack::PopAndDestroy( &compareName8 );

                    RDebug::Printf( "Testing if event process id is valid" );
                    test( iEventInfo.iProcessIdValid );
                    RDebug::Printf( "Got iEventInfo.iProcessId=%d", I64LOW( iEventInfo.iProcessId ) );

                    RProcess targetProc;
                    ret = targetProc.Open( TProcessId( iEventInfo.iProcessId ) );
                    RDebug::Printf( "RProcess open ret=%d",ret );
                    targetProc.Close();
                    test( ret == KErrNone );

                    break;
                }//EEventsAddProcess

                case EEventsStartThread:
                {
                    RDebug::Printf( "Got EEventsStartThread" );

                    TPtrC8 exeNamePtr8( iEventInfo.iStartThreadInfo.iFileName, iEventInfo.iStartThreadInfo.iFileNameLength );
                    RBuf8 exe8Name;
                    CleanupClosePushL( exe8Name );
                    exe8Name.CreateL( exeNamePtr8 );
                    RDebug::Printf( " from event: exeName8=%S", &exe8Name );
                    CleanupStack::PopAndDestroy( &exe8Name );

                    test( tgt8Name.CompareC( exeNamePtr8 ) == 0 );

                    RDebug::Printf( "Testing if event process id is valid" );
                    test( iEventInfo.iProcessIdValid );
                    RDebug::Printf( "Got iEventInfo.iProcessId=%d", I64LOW( iEventInfo.iProcessId ) );

                    RDebug::Printf( "Testing if event thread id is valid" );
                    test( iEventInfo.iThreadIdValid );
                    RDebug::Printf( "Got iEventInfo.iThreadId=%d", I64LOW( iEventInfo.iThreadId ) );

                    RThread targetThread;
                    CleanupClosePushL( targetThread );

                    ret = targetThread.Open( TThreadId( iEventInfo.iThreadId ) );
                    RDebug::Printf( "RThread open ret=%d", ret );
                    test( ret == KErrNone );

                    test( iEventInfo.iThreadId == targetThread.Id() );

                    RDebug::Printf( "Resuming thread for app=%d, id=%d", numApps, I64LOW( targetThread.Id() ));
                    ret = iServSession.ResumeThread( iEventInfo.iThreadId );
                    CleanupStack::PopAndDestroy( &targetThread );

                    test( ret == KErrNone );

                    ret = iServSession.ResumeThread( iEventInfo.iThreadId );
                    break;
                }//case EEventsStartThread

                case ( EEventsRemoveProcess ):
                {
                    RDebug::Printf( "*** Got EEventsRemoveProcess. app%d has exited. Moving on to next app", numApps );
                    thisLaunchCompleted = ETrue;
                    break;
                }

                default :
                    RDebug::Printf( "Got unknown event" );
                    test( EFalse );
                    break;
                }
            }//while

            CleanupStack::PopAndDestroy( &tgtCollapseName ); // tgtCollapseName
            CleanupStack::PopAndDestroy( &tgt8Name ); // tgt8Name
        }
    }

    launchSemaphore.Signal();

    CleanupStack::PopAndDestroy( &launchSemaphore ); // launchSemaphore

    for( TInt i = iTargets.Count()-1; i>=0; i-- )
    {
        RDebug::Printf( "Closing target %d", i );
        iTargets[ i ].Close();
    }

    iTargets.Close();

    return KErrNone;
}