|
1 /* |
|
2 * Copyright (c) 2007 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: DRM Automated Usage handling |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 // INCLUDE FILES |
|
20 #include <caf/caftypes.h> |
|
21 #include <caf/data.h> |
|
22 #include <oma2agent.h> |
|
23 #include <utf.h> |
|
24 #include <drmrights.h> |
|
25 #include <drmagents.h> |
|
26 #include <e32cmn.h> |
|
27 #include <drmutility.h> |
|
28 |
|
29 #include "drmautomatedusageimpl.h" |
|
30 #include "drmautomatedusagedata.h" |
|
31 #include "drmutilityui.h" |
|
32 |
|
33 // CONSTANTS |
|
34 _LIT( KAuClassificationRingingTone, "Ringtone" ); |
|
35 _LIT( KAuClassificationVideoTone, "Videotone" ); |
|
36 |
|
37 const TInt KUrlMaxLen = 1024; |
|
38 const TInt KTimeMarginal = 5000000; // 5 seconds |
|
39 |
|
40 // FORWARD DECLARATIONS |
|
41 class CDRMConstraint; |
|
42 |
|
43 // ============================= LOCAL FUNCTIONS =============================== |
|
44 |
|
45 LOCAL_C TBool HasInterval( const CDRMConstraint *aConstraint ) |
|
46 { |
|
47 return aConstraint->iActiveConstraints & EConstraintInterval; |
|
48 } |
|
49 |
|
50 LOCAL_C TBool HasEndTime( const CDRMConstraint *aConstraint ) |
|
51 { |
|
52 return aConstraint->iActiveConstraints & EConstraintEndTime; |
|
53 } |
|
54 |
|
55 LOCAL_C TBool EndTimesEqual( const CDRMConstraint *aFirst, |
|
56 const CDRMConstraint *aSecond ) |
|
57 { |
|
58 TBool equal( EFalse ); |
|
59 TInt64 difference( aFirst->iEndTime.Int64() - aSecond->iEndTime.Int64() ); |
|
60 if( -KTimeMarginal <= difference && difference <= KTimeMarginal ) |
|
61 { |
|
62 equal = ETrue; |
|
63 } |
|
64 return equal; |
|
65 } |
|
66 |
|
67 LOCAL_C TBool IntervalsEqual( const CDRMConstraint *aFirst, |
|
68 const CDRMConstraint *aSecond ) |
|
69 { |
|
70 TBool equal( EFalse ); |
|
71 TInt64 startDifference( |
|
72 aFirst->iIntervalStart.Int64() - aSecond->iIntervalStart.Int64() ); |
|
73 |
|
74 if( aFirst->iInterval == aSecond->iInterval && |
|
75 -KTimeMarginal <= startDifference && |
|
76 startDifference <= KTimeMarginal ) |
|
77 { |
|
78 equal = ETrue; |
|
79 } |
|
80 return equal; |
|
81 } |
|
82 |
|
83 |
|
84 LOCAL_C HBufC8* GetContentIdL( const ContentAccess::CData& aData ) |
|
85 { |
|
86 HBufC* uniqueId( NULL ); |
|
87 HBufC8* uniqueId8( NULL ); |
|
88 TPtr value( NULL, 0 ); |
|
89 |
|
90 uniqueId = HBufC::NewLC( ContentAccess::KMaxCafContentName ); |
|
91 |
|
92 value.Set( uniqueId->Des() ); |
|
93 |
|
94 User::LeaveIfError( aData.GetStringAttribute( ContentAccess::EContentID, |
|
95 value ) ); |
|
96 |
|
97 uniqueId8 = CnvUtfConverter::ConvertFromUnicodeToUtf8L( value ); |
|
98 CleanupStack::PopAndDestroy( uniqueId ); |
|
99 |
|
100 return uniqueId8; |
|
101 } |
|
102 |
|
103 LOCAL_C TBool HasCountOrAccumulated( const CDRMConstraint* aConstraint ) |
|
104 { |
|
105 // constraint has counters, timed counters or accumulated |
|
106 if ( aConstraint->iActiveConstraints & ( EConstraintCounter | |
|
107 EConstraintTimedCounter | |
|
108 EConstraintAccumulated ) ) |
|
109 { |
|
110 return ETrue; |
|
111 } |
|
112 return EFalse; |
|
113 } |
|
114 |
|
115 #pragma mark - |
|
116 // ============================ MEMBER FUNCTIONS =============================== |
|
117 |
|
118 // ----------------------------------------------------------------------------- |
|
119 // DRM::CDrmAutomatedUsageImpl::CDrmAutomatedUsageImpl |
|
120 // C++ default constructor can NOT contain any code, that |
|
121 // might leave. |
|
122 // ----------------------------------------------------------------------------- |
|
123 // |
|
124 DRM::CDrmAutomatedUsageImpl::CDrmAutomatedUsageImpl( |
|
125 CCoeEnv* aCoeEnv, |
|
126 DRM::CDrmUtility* aDrmUtility ): CActive( EPriorityStandard ), |
|
127 iAuObserver( NULL ), |
|
128 iCoeEnv( aCoeEnv ), |
|
129 iDrmUtility( aDrmUtility ) |
|
130 { |
|
131 |
|
132 } |
|
133 |
|
134 // ----------------------------------------------------------------------------- |
|
135 // DRM::CDrmAutomatedUsageImpl::ConstructL |
|
136 // Symbian 2nd phase constructor can leave. |
|
137 // ----------------------------------------------------------------------------- |
|
138 // |
|
139 void DRM::CDrmAutomatedUsageImpl::ConstructL() |
|
140 { |
|
141 iDrmUtilityUi = DRM::CDrmUtilityUI::NewL( iCoeEnv ); |
|
142 |
|
143 iDrmQueue = CDrmQueue< DRM::CDrmAutomatedUsageData >::NewL(); |
|
144 |
|
145 User::LeaveIfError( iOmaClient.Connect() ); |
|
146 |
|
147 //User::LeaveIfError( iWmClient.Connect() ); |
|
148 |
|
149 User::LeaveIfError( iDrmHelperClient.Connect() ); |
|
150 } |
|
151 |
|
152 // ----------------------------------------------------------------------------- |
|
153 // DRM::CDrmAutomatedUsageImpl::NewL |
|
154 // Two-phased constructor. |
|
155 // ----------------------------------------------------------------------------- |
|
156 // |
|
157 EXPORT_C DRM::CDrmAutomatedUsageImpl* DRM::CDrmAutomatedUsageImpl::NewL( |
|
158 CCoeEnv* aCoeEnv, |
|
159 DRM::CDrmUtility* aDrmUtility ) |
|
160 { |
|
161 DRM::CDrmAutomatedUsageImpl* self( |
|
162 DRM::CDrmAutomatedUsageImpl::NewLC( aCoeEnv, |
|
163 aDrmUtility ) ); |
|
164 CleanupStack::Pop( self ); |
|
165 return self; |
|
166 } |
|
167 |
|
168 |
|
169 // ----------------------------------------------------------------------------- |
|
170 // DRM::CDrmAutomatedUsageImpl::NewLC |
|
171 // Two-phased constructor. |
|
172 // ----------------------------------------------------------------------------- |
|
173 // |
|
174 EXPORT_C DRM::CDrmAutomatedUsageImpl* DRM::CDrmAutomatedUsageImpl::NewLC( |
|
175 CCoeEnv* aCoeEnv, DRM::CDrmUtility* aDrmUtility ) |
|
176 { |
|
177 DRM::CDrmAutomatedUsageImpl* self( |
|
178 new( ELeave ) DRM::CDrmAutomatedUsageImpl( aCoeEnv, |
|
179 aDrmUtility ) ); |
|
180 CleanupStack::PushL( self ); |
|
181 self->ConstructL(); |
|
182 return self; |
|
183 } |
|
184 |
|
185 |
|
186 // Destructor |
|
187 DRM::CDrmAutomatedUsageImpl::~CDrmAutomatedUsageImpl() |
|
188 { |
|
189 DRM::CDrmAutomatedUsageData* data( iDrmQueue->PopFront() ); |
|
190 |
|
191 // Empty the queue: |
|
192 while ( data ) |
|
193 { |
|
194 // Complete the outstanding requestest with cancel |
|
195 data->iObserver->OperationCompleted( data->iOperationId, KErrCancel ); |
|
196 delete data; |
|
197 data = iDrmQueue->PopFront(); |
|
198 } |
|
199 |
|
200 delete iDrmQueue; |
|
201 |
|
202 delete iDrmUtilityUi; |
|
203 |
|
204 iDrmHelperClient.Close(); |
|
205 |
|
206 //iWmClient.Close(); |
|
207 |
|
208 iOmaClient.Close(); |
|
209 |
|
210 // Remove the object from active scheduler etc. |
|
211 if ( IsAdded() ) |
|
212 { |
|
213 Deque(); |
|
214 } |
|
215 } |
|
216 |
|
217 |
|
218 // ----------------------------------------------------------------------------- |
|
219 // DRM::CDrmAutomatedUsageImpl::CanSetAutomated |
|
220 // Implementation of file-based CanSetAutomated |
|
221 // (other items were commented in a header). |
|
222 // ----------------------------------------------------------------------------- |
|
223 // |
|
224 |
|
225 EXPORT_C TBool DRM::CDrmAutomatedUsageImpl::CanSetAutomatedL( |
|
226 RFile& aFile, |
|
227 const ContentAccess::TIntent aIntent, |
|
228 const DRM::TDrmAutomatedType aAutomatedType ) |
|
229 { |
|
230 TBool returnValue( EFalse ); |
|
231 TPtrC drmAgent( KNullDesC ); |
|
232 DRM::TDrmProtectionStatus protectedFile( DRM::EUUnknown ); |
|
233 |
|
234 returnValue = iDrmUtility->GetDrmInfoL( aFile, drmAgent, protectedFile ); |
|
235 if ( !returnValue || protectedFile == DRM::EUUnprotected ) |
|
236 { |
|
237 // not DRM file at all or not protected DRM file. |
|
238 // So can be set as automated. |
|
239 return ETrue; |
|
240 } |
|
241 if ( drmAgent == DRM::KDrmWMAgentName ) |
|
242 { |
|
243 //WMDRM not supported as automated. So no need to continue. |
|
244 return EFalse; |
|
245 } |
|
246 |
|
247 ContentAccess::CData* data( |
|
248 ContentAccess::CData::NewLC( aFile, |
|
249 ContentAccess::KDefaultContentObject, |
|
250 ContentAccess::EPeek ) ); |
|
251 |
|
252 returnValue = CanSetAutomatedL( *data, aIntent, aAutomatedType ); |
|
253 CleanupStack::PopAndDestroy( data ); |
|
254 return returnValue; |
|
255 } |
|
256 |
|
257 // ----------------------------------------------------------------------------- |
|
258 // DRM::CDrmAutomatedUsageImpl::CanSetAutomated |
|
259 // Implementation of ContentAccess::CData-based CanSetAutomated |
|
260 // (other items were commented in a header). |
|
261 // ----------------------------------------------------------------------------- |
|
262 // |
|
263 |
|
264 EXPORT_C TBool DRM::CDrmAutomatedUsageImpl::CanSetAutomatedL( |
|
265 const ContentAccess::CData& aData, |
|
266 const ContentAccess::TIntent aIntent, |
|
267 const DRM::TDrmAutomatedType aAutomatedType ) |
|
268 { |
|
269 TInt err( 0 ); |
|
270 TInt agentUid( 0 ); |
|
271 HBufC8* uniqueId8( NULL ); |
|
272 TBool canSetAutomated( EFalse ); |
|
273 TBool protectedFile( EFalse ); |
|
274 |
|
275 User::LeaveIfError( aData.GetAttribute( ContentAccess::EIsProtected, |
|
276 protectedFile ) ); |
|
277 if ( !protectedFile ) |
|
278 { |
|
279 // not protected. So can be set as automated. |
|
280 return ETrue; |
|
281 } |
|
282 |
|
283 User::LeaveIfError( aData.GetAttribute( DRM::EDrmAgentUid, agentUid ) ); |
|
284 |
|
285 if ( agentUid == DRM::EDrmWmAgent ) |
|
286 { |
|
287 //WMDRM not supported as automated. So no need to continue. |
|
288 return EFalse; |
|
289 } |
|
290 |
|
291 uniqueId8 = GetContentIdL( aData ); |
|
292 CleanupStack::PushL( uniqueId8 ); |
|
293 |
|
294 // now check whether there is OMA RO |
|
295 // suitable for automated use |
|
296 canSetAutomated = DoCanSetAutomatedL( *uniqueId8, aIntent, aAutomatedType ); |
|
297 |
|
298 if( canSetAutomated ) |
|
299 { |
|
300 TInt filetype( 0 ); |
|
301 User::LeaveIfError( aData.GetAttribute( EFileType, filetype ) ); |
|
302 if ( aIntent == ContentAccess::EPlay && filetype == EOma2Dcf ) |
|
303 { |
|
304 // If Content type == OMA2 && intent == Play |
|
305 // let's look at classification info |
|
306 TPtr value( NULL, 0 ); |
|
307 HBufC* classificationInfo( HBufC::NewLC( KUrlMaxLen ) ); |
|
308 value.Set( classificationInfo->Des() ); |
|
309 |
|
310 err = aData.GetStringAttribute( EClassificationInfo, value ); |
|
311 if( err && err != KErrCANotSupported ) |
|
312 { |
|
313 User::Leave( err ); |
|
314 } |
|
315 |
|
316 if ( classificationInfo-> |
|
317 FindF( KAuClassificationRingingTone ) == KErrNotFound && |
|
318 classificationInfo-> |
|
319 FindF( KAuClassificationVideoTone ) == KErrNotFound ) |
|
320 { |
|
321 canSetAutomated = EFalse; |
|
322 } |
|
323 CleanupStack::PopAndDestroy( classificationInfo ); |
|
324 } |
|
325 } |
|
326 |
|
327 CleanupStack::PopAndDestroy( uniqueId8 ); |
|
328 |
|
329 return canSetAutomated; |
|
330 } |
|
331 #pragma mark - |
|
332 |
|
333 // ----------------------------------------------------------------------------- |
|
334 // DRM::CDrmAutomatedUsageImpl::SetAutomatedL |
|
335 // Implementation of file-based SetAutomated |
|
336 // (other items were commented in a header). |
|
337 // ----------------------------------------------------------------------------- |
|
338 // |
|
339 EXPORT_C void DRM::CDrmAutomatedUsageImpl::SetAutomatedL( |
|
340 RFile& aFile, |
|
341 const ContentAccess::TIntent aIntent, |
|
342 const DRM::TDrmAutomatedType aAutomatedType, |
|
343 const DRM::TDrmAutomatedServiceType aServiceType ) |
|
344 { |
|
345 ContentAccess::CData* data = |
|
346 ContentAccess::CData::NewLC( aFile, |
|
347 ContentAccess::KDefaultContentObject, |
|
348 ContentAccess::EPeek ); |
|
349 SetAutomatedL( *data, aIntent, aAutomatedType, aServiceType); |
|
350 CleanupStack::PopAndDestroy( data ); |
|
351 } |
|
352 |
|
353 // ----------------------------------------------------------------------------- |
|
354 // DRM::CDrmAutomatedUsageImpl::SetAutomatedAsyncL |
|
355 // Implementation of file-based SetAutomated |
|
356 // (other items were commented in a header). |
|
357 // ----------------------------------------------------------------------------- |
|
358 // |
|
359 EXPORT_C TInt DRM::CDrmAutomatedUsageImpl::SetAutomatedAsyncL( |
|
360 RFile& aFile, |
|
361 const ContentAccess::TIntent aIntent, |
|
362 const DRM::TDrmAutomatedType aAutomatedType, |
|
363 DRM::MDrmAsyncObserver& aObserver, |
|
364 const DRM::TDrmAutomatedServiceType aServiceType ) |
|
365 { |
|
366 TInt ret( KErrNone ); |
|
367 |
|
368 ContentAccess::CData* data = |
|
369 ContentAccess::CData::NewLC( aFile, |
|
370 ContentAccess::KDefaultContentObject, |
|
371 ContentAccess::EPeek ); |
|
372 |
|
373 ret = SetAutomatedAsyncL( *data, aIntent, aAutomatedType, aObserver, aServiceType ); |
|
374 |
|
375 CleanupStack::PopAndDestroy( data ); |
|
376 |
|
377 return ret; |
|
378 } |
|
379 |
|
380 // ----------------------------------------------------------------------------- |
|
381 // DRM::CDrmAutomatedUsageImpl::SetAutomatedL |
|
382 // Implementation of ContentAccess::CData-based SetAutomated |
|
383 // (other items were commented in a header). |
|
384 // ----------------------------------------------------------------------------- |
|
385 // |
|
386 EXPORT_C void DRM::CDrmAutomatedUsageImpl::SetAutomatedL( |
|
387 const ContentAccess::CData& aData, |
|
388 const ContentAccess::TIntent aIntent, |
|
389 const DRM::TDrmAutomatedType aAutomatedType, |
|
390 const DRM::TDrmAutomatedServiceType aServiceType ) |
|
391 { |
|
392 if ( !CanSetAutomatedL( aData, aIntent, aAutomatedType ) ) |
|
393 { |
|
394 User::Leave( KErrArgument ); |
|
395 } |
|
396 |
|
397 DRM::CDrmAutomatedUsageData* data( |
|
398 DRM::CDrmAutomatedUsageData::NewLC( |
|
399 aData, |
|
400 aIntent, |
|
401 aAutomatedType, |
|
402 NULL, |
|
403 aServiceType, |
|
404 DRM::CDrmAutomatedUsageData::ESetAutomated ) ); |
|
405 |
|
406 User::LeaveIfError ( DoSetAutomatedL( data ) ); |
|
407 |
|
408 CleanupStack::PopAndDestroy( data ); |
|
409 } |
|
410 |
|
411 // ----------------------------------------------------------------------------- |
|
412 // DRM::CDrmAutomatedUsageImpl::SetAutomatedAsyncL |
|
413 // Implementation of ContentAccess::CData-based SetAutomated |
|
414 // (other items were commented in a header). |
|
415 // ----------------------------------------------------------------------------- |
|
416 // |
|
417 EXPORT_C TInt DRM::CDrmAutomatedUsageImpl::SetAutomatedAsyncL( |
|
418 const ContentAccess::CData& aData, |
|
419 const ContentAccess::TIntent aIntent, |
|
420 const DRM::TDrmAutomatedType aAutomatedType, |
|
421 DRM::MDrmAsyncObserver& aObserver, |
|
422 const DRM::TDrmAutomatedServiceType aServiceType ) |
|
423 { |
|
424 if ( !CanSetAutomatedL( aData, aIntent, aAutomatedType ) ) |
|
425 { |
|
426 User::Leave( KErrArgument ); |
|
427 } |
|
428 |
|
429 DRM::CDrmAutomatedUsageData* data( |
|
430 DRM::CDrmAutomatedUsageData::NewL( |
|
431 aData, |
|
432 aIntent, |
|
433 aAutomatedType, |
|
434 &aObserver, |
|
435 aServiceType, |
|
436 DRM::CDrmAutomatedUsageData::ESetAutomated ) ); |
|
437 |
|
438 iDrmQueue->AppendToQueueL( data ); |
|
439 |
|
440 TRequestStatus* status( &iStatus ); |
|
441 |
|
442 Activate( status ); |
|
443 |
|
444 return data->iOperationId; |
|
445 } |
|
446 |
|
447 #pragma mark - |
|
448 // ----------------------------------------------------------------------------- |
|
449 // DRM::CDrmAutomatedUsageImpl::RemoveAutomated |
|
450 // Removes content from automated use |
|
451 // (other items were commented in a header). |
|
452 // ----------------------------------------------------------------------------- |
|
453 // |
|
454 EXPORT_C void DRM::CDrmAutomatedUsageImpl::RemoveAutomatedL( |
|
455 RFile& aFile, |
|
456 const ContentAccess::TIntent aIntent, |
|
457 const DRM::TDrmAutomatedType aAutomatedType, |
|
458 const DRM::TDrmAutomatedServiceType aServiceType ) |
|
459 { |
|
460 ContentAccess::CData* data( |
|
461 ContentAccess::CData::NewLC( aFile, |
|
462 ContentAccess::KDefaultContentObject, |
|
463 ContentAccess::EPeek ) ); |
|
464 |
|
465 RemoveAutomatedL( *data, aIntent, aAutomatedType, aServiceType ); |
|
466 CleanupStack::PopAndDestroy( data ); |
|
467 } |
|
468 |
|
469 // ----------------------------------------------------------------------------- |
|
470 // DRM::CDrmAutomatedUsageImpl::RemoveAutomatedAsyncL |
|
471 // Removes content from automated use |
|
472 // (other items were commented in a header). |
|
473 // ----------------------------------------------------------------------------- |
|
474 // |
|
475 EXPORT_C TInt DRM::CDrmAutomatedUsageImpl::RemoveAutomatedAsyncL( |
|
476 RFile& aFile, |
|
477 const ContentAccess::TIntent aIntent, |
|
478 const DRM::TDrmAutomatedType aAutomatedType, |
|
479 DRM::MDrmAsyncObserver& aObserver, |
|
480 const DRM::TDrmAutomatedServiceType aServiceType ) |
|
481 { |
|
482 TInt ret( KErrNone ); |
|
483 |
|
484 ContentAccess::CData* data( |
|
485 ContentAccess::CData::NewLC( aFile, |
|
486 ContentAccess::KDefaultContentObject, |
|
487 ContentAccess::EPeek ) ); |
|
488 |
|
489 ret = RemoveAutomatedAsyncL( *data, |
|
490 aIntent, |
|
491 aAutomatedType, |
|
492 aObserver, |
|
493 aServiceType ); |
|
494 |
|
495 CleanupStack::PopAndDestroy( data ); |
|
496 return ret; |
|
497 } |
|
498 |
|
499 // ----------------------------------------------------------------------------- |
|
500 // DRM::CDrmAutomatedUsageImpl::RemoveAutomatedL |
|
501 // Removes content from automated use |
|
502 // (other items were commented in a header). |
|
503 // ----------------------------------------------------------------------------- |
|
504 // |
|
505 EXPORT_C void DRM::CDrmAutomatedUsageImpl::RemoveAutomatedL( |
|
506 const ContentAccess::CData& aData, |
|
507 const ContentAccess::TIntent aIntent, |
|
508 const DRM::TDrmAutomatedType aAutomatedType, |
|
509 const DRM::TDrmAutomatedServiceType aServiceType ) |
|
510 { |
|
511 DRM::CDrmAutomatedUsageData* data ( |
|
512 DRM::CDrmAutomatedUsageData::NewLC( |
|
513 aData, |
|
514 aIntent, |
|
515 aAutomatedType, |
|
516 NULL, |
|
517 aServiceType, |
|
518 DRM::CDrmAutomatedUsageData::ERemoveAutomated ) ); |
|
519 |
|
520 User::LeaveIfError( DoRemoveAutomated( data ) ); |
|
521 |
|
522 CleanupStack::PopAndDestroy( data ); |
|
523 } |
|
524 |
|
525 // ----------------------------------------------------------------------------- |
|
526 // DRM::CDrmAutomatedUsageImpl::RemoveAutomatedAsyncL |
|
527 // Removes content from automated use |
|
528 // (other items were commented in a header). |
|
529 // ----------------------------------------------------------------------------- |
|
530 // |
|
531 EXPORT_C TInt DRM::CDrmAutomatedUsageImpl::RemoveAutomatedAsyncL( |
|
532 const ContentAccess::CData& aData, |
|
533 const ContentAccess::TIntent aIntent, |
|
534 const DRM::TDrmAutomatedType aAutomatedType, |
|
535 DRM::MDrmAsyncObserver& aObserver, |
|
536 const DRM::TDrmAutomatedServiceType aServiceType ) |
|
537 { |
|
538 DRM::CDrmAutomatedUsageData* data( |
|
539 DRM::CDrmAutomatedUsageData::NewL( |
|
540 aData, |
|
541 aIntent, |
|
542 aAutomatedType, |
|
543 &aObserver, |
|
544 aServiceType, |
|
545 DRM::CDrmAutomatedUsageData::ERemoveAutomated ) ); |
|
546 |
|
547 iDrmQueue->AppendToQueueL( data ); |
|
548 |
|
549 TRequestStatus* status( &iStatus ); |
|
550 |
|
551 Activate( status ); |
|
552 |
|
553 return data->iOperationId; |
|
554 } |
|
555 |
|
556 // ----------------------------------------------------------------------------- |
|
557 // DRM::CDrmAutomatedUsageImpl::RemoveAutomatedL |
|
558 // Removes content from automated use |
|
559 // (other items were commented in a header). |
|
560 // ----------------------------------------------------------------------------- |
|
561 // |
|
562 EXPORT_C void DRM::CDrmAutomatedUsageImpl::RemoveAutomatedL( |
|
563 const TDesC& aUniqueId, |
|
564 const ContentAccess::TIntent aIntent, |
|
565 const DRM::TDrmAutomatedType aAutomatedType, |
|
566 const DRM::TDrmAutomatedServiceType aServiceType ) |
|
567 { |
|
568 DRM::CDrmAutomatedUsageData* data( |
|
569 DRM::CDrmAutomatedUsageData::NewLC( |
|
570 aUniqueId, |
|
571 aIntent, |
|
572 aAutomatedType, |
|
573 NULL, |
|
574 aServiceType, |
|
575 DRM::CDrmAutomatedUsageData::ERemoveAutomated ) ); |
|
576 |
|
577 User::LeaveIfError( DoRemoveAutomated( data ) ); |
|
578 |
|
579 CleanupStack::PopAndDestroy( data ); |
|
580 } |
|
581 |
|
582 // ----------------------------------------------------------------------------- |
|
583 // DRM::CDrmAutomatedUsageImpl::RemoveAutomatedAsyncL |
|
584 // Removes content from automated use |
|
585 // (other items were commented in a header). |
|
586 // ----------------------------------------------------------------------------- |
|
587 // |
|
588 EXPORT_C TInt DRM::CDrmAutomatedUsageImpl::RemoveAutomatedAsyncL( |
|
589 const TDesC& aUniqueId, |
|
590 const ContentAccess::TIntent aIntent, |
|
591 const TDrmAutomatedType aAutomatedType, |
|
592 MDrmAsyncObserver& aObserver, |
|
593 const TDrmAutomatedServiceType aServiceType ) |
|
594 { |
|
595 DRM::CDrmAutomatedUsageData* data( |
|
596 DRM::CDrmAutomatedUsageData::NewL( |
|
597 aUniqueId, |
|
598 aIntent, |
|
599 aAutomatedType, |
|
600 &aObserver, |
|
601 aServiceType, |
|
602 DRM::CDrmAutomatedUsageData::ERemoveAutomated ) ); |
|
603 |
|
604 iDrmQueue->AppendToQueueL( data ); |
|
605 |
|
606 TRequestStatus* status( &iStatus ); |
|
607 |
|
608 Activate( status ); |
|
609 |
|
610 return data->iOperationId; |
|
611 } |
|
612 |
|
613 #pragma mark - |
|
614 // ----------------------------------------------------------------------------- |
|
615 // DRM::CDrmAutomatedUsageImpl::RegisterEventObserverL |
|
616 // Registers the client to listen for automated usage events |
|
617 // (other items were commented in a header). |
|
618 // ----------------------------------------------------------------------------- |
|
619 // |
|
620 EXPORT_C void DRM::CDrmAutomatedUsageImpl::RegisterEventObserverL( |
|
621 DRM::MDrmAutomatedUsageObserver& aObserver ) |
|
622 { |
|
623 if ( iAuObserver ) |
|
624 { |
|
625 User::Leave( KErrInUse ); |
|
626 } |
|
627 iAuObserver = &aObserver; |
|
628 } |
|
629 |
|
630 // ----------------------------------------------------------------------------- |
|
631 // DRM::CDrmAutomatedUsageImpl::UnregisterEventObserverL |
|
632 // Registers the client to listen for automated usage events |
|
633 // (other items were commented in a header). |
|
634 // ----------------------------------------------------------------------------- |
|
635 // |
|
636 EXPORT_C void DRM::CDrmAutomatedUsageImpl::UnregisterEventObserverL( |
|
637 DRM::MDrmAutomatedUsageObserver& aObserver ) |
|
638 { |
|
639 if ( iAuObserver == &aObserver ) |
|
640 { |
|
641 iAuObserver=NULL; |
|
642 } |
|
643 } |
|
644 |
|
645 // ----------------------------------------------------------------------------- |
|
646 // DRM::CDrmAutomatedUsageImpl::CancelOperation |
|
647 // Cancels the async operation |
|
648 // (other items were commented in a header). |
|
649 // ----------------------------------------------------------------------------- |
|
650 EXPORT_C TInt DRM::CDrmAutomatedUsageImpl::CancelOperation( TInt aOperationId ) |
|
651 { |
|
652 TInt returnValue( KErrNotFound ); |
|
653 DRM::CDrmAutomatedUsageData* data( iDrmQueue->PopItem( aOperationId ) ); |
|
654 |
|
655 if ( data ) |
|
656 { |
|
657 data->iObserver->OperationCompleted( aOperationId, KErrCancel ); |
|
658 delete data; |
|
659 returnValue = KErrNone; |
|
660 } |
|
661 |
|
662 return returnValue; |
|
663 } |
|
664 #pragma mark - |
|
665 // ----------------------------------------------------------------------------- |
|
666 // ----------------------------------------------------------------------------- |
|
667 EXPORT_C TInt DRM::CDrmAutomatedUsageImpl::HandleErrorAsyncL( |
|
668 RFile& /* aFile */, |
|
669 ContentAccess::TIntent /* aIntent */, |
|
670 TInt /* aError */, |
|
671 DRM::MDrmHandleErrorObserver& /* aObserver */ ) |
|
672 { |
|
673 User::Leave( KErrNotSupported ); |
|
674 return KErrNotSupported; |
|
675 } |
|
676 |
|
677 // ----------------------------------------------------------------------------- |
|
678 // ----------------------------------------------------------------------------- |
|
679 EXPORT_C void DRM::CDrmAutomatedUsageImpl::HandleErrorL( |
|
680 RFile& /* aFile */, |
|
681 ContentAccess::TIntent /* aIntent */, |
|
682 TInt /* aError */, |
|
683 DRM::MDrmHandleErrorObserver* /* aObserver */ ) |
|
684 { |
|
685 User::Leave( KErrNotSupported ); |
|
686 } |
|
687 |
|
688 // ----------------------------------------------------------------------------- |
|
689 // ----------------------------------------------------------------------------- |
|
690 EXPORT_C TInt DRM::CDrmAutomatedUsageImpl::HandleErrorAsyncL( |
|
691 ContentAccess::CData& /* aFile */, |
|
692 ContentAccess::TIntent /* aIntent */, |
|
693 TInt /* aError */, |
|
694 DRM::MDrmHandleErrorObserver& /* aObserver */ ) |
|
695 { |
|
696 User::Leave( KErrNotSupported ); |
|
697 return KErrNotSupported; |
|
698 } |
|
699 |
|
700 // ----------------------------------------------------------------------------- |
|
701 // ----------------------------------------------------------------------------- |
|
702 EXPORT_C void DRM::CDrmAutomatedUsageImpl::HandleErrorL( |
|
703 ContentAccess::CData& /* aFile */, |
|
704 ContentAccess::TIntent /* aIntent */, |
|
705 TInt /* aError */, |
|
706 DRM::MDrmHandleErrorObserver* /* aObserver */ ) |
|
707 { |
|
708 } |
|
709 #pragma mark - |
|
710 |
|
711 // ----------------------------------------------------------------------------- |
|
712 // CDrmAutomatedUsageImpl::DoSetAutomatedL |
|
713 // ----------------------------------------------------------------------------- |
|
714 // |
|
715 TInt DRM::CDrmAutomatedUsageImpl::DoSetAutomatedL( |
|
716 DRM::CDrmAutomatedUsageData* aAutomatedUsageData ) |
|
717 { |
|
718 if ( DoCanSetAutomatedL( |
|
719 aAutomatedUsageData->iUniqueId8->Des(), |
|
720 aAutomatedUsageData->iIntent, |
|
721 aAutomatedUsageData->iAutomatedType, |
|
722 ETrue ) ) |
|
723 { |
|
724 return iDrmHelperClient.SetAutomated( |
|
725 aAutomatedUsageData->iUniqueId8->Des(), |
|
726 aAutomatedUsageData->iAutomatedType, |
|
727 aAutomatedUsageData->iIntent, |
|
728 aAutomatedUsageData->iServiceType ); |
|
729 } |
|
730 else |
|
731 { |
|
732 return KErrCancel; |
|
733 } |
|
734 } |
|
735 |
|
736 #pragma mark - |
|
737 |
|
738 // ----------------------------------------------------------------------------- |
|
739 // CDrmAutomatedUsageImpl::DoCanSetAutomatedL |
|
740 // ----------------------------------------------------------------------------- |
|
741 // |
|
742 TBool DRM::CDrmAutomatedUsageImpl::DoCanSetAutomatedL( |
|
743 const TDesC8& aUniqueId8, |
|
744 const ContentAccess::TIntent aIntent, |
|
745 const DRM::TDrmAutomatedType aAutomatedType, |
|
746 const TBool aUseQueries ) |
|
747 { |
|
748 TBool canSetAutomated( EFalse ); |
|
749 CDRMPermission* activePermission( NULL ); |
|
750 TUint32 rejection( KErrNone ); |
|
751 CDRMConstraint* constraint( NULL ); |
|
752 CDRMConstraint* toplevel( NULL ); |
|
753 |
|
754 // First, fetch active permission from rights server |
|
755 activePermission = iOmaClient.GetActiveRightsL( |
|
756 aIntent, aUniqueId8, rejection ); |
|
757 |
|
758 if ( !activePermission ) |
|
759 { |
|
760 // No permission found so not possible to set as automated |
|
761 return EFalse; |
|
762 } |
|
763 |
|
764 CleanupStack::PushL( activePermission ); |
|
765 |
|
766 toplevel = activePermission->TopLevelConstraint(); |
|
767 constraint = activePermission->ConstraintForIntent( aIntent ); |
|
768 |
|
769 if ( toplevel ) |
|
770 { |
|
771 constraint->Merge( *toplevel ); |
|
772 } |
|
773 |
|
774 // Active permission for given intent must have valid constraint |
|
775 // and it must not be count or accumulated time based |
|
776 canSetAutomated = !HasCountOrAccumulated( constraint ); |
|
777 |
|
778 if ( canSetAutomated && aAutomatedType == DRM::EAUAutomatedTypeTheme ) |
|
779 { |
|
780 // Automated type is theme so must check whether active RO suits |
|
781 // for theme use |
|
782 canSetAutomated = DoCanSetAutomatedThemeL( aUniqueId8 ); |
|
783 } |
|
784 |
|
785 if ( canSetAutomated && aUseQueries ) |
|
786 { |
|
787 canSetAutomated = iDrmUtilityUi->SetAutomatedQueryL( constraint ); |
|
788 } |
|
789 CleanupStack::PopAndDestroy( activePermission ); |
|
790 return canSetAutomated; |
|
791 } |
|
792 |
|
793 // ----------------------------------------------------------------------------- |
|
794 // CDrmAutomatedUsageImpl::DoCanSetAutomatedThemeL |
|
795 // ----------------------------------------------------------------------------- |
|
796 // |
|
797 TBool DRM::CDrmAutomatedUsageImpl::DoCanSetAutomatedThemeL( |
|
798 const TDesC8& aUniqueId8 ) |
|
799 { |
|
800 TBool canSetAutomatedTheme( ETrue ); |
|
801 TUint32 rejection( KErrNone ); |
|
802 CDRMPermission* playPermission( NULL ); |
|
803 CDRMConstraint* playConstraint( NULL ); |
|
804 CDRMConstraint* playToplevel( NULL ); |
|
805 |
|
806 CDRMPermission* displayPermission( NULL ); |
|
807 CDRMConstraint* displayConstraint( NULL ); |
|
808 CDRMConstraint* displayToplevel( NULL ); |
|
809 |
|
810 CDRMPermission* executePermission( NULL ); |
|
811 CDRMConstraint* executeConstraint( NULL ); |
|
812 CDRMConstraint* executeToplevel( NULL ); |
|
813 |
|
814 //Check are there active play rights |
|
815 playPermission = iOmaClient.GetActiveRightsL( |
|
816 ContentAccess::EPlay, aUniqueId8, rejection ); |
|
817 |
|
818 if( !playPermission ) |
|
819 { |
|
820 return EFalse; |
|
821 } |
|
822 |
|
823 CleanupStack::PushL( playPermission ); |
|
824 |
|
825 //Check are there active view rights |
|
826 displayPermission = iOmaClient.GetActiveRightsL( |
|
827 ContentAccess::EView, aUniqueId8, rejection ); |
|
828 |
|
829 if( !displayPermission ) |
|
830 { |
|
831 CleanupStack::PopAndDestroy( playPermission ); |
|
832 return EFalse; |
|
833 } |
|
834 |
|
835 CleanupStack::PushL( displayPermission ); |
|
836 |
|
837 //Check are there active execute rights |
|
838 executePermission = iOmaClient.GetActiveRightsL( |
|
839 ContentAccess::EExecute, aUniqueId8, rejection ); |
|
840 |
|
841 if( !executePermission ) |
|
842 { |
|
843 CleanupStack::PopAndDestroy( 2 ); //playPermission, displayPermission |
|
844 return EFalse; |
|
845 } |
|
846 |
|
847 CleanupStack::PushL( executePermission ); |
|
848 |
|
849 //If Play, View and Execute rights are valid, test constraints |
|
850 playConstraint = |
|
851 playPermission->ConstraintForIntent( ContentAccess::EPlay ); |
|
852 playToplevel = playPermission->TopLevelConstraint(); |
|
853 if ( playToplevel ) |
|
854 { |
|
855 playConstraint->Merge( *playToplevel ); |
|
856 } |
|
857 |
|
858 displayConstraint = |
|
859 displayPermission->ConstraintForIntent( ContentAccess::EView ); |
|
860 displayToplevel = displayPermission->TopLevelConstraint(); |
|
861 if ( displayToplevel ) |
|
862 { |
|
863 displayConstraint->Merge( *displayToplevel ); |
|
864 } |
|
865 |
|
866 executeConstraint = |
|
867 executePermission->ConstraintForIntent( ContentAccess::EExecute ); |
|
868 executeToplevel = executePermission->TopLevelConstraint(); |
|
869 if ( executeToplevel ) |
|
870 { |
|
871 executeConstraint->Merge( *executeToplevel ); |
|
872 } |
|
873 |
|
874 // Check that all the constraints are not statefull |
|
875 // from stateful ROs, uncactivated interval is ok. |
|
876 if ( HasCountOrAccumulated( playConstraint ) || |
|
877 HasCountOrAccumulated( displayConstraint ) || |
|
878 HasCountOrAccumulated( executeConstraint ) ) |
|
879 { |
|
880 canSetAutomatedTheme = EFalse; |
|
881 } |
|
882 |
|
883 // For end time based, end times must match |
|
884 if ( canSetAutomatedTheme && |
|
885 ( HasEndTime( playConstraint ) || |
|
886 HasEndTime( displayConstraint ) || |
|
887 HasEndTime( executeConstraint ) ) ) |
|
888 { |
|
889 canSetAutomatedTheme = |
|
890 HasEndTime( playConstraint ) && |
|
891 HasEndTime( displayConstraint ) && |
|
892 HasEndTime( executeConstraint ) && |
|
893 EndTimesEqual( playConstraint, displayConstraint ) && |
|
894 EndTimesEqual( playConstraint, executeConstraint ); |
|
895 } |
|
896 |
|
897 // For Interval based, intervals and interval activation times must match |
|
898 if ( canSetAutomatedTheme && |
|
899 ( HasInterval( playConstraint ) || |
|
900 HasInterval( displayConstraint ) || |
|
901 HasInterval( executeConstraint ) ) ) |
|
902 { |
|
903 canSetAutomatedTheme = |
|
904 HasInterval( playConstraint ) && |
|
905 HasInterval( displayConstraint ) && |
|
906 HasInterval( executeConstraint ) && |
|
907 IntervalsEqual( playConstraint, displayConstraint ) && |
|
908 IntervalsEqual( playConstraint, executeConstraint ); |
|
909 } |
|
910 |
|
911 CleanupStack::PopAndDestroy( 3 ); //playPermission, viewPermission, |
|
912 //executePermission |
|
913 |
|
914 return canSetAutomatedTheme; |
|
915 } |
|
916 |
|
917 #pragma mark - |
|
918 |
|
919 // ----------------------------------------------------------------------------- |
|
920 // CDrmAutomatedUsageImpl::DoRemoveAutomated |
|
921 // ----------------------------------------------------------------------------- |
|
922 // |
|
923 TInt DRM::CDrmAutomatedUsageImpl::DoRemoveAutomated( |
|
924 DRM::CDrmAutomatedUsageData* aAutomatedUsageData ) |
|
925 { |
|
926 return iDrmHelperClient.RemoveAutomated( |
|
927 aAutomatedUsageData->iUniqueId8->Des(), |
|
928 aAutomatedUsageData->iAutomatedType, |
|
929 aAutomatedUsageData->iIntent, |
|
930 aAutomatedUsageData->iServiceType ); |
|
931 } |
|
932 |
|
933 |
|
934 |
|
935 // ----------------------------------------------------------------------------- |
|
936 // CDrmAutomatedUsageImpl::DoCancel |
|
937 // ----------------------------------------------------------------------------- |
|
938 // |
|
939 void DRM::CDrmAutomatedUsageImpl::DoCancel() |
|
940 { |
|
941 } |
|
942 |
|
943 // ----------------------------------------------------------------------------- |
|
944 // CDrmAutomatedUsageImpl::RunL |
|
945 // ----------------------------------------------------------------------------- |
|
946 // |
|
947 void DRM::CDrmAutomatedUsageImpl::RunL() |
|
948 { |
|
949 DRM::CDrmAutomatedUsageData* data( iDrmQueue->PopFront() ); |
|
950 TRequestStatus *status( &iStatus ); |
|
951 |
|
952 if ( !data ) |
|
953 { |
|
954 return; |
|
955 } |
|
956 |
|
957 CleanupStack::PushL( data ); |
|
958 |
|
959 // Take this into the "current" variable in case an error occurs |
|
960 iObserver = data->iObserver; |
|
961 iOperationId = data->iOperationId; |
|
962 |
|
963 TInt err( KErrNone ); |
|
964 |
|
965 switch ( data->iOperation ) |
|
966 { |
|
967 case DRM::CDrmAutomatedUsageData::ESetAutomated: |
|
968 |
|
969 err = DoSetAutomatedL( data ); |
|
970 |
|
971 break; |
|
972 |
|
973 case DRM::CDrmAutomatedUsageData::ERemoveAutomated: |
|
974 |
|
975 err = DoRemoveAutomated( data ); |
|
976 |
|
977 break; |
|
978 |
|
979 default: |
|
980 |
|
981 err = KErrArgument; |
|
982 |
|
983 break; |
|
984 } |
|
985 |
|
986 iObserver->OperationCompleted( iOperationId, err ); |
|
987 |
|
988 CleanupStack::PopAndDestroy( data ); |
|
989 |
|
990 // Get ready for another round: |
|
991 SetActive(); |
|
992 |
|
993 // complete internal request: |
|
994 User::RequestComplete( status, KErrNone ); |
|
995 } |
|
996 |
|
997 // ----------------------------------------------------------------------------- |
|
998 // DRM::CDrmAutomatedUsageImpl::RunError |
|
999 // ----------------------------------------------------------------------------- |
|
1000 // |
|
1001 TInt DRM::CDrmAutomatedUsageImpl::RunError( |
|
1002 TInt aError ) |
|
1003 { |
|
1004 iObserver->OperationCompleted( iOperationId, aError ); |
|
1005 iObserver = NULL; |
|
1006 iOperationId = NULL; |
|
1007 return KErrNone; |
|
1008 } |
|
1009 |
|
1010 // ----------------------------------------------------------------------------- |
|
1011 // CDrmAutomatedUsageImpl::Activate |
|
1012 // ----------------------------------------------------------------------------- |
|
1013 // |
|
1014 void DRM::CDrmAutomatedUsageImpl::Activate( TRequestStatus*& aStatus ) |
|
1015 { |
|
1016 if ( !IsAdded() ) |
|
1017 { |
|
1018 CActiveScheduler::Add( this ); |
|
1019 } |
|
1020 |
|
1021 if ( !IsActive() ) |
|
1022 { |
|
1023 SetActive(); |
|
1024 |
|
1025 // complete internal request: |
|
1026 User::RequestComplete( aStatus, KErrNone ); |
|
1027 } |
|
1028 } |
|
1029 |
|
1030 // End of File |