aimitakeshi | 27ed8ad | 2010-07-29 10:12:27 +0900 | [diff] [blame] | 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: |
Riley Spahn | f785f49 | 2014-07-01 15:32:31 -0700 | [diff] [blame] | 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 | |
aimitakeshi | 27ed8ad | 2010-07-29 10:12:27 +0900 | [diff] [blame] | 58 | DrmManagerService(); |
| 59 | virtual ~DrmManagerService(); |
| 60 | |
Riley Spahn | f785f49 | 2014-07-01 15:32:31 -0700 | [diff] [blame] | 61 | static const char *get_perm_label(drm_perm_t perm); |
| 62 | |
Steven Moreland | 1a394d5 | 2019-01-11 15:49:24 -0800 | [diff] [blame] | 63 | static bool selinuxIsProtectedCallAllowed(pid_t spid, const char* ssid, drm_perm_t perm); |
Riley Spahn | f785f49 | 2014-07-01 15:32:31 -0700 | [diff] [blame] | 64 | |
| 65 | static bool isProtectedCallAllowed(drm_perm_t perm); |
| 66 | |
aimitakeshi | 27ed8ad | 2010-07-29 10:12:27 +0900 | [diff] [blame] | 67 | public: |
Gloria Wang | 8f00151 | 2011-07-21 15:10:22 -0700 | [diff] [blame] | 68 | int addUniqueId(bool isNative); |
Takeshi Aimi | 2272ee2 | 2010-09-20 23:40:41 +0900 | [diff] [blame] | 69 | |
| 70 | void removeUniqueId(int uniqueId); |
| 71 | |
Takeshi Aimi | e943f84 | 2010-10-08 23:05:49 +0900 | [diff] [blame] | 72 | void addClient(int uniqueId); |
aimitakeshi | 27ed8ad | 2010-07-29 10:12:27 +0900 | [diff] [blame] | 73 | |
Takeshi Aimi | e943f84 | 2010-10-08 23:05:49 +0900 | [diff] [blame] | 74 | void removeClient(int uniqueId); |
aimitakeshi | 27ed8ad | 2010-07-29 10:12:27 +0900 | [diff] [blame] | 75 | |
| 76 | status_t setDrmServiceListener( |
| 77 | int uniqueId, const sp<IDrmServiceListener>& drmServiceListener); |
| 78 | |
aimitakeshi | 27ed8ad | 2010-07-29 10:12:27 +0900 | [diff] [blame] | 79 | DrmConstraints* getConstraints(int uniqueId, const String8* path, const int action); |
| 80 | |
Takeshi Aimi | 3473846 | 2010-11-16 13:56:11 +0900 | [diff] [blame] | 81 | DrmMetadata* getMetadata(int uniqueId, const String8* path); |
| 82 | |
aimitakeshi | 27ed8ad | 2010-07-29 10:12:27 +0900 | [diff] [blame] | 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 | |
Takeshi Aimi | 2272ee2 | 2010-09-20 23:40:41 +0900 | [diff] [blame] | 89 | status_t saveRights(int uniqueId, const DrmRights& drmRights, |
aimitakeshi | 27ed8ad | 2010-07-29 10:12:27 +0900 | [diff] [blame] | 90 | const String8& rightsPath, const String8& contentPath); |
| 91 | |
James Dong | bf5b3b2 | 2012-07-30 17:57:39 -0700 | [diff] [blame] | 92 | String8 getOriginalMimeType(int uniqueId, const String8& path, int fd); |
aimitakeshi | 27ed8ad | 2010-07-29 10:12:27 +0900 | [diff] [blame] | 93 | |
| 94 | int getDrmObjectType(int uniqueId, const String8& path, const String8& mimeType); |
| 95 | |
| 96 | int checkRightsStatus(int uniqueId, const String8& path,int action); |
| 97 | |
Jeff Tinker | 5d49bef | 2018-10-03 23:01:09 -0700 | [diff] [blame] | 98 | status_t consumeRights(int uniqueId, sp<DecryptHandle>& decryptHandle, int action, |
| 99 | bool reserve); |
aimitakeshi | 27ed8ad | 2010-07-29 10:12:27 +0900 | [diff] [blame] | 100 | |
Takeshi Aimi | 2272ee2 | 2010-09-20 23:40:41 +0900 | [diff] [blame] | 101 | status_t setPlaybackStatus( |
Jeff Tinker | 5d49bef | 2018-10-03 23:01:09 -0700 | [diff] [blame] | 102 | int uniqueId, sp<DecryptHandle>& decryptHandle, int playbackStatus, int64_t position); |
aimitakeshi | 27ed8ad | 2010-07-29 10:12:27 +0900 | [diff] [blame] | 103 | |
| 104 | bool validateAction(int uniqueId, const String8& path, |
| 105 | int action, const ActionDescription& description); |
| 106 | |
Takeshi Aimi | 2272ee2 | 2010-09-20 23:40:41 +0900 | [diff] [blame] | 107 | status_t removeRights(int uniqueId, const String8& path); |
aimitakeshi | 27ed8ad | 2010-07-29 10:12:27 +0900 | [diff] [blame] | 108 | |
Takeshi Aimi | 2272ee2 | 2010-09-20 23:40:41 +0900 | [diff] [blame] | 109 | status_t removeAllRights(int uniqueId); |
aimitakeshi | 27ed8ad | 2010-07-29 10:12:27 +0900 | [diff] [blame] | 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 | |
Jeff Tinker | 5d49bef | 2018-10-03 23:01:09 -0700 | [diff] [blame] | 119 | sp<DecryptHandle> openDecryptSession( |
James Dong | 9d2f386 | 2012-01-10 08:24:37 -0800 | [diff] [blame] | 120 | int uniqueId, int fd, off64_t offset, off64_t length, const char *mime); |
aimitakeshi | 27ed8ad | 2010-07-29 10:12:27 +0900 | [diff] [blame] | 121 | |
Jeff Tinker | 5d49bef | 2018-10-03 23:01:09 -0700 | [diff] [blame] | 122 | sp<DecryptHandle> openDecryptSession( |
James Dong | 9d2f386 | 2012-01-10 08:24:37 -0800 | [diff] [blame] | 123 | int uniqueId, const char* uri, const char* mime); |
Takeshi Aimi | e943f84 | 2010-10-08 23:05:49 +0900 | [diff] [blame] | 124 | |
Jeff Tinker | 5d49bef | 2018-10-03 23:01:09 -0700 | [diff] [blame] | 125 | sp<DecryptHandle> openDecryptSession(int uniqueId, const DrmBuffer& buf, |
Kei Takahashi | cba7b32 | 2012-01-18 17:10:19 +0900 | [diff] [blame] | 126 | const String8& mimeType); |
| 127 | |
Jeff Tinker | 5d49bef | 2018-10-03 23:01:09 -0700 | [diff] [blame] | 128 | status_t closeDecryptSession(int uniqueId, sp<DecryptHandle>& decryptHandle); |
aimitakeshi | 27ed8ad | 2010-07-29 10:12:27 +0900 | [diff] [blame] | 129 | |
Jeff Tinker | 5d49bef | 2018-10-03 23:01:09 -0700 | [diff] [blame] | 130 | status_t initializeDecryptUnit(int uniqueId, sp<DecryptHandle>& decryptHandle, |
aimitakeshi | 27ed8ad | 2010-07-29 10:12:27 +0900 | [diff] [blame] | 131 | int decryptUnitId, const DrmBuffer* headerInfo); |
| 132 | |
Jeff Tinker | 5d49bef | 2018-10-03 23:01:09 -0700 | [diff] [blame] | 133 | status_t decrypt(int uniqueId, sp<DecryptHandle>& decryptHandle, int decryptUnitId, |
Takeshi Aimi | 2272ee2 | 2010-09-20 23:40:41 +0900 | [diff] [blame] | 134 | const DrmBuffer* encBuffer, DrmBuffer** decBuffer, DrmBuffer* IV); |
aimitakeshi | 27ed8ad | 2010-07-29 10:12:27 +0900 | [diff] [blame] | 135 | |
Jeff Tinker | 5d49bef | 2018-10-03 23:01:09 -0700 | [diff] [blame] | 136 | status_t finalizeDecryptUnit(int uniqueId, sp<DecryptHandle>& decryptHandle, |
| 137 | int decryptUnitId); |
aimitakeshi | 27ed8ad | 2010-07-29 10:12:27 +0900 | [diff] [blame] | 138 | |
Jeff Tinker | 5d49bef | 2018-10-03 23:01:09 -0700 | [diff] [blame] | 139 | ssize_t pread(int uniqueId, sp<DecryptHandle>& decryptHandle, |
Gloria Wang | a2cd44c | 2010-11-19 15:19:36 -0800 | [diff] [blame] | 140 | void* buffer, ssize_t numBytes, off64_t offset); |
aimitakeshi | 27ed8ad | 2010-07-29 10:12:27 +0900 | [diff] [blame] | 141 | |
James Dong | 8635b7b | 2011-03-14 17:01:38 -0700 | [diff] [blame] | 142 | virtual status_t dump(int fd, const Vector<String16>& args); |
| 143 | |
aimitakeshi | 27ed8ad | 2010-07-29 10:12:27 +0900 | [diff] [blame] | 144 | private: |
Robert Shih | 7bcf792 | 2020-02-07 15:01:57 -0800 | [diff] [blame] | 145 | sp<DrmManager> mDrmManager; |
aimitakeshi | 27ed8ad | 2010-07-29 10:12:27 +0900 | [diff] [blame] | 146 | }; |
| 147 | |
| 148 | }; |
| 149 | |
| 150 | #endif /* __DRM_MANAGER_SERVICE_H__ */ |
| 151 | |