Пример #1
0
// --------------------------------------------------------------------------
// Check whether client key event request can be executed
// --------------------------------------------------------------------------
void CAknCompaSrvSession::CheckKeyDownPermissionL(const RMessage2& aMessage)
    {
    // We try to increase security by allowing only foreground application
    // to set key down. As the simulated key events are sent to the
    // foreground application by window server, the application is
    // sending a key event to itself.

    // Granted if client has ECapabilitySwEvent or request is coming from
    // EikSrv. TApaTaskList won't report EikSrv in foreground though
    // it's displaying a note.
    if (!aMessage.HasCapability(ECapabilitySwEvent) &&
        !CAknCompaServer::IsGlobalUiSrv(aMessage))
        {
        // Allow key down only from a foreground task
        TApaTaskList tasklist(Server().WsSession());
        TApaTask foregroundTask = tasklist.FindByPos(0);

        RThread thread;
        User::LeaveIfError(thread.Open(foregroundTask.ThreadId()));
        TSecurityPolicy securityPolicy(thread.SecureId());
        thread.Close();

        if (!securityPolicy.CheckPolicy(aMessage))
            {
            User::Leave(KErrPermissionDenied);
            }
        }
    }
	EXPORT_C void KillApplicationL(RWsSession& aWs, TUid aUid, TInt aRetryInterval )
	{
		TTime wait_until; wait_until.HomeTime();
		wait_until+=TTimeIntervalSeconds(15);
	
		TApaTaskList taskList( aWs );

		for(;;) {
			TApaTask task = taskList.FindApp(aUid);
			if(! task.Exists()) {
				break;
			}
			TTime now; now.HomeTime();
			if (now < wait_until) {
				task.EndTask();
				//DebugMsg(_L("waiting..."), aDebugLog);
				User::After(TTimeIntervalMicroSeconds32(aRetryInterval*1000) );
			} else {
				break;
			}
		}
		TApaTask task = taskList.FindApp(aUid);
		if( task.Exists()) {
#ifdef __S60V3__
			task.KillTask();
#else
			RThread t;
			if (t.Open(task.ThreadId())==KErrNone) {
				//DebugMsg(_L("killing"), aDebugLog);
				t.Kill(2003);
				t.Close();
			}
#endif
		}
	}
void COomAppCloseWatcher::Start(const TApaTask& aTask)
    {
    FUNC_LOG;

    if (!IsActive())
        {
        TInt err = iThread.Open(aTask.ThreadId());
        if (err == KErrNone)
            {
            iOriginalProcessPriority = iThread.ProcessPriority();
            iThread.SetProcessPriority(EPriorityForeground);
            iThread.Logon(iStatus);
            SetActive();
            }
        else
            {
            TRequestStatus* s = &iStatus;
            User::RequestComplete(s, err);
            SetActive();
            }
        }
    }