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