Ronghua Wu | 10305cc | 2015-02-22 07:55:32 -0800 | [diff] [blame] | 1 | /* |
| 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 Shih | 0f3a8a0 | 2019-11-14 15:43:39 -0800 | [diff] [blame^] | 21 | #include <aidl/android/media/IResourceManagerClient.h> |
| 22 | #include <aidl/android/media/IResourceManagerService.h> |
| 23 | #include <android/binder_auto_utils.h> |
Ronghua Wu | 10305cc | 2015-02-22 07:55:32 -0800 | [diff] [blame] | 24 | #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 Shih | c3af31b | 2019-09-20 21:45:01 -0700 | [diff] [blame] | 30 | #include <map> |
Robert Shih | 0f3a8a0 | 2019-11-14 15:43:39 -0800 | [diff] [blame^] | 31 | #include <memory> |
Robert Shih | c3af31b | 2019-09-20 21:45:01 -0700 | [diff] [blame] | 32 | #include <utility> |
| 33 | #include <vector> |
| 34 | |
Ronghua Wu | 10305cc | 2015-02-22 07:55:32 -0800 | [diff] [blame] | 35 | namespace android { |
| 36 | |
| 37 | class DrmSessionManagerTest; |
Chong Zhang | 181e695 | 2019-10-09 13:23:39 -0700 | [diff] [blame] | 38 | |
Robert Shih | 0f3a8a0 | 2019-11-14 15:43:39 -0800 | [diff] [blame^] | 39 | using aidl::android::media::IResourceManagerClient; |
| 40 | using aidl::android::media::IResourceManagerService; |
Ronghua Wu | 10305cc | 2015-02-22 07:55:32 -0800 | [diff] [blame] | 41 | |
| 42 | bool isEqualSessionId(const Vector<uint8_t> &sessionId1, const Vector<uint8_t> &sessionId2); |
| 43 | |
| 44 | struct SessionInfo { |
Robert Shih | c3af31b | 2019-09-20 21:45:01 -0700 | [diff] [blame] | 45 | pid_t pid; |
| 46 | uid_t uid; |
| 47 | int64_t clientId; |
Ronghua Wu | 10305cc | 2015-02-22 07:55:32 -0800 | [diff] [blame] | 48 | }; |
| 49 | |
Robert Shih | c3af31b | 2019-09-20 21:45:01 -0700 | [diff] [blame] | 50 | typedef std::map<std::vector<uint8_t>, SessionInfo> SessionInfoMap; |
Ronghua Wu | 10305cc | 2015-02-22 07:55:32 -0800 | [diff] [blame] | 51 | |
Robert Shih | 0f3a8a0 | 2019-11-14 15:43:39 -0800 | [diff] [blame^] | 52 | struct DrmSessionManager : public RefBase { |
Ronghua Wu | 5c3da20 | 2015-02-22 08:45:28 -0800 | [diff] [blame] | 53 | static sp<DrmSessionManager> Instance(); |
| 54 | |
Ronghua Wu | 10305cc | 2015-02-22 07:55:32 -0800 | [diff] [blame] | 55 | DrmSessionManager(); |
Robert Shih | 0f3a8a0 | 2019-11-14 15:43:39 -0800 | [diff] [blame^] | 56 | explicit DrmSessionManager(const std::shared_ptr<IResourceManagerService> &service); |
Ronghua Wu | 10305cc | 2015-02-22 07:55:32 -0800 | [diff] [blame] | 57 | |
Robert Shih | 0f3a8a0 | 2019-11-14 15:43:39 -0800 | [diff] [blame^] | 58 | void addSession(int pid, |
| 59 | const std::shared_ptr<IResourceManagerClient>& drm, |
| 60 | const Vector<uint8_t>& sessionId); |
Ronghua Wu | 10305cc | 2015-02-22 07:55:32 -0800 | [diff] [blame] | 61 | void useSession(const Vector<uint8_t>& sessionId); |
| 62 | void removeSession(const Vector<uint8_t>& sessionId); |
Ronghua Wu | 10305cc | 2015-02-22 07:55:32 -0800 | [diff] [blame] | 63 | bool reclaimSession(int callingPid); |
| 64 | |
Robert Shih | c3af31b | 2019-09-20 21:45:01 -0700 | [diff] [blame] | 65 | // sanity check APIs |
| 66 | size_t getSessionCount() const; |
| 67 | bool containsSession(const Vector<uint8_t>& sessionId) const; |
| 68 | |
| 69 | // implements DeathRecipient |
Robert Shih | 0f3a8a0 | 2019-11-14 15:43:39 -0800 | [diff] [blame^] | 70 | void binderDied(); |
Robert Shih | c3af31b | 2019-09-20 21:45:01 -0700 | [diff] [blame] | 71 | |
Ronghua Wu | 10305cc | 2015-02-22 07:55:32 -0800 | [diff] [blame] | 72 | protected: |
| 73 | virtual ~DrmSessionManager(); |
| 74 | |
| 75 | private: |
Robert Shih | c3af31b | 2019-09-20 21:45:01 -0700 | [diff] [blame] | 76 | void init(); |
Ronghua Wu | 10305cc | 2015-02-22 07:55:32 -0800 | [diff] [blame] | 77 | |
Robert Shih | 0f3a8a0 | 2019-11-14 15:43:39 -0800 | [diff] [blame^] | 78 | std::shared_ptr<IResourceManagerService> mService; |
Ronghua Wu | 10305cc | 2015-02-22 07:55:32 -0800 | [diff] [blame] | 79 | mutable Mutex mLock; |
Robert Shih | c3af31b | 2019-09-20 21:45:01 -0700 | [diff] [blame] | 80 | SessionInfoMap mSessionMap; |
| 81 | bool mInitialized; |
Robert Shih | 0f3a8a0 | 2019-11-14 15:43:39 -0800 | [diff] [blame^] | 82 | ::ndk::ScopedAIBinder_DeathRecipient mDeathRecipient; |
Ronghua Wu | 10305cc | 2015-02-22 07:55:32 -0800 | [diff] [blame] | 83 | |
| 84 | DISALLOW_EVIL_CONSTRUCTORS(DrmSessionManager); |
| 85 | }; |
| 86 | |
| 87 | } // namespace android |
| 88 | |
| 89 | #endif // DRM_SESSION_MANAGER_H_ |