51
|
1 |
/*
|
|
2 |
* Copyright (c) 2005 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: GPRS and Wlan status getter for sending Generic Alerts
|
|
15 |
*
|
|
16 |
*/
|
|
17 |
|
|
18 |
// INCLUDE FILES
|
|
19 |
|
|
20 |
//System Includes
|
|
21 |
#include <startupdomainpskeys.h> //GlobalRFsStates
|
|
22 |
#include <rconnmon.h> //RConnectionMonitor
|
|
23 |
#include <featmgr.h> //Feature Manager
|
|
24 |
#include <features.hrh> //Feature Manager
|
|
25 |
#include <cmconnectionmethoddef.h>
|
|
26 |
#include <cmmanagerext.h>
|
|
27 |
#include <cmpluginwlandef.h>
|
|
28 |
#include <cmpluginpacketdatadef.h>
|
|
29 |
|
|
30 |
//User Includes
|
|
31 |
#include "FotaServer.h"
|
|
32 |
#include "FotaNetworkRegStatus.h"
|
|
33 |
|
|
34 |
// -----------------------------------------------------------------------------
|
|
35 |
// CFotaNetworkRegStatus::NewL
|
|
36 |
// Symbian 2-Phase construction, NewL used for creating object of this class
|
|
37 |
// This method can leave
|
|
38 |
// -----------------------------------------------------------------------------
|
|
39 |
|
|
40 |
CFotaNetworkRegStatus* CFotaNetworkRegStatus::NewL(CFotaServer* aObserver)
|
|
41 |
{
|
|
42 |
CFotaNetworkRegStatus* self = CFotaNetworkRegStatus::NewLC(aObserver);
|
|
43 |
CleanupStack::Pop(self);
|
|
44 |
return self;
|
|
45 |
}
|
|
46 |
|
|
47 |
// -----------------------------------------------------------------------------
|
|
48 |
// CFotaNetworkRegStatus::NewLC
|
|
49 |
// Symbian 2-Phase construction, NewLC used for creating object of this class
|
|
50 |
// This method can leave
|
|
51 |
// -----------------------------------------------------------------------------
|
|
52 |
|
|
53 |
CFotaNetworkRegStatus* CFotaNetworkRegStatus::NewLC(CFotaServer* aObserver)
|
|
54 |
{
|
|
55 |
CFotaNetworkRegStatus* self = new (ELeave) CFotaNetworkRegStatus(
|
|
56 |
aObserver);
|
|
57 |
CleanupStack::PushL(self);
|
|
58 |
self->ConstructL();
|
|
59 |
|
|
60 |
return self;
|
|
61 |
}
|
|
62 |
|
|
63 |
// -----------------------------------------------------------------------------
|
|
64 |
// CFotaNetworkRegStatus::ConstructL
|
|
65 |
// Symbian 2-Phase construction, ConstructL used for constructing the members of this class
|
|
66 |
// This method can leave
|
|
67 |
// -----------------------------------------------------------------------------
|
|
68 |
|
|
69 |
void CFotaNetworkRegStatus::ConstructL()
|
|
70 |
{
|
|
71 |
iTimer.CreateLocal();
|
|
72 |
iMonitor.ConnectL();
|
|
73 |
}
|
|
74 |
|
|
75 |
// -----------------------------------------------------------------------------
|
|
76 |
// CFotaNetworkRegStatus::CFotaNetworkRegStatus
|
|
77 |
// C++ Constructor
|
|
78 |
// This method shouldn't leave
|
|
79 |
// -----------------------------------------------------------------------------
|
|
80 |
|
|
81 |
CFotaNetworkRegStatus::CFotaNetworkRegStatus(CFotaServer* aObserver) :
|
|
82 |
CActive(CActive::EPriorityStandard), iObserver(aObserver), iRetriesLeft(
|
|
83 |
KRetries), iGlobalRFState(EFalse)
|
|
84 |
{
|
|
85 |
CActiveScheduler::Add(this); // Add AO to current active scheduler
|
|
86 |
}
|
|
87 |
|
|
88 |
// -----------------------------------------------------------------------------
|
|
89 |
// CFotaNetworkRegStatus::~CFotaNetworkRegStatus
|
|
90 |
// C++ Desctructor
|
|
91 |
// This method shouldn't leave
|
|
92 |
// -----------------------------------------------------------------------------
|
|
93 |
|
|
94 |
CFotaNetworkRegStatus::~CFotaNetworkRegStatus()
|
|
95 |
{
|
|
96 |
Cancel();
|
|
97 |
|
|
98 |
iTimer.Close();
|
|
99 |
iMonitor.Close();
|
|
100 |
}
|
|
101 |
|
|
102 |
// -----------------------------------------------------------------------------
|
|
103 |
// CFotaNetworkRegStatus::DoCancel()
|
|
104 |
// Cancels currently active notifier, if such exists
|
|
105 |
// -----------------------------------------------------------------------------
|
|
106 |
//
|
|
107 |
void CFotaNetworkRegStatus::DoCancel()
|
|
108 |
{
|
|
109 |
FLOG(_L("CFotaNetworkRegStatus::DoCancel >>"));
|
|
110 |
|
|
111 |
if (IsActive())
|
|
112 |
{
|
|
113 |
iTimer.Cancel();
|
|
114 |
// Cancel();
|
|
115 |
}
|
|
116 |
|
|
117 |
FLOG(_L("CFotaNetworkRegStatus::DoCancel <<"));
|
|
118 |
}
|
|
119 |
|
|
120 |
// -----------------------------------------------------------------------------
|
|
121 |
// CFotaNetworkRegStatus::StartMonitoringL
|
|
122 |
// Monitors for connection status
|
|
123 |
// This method don't leave
|
|
124 |
// -----------------------------------------------------------------------------
|
|
125 |
|
|
126 |
void CFotaNetworkRegStatus::StartMonitoringL()
|
|
127 |
{
|
|
128 |
FLOG(_L("CFotaNetworkRegStatus::StartMonitoringL >>"));
|
|
129 |
|
|
130 |
//Check offline state
|
|
131 |
FLOG(_L("Check GlobalRF state..."));
|
|
132 |
if (!iGlobalRFState)
|
|
133 |
{
|
|
134 |
iGlobalRFState = CheckGlobalRFState();
|
|
135 |
}
|
|
136 |
|
|
137 |
if (iGlobalRFState)
|
|
138 |
{
|
|
139 |
//Check registration state only if iGlobalRFState is true
|
|
140 |
FLOG(_L("Check registration state..."));
|
|
141 |
if (CheckNetworkRegStateL())
|
|
142 |
{
|
|
143 |
//If both are successful report complete
|
|
144 |
FLOG(
|
|
145 |
_L("Network Registration is successful, sending Status as success to FotaServer"));
|
|
146 |
iObserver->ReportNetworkStatus(ETrue);
|
|
147 |
return;
|
|
148 |
}
|
|
149 |
}
|
|
150 |
//If one of them is not successful, start timer and retry KRetries times...
|
|
151 |
|
|
152 |
if (--iRetriesLeft >= 0)
|
|
153 |
{
|
|
154 |
FLOG(_L("Retry count... [%d]"), KRetries - iRetriesLeft);
|
|
155 |
iTimer.After(iStatus, KTimeInterval);
|
|
156 |
if (!IsActive())
|
|
157 |
SetActive();
|
|
158 |
}
|
|
159 |
else
|
|
160 |
{
|
|
161 |
FLOG(
|
|
162 |
_L("Maximum retries (%d) reached, sending Status as failure to FotaServer"),
|
|
163 |
KRetries);
|
|
164 |
iObserver->ReportNetworkStatus(IsWlanSupportedL());
|
|
165 |
}
|
|
166 |
|
|
167 |
FLOG(_L("CFotaNetworkRegStatus::StartMonitoringL <<"));
|
|
168 |
}
|
|
169 |
|
|
170 |
// -----------------------------------------------------------------------------
|
|
171 |
// CFotaNetworkRegStatus::RunL()
|
|
172 |
// Called when event accomplished
|
|
173 |
// -----------------------------------------------------------------------------
|
|
174 |
//
|
|
175 |
void CFotaNetworkRegStatus::RunL()
|
|
176 |
{
|
|
177 |
FLOG(_L("CFotaNetworkRegStatus::RunL >>"));
|
|
178 |
|
|
179 |
if (iStatus == KErrNone)
|
|
180 |
{
|
|
181 |
StartMonitoringL();
|
|
182 |
}
|
|
183 |
else
|
|
184 |
{
|
|
185 |
iObserver->ReportNetworkStatus(EFalse);
|
|
186 |
}
|
|
187 |
|
|
188 |
FLOG(_L("CFotaNetworkRegStatus::RunL <<"));
|
|
189 |
}
|
|
190 |
|
|
191 |
// -----------------------------------------------------------------------------
|
|
192 |
// CFotaNetworkRegStatus::RunError
|
|
193 |
// Called when RunL leaves
|
|
194 |
// This method can't leave
|
|
195 |
// -----------------------------------------------------------------------------
|
|
196 |
|
|
197 |
TInt CFotaNetworkRegStatus::RunError(TInt aError)
|
|
198 |
{
|
|
199 |
FLOG(_L("CFotaNetworkRegStatus::RunL >>"));
|
|
200 |
iObserver->ReportNetworkStatus(EFalse);
|
|
201 |
FLOG(_L("CFotaNetworkRegStatus::RunL <<"));
|
|
202 |
return KErrNone;
|
|
203 |
}
|
|
204 |
|
|
205 |
// -----------------------------------------------------------------------------
|
|
206 |
// CFotaNetworkRegStatus::CheckGlobalRFState
|
|
207 |
// Checks for GlobalRFState, set by Starter
|
|
208 |
// This method can't leave
|
|
209 |
// -----------------------------------------------------------------------------
|
|
210 |
|
|
211 |
TBool CFotaNetworkRegStatus::CheckGlobalRFState()
|
|
212 |
{
|
|
213 |
FLOG(_L("CFotaNetworkRegStatus::CheckGlobalRFState >>"));
|
|
214 |
|
|
215 |
RProperty prop;
|
|
216 |
TInt val = KErrNone;
|
|
217 |
TInt err = KErrNone;
|
|
218 |
TInt status = EFalse;
|
|
219 |
|
|
220 |
err = prop.Get(KPSUidStartup, KPSGlobalSystemState, val);
|
|
221 |
if (err == KErrNone && val == ESwStateNormalRfOn)
|
|
222 |
{
|
|
223 |
//Phone is not offline. Check for Network Registration status
|
|
224 |
FLOG(_L("Phone is online. Check for Network Registration status"));
|
|
225 |
status = ETrue;
|
|
226 |
}
|
|
227 |
else
|
|
228 |
{
|
|
229 |
//Phone is offline. No Network activities allowed.
|
|
230 |
FLOG(_L("Phone is offline. No Network activities allowed."));
|
|
231 |
status = EFalse;
|
|
232 |
}
|
|
233 |
FLOG(_L("CFotaNetworkRegStatus::CheckGlobalRFState, status = %d <<"),
|
|
234 |
status);
|
|
235 |
return status;
|
|
236 |
}
|
|
237 |
|
|
238 |
// -----------------------------------------------------------------------------
|
|
239 |
// CFotaNetworkRegStatus::CheckNetworkRegStatusL
|
|
240 |
// Checks for Network registration status
|
|
241 |
// This method can leave
|
|
242 |
// -----------------------------------------------------------------------------
|
|
243 |
|
|
244 |
TBool CFotaNetworkRegStatus::CheckNetworkRegStateL()
|
|
245 |
{
|
|
246 |
FLOG(_L("CFotaNetworkRegStatus::CheckNetworkRegStateL >>"));
|
|
247 |
|
|
248 |
TBool status = EFalse;
|
|
249 |
|
|
250 |
TInt registrationStatus(KErrNone);
|
|
251 |
TRequestStatus status1;
|
|
252 |
iMonitor.GetIntAttribute(EBearerIdGSM, // See bearer ids from TConnMonBearerId
|
|
253 |
0, KNetworkRegistration, registrationStatus, status1);
|
|
254 |
User::WaitForRequest(status1);
|
|
255 |
|
|
256 |
if (status1.Int() == KErrNone)
|
|
257 |
{
|
|
258 |
switch (registrationStatus)
|
|
259 |
{
|
|
260 |
case ENetworkRegistrationHomeNetwork:
|
|
261 |
case ENetworkRegistrationRoaming:
|
|
262 |
{
|
|
263 |
status = ETrue;
|
|
264 |
break;
|
|
265 |
}
|
|
266 |
default:
|
|
267 |
{
|
|
268 |
/* Includes - ENetworkRegistrationNotAvailable:
|
|
269 |
ENetworkRegistrationUnknown:
|
|
270 |
ENetworkRegistrationNoService:
|
|
271 |
ENetworkRegistrationEmergencyOnly:
|
|
272 |
ENetworkRegistrationSearching:
|
|
273 |
ENetworkRegistrationBusy:
|
|
274 |
ENetworkRegistrationDenied:*/
|
|
275 |
status = EFalse;
|
|
276 |
break;
|
|
277 |
}
|
|
278 |
}
|
|
279 |
}
|
|
280 |
|
|
281 |
FLOG(_L("CFotaNetworkRegStatus::CheckNetworkRegStateL, status = %d <<"),
|
|
282 |
status);
|
|
283 |
return status;
|
|
284 |
}
|
|
285 |
|
|
286 |
// -----------------------------------------------------------------------------
|
|
287 |
// CFotaNetworkRegStatus::IsWlanSupportedL
|
|
288 |
// Checks whether Wlan supported on device and active
|
|
289 |
// This method can leave
|
|
290 |
// -----------------------------------------------------------------------------
|
|
291 |
|
|
292 |
TBool CFotaNetworkRegStatus::IsWlanSupportedL()
|
|
293 |
{
|
|
294 |
FLOG(_L("CFotaNetworkRegStatus::IsWlanSupportedL >>"));
|
|
295 |
|
|
296 |
TBool status = EFalse;
|
|
297 |
|
|
298 |
FeatureManager::InitializeLibL();
|
|
299 |
if (FeatureManager::FeatureSupported(KFeatureIdProtocolWlan)) // check for feature enabled
|
|
300 |
{
|
|
301 |
status = ETrue;
|
|
302 |
}
|
|
303 |
|
|
304 |
FeatureManager::UnInitializeLib();
|
|
305 |
|
|
306 |
#if defined(__WINS__)
|
|
307 |
status = ETrue;
|
|
308 |
#endif
|
|
309 |
|
|
310 |
FLOG(_L("CFotaNetworkRegStatus::IsWlanSupportedL, status = %d <<"),
|
|
311 |
status);
|
|
312 |
return status;
|
|
313 |
}
|
|
314 |
|
|
315 |
// -----------------------------------------------------------------------------
|
|
316 |
// CFotaNetworkRegStatus::IsConnectionPossibleL
|
|
317 |
// Checks whether the network connection is possible in the given IAP Id
|
|
318 |
// This method can leave
|
|
319 |
// -----------------------------------------------------------------------------
|
|
320 |
/*TBool CFotaNetworkRegStatus::IsConnectionPossibleL(TInt aIapid)
|
|
321 |
{
|
|
322 |
FLOG(_L("CFotaNetworkRegStatus::IsConnectionPossibleL >>"));
|
|
323 |
TBool status(EFalse);
|
|
324 |
|
|
325 |
TUint32 bearer = FindBearerL(aIapid);
|
|
326 |
if (bearer == KUidPacketDataBearerType)
|
|
327 |
{
|
|
328 |
FLOG(_L("Bearer is Packet data"));
|
|
329 |
if (CheckGlobalRFState() && CheckNetworkRegStateL())
|
|
330 |
{
|
|
331 |
FLOG(_L("Network is up and connection is possible "));
|
|
332 |
status = ETrue;
|
|
333 |
}
|
|
334 |
else
|
|
335 |
{
|
|
336 |
FLOG(_L("Network is not up and connection is not possible "));
|
|
337 |
status = EFalse;
|
|
338 |
}
|
|
339 |
}
|
|
340 |
else if (bearer == KUidWlanBearerType)//for wlan or other bearers
|
|
341 |
{
|
|
342 |
FLOG(_L("Bearer is wlan and proceeding for download "));
|
|
343 |
//proceed & this else loop to be removed
|
|
344 |
status = ETrue;
|
|
345 |
}
|
|
346 |
else
|
|
347 |
{
|
|
348 |
FLOG(_L("Bearer is not packet data or WLAN"));
|
|
349 |
}
|
|
350 |
|
|
351 |
FLOG(_L("CFotaNetworkRegStatus::IsConnectionPossibleL, status = %d <<"),
|
|
352 |
status);
|
|
353 |
return status;
|
|
354 |
}*/
|
|
355 |
|
|
356 |
// ----------------------------------------------------------------------------------------
|
|
357 |
// CFotaDownload::FindBearerId
|
|
358 |
// Finds the Bearer Id for a given IAP Id
|
|
359 |
// ----------------------------------------------------------------------------------------
|
|
360 |
/*TUint32 CFotaNetworkRegStatus::FindBearerL(TInt aIapId)
|
|
361 |
{
|
|
362 |
FLOG(_L("CFotaNetworkRegStatus::FindBearerL: %d"), aIapId);
|
|
363 |
TUint32 bearer = 0;
|
|
364 |
TInt err(KErrNone);
|
|
365 |
// Query CM Id
|
|
366 |
TInt cmId(aIapId);
|
|
367 |
RCmManagerExt CmManagerExt;
|
|
368 |
TRAP( err, CmManagerExt.OpenL() );
|
|
369 |
FLOG(_L("CmManagerExt.OpenL() with error as %d"), err);
|
|
370 |
if (err == KErrNone)
|
|
371 |
{
|
|
372 |
RCmConnectionMethodExt cm;
|
|
373 |
TRAP( err, cm = CmManagerExt.ConnectionMethodL( cmId ) );
|
|
374 |
FLOG(_L("CmManagerExt.ConnectionMethodL with error as %d"), err);
|
|
375 |
if (err == KErrNone)
|
|
376 |
{
|
|
377 |
CleanupClosePushL(cm);
|
|
378 |
FLOG(_L("cm pushed to cleanupstack "));
|
|
379 |
bearer = cm.GetIntAttributeL(CMManager::ECmBearerType);
|
|
380 |
FLOG(_L("bearer is %d "), bearer);
|
|
381 |
CleanupStack::PopAndDestroy(); // cm
|
|
382 |
FLOG(_L("cm poped & destroyed from cleanupstack "));
|
|
383 |
}
|
|
384 |
|
|
385 |
CmManagerExt.Close();
|
|
386 |
FLOG(_L("CmManagerExt closed "));
|
|
387 |
}
|
|
388 |
FLOG(_L("CFotaNetworkRegStatus::FindBearerL end with bearer: %d"), bearer);
|
|
389 |
return bearer;
|
|
390 |
}*/
|
|
391 |
|
|
392 |
// End of File
|