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, const char* ssid, 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, sp<DecryptHandle>& decryptHandle, int action, 99 bool reserve); 100 101 status_t setPlaybackStatus( 102 int uniqueId, sp<DecryptHandle>& decryptHandle, int playbackStatus, int64_t position); 103 104 bool validateAction(int uniqueId, const String8& path, 105 int action, const ActionDescription& description); 106 107 status_t removeRights(int uniqueId, const String8& path); 108 109 status_t removeAllRights(int uniqueId); 110 111 int openConvertSession(int uniqueId, const String8& mimeType); 112 113 DrmConvertedStatus* convertData(int uniqueId, int convertId, const DrmBuffer* inputData); 114 115 DrmConvertedStatus* closeConvertSession(int uniqueId, int convertId); 116 117 status_t getAllSupportInfo(int uniqueId, int* length, DrmSupportInfo** drmSupportInfoArray); 118 119 sp<DecryptHandle> openDecryptSession( 120 int uniqueId, int fd, off64_t offset, off64_t length, const char *mime); 121 122 sp<DecryptHandle> openDecryptSession( 123 int uniqueId, const char* uri, const char* mime); 124 125 sp<DecryptHandle> openDecryptSession(int uniqueId, const DrmBuffer& buf, 126 const String8& mimeType); 127 128 status_t closeDecryptSession(int uniqueId, sp<DecryptHandle>& decryptHandle); 129 130 status_t initializeDecryptUnit(int uniqueId, sp<DecryptHandle>& decryptHandle, 131 int decryptUnitId, const DrmBuffer* headerInfo); 132 133 status_t decrypt(int uniqueId, sp<DecryptHandle>& decryptHandle, int decryptUnitId, 134 const DrmBuffer* encBuffer, DrmBuffer** decBuffer, DrmBuffer* IV); 135 136 status_t finalizeDecryptUnit(int uniqueId, sp<DecryptHandle>& decryptHandle, 137 int decryptUnitId); 138 139 ssize_t pread(int uniqueId, sp<DecryptHandle>& decryptHandle, 140 void* buffer, ssize_t numBytes, off64_t offset); 141 142 virtual status_t dump(int fd, const Vector<String16>& args); 143 144 private: 145 sp<DrmManager> mDrmManager; 146 }; 147 148 }; 149 150 #endif /* __DRM_MANAGER_SERVICE_H__ */ 151 152