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 | |
Robert Shih | 10fe943 | 2019-11-09 08:26:49 -0800 | [diff] [blame] | 20 | #include <android/hardware/drm/1.0/ICryptoFactory.h> |
Robert Shih | 5ff3ad6 | 2019-11-09 08:26:49 -0800 | [diff] [blame] | 21 | #include <android/hardware/drm/1.0/IDrmFactory.h> |
Robert Shih | 28c2ed3 | 2019-10-27 22:55:12 -0700 | [diff] [blame] | 22 | #include <utils/Errors.h> // for status_t |
| 23 | #include <utils/StrongPointer.h> |
Robert Shih | 61e1c76 | 2019-10-31 21:26:58 -0700 | [diff] [blame] | 24 | #include <binder/Parcel.h> |
Robert Shih | 10fe943 | 2019-11-09 08:26:49 -0800 | [diff] [blame] | 25 | #include <vector> |
| 26 | |
| 27 | using namespace ::android::hardware::drm; |
Robert Shih | 28c2ed3 | 2019-10-27 22:55:12 -0700 | [diff] [blame] | 28 | |
| 29 | namespace android { |
| 30 | |
| 31 | struct ICrypto; |
| 32 | struct IDrm; |
| 33 | |
| 34 | namespace DrmUtils { |
| 35 | |
| 36 | bool UseDrmService(); |
| 37 | |
| 38 | sp<IDrm> MakeDrm(status_t *pstatus = nullptr); |
| 39 | |
| 40 | sp<ICrypto> MakeCrypto(status_t *pstatus = nullptr); |
| 41 | |
Robert Shih | 61e1c76 | 2019-10-31 21:26:58 -0700 | [diff] [blame] | 42 | template<typename BA> |
| 43 | void WriteByteArray(Parcel &obj, const BA &vec) { |
| 44 | obj.writeInt32(vec.size()); |
| 45 | if (vec.size()) { |
| 46 | obj.write(vec.data(), vec.size()); |
| 47 | } |
| 48 | } |
| 49 | |
| 50 | template<typename ET, typename BA> |
| 51 | void WriteEventToParcel( |
| 52 | Parcel &obj, |
| 53 | ET eventType, |
| 54 | const BA &sessionId, |
| 55 | const BA &data) { |
| 56 | WriteByteArray(obj, sessionId); |
| 57 | WriteByteArray(obj, data); |
| 58 | obj.writeInt32(eventType); |
| 59 | } |
| 60 | |
| 61 | template<typename BA> |
| 62 | void WriteExpirationUpdateToParcel( |
| 63 | Parcel &obj, |
| 64 | const BA &sessionId, |
| 65 | int64_t expiryTimeInMS) { |
| 66 | WriteByteArray(obj, sessionId); |
| 67 | obj.writeInt64(expiryTimeInMS); |
| 68 | } |
| 69 | |
| 70 | template<typename BA, typename KSL> |
| 71 | void WriteKeysChange( |
| 72 | Parcel &obj, |
| 73 | const BA &sessionId, |
| 74 | const KSL &keyStatusList, |
| 75 | bool hasNewUsableKey) { |
| 76 | WriteByteArray(obj, sessionId); |
| 77 | obj.writeInt32(keyStatusList.size()); |
| 78 | for (const auto &keyStatus : keyStatusList) { |
| 79 | WriteByteArray(obj, keyStatus.keyId); |
| 80 | obj.writeInt32(keyStatus.type); |
| 81 | } |
| 82 | obj.writeInt32(hasNewUsableKey); |
| 83 | } |
| 84 | |
Robert Shih | c0d1d0e | 2019-11-24 13:21:04 -0800 | [diff] [blame^] | 85 | std::vector<sp<::V1_0::IDrmFactory>> MakeDrmFactories(const uint8_t uuid[16] = nullptr); |
Robert Shih | 5ff3ad6 | 2019-11-09 08:26:49 -0800 | [diff] [blame] | 86 | |
| 87 | std::vector<sp<::V1_0::IDrmPlugin>> MakeDrmPlugins(const uint8_t uuid[16], |
| 88 | const char *appPackageName); |
| 89 | |
Robert Shih | 10fe943 | 2019-11-09 08:26:49 -0800 | [diff] [blame] | 90 | std::vector<sp<::V1_0::ICryptoFactory>> MakeCryptoFactories(const uint8_t uuid[16]); |
| 91 | |
| 92 | std::vector<sp<::V1_0::ICryptoPlugin>> MakeCryptoPlugins(const uint8_t uuid[16], |
| 93 | const void *initData, size_t initDataSize); |
| 94 | |
Robert Shih | 28c2ed3 | 2019-10-27 22:55:12 -0700 | [diff] [blame] | 95 | } // namespace DrmUtils |
| 96 | |
| 97 | } // namespace android |
| 98 | |
| 99 | #endif // ANDROID_DRMUTILS_H |