blob: 9e43504de076183194784e2294eeabd01d3f9122 [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 Shih0f3a8a02019-11-14 15:43:39 -080021#include <aidl/android/media/IResourceManagerClient.h>
22#include <aidl/android/media/IResourceManagerService.h>
23#include <android/binder_auto_utils.h>
Ronghua Wu10305cc2015-02-22 07:55:32 -080024#include <media/stagefright/foundation/ABase.h>
25#include <utils/RefBase.h>
26#include <utils/KeyedVector.h>
27#include <utils/threads.h>
28#include <utils/Vector.h>
29
Robert Shihc3af31b2019-09-20 21:45:01 -070030#include <map>
Robert Shih0f3a8a02019-11-14 15:43:39 -080031#include <memory>
Robert Shihc3af31b2019-09-20 21:45:01 -070032#include <utility>
33#include <vector>
34
Ronghua Wu10305cc2015-02-22 07:55:32 -080035namespace android {
36
37class DrmSessionManagerTest;
Chong Zhang181e6952019-10-09 13:23:39 -070038
Robert Shih0f3a8a02019-11-14 15:43:39 -080039using aidl::android::media::IResourceManagerClient;
40using aidl::android::media::IResourceManagerService;
Ronghua Wu10305cc2015-02-22 07:55:32 -080041
42bool isEqualSessionId(const Vector<uint8_t> &sessionId1, const Vector<uint8_t> &sessionId2);
43
44struct SessionInfo {
Robert Shihc3af31b2019-09-20 21:45:01 -070045 pid_t pid;
46 uid_t uid;
47 int64_t clientId;
Ronghua Wu10305cc2015-02-22 07:55:32 -080048};
49
Robert Shihc3af31b2019-09-20 21:45:01 -070050typedef std::map<std::vector<uint8_t>, SessionInfo> SessionInfoMap;
Ronghua Wu10305cc2015-02-22 07:55:32 -080051
Robert Shih0f3a8a02019-11-14 15:43:39 -080052struct DrmSessionManager : public RefBase {
Ronghua Wu5c3da202015-02-22 08:45:28 -080053 static sp<DrmSessionManager> Instance();
54
Ronghua Wu10305cc2015-02-22 07:55:32 -080055 DrmSessionManager();
Robert Shih0f3a8a02019-11-14 15:43:39 -080056 explicit DrmSessionManager(const std::shared_ptr<IResourceManagerService> &service);
Ronghua Wu10305cc2015-02-22 07:55:32 -080057
Robert Shih0f3a8a02019-11-14 15:43:39 -080058 void addSession(int pid,
59 const std::shared_ptr<IResourceManagerClient>& drm,
60 const Vector<uint8_t>& sessionId);
Ronghua Wu10305cc2015-02-22 07:55:32 -080061 void useSession(const Vector<uint8_t>& sessionId);
62 void removeSession(const Vector<uint8_t>& sessionId);
Ronghua Wu10305cc2015-02-22 07:55:32 -080063 bool reclaimSession(int callingPid);
64
Robert Shihc3af31b2019-09-20 21:45:01 -070065 // sanity check APIs
66 size_t getSessionCount() const;
67 bool containsSession(const Vector<uint8_t>& sessionId) const;
68
69 // implements DeathRecipient
Robert Shih0f3a8a02019-11-14 15:43:39 -080070 void binderDied();
Robert Shihc3af31b2019-09-20 21:45:01 -070071
Ronghua Wu10305cc2015-02-22 07:55:32 -080072protected:
73 virtual ~DrmSessionManager();
74
75private:
Robert Shihc3af31b2019-09-20 21:45:01 -070076 void init();
Ronghua Wu10305cc2015-02-22 07:55:32 -080077
Robert Shih0f3a8a02019-11-14 15:43:39 -080078 std::shared_ptr<IResourceManagerService> mService;
Ronghua Wu10305cc2015-02-22 07:55:32 -080079 mutable Mutex mLock;
Robert Shihc3af31b2019-09-20 21:45:01 -070080 SessionInfoMap mSessionMap;
81 bool mInitialized;
Robert Shih0f3a8a02019-11-14 15:43:39 -080082 ::ndk::ScopedAIBinder_DeathRecipient mDeathRecipient;
Ronghua Wu10305cc2015-02-22 07:55:32 -080083
84 DISALLOW_EVIL_CONSTRUCTORS(DrmSessionManager);
85};
86
87} // namespace android
88
89#endif // DRM_SESSION_MANAGER_H_