blob: 47f188da187e08a8a9f32b5108bfb62e04484e47 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
|
// Copyright 2018 Google LLC. All Rights Reserved. This file and proprietary
// source code may only be used and distributed under the Widevine Master
// License Agreement.
#include <utils/Log.h>
#include <string>
#include "MemoryFileSystem.h"
#include "Utils.h"
namespace android {
namespace hardware {
namespace drm {
namespace V1_1 {
namespace clearkey {
std::string MemoryFileSystem::GetFileName(const std::string& path) {
size_t index = path.find_last_of("/");
if (index != std::string::npos) {
return path.substr(index+1);
} else {
return path;
}
}
bool MemoryFileSystem::FileExists(const std::string& fileName) const {
auto result = mMemoryFileSystem.find(fileName);
return result != mMemoryFileSystem.end();
}
ssize_t MemoryFileSystem::GetFileSize(const std::string& fileName) const {
auto result = mMemoryFileSystem.find(fileName);
if (result != mMemoryFileSystem.end()) {
return static_cast<ssize_t>(result->second.getFileSize());
} else {
ALOGE("Failed to get size for %s", fileName.c_str());
return -1;
}
}
size_t MemoryFileSystem::Read(const std::string& path, std::string* buffer) {
std::string key = GetFileName(path);
auto result = mMemoryFileSystem.find(key);
if (result != mMemoryFileSystem.end()) {
std::string serializedHashFile = result->second.getContent();
buffer->assign(serializedHashFile);
return buffer->size();
} else {
ALOGE("Failed to read from %s", path.c_str());
return -1;
}
}
size_t MemoryFileSystem::Write(const std::string& path, const MemoryFile& memoryFile) {
std::string key = GetFileName(path);
mMemoryFileSystem.insert(std::pair<std::string, MemoryFile>(key, memoryFile));
return memoryFile.getFileSize();
}
bool MemoryFileSystem::RemoveFile(const std::string& fileName) {
auto result = mMemoryFileSystem.find(fileName);
if (result != mMemoryFileSystem.end()) {
mMemoryFileSystem.erase(result);
return true;
} else {
ALOGE("Cannot find license to remove: %s", fileName.c_str());
return false;
}
}
bool MemoryFileSystem::RemoveAllFiles() {
mMemoryFileSystem.clear();
return mMemoryFileSystem.empty();
}
} // namespace clearkey
} // namespace V1_1
} // namespace drm
} // namespace hardware
} // namespace android
|