blob: 3258f7a76f129b35eb23d5c03d0c893f13ef36e4 [file] [log] [blame]
Ronghua Wu10305cc2015-02-22 07:55:32 -08001/*
2 * Copyright (C) 2015 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_SESSION_MANAGER_H_
18
19#define DRM_SESSION_MANAGER_H_
20
Robert Shihc3af31b2019-09-20 21:45:01 -070021#include <binder/IBinder.h>
Ronghua Wu10305cc2015-02-22 07:55:32 -080022#include <media/stagefright/foundation/ABase.h>
23#include <utils/RefBase.h>
24#include <utils/KeyedVector.h>
25#include <utils/threads.h>
26#include <utils/Vector.h>
27
Robert Shihc3af31b2019-09-20 21:45:01 -070028#include <map>
29#include <utility>
30#include <vector>
31
Ronghua Wu10305cc2015-02-22 07:55:32 -080032namespace android {
33
34class DrmSessionManagerTest;
Chong Zhang181e6952019-10-09 13:23:39 -070035
36namespace media {
Robert Shihc3af31b2019-09-20 21:45:01 -070037class IResourceManagerClient;
Chong Zhang181e6952019-10-09 13:23:39 -070038class IResourceManagerService;
39}
40using android::media::IResourceManagerClient;
41using android::media::IResourceManagerService;
Ronghua Wu10305cc2015-02-22 07:55:32 -080042
43bool isEqualSessionId(const Vector<uint8_t> &sessionId1, const Vector<uint8_t> &sessionId2);
44
45struct SessionInfo {
Robert Shihc3af31b2019-09-20 21:45:01 -070046 pid_t pid;
47 uid_t uid;
48 int64_t clientId;
Ronghua Wu10305cc2015-02-22 07:55:32 -080049};
50
Robert Shihc3af31b2019-09-20 21:45:01 -070051typedef std::map<std::vector<uint8_t>, SessionInfo> SessionInfoMap;
Ronghua Wu10305cc2015-02-22 07:55:32 -080052
Robert Shihc3af31b2019-09-20 21:45:01 -070053struct DrmSessionManager : public IBinder::DeathRecipient {
Ronghua Wu5c3da202015-02-22 08:45:28 -080054 static sp<DrmSessionManager> Instance();
55
Ronghua Wu10305cc2015-02-22 07:55:32 -080056 DrmSessionManager();
Robert Shihc3af31b2019-09-20 21:45:01 -070057 explicit DrmSessionManager(const sp<IResourceManagerService> &service);
Ronghua Wu10305cc2015-02-22 07:55:32 -080058
Robert Shihc3af31b2019-09-20 21:45:01 -070059 void addSession(int pid, const sp<IResourceManagerClient>& drm, const Vector<uint8_t>& sessionId);
Ronghua Wu10305cc2015-02-22 07:55:32 -080060 void useSession(const Vector<uint8_t>& sessionId);
61 void removeSession(const Vector<uint8_t>& sessionId);
Ronghua Wu10305cc2015-02-22 07:55:32 -080062 bool reclaimSession(int callingPid);
63
Robert Shihc3af31b2019-09-20 21:45:01 -070064 // sanity check APIs
65 size_t getSessionCount() const;
66 bool containsSession(const Vector<uint8_t>& sessionId) const;
67
68 // implements DeathRecipient
69 virtual void binderDied(const wp<IBinder>& /*who*/);
70
Ronghua Wu10305cc2015-02-22 07:55:32 -080071protected:
72 virtual ~DrmSessionManager();
73
74private:
Robert Shihc3af31b2019-09-20 21:45:01 -070075 void init();
Ronghua Wu10305cc2015-02-22 07:55:32 -080076
Robert Shihc3af31b2019-09-20 21:45:01 -070077 sp<IResourceManagerService> mService;
Ronghua Wu10305cc2015-02-22 07:55:32 -080078 mutable Mutex mLock;
Robert Shihc3af31b2019-09-20 21:45:01 -070079 SessionInfoMap mSessionMap;
80 bool mInitialized;
Ronghua Wu10305cc2015-02-22 07:55:32 -080081
82 DISALLOW_EVIL_CONSTRUCTORS(DrmSessionManager);
83};
84
85} // namespace android
86
87#endif // DRM_SESSION_MANAGER_H_