|
1 /* |
|
2 * Copyright (c) 2006 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: Implementation of drm media OMA agent |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 #include <caf/rightsinfo.h> |
|
20 #ifdef CAMESE_IN_DRM_UTILITY |
|
21 #include <drmuihandling.h> |
|
22 #include <drmutility.h> |
|
23 #include <drmrightsinfo.h> |
|
24 #include <drmautomatedusage.h> |
|
25 #include <caf/data.h> |
|
26 #include <DRMRights.h> |
|
27 #include <DRMCommon.h> |
|
28 #else |
|
29 #include <DRMHelper.h> |
|
30 #endif |
|
31 #include "mpxmedia.h" |
|
32 #include "mpxmediadrmdefs.h" |
|
33 #include "mpxdrmmediaomaagent.h" |
|
34 #include "mpxlog.h" |
|
35 |
|
36 // CONSTANTS |
|
37 const TUint32 KMPXAboutToExpireCount = 3; |
|
38 const TInt KMPXAboutToExpireTime = 7; |
|
39 const TInt KMPXAboutToExpireAccTime = 15*60; // 15 minutes |
|
40 const TInt KMPXSecondsInDay = 86400; |
|
41 #ifdef CAMESE_IN_DRM_UTILITY |
|
42 const TInt KUrlMaxLen( 1024 ); // Same than in DRMHelper |
|
43 #endif |
|
44 |
|
45 |
|
46 // ----------------------------------------------------------------------------- |
|
47 // Two-phased constructor. |
|
48 // ----------------------------------------------------------------------------- |
|
49 // |
|
50 CMPXDrmMediaOmaAgent* CMPXDrmMediaOmaAgent::NewL() |
|
51 { |
|
52 MPX_FUNC("CMPXDrmMediaOmaAgent::NewL()"); |
|
53 CMPXDrmMediaOmaAgent* p = CMPXDrmMediaOmaAgent::NewLC(); |
|
54 CleanupStack::Pop(p); |
|
55 return p; |
|
56 } |
|
57 |
|
58 // ----------------------------------------------------------------------------- |
|
59 // Two-phased constructor. |
|
60 // ----------------------------------------------------------------------------- |
|
61 // |
|
62 CMPXDrmMediaOmaAgent* CMPXDrmMediaOmaAgent::NewLC() |
|
63 { |
|
64 MPX_FUNC("CMPXDrmMediaOmaAgent::NewLC()"); |
|
65 CMPXDrmMediaOmaAgent* p = new (ELeave) CMPXDrmMediaOmaAgent(); |
|
66 CleanupStack::PushL(p); |
|
67 p->ConstructL(); |
|
68 return p; |
|
69 } |
|
70 |
|
71 // ----------------------------------------------------------------------------- |
|
72 // Destructor |
|
73 // ----------------------------------------------------------------------------- |
|
74 // |
|
75 CMPXDrmMediaOmaAgent::~CMPXDrmMediaOmaAgent() |
|
76 { |
|
77 MPX_FUNC("CMPXDrmMediaOmaAgent::~CMPXDrmMediaOmaAgent()"); |
|
78 Close(); |
|
79 #ifdef CAMESE_IN_DRM_UTILITY |
|
80 delete iDrmHandler; |
|
81 |
|
82 if ( iDRMCommon ) |
|
83 { |
|
84 iDRMCommon->Disconnect(); |
|
85 } |
|
86 delete iDRMCommon; |
|
87 #else |
|
88 delete iDrmHelper; |
|
89 #endif |
|
90 iFs.Close(); |
|
91 } |
|
92 |
|
93 // ----------------------------------------------------------------------------- |
|
94 // Default constructor |
|
95 // ----------------------------------------------------------------------------- |
|
96 // |
|
97 CMPXDrmMediaOmaAgent::CMPXDrmMediaOmaAgent() |
|
98 { |
|
99 MPX_FUNC("CMPXDrmMediaOmaAgent::CMPXDrmMediaOmaAgent()"); |
|
100 } |
|
101 |
|
102 // ---------------------------------------------------------------------------- |
|
103 // 2nd phase constructor. |
|
104 // ---------------------------------------------------------------------------- |
|
105 // |
|
106 void CMPXDrmMediaOmaAgent::ConstructL() |
|
107 { |
|
108 MPX_FUNC("CMPXDrmMediaOmaAgent::ConstructL()"); |
|
109 |
|
110 User::LeaveIfError( iFs.Connect() ); |
|
111 #ifdef CAMESE_IN_DRM_UTILITY |
|
112 iDrmHandler = DRM::CDrmUiHandling::NewL(); |
|
113 |
|
114 iDRMCommon = DRMCommon::NewL(); |
|
115 User::LeaveIfError( iDRMCommon->Connect() ); |
|
116 #else |
|
117 iDrmHelper = CDRMHelper::NewL(); |
|
118 #endif |
|
119 } |
|
120 |
|
121 |
|
122 // ---------------------------------------------------------------------------- |
|
123 // Initialize utility using a filename |
|
124 // ---------------------------------------------------------------------------- |
|
125 // |
|
126 void CMPXDrmMediaOmaAgent::InitL( const TDesC& aFileName ) |
|
127 { |
|
128 MPX_DEBUG2("CMPXDrmMediaOmaAgent::InitL(%S) entering", &aFileName ); |
|
129 |
|
130 Close(); |
|
131 CreateMediaL(); |
|
132 iData = CData::NewL( |
|
133 (TVirtualPathPtr) aFileName, |
|
134 EPeek, |
|
135 EContentShareReadOnly ); |
|
136 User::LeaveIfError( iFile.Open( iFs, aFileName, EFileShareReadersOrWriters )); |
|
137 |
|
138 MPX_DEBUG1("CMPXDrmMediaOmaAgent::InitL() exiting" ); |
|
139 } |
|
140 |
|
141 // ---------------------------------------------------------------------------- |
|
142 // Initialize utility using a file handle |
|
143 // ---------------------------------------------------------------------------- |
|
144 // |
|
145 void CMPXDrmMediaOmaAgent::InitL( RFile& aFile ) |
|
146 { |
|
147 MPX_DEBUG1("CMPXDrmMediaOmaAgent::InitL(RFile) entering" ); |
|
148 |
|
149 Close(); |
|
150 CreateMediaL(); |
|
151 iData = CData::NewL( |
|
152 aFile, |
|
153 KDefaultContentObject(), |
|
154 EPeek ); |
|
155 User::LeaveIfError( iFile.Duplicate( aFile ) ); |
|
156 |
|
157 MPX_DEBUG1("CMPXDrmMediaOmaAgent::InitL(RFile) exiting" ); |
|
158 } |
|
159 |
|
160 // ---------------------------------------------------------------------------- |
|
161 // Gets media object with the given attributes |
|
162 // ---------------------------------------------------------------------------- |
|
163 // |
|
164 const CMPXMedia& CMPXDrmMediaOmaAgent::GetMediaL( TUint aAttributes ) |
|
165 { |
|
166 MPX_DEBUG2("CMPXDrmMediaOmaAgent::GetMediaL(%d) entering", aAttributes ); |
|
167 |
|
168 if ( iMedia ) |
|
169 { |
|
170 if ( aAttributes & KMPXMediaDrmProtected.iAttributeId ) |
|
171 { |
|
172 GetProtectedL(); |
|
173 } |
|
174 if (( aAttributes & KMPXMediaDrmRightsStatus.iAttributeId ) || |
|
175 ( aAttributes & KMPXMediaDrmSendingAllowed.iAttributeId )) |
|
176 { |
|
177 GetRightsDetailsL(); |
|
178 } |
|
179 if ( aAttributes & KMPXMediaDrmRightsType.iAttributeId ) |
|
180 { |
|
181 GetRightsTypeL(); |
|
182 } |
|
183 if ( aAttributes & KMPXMediaDrmCount.iAttributeId ) |
|
184 { |
|
185 GetCountL(); |
|
186 } |
|
187 if ( aAttributes & KMPXMediaDrmStartTime.iAttributeId ) |
|
188 { |
|
189 GetStartTimeL(); |
|
190 } |
|
191 if ( aAttributes & KMPXMediaDrmEndTime.iAttributeId ) |
|
192 { |
|
193 GetEndTimeL(); |
|
194 } |
|
195 if ( aAttributes & KMPXMediaDrmInterval.iAttributeId ) |
|
196 { |
|
197 GetIntervalL(); |
|
198 } |
|
199 if ( aAttributes & KMPXMediaDrmIntervalStartTime.iAttributeId ) |
|
200 { |
|
201 GetIntervalStartTimeL(); |
|
202 } |
|
203 if ( aAttributes & KMPXMediaDrmAccumulatedTime.iAttributeId ) |
|
204 { |
|
205 GetAccumulatedTimeL(); |
|
206 } |
|
207 if ( aAttributes & KMPXMediaDrmCanSetAutomated.iAttributeId ) |
|
208 { |
|
209 GetCanSetAutomatedL(); |
|
210 } |
|
211 if ( aAttributes & KMPXMediaDrmHasInfoUrl.iAttributeId ) |
|
212 { |
|
213 GetHasInfoUrlL(); |
|
214 } |
|
215 if ( aAttributes & KMPXMediaDrmHasPreviewUrl.iAttributeId ) |
|
216 { |
|
217 GetHasPreviewUrlL(); |
|
218 } |
|
219 if ( aAttributes & KMPXMediaDrmAboutToExpire.iAttributeId ) |
|
220 { |
|
221 GetAboutToExpireL(); |
|
222 } |
|
223 } |
|
224 |
|
225 MPX_DEBUG1("CMPXDrmMediaOmaAgent::GetMediaL() exiting" ); |
|
226 return *iMedia; |
|
227 } |
|
228 |
|
229 // ---------------------------------------------------------------------------- |
|
230 // Consumes the rights for the current media according |
|
231 // to the specified consume type |
|
232 // ---------------------------------------------------------------------------- |
|
233 // |
|
234 void CMPXDrmMediaOmaAgent::ConsumeL( TDrmConsumeType aType ) |
|
235 { |
|
236 MPX_DEBUG1("CMPXDrmMediaOmaAgent::ConsumeL() entering"); |
|
237 #ifdef CAMESE_IN_DRM_UTILITY |
|
238 // ConsumeL is not used at the moment |
|
239 ASSERT(0); |
|
240 User::Leave( KErrNotSupported ); |
|
241 #else |
|
242 if ( iMedia ) |
|
243 { |
|
244 CDRMHelper::TDRMHelperConsumeAction action( CDRMHelper::EStart ); |
|
245 switch ( aType ) |
|
246 { |
|
247 case ( EMPXDrmConsumeStart ): |
|
248 { |
|
249 action = CDRMHelper::EStart; |
|
250 break; |
|
251 } |
|
252 case ( EMPXDrmConsumePause ): |
|
253 { |
|
254 action = CDRMHelper::EPause; |
|
255 break; |
|
256 } |
|
257 case ( EMPXDrmConsumeContinue ): |
|
258 { |
|
259 action = CDRMHelper::EContinue; |
|
260 break; |
|
261 } |
|
262 case ( EMPXDrmConsumeFinish ): |
|
263 { |
|
264 action = CDRMHelper::EFinish; |
|
265 break; |
|
266 } |
|
267 default: |
|
268 { |
|
269 break; |
|
270 } |
|
271 } |
|
272 |
|
273 User::LeaveIfError( iDrmHelper->ConsumeFile2( |
|
274 iFile, |
|
275 ContentAccess::EPlay, |
|
276 action )); |
|
277 } |
|
278 #endif |
|
279 MPX_DEBUG1("CMPXDrmMediaOmaAgent::ConsumeL() exiting" ); |
|
280 } |
|
281 |
|
282 // ---------------------------------------------------------------------------- |
|
283 // Closes and uninitializes the agent and cleans up member variables |
|
284 // ---------------------------------------------------------------------------- |
|
285 // |
|
286 void CMPXDrmMediaOmaAgent::Close() |
|
287 { |
|
288 MPX_DEBUG1("CXMPXDrmMediaOmaAgent::Close() entering"); |
|
289 |
|
290 CMPXDrmMediaAgent::Close(); |
|
291 delete iRightsConstraints; |
|
292 iRightsConstraints = NULL; |
|
293 iFile.Close(); |
|
294 |
|
295 MPX_DEBUG1("CXMPXDrmMediaOmaAgent::Close() exiting"); |
|
296 } |
|
297 |
|
298 // ---------------------------------------------------------------------------- |
|
299 // Creates a new media object |
|
300 // ---------------------------------------------------------------------------- |
|
301 // |
|
302 void CMPXDrmMediaOmaAgent::CreateMediaL() |
|
303 { |
|
304 MPX_DEBUG1("CXMPXDrmMediaOmaAgent::CreateMediaL() entering"); |
|
305 |
|
306 CMPXDrmMediaAgent::CreateMediaL(); |
|
307 |
|
308 // Set the type to OMA |
|
309 iMedia->SetTObjectValueL( KMPXMediaDrmType, EMPXDrmTypeOMA ); |
|
310 |
|
311 MPX_DEBUG1("CXMPXDrmMediaOmaAgent::CreateMediaL() exiting"); |
|
312 } |
|
313 |
|
314 // ---------------------------------------------------------------------------- |
|
315 // Gets the rights details |
|
316 // ---------------------------------------------------------------------------- |
|
317 // |
|
318 void CMPXDrmMediaOmaAgent::GetRightsDetailsL() |
|
319 { |
|
320 MPX_DEBUG1("CXMPXDrmMediaOmaAgent::GetRightsDetailsL() entering"); |
|
321 |
|
322 if ( !iMedia->IsSupported( KMPXMediaDrmRightsStatus ) || |
|
323 !iMedia->IsSupported( KMPXMediaDrmSendingAllowed )) |
|
324 { |
|
325 #ifdef CAMESE_IN_DRM_UTILITY |
|
326 TBool expired( EFalse ); |
|
327 TBool sendingAllowed( ETrue ); |
|
328 HBufC* contentURI = NULL; |
|
329 HBufC8* contentURI8 = NULL; |
|
330 CDRMRights* activeRights = NULL; |
|
331 |
|
332 // Get forwardable status from CAF |
|
333 User::LeaveIfError( iData->GetAttribute( EIsForwardable, sendingAllowed ) ) ; |
|
334 |
|
335 // Get constraints. Copied from CDRMHelper::GetRightsDetailsL |
|
336 contentURI = HBufC::NewLC( KUrlMaxLen ); |
|
337 TPtr ptr = contentURI->Des(); |
|
338 User::LeaveIfError( iData->GetStringAttribute( EContentID, ptr ) ); |
|
339 |
|
340 contentURI8 = HBufC8::NewLC( contentURI->Length() ); |
|
341 contentURI8->Des().Copy( contentURI->Des() ); |
|
342 |
|
343 // GetActiveRights returns negative value if rights are not valid |
|
344 if ( iDRMCommon->GetActiveRights( *contentURI8, ContentAccess::EPlay, activeRights ) > 0 ) |
|
345 { |
|
346 // rights are valid |
|
347 activeRights->GetPlayRight( iRightsConstraints ); |
|
348 } |
|
349 else |
|
350 { |
|
351 expired = ETrue; |
|
352 } |
|
353 CleanupStack::PopAndDestroy( 2 ); // contentURI8, contentURI |
|
354 #else |
|
355 TInt error( KErrNone ); |
|
356 TBool expired( EFalse ); |
|
357 TBool sendingAllowed( ETrue ); |
|
358 CDRMHelperRightsConstraints* ignore1( NULL ); |
|
359 CDRMHelperRightsConstraints* ignore2( NULL ); |
|
360 CDRMHelperRightsConstraints* ignore3( NULL ); |
|
361 delete iRightsConstraints; |
|
362 iRightsConstraints = NULL; |
|
363 |
|
364 TRAP( error, iDrmHelper->GetRightsDetailsL( |
|
365 iFile, |
|
366 ContentAccess::EPlay, |
|
367 expired, |
|
368 sendingAllowed, |
|
369 iRightsConstraints, |
|
370 ignore1, |
|
371 ignore2, |
|
372 ignore3 )); |
|
373 delete ignore1; |
|
374 delete ignore2; |
|
375 delete ignore3; |
|
376 #endif |
|
377 |
|
378 if ( expired ) |
|
379 { |
|
380 iMedia->SetTObjectValueL( KMPXMediaDrmRightsStatus, |
|
381 EMPXDrmRightsExpired ); |
|
382 } |
|
383 else if ( iRightsConstraints ) |
|
384 { |
|
385 if ( iRightsConstraints->IsPreview() ) |
|
386 { |
|
387 iMedia->SetTObjectValueL( KMPXMediaDrmRightsStatus, |
|
388 EMPXDrmRightsPreview ); |
|
389 } |
|
390 else if ( iRightsConstraints->FullRights() ) |
|
391 { |
|
392 iMedia->SetTObjectValueL( KMPXMediaDrmRightsStatus, |
|
393 EMPXDrmRightsFull ); |
|
394 } |
|
395 else |
|
396 { |
|
397 iMedia->SetTObjectValueL( KMPXMediaDrmRightsStatus, |
|
398 EMPXDrmRightsRestricted ); |
|
399 } |
|
400 } |
|
401 else |
|
402 { |
|
403 // Not expired, no constraints object obtainable, |
|
404 // so check if it's protected |
|
405 if ( !iMedia->IsSupported( KMPXMediaDrmProtected )) |
|
406 { |
|
407 GetProtectedL(); |
|
408 } |
|
409 TBool prot( iMedia->ValueTObjectL<TBool>( KMPXMediaDrmProtected )); |
|
410 if ( prot ) |
|
411 { |
|
412 iMedia->SetTObjectValueL( KMPXMediaDrmRightsStatus, |
|
413 EMPXDrmRightsMissing ); |
|
414 } |
|
415 else |
|
416 { |
|
417 iMedia->SetTObjectValueL( KMPXMediaDrmRightsStatus, |
|
418 EMPXDrmRightsFull ); |
|
419 } |
|
420 } |
|
421 |
|
422 iMedia->SetTObjectValueL( KMPXMediaDrmSendingAllowed, |
|
423 sendingAllowed ); |
|
424 } |
|
425 |
|
426 MPX_DEBUG1("CXMPXDrmMediaOmaAgent::GetRightsDetailsL() exiting"); |
|
427 } |
|
428 |
|
429 // ---------------------------------------------------------------------------- |
|
430 // Gets the rights type attribute if not already obtained |
|
431 // ---------------------------------------------------------------------------- |
|
432 // |
|
433 void CMPXDrmMediaOmaAgent::GetRightsTypeL() |
|
434 { |
|
435 MPX_DEBUG1("CXMPXDrmMediaOmaAgent::GetRightsTypeL() entering"); |
|
436 |
|
437 if ( !iMedia->IsSupported( KMPXMediaDrmRightsType )) |
|
438 { |
|
439 // Check if it's protected or not first |
|
440 if ( !iMedia->IsSupported( KMPXMediaDrmProtected )) |
|
441 { |
|
442 GetProtectedL(); |
|
443 } |
|
444 TBool prot( iMedia->ValueTObjectL<TBool>( KMPXMediaDrmProtected )); |
|
445 if ( !prot ) |
|
446 { |
|
447 iMedia->SetTObjectValueL( KMPXMediaDrmRightsType, |
|
448 EMPXDrmRightsTypeNoRestriction ); |
|
449 } |
|
450 else |
|
451 { |
|
452 // Else it's a protected file, so get the rights constraints |
|
453 if ( !iRightsConstraints ) |
|
454 { |
|
455 GetRightsDetailsL(); |
|
456 } |
|
457 |
|
458 // Check if it's a count based rights |
|
459 GetCountL(); |
|
460 if ( !iMedia->IsSupported( KMPXMediaDrmCount )) |
|
461 { |
|
462 // Check if it's time based |
|
463 GetStartTimeL(); |
|
464 if ( !iMedia->IsSupported( KMPXMediaDrmStartTime )) |
|
465 { |
|
466 // Check if it's interval based |
|
467 GetIntervalL(); |
|
468 if ( !iMedia->IsSupported( KMPXMediaDrmInterval )) |
|
469 { |
|
470 // Check if it's accumulated time based |
|
471 GetAccumulatedTimeL(); |
|
472 if ( !iMedia->IsSupported( KMPXMediaDrmAccumulatedTime )) |
|
473 { |
|
474 // not have any of the restriction types |
|
475 iMedia->SetTObjectValueL( |
|
476 KMPXMediaDrmRightsType, |
|
477 EMPXDrmRightsTypeNoRestriction ); |
|
478 } // else not accumulated time |
|
479 } // else not interval |
|
480 } // else not time based |
|
481 } // else not count based |
|
482 } // else protected file |
|
483 } |
|
484 |
|
485 MPX_DEBUG1("CXMPXDrmMediaOmaAgent::GetRightsTypeL() exiting"); |
|
486 } |
|
487 |
|
488 // ---------------------------------------------------------------------------- |
|
489 // Gets the count attribute if not already obtained |
|
490 // ---------------------------------------------------------------------------- |
|
491 // |
|
492 void CMPXDrmMediaOmaAgent::GetCountL() |
|
493 { |
|
494 MPX_DEBUG1("CXMPXDrmMediaOmaAgent::GetCountL() entering"); |
|
495 |
|
496 // Do not need to check if it already supported, we |
|
497 // just overwrite the old value if possible |
|
498 if ( !iRightsConstraints ) |
|
499 { |
|
500 GetRightsDetailsL(); |
|
501 } |
|
502 if ( iRightsConstraints ) |
|
503 { |
|
504 TUint32 countLeft( 0 ); |
|
505 TUint32 originalCount( 0 ); |
|
506 TUint32 timedCount( 0 ); |
|
507 #ifdef CAMESE_IN_DRM_UTILITY |
|
508 // Logic copied from CDRMHelperRightsConstraints |
|
509 |
|
510 TInt error1 = iRightsConstraints->GetCounters( countLeft, originalCount ); |
|
511 |
|
512 TBool timedCounter = EFalse; |
|
513 if ( ( iRightsConstraints->GetConstraint()).iActiveConstraints & |
|
514 EConstraintTimedCounter ) |
|
515 { |
|
516 timedCount = ( iRightsConstraints->GetConstraint()).iTimedCounter; |
|
517 timedCounter = ETrue; |
|
518 } |
|
519 |
|
520 if ( timedCounter ) |
|
521 { |
|
522 iMedia->SetTObjectValueL( KMPXMediaDrmRightsType, |
|
523 EMPXDrmRightsTypeTimeCount ); |
|
524 if ( error1 != DRMCommon::ENoRights ) |
|
525 { |
|
526 countLeft = Min( countLeft, timedCount ); |
|
527 } |
|
528 else |
|
529 { |
|
530 countLeft = timedCount; |
|
531 } |
|
532 iMedia->SetTObjectValueL( KMPXMediaDrmCount, |
|
533 countLeft ); |
|
534 MPX_DEBUG2("CXMPXDrmMediaOmaAgent::GetCountL(): count = %d", countLeft); |
|
535 } |
|
536 else if ( error1 != DRMCommon::ENoRights ) |
|
537 { |
|
538 iMedia->SetTObjectValueL( KMPXMediaDrmRightsType, |
|
539 EMPXDrmRightsTypeCount ); |
|
540 iMedia->SetTObjectValueL( KMPXMediaDrmCount, |
|
541 countLeft ); |
|
542 MPX_DEBUG2("CXMPXDrmMediaOmaAgent::GetCountL(): count = %d", countLeft); |
|
543 } |
|
544 #else |
|
545 TTimeIntervalSeconds ignoreTime; |
|
546 TRAPD( error1, iRightsConstraints->GetCountersL( |
|
547 countLeft, |
|
548 originalCount )); |
|
549 TRAPD( error2, iRightsConstraints->GetTimedCountL( |
|
550 timedCount, |
|
551 originalCount, |
|
552 ignoreTime )); |
|
553 if ( KErrNone == error2 ) |
|
554 { |
|
555 iMedia->SetTObjectValueL( KMPXMediaDrmRightsType, |
|
556 EMPXDrmRightsTypeTimeCount ); |
|
557 if ( KErrNone == error1 ) |
|
558 { |
|
559 countLeft = Min( countLeft, timedCount ); |
|
560 } |
|
561 else |
|
562 { |
|
563 countLeft = timedCount; |
|
564 } |
|
565 iMedia->SetTObjectValueL( KMPXMediaDrmCount, |
|
566 countLeft ); |
|
567 MPX_DEBUG2("CXMPXDrmMediaOmaAgent::GetCountL(): count = %d", countLeft); |
|
568 } |
|
569 else if ( KErrNone == error1 ) |
|
570 { |
|
571 iMedia->SetTObjectValueL( KMPXMediaDrmRightsType, |
|
572 EMPXDrmRightsTypeCount ); |
|
573 iMedia->SetTObjectValueL( KMPXMediaDrmCount, |
|
574 countLeft ); |
|
575 MPX_DEBUG2("CXMPXDrmMediaOmaAgent::GetCountL(): count = %d", countLeft); |
|
576 } |
|
577 #endif |
|
578 } |
|
579 |
|
580 MPX_DEBUG1("CXMPXDrmMediaOmaAgent::GetCountL() exiting"); |
|
581 } |
|
582 |
|
583 // ---------------------------------------------------------------------------- |
|
584 // Gets the start time attribute if not already obtained |
|
585 // ---------------------------------------------------------------------------- |
|
586 // |
|
587 void CMPXDrmMediaOmaAgent::GetStartTimeL() |
|
588 { |
|
589 MPX_DEBUG1("CXMPXDrmMediaOmaAgent::GetStartTimeL() entering"); |
|
590 |
|
591 if ( !iMedia->IsSupported( KMPXMediaDrmStartTime )) |
|
592 { |
|
593 if ( !iRightsConstraints ) |
|
594 { |
|
595 GetRightsDetailsL(); |
|
596 } |
|
597 if ( iRightsConstraints ) |
|
598 { |
|
599 TTime startTime; |
|
600 #ifdef CAMESE_IN_DRM_UTILITY |
|
601 if( iRightsConstraints->GetStartTime( startTime ) != DRMCommon::ENoRights ) |
|
602 #else |
|
603 TRAPD( error, iRightsConstraints->GetStartTimeL( startTime )); |
|
604 if ( KErrNone == error ) |
|
605 #endif |
|
606 { |
|
607 iMedia->SetTObjectValueL( KMPXMediaDrmRightsType, |
|
608 EMPXDrmRightsTypeTime ); |
|
609 iMedia->SetTObjectValueL( KMPXMediaDrmStartTime, |
|
610 startTime.Int64() ); |
|
611 MPX_DEBUG1("CXMPXDrmMediaOmaAgent::GetCountL(): setting start time"); |
|
612 } |
|
613 } |
|
614 } |
|
615 |
|
616 MPX_DEBUG1("CXMPXDrmMediaOmaAgent::GetStartTimeL() exiting"); |
|
617 } |
|
618 |
|
619 // ---------------------------------------------------------------------------- |
|
620 // Gets the end time attribute if not already obtained |
|
621 // ---------------------------------------------------------------------------- |
|
622 // |
|
623 void CMPXDrmMediaOmaAgent::GetEndTimeL() |
|
624 { |
|
625 MPX_DEBUG1("CXMPXDrmMediaOmaAgent::GetEndTimeL() entering"); |
|
626 |
|
627 if ( !iMedia->IsSupported( KMPXMediaDrmEndTime )) |
|
628 { |
|
629 if ( !iRightsConstraints ) |
|
630 { |
|
631 GetRightsDetailsL(); |
|
632 } |
|
633 if ( iRightsConstraints ) |
|
634 { |
|
635 TTime endTime; |
|
636 #ifdef CAMESE_IN_DRM_UTILITY |
|
637 if( iRightsConstraints->GetEndTime( endTime ) != DRMCommon::ENoRights ) |
|
638 #else |
|
639 TRAPD( error, iRightsConstraints->GetEndTimeL( endTime )); |
|
640 if ( KErrNone == error ) |
|
641 #endif |
|
642 { |
|
643 iMedia->SetTObjectValueL( KMPXMediaDrmRightsType, |
|
644 EMPXDrmRightsTypeTime ); |
|
645 iMedia->SetTObjectValueL( KMPXMediaDrmEndTime, |
|
646 endTime.Int64() ); |
|
647 MPX_DEBUG1("CXMPXDrmMediaOmaAgent::GetCountL(): setting end time"); |
|
648 } |
|
649 } |
|
650 } |
|
651 |
|
652 MPX_DEBUG1("CXMPXDrmMediaOmaAgent::GetEndTimeL() exiting"); |
|
653 } |
|
654 |
|
655 // ---------------------------------------------------------------------------- |
|
656 // Gets the interval attribute if not already obtained |
|
657 // ---------------------------------------------------------------------------- |
|
658 // |
|
659 void CMPXDrmMediaOmaAgent::GetIntervalL() |
|
660 { |
|
661 MPX_DEBUG1("CXMPXDrmMediaOmaAgent::GetIntervalL() entering"); |
|
662 |
|
663 if ( !iMedia->IsSupported( KMPXMediaDrmInterval )) |
|
664 { |
|
665 if ( !iRightsConstraints ) |
|
666 { |
|
667 GetRightsDetailsL(); |
|
668 } |
|
669 if ( iRightsConstraints ) |
|
670 { |
|
671 TTimeIntervalSeconds interval; |
|
672 #ifdef CAMESE_IN_DRM_UTILITY |
|
673 if( iRightsConstraints->GetInterval( interval ) != DRMCommon::ENoRights ) |
|
674 #else |
|
675 TRAPD( error, iRightsConstraints->GetIntervalL( interval )); |
|
676 if ( KErrNone == error ) |
|
677 #endif |
|
678 { |
|
679 iMedia->SetTObjectValueL( KMPXMediaDrmRightsType, |
|
680 EMPXDrmRightsTypeInterval ); |
|
681 iMedia->SetTObjectValueL( KMPXMediaDrmInterval, |
|
682 interval ); |
|
683 MPX_DEBUG1("CXMPXDrmMediaOmaAgent::GetCountL(): setting interval"); |
|
684 } |
|
685 } |
|
686 } |
|
687 |
|
688 MPX_DEBUG1("CXMPXDrmMediaOmaAgent::GetIntervalL() exiting"); |
|
689 } |
|
690 |
|
691 // ---------------------------------------------------------------------------- |
|
692 // Gets the interval start time attribute if not already obtained |
|
693 // ---------------------------------------------------------------------------- |
|
694 // |
|
695 void CMPXDrmMediaOmaAgent::GetIntervalStartTimeL() |
|
696 { |
|
697 MPX_DEBUG1("CXMPXDrmMediaOmaAgent::GetIntervalStartTimeL() entering"); |
|
698 |
|
699 if ( !iMedia->IsSupported( KMPXMediaDrmIntervalStartTime )) |
|
700 { |
|
701 if ( !iRightsConstraints ) |
|
702 { |
|
703 GetRightsDetailsL(); |
|
704 } |
|
705 if ( iRightsConstraints ) |
|
706 { |
|
707 TTime intervalStart; |
|
708 #ifdef CAMESE_IN_DRM_UTILITY |
|
709 if( iRightsConstraints->GetIntervalStart( intervalStart ) != DRMCommon::ENoRights ) |
|
710 #else |
|
711 TRAPD( error, iRightsConstraints->GetIntervalStartL( |
|
712 intervalStart )); |
|
713 if ( KErrNone == error ) |
|
714 #endif |
|
715 { |
|
716 iMedia->SetTObjectValueL( KMPXMediaDrmIntervalStartTime, |
|
717 intervalStart.Int64() ); |
|
718 MPX_DEBUG1("CXMPXDrmMediaOmaAgent::GetCountL(): setting interval start time"); |
|
719 } |
|
720 } |
|
721 } |
|
722 |
|
723 MPX_DEBUG1("CXMPXDrmMediaOmaAgent::GetIntervalStartTimeL() exiting"); |
|
724 } |
|
725 |
|
726 // ---------------------------------------------------------------------------- |
|
727 // Gets the accumlated time attribute if not already obtained |
|
728 // ---------------------------------------------------------------------------- |
|
729 // |
|
730 void CMPXDrmMediaOmaAgent::GetAccumulatedTimeL() |
|
731 { |
|
732 MPX_DEBUG1("CXMPXDrmMediaOmaAgent::GetAccumulatedTimeL() entering"); |
|
733 |
|
734 if ( !iMedia->IsSupported( KMPXMediaDrmAccumulatedTime )) |
|
735 { |
|
736 if ( !iRightsConstraints ) |
|
737 { |
|
738 GetRightsDetailsL(); |
|
739 } |
|
740 if ( iRightsConstraints ) |
|
741 { |
|
742 #ifdef CAMESE_IN_DRM_UTILITY |
|
743 // Copied from DRMHelper::GetAccumulatedTimeL |
|
744 if ((iRightsConstraints->GetConstraint()).iActiveConstraints & |
|
745 EConstraintAccumulated ) |
|
746 { |
|
747 TTimeIntervalSeconds time = |
|
748 (iRightsConstraints->GetConstraint()).iAccumulatedTime; |
|
749 #else |
|
750 TTimeIntervalSeconds time; |
|
751 TRAPD( error, iRightsConstraints->GetAccumulatedTimeL( time )); |
|
752 if ( KErrNone == error ) |
|
753 { |
|
754 #endif |
|
755 iMedia->SetTObjectValueL( KMPXMediaDrmRightsType, |
|
756 EMPXDrmRightsTypeAccTime ); |
|
757 iMedia->SetTObjectValueL( KMPXMediaDrmAccumulatedTime, |
|
758 time ); |
|
759 MPX_DEBUG1("CXMPXDrmMediaOmaAgent::GetCountL(): setting accumulated time"); |
|
760 } |
|
761 } |
|
762 } |
|
763 |
|
764 MPX_DEBUG1("CXMPXDrmMediaOmaAgent::GetAccumulatedTimeL() exiting"); |
|
765 } |
|
766 |
|
767 // ---------------------------------------------------------------------------- |
|
768 // Gets the can set automated attribute if not already obtained |
|
769 // ---------------------------------------------------------------------------- |
|
770 // |
|
771 void CMPXDrmMediaOmaAgent::GetCanSetAutomatedL() |
|
772 { |
|
773 MPX_DEBUG1("CXMPXDrmMediaOmaAgent::GetCanSetAutomatedL() entering"); |
|
774 |
|
775 if ( !iMedia->IsSupported( KMPXMediaDrmCanSetAutomated )) |
|
776 { |
|
777 TBool canSetAutomated( ETrue ); |
|
778 |
|
779 #ifdef CAMESE_IN_DRM_UTILITY |
|
780 DRM::CDrmAutomatedUsage* drmAutomatedUsage = DRM::CDrmAutomatedUsage::NewLC(); |
|
781 |
|
782 TRAP_IGNORE( |
|
783 canSetAutomated = drmAutomatedUsage->CanSetAutomatedL( iFile, |
|
784 ContentAccess::EPlay, DRM::EAUAutomatedTypeRingingTone ); |
|
785 ); |
|
786 CleanupStack::PopAndDestroy( drmAutomatedUsage ); |
|
787 |
|
788 iMedia->SetTObjectValueL( KMPXMediaDrmCanSetAutomated, canSetAutomated ); |
|
789 #else |
|
790 iDrmHelper->CanSetAutomated( iFile, canSetAutomated ); |
|
791 iMedia->SetTObjectValueL( KMPXMediaDrmCanSetAutomated, |
|
792 canSetAutomated ); |
|
793 #endif |
|
794 MPX_DEBUG2("CXMPXDrmMediaOmaAgent::GetCanSetAutomatedL(): set to %d", canSetAutomated ); |
|
795 } |
|
796 |
|
797 MPX_DEBUG1("CXMPXDrmMediaOmaAgent::GetCanSetAutomatedL() exiting"); |
|
798 } |
|
799 |
|
800 // ---------------------------------------------------------------------------- |
|
801 // Gets the info url attribute if not already obtained |
|
802 // ---------------------------------------------------------------------------- |
|
803 // |
|
804 void CMPXDrmMediaOmaAgent::GetHasInfoUrlL() |
|
805 { |
|
806 MPX_DEBUG1("CXMPXDrmMediaOmaAgent::GetHasInfoUrlL() entering"); |
|
807 |
|
808 if ( !iMedia->IsSupported( KMPXMediaDrmHasInfoUrl )) |
|
809 { |
|
810 #ifdef CAMESE_IN_DRM_UTILITY |
|
811 DRM::TDrmUiUrlType types = DRM::TDrmUiUrlType( 0 ); |
|
812 TRAP_IGNORE( iDrmHandler->AvailableUrlsL( iFile, types ) ); |
|
813 TBool hasInfoUrl = ( types & DRM::EUHInfoUrl ) == DRM::EUHInfoUrl; |
|
814 |
|
815 iMedia->SetTObjectValueL( KMPXMediaDrmHasInfoUrl, hasInfoUrl ); |
|
816 #else |
|
817 TFileName filename; |
|
818 iFile.FullName( filename ); |
|
819 HBufC8* infoUrl( NULL ); |
|
820 TBool hasInfoUrl( EFalse ); |
|
821 TRAP_IGNORE( iDrmHelper->HasInfoUrlL( filename, infoUrl )); |
|
822 delete infoUrl; |
|
823 iMedia->SetTObjectValueL( KMPXMediaDrmHasInfoUrl, |
|
824 hasInfoUrl ); |
|
825 #endif |
|
826 MPX_DEBUG2("CXMPXDrmMediaOmaAgent::GetHasInfoUrlL(): set to %d", hasInfoUrl ); |
|
827 } |
|
828 |
|
829 MPX_DEBUG1("CXMPXDrmMediaOmaAgent::GetHasInfoUrlL() exiting"); |
|
830 } |
|
831 |
|
832 // ---------------------------------------------------------------------------- |
|
833 // Gets the preview url attribute if not already obtained |
|
834 // ---------------------------------------------------------------------------- |
|
835 // |
|
836 void CMPXDrmMediaOmaAgent::GetHasPreviewUrlL() |
|
837 { |
|
838 MPX_DEBUG1("CXMPXDrmMediaOmaAgent::GetHasPreviewUrlL() entering"); |
|
839 |
|
840 if ( !iMedia->IsSupported( KMPXMediaDrmHasPreviewUrl )) |
|
841 { |
|
842 #ifdef CAMESE_IN_DRM_UTILITY |
|
843 DRM::TDrmUiUrlType types = DRM::TDrmUiUrlType( 0 ); |
|
844 TRAP_IGNORE( iDrmHandler->AvailableUrlsL( iFile, types ) ); |
|
845 TBool hasPreviewUrl = ( ( types & DRM::EUHPreviewRightsUrl ) |
|
846 == DRM::EUHPreviewRightsUrl ); |
|
847 iMedia->SetTObjectValueL( KMPXMediaDrmHasPreviewUrl, hasPreviewUrl ); |
|
848 #else |
|
849 TFileName filename; |
|
850 iFile.FullName( filename ); |
|
851 HBufC8* previewUrl( NULL ); |
|
852 TRAP_IGNORE( iDrmHelper->HasPreviewL( filename, previewUrl )); |
|
853 TBool hasPreviewUrl( previewUrl != NULL ); |
|
854 delete previewUrl; |
|
855 iMedia->SetTObjectValueL( KMPXMediaDrmHasPreviewUrl, |
|
856 hasPreviewUrl ); |
|
857 #endif |
|
858 MPX_DEBUG2("CXMPXDrmMediaOmaAgent::GetHasPreviewUrlL(): set to %d", hasPreviewUrl ); |
|
859 } |
|
860 |
|
861 MPX_DEBUG1("CXMPXDrmMediaOmaAgent::GetHasPreviewUrlL() exiting"); |
|
862 } |
|
863 |
|
864 // ---------------------------------------------------------------------------- |
|
865 // Gets whether the DRM object is about to expire or not |
|
866 // ---------------------------------------------------------------------------- |
|
867 // |
|
868 void CMPXDrmMediaOmaAgent::GetAboutToExpireL() |
|
869 { |
|
870 MPX_DEBUG1("CXMPXDrmMediaOmaAgent::GetAboutToExpireL() entering"); |
|
871 |
|
872 TBool aboutToExpire( EFalse ); |
|
873 if ( !iMedia->IsSupported( KMPXMediaDrmRightsStatus )) |
|
874 { |
|
875 GetRightsDetailsL(); |
|
876 } |
|
877 |
|
878 // Only restricted types can expire |
|
879 if ( EMPXDrmRightsRestricted == |
|
880 iMedia->ValueTObjectL<TBool>( KMPXMediaDrmRightsStatus )) |
|
881 { |
|
882 // Get the type |
|
883 if ( !iRightsConstraints ) |
|
884 { |
|
885 GetRightsDetailsL(); |
|
886 } |
|
887 |
|
888 // Check if it's a count based rights |
|
889 GetCountL(); |
|
890 if ( iMedia->IsSupported( KMPXMediaDrmCount ) ) |
|
891 { |
|
892 // count based, or time/count based |
|
893 MPX_DEBUG1( "CXMPXDrmMediaOmaAgent::GetAboutToExpireL EMPXDrmRightsTypeCount/EMPXDrmRightsTypeTimeCount" ); |
|
894 // Try to get count value |
|
895 TInt count(iMedia->ValueTObjectL<TInt>( KMPXMediaDrmCount )); |
|
896 if ( count <= KMPXAboutToExpireCount ) |
|
897 { |
|
898 aboutToExpire = ETrue; |
|
899 } |
|
900 } // end if count type |
|
901 else |
|
902 { |
|
903 GetStartTimeL(); |
|
904 if ( iMedia->IsSupported( KMPXMediaDrmStartTime ) ) |
|
905 { |
|
906 // time based |
|
907 MPX_DEBUG1( "CXMPXDrmMediaOmaAgent::GetAboutToExpireL EMPXDrmRightsTypeTime" ); |
|
908 if ( !iMedia->IsSupported( KMPXMediaDrmEndTime )) |
|
909 { |
|
910 GetEndTimeL(); |
|
911 } |
|
912 |
|
913 // Check if end time attribute was actually fetched |
|
914 // in GetEndTimeL() |
|
915 if ( iMedia->IsSupported( KMPXMediaDrmEndTime )) |
|
916 { |
|
917 TInt64 end( |
|
918 iMedia->ValueTObjectL<TInt64>( KMPXMediaDrmEndTime )); |
|
919 TTime endTime( end ); |
|
920 TTime currentTime; |
|
921 currentTime.HomeTime(); |
|
922 TInt diff( endTime.DaysFrom( currentTime ).Int() ); |
|
923 if ( diff <= KMPXAboutToExpireTime ) |
|
924 { |
|
925 aboutToExpire = ETrue; |
|
926 } |
|
927 } |
|
928 } // end if time type |
|
929 else |
|
930 { |
|
931 GetIntervalL(); |
|
932 if ( iMedia->IsSupported( KMPXMediaDrmInterval ) ) |
|
933 { |
|
934 // interval based |
|
935 MPX_DEBUG1( "CXMPXDrmMediaOmaAgent::GetAboutToExpireL EMPXDrmRightsTypeInterval" ); |
|
936 if ( !iMedia->IsSupported( KMPXMediaDrmInterval )) |
|
937 { |
|
938 GetIntervalL(); |
|
939 } |
|
940 if ( !iMedia->IsSupported( KMPXMediaDrmIntervalStartTime )) |
|
941 { |
|
942 GetIntervalStartTimeL(); |
|
943 } |
|
944 |
|
945 TInt intervalDiff( 0 ); |
|
946 const TTimeIntervalSeconds& interval( |
|
947 iMedia->ValueTObjectL<TTimeIntervalSeconds>( |
|
948 KMPXMediaDrmInterval )); |
|
949 if ( iMedia->IsSupported( KMPXMediaDrmIntervalStartTime )) |
|
950 { |
|
951 // Interval has already started |
|
952 TTime currentTime; |
|
953 currentTime.HomeTime(); |
|
954 TInt64 start( |
|
955 iMedia->ValueTObjectL<TInt64>( KMPXMediaDrmIntervalStartTime )); |
|
956 TTime intervalStart( start ); |
|
957 TTimeIntervalSeconds secondsFromStart; |
|
958 currentTime.SecondsFrom( intervalStart, secondsFromStart ); |
|
959 intervalDiff = ( interval.Int() - secondsFromStart.Int() ) / |
|
960 KMPXSecondsInDay; |
|
961 } |
|
962 else |
|
963 { |
|
964 // Interval has not started yet |
|
965 intervalDiff = interval.Int() / KMPXSecondsInDay; |
|
966 } |
|
967 if ( intervalDiff <= KMPXAboutToExpireTime ) |
|
968 { |
|
969 aboutToExpire = ETrue; |
|
970 } |
|
971 } // end if interval type |
|
972 else |
|
973 { |
|
974 GetAccumulatedTimeL(); |
|
975 if ( iMedia->IsSupported( KMPXMediaDrmAccumulatedTime ) ) |
|
976 { |
|
977 MPX_DEBUG1( "CXMPXDrmMediaOmaAgent::GetAboutToExpireL EMPXDrmRightsTypeAccTime" ); |
|
978 if ( !iMedia->IsSupported( KMPXMediaDrmAccumulatedTime )) |
|
979 { |
|
980 GetAccumulatedTimeL(); |
|
981 } |
|
982 const TTimeIntervalSeconds& accTime( |
|
983 iMedia->ValueTObjectL<TTimeIntervalSeconds>( |
|
984 KMPXMediaDrmAccumulatedTime )); |
|
985 if ( accTime.Int() < KMPXAboutToExpireAccTime ) |
|
986 { |
|
987 aboutToExpire = ETrue; |
|
988 } |
|
989 } // end if accumulated time type |
|
990 } |
|
991 } |
|
992 } |
|
993 } |
|
994 |
|
995 iMedia->SetTObjectValueL( KMPXMediaDrmAboutToExpire, |
|
996 aboutToExpire ); |
|
997 |
|
998 MPX_DEBUG1("CXMPXDrmMediaOmaAgent::GetAboutToExpireL() exiting"); |
|
999 } |
|
1000 |
|
1001 // end of file |