blob: f9b8bef8bc21877ca172752fb070fa02859b7e0f [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
Steven Moreland1a394d52019-01-11 15:49:24 -080063 static bool selinuxIsProtectedCallAllowed(pid_t spid, const char* ssid, drm_perm_t perm);
Riley Spahnf785f492014-07-01 15:32:31 -070064
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
Jeff Tinker5d49bef2018-10-03 23:01:09 -070098 status_t consumeRights(int uniqueId, sp<DecryptHandle>& decryptHandle, int action,
99 bool reserve);
aimitakeshi27ed8ad2010-07-29 10:12:27 +0900100
Takeshi Aimi2272ee22010-09-20 23:40:41 +0900101 status_t setPlaybackStatus(
Jeff Tinker5d49bef2018-10-03 23:01:09 -0700102 int uniqueId, sp<DecryptHandle>& decryptHandle, int playbackStatus, int64_t position);
aimitakeshi27ed8ad2010-07-29 10:12:27 +0900103
104 bool validateAction(int uniqueId, const String8& path,
105 int action, const ActionDescription& description);
106
Takeshi Aimi2272ee22010-09-20 23:40:41 +0900107 status_t removeRights(int uniqueId, const String8& path);
aimitakeshi27ed8ad2010-07-29 10:12:27 +0900108
Takeshi Aimi2272ee22010-09-20 23:40:41 +0900109 status_t removeAllRights(int uniqueId);
aimitakeshi27ed8ad2010-07-29 10:12:27 +0900110
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 Tinker5d49bef2018-10-03 23:01:09 -0700119 sp<DecryptHandle> openDecryptSession(
James Dong9d2f3862012-01-10 08:24:37 -0800120 int uniqueId, int fd, off64_t offset, off64_t length, const char *mime);
aimitakeshi27ed8ad2010-07-29 10:12:27 +0900121
Jeff Tinker5d49bef2018-10-03 23:01:09 -0700122 sp<DecryptHandle> openDecryptSession(
James Dong9d2f3862012-01-10 08:24:37 -0800123 int uniqueId, const char* uri, const char* mime);
Takeshi Aimie943f842010-10-08 23:05:49 +0900124
Jeff Tinker5d49bef2018-10-03 23:01:09 -0700125 sp<DecryptHandle> openDecryptSession(int uniqueId, const DrmBuffer& buf,
Kei Takahashicba7b322012-01-18 17:10:19 +0900126 const String8& mimeType);
127
Jeff Tinker5d49bef2018-10-03 23:01:09 -0700128 status_t closeDecryptSession(int uniqueId, sp<DecryptHandle>& decryptHandle);
aimitakeshi27ed8ad2010-07-29 10:12:27 +0900129
Jeff Tinker5d49bef2018-10-03 23:01:09 -0700130 status_t initializeDecryptUnit(int uniqueId, sp<DecryptHandle>& decryptHandle,
aimitakeshi27ed8ad2010-07-29 10:12:27 +0900131 int decryptUnitId, const DrmBuffer* headerInfo);
132
Jeff Tinker5d49bef2018-10-03 23:01:09 -0700133 status_t decrypt(int uniqueId, sp<DecryptHandle>& decryptHandle, int decryptUnitId,
Takeshi Aimi2272ee22010-09-20 23:40:41 +0900134 const DrmBuffer* encBuffer, DrmBuffer** decBuffer, DrmBuffer* IV);
aimitakeshi27ed8ad2010-07-29 10:12:27 +0900135
Jeff Tinker5d49bef2018-10-03 23:01:09 -0700136 status_t finalizeDecryptUnit(int uniqueId, sp<DecryptHandle>& decryptHandle,
137 int decryptUnitId);
aimitakeshi27ed8ad2010-07-29 10:12:27 +0900138
Jeff Tinker5d49bef2018-10-03 23:01:09 -0700139 ssize_t pread(int uniqueId, sp<DecryptHandle>& decryptHandle,
Gloria Wanga2cd44c2010-11-19 15:19:36 -0800140 void* buffer, ssize_t numBytes, off64_t offset);
aimitakeshi27ed8ad2010-07-29 10:12:27 +0900141
James Dong8635b7b2011-03-14 17:01:38 -0700142 virtual status_t dump(int fd, const Vector<String16>& args);
143
aimitakeshi27ed8ad2010-07-29 10:12:27 +0900144private:
Robert Shih7bcf7922020-02-07 15:01:57 -0800145 sp<DrmManager> mDrmManager;
aimitakeshi27ed8ad2010-07-29 10:12:27 +0900146};
147
148};
149
150#endif /* __DRM_MANAGER_SERVICE_H__ */
151