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: Active Object for wiping Call-logs, called by lawmocalllogsplugin. |
|
15 * |
|
16 */ |
|
17 #include <logcli.h> |
|
18 #include <f32file.h> |
|
19 #include <logwrap.h> |
|
20 #include <logview.h> |
|
21 #include <e32base.h> |
|
22 #include <logwraplimits.h> |
|
23 #include <logwrapconst.h> |
|
24 #include "lawmocalllogsasyncwipe.h" |
|
25 #include "fdebug.h" |
|
26 |
|
27 // Application Closing |
|
28 #include <apgtask.h> |
|
29 #include <w32std.h> |
|
30 |
|
31 // ----------------------------------------------------------------------------- |
|
32 // CActiveWipeObject::CActiveWipeObject |
|
33 // Description: CActiveWipeObject constructer . Initializes datamember of MLawmoPluginWipeObserver |
|
34 // ----------------------------------------------------------------------------- |
|
35 // |
|
36 CActiveWipeObject::CActiveWipeObject(MLawmoPluginWipeObserver* aObserver) : |
|
37 CActive(EPriorityStandard), iObserver(aObserver), ilogClient(NULL), iTimerStarted (EFalse) |
|
38 { |
|
39 FLOG( |
|
40 _L( " CAllLogs: CActiveWipeObject::CActiveWipeObject(MLawmoPluginWipeObserver* aObserver) >> ")); |
|
41 // See ConstructL() for initialisation completion. |
|
42 FLOG( |
|
43 _L( " CAllLogs: CActiveWipeObject::CActiveWipeObject(MLawmoPluginWipeObserver* aObserver) << ")); |
|
44 } |
|
45 |
|
46 // ----------------------------------------------------------------------------- |
|
47 // CActiveWipeObject::NewL |
|
48 // Description: CActiveWipeObject constructer |
|
49 // ----------------------------------------------------------------------------- |
|
50 // |
|
51 CActiveWipeObject* CActiveWipeObject::NewL( |
|
52 MLawmoPluginWipeObserver* aObserver) |
|
53 { |
|
54 FLOG(_L( " CAllLogs: CActiveWipeObject::NewL >> ")); |
|
55 CActiveWipeObject* self = new (ELeave) CActiveWipeObject(aObserver); |
|
56 CleanupStack::PushL(self); |
|
57 self->ConstructL(); |
|
58 CleanupStack::Pop(); |
|
59 FLOG(_L( " CAllLogs: CActiveWipeObject::NewL << ")); |
|
60 return self; |
|
61 } |
|
62 |
|
63 // ---------------------------------------------------------------------------------------- |
|
64 // CActiveWipeObject::ConstructL |
|
65 // ---------------------------------------------------------------------------------------- |
|
66 void CActiveWipeObject::ConstructL() |
|
67 { |
|
68 FLOG(_L( " CAllLogs: CActiveWipeObject::ConstructL >> ")); |
|
69 iTimer.CreateLocal(); |
|
70 User::LeaveIfError(iWsSession.Connect()); |
|
71 CActiveScheduler::Add(this); // Add to scheduler |
|
72 FLOG(_L( " CAllLogs: CActiveWipeObject::ConstructL << ")); |
|
73 } |
|
74 |
|
75 // |
|
76 //----------------------------------------------------------------------------- |
|
77 // CActiveWipeObject:: CActiveWipeObject |
|
78 // Description: CActiveWipeObject Destructer |
|
79 // ----------------------------------------------------------------------------- |
|
80 // |
|
81 CActiveWipeObject::~CActiveWipeObject() |
|
82 { |
|
83 FLOG(_L( " CAllLogs: CActiveWipeObject::~CActiveWipeObject() >> ")); |
|
84 Cancel(); |
|
85 if (ilogClient) |
|
86 { |
|
87 delete ilogClient; |
|
88 } |
|
89 |
|
90 if (ifs.Handle()) |
|
91 { |
|
92 ifs.Close(); |
|
93 } |
|
94 |
|
95 iTimer.Close(); |
|
96 |
|
97 iWsSession.Close(); |
|
98 |
|
99 FLOG(_L( " CAllLogs: CActiveWipeObject::~CActiveWipeObject() << ")); |
|
100 } |
|
101 |
|
102 // |
|
103 //----------------------------------------------------------------------------- |
|
104 // CActiveWipeObject::WipeAsyncL |
|
105 // Description: Wipes the logs |
|
106 // ---------------------------------------------------------------------------- |
|
107 // |
|
108 |
|
109 void CActiveWipeObject::WipeAsyncL() |
|
110 { |
|
111 FLOG(_L(" CAllLogs: void CActiveWipeObject::WipeAsyncL () >>")); |
|
112 if (!WaitTillLogsAppKilled()) //Application is closed already |
|
113 { |
|
114 ClearLogsL(); |
|
115 } |
|
116 |
|
117 FLOG(_L(" CAllLogs: void CActiveWipeObject::WipeAsyncL () <<")); |
|
118 } |
|
119 |
|
120 // |
|
121 //----------------------------------------------------------------------------- |
|
122 // CActiveWipeObject::RunError |
|
123 // Description: This returns error |
|
124 //----------------------------------------------------------------------------- |
|
125 // |
|
126 |
|
127 TInt CActiveWipeObject::RunError(TInt aError) |
|
128 { |
|
129 FLOG(_L(" CAllLogs: TInt CActiveWipeObject::RunError(TInt aError) >>")); |
|
130 FLOG(_L(" CAllLogs: RunError error %d"), aError); |
|
131 iObserver->HandleWipeCompleted(aError); |
|
132 FLOG(_L(" CAllLogs: TInt CActiveWipeObject::RunError(TInt aError) <<")); |
|
133 return KErrNone; |
|
134 } |
|
135 |
|
136 // |
|
137 //----------------------------------------------------------------------------- |
|
138 // CActiveWipeObject::DoCancel |
|
139 // Description: This calls CActive's Cancel |
|
140 //----------------------------------------------------------------------------- |
|
141 // |
|
142 void CActiveWipeObject::DoCancel() |
|
143 { |
|
144 FLOG(_L(" CAllLogs: void CActiveWipeObject::DoCancel() >>")); |
|
145 if (iTimerStarted) |
|
146 { |
|
147 iTimer.Cancel(); |
|
148 } |
|
149 else |
|
150 { |
|
151 ilogClient->Cancel(); |
|
152 } |
|
153 FLOG(_L(" CAllLogs: void CActiveWipeObject::DoCancel() <<")); |
|
154 } |
|
155 |
|
156 TBool CActiveWipeObject::WaitTillLogsAppKilled() |
|
157 { |
|
158 FLOG(_L(" WaitTillLogsAppKilled() >>")); |
|
159 |
|
160 TBool ret(EFalse); |
|
161 TBool flag(ETrue); |
|
162 |
|
163 TApaTaskList list(iWsSession); |
|
164 TUid uid = |
|
165 { |
|
166 KCallLogsAppUid |
|
167 }; |
|
168 |
|
169 while (flag) |
|
170 { |
|
171 TApaTask task(list.FindApp(uid)); |
|
172 if (task.Exists()) |
|
173 { |
|
174 FLOG(_L("Killing one instance...")); |
|
175 task.EndTask(); |
|
176 User::After(500000); |
|
177 ret = ETrue; |
|
178 } |
|
179 else |
|
180 { |
|
181 flag = EFalse; |
|
182 } |
|
183 } |
|
184 if (ret) |
|
185 { |
|
186 FLOG(_L(" WaitTillPhonebookKilled: iTimer.After(iStatus,1000); ")); |
|
187 iTimerStarted = ETrue; // If time is started, this is true |
|
188 iTimer.After(iStatus, 2000); // 0.002 sec |
|
189 SetActive(); |
|
190 } |
|
191 |
|
192 FLOG(_L(" WaitTillLogsAppKilled(), ret = %d <<"), ret); |
|
193 return ret; |
|
194 } |
|
195 |
|
196 |
|
197 // |
|
198 //----------------------------------------------------------------------------- |
|
199 // CActiveWipeObject::RunL |
|
200 // Description: Clears the logs |
|
201 //----------------------------------------------------------------------------- |
|
202 // |
|
203 void CActiveWipeObject::ClearLogsL() |
|
204 { |
|
205 FLOG(_L("void CActiveWipeObject::ClearLogs() >> ")); |
|
206 TTime time(KMaxTime); |
|
207 User::LeaveIfError(ifs.Connect()); |
|
208 ilogClient = CLogClient::NewL(ifs); |
|
209 FLOG(_L("iStatus.Int() = %d "), iStatus.Int()); |
|
210 ilogClient->ClearLog(time, iStatus); |
|
211 SetActive(); |
|
212 |
|
213 FLOG(_L("void CActiveWipeObject::ClearLogs() << ")); |
|
214 } |
|
215 |
|
216 // |
|
217 //----------------------------------------------------------------------------- |
|
218 // CActiveWipeObject::RunL |
|
219 // Description: Called when either timer expires of logs are cleared |
|
220 //----------------------------------------------------------------------------- |
|
221 // |
|
222 void CActiveWipeObject::RunL() |
|
223 { |
|
224 FLOG(_L(" CAllLogs: void CActiveWipeObject::RunL() >>")); |
|
225 FLOG(_L("void CActiveWipeObject::RunL(): iStatus= %d "), iStatus.Int()); |
|
226 |
|
227 if (iTimerStarted) |
|
228 { |
|
229 iTimerStarted = EFalse; |
|
230 ClearLogsL(); |
|
231 } |
|
232 else |
|
233 iObserver->HandleWipeCompleted(iStatus.Int()); |
|
234 FLOG(_L(" CAllLogs: void CActiveWipeObject::RunL() <<")); |
|
235 } |
|