Files
android/libwvdrmengine/oemcrypto/mock/src/oemcrypto_logging.cpp
Fred Gylys-Colwell 87ea4f6ad4 Merge OEMCrypto changes from CDM to android repository
This is a merge of the following CLs:

Style clean up in oemcrypto/mock
https://widevine-internal-review.googlesource.com/#/c/10660

Split off default keybox.
https://widevine-internal-review.googlesource.com/#/c/10661/

Split off several properties from CryptoEngine.
https://widevine-internal-review.googlesource.com/#/c/10662/

Split off Keybox installation.
https://widevine-internal-review.googlesource.com/#/c/10680/

Wii-U build compatibility fixes.
https://widevine-internal-review.googlesource.com/#/c/10720/

Fix style issues in oemcrypto_logging_test.
https://widevine-internal-review.googlesource.com/#/c/10824/

Correct OEMCrypto error codes in the mock.
https://widevine-internal-review.googlesource.com/#/c/10821/

Enable logging during OEMCrypto unit tests.
https://widevine-internal-review.googlesource.com/#/c/10833/

Wait to create usage table path until needed.
https://widevine-internal-review.googlesource.com/#/c/10831/

Allow keybox installation to be unimplemented.
https://widevine-internal-review.googlesource.com/#/c/10850/

Minor clean up in the OEMCrypto header.
https://widevine-internal-review.googlesource.com/#/c/10921/

Add usage table device property to the mock oemcrypto
https://widevine-internal-review.googlesource.com/#/c/11092/

Change-Id: I02a818a620bcd4bd2291f1b3c0ac9308ae444319
2015-03-02 16:45:43 -08:00

109 lines
2.8 KiB
C++

// Copyright 2014 Google Inc. All Rights Reserved.
#include "oemcrypto_logging.h"
#include <stdio.h>
namespace wvoec_mock {
int logging_category_setting = 0x00;
void SetLoggingSettings(int level, int categories) {
SetLoggingLevel(level);
TurnOffLoggingForAllCategories();
AddLoggingForCategories(categories);
}
void TurnOffLoggingForAllCategories() {
logging_category_setting = 0;
}
void SetLoggingLevel(int level){;
wvcdm::g_cutoff = static_cast<wvcdm::LogPriority>(level);
}
void SetLoggingLevel(wvcdm::LogPriority level) {
wvcdm::g_cutoff = level;
}
void AddLoggingForCategories(int categories) {
logging_category_setting |= categories;
}
void RemoveLoggingForCategories(int categories) {
logging_category_setting &= ~categories;
}
bool LogCategoryEnabled(int categories) {
return ( (logging_category_setting & categories) !=0 );
}
void dump_hex_helper(std::string& buffer, std::string name,
const uint8_t* vector, size_t length) {
buffer += name + " = ";
if (vector == NULL) {
buffer +="NULL;\n";
LOGE(buffer.c_str());
return;
}
int a, b;
char int_to_hexcar[16] = {'0', '1', '2', '3', '4', '5', '6', '7',
'8', '9', 'A', 'B', 'C', 'D', 'E', 'F'};
for (size_t i = 0; i < length; i++) {
if (i == 0) {
buffer += "\n wvcdm::a2b_hex(\"";
} else if (i % 32 == 0) {
buffer += "\"\n \"";
}
a = vector[i] % 16;
b = (vector[i] - a) / 16;
buffer += int_to_hexcar[b];
buffer += int_to_hexcar[a];
}
buffer += "\");\n";
}
void dump_hex(std::string name, const uint8_t* vector, size_t length) {
std::string buffer="";
dump_hex_helper(buffer, name, vector, length);
LOGV(buffer.c_str());
}
void dump_array_part_helper(std::string& buffer, std::string array,
size_t index, std::string name,
const uint8_t* vector, size_t length) {
char index_str[256];
snprintf(index_str, sizeof index_str, "%zu", index);
if (vector == NULL) {
buffer += array.c_str();
buffer += "[";
buffer += index_str;
buffer += "].";
buffer += name.c_str();
buffer += " = NULL;\n";
LOGW(buffer.c_str());
return;
}
buffer += "std::string s";
buffer += index_str;
buffer+= "_";
dump_hex_helper(buffer, name, vector, length);
buffer += array.c_str();
buffer += "[";
buffer += index_str;
buffer += "]." + name + " = message_ptr + message.find(s";
buffer += index_str;
buffer += "_" + name + ".data());\n";
}
void dump_array_part(std::string array, size_t index,
std::string name, const uint8_t* vector, size_t length) {
std::string buffer ="";
dump_array_part_helper(buffer, array, index, name, vector, length);
LOGV(buffer.c_str());
}
} // namespace wvoec_mock