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 } }
static bool StartBrowser(dword uid, const char *url){ bool is_https = false; if(text_utils::CheckStringBegin(url, text_utils::HTTPS_PREFIX)) is_https = true; else text_utils::CheckStringBegin(url, text_utils::HTTP_PREFIX); const TUid uid_value = { uid }; Cstr_w par; par.Format(L"4 %#%") <<(!is_https ? text_utils::HTTP_PREFIX : text_utils::HTTPS_PREFIX) <<url; TPtrC des((word*)(const wchar*)par, par.Length()); TApaTaskList tl(CEikonEnv::Static()->WsSession()); TApaTask task = tl.FindApp(uid_value); bool ok = false; bool exists = task.Exists(); //Info("uid", uid); if(exists && uid==0x10008d39){ //kill web browser task.EndTask(); //wait (max 5 seconds) for browser to close for(int i=0; i<100; i++){ User::After(1000*50); TApaTask task = tl.FindApp(uid_value); if(!task.Exists()){ exists = false; break; } } } if(exists){ task.BringToForeground(); /* Cstr_c s8; s8.Copy(par); TPtrC8 des8((byte*)(const char*)s8, s8.Length()); task.SendMessage(TUid::Uid(0), des8); // UID not used */ HBufC8 *param = HBufC8::NewL(par.Length() + 2); param->Des().Append(des); task.SendMessage(TUid::Uid(0), *param); // Uid is not used delete param; ok = true; }else { RApaLsSession ls; if(!ls.Connect()){ TThreadId tid; int err = ls.StartDocument(des, uid_value, tid); ls.Close(); ok = (!err); } } return ok; }
void MpFetcherTestAppView::endMP() { TApaTaskList taskList(CEikonEnv::Static()->WsSession()); TApaTask task = taskList.FindApp(TUid::Uid(270564450)); if (task.Exists()) { task.EndTask(); } else { qCritical("Cannot bring to forward task %08x", 270564450); } }
TInt CLaunchSaver::HandleScreensaverEventL( TScreensaverEvent aEvent, TAny* /*aData*/ ) { TInt err( KErrNone ); switch ( aEvent ) { case EScreensaverEventTimeout: { // Keep lights on iHost->RequestTimeout( KLightsOnTimeoutInterval ); break; } case EScreensaverEventStarting: { // Launch new process RApaLsSession apaLsSession; TInt err = apaLsSession.Connect(); if ( err == KErrNone ) { TThreadId thread; err = apaLsSession.StartDocument( KNullDesC, KUidSaverExe, thread ); apaLsSession.Close(); } // Switch to partial mode to save power TScreensaverPartialMode partial; partial.iType = EPartialModeTypeMostPowerSaving; // Set partial mode for almost the whole screen // (doesn't go to partial mode if whole screen is specified) TInt height = CEikonEnv::Static()->ScreenDevice()->SizeInPixels().iHeight; iHost->SetActiveDisplayArea( 0, height - 1, partial ); if( err == KErrNone ) { iHost->RequestTimeout( KLightsOnTimeoutInterval ); } break; } case EScreensaverEventStopping: { // Kill saver process TApaTaskList list( CEikonEnv::Static()->WsSession() ); TApaTask task = list.FindApp( KUidSaverExe ); if ( task.Exists() ) { task.EndTask(); } break; } default: { break; } } // switch ( aEvent ) return err; }