forked from kmiit/FakeOmapi
-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathService.cpp
More file actions
63 lines (57 loc) · 2.75 KB
/
Service.cpp
File metadata and controls
63 lines (57 loc) · 2.75 KB
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
#include "Service.h"
#include "Terminal.h"
namespace aidl::android::se::omapi {
SecureElementService::SecureElementService() {
createTerminals();
}
SecureElementService::~SecureElementService() = default;
ndk::ScopedAStatus SecureElementService::getReaders(std::vector<std::string>* readers) {
LOG(INFO) << __func__;
std::lock_guard<std::mutex> lock(mTerminalsMutex);
for (const auto& pair : mTerminals) {
if (pair.first.find(ESE_TERMINAL) == 0) {
readers->push_back(pair.first);
}
}
return ndk::ScopedAStatus::ok();
}
ndk::ScopedAStatus SecureElementService::getReader(const std::string& readerName,
std::shared_ptr<ISecureElementReader>* readerObj) {
LOG(INFO) << __func__ << " for " << readerName;
std::lock_guard<std::mutex> lock(mTerminalsMutex);
auto it = mTerminals.find(readerName);
if (it == mTerminals.end()) {
LOG(ERROR) << __func__ << ": reader not found: " << readerName;
return ndk::ScopedAStatus::fromExceptionCodeWithMessage(
EX_ILLEGAL_ARGUMENT, "Reader not found");
}
::android::sp<Terminal> terminal = it->second;
if (terminal == nullptr) {
LOG(ERROR) << __func__ << ": terminal is null for " << readerName;
return ndk::ScopedAStatus::fromExceptionCodeWithMessage(
EX_ILLEGAL_STATE, "Terminal is null");
}
*readerObj = terminal->newSecureElementReader(this->ref<SecureElementService>());
return ndk::ScopedAStatus::ok();
}
ndk::ScopedAStatus SecureElementService::isNfcEventAllowed(const std::string& /*readerName*/,
const std::vector<uint8_t>& /*aid*/,
const std::vector<std::string>& packageNames,
int32_t /*userId*/,
std::vector<bool>* isAllowed) {
LOG(INFO) << __func__;
// No NFC path in TWRP; deny all.
isAllowed->assign(packageNames.size(), false);
return ndk::ScopedAStatus::ok();
}
void SecureElementService::createTerminals() {
const std::string name = std::string(ESE_TERMINAL) + "1";
::android::sp<Terminal> terminal = new Terminal(name);
mTerminals.insert({name, terminal});
// Match upstream Java SecureElementService.onCreate(): block in the
// service-creation path until the SE HAL is connected. Otherwise the
// first openSession() race after addService() returns
// EX_ILLEGAL_STATE before the HAL has even bound.
terminal->initialize(true);
}
}