Robert Shih | 28c2ed3 | 2019-10-27 22:55:12 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2019 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 ANDROID_DRMUTILS_H |
| 18 | #define ANDROID_DRMUTILS_H |
| 19 | |
| 20 | #include <utils/Errors.h> // for status_t |
| 21 | #include <utils/StrongPointer.h> |
Robert Shih | 61e1c76 | 2019-10-31 21:26:58 -0700 | [diff] [blame] | 22 | #include <binder/Parcel.h> |
Robert Shih | 28c2ed3 | 2019-10-27 22:55:12 -0700 | [diff] [blame] | 23 | |
| 24 | namespace android { |
| 25 | |
| 26 | struct ICrypto; |
| 27 | struct IDrm; |
| 28 | |
| 29 | namespace DrmUtils { |
| 30 | |
| 31 | bool UseDrmService(); |
| 32 | |
| 33 | sp<IDrm> MakeDrm(status_t *pstatus = nullptr); |
| 34 | |
| 35 | sp<ICrypto> MakeCrypto(status_t *pstatus = nullptr); |
| 36 | |
Robert Shih | 61e1c76 | 2019-10-31 21:26:58 -0700 | [diff] [blame] | 37 | template<typename BA> |
| 38 | void WriteByteArray(Parcel &obj, const BA &vec) { |
| 39 | obj.writeInt32(vec.size()); |
| 40 | if (vec.size()) { |
| 41 | obj.write(vec.data(), vec.size()); |
| 42 | } |
| 43 | } |
| 44 | |
| 45 | template<typename ET, typename BA> |
| 46 | void WriteEventToParcel( |
| 47 | Parcel &obj, |
| 48 | ET eventType, |
| 49 | const BA &sessionId, |
| 50 | const BA &data) { |
| 51 | WriteByteArray(obj, sessionId); |
| 52 | WriteByteArray(obj, data); |
| 53 | obj.writeInt32(eventType); |
| 54 | } |
| 55 | |
| 56 | template<typename BA> |
| 57 | void WriteExpirationUpdateToParcel( |
| 58 | Parcel &obj, |
| 59 | const BA &sessionId, |
| 60 | int64_t expiryTimeInMS) { |
| 61 | WriteByteArray(obj, sessionId); |
| 62 | obj.writeInt64(expiryTimeInMS); |
| 63 | } |
| 64 | |
| 65 | template<typename BA, typename KSL> |
| 66 | void WriteKeysChange( |
| 67 | Parcel &obj, |
| 68 | const BA &sessionId, |
| 69 | const KSL &keyStatusList, |
| 70 | bool hasNewUsableKey) { |
| 71 | WriteByteArray(obj, sessionId); |
| 72 | obj.writeInt32(keyStatusList.size()); |
| 73 | for (const auto &keyStatus : keyStatusList) { |
| 74 | WriteByteArray(obj, keyStatus.keyId); |
| 75 | obj.writeInt32(keyStatus.type); |
| 76 | } |
| 77 | obj.writeInt32(hasNewUsableKey); |
| 78 | } |
| 79 | |
Robert Shih | 28c2ed3 | 2019-10-27 22:55:12 -0700 | [diff] [blame] | 80 | } // namespace DrmUtils |
| 81 | |
| 82 | } // namespace android |
| 83 | |
| 84 | #endif // ANDROID_DRMUTILS_H |