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 //#define LOG_NDEBUG 0
18 #define LOG_TAG "DrmUtils"
19 
20 #include <android/binder_manager.h>
21 #include <android/hardware/drm/1.0/ICryptoFactory.h>
22 #include <android/hardware/drm/1.0/ICryptoPlugin.h>
23 #include <android/hardware/drm/1.0/IDrmFactory.h>
24 #include <android/hardware/drm/1.0/IDrmPlugin.h>
25 #include <android/hardware/drm/1.1/ICryptoFactory.h>
26 #include <android/hardware/drm/1.1/IDrmFactory.h>
27 #include <android/hardware/drm/1.2/ICryptoFactory.h>
28 #include <android/hardware/drm/1.2/IDrmFactory.h>
29 #include <android/hardware/drm/1.3/ICryptoFactory.h>
30 #include <android/hardware/drm/1.3/IDrmFactory.h>
31 #include <android/hardware/drm/1.4/ICryptoFactory.h>
32 #include <android/hardware/drm/1.4/IDrmFactory.h>
33 #include <android/hidl/manager/1.2/IServiceManager.h>
34 #include <hidl/HidlSupport.h>
35 #include <json/json.h>
36 
37 #include <cutils/properties.h>
38 #include <utils/Errors.h>
39 #include <utils/Log.h>
40 #include <utils/String16.h>
41 
42 #include <mediadrm/CryptoHal.h>
43 #include <mediadrm/DrmHal.h>
44 #include <mediadrm/DrmUtils.h>
45 #include <mediadrm/ICrypto.h>
46 #include <mediadrm/IDrm.h>
47 
48 #include <map>
49 #include <string>
50 
51 using HServiceManager = ::android::hidl::manager::V1_2::IServiceManager;
52 using ::android::hardware::hidl_array;
53 using ::android::hardware::hidl_string;
54 using ::android::hardware::hidl_vec;
55 using namespace ::android::hardware::drm;
56 
57 namespace android {
58 namespace DrmUtils {
59 
60 namespace {
61 
62 template <typename Hal, typename... Ts>
MakeObject(status_t * pstatus,Ts...args)63 Hal* MakeObject(status_t* pstatus, Ts... args) {
64     status_t err = OK;
65     status_t& status = pstatus ? *pstatus : err;
66     auto obj = new Hal(args...);
67     status = obj->initCheck();
68     if (status != OK && status != NO_INIT) {
69         return NULL;
70     }
71     return obj;
72 }
73 
74 template <typename Hal, typename V, typename M>
MakeHidlFactories(const uint8_t uuid[16],V & factories,M & instances)75 void MakeHidlFactories(const uint8_t uuid[16], V& factories, M& instances) {
76     sp<HServiceManager> serviceManager = HServiceManager::getService();
77     if (serviceManager == nullptr) {
78         LOG2BE("Failed to get service manager");
79         return;
80     }
81 
82     serviceManager->listManifestByInterface(
83             Hal::descriptor, [&](const hidl_vec<hidl_string>& registered) {
84                 for (const auto& instance : registered) {
85                     auto factory = Hal::getService(instance);
86                     if (factory != nullptr) {
87                         instances[instance.c_str()] = Hal::descriptor;
88                         if (!uuid) {
89                             factories.push_back(factory);
90                             continue;
91                         }
92                         auto supported = factory->isCryptoSchemeSupported(uuid);
93                         if (!supported.isOk()) {
94                             LOG2BE(uuid, "isCryptoSchemeSupported txn failed: %s",
95                                    supported.description().c_str());
96                             continue;
97                         }
98                         if (supported) {
99                             factories.push_back(factory);
100                         }
101                     }
102                 }
103             });
104 }
105 
106 template <typename Hal, typename V>
MakeHidlFactories(const uint8_t uuid[16],V & factories)107 void MakeHidlFactories(const uint8_t uuid[16], V& factories) {
108     std::map<std::string, std::string> instances;
109     MakeHidlFactories<Hal>(uuid, factories, instances);
110 }
111 
toHidlVec(const void * ptr,size_t size)112 hidl_vec<uint8_t> toHidlVec(const void* ptr, size_t size) {
113     hidl_vec<uint8_t> vec(size);
114     if (ptr != nullptr) {
115         memcpy(vec.data(), ptr, size);
116     }
117     return vec;
118 }
119 
toHidlArray16(const uint8_t * ptr)120 hidl_array<uint8_t, 16> toHidlArray16(const uint8_t* ptr) {
121     if (ptr == nullptr) {
122         return hidl_array<uint8_t, 16>();
123     }
124     return hidl_array<uint8_t, 16>(ptr);
125 }
126 
MakeDrmPlugin(const sp<::V1_0::IDrmFactory> & factory,const uint8_t uuid[16],const char * appPackageName)127 sp<::V1_0::IDrmPlugin> MakeDrmPlugin(const sp<::V1_0::IDrmFactory>& factory, const uint8_t uuid[16],
128                                      const char* appPackageName) {
129     sp<::V1_0::IDrmPlugin> plugin;
130     auto err = factory->createPlugin(
131             toHidlArray16(uuid), hidl_string(appPackageName),
132             [&](::V1_0::Status status, const sp<::V1_0::IDrmPlugin>& hPlugin) {
133                 if (status != ::V1_0::Status::OK) {
134                     LOG2BE(uuid, "MakeDrmPlugin failed: %d", status);
135                     return;
136                 }
137                 plugin = hPlugin;
138             });
139     if (err.isOk()) {
140         return plugin;
141     } else {
142         LOG2BE(uuid, "MakeDrmPlugin txn failed: %s", err.description().c_str());
143         return nullptr;
144     }
145 }
146 
MakeCryptoPlugin(const sp<::V1_0::ICryptoFactory> & factory,const uint8_t uuid[16],const void * initData,size_t initDataSize)147 sp<::V1_0::ICryptoPlugin> MakeCryptoPlugin(const sp<::V1_0::ICryptoFactory>& factory,
148                                            const uint8_t uuid[16], const void* initData,
149                                            size_t initDataSize) {
150     sp<::V1_0::ICryptoPlugin> plugin;
151     auto err = factory->createPlugin(
152             toHidlArray16(uuid), toHidlVec(initData, initDataSize),
153             [&](::V1_0::Status status, const sp<::V1_0::ICryptoPlugin>& hPlugin) {
154                 if (status != ::V1_0::Status::OK) {
155                     LOG2BE(uuid, "MakeCryptoPlugin failed: %d", status);
156                     return;
157                 }
158                 plugin = hPlugin;
159             });
160     if (err.isOk()) {
161         return plugin;
162     } else {
163         LOG2BE(uuid, "MakeCryptoPlugin txn failed: %s", err.description().c_str());
164         return nullptr;
165     }
166 }
167 
168 }  // namespace
169 
UseDrmService()170 bool UseDrmService() {
171     return property_get_bool("mediadrm.use_mediadrmserver", true);
172 }
173 
makeDrmFactoriesAidl()174 std::vector<std::shared_ptr<IDrmFactoryAidl>> makeDrmFactoriesAidl() {
175     std::vector<std::shared_ptr<IDrmFactoryAidl>> factories;
176     AServiceManager_forEachDeclaredInstance(
177         IDrmFactoryAidl::descriptor, static_cast<void*>(&factories),
178         [](const char* instance, void* context) {
179             auto fullName = std::string(IDrmFactoryAidl::descriptor) + "/" + std::string(instance);
180             auto factory = IDrmFactoryAidl::fromBinder(
181                     ::ndk::SpAIBinder(AServiceManager_waitForService(fullName.c_str())));
182             if (factory == nullptr) {
183                 ALOGE("not found IDrmFactory. Instance name:[%s]", fullName.c_str());
184                 return;
185             }
186 
187             ALOGI("found IDrmFactory. Instance name:[%s]", fullName.c_str());
188             static_cast<std::vector<std::shared_ptr<IDrmFactoryAidl>>*>(context)->emplace_back(
189                     factory);
190         });
191 
192     return factories;
193 }
194 
MakeDrm(IDrmFrontend frontend,status_t * pstatus)195 sp<IDrm> MakeDrm(IDrmFrontend frontend, status_t* pstatus) {
196     return MakeObject<DrmMetricsLogger>(pstatus, frontend);
197 }
198 
MakeCrypto(status_t * pstatus)199 sp<ICrypto> MakeCrypto(status_t* pstatus) {
200     return MakeObject<CryptoHal>(pstatus);
201 }
202 
MakeDrmFactories(const uint8_t uuid[16])203 std::vector<sp<::V1_0::IDrmFactory>> MakeDrmFactories(const uint8_t uuid[16]) {
204     std::vector<sp<::V1_0::IDrmFactory>> drmFactories;
205     std::map<std::string, std::string> instances;
206     MakeHidlFactories<::V1_0::IDrmFactory>(uuid, drmFactories, instances);
207     MakeHidlFactories<::V1_1::IDrmFactory>(uuid, drmFactories, instances);
208     MakeHidlFactories<::V1_2::IDrmFactory>(uuid, drmFactories, instances);
209     MakeHidlFactories<::V1_3::IDrmFactory>(uuid, drmFactories, instances);
210     MakeHidlFactories<::V1_4::IDrmFactory>(uuid, drmFactories, instances);
211     for (auto const& entry : instances) {
212         LOG2BI("found instance=%s version=%s", entry.first.c_str(), entry.second.c_str());
213     }
214     return drmFactories;
215 }
216 
MakeDrmPlugins(const uint8_t uuid[16],const char * appPackageName)217 std::vector<sp<::V1_0::IDrmPlugin>> MakeDrmPlugins(const uint8_t uuid[16],
218                                                    const char* appPackageName) {
219     std::vector<sp<::V1_0::IDrmPlugin>> plugins;
220     for (const auto& factory : MakeDrmFactories(uuid)) {
221         plugins.push_back(MakeDrmPlugin(factory, uuid, appPackageName));
222     }
223     return plugins;
224 }
225 
MakeCryptoFactories(const uint8_t uuid[16])226 std::vector<sp<::V1_0::ICryptoFactory>> MakeCryptoFactories(const uint8_t uuid[16]) {
227     std::vector<sp<::V1_0::ICryptoFactory>> cryptoFactories;
228     MakeHidlFactories<::V1_0::ICryptoFactory>(uuid, cryptoFactories);
229     MakeHidlFactories<::V1_1::ICryptoFactory>(uuid, cryptoFactories);
230     MakeHidlFactories<::V1_2::ICryptoFactory>(uuid, cryptoFactories);
231     MakeHidlFactories<::V1_3::ICryptoFactory>(uuid, cryptoFactories);
232     MakeHidlFactories<::V1_4::ICryptoFactory>(uuid, cryptoFactories);
233     return cryptoFactories;
234 }
235 
MakeCryptoPlugins(const uint8_t uuid[16],const void * initData,size_t initDataSize)236 std::vector<sp<::V1_0::ICryptoPlugin>> MakeCryptoPlugins(const uint8_t uuid[16],
237                                                          const void* initData,
238                                                          size_t initDataSize) {
239     std::vector<sp<::V1_0::ICryptoPlugin>> plugins;
240     for (const auto& factory : MakeCryptoFactories(uuid)) {
241         plugins.push_back(MakeCryptoPlugin(factory, uuid, initData, initDataSize));
242     }
243     return plugins;
244 }
245 
toStatusT_1_4(::V1_4::Status status)246 status_t toStatusT_1_4(::V1_4::Status status) {
247     switch (status) {
248         case ::V1_4::Status::OK:
249             return OK;
250         case ::V1_4::Status::BAD_VALUE:
251             return BAD_VALUE;
252         case ::V1_4::Status::ERROR_DRM_CANNOT_HANDLE:
253             return ERROR_DRM_CANNOT_HANDLE;
254         case ::V1_4::Status::ERROR_DRM_DECRYPT:
255             return ERROR_DRM_DECRYPT;
256         case ::V1_4::Status::ERROR_DRM_DEVICE_REVOKED:
257             return ERROR_DRM_DEVICE_REVOKED;
258         case ::V1_4::Status::ERROR_DRM_FRAME_TOO_LARGE:
259             return ERROR_DRM_FRAME_TOO_LARGE;
260         case ::V1_4::Status::ERROR_DRM_INSUFFICIENT_OUTPUT_PROTECTION:
261             return ERROR_DRM_INSUFFICIENT_OUTPUT_PROTECTION;
262         case ::V1_4::Status::ERROR_DRM_INSUFFICIENT_SECURITY:
263             return ERROR_DRM_INSUFFICIENT_SECURITY;
264         case ::V1_4::Status::ERROR_DRM_INVALID_STATE:
265             return ERROR_DRM_INVALID_STATE;
266         case ::V1_4::Status::ERROR_DRM_LICENSE_EXPIRED:
267             return ERROR_DRM_LICENSE_EXPIRED;
268         case ::V1_4::Status::ERROR_DRM_NO_LICENSE:
269             return ERROR_DRM_NO_LICENSE;
270         case ::V1_4::Status::ERROR_DRM_NOT_PROVISIONED:
271             return ERROR_DRM_NOT_PROVISIONED;
272         case ::V1_4::Status::ERROR_DRM_RESOURCE_BUSY:
273             return ERROR_DRM_RESOURCE_BUSY;
274         case ::V1_4::Status::ERROR_DRM_RESOURCE_CONTENTION:
275             return ERROR_DRM_RESOURCE_CONTENTION;
276         case ::V1_4::Status::ERROR_DRM_SESSION_LOST_STATE:
277             return ERROR_DRM_SESSION_LOST_STATE;
278         case ::V1_4::Status::ERROR_DRM_SESSION_NOT_OPENED:
279             return ERROR_DRM_SESSION_NOT_OPENED;
280 
281         // New in S / drm@1.4:
282         case ::V1_4::Status::CANNOT_DECRYPT_ZERO_SUBSAMPLES:
283             return ERROR_DRM_ZERO_SUBSAMPLES;
284         case ::V1_4::Status::CRYPTO_LIBRARY_ERROR:
285             return ERROR_DRM_CRYPTO_LIBRARY;
286         case ::V1_4::Status::GENERAL_OEM_ERROR:
287             return ERROR_DRM_GENERIC_OEM;
288         case ::V1_4::Status::GENERAL_PLUGIN_ERROR:
289             return ERROR_DRM_GENERIC_PLUGIN;
290         case ::V1_4::Status::INIT_DATA_INVALID:
291             return ERROR_DRM_INIT_DATA;
292         case ::V1_4::Status::KEY_NOT_LOADED:
293             return ERROR_DRM_KEY_NOT_LOADED;
294         case ::V1_4::Status::LICENSE_PARSE_ERROR:
295             return ERROR_DRM_LICENSE_PARSE;
296         case ::V1_4::Status::LICENSE_POLICY_ERROR:
297             return ERROR_DRM_LICENSE_POLICY;
298         case ::V1_4::Status::LICENSE_RELEASE_ERROR:
299             return ERROR_DRM_LICENSE_RELEASE;
300         case ::V1_4::Status::LICENSE_REQUEST_REJECTED:
301             return ERROR_DRM_LICENSE_REQUEST_REJECTED;
302         case ::V1_4::Status::LICENSE_RESTORE_ERROR:
303             return ERROR_DRM_LICENSE_RESTORE;
304         case ::V1_4::Status::LICENSE_STATE_ERROR:
305             return ERROR_DRM_LICENSE_STATE;
306         case ::V1_4::Status::MALFORMED_CERTIFICATE:
307             return ERROR_DRM_CERTIFICATE_MALFORMED;
308         case ::V1_4::Status::MEDIA_FRAMEWORK_ERROR:
309             return ERROR_DRM_MEDIA_FRAMEWORK;
310         case ::V1_4::Status::MISSING_CERTIFICATE:
311             return ERROR_DRM_CERTIFICATE_MISSING;
312         case ::V1_4::Status::PROVISIONING_CERTIFICATE_ERROR:
313             return ERROR_DRM_PROVISIONING_CERTIFICATE;
314         case ::V1_4::Status::PROVISIONING_CONFIGURATION_ERROR:
315             return ERROR_DRM_PROVISIONING_CONFIG;
316         case ::V1_4::Status::PROVISIONING_PARSE_ERROR:
317             return ERROR_DRM_PROVISIONING_PARSE;
318         case ::V1_4::Status::PROVISIONING_REQUEST_REJECTED:
319             return ERROR_DRM_PROVISIONING_REQUEST_REJECTED;
320         case ::V1_4::Status::RETRYABLE_PROVISIONING_ERROR:
321             return ERROR_DRM_PROVISIONING_RETRY;
322         case ::V1_4::Status::SECURE_STOP_RELEASE_ERROR:
323             return ERROR_DRM_SECURE_STOP_RELEASE;
324         case ::V1_4::Status::STORAGE_READ_FAILURE:
325             return ERROR_DRM_STORAGE_READ;
326         case ::V1_4::Status::STORAGE_WRITE_FAILURE:
327             return ERROR_DRM_STORAGE_WRITE;
328 
329         case ::V1_4::Status::ERROR_DRM_UNKNOWN:
330         default:
331             return ERROR_DRM_UNKNOWN;
332     }
333     return ERROR_DRM_UNKNOWN;
334 }
335 
336 namespace {
logPriorityToChar(::V1_4::LogPriority priority)337 char logPriorityToChar(::V1_4::LogPriority priority) {
338     char p = 'U';
339     switch (priority) {
340         case ::V1_4::LogPriority::VERBOSE:
341             p = 'V';
342             break;
343         case ::V1_4::LogPriority::DEBUG:
344             p = 'D';
345             break;
346         case ::V1_4::LogPriority::INFO:
347             p = 'I';
348             break;
349         case ::V1_4::LogPriority::WARN:
350             p = 'W';
351             break;
352         case ::V1_4::LogPriority::ERROR:
353             p = 'E';
354             break;
355         case ::V1_4::LogPriority::FATAL:
356             p = 'F';
357             break;
358         default:
359             p = 'U';
360             break;
361     }
362     return p;
363 }
364 }  // namespace
365 
GetExceptionMessage(const DrmStatus & err,const char * defaultMsg,const Vector<::V1_4::LogMessage> & logs)366 std::string GetExceptionMessage(const DrmStatus &err, const char* defaultMsg,
367                                 const Vector<::V1_4::LogMessage>& logs) {
368     std::string ruler("==============================");
369     std::string header("Beginning of DRM Plugin Log");
370     std::string footer("End of DRM Plugin Log");
371     std::string msg(err.getErrorMessage());
372     String8 msg8;
373     if (!msg.empty()) {
374         msg8 += msg.c_str();
375         msg8 += ": ";
376     } else if (defaultMsg) {
377         msg8 += defaultMsg;
378         msg8 += ": ";
379     }
380     msg8 += StrCryptoError(err).c_str();
381     msg8 += String8::format("\ncdm err: %d, oem err: %d, ctx: %d",
382                             err.getCdmErr(), err.getOemErr(), err.getContext());
383     msg8 += String8::format("\n%s %s %s", ruler.c_str(), header.c_str(), ruler.c_str());
384 
385     for (auto log : logs) {
386         time_t seconds = log.timeMs / 1000;
387         int ms = log.timeMs % 1000;
388         char buf[64] = {0};
389         std::string timeStr = "00-00 00:00:00";
390         if (strftime(buf, sizeof buf, "%m-%d %H:%M:%S", std::localtime(&seconds))) {
391             timeStr = buf;
392         }
393 
394         char p = logPriorityToChar(log.priority);
395         msg8 += String8::format("\n  %s.%03d %c %s", timeStr.c_str(), ms, p, log.message.c_str());
396     }
397 
398     msg8 += String8::format("\n%s %s %s", ruler.c_str(), footer.c_str(), ruler.c_str());
399     return msg8.c_str();
400 }
401 
addLog(const::V1_4::LogMessage & log)402 void LogBuffer::addLog(const ::V1_4::LogMessage& log) {
403     std::unique_lock<std::mutex> lock(mMutex);
404     mBuffer.push_back(log);
405     while (mBuffer.size() > MAX_CAPACITY) {
406         mBuffer.pop_front();
407     }
408 }
409 
getLogs()410 Vector<::V1_4::LogMessage> LogBuffer::getLogs() {
411     std::unique_lock<std::mutex> lock(mMutex);
412     Vector<::V1_4::LogMessage> logs;
413     for (auto log : mBuffer) {
414         logs.push_back(log);
415     }
416     return logs;
417 }
418 
statusAidlToDrmStatus(::ndk::ScopedAStatus & statusAidl)419 DrmStatus statusAidlToDrmStatus(::ndk::ScopedAStatus& statusAidl) {
420     if (statusAidl.isOk()) return OK;
421     if (statusAidl.getExceptionCode() != EX_SERVICE_SPECIFIC) return DEAD_OBJECT;
422     auto astatus = static_cast<StatusAidl>(statusAidl.getServiceSpecificError());
423     status_t status{};
424     switch (astatus) {
425     case StatusAidl::OK:
426         status = OK;
427         break;
428     case StatusAidl::BAD_VALUE:
429         status = BAD_VALUE;
430         break;
431     case StatusAidl::ERROR_DRM_CANNOT_HANDLE:
432         status = ERROR_DRM_CANNOT_HANDLE;
433         break;
434     case StatusAidl::ERROR_DRM_DECRYPT:
435         status = ERROR_DRM_DECRYPT;
436         break;
437     case StatusAidl::ERROR_DRM_DEVICE_REVOKED:
438         status = ERROR_DRM_DEVICE_REVOKED;
439         break;
440     case StatusAidl::ERROR_DRM_FRAME_TOO_LARGE:
441         status = ERROR_DRM_FRAME_TOO_LARGE;
442         break;
443     case StatusAidl::ERROR_DRM_INSUFFICIENT_OUTPUT_PROTECTION:
444         status = ERROR_DRM_INSUFFICIENT_OUTPUT_PROTECTION;
445         break;
446     case StatusAidl::ERROR_DRM_INSUFFICIENT_SECURITY:
447         status = ERROR_DRM_INSUFFICIENT_SECURITY;
448         break;
449     case StatusAidl::ERROR_DRM_INVALID_STATE:
450         status = ERROR_DRM_INVALID_STATE;
451         break;
452     case StatusAidl::ERROR_DRM_LICENSE_EXPIRED:
453         status = ERROR_DRM_LICENSE_EXPIRED;
454         break;
455     case StatusAidl::ERROR_DRM_NO_LICENSE:
456         status = ERROR_DRM_NO_LICENSE;
457         break;
458     case StatusAidl::ERROR_DRM_NOT_PROVISIONED:
459         status = ERROR_DRM_NOT_PROVISIONED;
460         break;
461     case StatusAidl::ERROR_DRM_RESOURCE_BUSY:
462         status = ERROR_DRM_RESOURCE_BUSY;
463         break;
464     case StatusAidl::ERROR_DRM_RESOURCE_CONTENTION:
465         status = ERROR_DRM_RESOURCE_CONTENTION;
466         break;
467     case StatusAidl::ERROR_DRM_SESSION_LOST_STATE:
468         status = ERROR_DRM_SESSION_LOST_STATE;
469         break;
470     case StatusAidl::ERROR_DRM_SESSION_NOT_OPENED:
471         status = ERROR_DRM_SESSION_NOT_OPENED;
472         break;
473 
474     // New in S / drm@1.4:
475     case StatusAidl::CANNOT_DECRYPT_ZERO_SUBSAMPLES:
476         status = ERROR_DRM_ZERO_SUBSAMPLES;
477         break;
478     case StatusAidl::CRYPTO_LIBRARY_ERROR:
479         status = ERROR_DRM_CRYPTO_LIBRARY;
480         break;
481     case StatusAidl::GENERAL_OEM_ERROR:
482         status = ERROR_DRM_GENERIC_OEM;
483         break;
484     case StatusAidl::GENERAL_PLUGIN_ERROR:
485         status = ERROR_DRM_GENERIC_PLUGIN;
486         break;
487     case StatusAidl::INIT_DATA_INVALID:
488         status = ERROR_DRM_INIT_DATA;
489         break;
490     case StatusAidl::KEY_NOT_LOADED:
491         status = ERROR_DRM_KEY_NOT_LOADED;
492         break;
493     case StatusAidl::LICENSE_PARSE_ERROR:
494         status = ERROR_DRM_LICENSE_PARSE;
495         break;
496     case StatusAidl::LICENSE_POLICY_ERROR:
497         status = ERROR_DRM_LICENSE_POLICY;
498         break;
499     case StatusAidl::LICENSE_RELEASE_ERROR:
500         status = ERROR_DRM_LICENSE_RELEASE;
501         break;
502     case StatusAidl::LICENSE_REQUEST_REJECTED:
503         status = ERROR_DRM_LICENSE_REQUEST_REJECTED;
504         break;
505     case StatusAidl::LICENSE_RESTORE_ERROR:
506         status = ERROR_DRM_LICENSE_RESTORE;
507         break;
508     case StatusAidl::LICENSE_STATE_ERROR:
509         status = ERROR_DRM_LICENSE_STATE;
510         break;
511     case StatusAidl::MALFORMED_CERTIFICATE:
512         status = ERROR_DRM_CERTIFICATE_MALFORMED;
513         break;
514     case StatusAidl::MEDIA_FRAMEWORK_ERROR:
515         status = ERROR_DRM_MEDIA_FRAMEWORK;
516         break;
517     case StatusAidl::MISSING_CERTIFICATE:
518         status = ERROR_DRM_CERTIFICATE_MISSING;
519         break;
520     case StatusAidl::PROVISIONING_CERTIFICATE_ERROR:
521         status = ERROR_DRM_PROVISIONING_CERTIFICATE;
522         break;
523     case StatusAidl::PROVISIONING_CONFIGURATION_ERROR:
524         status = ERROR_DRM_PROVISIONING_CONFIG;
525         break;
526     case StatusAidl::PROVISIONING_PARSE_ERROR:
527         status = ERROR_DRM_PROVISIONING_PARSE;
528         break;
529     case StatusAidl::PROVISIONING_REQUEST_REJECTED:
530         status = ERROR_DRM_PROVISIONING_REQUEST_REJECTED;
531         break;
532     case StatusAidl::RETRYABLE_PROVISIONING_ERROR:
533         status = ERROR_DRM_PROVISIONING_RETRY;
534         break;
535     case StatusAidl::SECURE_STOP_RELEASE_ERROR:
536         status = ERROR_DRM_SECURE_STOP_RELEASE;
537         break;
538     case StatusAidl::STORAGE_READ_FAILURE:
539         status = ERROR_DRM_STORAGE_READ;
540         break;
541     case StatusAidl::STORAGE_WRITE_FAILURE:
542         status = ERROR_DRM_STORAGE_WRITE;
543         break;
544 
545     case StatusAidl::ERROR_DRM_UNKNOWN:
546     default:
547         status = ERROR_DRM_UNKNOWN;
548         break;
549     }
550 
551     return DrmStatus(status, statusAidl.getMessage());
552 }
553 
554 LogBuffer gLogBuf;
555 }  // namespace DrmUtils
556 }  // namespace android
557