|
1 /* |
|
2 * Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies). |
|
3 * All rights reserved. |
|
4 * This component and the accompanying materials are made available |
|
5 * under the terms of "Eclipse Public License v1.0" |
|
6 * which accompanies this distribution, and is available |
|
7 * at the URL "http://www.eclipse.org/legal/epl-v10.html". |
|
8 * |
|
9 * Initial Contributors: |
|
10 * Nokia Corporation - initial contribution. |
|
11 * |
|
12 * Contributors: |
|
13 * |
|
14 * Description: |
|
15 * |
|
16 */ |
|
17 |
|
18 #include <QDebug> |
|
19 #include "logsservicetesterappcloser.h" |
|
20 |
|
21 // ----------------------------------------------------------------------------- |
|
22 // |
|
23 // ----------------------------------------------------------------------------- |
|
24 // |
|
25 LogsServiceTesterAppCloser::LogsServiceTesterAppCloser(QObject* parent) : |
|
26 QObject(parent) |
|
27 { |
|
28 mAppCloseWatch = new CAppCloseWatcher(*this); |
|
29 connect(&mTimer, SIGNAL(timeout()), this, SLOT(closeAppTimeout())); |
|
30 } |
|
31 |
|
32 // ----------------------------------------------------------------------------- |
|
33 // |
|
34 // ----------------------------------------------------------------------------- |
|
35 // |
|
36 LogsServiceTesterAppCloser::~LogsServiceTesterAppCloser() |
|
37 { |
|
38 delete mAppCloseWatch; |
|
39 } |
|
40 |
|
41 // ----------------------------------------------------------------------------- |
|
42 // |
|
43 // ----------------------------------------------------------------------------- |
|
44 // |
|
45 void LogsServiceTesterAppCloser::AppClosed(TInt aError) |
|
46 { |
|
47 mTimer.stop(); |
|
48 if (aError == KErrNone) { |
|
49 emit closed(); |
|
50 } else { |
|
51 emit closeError(aError); |
|
52 } |
|
53 } |
|
54 |
|
55 // ----------------------------------------------------------------------------- |
|
56 // |
|
57 // ----------------------------------------------------------------------------- |
|
58 // |
|
59 void LogsServiceTesterAppCloser::closeAppTimeout() |
|
60 { |
|
61 mAppCloseWatch->Cancel(); |
|
62 emit closeError(ErrorClosingTimeout); |
|
63 } |
|
64 |
|
65 // ----------------------------------------------------------------------------- |
|
66 // |
|
67 // ----------------------------------------------------------------------------- |
|
68 // |
|
69 void LogsServiceTesterAppCloser::closeApp(TApaTask& aTask) |
|
70 { |
|
71 if ( !mAppCloseWatch->IsActive() ) { |
|
72 mTimer.start(3000); //3 sec. |
|
73 mTimer.setSingleShot(true); |
|
74 mAppCloseWatch->Start(aTask); |
|
75 aTask.EndTask(); |
|
76 } else { |
|
77 emit closeError(ErrorClosingOngoing); |
|
78 } |
|
79 } |
|
80 |
|
81 // ----------------------------------------------------------------------------- |
|
82 // |
|
83 // ----------------------------------------------------------------------------- |
|
84 // |
|
85 void LogsServiceTesterAppCloser::closeDialerApp() |
|
86 { |
|
87 qDebug() << "[LOGS_TESTER] -> LogsServiceTesterAppCloser::closeDialerApp()"; |
|
88 const TUid KUidDialer = { 0x101F4CD5 }; |
|
89 RWsSession ws; |
|
90 TInt err = ws.Connect(); |
|
91 if (err == KErrNone) { |
|
92 TApaTaskList tl( ws); |
|
93 TApaTask dialerTask = (TApaTask)tl.FindApp( KUidDialer ); |
|
94 if (dialerTask.Exists()) { |
|
95 qDebug() << "[LOGS_TESTER] dialer is running, killing"; |
|
96 closeApp(dialerTask); |
|
97 } else { |
|
98 qDebug() << "[LOGS_TESTER] dialer is not running"; |
|
99 emit closeError(ErrorAppNotRunning); |
|
100 } |
|
101 ws.Close(); |
|
102 } else { |
|
103 emit closeError(err); |
|
104 } |
|
105 qDebug() << "[LOGS_TESTER] <- LogsServiceTesterAppCloser::closeDialerApp()"; |
|
106 } |
|
107 |
|
108 |
|
109 |
|
110 // ----------------------------------------------------------------------------- |
|
111 // |
|
112 // ----------------------------------------------------------------------------- |
|
113 // |
|
114 CAppCloseWatcher::CAppCloseWatcher(MCloseOberver& aObserver) : |
|
115 CActive(CActive::EPriorityStandard), iObserver(aObserver) |
|
116 { |
|
117 CActiveScheduler::Add(this); |
|
118 } |
|
119 |
|
120 // ----------------------------------------------------------------------------- |
|
121 // |
|
122 // ----------------------------------------------------------------------------- |
|
123 // |
|
124 CAppCloseWatcher::~CAppCloseWatcher() |
|
125 { |
|
126 Cancel(); |
|
127 } |
|
128 |
|
129 // ----------------------------------------------------------------------------- |
|
130 // |
|
131 // ----------------------------------------------------------------------------- |
|
132 // |
|
133 void CAppCloseWatcher::Start(const TApaTask& aTask) |
|
134 { |
|
135 qDebug() << "[LOGS_TESTER] -> CAppCloseWatcher::Start()!"; |
|
136 if (!IsActive()) |
|
137 { |
|
138 TInt err = iThread.Open(aTask.ThreadId()); |
|
139 if (err == KErrNone) |
|
140 { |
|
141 qDebug() << "[LOGS_TESTER] calling iThread.Logon(iStatus)"; |
|
142 iOriginalProcessPriority = iThread.ProcessPriority(); |
|
143 iThread.SetProcessPriority(EPriorityForeground); |
|
144 iThread.Logon(iStatus); |
|
145 SetActive(); |
|
146 } |
|
147 else |
|
148 { |
|
149 qDebug() << "[LOGS_TESTER] calling iThread.Open() failed: "<< err; |
|
150 TRequestStatus* s = &iStatus; |
|
151 User::RequestComplete(s, err); |
|
152 SetActive(); |
|
153 } |
|
154 } |
|
155 qDebug() << "[LOGS_TESTER] <- CAppCloseWatcher::Start()"; |
|
156 } |
|
157 |
|
158 // ----------------------------------------------------------------------------- |
|
159 // |
|
160 // ----------------------------------------------------------------------------- |
|
161 // |
|
162 void CAppCloseWatcher::DoCancel() |
|
163 { |
|
164 qDebug() << "[LOGS_TESTER] -> CAppCloseWatcher::DoCancel()"; |
|
165 iThread.LogonCancel(iStatus); |
|
166 iThread.SetProcessPriority(iOriginalProcessPriority); |
|
167 iThread.Close(); |
|
168 qDebug() << "[LOGS_TESTER] -> CAppCloseWatcher::DoCancel()"; |
|
169 } |
|
170 |
|
171 // ----------------------------------------------------------------------------- |
|
172 // |
|
173 // ----------------------------------------------------------------------------- |
|
174 // |
|
175 void CAppCloseWatcher::RunL() |
|
176 { |
|
177 qDebug() << "[LOGS_TESTER] -> CAppCloseWatcher::RunL()"; |
|
178 if (iThread.Handle()) |
|
179 iThread.SetProcessPriority(iOriginalProcessPriority); |
|
180 iThread.Close(); |
|
181 iObserver.AppClosed(iStatus.Int()); |
|
182 qDebug() << "[LOGS_TESTER] <- CAppCloseWatcher::RunL()"; |
|
183 } |