blob: b1ad5806719ff405284b9263e1430b8191f91915 [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>
22#include <media/IResourceManagerService.h>
Ronghua Wu10305cc2015-02-22 07:55:32 -080023#include <media/stagefright/foundation/ABase.h>
24#include <utils/RefBase.h>
25#include <utils/KeyedVector.h>
26#include <utils/threads.h>
27#include <utils/Vector.h>
28
Robert Shihc3af31b2019-09-20 21:45:01 -070029#include <map>
30#include <utility>
31#include <vector>
32
Ronghua Wu10305cc2015-02-22 07:55:32 -080033namespace android {
34
35class DrmSessionManagerTest;
Robert Shihc3af31b2019-09-20 21:45:01 -070036class IResourceManagerClient;
Ronghua Wu10305cc2015-02-22 07:55:32 -080037
38bool isEqualSessionId(const Vector<uint8_t> &sessionId1, const Vector<uint8_t> &sessionId2);
39
40struct SessionInfo {
Robert Shihc3af31b2019-09-20 21:45:01 -070041 pid_t pid;
42 uid_t uid;
43 int64_t clientId;
Ronghua Wu10305cc2015-02-22 07:55:32 -080044};
45
Robert Shihc3af31b2019-09-20 21:45:01 -070046typedef std::map<std::vector<uint8_t>, SessionInfo> SessionInfoMap;
Ronghua Wu10305cc2015-02-22 07:55:32 -080047
Robert Shihc3af31b2019-09-20 21:45:01 -070048struct DrmSessionManager : public IBinder::DeathRecipient {
Ronghua Wu5c3da202015-02-22 08:45:28 -080049 static sp<DrmSessionManager> Instance();
50
Ronghua Wu10305cc2015-02-22 07:55:32 -080051 DrmSessionManager();
Robert Shihc3af31b2019-09-20 21:45:01 -070052 explicit DrmSessionManager(const sp<IResourceManagerService> &service);
Ronghua Wu10305cc2015-02-22 07:55:32 -080053
Robert Shihc3af31b2019-09-20 21:45:01 -070054 void addSession(int pid, const sp<IResourceManagerClient>& drm, const Vector<uint8_t>& sessionId);
Ronghua Wu10305cc2015-02-22 07:55:32 -080055 void useSession(const Vector<uint8_t>& sessionId);
56 void removeSession(const Vector<uint8_t>& sessionId);
Ronghua Wu10305cc2015-02-22 07:55:32 -080057 bool reclaimSession(int callingPid);
58
Robert Shihc3af31b2019-09-20 21:45:01 -070059 // sanity check APIs
60 size_t getSessionCount() const;
61 bool containsSession(const Vector<uint8_t>& sessionId) const;
62
63 // implements DeathRecipient
64 virtual void binderDied(const wp<IBinder>& /*who*/);
65
Ronghua Wu10305cc2015-02-22 07:55:32 -080066protected:
67 virtual ~DrmSessionManager();
68
69private:
Robert Shihc3af31b2019-09-20 21:45:01 -070070 void init();
Ronghua Wu10305cc2015-02-22 07:55:32 -080071
Robert Shihc3af31b2019-09-20 21:45:01 -070072 sp<IResourceManagerService> mService;
Ronghua Wu10305cc2015-02-22 07:55:32 -080073 mutable Mutex mLock;
Robert Shihc3af31b2019-09-20 21:45:01 -070074 SessionInfoMap mSessionMap;
75 bool mInitialized;
Ronghua Wu10305cc2015-02-22 07:55:32 -080076
77 DISALLOW_EVIL_CONSTRUCTORS(DrmSessionManager);
78};
79
80} // namespace android
81
82#endif // DRM_SESSION_MANAGER_H_