blob: 45cee2e203136cf01b05810400438089fad7ed7a [file] [log] [blame]
aimitakeshi27ed8ad2010-07-29 10:12:27 +09001/*
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
27namespace android {
28
29class DrmManager;
30class String8;
31class 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 */
40class DrmManagerService : public BnDrmManagerService {
41public:
42 static void instantiate();
43
44private:
Riley Spahnf785f492014-07-01 15:32:31 -070045 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
aimitakeshi27ed8ad2010-07-29 10:12:27 +090058 DrmManagerService();
59 virtual ~DrmManagerService();
60
Riley Spahnf785f492014-07-01 15:32:31 -070061 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
aimitakeshi27ed8ad2010-07-29 10:12:27 +090067public:
Gloria Wang8f001512011-07-21 15:10:22 -070068 int addUniqueId(bool isNative);
Takeshi Aimi2272ee22010-09-20 23:40:41 +090069
70 void removeUniqueId(int uniqueId);
71
Takeshi Aimie943f842010-10-08 23:05:49 +090072 void addClient(int uniqueId);
aimitakeshi27ed8ad2010-07-29 10:12:27 +090073
Takeshi Aimie943f842010-10-08 23:05:49 +090074 void removeClient(int uniqueId);
aimitakeshi27ed8ad2010-07-29 10:12:27 +090075
76 status_t setDrmServiceListener(
77 int uniqueId, const sp<IDrmServiceListener>& drmServiceListener);
78
aimitakeshi27ed8ad2010-07-29 10:12:27 +090079 DrmConstraints* getConstraints(int uniqueId, const String8* path, const int action);
80
Takeshi Aimi34738462010-11-16 13:56:11 +090081 DrmMetadata* getMetadata(int uniqueId, const String8* path);
82
aimitakeshi27ed8ad2010-07-29 10:12:27 +090083 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 Aimi2272ee22010-09-20 23:40:41 +090089 status_t saveRights(int uniqueId, const DrmRights& drmRights,
aimitakeshi27ed8ad2010-07-29 10:12:27 +090090 const String8& rightsPath, const String8& contentPath);
91
James Dongbf5b3b22012-07-30 17:57:39 -070092 String8 getOriginalMimeType(int uniqueId, const String8& path, int fd);
aimitakeshi27ed8ad2010-07-29 10:12:27 +090093
94 int getDrmObjectType(int uniqueId, const String8& path, const String8& mimeType);
95
96 int checkRightsStatus(int uniqueId, const String8& path,int action);
97
Takeshi Aimi2272ee22010-09-20 23:40:41 +090098 status_t consumeRights(int uniqueId, DecryptHandle* decryptHandle, int action, bool reserve);
aimitakeshi27ed8ad2010-07-29 10:12:27 +090099
Takeshi Aimi2272ee22010-09-20 23:40:41 +0900100 status_t setPlaybackStatus(
Gloria Wanga2cd44c2010-11-19 15:19:36 -0800101 int uniqueId, DecryptHandle* decryptHandle, int playbackStatus, int64_t position);
aimitakeshi27ed8ad2010-07-29 10:12:27 +0900102
103 bool validateAction(int uniqueId, const String8& path,
104 int action, const ActionDescription& description);
105
Takeshi Aimi2272ee22010-09-20 23:40:41 +0900106 status_t removeRights(int uniqueId, const String8& path);
aimitakeshi27ed8ad2010-07-29 10:12:27 +0900107
Takeshi Aimi2272ee22010-09-20 23:40:41 +0900108 status_t removeAllRights(int uniqueId);
aimitakeshi27ed8ad2010-07-29 10:12:27 +0900109
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
James Dong9d2f3862012-01-10 08:24:37 -0800118 DecryptHandle* openDecryptSession(
119 int uniqueId, int fd, off64_t offset, off64_t length, const char *mime);
aimitakeshi27ed8ad2010-07-29 10:12:27 +0900120
James Dong9d2f3862012-01-10 08:24:37 -0800121 DecryptHandle* openDecryptSession(
122 int uniqueId, const char* uri, const char* mime);
Takeshi Aimie943f842010-10-08 23:05:49 +0900123
Kei Takahashicba7b322012-01-18 17:10:19 +0900124 DecryptHandle* openDecryptSession(int uniqueId, const DrmBuffer& buf,
125 const String8& mimeType);
126
Takeshi Aimi2272ee22010-09-20 23:40:41 +0900127 status_t closeDecryptSession(int uniqueId, DecryptHandle* decryptHandle);
aimitakeshi27ed8ad2010-07-29 10:12:27 +0900128
Takeshi Aimi2272ee22010-09-20 23:40:41 +0900129 status_t initializeDecryptUnit(int uniqueId, DecryptHandle* decryptHandle,
aimitakeshi27ed8ad2010-07-29 10:12:27 +0900130 int decryptUnitId, const DrmBuffer* headerInfo);
131
Takeshi Aimi2272ee22010-09-20 23:40:41 +0900132 status_t decrypt(int uniqueId, DecryptHandle* decryptHandle, int decryptUnitId,
133 const DrmBuffer* encBuffer, DrmBuffer** decBuffer, DrmBuffer* IV);
aimitakeshi27ed8ad2010-07-29 10:12:27 +0900134
Takeshi Aimi2272ee22010-09-20 23:40:41 +0900135 status_t finalizeDecryptUnit(int uniqueId, DecryptHandle* decryptHandle, int decryptUnitId);
aimitakeshi27ed8ad2010-07-29 10:12:27 +0900136
137 ssize_t pread(int uniqueId, DecryptHandle* decryptHandle,
Gloria Wanga2cd44c2010-11-19 15:19:36 -0800138 void* buffer, ssize_t numBytes, off64_t offset);
aimitakeshi27ed8ad2010-07-29 10:12:27 +0900139
James Dong8635b7b2011-03-14 17:01:38 -0700140 virtual status_t dump(int fd, const Vector<String16>& args);
141
aimitakeshi27ed8ad2010-07-29 10:12:27 +0900142private:
143 DrmManager* mDrmManager;
144};
145
146};
147
148#endif /* __DRM_MANAGER_SERVICE_H__ */
149