blob: a5bc09bfabb5ecc7fff43790f82ccfc49a53661f [file] [log] [blame]
Robert Shih28c2ed32019-10-27 22:55:12 -07001/*
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 Shih61e1c762019-10-31 21:26:58 -070022#include <binder/Parcel.h>
Robert Shih28c2ed32019-10-27 22:55:12 -070023
24namespace android {
25
26struct ICrypto;
27struct IDrm;
28
29namespace DrmUtils {
30
31bool UseDrmService();
32
33sp<IDrm> MakeDrm(status_t *pstatus = nullptr);
34
35sp<ICrypto> MakeCrypto(status_t *pstatus = nullptr);
36
Robert Shih61e1c762019-10-31 21:26:58 -070037template<typename BA>
38void 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
45template<typename ET, typename BA>
46void 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
56template<typename BA>
57void WriteExpirationUpdateToParcel(
58 Parcel &obj,
59 const BA &sessionId,
60 int64_t expiryTimeInMS) {
61 WriteByteArray(obj, sessionId);
62 obj.writeInt64(expiryTimeInMS);
63}
64
65template<typename BA, typename KSL>
66void 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 Shih28c2ed32019-10-27 22:55:12 -070080} // namespace DrmUtils
81
82} // namespace android
83
84#endif // ANDROID_DRMUTILS_H