|
1 /* |
|
2 * Copyright (c) 2010 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: class for prompting user to authorize a service |
|
15 * connection request. |
|
16 * |
|
17 */ |
|
18 |
|
19 #include <hb/hbcore/hbsymbianvariant.h> |
|
20 #include <btengconnman.h> |
|
21 #include "btnotifserviceauthorizer.h" |
|
22 #include "btnotifsecuritymanager.h" |
|
23 #include "bluetoothtrace.h" |
|
24 #include "btnotifclientserver.h" |
|
25 #include "bluetoothnotification.h" |
|
26 #include "btnotifconnectiontracker.h" |
|
27 #include "btnotificationmanager.h" |
|
28 #include "bluetoothnotification.h" |
|
29 #include "btnotifserver.h" |
|
30 #include "btnotifutil.h" |
|
31 |
|
32 // |
|
33 // SDP UUID Constants - Short form |
|
34 // Taken from Bluetooth Profile specification v1.1 |
|
35 // These are used when registering the service to |
|
36 // local SDP database and when searching the service |
|
37 // information from remote device. |
|
38 const TUint KBTSdpDun = 0x1103; |
|
39 const TUint KBTSdpGenericTelephony = 0x1204; |
|
40 const TUint KBTSdpFax = 0x1111; |
|
41 const TUint KBTSdpObjectPush = 0x1105; |
|
42 const TUint KBTSdpFileTransfer = 0x1106; |
|
43 const TUint KBTSdpHeadSet = 0x1108; |
|
44 const TUint KBTSdpGenericNetworking = 0x1201; |
|
45 const TUint KBTSdpBasicImaging = 0x111b; |
|
46 |
|
47 |
|
48 CBTNotifServiceAuthorizer* CBTNotifServiceAuthorizer::NewL( |
|
49 CBTNotifSecurityManager& aParent) |
|
50 { |
|
51 CBTNotifServiceAuthorizer* me = new (ELeave) CBTNotifServiceAuthorizer(aParent); |
|
52 CleanupStack::PushL(me); |
|
53 me->ConstructL(); |
|
54 CleanupStack::Pop(me); |
|
55 return me; |
|
56 } |
|
57 |
|
58 CBTNotifServiceAuthorizer::~CBTNotifServiceAuthorizer() |
|
59 { |
|
60 iParams.Close(); |
|
61 if( iNotification ) |
|
62 { |
|
63 // Clear the notification callback, we cannot receive them anymore. |
|
64 iNotification->RemoveObserver(); |
|
65 iNotification->Close(); // Also dequeues the notification from the queue. |
|
66 iNotification = NULL; |
|
67 } |
|
68 if ( !iNotifierMessage.IsNull() ) |
|
69 { |
|
70 iNotifierMessage.Complete( KErrServerTerminated ); |
|
71 } |
|
72 } |
|
73 |
|
74 CBTNotifServiceAuthorizer::CBTNotifServiceAuthorizer( |
|
75 CBTNotifSecurityManager& aParent) |
|
76 :iParent(aParent) |
|
77 { |
|
78 } |
|
79 |
|
80 void CBTNotifServiceAuthorizer::ConstructL() |
|
81 { |
|
82 } |
|
83 |
|
84 void CBTNotifServiceAuthorizer::StartNotifierL(const RMessage2& aMessage) |
|
85 { |
|
86 if (!iNotifierMessage.IsNull()) |
|
87 { |
|
88 if(aMessage.Function() == EBTNotifCancelNotifier) |
|
89 { |
|
90 TInt err = iNotification->Close(); |
|
91 iNotifierMessage.Complete(KErrCancel); |
|
92 aMessage.Complete(err); |
|
93 return; |
|
94 } |
|
95 BOstrace0(TRACE_DEBUG,DUMMY_DEVLIST,"[BTNotif]:We are busy"); |
|
96 User::Leave(KErrServerBusy ); |
|
97 } |
|
98 |
|
99 iParams.ReAllocL( aMessage.GetDesLengthL( EBTNotifSrvParamSlot ) ); |
|
100 aMessage.ReadL( EBTNotifSrvParamSlot, iParams ); |
|
101 |
|
102 TBTAuthorisationParams params; |
|
103 TPckgC<TBTAuthorisationParams> paramsPckg( params ); |
|
104 paramsPckg.Set( iParams ); |
|
105 |
|
106 iServiceId = paramsPckg().iUid.iUid; |
|
107 |
|
108 const CBtDevExtension* dev = NULL; |
|
109 dev = iParent.BTDevRepository().Device(paramsPckg().iBDAddr); |
|
110 |
|
111 if(dev && dev->Device().GlobalSecurity().Banned() ) |
|
112 { |
|
113 // If the device is banned, service connection from |
|
114 // this device is not allowed: |
|
115 BOstrace0(TRACE_DEBUG,DUMMY_DEVLIST,"[BTNotif]:Device is banned"); |
|
116 aMessage.Complete( KErrCancel); |
|
117 return; |
|
118 } |
|
119 |
|
120 if(dev && dev->Device().GlobalSecurity().NoAuthorise()) |
|
121 { |
|
122 // If the device is a trusted one, no need to pop up query messages. |
|
123 TPckgBuf<TBool> answer; |
|
124 answer() = ETrue; |
|
125 aMessage.Write(EBTNotifSrvReplySlot, answer); |
|
126 aMessage.Complete(KErrNone); |
|
127 return; |
|
128 } |
|
129 |
|
130 // User must namually authorize this request. |
|
131 // Get needed info for the dialog: |
|
132 iPairedDevice = (dev == NULL ) ? EFalse : dev->IsUserAwareBonded(); |
|
133 iDeviceClass = (dev == NULL ) ? 0 : dev->Device().DeviceClass().DeviceClass(); |
|
134 TBTNotifUtil::GetDeviceUiNameL(iCurrentDeviceName, |
|
135 dev, paramsPckg().iName, paramsPckg().iBDAddr ); |
|
136 |
|
137 TBool autoAuthorize; |
|
138 PrepareNotificationL(autoAuthorize, |
|
139 TBluetoothDialogParams::EUserAuthorization, |
|
140 EAuthorization, iPairedDevice); |
|
141 if ( autoAuthorize ) |
|
142 { |
|
143 TPckgBuf<TBool> answer; |
|
144 answer() = ETrue; |
|
145 aMessage.Write(EBTNotifSrvReplySlot, answer); |
|
146 aMessage.Complete(KErrNone); |
|
147 } |
|
148 else |
|
149 { |
|
150 iNotification->ShowL(); |
|
151 // we do not save the message until all leavable functions have executed successfully. |
|
152 // This makes sure the iNotifierMessage has a valid handle. |
|
153 iNotifierMessage = aMessage; |
|
154 } |
|
155 } |
|
156 |
|
157 void CBTNotifServiceAuthorizer::MBRDataReceived( CHbSymbianVariantMap& aData ) |
|
158 { |
|
159 // "actionResult" will be true if the user clicks 'Yes' on the dialog and false, if he/she clicks 'No' |
|
160 // "iCheckBoxState" will be set to true of the checkbox is checked, else false. |
|
161 if(aData.Keys().MdcaPoint(0).Compare(_L("actionResult")) == 0) |
|
162 { |
|
163 TBTAuthorisationParams params; |
|
164 TPckgC<TBTAuthorisationParams> paramsPckg(params); |
|
165 paramsPckg.Set(iParams); |
|
166 |
|
167 TPckgBuf<TBool> answer; |
|
168 TInt val = *(static_cast<TInt*>(aData.Get(_L("actionResult"))->Data())); |
|
169 if(val) |
|
170 { |
|
171 answer() = ETrue; |
|
172 if(iCheckBoxState) |
|
173 { |
|
174 // Set the device "Trusted" property |
|
175 iParent.TrustDevice(paramsPckg().iBDAddr); |
|
176 } |
|
177 } |
|
178 else |
|
179 { |
|
180 answer() = EFalse; |
|
181 if(iCheckBoxState) |
|
182 { |
|
183 // If the device is paried, unpair it as well. |
|
184 if(iPairedDevice) |
|
185 { |
|
186 iParent.UnpairDevice(paramsPckg().iBDAddr); |
|
187 } |
|
188 |
|
189 //Set the device "Blocked" property |
|
190 iParent.BlockDevice(paramsPckg().iBDAddr,ETrue); |
|
191 } |
|
192 } |
|
193 if ( !iNotifierMessage.IsNull() ) |
|
194 { |
|
195 iNotifierMessage.Write(EBTNotifSrvReplySlot, answer); |
|
196 iNotifierMessage.Complete(KErrNone); |
|
197 } |
|
198 } |
|
199 else if(aData.Keys().MdcaPoint(0).Compare(_L("checkBoxState")) == 0) |
|
200 { |
|
201 iCheckBoxState = *(static_cast<TInt*>(aData.Get(_L("checkBoxState"))->Data())); |
|
202 } |
|
203 } |
|
204 |
|
205 void CBTNotifServiceAuthorizer::MBRNotificationClosed( TInt aError, const TDesC8& aData ) |
|
206 { |
|
207 (void) aError; |
|
208 (void) aData; |
|
209 iNotification->RemoveObserver(); |
|
210 iNotification = NULL; |
|
211 } |
|
212 |
|
213 void CBTNotifServiceAuthorizer::PrepareNotificationL(TBool& aAutoAuthorize, |
|
214 TBluetoothDialogParams::TBTDialogType aType, |
|
215 TBTDialogResourceId aResourceId, TBool aPaired) |
|
216 { |
|
217 iNotification = iParent.ConnectionTracker().NotificationManager()->GetNotification(); |
|
218 User::LeaveIfNull( iNotification ); // For OOM exception, leaves with KErrNoMemory |
|
219 iNotification->SetObserver( this ); |
|
220 iNotification->SetNotificationType( aType, aResourceId ); |
|
221 TInt err = KErrNone; |
|
222 aAutoAuthorize = EFalse; |
|
223 |
|
224 //Set the dialog title based on the service IDs |
|
225 switch(iServiceId) |
|
226 { |
|
227 case KBTSdpObjectPush: |
|
228 case KBTSdpBasicImaging: |
|
229 { |
|
230 if(aPaired) |
|
231 { |
|
232 err = iNotification->SetData( TBluetoothDialogParams::EDialogTitle, TBluetoothDialogParams::EReceiveFromPairedDevice); |
|
233 // In case of receiving a msg from a paired deivce, the checkbox is checked by default. |
|
234 iCheckBoxState = ETrue; |
|
235 User::LeaveIfError(err); |
|
236 } |
|
237 else |
|
238 { |
|
239 err = iNotification->SetData( TBluetoothDialogParams::EDialogTitle, TBluetoothDialogParams::EReceive); |
|
240 iCheckBoxState = EFalse; |
|
241 User::LeaveIfError(err); |
|
242 } |
|
243 } |
|
244 break; |
|
245 |
|
246 case KBTSdpFax: |
|
247 case KBTSdpDun: |
|
248 case KBTSdpFileTransfer: |
|
249 case KBTSdpHeadSet: |
|
250 case KBTSdpGenericTelephony: |
|
251 case KBTSdpGenericNetworking: |
|
252 { |
|
253 err = iNotification->SetData( TBluetoothDialogParams::EDialogTitle, TBluetoothDialogParams::EConnect); |
|
254 // In case of an incoming connection, the checkbox is checked by default. |
|
255 iCheckBoxState = ETrue; |
|
256 User::LeaveIfError(err); |
|
257 } |
|
258 break; |
|
259 |
|
260 default: |
|
261 { |
|
262 TBTAuthorisationParams params; |
|
263 TPckgC<TBTAuthorisationParams> paramsPckg(params); |
|
264 paramsPckg.Set(iParams); |
|
265 |
|
266 // In this case, if there already exists a connection to an audio device, then we simply accept |
|
267 // the incoming connection without querying the user. |
|
268 // If there is no existing connection, then we pop up a query message. |
|
269 if(IsExistingConnectionToAudioL(paramsPckg().iBDAddr)) |
|
270 { |
|
271 aAutoAuthorize = ETrue; |
|
272 return; |
|
273 } |
|
274 else |
|
275 { |
|
276 err = iNotification->SetData( TBluetoothDialogParams::EDialogTitle, TBluetoothDialogParams::EConnect); |
|
277 // In case of an incoming connection, the checkbox is checked by default. |
|
278 iCheckBoxState = ETrue; |
|
279 User::LeaveIfError(err); |
|
280 } |
|
281 } |
|
282 break; |
|
283 } |
|
284 |
|
285 //Add the device name |
|
286 err = iNotification->SetData( TBluetoothDeviceDialog::EDeviceName, iCurrentDeviceName ); |
|
287 User::LeaveIfError(err); |
|
288 //Add the device class |
|
289 err = iNotification->SetData( TBluetoothDeviceDialog::EDeviceClass, iDeviceClass ); |
|
290 User::LeaveIfError(err); |
|
291 |
|
292 } |
|
293 |
|
294 TBool CBTNotifServiceAuthorizer::IsExistingConnectionToAudioL(const TBTDevAddr& aDevAddr) |
|
295 { |
|
296 CBTEngConnMan* connMan = CBTEngConnMan::NewL(); |
|
297 TBTEngConnectionStatus conntatus(EBTEngNotConnected); |
|
298 (void) connMan->IsConnected(aDevAddr,conntatus); |
|
299 delete connMan; |
|
300 return (conntatus==EBTEngConnected || conntatus==EBTEngConnecting); |
|
301 } |
|
302 |