24
|
1 |
// Copyright (c) 2000-2009 Nokia Corporation and/or its subsidiary(-ies).
|
|
2 |
// All rights reserved.
|
|
3 |
// This component and the accompanying materials are made available
|
|
4 |
// under the terms of "Eclipse Public License v1.0"
|
|
5 |
// which accompanies this distribution, and is available
|
|
6 |
// at the URL "http://www.eclipse.org/legal/epl-v10.html".
|
|
7 |
//
|
|
8 |
// Initial Contributors:
|
|
9 |
// Nokia Corporation - initial contribution.
|
|
10 |
//
|
|
11 |
// Contributors:
|
|
12 |
//
|
|
13 |
// Description:
|
|
14 |
// SIGNALSTRENGHWATCHER.CPP
|
|
15 |
//
|
|
16 |
//
|
|
17 |
|
|
18 |
// User includes
|
|
19 |
#include "watcherlog.h"
|
|
20 |
#include "signalstrengthwatcher.h"
|
|
21 |
|
|
22 |
// System includes
|
|
23 |
#include <sacls.h>
|
|
24 |
|
|
25 |
#include <commsdat.h>
|
|
26 |
|
|
27 |
// In dBm
|
|
28 |
const TInt32 KSignalStrengthHigh = -51;
|
|
29 |
const TInt32 KSignalStrengthMedium = -77;
|
|
30 |
const TInt32 KSignalStrengthNone = -113;
|
|
31 |
const TInt8 KSignalZeroBars = 0;
|
|
32 |
const TInt8 KSignalThreeBars = 3;
|
|
33 |
const TInt8 KSignalFiveBars = 5;
|
|
34 |
|
|
35 |
//
|
|
36 |
// ------> Global exports
|
|
37 |
//
|
|
38 |
|
|
39 |
|
|
40 |
//
|
|
41 |
// ------> CSignalStrengthWatcher (source)
|
|
42 |
//
|
|
43 |
|
|
44 |
CSignalStrengthWatcher::CSignalStrengthWatcher()
|
|
45 |
: CPhoneWatcher()
|
|
46 |
{
|
|
47 |
}
|
|
48 |
|
|
49 |
CSignalStrengthWatcher* CSignalStrengthWatcher::NewL(TAny* /*aWatcherParams*/)
|
|
50 |
{
|
|
51 |
CSignalStrengthWatcher* self= new (ELeave) CSignalStrengthWatcher();
|
|
52 |
CleanupStack::PushL(self);
|
|
53 |
self->ConstructL();
|
|
54 |
CleanupStack::Pop();
|
|
55 |
|
|
56 |
return self;
|
|
57 |
}
|
|
58 |
|
|
59 |
void CSignalStrengthWatcher::ConstructL()
|
|
60 |
{
|
|
61 |
CWatcherBase::ConstructL();
|
|
62 |
|
|
63 |
User::LeaveIfError(iNetworkStrengthProperty.Attach(KUidSystemCategory, KUidNetworkStrength.iUid));
|
|
64 |
}
|
|
65 |
|
|
66 |
CSignalStrengthWatcher::~CSignalStrengthWatcher()
|
|
67 |
{
|
|
68 |
Cancel();
|
|
69 |
iNetworkStrengthProperty.Close();
|
|
70 |
}
|
|
71 |
|
|
72 |
//
|
|
73 |
//
|
|
74 |
//
|
|
75 |
|
|
76 |
void CSignalStrengthWatcher::HandlePhoneStateEventL(TInt aCompletionCode)
|
|
77 |
{
|
|
78 |
switch(SignalStrengthState())
|
|
79 |
{
|
|
80 |
case ESignalStrengthNotYetInitialised:
|
|
81 |
case ESignalStrengthStateRequestInitialSignalStrength:
|
|
82 |
LOGSIGNAL1("SignalStrengthWatcher : Requesting initial signal strength");
|
|
83 |
Phone().GetSignalStrength(iStatus, iSignalStrength, iSignalBars);
|
|
84 |
SignalStrengthState() = ESignalStrengthWaitingForInitialSignalStrength;
|
|
85 |
SetActive();
|
|
86 |
break;
|
|
87 |
|
|
88 |
case ESignalStrengthWaitingForInitialSignalStrength:
|
|
89 |
SignalStrengthState() = ESignalStrengthStateIssuingSignalChangeNotificationRequest;
|
|
90 |
HandleSignalStrengthUpdateL(aCompletionCode);
|
|
91 |
break;
|
|
92 |
|
|
93 |
case ESignalStrengthStateIssuingSignalChangeNotificationRequest:
|
|
94 |
HandleSignalStrengthUpdateL(aCompletionCode);
|
|
95 |
break;
|
|
96 |
|
|
97 |
default:
|
|
98 |
__ASSERT_DEBUG(0, SignalPanic(EUnexpectedState));
|
|
99 |
}
|
|
100 |
}
|
|
101 |
|
|
102 |
void CSignalStrengthWatcher::HandleCancel()
|
|
103 |
{
|
|
104 |
if (Phone().SubSessionHandle() == KNullHandle)
|
|
105 |
return;
|
|
106 |
|
|
107 |
if (SignalStrengthState() == ESignalStrengthWaitingForInitialSignalStrength)
|
|
108 |
Phone().CancelAsyncRequest(EMobilePhoneGetSignalStrength);
|
|
109 |
else if (SignalStrengthState() == ESignalStrengthStateIssuingSignalChangeNotificationRequest)
|
|
110 |
Phone().CancelAsyncRequest(EMobilePhoneNotifySignalStrengthChange);
|
|
111 |
}
|
|
112 |
|
|
113 |
void CSignalStrengthWatcher::ReleasePhoneResources()
|
|
114 |
//
|
|
115 |
// Called by the phone watcher base class. Release any telephony related
|
|
116 |
// resources and reset and state.
|
|
117 |
//
|
|
118 |
{
|
|
119 |
// This is only called within RunL and therefore we can't be active
|
|
120 |
__ASSERT_DEBUG(!IsActive(), SignalPanic(EUnexpectedActiveState));
|
|
121 |
|
|
122 |
// Reset state
|
|
123 |
iState = ESignalStrengthNotYetInitialised;
|
|
124 |
}
|
|
125 |
|
|
126 |
|
|
127 |
//
|
|
128 |
//
|
|
129 |
//
|
|
130 |
|
|
131 |
void CSignalStrengthWatcher::HandleSignalStrengthUpdateL(TInt aCompletionCode)
|
|
132 |
{
|
|
133 |
LOGSIGNAL1("SignalStrengthNotifier : Handling signal strength update");
|
|
134 |
if (aCompletionCode < KErrNone)
|
|
135 |
{
|
|
136 |
LOGSIGNAL2("SignalStrengthNotifier : Handling request error (%d)", aCompletionCode);
|
|
137 |
|
|
138 |
// Indicate we don't know what the signal strength is
|
|
139 |
TInt ret = iNetworkStrengthProperty.Set(ESANetworkStrengthUnknown);
|
|
140 |
if (!(ret == KErrNone || ret == KErrNotFound))
|
|
141 |
User::Leave(ret);
|
|
142 |
|
|
143 |
if (aCompletionCode == KErrNotSupported)
|
|
144 |
{
|
|
145 |
// If the TSY returns 'Not supported' then it isn't
|
|
146 |
// worth re-sending the request, so give up gracefully.
|
|
147 |
SetDisabled(_L("SignalStrengthNotifier : TSY returned not supported (%d)"), aCompletionCode);
|
|
148 |
}
|
|
149 |
else if (aCompletionCode == KErrCancel)
|
|
150 |
{
|
|
151 |
// Signal Strength watcher was cancelled
|
|
152 |
SetDisabled(_L("SignalStrengthNotifier : TSY has cancelled request (%d)"), aCompletionCode);
|
|
153 |
}
|
|
154 |
else if (aCompletionCode == KWatcherBaseModemNotDetected)
|
|
155 |
{
|
|
156 |
// We should release all telephony related resources until the
|
|
157 |
// phone is available again.
|
|
158 |
Cancel();
|
|
159 |
Reset();
|
|
160 |
|
|
161 |
// The modem / phone cannot be found. Wait until it becomes available again...
|
|
162 |
WaitForPhoneToPowerUpL();
|
|
163 |
}
|
|
164 |
else if (ErrorCountIncrement() >= KErrorRetryCount)
|
|
165 |
{
|
|
166 |
// We've already tried as many times as possible. Shut ourselves down forever.
|
|
167 |
// This watcher will be restarted when the machine is rebooted.
|
|
168 |
SetDisabled(_L("SignalStrengthNotifier : Max retries reached or exceeded. Shutting down until reboot."), 0);
|
|
169 |
}
|
|
170 |
else
|
|
171 |
{
|
|
172 |
// Doing this means we will asynchronously request the signal strength
|
|
173 |
// so that we can update to a real value again.
|
|
174 |
SignalStrengthState() = ESignalStrengthNotYetInitialised;
|
|
175 |
SuspendFor(KErrorRetryPausePeriod);
|
|
176 |
}
|
|
177 |
}
|
|
178 |
else
|
|
179 |
{
|
|
180 |
LOGSIGNAL2("SignalStrengthNotifier : Signal strength is: %d", (TInt) iSignalStrength);
|
|
181 |
LOGSIGNAL2("SignalStrengthNotifier : Signal bars is: %d", iSignalBars);
|
|
182 |
|
|
183 |
// What is the signal strength now?
|
|
184 |
TInt newState = ESANetworkStrengthUnknown;
|
|
185 |
// iSignalStrength is in dBm - hence use of negative numbers
|
|
186 |
if ((iSignalStrength == KSignalStrengthNone) || (iSignalBars == KSignalZeroBars))
|
|
187 |
newState = ESANetworkStrengthNone;
|
|
188 |
else if ((iSignalStrength < KSignalStrengthMedium) || (iSignalBars < KSignalThreeBars))
|
|
189 |
newState = ESANetworkStrengthLow;
|
|
190 |
else if ((iSignalStrength < KSignalStrengthHigh) || (iSignalBars < KSignalFiveBars))
|
|
191 |
newState = ESANetworkStrengthMedium;
|
|
192 |
else
|
|
193 |
newState = ESANetworkStrengthHigh;
|
|
194 |
|
|
195 |
// Update properties
|
|
196 |
LOGSIGNAL1("SignalStrengthNotifier : Informing properties of signal strength change");
|
|
197 |
TInt ret = iNetworkStrengthProperty.Set(newState);
|
|
198 |
if (!(ret == KErrNone || ret == KErrNotFound))
|
|
199 |
User::Leave(ret);
|
|
200 |
|
|
201 |
LOGSIGNAL1("SignalStrengthNotifier : Requesting signal strength change notification");
|
|
202 |
Phone().NotifySignalStrengthChange(iStatus, iSignalStrength, iSignalBars);
|
|
203 |
SetActive();
|
|
204 |
}
|
|
205 |
}
|
|
206 |
|
|
207 |
|
|
208 |
//
|
|
209 |
//
|
|
210 |
//
|
|
211 |
|
|
212 |
//
|
|
213 |
// Panic Function
|
|
214 |
//
|
|
215 |
void CSignalStrengthWatcher::SignalPanic(TWatcherPanic aPanicNumber)
|
|
216 |
{
|
|
217 |
_LIT(panicText,"Signal Strength Watcher");
|
|
218 |
User::Panic(panicText,aPanicNumber);
|
|
219 |
}
|
|
220 |
|
|
221 |
|
|
222 |
|
|
223 |
|
|
224 |
|
|
225 |
|
|
226 |
|
|
227 |
|
|
228 |
|
|
229 |
|