1 /*
2  * Copyright (C) 2010 The Android Open Source Project
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 #include <drm/DrmRights.h>
18 #include <ReadWriteUtils.h>
19 
20 using namespace android;
21 
DrmRights(const String8 & rightsFilePath,const String8 & mimeType,const String8 & accountId,const String8 & subscriptionId)22 DrmRights::DrmRights(const String8& rightsFilePath, const String8& mimeType,
23             const String8& accountId, const String8& subscriptionId) :
24     mMimeType(mimeType),
25     mAccountId(accountId),
26     mSubscriptionId(subscriptionId),
27     mRightsFromFile(NULL) {
28     int rightsLength = 0;
29     if (String8("") != rightsFilePath) {
30         rightsLength = ReadWriteUtils::readBytes(rightsFilePath, &mRightsFromFile);
31     }
32     mData = DrmBuffer(mRightsFromFile, rightsLength);
33 }
34 
DrmRights(const DrmBuffer & rightsData,const String8 & mimeType,const String8 & accountId,const String8 & subscriptionId)35 DrmRights::DrmRights(const DrmBuffer& rightsData, const String8& mimeType,
36             const String8& accountId, const String8& subscriptionId) :
37     mData(rightsData),
38     mMimeType(mimeType),
39     mAccountId(accountId),
40     mSubscriptionId(subscriptionId),
41     mRightsFromFile(NULL) {
42 }
43 
~DrmRights()44 DrmRights::~DrmRights() {
45     delete[] mRightsFromFile; mRightsFromFile = NULL;
46 }
47 
getData(void) const48 const DrmBuffer& DrmRights::getData(void) const {
49     return mData;
50 }
51 
getMimeType(void) const52 String8 DrmRights::getMimeType(void) const {
53     return mMimeType;
54 }
55 
getAccountId(void) const56 String8 DrmRights::getAccountId(void) const {
57     return mAccountId;
58 }
59 
getSubscriptionId(void) const60 String8 DrmRights::getSubscriptionId(void) const {
61     return mSubscriptionId;
62 }
63 
64