58
|
1 |
/*
|
|
2 |
* Copyright (c) 2007 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: This is the implementation of the runtime requirements
|
|
15 |
* information data class.
|
|
16 |
*
|
|
17 |
*/
|
|
18 |
|
|
19 |
|
|
20 |
// System Include Files
|
|
21 |
#include <aknmessagequerydialog.h> // CAknMessageQueryDialog
|
|
22 |
#include <centralrepository.h> // CRepository
|
|
23 |
#include <DiagFrameworkDebug.h> // Debugging Macros
|
|
24 |
#include <DiagResultsDatabase.h> // RDiagResultsDatabase
|
|
25 |
#include <DiagResultsDatabaseTestRecordInfo.h>
|
|
26 |
#include <f32file.h> // RFs
|
|
27 |
#include <StringLoader.h> // StringLoader
|
|
28 |
#include <devdiagapp.rsg> // Resource defintions
|
|
29 |
|
|
30 |
// User Include Files
|
|
31 |
#include "devdiag.pan" // Panic
|
|
32 |
#include "devdiagruntimereqsinfo.h" // CDevDiagRuntimeReqsInfo
|
|
33 |
#include "devdiagprivatecrkeys.h" // CR Key ID Definitions
|
|
34 |
|
|
35 |
|
|
36 |
|
|
37 |
// ============================ MEMBER FUNCTIONS =============================
|
|
38 |
|
|
39 |
// ---------------------------------------------------------------------------
|
|
40 |
// Static two-phase constructor.
|
|
41 |
// ---------------------------------------------------------------------------
|
|
42 |
//
|
|
43 |
CDevDiagRuntimeReqsInfo* CDevDiagRuntimeReqsInfo::NewL( RFs& aFs,
|
|
44 |
RDiagResultsDatabase& aDb,
|
|
45 |
TCallBack aCallback )
|
|
46 |
{
|
|
47 |
LOGSTRING( "CDevDiagRuntimeReqsInfo::NewL()" )
|
|
48 |
|
|
49 |
CDevDiagRuntimeReqsInfo* self = new ( ELeave ) CDevDiagRuntimeReqsInfo( aFs,
|
|
50 |
aDb,
|
|
51 |
aCallback );
|
|
52 |
CleanupStack::PushL( self );
|
|
53 |
self->ConstructL();
|
|
54 |
CleanupStack::Pop( self );
|
|
55 |
return self;
|
|
56 |
}
|
|
57 |
|
|
58 |
// ---------------------------------------------------------------------------
|
|
59 |
// Destructor.
|
|
60 |
// ---------------------------------------------------------------------------
|
|
61 |
//
|
|
62 |
CDevDiagRuntimeReqsInfo::~CDevDiagRuntimeReqsInfo()
|
|
63 |
{
|
|
64 |
LOGSTRING( "CDevDiagRuntimeReqsInfo::~CDevDiagRuntimeReqsInfo()" )
|
|
65 |
|
|
66 |
Cancel();
|
|
67 |
delete iTelephony;
|
|
68 |
|
|
69 |
}
|
|
70 |
|
|
71 |
// ---------------------------------------------------------------------------
|
|
72 |
// Begins checking if the diagnostics runtime requirements are satisfied.
|
|
73 |
// ---------------------------------------------------------------------------
|
|
74 |
//
|
|
75 |
void CDevDiagRuntimeReqsInfo::CheckRuntimeRequirementsL( TBool aResumingTests )
|
|
76 |
{
|
|
77 |
LOGSTRING( "CDevDiagRuntimeReqsInfo::CheckRuntimeRequirementsL()" )
|
|
78 |
|
|
79 |
// If the requirements are already being checked, start over.
|
|
80 |
if ( iState != EStateInitial )
|
|
81 |
{
|
|
82 |
Cancel();
|
|
83 |
}
|
|
84 |
|
|
85 |
iResumingTests = aResumingTests;
|
|
86 |
|
|
87 |
// (Check 1) Check the free disk space.
|
|
88 |
CheckDiskSpaceL();
|
|
89 |
|
|
90 |
// (Check 2) Check the battery level.
|
|
91 |
CheckBatteryLevelL();
|
|
92 |
}
|
|
93 |
|
|
94 |
// ---------------------------------------------------------------------------
|
|
95 |
// Returns the runtime requirements result, which indicates if the runtime
|
|
96 |
// requirements were satisfied.
|
|
97 |
// ---------------------------------------------------------------------------
|
|
98 |
//
|
|
99 |
CDevDiagRuntimeReqsInfo::TResult CDevDiagRuntimeReqsInfo::Result() const
|
|
100 |
{
|
|
101 |
return iResult;
|
|
102 |
}
|
|
103 |
|
|
104 |
// ---------------------------------------------------------------------------
|
|
105 |
// Displays the dialog associated with the result of the runtime checks.
|
|
106 |
// ---------------------------------------------------------------------------
|
|
107 |
//
|
|
108 |
TInt CDevDiagRuntimeReqsInfo::DisplayDialogL() const
|
|
109 |
{
|
|
110 |
LOGSTRING( "CDevDiagRuntimeReqsInfo::DisplayDialogL()" )
|
|
111 |
|
|
112 |
// Act on the result.
|
|
113 |
switch ( iResult )
|
|
114 |
{
|
|
115 |
case EResultErrLowDisk:
|
|
116 |
return DisplayMessageQueryDialogL( R_DEVDIAG_LOW_DISK_DIALOG );
|
|
117 |
|
|
118 |
case EResultErrLowBattery:
|
|
119 |
return DisplayMessageQueryDialogL( R_DEVDIAG_LOW_BATTERY_DIALOG );
|
|
120 |
|
|
121 |
case EResultOk:
|
|
122 |
default:
|
|
123 |
return EAknSoftkeyOk;
|
|
124 |
}
|
|
125 |
}
|
|
126 |
|
|
127 |
// ---------------------------------------------------------------------------
|
|
128 |
// C++ constructor.
|
|
129 |
// ---------------------------------------------------------------------------
|
|
130 |
//
|
|
131 |
CDevDiagRuntimeReqsInfo::CDevDiagRuntimeReqsInfo( RFs& aFs,
|
|
132 |
RDiagResultsDatabase& aDb,
|
|
133 |
TCallBack aCallback )
|
|
134 |
: CActive( EPriorityStandard ),
|
|
135 |
iFs( aFs ),
|
|
136 |
iDb( aDb ),
|
|
137 |
iCallback( aCallback ),
|
|
138 |
iBatteryInfo(),
|
|
139 |
iBatteryInfoPackage( iBatteryInfo )
|
|
140 |
{
|
|
141 |
LOGSTRING( "CDevDiagRuntimeReqsInfo::CDevDiagRuntimeReqsInfo()" )
|
|
142 |
|
|
143 |
CActiveScheduler::Add( this );
|
|
144 |
}
|
|
145 |
|
|
146 |
// ---------------------------------------------------------------------------
|
|
147 |
// Two-phased constructor.
|
|
148 |
// ---------------------------------------------------------------------------
|
|
149 |
//
|
|
150 |
void CDevDiagRuntimeReqsInfo::ConstructL()
|
|
151 |
{
|
|
152 |
LOGSTRING( "CDevDiagRuntimeReqsInfo::ConstructL()" )
|
|
153 |
|
|
154 |
ReadCentralRepositoryValuesL();
|
|
155 |
}
|
|
156 |
|
|
157 |
// ---------------------------------------------------------------------------
|
|
158 |
// Reads the runtime requirements values from the central repository and
|
|
159 |
// stores them to the object.
|
|
160 |
// ---------------------------------------------------------------------------
|
|
161 |
//
|
|
162 |
void CDevDiagRuntimeReqsInfo::ReadCentralRepositoryValuesL()
|
|
163 |
{
|
|
164 |
LOGSTRING( "CDevDiagRuntimeReqsInfo::ReadCentralRepositoryValuesL()" )
|
|
165 |
|
|
166 |
CRepository* repository = CRepository::NewLC( KCRUidDevDiag );
|
|
167 |
|
|
168 |
// The required battery level.
|
|
169 |
User::LeaveIfError( repository->Get( KDevDiagAppMinBatteryLevel,
|
|
170 |
iMinBatteryLevel ) );
|
|
171 |
|
|
172 |
// The required free disk space. A local TInt is used because the data
|
|
173 |
// member is a TInt64, but the CR only has a getter function for TInt.
|
|
174 |
TInt minDiskSpaceRequired;
|
|
175 |
User::LeaveIfError( repository->Get( KDevDiagAppMinDiskSpace,
|
|
176 |
minDiskSpaceRequired ) );
|
|
177 |
iMinDiskSpaceFree = minDiskSpaceRequired;
|
|
178 |
|
|
179 |
|
|
180 |
LOGSTRING3( "CDevDiagRuntimeReqsInfo::ReadCentralRepositoryValuesL() -"
|
|
181 |
L" iMinBatteryLevel %d, iMinDiskSpaceFree %d",
|
|
182 |
iMinBatteryLevel,
|
|
183 |
minDiskSpaceRequired )
|
|
184 |
|
|
185 |
CleanupStack::PopAndDestroy( repository );
|
|
186 |
}
|
|
187 |
|
|
188 |
|
|
189 |
// ---------------------------------------------------------------------------
|
|
190 |
// Checks if there is enough free estimated disk space to log test results.
|
|
191 |
// ---------------------------------------------------------------------------
|
|
192 |
//
|
|
193 |
void CDevDiagRuntimeReqsInfo::CheckDiskSpaceL()
|
|
194 |
{
|
|
195 |
LOGSTRING( "CDevDiagRuntimeReqsInfo::CheckDiskSpaceL()" )
|
|
196 |
|
|
197 |
// If the runtime requirements have already failed, this function will
|
|
198 |
// set us active and complete the request.
|
|
199 |
if ( CheckCompletion() )
|
|
200 |
{
|
|
201 |
return;
|
|
202 |
}
|
|
203 |
|
|
204 |
// Set default values for this check.
|
|
205 |
iDiskSpaceFree = 0;
|
|
206 |
|
|
207 |
// Get the free disk space.
|
|
208 |
TVolumeInfo volumeData;
|
|
209 |
User::LeaveIfError( iFs.Volume( volumeData ) );
|
|
210 |
iDiskSpaceFree = volumeData.iFree;
|
|
211 |
|
|
212 |
// Check the free disk level.
|
|
213 |
if ( iDiskSpaceFree < iMinDiskSpaceFree )
|
|
214 |
{
|
|
215 |
iResult = EResultErrLowDisk;
|
|
216 |
}
|
|
217 |
|
|
218 |
return;
|
|
219 |
}
|
|
220 |
|
|
221 |
// ---------------------------------------------------------------------------
|
|
222 |
// Checks if the phone's battery level is adequate to run tests.
|
|
223 |
// ---------------------------------------------------------------------------
|
|
224 |
//
|
|
225 |
void CDevDiagRuntimeReqsInfo::CheckBatteryLevelL()
|
|
226 |
{
|
|
227 |
LOGSTRING( "CDevDiagRuntimeReqsInfo::CheckBatteryLevelL()" )
|
|
228 |
|
|
229 |
// If the runtime requirements have already failed, this function will
|
|
230 |
// set us active and complete the request.
|
|
231 |
if ( CheckCompletion() )
|
|
232 |
{
|
|
233 |
return;
|
|
234 |
}
|
|
235 |
|
|
236 |
// Check the battery level.
|
|
237 |
switch ( iState )
|
|
238 |
{
|
|
239 |
case EStateInitial:
|
|
240 |
{
|
|
241 |
iState = EStateCheckingBattery;
|
|
242 |
|
|
243 |
// Issue the asynchronous request.
|
|
244 |
if ( !iTelephony )
|
|
245 |
{
|
|
246 |
iTelephony = CTelephony::NewL();
|
|
247 |
}
|
|
248 |
|
|
249 |
iTelephony->GetBatteryInfo( iStatus, iBatteryInfoPackage );
|
|
250 |
SetActive();
|
|
251 |
break;
|
|
252 |
}
|
|
253 |
|
|
254 |
case EStateCheckingBattery:
|
|
255 |
{
|
|
256 |
iState = EStateInitial;
|
|
257 |
|
|
258 |
// Check the battery level.
|
|
259 |
if ( iStatus != KErrNone )
|
|
260 |
{
|
|
261 |
iResult = EResultErrLowBattery;
|
|
262 |
break;
|
|
263 |
}
|
|
264 |
|
|
265 |
if ( iBatteryInfo.iChargeLevel < TUint( iMinBatteryLevel ) )
|
|
266 |
{
|
|
267 |
iResult = EResultErrLowBattery;
|
|
268 |
}
|
|
269 |
|
|
270 |
iBatteryLevel = iBatteryInfo.iChargeLevel;
|
|
271 |
break;
|
|
272 |
}
|
|
273 |
|
|
274 |
default:
|
|
275 |
{
|
|
276 |
__ASSERT_DEBUG( EFalse, Panic( EDevDiagApplicationRuntimeReqs) );
|
|
277 |
iResult = EResultErrLowBattery;
|
|
278 |
CheckCompletion();
|
|
279 |
break;
|
|
280 |
}
|
|
281 |
}
|
|
282 |
}
|
|
283 |
|
|
284 |
|
|
285 |
// ---------------------------------------------------------------------------
|
|
286 |
// This is a utility function to handle the common checking for completion
|
|
287 |
// of the runtime requirements checks.
|
|
288 |
// ---------------------------------------------------------------------------
|
|
289 |
//
|
|
290 |
TBool CDevDiagRuntimeReqsInfo::CheckCompletion()
|
|
291 |
{
|
|
292 |
LOGSTRING( "CDevDiagRuntimeReqsInfo::CheckCompletion()" )
|
|
293 |
|
|
294 |
// If there is already a failed check, complete the asynchronous request
|
|
295 |
// if it hasn't already been done.
|
|
296 |
if ( iResult != EResultOk && iState != EStateComplete )
|
|
297 |
{
|
|
298 |
LOGSTRING( "CDevDiagRuntimeReqsInfo::CheckCompletion() - completed" )
|
|
299 |
iState = EStateComplete;
|
|
300 |
TRequestStatus* status = &iStatus;
|
|
301 |
User::RequestComplete( status, KErrNone );
|
|
302 |
SetActive();
|
|
303 |
return ETrue;
|
|
304 |
}
|
|
305 |
|
|
306 |
if ( iState == EStateComplete )
|
|
307 |
{
|
|
308 |
return ETrue;
|
|
309 |
}
|
|
310 |
|
|
311 |
return EFalse;
|
|
312 |
}
|
|
313 |
|
|
314 |
// ---------------------------------------------------------------------------
|
|
315 |
// Utility function to display a message dialog associated with the specified
|
|
316 |
// resource.
|
|
317 |
// ---------------------------------------------------------------------------
|
|
318 |
//
|
|
319 |
TInt CDevDiagRuntimeReqsInfo::DisplayMessageQueryDialogL( TInt aResource )
|
|
320 |
{
|
|
321 |
LOGSTRING2( "CDevDiagRuntimeReqsInfo::DisplayMessageQueryDialogL( %d )",
|
|
322 |
aResource )
|
|
323 |
CAknMessageQueryDialog* dlg = new ( ELeave ) CAknMessageQueryDialog;
|
|
324 |
return dlg->ExecuteLD( aResource );
|
|
325 |
}
|
|
326 |
|
|
327 |
|
|
328 |
// ---------------------------------------------------------------------------
|
|
329 |
// From CActive.
|
|
330 |
// This function is called when an active request completes.
|
|
331 |
// ---------------------------------------------------------------------------
|
|
332 |
//
|
|
333 |
void CDevDiagRuntimeReqsInfo::RunL()
|
|
334 |
{
|
|
335 |
LOGSTRING( "CDevDiagRuntimeReqsInfo::RunL()" )
|
|
336 |
|
|
337 |
switch ( iState )
|
|
338 |
{
|
|
339 |
case EStateCheckingBattery:
|
|
340 |
// (Check 1) Check the battery level.
|
|
341 |
CheckBatteryLevelL();
|
|
342 |
|
|
343 |
|
|
344 |
case EStateComplete:
|
|
345 |
default:
|
|
346 |
{
|
|
347 |
delete iTelephony;
|
|
348 |
iTelephony = NULL;
|
|
349 |
// Inform the observer that checking is complete.
|
|
350 |
iCallback.CallBack();
|
|
351 |
}
|
|
352 |
}
|
|
353 |
}
|
|
354 |
|
|
355 |
// ---------------------------------------------------------------------------
|
|
356 |
// CDevDiagRuntimeReqsInfo::RunError
|
|
357 |
// ---------------------------------------------------------------------------
|
|
358 |
//
|
|
359 |
TInt CDevDiagRuntimeReqsInfo::RunError( TInt aError )
|
|
360 |
{
|
|
361 |
LOGSTRING2( "CDevDiagRuntimeReqsInfo::RunError( %d )", aError )
|
|
362 |
return KErrNone;
|
|
363 |
}
|
|
364 |
|
|
365 |
// ---------------------------------------------------------------------------
|
|
366 |
// From CActive.
|
|
367 |
// This function is called to cancel any outstanding asynchronous requests.
|
|
368 |
// ---------------------------------------------------------------------------
|
|
369 |
//
|
|
370 |
void CDevDiagRuntimeReqsInfo::DoCancel()
|
|
371 |
{
|
|
372 |
LOGSTRING( "CDevDiagRuntimeReqsInfo::DoCancel()" )
|
|
373 |
|
|
374 |
// Cancel the asynchronous requests.
|
|
375 |
switch ( iState )
|
|
376 |
{
|
|
377 |
case EStateCheckingBattery:
|
|
378 |
__ASSERT_DEBUG( iTelephony, Panic( EDevDiagApplicationRuntimeReqs ) );
|
|
379 |
iTelephony->CancelAsync( CTelephony::EGetBatteryInfoCancel );
|
|
380 |
break;
|
|
381 |
|
|
382 |
default:
|
|
383 |
break;
|
|
384 |
}
|
|
385 |
}
|
|
386 |
|
|
387 |
// End of File
|