filedetails/filedetailsdialog/src/MediaPlayerDrmHelper.cpp
changeset 0 96612d01cf9f
equal deleted inserted replaced
-1:000000000000 0:96612d01cf9f
       
     1 /*
       
     2 * Copyright (c) 2002-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 the License "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 helper for Media files.*
       
    15 */
       
    16 
       
    17 
       
    18 
       
    19 // INCLUDE FILES
       
    20 #include    <DRMHelper.h>
       
    21 #include    <bamdesca.h>
       
    22 #include    <bautils.h>
       
    23 #include    <coemain.h>
       
    24 #include    <StringLoader.h>
       
    25 #include    <aknnotewrappers.h>
       
    26 #include    <data_caging_path_literals.hrh>
       
    27 
       
    28 #include    "MediaPlayerDrmHelper.h"
       
    29 #include    <MPFileDetails.h>
       
    30 
       
    31 #include    <drmuihandling.h>
       
    32 #include    <drmautomatedusage.h>
       
    33 #include    <Oma2Agent.h>
       
    34 
       
    35 #include    "mpxvideo_debug.h"
       
    36 
       
    37 // ============================ MEMBER FUNCTIONS ===============================
       
    38 
       
    39 // -----------------------------------------------------------------------------
       
    40 // CMediaPlayerDrmHelper::CMediaPlayerDrmHelper(aDrmHelper,aUIController)
       
    41 // C++ default constructor can NOT contain any code, that
       
    42 // might leave.
       
    43 // -----------------------------------------------------------------------------
       
    44 //
       
    45 CMediaPlayerDrmHelper::CMediaPlayerDrmHelper(
       
    46                           CDRMHelper* aDrmHelper,
       
    47                           CMPVideoPlayerUIController* /*aUIController*/ )
       
    48     : iDrmHelper(aDrmHelper)
       
    49     , iEnv(CCoeEnv::Static())
       
    50 {
       
    51     MPX_ENTER_EXIT(_L("CMediaPlayerDrmHelper::CMediaPlayerDrmHelper()"));
       
    52 }
       
    53 
       
    54 // -----------------------------------------------------------------------------
       
    55 // CMediaPlayerDrmHelper::CMediaPlayerDrmHelper(aDrmHelper)
       
    56 // C++ default constructor can NOT contain any code, that
       
    57 // might leave.
       
    58 // -----------------------------------------------------------------------------
       
    59 //
       
    60 CMediaPlayerDrmHelper::CMediaPlayerDrmHelper( CDRMHelper* aDrmHelper )
       
    61     : iDrmHelper(aDrmHelper)
       
    62     , iEnv( CCoeEnv::Static() )
       
    63 {
       
    64     MPX_ENTER_EXIT(_L("CMediaPlayerDrmHelper::CMediaPlayerDrmHelper()"));
       
    65 }
       
    66 
       
    67 // -----------------------------------------------------------------------------
       
    68 // CMediaPlayerDrmHelper::ConstructL
       
    69 // Symbian 2nd phase constructor can leave.
       
    70 // -----------------------------------------------------------------------------
       
    71 //
       
    72 void CMediaPlayerDrmHelper::ConstructL()
       
    73 {
       
    74     MPX_ENTER_EXIT(_L("CMediaPlayerDrmHelper::ConstructL()"));
       
    75     iDrmUiHandling = DRM::CDrmUiHandling::NewL(iEnv);
       
    76     iDrmUtility = &iDrmUiHandling->GetUtility();
       
    77 }
       
    78 
       
    79 // -----------------------------------------------------------------------------
       
    80 // CMediaPlayerDrmHelper::NewL(aDrmHelper,aUIController)
       
    81 // Two-phased constructor.
       
    82 // -----------------------------------------------------------------------------
       
    83 //
       
    84 CMediaPlayerDrmHelper*
       
    85 CMediaPlayerDrmHelper::NewL( CDRMHelper* aDrmHelper,
       
    86                              CMPVideoPlayerUIController* aUIController )
       
    87 {
       
    88     MPX_ENTER_EXIT(_L("CMediaPlayerDrmHelper::NewL()"));
       
    89 
       
    90     CMediaPlayerDrmHelper* self =
       
    91         new (ELeave) CMediaPlayerDrmHelper(aDrmHelper,aUIController);
       
    92 
       
    93     CleanupStack::PushL(self);
       
    94     self->ConstructL();
       
    95     CleanupStack::Pop(self);
       
    96 
       
    97     return self;
       
    98 }
       
    99 
       
   100 // -----------------------------------------------------------------------------
       
   101 // CMediaPlayerDrmHelper::NewL(aDrmHelper,aUIController)
       
   102 // Two-phased constructor.
       
   103 // -----------------------------------------------------------------------------
       
   104 //
       
   105 CMediaPlayerDrmHelper* CMediaPlayerDrmHelper::NewL( CDRMHelper* aDrmHelper )
       
   106 {
       
   107     MPX_ENTER_EXIT(_L("CMediaPlayerDrmHelper::NewL()"));
       
   108 
       
   109     CMediaPlayerDrmHelper* self =
       
   110         new (ELeave) CMediaPlayerDrmHelper(aDrmHelper);
       
   111 
       
   112     CleanupStack::PushL(self);
       
   113     self->ConstructL();
       
   114     CleanupStack::Pop(self);
       
   115 
       
   116     return self;
       
   117 }
       
   118 
       
   119 // -----------------------------------------------------------------------------
       
   120 // CMediaPlayerDrmHelper::~CMediaPlayerDrmHelper
       
   121 // Destructor
       
   122 // -----------------------------------------------------------------------------
       
   123 //
       
   124 CMediaPlayerDrmHelper::~CMediaPlayerDrmHelper()
       
   125 {
       
   126     MPX_ENTER_EXIT(_L("CMediaPlayerDrmHelper::~CMediaPlayerDrmHelper()"));
       
   127 
       
   128     delete iInfoUrl;
       
   129     delete iFileName;
       
   130     delete iPreviewUri;
       
   131     delete iRightsConstraints;
       
   132     delete iDrmUiHandling;
       
   133 }
       
   134 
       
   135 // -----------------------------------------------------------------------------
       
   136 // CMediaPlayerDrmHelper::LoadDrmUsageRightsInfoL
       
   137 // -----------------------------------------------------------------------------
       
   138 //
       
   139 void
       
   140 CMediaPlayerDrmHelper::LoadDrmUsageRightsInfoL( const TDesC& aFileName )
       
   141 {
       
   142     MPX_ENTER_EXIT(_L("CMediaPlayerDrmHelper::LoadDrmUsageRightsInfoL()"));
       
   143 
       
   144 
       
   145     if ( BaflUtils::FileExists(iEnv->FsSession(), aFileName) )
       
   146     {
       
   147         iExpired = EFalse;
       
   148         delete iInfoUrl;
       
   149         iInfoUrl = NULL;
       
   150         delete iPreviewUri;
       
   151         iPreviewUri = NULL;
       
   152         delete iRightsConstraints;
       
   153         iRightsConstraints = NULL;
       
   154         delete iFileName;
       
   155         iFileName = NULL;
       
   156 
       
   157         iFileName = aFileName.AllocL();
       
   158 
       
   159 #ifdef SYMBIAN_ENABLE_64_BIT_FILE_SERVER_API
       
   160         RFile64 fileHandle;
       
   161 #else
       
   162         RFile fileHandle;
       
   163 #endif // SYMBIAN_ENABLE_64_BIT_FILE_SERVER_API
       
   164 
       
   165         TUint fileMode = EFileShareReadersOrWriters |
       
   166                          EFileStream |
       
   167                          EFileRead;
       
   168 
       
   169         CreateFileHandleLC( fileHandle, *iFileName, fileMode );
       
   170         LoadDrmUsageRightsInfoL( fileHandle );
       
   171         CleanupStack::PopAndDestroy(); // fileHandle
       
   172     }
       
   173     else
       
   174     {
       
   175         User::Leave(KErrNotFound);
       
   176     }
       
   177 }
       
   178 
       
   179 // -----------------------------------------------------------------------------
       
   180 // CMediaPlayerDrmHelper::GetDrmUsageRightsStatus
       
   181 // -----------------------------------------------------------------------------
       
   182 //
       
   183 void
       
   184 CMediaPlayerDrmHelper::GetDrmUsageRightsStatus(TMediaPlayerRightsStatus& aStatus)
       
   185 {
       
   186     MPX_ENTER_EXIT(_L("CMediaPlayerDrmHelper::GetDrmUsageRightsStatus()"));
       
   187 
       
   188     if ( ! iProtected )
       
   189     {
       
   190         aStatus = EMediaPlayerFull;
       
   191     }
       
   192     // This check ensures that the non-OMA DRM is assigned the correct status.
       
   193     // If content is not OMA DRM then currently the only other choice is WM DRM.
       
   194     else if ( iProtected && ! iOMAProtected )
       
   195     {
       
   196         if ( iExpired )
       
   197         {
       
   198             aStatus = KMediaPlayerWmdrmExpired;
       
   199         }
       
   200         else
       
   201         {
       
   202             aStatus = KMediaPlayerWmdrmValid;
       
   203         }
       
   204     }
       
   205     else if ( iExpired )
       
   206     {
       
   207         aStatus = EMediaPlayerExpired;
       
   208     }
       
   209     else if ( iRightsConstraints )
       
   210     {
       
   211         if ( iRightsConstraints->IsPreview() )
       
   212         {
       
   213             aStatus = EMediaPlayerPreview;
       
   214         }
       
   215         else if ( iRightsConstraints->FullRights() )
       
   216         {
       
   217             aStatus = EMediaPlayerFull;
       
   218         }
       
   219         else
       
   220         {
       
   221             TTime time;
       
   222             TTime startTime;
       
   223 
       
   224             time.HomeTime();
       
   225             TInt error = GetDrmStartTime(startTime);
       
   226 
       
   227             // Check that usage time has already started
       
   228             if (!error && time < startTime)
       
   229             {
       
   230                 aStatus = EMediaPlayerExpired;
       
   231             }
       
   232             else
       
   233             {
       
   234                 aStatus = EMediaPlayerRestricted;
       
   235             }
       
   236         }
       
   237     }
       
   238     else
       
   239     {
       
   240         aStatus = EMediaPlayerMissing;
       
   241     }
       
   242 
       
   243     MPX_DEBUG(_L(
       
   244         "CMediaPlayerDrmHelper::GetDrmUsageRightsStatus() ret %d"),
       
   245         aStatus);
       
   246 }
       
   247 
       
   248 // -----------------------------------------------------------------------------
       
   249 // CMediaPlayerDrmHelper::GetDrmStartTime
       
   250 // -----------------------------------------------------------------------------
       
   251 //
       
   252 TInt CMediaPlayerDrmHelper::GetDrmStartTime(TTime& aStartTime)
       
   253 {
       
   254     MPX_ENTER_EXIT(_L("CMediaPlayerDrmHelper::GetDrmStartTime()"));
       
   255 
       
   256     TInt error = KErrNone;
       
   257 
       
   258     if (!iProtected || !iOMAProtected)
       
   259     {
       
   260         error = KErrNotFound;
       
   261     }
       
   262     else if (iRightsConstraints)
       
   263     {
       
   264         TRAP(error, iRightsConstraints->GetStartTimeL(aStartTime));
       
   265     }
       
   266     else
       
   267     {
       
   268         error = KErrNotReady;
       
   269     }
       
   270 
       
   271     return error;
       
   272 }
       
   273 
       
   274 // -----------------------------------------------------------------------------
       
   275 // CMediaPlayerDrmHelper::DrmHelper
       
   276 // -----------------------------------------------------------------------------
       
   277 //
       
   278 CDRMHelper* CMediaPlayerDrmHelper::DrmHelper()
       
   279 {
       
   280     MPX_ENTER_EXIT(_L("CMediaPlayerDrmHelper::DrmHelper()"));
       
   281     return iDrmHelper;
       
   282 }
       
   283 
       
   284 // -----------------------------------------------------------------------------
       
   285 // CMediaPlayerDrmHelper::LoadDrmUsageRightsInfoL
       
   286 // -----------------------------------------------------------------------------
       
   287 //
       
   288 void CMediaPlayerDrmHelper::LoadDrmUsageRightsInfoL( 
       
   289 #ifdef SYMBIAN_ENABLE_64_BIT_FILE_SERVER_API
       
   290                                                      RFile64& aFile )
       
   291 #else
       
   292                                                      RFile& aFile )
       
   293 #endif // SYMBIAN_ENABLE_64_BIT_FILE_SERVER_API
       
   294 {
       
   295    MPX_ENTER_EXIT(_L("CMediaPlayerDrmHelper::LoadDrmUsageRightsInfoL()"));
       
   296 
       
   297     iExpired = EFalse;
       
   298     delete iInfoUrl;
       
   299     iInfoUrl = NULL;
       
   300     delete iPreviewUri;
       
   301     iPreviewUri = NULL;
       
   302     delete iRightsConstraints;
       
   303     iRightsConstraints = NULL;
       
   304     delete iFileName;
       
   305     iFileName = NULL;
       
   306 
       
   307     //
       
   308     //  Get the agent information and protection status
       
   309     //
       
   310     TPtrC agentId;
       
   311     DRM::TDrmProtectionStatus protectionStatus;
       
   312     iDrmUtility->GetDrmInfoL( aFile, agentId, protectionStatus );
       
   313     iProtected = ( protectionStatus == DRM::EUProtected );
       
   314     iOMAProtected = ( agentId.Match(KOmaDrm2AgentName) != KErrNotFound );
       
   315 
       
   316     // Check to make sure that DRM helper is accessed only for OMA DRM
       
   317     if ( iProtected && iOMAProtected )
       
   318     {
       
   319         CDRMHelperRightsConstraints* ignore1 = NULL;
       
   320         CDRMHelperRightsConstraints* ignore2 = NULL;
       
   321         CDRMHelperRightsConstraints* ignore3 = NULL;
       
   322 
       
   323         // No replacement for this currently available via DRM Utility
       
   324         TRAPD( error, iDrmHelper->GetRightsDetailsL( aFile,
       
   325                                                      ContentAccess::EPlay,
       
   326                                                      iExpired,
       
   327                                                      iDrmSendingAllowed,
       
   328                                                      iRightsConstraints,
       
   329                                                      ignore1,
       
   330                                                      ignore2,
       
   331                                                      ignore3 ) );
       
   332 
       
   333         // Delete ignored constraints
       
   334         delete ignore1;
       
   335         ignore1 = NULL;
       
   336         delete ignore2;
       
   337         ignore2 = NULL;
       
   338         delete ignore3;
       
   339         ignore3 = NULL;
       
   340 
       
   341         if ( error == KErrCANoPermission )
       
   342         {
       
   343             iExpired = ETrue;
       
   344         }
       
   345         else if (error != KErrCANoRights)
       
   346         {
       
   347             User::LeaveIfError( error );
       
   348         }
       
   349     }
       
   350     // get the attributes for protected WMDRM content
       
   351     else if ( iProtected && ! iOMAProtected )
       
   352     {
       
   353         CContent* content = CContent::NewLC(aFile);
       
   354 
       
   355         TInt value;
       
   356         TInt err;
       
   357 
       
   358         err = content->GetAttribute( ECanPlay, value );
       
   359 
       
   360         if ( err == KErrNone )
       
   361         {
       
   362             iExpired = ( ! value );
       
   363             MPX_DEBUG(_L("   iExpired = %d"), iExpired);
       
   364         }
       
   365         else
       
   366         {
       
   367         MPX_DEBUG(_L("   ECanPlay failed"));
       
   368         }
       
   369 
       
   370         err = content->GetAttribute( EIsForwardable, value );
       
   371 
       
   372         if ( err == KErrNone )
       
   373         {
       
   374             iDrmSendingAllowed = value;
       
   375             MPX_DEBUG(_L("   iDrmSendingAllowed = %d"), iDrmSendingAllowed);
       
   376         }
       
   377         else
       
   378         {
       
   379         MPX_DEBUG(_L("   EIsForwardable failed"));
       
   380         }
       
   381 
       
   382         CleanupStack::PopAndDestroy( content );
       
   383     }
       
   384     else
       
   385     {
       
   386         iExpired = EFalse;
       
   387         iDrmSendingAllowed = ETrue;
       
   388     }
       
   389 }
       
   390 
       
   391 // -----------------------------------------------------------------------------
       
   392 // CMediaPlayerDrmHelper::CreateFileHandleLC
       
   393 // -----------------------------------------------------------------------------
       
   394 //
       
   395 void CMediaPlayerDrmHelper::CreateFileHandleLC( 
       
   396 #ifdef SYMBIAN_ENABLE_64_BIT_FILE_SERVER_API
       
   397                                                 RFile64& aHandle,
       
   398 #else
       
   399                                                 RFile& aHandle,
       
   400 #endif // SYMBIAN_ENABLE_64_BIT_FILE_SERVER_API
       
   401                                                 const TDesC& aName,
       
   402                                                 TUint aFileMode )
       
   403 {
       
   404     // Get the file server session
       
   405     RFs fs = CEikonEnv::Static()->FsSession();
       
   406     User::LeaveIfError(aHandle.Open(fs, aName, aFileMode));
       
   407     CleanupClosePushL(aHandle);
       
   408 }
       
   409 
       
   410 //  End of File