|
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: Class used to check the protection of the |
|
15 * media files. |
|
16 * |
|
17 */ |
|
18 |
|
19 |
|
20 |
|
21 |
|
22 // INCLUDE FILES |
|
23 |
|
24 #include "mediafileprotection.h" |
|
25 #include "mediafilelist.h" |
|
26 #include "mediafilelistdebug.h" |
|
27 #include <mediafilelist.rsg> |
|
28 |
|
29 #include <DRMCommon.h> |
|
30 #include <drmutility.h> |
|
31 #include <drmagents.h> |
|
32 #include <bautils.h> |
|
33 #include <StringLoader.h> |
|
34 |
|
35 |
|
36 |
|
37 /****************************************************************************** |
|
38 * class CMFProtectionHandler |
|
39 ******************************************************************************/ |
|
40 |
|
41 // ----------------------------------------------------------------------------- |
|
42 // CMFProtectionHandler::NewL |
|
43 // |
|
44 // ----------------------------------------------------------------------------- |
|
45 CMFProtectionHandler* CMFProtectionHandler::NewL() |
|
46 { |
|
47 CMFProtectionHandler* self = new (ELeave) CMFProtectionHandler(); |
|
48 CleanupStack::PushL(self); |
|
49 self->ConstructL(); |
|
50 CleanupStack::Pop(self); |
|
51 |
|
52 return self; |
|
53 } |
|
54 |
|
55 |
|
56 // ----------------------------------------------------------------------------- |
|
57 // CMFProtectionHandler::CMFProtectionHandler |
|
58 // |
|
59 // ----------------------------------------------------------------------------- |
|
60 // |
|
61 CMFProtectionHandler::CMFProtectionHandler() |
|
62 { |
|
63 iMaxFileSize = KErrNotFound; |
|
64 } |
|
65 |
|
66 |
|
67 // ----------------------------------------------------------------------------- |
|
68 // CMFProtectionHandler::CMFProtectionHandler |
|
69 // |
|
70 // ----------------------------------------------------------------------------- |
|
71 // |
|
72 void CMFProtectionHandler::ConstructL() |
|
73 { |
|
74 iDriveUtil = CDriveUtil::NewL(); |
|
75 iVariation = CMediaFileDialogVariation::NewL(); |
|
76 |
|
77 iDRMHelper = CDRMHelper::NewL( *CCoeEnv::Static() ); |
|
78 |
|
79 iDRMCommon = DRMCommon::NewL(); |
|
80 User::LeaveIfError( iDRMCommon->Connect() ); |
|
81 |
|
82 iExcludedMimeTypes = CMimeTypeList::NewL(); |
|
83 |
|
84 User::LeaveIfError( iApaLsSession.Connect() ); |
|
85 User::LeaveIfError( iFsSession.Connect() ); |
|
86 } |
|
87 |
|
88 |
|
89 // ---------------------------------------------------------------------------- |
|
90 // Destructor |
|
91 // |
|
92 // ---------------------------------------------------------------------------- |
|
93 // |
|
94 CMFProtectionHandler::~CMFProtectionHandler() |
|
95 { |
|
96 delete iDriveUtil; |
|
97 delete iVariation; |
|
98 |
|
99 delete iDRMHelper; |
|
100 |
|
101 if ( iDRMCommon ) |
|
102 { |
|
103 iDRMCommon->Disconnect(); // ignore possible error |
|
104 delete iDRMCommon; |
|
105 } |
|
106 |
|
107 delete iExcludedMimeTypes; |
|
108 iApaLsSession.Close(); |
|
109 iFsSession.Close(); |
|
110 } |
|
111 |
|
112 |
|
113 // ----------------------------------------------------------------------------- |
|
114 // CMFProtectionHandler::SetAttr |
|
115 // |
|
116 // ----------------------------------------------------------------------------- |
|
117 void CMFProtectionHandler::SetAttrL( TInt aAttr, TInt aValue ) |
|
118 { |
|
119 switch ( aAttr ) |
|
120 { |
|
121 case CMediaFileList::EAttrFileSize: |
|
122 { |
|
123 iMaxFileSize = aValue; |
|
124 break; |
|
125 } |
|
126 case CMediaFileList::EAttrAutomatedType: |
|
127 { |
|
128 iAutomatedType = (CDRMHelper::TDRMHelperAutomatedType) aValue; |
|
129 break; |
|
130 } |
|
131 |
|
132 default: |
|
133 { |
|
134 break; |
|
135 } |
|
136 } |
|
137 } |
|
138 |
|
139 |
|
140 // ----------------------------------------------------------------------------- |
|
141 // CMFProtectionHandler::SetAttrL |
|
142 // |
|
143 // ----------------------------------------------------------------------------- |
|
144 void CMFProtectionHandler::SetAttrL( TInt aAttr, const TDesC& aValue ) |
|
145 { |
|
146 if ( aAttr == CMediaFileList::EAttrExcludeMimeType ) |
|
147 { |
|
148 if ( aValue.Length() > KMaxFileName || aValue.Length() == 0 ) |
|
149 { |
|
150 User::Leave( KErrArgument ); |
|
151 } |
|
152 |
|
153 iExcludedMimeTypes->AddMimeTypeL( aValue ); |
|
154 } |
|
155 } |
|
156 |
|
157 |
|
158 // ----------------------------------------------------------------------------- |
|
159 // CMFProtectionHandler::IsVideoValid |
|
160 // |
|
161 // ----------------------------------------------------------------------------- |
|
162 // |
|
163 TBool CMFProtectionHandler::IsVideoValid( const TDesC& aFileName, |
|
164 TIntention aIntention ) |
|
165 { |
|
166 TInt err = KErrNone; |
|
167 TBool ret = EFalse; |
|
168 |
|
169 TRAP( err, ret = IsVideoValidL (aFileName, aIntention ) ) |
|
170 |
|
171 if ( err != KErrNone ) |
|
172 { |
|
173 return EFalse; // in case of error file is not valid |
|
174 } |
|
175 |
|
176 return ret; |
|
177 } |
|
178 |
|
179 |
|
180 // ----------------------------------------------------------------------------- |
|
181 // CMFProtectionHandler::IsVideoValidL |
|
182 // |
|
183 // ----------------------------------------------------------------------------- |
|
184 // |
|
185 TBool CMFProtectionHandler::IsVideoValidL( const TDesC& aFileName, |
|
186 TIntention /*aIntention*/ ) |
|
187 { |
|
188 TBuf<KMaxDataTypeLength> dataType( DataTypeL( aFileName ).Des() ); |
|
189 |
|
190 if ( iExcludedMimeTypes->FindMimeTypeL( dataType ) ) |
|
191 { |
|
192 return EFalse; |
|
193 } |
|
194 |
|
195 CContent* content = CContent::NewLC( aFileName, |
|
196 EContentShareReadWrite ); |
|
197 TInt deliveryMethod = 0; |
|
198 content->GetAttribute( EDeliveryMethod, deliveryMethod ); |
|
199 |
|
200 CleanupStack::PopAndDestroy( content ); |
|
201 |
|
202 if( deliveryMethod == EOmaDrm2 ) |
|
203 { |
|
204 // if video it is OMA DRM 2 protected, it cannot be previewed |
|
205 return EFalse; |
|
206 } |
|
207 return ETrue; |
|
208 } |
|
209 |
|
210 |
|
211 // ----------------------------------------------------------------------------- |
|
212 // CMFProtectionHandler::IsFileValid |
|
213 // |
|
214 // Checks protection state of media file. If this function returns EFalse, |
|
215 // media file cannot be used for playing/selection. |
|
216 // |
|
217 // ----------------------------------------------------------------------------- |
|
218 // |
|
219 TBool CMFProtectionHandler::IsFileValid( const TDesC& aFileName, |
|
220 TIntention aIntention ) |
|
221 { |
|
222 TInt err = KErrNone; |
|
223 TBool ret = EFalse; |
|
224 |
|
225 TRAP( err, ret = IsFileValidL (aFileName, aIntention ) ) |
|
226 |
|
227 if ( err != KErrNone ) |
|
228 { |
|
229 return EFalse; // in case of error file is not valid |
|
230 } |
|
231 |
|
232 return ret; |
|
233 } |
|
234 |
|
235 |
|
236 // ----------------------------------------------------------------------------- |
|
237 // CMFProtectionHandler::IsFileValidL |
|
238 // |
|
239 // Function is copy from CFLDDRMImplementation.cpp. |
|
240 // ----------------------------------------------------------------------------- |
|
241 // |
|
242 TBool CMFProtectionHandler::IsFileValidL( const TDesC& aFileName, |
|
243 TIntention aIntention ) |
|
244 { |
|
245 TInt err = KErrNone; |
|
246 TBuf<KMaxDataTypeLength> dataType( DataTypeL( aFileName ).Des() ); |
|
247 |
|
248 if ( aFileName.Length() == 0 ) |
|
249 { |
|
250 return ETrue; // empty filename is valid?? |
|
251 } |
|
252 |
|
253 if ( iExcludedMimeTypes->FindMimeTypeL( dataType ) ) |
|
254 { |
|
255 ShowErrorNoteL( R_QTN_INFO_FILE_FORMAT_ERROR ); |
|
256 return EFalse; |
|
257 } |
|
258 |
|
259 if ( aIntention == CMFProtectionHandler::ESelect && |
|
260 !CheckFileSize( aFileName, dataType ) ) |
|
261 { |
|
262 HBufC* hBuf = StringLoader::LoadLC( R_QTN_INFO_FILE_SIZE_ERROR, iMaxFileSize ); |
|
263 TMFDialogUtil::ShowInformationNoteL( *hBuf ); |
|
264 CleanupStack::PopAndDestroy( hBuf ); |
|
265 return EFalse; |
|
266 } |
|
267 |
|
268 if ( iDriveUtil->IsRom( aFileName ) ) |
|
269 { |
|
270 return ETrue; // files in ROM are always valid |
|
271 } |
|
272 |
|
273 // check if file is WMDRM protected |
|
274 TBool prot = EFalse; |
|
275 TRAP( err, prot = IsFileWMDRMProtectedL( aFileName ) ); |
|
276 if ( err != KErrNone ) |
|
277 { |
|
278 ShowErrorNoteL( R_QTN_INFO_FILE_FORMAT_ERROR ); |
|
279 return EFalse; |
|
280 } |
|
281 if ( prot ) |
|
282 { |
|
283 if ( aIntention == EPlay ) |
|
284 { |
|
285 ShowErrorNoteL( R_QTN_INFO_DRM_PREV_RIGHTS_USE ); |
|
286 } |
|
287 else |
|
288 { |
|
289 ShowErrorNoteL( R_QTN_INFO_DRM_PROTECTED ); |
|
290 } |
|
291 return EFalse; |
|
292 } |
|
293 |
|
294 ContentAccess::TVirtualPathPtr path( aFileName, |
|
295 ContentAccess::KDefaultContentObject ); |
|
296 CData* data = CData::NewLC( path, EContentShareReadWrite ); |
|
297 TInt isProtected; |
|
298 err = data->GetAttribute( EIsProtected, isProtected ); |
|
299 CleanupStack::PopAndDestroy( data ); |
|
300 |
|
301 if ( err != DRMCommon::EOk ) |
|
302 { |
|
303 // DRM Helper class knows at least rights db corrupted error message. |
|
304 // Leaves on system-wide error code. |
|
305 iDRMHelper->HandleErrorL( err, aFileName ); |
|
306 return EFalse; |
|
307 } |
|
308 |
|
309 // Obtain information whether the file can be set as automated content |
|
310 TBool canSetAutomated = EFalse; |
|
311 TInt canSetAutomatedErr = |
|
312 iDRMHelper->CanSetAutomated( aFileName, canSetAutomated ); |
|
313 |
|
314 if ( !isProtected && canSetAutomated ) |
|
315 { |
|
316 // The file in question is not DRM protected. |
|
317 // Return ETrue if file is also Ok unprotected, otherwise EFalse. |
|
318 TBool ret = IsFileValidUnprotectedL( aFileName, aIntention ); |
|
319 return ret; |
|
320 } |
|
321 |
|
322 // Operator requirement: Check restrictions if file is mp4 audio |
|
323 if ( iVariation->IsBlockedProtectedType( dataType ) ) |
|
324 { |
|
325 ShowErrorNoteL( R_QTN_INFO_DRM_PROTECTED ); |
|
326 return EFalse; |
|
327 } |
|
328 |
|
329 if ( canSetAutomatedErr == DRMCommon::ERightsExpired || |
|
330 canSetAutomatedErr == DRMCommon::ENoRights ) |
|
331 { |
|
332 // Rights are expired, future rights or missing |
|
333 iDRMHelper->HandleErrorL( canSetAutomatedErr, aFileName ); |
|
334 return EFalse; |
|
335 } |
|
336 |
|
337 // Operator requirement: Check DRM v2 tones |
|
338 if ( !canSetAutomated ) |
|
339 { |
|
340 // This is DRM v2 file OR count based v1 tone |
|
341 if ( aIntention == EPlay ) |
|
342 { |
|
343 ShowErrorNoteL( R_QTN_INFO_DRM_PREV_RIGHTS_USE ); |
|
344 } |
|
345 else |
|
346 { |
|
347 ShowErrorNoteL( R_QTN_INFO_DRM_PROTECTED ); |
|
348 } |
|
349 return EFalse; |
|
350 } |
|
351 |
|
352 TInt32 infoBits( 0x00000000 ); |
|
353 |
|
354 // Find out rights information |
|
355 if ( !GetFileInfoL( aFileName, infoBits ) ) |
|
356 { |
|
357 // Corrupted file or "No rights" situation |
|
358 return EFalse; |
|
359 } |
|
360 |
|
361 // Operator requirement: Check CFM protection |
|
362 if ( infoBits & ENoRingingTone ) |
|
363 { |
|
364 // This is CFM protected file, ringingtone is set to "no" |
|
365 if ( aIntention == EPlay ) |
|
366 { |
|
367 ShowErrorNoteL( R_QTN_INFO_DRM_PREV_RIGHTS_USE ); |
|
368 } |
|
369 else |
|
370 { |
|
371 ShowErrorNoteL( R_QTN_INFO_DRM_PREV_RIGHTS_SET ); |
|
372 } |
|
373 return EFalse; |
|
374 } |
|
375 |
|
376 if ( aIntention == ESelect ) |
|
377 { |
|
378 // Rights are good to go, and intention is selection |
|
379 // call SetAutomatedPassive to show 'activation query' |
|
380 iDRMHelper->SetAutomatedType( iAutomatedType ); |
|
381 err = iDRMHelper->SetAutomatedPassive( aFileName ); |
|
382 if ( err != KErrCancel ) |
|
383 { |
|
384 // User accepted dialog |
|
385 User::LeaveIfError( err ); |
|
386 // New way, does not require DRM capability |
|
387 data = CData::NewLC( path, EContentShareReadWrite ); |
|
388 err = data->ExecuteIntent( ContentAccess::EPlay ); |
|
389 // Wrongly requires DRM after all. According to Risto Vilkman |
|
390 // from DRM, KErrAccessDenied can be ignored, since if |
|
391 // CanSetAutomated says the tone is OK, it's OK. |
|
392 if ( err != KErrNone && err != KErrAccessDenied ) |
|
393 { |
|
394 User::Leave( err ); |
|
395 } |
|
396 CleanupStack::PopAndDestroy( data ); |
|
397 } |
|
398 else |
|
399 { |
|
400 // User canceled dialog |
|
401 return EFalse; |
|
402 } |
|
403 } |
|
404 |
|
405 return ETrue; |
|
406 } |
|
407 |
|
408 |
|
409 // ----------------------------------------------------------------------------- |
|
410 // CMFProtectionHandler::GetFileInfo |
|
411 // |
|
412 // Function is copy from CFLDDRMImplementation.cpp. |
|
413 // ----------------------------------------------------------------------------- |
|
414 // |
|
415 TBool CMFProtectionHandler::GetFileInfoL( const TDesC& aFileName, |
|
416 TInt32& aInfoBits ) |
|
417 { |
|
418 DRMCommon::TContentProtection contentProtection; // ignored |
|
419 HBufC8* mimeType = NULL; // ignored |
|
420 TUint dataLength = 0; // ignored |
|
421 HBufC8* contentURI = NULL; |
|
422 |
|
423 // Obtain content URI |
|
424 TInt error = iDRMCommon->GetFileInfo( |
|
425 aFileName, contentProtection, mimeType, contentURI, dataLength ); |
|
426 delete mimeType; |
|
427 |
|
428 if ( error != DRMCommon::EOk ) |
|
429 { |
|
430 delete contentURI; |
|
431 // Handle possible corrupt file situation |
|
432 iDRMHelper->HandleErrorL( error, aFileName ); |
|
433 return EFalse; |
|
434 } |
|
435 |
|
436 // Obtain rights object |
|
437 CDRMRights* rights = NULL; |
|
438 error = iDRMCommon->GetActiveRights( *contentURI, DRMCommon::EPlay, rights ); |
|
439 delete contentURI; |
|
440 |
|
441 if ( error == DRMCommon::ENoRights ) |
|
442 { |
|
443 delete rights; |
|
444 // There is no rights for given file |
|
445 // Should never arrive here, ENoRights is handled |
|
446 // already in IsFileValidL() |
|
447 iDRMHelper->HandleErrorL( error, aFileName ); |
|
448 return EFalse; |
|
449 } |
|
450 |
|
451 // Obtain infobits ( needed only for CFM case ) |
|
452 aInfoBits = rights->GetPermission().iInfoBits; |
|
453 delete rights; |
|
454 return ETrue; |
|
455 } |
|
456 |
|
457 |
|
458 // ----------------------------------------------------------------------------- |
|
459 // CMFProtectionHandler::IsFileWMDRMProtectedL |
|
460 // |
|
461 // Function is copy from CFLDDRMImplementation.cpp. |
|
462 // ----------------------------------------------------------------------------- |
|
463 // |
|
464 TBool CMFProtectionHandler::IsFileWMDRMProtectedL( const TDesC& aFileName ) |
|
465 { |
|
466 TBool res = EFalse; |
|
467 RFile hFile; |
|
468 |
|
469 TInt err = hFile.Open( iFsSession, aFileName, |
|
470 EFileRead | EFileStream | EFileShareReadersOnly ); |
|
471 if ( err == KErrInUse ) |
|
472 { |
|
473 err = hFile.Open( iFsSession, aFileName, |
|
474 EFileRead | EFileStream | EFileShareAny ); |
|
475 } |
|
476 if ( err != KErrNone ) |
|
477 { |
|
478 User::Leave( err ); |
|
479 } |
|
480 CleanupClosePushL( hFile ); |
|
481 |
|
482 TPtrC agent( KNullDesC ); |
|
483 DRM::CDrmUtility* drmUtil = DRM::CDrmUtility::NewLC(); |
|
484 drmUtil->GetAgentL( hFile, agent ); |
|
485 if ( agent.Compare( DRM::KDrmWMAgentName ) == 0 ) |
|
486 { |
|
487 res = ETrue; |
|
488 } |
|
489 CleanupStack::PopAndDestroy( drmUtil ); |
|
490 |
|
491 CleanupStack::PopAndDestroy( &hFile ); |
|
492 return res; |
|
493 } |
|
494 |
|
495 |
|
496 // ----------------------------------------------------------------------------- |
|
497 // CMFProtectionHandler::DataTypeL |
|
498 // |
|
499 // Function is copy from CFLDDRMImplementationCommon.cpp. |
|
500 // ----------------------------------------------------------------------------- |
|
501 // |
|
502 TDataType CMFProtectionHandler::DataTypeL( const TDesC& aFileName ) |
|
503 { |
|
504 TUid dummyUid = { 0 }; |
|
505 TDataType dataType( dummyUid ); |
|
506 User::LeaveIfError( |
|
507 iApaLsSession.AppForDocument( aFileName, dummyUid, dataType ) ); |
|
508 |
|
509 return dataType; |
|
510 } |
|
511 |
|
512 |
|
513 // ----------------------------------------------------------------------------- |
|
514 // CMFProtectionHandler::IsFileValidUnprotectedL |
|
515 // |
|
516 // Function is copy from CFLDDRMImplementationCommon.cpp. |
|
517 // ----------------------------------------------------------------------------- |
|
518 // |
|
519 TBool CMFProtectionHandler::IsFileValidUnprotectedL( const TDesC& aFileName, |
|
520 TIntention aIntention ) |
|
521 { |
|
522 TDataType dataType = DataTypeL( aFileName ); |
|
523 TBuf<KMaxDataTypeLength> mimeType; |
|
524 |
|
525 mimeType = dataType.Des(); |
|
526 |
|
527 if ( iVariation->IsBlockedType( mimeType ) ) |
|
528 { |
|
529 if ( aIntention == ESelect ) |
|
530 { |
|
531 ShowErrorNoteL( R_QTN_INFO_TEXT_NOT_ALLOWED ); |
|
532 } |
|
533 return EFalse; |
|
534 } |
|
535 |
|
536 // Operator requirement. Check if DRM is required with tones. |
|
537 if ( aIntention == EPlay ) |
|
538 { |
|
539 if ( iVariation->IsBlockedDemoPlayType( mimeType ) ) |
|
540 { |
|
541 return EFalse; |
|
542 } |
|
543 } |
|
544 else |
|
545 { |
|
546 if ( iVariation->IsBlockedUnprotectedType( mimeType ) ) |
|
547 { |
|
548 ShowErrorNoteL( R_QTN_INFO_NO_DRM ); |
|
549 return EFalse; |
|
550 } |
|
551 } |
|
552 |
|
553 return ETrue; |
|
554 } |
|
555 |
|
556 |
|
557 // ----------------------------------------------------------------------------- |
|
558 // CMFProtectionHandler::CheckFileSize |
|
559 // |
|
560 // ----------------------------------------------------------------------------- |
|
561 // |
|
562 TBool CMFProtectionHandler::CheckFileSize( const TDesC& aFile, const TDesC& aMimeType ) |
|
563 { |
|
564 _LIT( KVideo, "video" ); |
|
565 const TInt KKiloByte = 1024; |
|
566 const TInt KSmallSize = 10; |
|
567 |
|
568 if ( iMaxFileSize < KSmallSize ) |
|
569 { |
|
570 return ETrue; // too small size limit |
|
571 } |
|
572 if ( aMimeType.Find( KVideo ) != KErrNotFound ) |
|
573 { |
|
574 return ETrue; // only audio files are checked |
|
575 } |
|
576 |
|
577 TEntry entry; |
|
578 TInt err = iFsSession.Entry( aFile, entry ); |
|
579 if ( err == KErrNone && iMaxFileSize != KErrNotFound ) |
|
580 { |
|
581 TInt size = iMaxFileSize * KKiloByte; // KBytes -> Bytes |
|
582 if ( entry.iSize > size ) |
|
583 { |
|
584 return EFalse; |
|
585 } |
|
586 } |
|
587 |
|
588 return ETrue; |
|
589 } |
|
590 |
|
591 |
|
592 // ----------------------------------------------------------------------------- |
|
593 // CMFProtectionHandler::ShowErrorNoteL |
|
594 // |
|
595 // ----------------------------------------------------------------------------- |
|
596 // |
|
597 void CMFProtectionHandler::ShowErrorNoteL( TInt aResourceId ) |
|
598 { |
|
599 TMFDialogUtil::ShowInformationNoteL( aResourceId ); |
|
600 } |
|
601 |
|
602 |
|
603 // End of File |