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 | c3af31b | 2019-09-20 21:45:01 -0700 | [diff] [blame^] | 21 | #include <binder/IBinder.h> |
| 22 | #include <media/IResourceManagerService.h> |
Ronghua Wu | 10305cc | 2015-02-22 07:55:32 -0800 | [diff] [blame] | 23 | #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 Shih | c3af31b | 2019-09-20 21:45:01 -0700 | [diff] [blame^] | 29 | #include <map> |
| 30 | #include <utility> |
| 31 | #include <vector> |
| 32 | |
Ronghua Wu | 10305cc | 2015-02-22 07:55:32 -0800 | [diff] [blame] | 33 | namespace android { |
| 34 | |
| 35 | class DrmSessionManagerTest; |
Robert Shih | c3af31b | 2019-09-20 21:45:01 -0700 | [diff] [blame^] | 36 | class IResourceManagerClient; |
Ronghua Wu | 10305cc | 2015-02-22 07:55:32 -0800 | [diff] [blame] | 37 | |
| 38 | bool isEqualSessionId(const Vector<uint8_t> &sessionId1, const Vector<uint8_t> &sessionId2); |
| 39 | |
| 40 | struct SessionInfo { |
Robert Shih | c3af31b | 2019-09-20 21:45:01 -0700 | [diff] [blame^] | 41 | pid_t pid; |
| 42 | uid_t uid; |
| 43 | int64_t clientId; |
Ronghua Wu | 10305cc | 2015-02-22 07:55:32 -0800 | [diff] [blame] | 44 | }; |
| 45 | |
Robert Shih | c3af31b | 2019-09-20 21:45:01 -0700 | [diff] [blame^] | 46 | typedef std::map<std::vector<uint8_t>, SessionInfo> SessionInfoMap; |
Ronghua Wu | 10305cc | 2015-02-22 07:55:32 -0800 | [diff] [blame] | 47 | |
Robert Shih | c3af31b | 2019-09-20 21:45:01 -0700 | [diff] [blame^] | 48 | struct DrmSessionManager : public IBinder::DeathRecipient { |
Ronghua Wu | 5c3da20 | 2015-02-22 08:45:28 -0800 | [diff] [blame] | 49 | static sp<DrmSessionManager> Instance(); |
| 50 | |
Ronghua Wu | 10305cc | 2015-02-22 07:55:32 -0800 | [diff] [blame] | 51 | DrmSessionManager(); |
Robert Shih | c3af31b | 2019-09-20 21:45:01 -0700 | [diff] [blame^] | 52 | explicit DrmSessionManager(const sp<IResourceManagerService> &service); |
Ronghua Wu | 10305cc | 2015-02-22 07:55:32 -0800 | [diff] [blame] | 53 | |
Robert Shih | c3af31b | 2019-09-20 21:45:01 -0700 | [diff] [blame^] | 54 | void addSession(int pid, const sp<IResourceManagerClient>& drm, const Vector<uint8_t>& sessionId); |
Ronghua Wu | 10305cc | 2015-02-22 07:55:32 -0800 | [diff] [blame] | 55 | void useSession(const Vector<uint8_t>& sessionId); |
| 56 | void removeSession(const Vector<uint8_t>& sessionId); |
Ronghua Wu | 10305cc | 2015-02-22 07:55:32 -0800 | [diff] [blame] | 57 | bool reclaimSession(int callingPid); |
| 58 | |
Robert Shih | c3af31b | 2019-09-20 21:45:01 -0700 | [diff] [blame^] | 59 | // 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 Wu | 10305cc | 2015-02-22 07:55:32 -0800 | [diff] [blame] | 66 | protected: |
| 67 | virtual ~DrmSessionManager(); |
| 68 | |
| 69 | private: |
Robert Shih | c3af31b | 2019-09-20 21:45:01 -0700 | [diff] [blame^] | 70 | void init(); |
Ronghua Wu | 10305cc | 2015-02-22 07:55:32 -0800 | [diff] [blame] | 71 | |
Robert Shih | c3af31b | 2019-09-20 21:45:01 -0700 | [diff] [blame^] | 72 | sp<IResourceManagerService> mService; |
Ronghua Wu | 10305cc | 2015-02-22 07:55:32 -0800 | [diff] [blame] | 73 | mutable Mutex mLock; |
Robert Shih | c3af31b | 2019-09-20 21:45:01 -0700 | [diff] [blame^] | 74 | SessionInfoMap mSessionMap; |
| 75 | bool mInitialized; |
Ronghua Wu | 10305cc | 2015-02-22 07:55:32 -0800 | [diff] [blame] | 76 | |
| 77 | DISALLOW_EVIL_CONSTRUCTORS(DrmSessionManager); |
| 78 | }; |
| 79 | |
| 80 | } // namespace android |
| 81 | |
| 82 | #endif // DRM_SESSION_MANAGER_H_ |