• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2017 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 "android.hardware.cas@1.0-TypeConvert"
19 
20 #include <utils/Log.h>
21 #include "TypeConvert.h"
22 
23 namespace android {
24 namespace hardware {
25 namespace cas {
26 namespace V1_0 {
27 namespace implementation {
28 
toStatus(status_t legacyStatus)29 Status toStatus(status_t legacyStatus) {
30     Status status;
31     switch(legacyStatus) {
32     case android::OK:
33         status = Status::OK;
34         break;
35     case android::ERROR_CAS_NO_LICENSE:
36         status = Status::ERROR_CAS_NO_LICENSE;
37         break;
38     case android::ERROR_CAS_LICENSE_EXPIRED:
39         status = Status::ERROR_CAS_LICENSE_EXPIRED;
40         break;
41     case android::ERROR_CAS_SESSION_NOT_OPENED:
42         status = Status::ERROR_CAS_SESSION_NOT_OPENED;
43         break;
44     case android::ERROR_CAS_CANNOT_HANDLE:
45         status = Status::ERROR_CAS_CANNOT_HANDLE;
46         break;
47     case android::ERROR_CAS_TAMPER_DETECTED:
48         status = Status::ERROR_CAS_INVALID_STATE;
49         break;
50     case android::BAD_VALUE:
51         status = Status::BAD_VALUE;
52         break;
53     case android::ERROR_CAS_NOT_PROVISIONED:
54         status = Status::ERROR_CAS_NOT_PROVISIONED;
55         break;
56     case android::ERROR_CAS_RESOURCE_BUSY:
57         status = Status::ERROR_CAS_RESOURCE_BUSY;
58         break;
59     case android::ERROR_CAS_INSUFFICIENT_OUTPUT_PROTECTION:
60         status = Status::ERROR_CAS_INSUFFICIENT_OUTPUT_PROTECTION;
61         break;
62     case android::ERROR_CAS_DEVICE_REVOKED:
63         status = Status::ERROR_CAS_DEVICE_REVOKED;
64         break;
65     case android::ERROR_CAS_DECRYPT_UNIT_NOT_INITIALIZED:
66         status = Status::ERROR_CAS_DECRYPT_UNIT_NOT_INITIALIZED;
67         break;
68     case android::ERROR_CAS_DECRYPT:
69         status = Status::ERROR_CAS_DECRYPT;
70         break;
71     default:
72         ALOGW("Unable to convert legacy status: %d, defaulting to UNKNOWN",
73             legacyStatus);
74         status = Status::ERROR_CAS_UNKNOWN;
75         break;
76     }
77     return status;
78 }
79 
sessionIdToString(const CasSessionId & sessionId)80 String8 sessionIdToString(const CasSessionId &sessionId) {
81     String8 result;
82     for (size_t i = 0; i < sessionId.size(); i++) {
83         result.appendFormat("%02x ", sessionId[i]);
84     }
85     if (result.isEmpty()) {
86         result.append("(null)");
87     }
88     return result;
89 }
90 
91 }  // namespace implementation
92 }  // namespace V1_0
93 }  // namespace cas
94 }  // namespace hardware
95 }  // namespace android
96