13 * |
13 * |
14 * Description: |
14 * Description: |
15 * |
15 * |
16 */ |
16 */ |
17 |
17 |
|
18 // System includes |
|
19 #include <ncp_feature_settings.hrh> |
|
20 |
18 // User includes |
21 // User includes |
19 #include "cradioaccessoryobserver.h" |
22 #include "cradioaccessoryobserver.h" |
20 #include "mradioheadseteventobserver.h" |
23 #include "mradioheadseteventobserver.h" |
21 #include "cradioenginelogger.h" |
24 #include "cradioenginelogger.h" |
22 |
25 |
|
26 #ifdef ASW_CORE_AUDIO_PLATFORM_VERSION // Nokia specific adaptation |
|
27 #include <accpolpropgenericid.h> |
|
28 |
|
29 #ifndef __WINS__ |
|
30 |
|
31 const TUint KPhysicalConnectionBitmask = KPCNokiaAV | KPCWired; |
|
32 |
|
33 #else |
|
34 |
|
35 const TUint KPhysicalConnectionBitmask = 0x20000 | 0x1; |
|
36 |
|
37 #endif // __WINS__ |
|
38 |
|
39 #else |
|
40 const TUint KPhysicalConnectionBitmask = KPCWired; |
|
41 #endif // ASW_CORE_AUDIO_PLATFORM_VERSION |
|
42 |
23 // --------------------------------------------------------------------------- |
43 // --------------------------------------------------------------------------- |
24 // |
44 // |
25 // --------------------------------------------------------------------------- |
45 // --------------------------------------------------------------------------- |
26 // |
46 // |
27 CRadioAccessoryObserver::CRadioAccessoryObserver() |
47 CRadioAccessoryObserver::CRadioAccessoryObserver() |
28 : CActive( CActive::EPriorityStandard ) |
48 : CActive( CActive::EPriorityStandard ) |
29 { |
49 { |
|
50 LEVEL3( LOG_METHOD_AUTO ); |
30 } |
51 } |
31 |
52 |
32 |
53 |
33 // --------------------------------------------------------------------------- |
54 // --------------------------------------------------------------------------- |
34 // |
55 // |
35 // --------------------------------------------------------------------------- |
56 // --------------------------------------------------------------------------- |
36 // |
57 // |
37 void CRadioAccessoryObserver::ConstructL() |
58 void CRadioAccessoryObserver::ConstructL() |
38 { |
59 { |
39 LOG_METHOD_AUTO; |
60 LEVEL2( LOG_METHOD_AUTO ); |
40 User::LeaveIfError( iAccessoryServer.Connect() ); |
61 User::LeaveIfError( iAccessoryServer.Connect() ); |
41 |
62 |
42 // Creates a new sub-session within an existing session. |
63 // Creates a new sub-session within an existing session. |
43 User::LeaveIfError( iAccessoryConn.CreateSubSession( iAccessoryServer ) ); |
64 User::LeaveIfError( iAccessoryConn.CreateSubSession( iAccessoryServer ) ); |
44 User::LeaveIfError( iAccessoryConn.GetAccessoryConnectionStatus( iAccPolGenIdArr ) ); |
65 User::LeaveIfError( iAccessoryConn.GetAccessoryConnectionStatus( iAccPolGenIdArr ) ); |
45 |
66 |
46 TInt nroChangedAccessories( 0 ); |
67 TInt nroChangedAccessories( 0 ); |
47 UpdateCurrentAccessoriesL( nroChangedAccessories ); |
68 UpdateCurrentAccessoriesL( nroChangedAccessories ); |
48 LOG_FORMAT( "CRadioAccessoryObserver::ConstructL() -- Found %d wired/BT accessories ( %d accessories in total ).", |
69 LOG_FORMAT( "Found %d wired/BT accessories ( %d accessories in total ).", |
49 nroChangedAccessories, iAccPolGenIdArr.Count() ); |
70 nroChangedAccessories, iAccPolGenIdArr.Count() ); |
50 CActiveScheduler::Add( this ); |
71 CActiveScheduler::Add( this ); |
51 // Accessory is always listened |
72 // Accessory is always listened |
52 iAccessoryConn.NotifyAccessoryConnectionStatusChanged( iStatus, iAccPolGenIdArr ); |
73 iAccessoryConn.NotifyAccessoryConnectionStatusChanged( iStatus, iAccPolGenIdArr ); |
53 SetActive(); |
74 SetActive(); |
82 // |
105 // |
83 // --------------------------------------------------------------------------- |
106 // --------------------------------------------------------------------------- |
84 // |
107 // |
85 TBool CRadioAccessoryObserver::FindAccessoryL( TBool aAcceptOnlyHeadset, TAccAudioOutPutType& aOutputType ) const |
108 TBool CRadioAccessoryObserver::FindAccessoryL( TBool aAcceptOnlyHeadset, TAccAudioOutPutType& aOutputType ) const |
86 { |
109 { |
|
110 LEVEL2( LOG_METHOD_AUTO ); |
87 #ifdef __WINS__ |
111 #ifdef __WINS__ |
88 TBool accessoryFound = ETrue; |
112 TBool accessoryFound = ETrue; |
89 aAcceptOnlyHeadset = ETrue; |
113 aAcceptOnlyHeadset = ETrue; |
90 aOutputType = EAccAudioOutPutTypePrivate; |
114 aOutputType = EAccAudioOutPutTypePrivate; |
91 #else |
115 #else |
92 TBool accessoryFound = EFalse; |
116 TBool accessoryFound = EFalse; |
93 |
117 |
94 LOG_FORMAT( "CRadioAccessoryObserver::FindAccessoryL - Connected accessories count = %d", iAccPolGenIdArr.Count()); |
118 LOG_FORMAT( "Connected accessories count = %d", iAccPolGenIdArr.Count()); |
95 for ( TInt i = 0; i < iAccPolGenIdArr.Count() && !accessoryFound; i++ ) |
119 for ( TInt i = 0; i < iAccPolGenIdArr.Count() && !accessoryFound; i++ ) |
96 { |
120 { |
97 TAccPolGenericID accPolGenId = iAccPolGenIdArr.GetGenericIDL( i ); |
121 TAccPolGenericID accPolGenId = iAccPolGenIdArr.GetGenericIDL( i ); |
98 |
122 |
99 //Check if physical connection is of acceptable type |
123 //Check if physical connection is of acceptable type |
100 TUint32 physicalConnectionCaps = accPolGenId.PhysicalConnectionCaps(); |
124 TUint32 physicalConnectionCaps = accPolGenId.PhysicalConnectionCaps(); |
101 if ( physicalConnectionCaps & KPCWired || physicalConnectionCaps & KPCBluetooth ) |
125 if ( physicalConnectionCaps & KPhysicalConnectionBitmask || physicalConnectionCaps & KPCBluetooth ) |
102 { |
126 { |
103 LOG_FORMAT( "CRadioAccessoryObserver::FindAccessoryL - is wired or BT ( physicalConnectionCaps = %d )", physicalConnectionCaps ); |
127 LOG_FORMAT( "is wired or BT ( physicalConnectionCaps = %d )", physicalConnectionCaps ); |
104 |
128 |
105 if ( !aAcceptOnlyHeadset ) |
129 if ( !aAcceptOnlyHeadset ) |
106 { |
130 { |
107 accessoryFound = ETrue; |
131 accessoryFound = ETrue; |
108 } |
132 } |
109 //Get device type ( check if is HeadSet ) |
133 //Get device type ( check if is HeadSet ) |
110 TUint32 deviceType = accPolGenId.DeviceTypeCaps(); |
134 TUint32 deviceType = accPolGenId.DeviceTypeCaps(); |
111 if ( deviceType & KDTHeadset ) |
135 if ( deviceType & KDTHeadset ) |
112 { |
136 { |
113 LOG_FORMAT( "CRadioAccessoryObserver::FindAccessoryL - is HeadSet( deviceType = %d )", deviceType ); |
137 LOG_FORMAT( "is HeadSet( deviceType = %d )", deviceType ); |
114 if ( !IsLineoutConnectedL( accPolGenId ) ) |
138 if ( !IsLineoutConnectedL( accPolGenId ) ) |
115 { |
139 { |
116 LOG( "CRadioAccessoryObserver::FindAccessoryL - Is a normal headSet" ); |
140 LOG( "Is a normal headSet" ); |
117 accessoryFound = ETrue; |
141 accessoryFound = ETrue; |
118 } |
142 } |
119 } |
143 } |
120 else if ( deviceType & KDTLoopset ) |
144 else if ( deviceType & KDTLoopset ) |
121 { |
145 { |
122 LOG_FORMAT( "CRadioAccessoryObserver::FindAccessoryL - is Loopset( deviceType = %d )", deviceType ); |
146 LOG_FORMAT( "is Loopset( deviceType = %d )", deviceType ); |
123 accessoryFound = ETrue; |
147 accessoryFound = ETrue; |
124 } |
148 } |
125 else |
149 else |
126 { |
150 { |
127 LOG_FORMAT( "CRadioAccessoryObserver::FindWiredAccessoryL - is NOT HeadSet or Loopset( deviceType = %d )", deviceType ); |
151 LOG_FORMAT( "is NOT HeadSet or Loopset( deviceType = %d )", deviceType ); |
128 } |
152 } |
129 |
153 |
130 if ( accessoryFound ) |
154 if ( accessoryFound ) |
131 { |
155 { |
132 // get the public/private status |
156 // get the public/private status |
135 |
159 |
136 TAccValueTypeTInt audioOutputTypeValue; |
160 TAccValueTypeTInt audioOutputTypeValue; |
137 iAccessoryConn.GetValueL( accPolGenId, nameRecord, audioOutputTypeValue ); |
161 iAccessoryConn.GetValueL( accPolGenId, nameRecord, audioOutputTypeValue ); |
138 |
162 |
139 aOutputType = static_cast<TAccAudioOutPutType>( audioOutputTypeValue.iValue ); |
163 aOutputType = static_cast<TAccAudioOutPutType>( audioOutputTypeValue.iValue ); |
140 LOG_FORMAT( "CRadioAccessoryObserver::FindAccessoryL - AudioOutputType = %d", aOutputType ); |
164 LOG_FORMAT( "AudioOutputType = %d", aOutputType ); |
141 } |
165 } |
142 } |
166 } |
143 else |
167 else |
144 { |
168 { |
145 LOG_FORMAT( "CRadioAccessoryObserver::FindAccessoryL - is NOT wired or BT ( physicalConnectionCaps = %d )", physicalConnectionCaps ); |
169 LOG_FORMAT( "is NOT wired or BT ( physicalConnectionCaps = %d )", physicalConnectionCaps ); |
146 } |
170 } |
147 } |
171 } |
148 #endif |
172 #endif |
149 return accessoryFound; |
173 return accessoryFound; |
150 } |
174 } |
163 // |
187 // |
164 // --------------------------------------------------------------------------- |
188 // --------------------------------------------------------------------------- |
165 // |
189 // |
166 TBool CRadioAccessoryObserver::IsLineoutConnectedL( TAccPolGenericID& aAccPolGenId ) const |
190 TBool CRadioAccessoryObserver::IsLineoutConnectedL( TAccPolGenericID& aAccPolGenId ) const |
167 { |
191 { |
|
192 LEVEL2( LOG_METHOD_AUTO ); |
168 TBool isLineOut( EFalse ); |
193 TBool isLineOut( EFalse ); |
169 |
194 |
170 CAccPolSubblockNameArray* nameArray = CAccPolSubblockNameArray::NewL(); |
195 CAccPolSubblockNameArray* nameArray = CAccPolSubblockNameArray::NewL(); |
171 CleanupStack::PushL( nameArray ); |
196 CleanupStack::PushL( nameArray ); |
172 iAccessoryConn.GetSubblockNameArrayL( aAccPolGenId, *nameArray ); |
197 iAccessoryConn.GetSubblockNameArrayL( aAccPolGenId, *nameArray ); |
173 |
198 |
174 TBool isAudioOutValue = nameArray->HasName( KAccAudioOut ); |
199 TBool isAudioOutValue = nameArray->HasName( KAccAudioOut ); |
175 CleanupStack::PopAndDestroy( nameArray ); |
200 CleanupStack::PopAndDestroy( nameArray ); |
176 if ( isAudioOutValue ) |
201 if ( isAudioOutValue ) |
177 { |
202 { |
178 LOG_FORMAT( "CRadioAccessoryObserver::IsLineoutConnectedL - isAudioOutValue = ( %d )", isAudioOutValue ); |
203 LOG_FORMAT( "isAudioOutValue = ( %d )", isAudioOutValue ); |
179 |
204 |
180 TAccPolNameRecord nameRecord; |
205 TAccPolNameRecord nameRecord; |
181 nameRecord.SetNameL( KAccAudioOut ); |
206 nameRecord.SetNameL( KAccAudioOut ); |
182 |
207 |
183 //Check if connected accessory is LineOut |
208 //Check if connected accessory is LineOut |
199 // |
224 // |
200 // --------------------------------------------------------------------------- |
225 // --------------------------------------------------------------------------- |
201 // |
226 // |
202 void CRadioAccessoryObserver::UpdateCurrentAccessoriesL( TInt& aNroChangedAccessories ) |
227 void CRadioAccessoryObserver::UpdateCurrentAccessoriesL( TInt& aNroChangedAccessories ) |
203 { |
228 { |
|
229 LEVEL2( LOG_METHOD_AUTO ); |
204 // first check, the removed accessories. |
230 // first check, the removed accessories. |
205 TInt removedAccessories = CountRemovedAccessoriesL(); |
231 TInt removedAccessories = CountRemovedAccessoriesL(); |
206 LOG_FORMAT( "CRadioAccessoryObserver::UpdateCurrentAccessoriesL() -- %d accessories removed.", removedAccessories ); |
232 LOG_FORMAT( "- %d accessories removed.", removedAccessories ); |
207 aNroChangedAccessories += removedAccessories; |
233 aNroChangedAccessories += removedAccessories; |
208 TInt addedAccessories = CountAddedAccessoriesL(); |
234 TInt addedAccessories = CountAddedAccessoriesL(); |
209 LOG_FORMAT( "CRadioAccessoryObserver::UpdateCurrentAccessoriesL() -- %d accessories added.", addedAccessories ); |
235 LOG_FORMAT( "- %d accessories added.", addedAccessories ); |
210 aNroChangedAccessories += addedAccessories; |
236 aNroChangedAccessories += addedAccessories; |
211 |
237 |
212 iSavedAccessories.Reset(); |
238 iSavedAccessories.Reset(); |
213 |
239 |
214 for ( TInt i = 0; i < iAccPolGenIdArr.Count(); i++ ) |
240 for ( TInt i = 0; i < iAccPolGenIdArr.Count(); i++ ) |
215 { |
241 { |
216 iSavedAccessories.AppendL( iAccPolGenIdArr.GetGenericIDL( i ) ); |
242 iSavedAccessories.AppendL( iAccPolGenIdArr.GetGenericIDL( i ) ); |
217 LOG_FORMAT( "CRadioAccessoryObserver::UpdateCurrentAccessoriesL() -- accessory in slot %d: %d", |
243 LOG_FORMAT( "- accessory in slot %d: %d", |
218 i, iAccPolGenIdArr.GetGenericIDL( i ).UniqueID() ); |
244 i, iAccPolGenIdArr.GetGenericIDL( i ).UniqueID() ); |
219 } |
245 } |
220 LOG_FORMAT( "CRadioAccessoryObserver::UpdateCurrentAccessoriesL() -- %d accessories in total.", iSavedAccessories.Count() ); |
246 LOG_FORMAT( "- %d accessories in total.", iSavedAccessories.Count() ); |
221 } |
247 } |
222 |
248 |
223 // --------------------------------------------------------------------------- |
249 // --------------------------------------------------------------------------- |
224 // |
250 // |
225 // --------------------------------------------------------------------------- |
251 // --------------------------------------------------------------------------- |
226 // |
252 // |
227 TInt CRadioAccessoryObserver::CountRemovedAccessoriesL() const |
253 TInt CRadioAccessoryObserver::CountRemovedAccessoriesL() const |
228 { |
254 { |
|
255 LEVEL2( LOG_METHOD_AUTO ); |
229 TInt removedAccessories( 0 ); |
256 TInt removedAccessories( 0 ); |
230 |
257 |
231 for ( TInt i = 0; i < iSavedAccessories.Count(); i++ ) |
258 for ( TInt i = 0; i < iSavedAccessories.Count(); i++ ) |
232 { |
259 { |
233 TAccPolGenericID savedAcc = iSavedAccessories[i]; |
260 TAccPolGenericID savedAcc = iSavedAccessories[i]; |
234 |
261 |
235 TUint32 physicalConnectionCaps = savedAcc.PhysicalConnectionCaps(); |
262 TUint32 physicalConnectionCaps = savedAcc.PhysicalConnectionCaps(); |
236 |
263 |
237 if ( physicalConnectionCaps & KPCWired || physicalConnectionCaps & KPCBluetooth ) |
264 if ( physicalConnectionCaps & KPhysicalConnectionBitmask || physicalConnectionCaps & KPCBluetooth ) |
238 { |
265 { |
239 TBool found( EFalse ); |
266 TBool found( EFalse ); |
240 |
267 |
241 for ( TInt j = 0; j < iAccPolGenIdArr.Count() && !found; j++ ) |
268 for ( TInt j = 0; j < iAccPolGenIdArr.Count() && !found; j++ ) |
242 { |
269 { |
243 TAccPolGenericID freshAcc = iAccPolGenIdArr.GetGenericIDL( j ); |
270 TAccPolGenericID freshAcc = iAccPolGenIdArr.GetGenericIDL( j ); |
244 if ( freshAcc.UniqueID() == savedAcc.UniqueID() ) |
271 if ( freshAcc.UniqueID() == savedAcc.UniqueID() ) |
245 { |
272 { |
246 LOG_FORMAT( "CRadioAccessoryObserver::CountRemovedAccessoriesL() -- Accessory with id = %d found.", savedAcc.UniqueID() ); |
273 LOG_FORMAT( "- Accessory with id = %d found.", savedAcc.UniqueID() ); |
247 found = ETrue; |
274 found = ETrue; |
248 } |
275 } |
249 } |
276 } |
250 if ( !found ) |
277 if ( !found ) |
251 { |
278 { |
252 LOG_FORMAT( "CRadioAccessoryObserver::CountRemovedAccessoriesL() -- Accessory with id = %d removed.", savedAcc.UniqueID() ); |
279 LOG_FORMAT( "- Accessory with id = %d removed.", savedAcc.UniqueID() ); |
253 removedAccessories++; |
280 removedAccessories++; |
254 } |
281 } |
255 } |
282 } |
256 } |
283 } |
257 return removedAccessories; |
284 return removedAccessories; |
261 // |
288 // |
262 // --------------------------------------------------------------------------- |
289 // --------------------------------------------------------------------------- |
263 // |
290 // |
264 TInt CRadioAccessoryObserver::CountAddedAccessoriesL() const |
291 TInt CRadioAccessoryObserver::CountAddedAccessoriesL() const |
265 { |
292 { |
|
293 LEVEL2( LOG_METHOD_AUTO ); |
266 TInt addedAccessories( 0 ); |
294 TInt addedAccessories( 0 ); |
267 |
295 |
268 for ( TInt i = 0; i < iAccPolGenIdArr.Count(); i++ ) |
296 for ( TInt i = 0; i < iAccPolGenIdArr.Count(); i++ ) |
269 { |
297 { |
270 TAccPolGenericID freshAcc = iAccPolGenIdArr.GetGenericIDL( i ); |
298 TAccPolGenericID freshAcc = iAccPolGenIdArr.GetGenericIDL( i ); |
271 |
299 |
272 TUint32 physicalConnectionCaps = freshAcc.PhysicalConnectionCaps(); |
300 TUint32 physicalConnectionCaps = freshAcc.PhysicalConnectionCaps(); |
273 |
301 |
274 if ( physicalConnectionCaps & KPCWired || physicalConnectionCaps & KPCBluetooth ) |
302 if ( physicalConnectionCaps & KPhysicalConnectionBitmask || physicalConnectionCaps & KPCBluetooth ) |
275 { |
303 { |
276 TBool found( EFalse ); |
304 TBool found( EFalse ); |
277 |
305 |
278 for ( TInt j = 0; j < iSavedAccessories.Count() && !found; j++ ) |
306 for ( TInt j = 0; j < iSavedAccessories.Count() && !found; j++ ) |
279 { |
307 { |
280 TAccPolGenericID savedAcc = iSavedAccessories[j]; |
308 TAccPolGenericID savedAcc = iSavedAccessories[j]; |
281 if ( savedAcc.UniqueID() == freshAcc.UniqueID() ) |
309 if ( savedAcc.UniqueID() == freshAcc.UniqueID() ) |
282 { |
310 { |
283 LOG_FORMAT( "CRadioAccessoryObserver::CountAddedAccessoriesL() -- Accessory with id = %d found.", freshAcc.UniqueID() ); |
311 LOG_FORMAT( "- Accessory with id = %d found.", freshAcc.UniqueID() ); |
284 found = ETrue; |
312 found = ETrue; |
285 } |
313 } |
286 } |
314 } |
287 if ( !found ) |
315 if ( !found ) |
288 { |
316 { |
289 LOG_FORMAT( "CRadioAccessoryObserver::CountAddedAccessoriesL() -- Accessory with id = %d added.", freshAcc.UniqueID() ); |
317 LOG_FORMAT( "- Accessory with id = %d added.", freshAcc.UniqueID() ); |
290 addedAccessories++; |
318 addedAccessories++; |
291 } |
319 } |
292 } |
320 } |
293 } |
321 } |
294 return addedAccessories; |
322 return addedAccessories; |
326 { |
355 { |
327 // Accessory mode may change when combined connection status changes |
356 // Accessory mode may change when combined connection status changes |
328 // or when audio routing status changes. |
357 // or when audio routing status changes. |
329 if ( audioOutputType == EAccAudioOutPutTypePrivate ) |
358 if ( audioOutputType == EAccAudioOutPutTypePrivate ) |
330 { |
359 { |
331 LOG( "CRadioAccessoryObserver::RunL - Headset connected" ); |
360 LOG( "Headset connected" ); |
332 iObserver->HeadsetConnectedCallbackL(); |
361 iObserver->HeadsetConnectedCallbackL(); |
333 } |
362 } |
334 else |
363 else |
335 { |
364 { |
336 LOG( "CRadioAccessoryObserver::RunL - Public wired or BT accessory connected." ); |
365 LOG( "Public wired or BT accessory connected." ); |
337 iObserver->HeadsetDisconnectedCallbackL(); |
366 iObserver->HeadsetDisconnectedCallbackL(); |
338 } |
367 } |
339 } |
368 } |
340 else |
369 else |
341 { |
370 { |
342 LOG( "CRadioAccessoryObserver::RunL - No wired or BT accessories available" ); |
371 LOG( "No wired or BT accessories available" ); |
343 iObserver->HeadsetDisconnectedCallbackL(); |
372 iObserver->HeadsetDisconnectedCallbackL(); |
344 } |
373 } |
345 } |
374 } |
346 } |
375 } |
347 |
376 |