|
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: Base class for all notifiers for pairing purpose. |
|
15 * |
|
16 */ |
|
17 |
|
18 #ifndef SYMBIAN_ENABLE_SPLIT_HEADERS |
|
19 #include <btextnotifiers.h> |
|
20 #else |
|
21 #include <btextnotifiers.h> |
|
22 #include <btextnotifierspartner.h> // new file introduced by xSymbian |
|
23 #endif |
|
24 |
|
25 #include <utf.h> // Unicode character conversion utilities |
|
26 #include <btengconnman.h> |
|
27 #include <BTNotif.rsg> // Own resources |
|
28 #include <bluetoothuiutil.h> |
|
29 #include "btnpairnotifier.h" |
|
30 #include "btNotifDebug.h" |
|
31 #include "btnotifnameutils.h" |
|
32 |
|
33 // ---------------------------------------------------------- |
|
34 // CBTNPairNotifierBase::NewL |
|
35 // ---------------------------------------------------------- |
|
36 // |
|
37 CBTNPairNotifierBase* CBTNPairNotifierBase::NewL() |
|
38 { |
|
39 CBTNPairNotifierBase* self = new (ELeave) CBTNPairNotifierBase(); |
|
40 CleanupStack::PushL( self ); |
|
41 self->ConstructL(); |
|
42 CleanupStack::Pop( self ); |
|
43 return self; |
|
44 } |
|
45 |
|
46 // ---------------------------------------------------------- |
|
47 // CBTNPairNotifierBase Destructor |
|
48 // ---------------------------------------------------------- |
|
49 // |
|
50 CBTNPairNotifierBase::~CBTNPairNotifierBase() |
|
51 { |
|
52 } |
|
53 |
|
54 // ---------------------------------------------------------- |
|
55 // CBTNPairNotifierBase default construct |
|
56 // ---------------------------------------------------------- |
|
57 // |
|
58 CBTNPairNotifierBase::CBTNPairNotifierBase() |
|
59 :iLocallyInitiated(EFalse) |
|
60 { |
|
61 } |
|
62 |
|
63 // ---------------------------------------------------------- |
|
64 // CBTNPairNotifierBase::RegisterL |
|
65 // ---------------------------------------------------------- |
|
66 // |
|
67 CBTNPairNotifierBase::TNotifierInfo CBTNPairNotifierBase::RegisterL() |
|
68 { |
|
69 return iInfo; |
|
70 } |
|
71 |
|
72 // ---------------------------------------------------------- |
|
73 // CBTNPairNotifierBase::GetParamsL |
|
74 // ---------------------------------------------------------- |
|
75 // |
|
76 void CBTNPairNotifierBase::GetParamsL(const TDesC8& aBuffer, TInt aReplySlot, const RMessagePtr2& aMessage) |
|
77 { |
|
78 (void)aBuffer; |
|
79 if( !iMessage.IsNull() ) |
|
80 { |
|
81 User::Leave(KErrInUse); |
|
82 } |
|
83 |
|
84 iMessage = (RMessage2)aMessage; |
|
85 iReplySlot = aReplySlot; |
|
86 |
|
87 if ( AutoLockOnL() ) |
|
88 { |
|
89 // The phone is locked, access denied. |
|
90 // |
|
91 CompleteMessage(KErrCancel); |
|
92 } |
|
93 |
|
94 } |
|
95 |
|
96 // ---------------------------------------------------------- |
|
97 // CBTNPairNotifierBase::UpdateL |
|
98 // ---------------------------------------------------------- |
|
99 // |
|
100 void CBTNPairNotifierBase::UpdateL(const TDesC8& aBuffer, TInt aReplySlot, const RMessagePtr2& aMessage) |
|
101 { |
|
102 (void) aReplySlot; |
|
103 UpdateL(aBuffer); |
|
104 aMessage.Complete(KErrNone); |
|
105 } |
|
106 |
|
107 // ---------------------------------------------------------- |
|
108 // CBTNPairNotifierBase::UpdateL |
|
109 // ---------------------------------------------------------- |
|
110 // |
|
111 TPtrC8 CBTNPairNotifierBase::UpdateL( const TDesC8& aBuffer ) |
|
112 { |
|
113 FLOG(_L("[BTNOTIF]\t CBTNPairNotifierBase::UpdateL()")); |
|
114 |
|
115 TBTDeviceNameUpdateParamsPckg pckg; |
|
116 pckg.Copy( aBuffer ); |
|
117 if (pckg().Type() != TBTNotifierUpdateParams2::EDeviceName) |
|
118 { |
|
119 TPtrC8 ret(KNullDesC8); |
|
120 return (ret); |
|
121 } |
|
122 |
|
123 if (pckg().Result() == KErrNone) |
|
124 { |
|
125 BtNotifNameUtils::SetDeviceNameL(pckg().DeviceName(), *iDevice); |
|
126 |
|
127 // Finally show new prompt for dialog if it is still on the screen |
|
128 // and user has not given a alias for device. |
|
129 if( !iNotifUiUtil->IsQueryReleased() && !iDevice->IsValidFriendlyName() ) |
|
130 { |
|
131 RBuf prompt; |
|
132 prompt.CleanupClosePushL(); |
|
133 GenerateQueryPromptL( prompt ); |
|
134 iNotifUiUtil->UpdateQueryDlgL( prompt ); |
|
135 CleanupStack::PopAndDestroy( &prompt ); |
|
136 } |
|
137 } |
|
138 |
|
139 FLOG(_L("[BTNOTIF]\t CBTNPairNotifierBase::UpdateL() completed")); |
|
140 TPtrC8 ret(KNullDesC8); |
|
141 return (ret); |
|
142 } |
|
143 |
|
144 // ---------------------------------------------------------- |
|
145 // CBTNPairNotifierBase::ProcessParamsGetDeviceL |
|
146 // Get device from registry based on notifier's param |
|
147 // ---------------------------------------------------------- |
|
148 // |
|
149 void CBTNPairNotifierBase::ProcessParamsGetDeviceL( const TBTDevAddr& aAddr, const TBTDeviceName& aName ) |
|
150 { |
|
151 iDevice = CBTDevice::NewL(aAddr); |
|
152 BtNotifNameUtils::SetDeviceNameL(aName, *iDevice); |
|
153 |
|
154 // Get all properties of device from registry. |
|
155 GetDeviceFromRegL( aAddr ); |
|
156 |
|
157 #ifdef _DEBUG |
|
158 FTRACE(FPrint(_L("[BTNOTIF]\t Executing authentication... Parameters:"))); |
|
159 TBuf<12> deviceAddressString; |
|
160 aAddr.GetReadable(deviceAddressString); |
|
161 FTRACE(FPrint(_L("[BTNOTIF]\t BT Address: %S"), &deviceAddressString)); |
|
162 #endif |
|
163 } |
|
164 |
|
165 // ---------------------------------------------------------- |
|
166 // CBTNPairNotifierBase::CheckBlockedDeviceL |
|
167 // Forbid pairing from remote banned devices |
|
168 // ---------------------------------------------------------- |
|
169 // |
|
170 TBool CBTNPairNotifierBase::CheckBlockedDeviceL() |
|
171 { |
|
172 if ( !iDevice ) |
|
173 { |
|
174 User::Leave( KErrGeneral ); |
|
175 } |
|
176 |
|
177 // Do not allow pairing attempt from banned devices |
|
178 if( iDevice->GlobalSecurity().Banned() && !iLocallyInitiated ) |
|
179 { |
|
180 FLOG(_L("[BTNOTIF]\t CBTNPairNotifierBase::CheckBlockedDeviceL() Pairing attempt from banned device is denied.")); |
|
181 CompleteMessage(KErrCancel); |
|
182 return ETrue; |
|
183 } |
|
184 return EFalse; |
|
185 } |
|
186 |
|
187 // ---------------------------------------------------------- |
|
188 // CBTNPairNotifierBase::AuthoriseIncomingPairingL |
|
189 // Query user to authorise imcoming pair request or not. |
|
190 // If reject, query whether to block the remot device. |
|
191 // ---------------------------------------------------------- |
|
192 // |
|
193 TBool CBTNPairNotifierBase::AuthoriseIncomingPairingL() |
|
194 { |
|
195 FLOG(_L("[BTNOTIF]\t CBTNPairNotifierBase::AuthoriseIncomingPairingL() >>")); |
|
196 |
|
197 // Start pairing observer so that user will be informed about the result: |
|
198 TInt err = CBTEngConnMan::StartPairingObserver( iBTAddr ); |
|
199 if ( err ) |
|
200 { |
|
201 // Failed to start observer because of other ongoing pairing, |
|
202 // reject this request: |
|
203 CompleteMessage( err ); |
|
204 return EFalse; |
|
205 } |
|
206 |
|
207 TBTDeviceName devName; |
|
208 BtNotifNameUtils::GetDeviceDisplayName( devName, iDevice ); |
|
209 RBuf prompt; |
|
210 prompt.CleanupClosePushL(); |
|
211 BluetoothUiUtil::LoadResourceAndSubstringL( |
|
212 prompt, R_BT_ACCEPT_PAIRING_REQUEST, devName, 0 ); |
|
213 |
|
214 devName.Zero(); |
|
215 // Show query for use to accept/reject incoming pairing request |
|
216 TInt keypress = iNotifUiUtil->ShowQueryL( prompt, R_BT_GENERIC_QUERY, |
|
217 ECmdBTnotifUnavailable, devName, CAknQueryDialog::EConfirmationTone ); |
|
218 CleanupStack::PopAndDestroy( &prompt ); |
|
219 |
|
220 if( iMessage.IsNull() ) // cancelled by the stack |
|
221 { |
|
222 return EFalse; |
|
223 } |
|
224 else if( !keypress ) // User rejected pairing |
|
225 { |
|
226 FLOG(_L("[BTNOTIF]\t CBTNPairNotifierBase: user rejected incoming pairing")); |
|
227 // stop observer to omit pairing failure note. |
|
228 CBTEngConnMan::StopPairingObserver( iDevice->BDAddr() ); |
|
229 iDevice->SetPaired(EFalse); |
|
230 CheckAndHandleQueryIntervalL(); |
|
231 if( !iMessage.IsNull() ) |
|
232 { |
|
233 // Ask user does he/she wishes to block this device (if not canceled because the |
|
234 // frequency is too high). |
|
235 QueryBlockDeviceL(); |
|
236 } |
|
237 return EFalse; |
|
238 } |
|
239 |
|
240 FLOG(_L("[BTNOTIF]\t CBTNPairNotifierBase::AuthoriseIncomingPairingL() << ")); |
|
241 return ETrue; |
|
242 } |
|
243 |
|
244 // ---------------------------------------------------------- |
|
245 // CBTNPairNotifierBase::GenerateQueryPromptL |
|
246 // To be implemented in derived classes. |
|
247 // ---------------------------------------------------------- |
|
248 // |
|
249 void CBTNPairNotifierBase::GenerateQueryPromptL( RBuf& aRBuf ) |
|
250 { |
|
251 FLOG(_L("[BTNOTIF]\t CBTNPairNotifierBase::GenerateQueryPromptL WARNING ")); |
|
252 (void) aRBuf; |
|
253 } |