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 #ifndef __DRM_MANAGER_SERVICE_H__ 18 #define __DRM_MANAGER_SERVICE_H__ 19 20 #include <utils/RefBase.h> 21 #include <utils/KeyedVector.h> 22 #include <binder/IInterface.h> 23 #include <binder/Parcel.h> 24 #include "IDrmManagerService.h" 25 #include "IDrmServiceListener.h" 26 27 namespace android { 28 29 class DrmManager; 30 class String8; 31 class Mutex; 32 33 /** 34 * This is the implementation class for DRM manager service. This delegates 35 * the responsibility to DrmManager. 36 * 37 * The instance of this class is created while starting the DRM manager service. 38 * 39 */ 40 class DrmManagerService : public BnDrmManagerService { 41 public: 42 static void instantiate(); 43 44 private: 45 enum drm_perm_t { 46 CONSUME_RIGHTS = 0, 47 SET_PLAYBACK_STATUS = 1, 48 OPEN_DECRYPT_SESSION = 2, 49 CLOSE_DECRYPT_SESSION = 3, 50 INITIALIZE_DECRYPT_UNIT = 4, 51 DECRYPT = 5, 52 FINALIZE_DECRYPT_UNIT = 6, 53 PREAD = 7, 54 }; 55 56 static const char *const drm_perm_labels[]; 57 58 DrmManagerService(); 59 virtual ~DrmManagerService(); 60 61 static const char *get_perm_label(drm_perm_t perm); 62 63 static bool selinuxIsProtectedCallAllowed(pid_t spid, drm_perm_t perm); 64 65 static bool isProtectedCallAllowed(drm_perm_t perm); 66 67 public: 68 int addUniqueId(bool isNative); 69 70 void removeUniqueId(int uniqueId); 71 72 void addClient(int uniqueId); 73 74 void removeClient(int uniqueId); 75 76 status_t setDrmServiceListener( 77 int uniqueId, const sp<IDrmServiceListener>& drmServiceListener); 78 79 DrmConstraints* getConstraints(int uniqueId, const String8* path, const int action); 80 81 DrmMetadata* getMetadata(int uniqueId, const String8* path); 82 83 bool canHandle(int uniqueId, const String8& path, const String8& mimeType); 84 85 DrmInfoStatus* processDrmInfo(int uniqueId, const DrmInfo* drmInfo); 86 87 DrmInfo* acquireDrmInfo(int uniqueId, const DrmInfoRequest* drmInforequest); 88 89 status_t saveRights(int uniqueId, const DrmRights& drmRights, 90 const String8& rightsPath, const String8& contentPath); 91 92 String8 getOriginalMimeType(int uniqueId, const String8& path, int fd); 93 94 int getDrmObjectType(int uniqueId, const String8& path, const String8& mimeType); 95 96 int checkRightsStatus(int uniqueId, const String8& path,int action); 97 98 status_t consumeRights(int uniqueId, DecryptHandle* decryptHandle, int action, bool reserve); 99 100 status_t setPlaybackStatus( 101 int uniqueId, DecryptHandle* decryptHandle, int playbackStatus, int64_t position); 102 103 bool validateAction(int uniqueId, const String8& path, 104 int action, const ActionDescription& description); 105 106 status_t removeRights(int uniqueId, const String8& path); 107 108 status_t removeAllRights(int uniqueId); 109 110 int openConvertSession(int uniqueId, const String8& mimeType); 111 112 DrmConvertedStatus* convertData(int uniqueId, int convertId, const DrmBuffer* inputData); 113 114 DrmConvertedStatus* closeConvertSession(int uniqueId, int convertId); 115 116 status_t getAllSupportInfo(int uniqueId, int* length, DrmSupportInfo** drmSupportInfoArray); 117 118 DecryptHandle* openDecryptSession( 119 int uniqueId, int fd, off64_t offset, off64_t length, const char *mime); 120 121 DecryptHandle* openDecryptSession( 122 int uniqueId, const char* uri, const char* mime); 123 124 DecryptHandle* openDecryptSession(int uniqueId, const DrmBuffer& buf, 125 const String8& mimeType); 126 127 status_t closeDecryptSession(int uniqueId, DecryptHandle* decryptHandle); 128 129 status_t initializeDecryptUnit(int uniqueId, DecryptHandle* decryptHandle, 130 int decryptUnitId, const DrmBuffer* headerInfo); 131 132 status_t decrypt(int uniqueId, DecryptHandle* decryptHandle, int decryptUnitId, 133 const DrmBuffer* encBuffer, DrmBuffer** decBuffer, DrmBuffer* IV); 134 135 status_t finalizeDecryptUnit(int uniqueId, DecryptHandle* decryptHandle, int decryptUnitId); 136 137 ssize_t pread(int uniqueId, DecryptHandle* decryptHandle, 138 void* buffer, ssize_t numBytes, off64_t offset); 139 140 virtual status_t dump(int fd, const Vector<String16>& args); 141 142 private: 143 DrmManager* mDrmManager; 144 }; 145 146 }; 147 148 #endif /* __DRM_MANAGER_SERVICE_H__ */ 149 150