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