sm7125: fingerprint: Rebase and kill Samsung's fingerprint interface

Change-Id: Ibd5ed5a300c071810d602ff2ffce6548dd2ea32a
tirimbino
Simon1511 2 years ago committed by Ruchit Marathe
parent 7aeb347e6c
commit 9831211081
  1. 2
      common.mk
  2. 8
      configs/framework_compatibility_matrix.xml
  3. 30
      fingerprint/Android.mk
  4. 295
      fingerprint/BiometricsFingerprint.cpp
  5. 61
      fingerprint/BiometricsFingerprint.h
  6. 101
      fingerprint/VendorConstants.h
  7. 2
      fingerprint/android.hardware.biometrics.fingerprint@2.3-service-samsung.sm7125.rc
  8. 10
      fingerprint/android.hardware.biometrics.fingerprint@2.3-service-samsung.sm7125.xml
  9. 8
      fingerprint/service.cpp
  10. 4
      interfaces/Android.bp
  11. 16
      interfaces/biometrics/fingerprint/3.0/Android.bp
  12. 7
      interfaces/biometrics/fingerprint/3.0/ISehBiometricsFingerprint.hal
  13. 2
      sepolicy/vendor/file_contexts
  14. 3
      sepolicy/vendor/hwservice_contexts

@ -178,7 +178,7 @@ PRODUCT_PACKAGES += \
# Fingerprint # Fingerprint
PRODUCT_PACKAGES += \ PRODUCT_PACKAGES += \
vendor.samsung.hardware.biometrics.fingerprint@3.0-service.sm7125 android.hardware.biometrics.fingerprint@2.3-service-samsung.sm7125
# fastbootd # fastbootd
PRODUCT_PACKAGES += \ PRODUCT_PACKAGES += \

@ -833,14 +833,6 @@
<instance>default</instance> <instance>default</instance>
</interface> </interface>
</hal> </hal>
<hal format="hidl" optional="true">
<name>vendor.samsung.hardware.biometrics.fingerprint</name>
<version>3.0</version>
<interface>
<name>ISehBiometricsFingerprint</name>
<instance>default</instance>
</interface>
</hal>
<hal format="hidl" optional="true"> <hal format="hidl" optional="true">
<name>vendor.samsung.hardware.bluetooth</name> <name>vendor.samsung.hardware.bluetooth</name>
<version>2.0</version> <version>2.0</version>

@ -26,17 +26,35 @@ LOCAL_SHARED_LIBRARIES := \
libbase \ libbase \
libhardware \ libhardware \
libhidlbase \ libhidlbase \
libhidltransport \
liblog \ liblog \
libutils \ libutils \
android.hardware.biometrics.fingerprint@2.1 \ android.hardware.biometrics.fingerprint@2.1 \
android.hardware.biometrics.fingerprint@2.2 \ android.hardware.biometrics.fingerprint@2.2 \
android.hardware.biometrics.fingerprint@2.3 \ android.hardware.biometrics.fingerprint@2.3
vendor.samsung.hardware.biometrics.fingerprint@3.0
LOCAL_MODULE := vendor.samsung.hardware.biometrics.fingerprint@3.0-service.sm7125 ifeq ($(TARGET_SEC_FP_CALL_NOTIFY_ON_CANCEL),true)
LOCAL_INIT_RC := vendor.samsung.hardware.biometrics.fingerprint@3.0-service.sm7125.rc LOCAL_CFLAGS += -DCALL_NOTIFY_ON_CANCEL
LOCAL_VINTF_FRAGMENTS := vendor.samsung.hardware.biometrics.fingerprint@3.0-service.sm7125.xml endif
ifeq ($(TARGET_SEC_FP_USES_PERCENTAGE_SAMPLES),true)
LOCAL_CFLAGS += -DUSES_PERCENTAGE_SAMPLES
endif
ifeq ($(TARGET_SEC_FP_CALL_CANCEL_ON_ENROLL_COMPLETION),true)
LOCAL_CFLAGS += -DCALL_CANCEL_ON_ENROLL_COMPLETION
endif
ifeq ($(TARGET_SEC_FP_HAS_FINGERPRINT_GESTURES),true)
LOCAL_CFLAGS += -DHAS_FINGERPRINT_GESTURES
endif
ifeq ($(TARGET_SEC_FP_REQUEST_FORCE_CALIBRATE),true)
LOCAL_CFLAGS += -DREQUEST_FORCE_CALIBRATE
endif
LOCAL_MODULE := android.hardware.biometrics.fingerprint@2.3-service-samsung.sm7125
LOCAL_INIT_RC := android.hardware.biometrics.fingerprint@2.3-service-samsung.sm7125.rc
LOCAL_VINTF_FRAGMENTS := android.hardware.biometrics.fingerprint@2.3-service-samsung.sm7125.xml
LOCAL_MODULE_RELATIVE_PATH := hw LOCAL_MODULE_RELATIVE_PATH := hw
LOCAL_MODULE_TAGS := optional LOCAL_MODULE_TAGS := optional
LOCAL_MODULE_OWNER := samsung LOCAL_MODULE_OWNER := samsung

@ -13,7 +13,7 @@
* See the License for the specific language governing permissions and * See the License for the specific language governing permissions and
* limitations under the License. * limitations under the License.
*/ */
#define LOG_TAG "vendor.samsung.hardware.biometrics.fingerprint@3.0-service.sm7125" #define LOG_TAG "android.hardware.biometrics.fingerprint@2.3-service-samsung.sm7125"
#include <android-base/logging.h> #include <android-base/logging.h>
@ -23,30 +23,28 @@
#include <hardware/hardware.h> #include <hardware/hardware.h>
#include "BiometricsFingerprint.h" #include "BiometricsFingerprint.h"
#include <android-base/properties.h> #include <android-base/properties.h>
#include <fstream>
#include <dlfcn.h> #include <dlfcn.h>
#include <fstream>
#include <inttypes.h> #include <inttypes.h>
#include <unistd.h> #include <unistd.h>
#include <thread>
#define SEH_FINGER_STATE 22 #ifdef HAS_FINGERPRINT_GESTURES
#define SEH_PARAM_PRESSED 2 #include <fcntl.h>
#define SEH_PARAM_RELEASED 1 #endif
#define SEH_AOSP_FQNAME "android.hardware.biometrics.fingerprint@2.3::IBiometricsFingerprint"
#define TSP_CMD_PATH "/sys/class/sec/tsp/cmd" #define TSP_CMD_PATH "/sys/class/sec/tsp/cmd"
#define HBM_PATH "/sys/class/lcd/panel/mask_brightness" #define HBM_PATH "/sys/class/lcd/panel/mask_brightness"
namespace vendor { namespace android {
namespace samsung {
namespace hardware { namespace hardware {
namespace biometrics { namespace biometrics {
namespace fingerprint { namespace fingerprint {
namespace V3_0 { namespace V2_3 {
namespace implementation { namespace implementation {
using RequestStatus = android::hardware::biometrics::fingerprint::V2_1::RequestStatus; using RequestStatus = android::hardware::biometrics::fingerprint::V2_1::RequestStatus;
ISehBiometricsFingerprint* SehBiometricsFingerprint::sInstance = nullptr; BiometricsFingerprint* BiometricsFingerprint::sInstance = nullptr;
template <typename T> template <typename T>
static void set(const std::string& path, const T& value) { static void set(const std::string& path, const T& value) {
@ -58,16 +56,7 @@ std::string getBootloader() {
return android::base::GetProperty("ro.boot.bootloader", ""); return android::base::GetProperty("ro.boot.bootloader", "");
} }
template <typename T> BiometricsFingerprint::BiometricsFingerprint() : mClientCallback(nullptr) {
static T get(const std::string& path, const T& def) {
std::ifstream file(path);
T result;
file >> result;
return file.fail() ? def : result;
}
SehBiometricsFingerprint::SehBiometricsFingerprint() : mClientCallback(nullptr) {
sInstance = this; // keep track of the most recent instance sInstance = this; // keep track of the most recent instance
if (!openHal()) { if (!openHal()) {
LOG(ERROR) << "Can't open HAL module"; LOG(ERROR) << "Can't open HAL module";
@ -86,55 +75,75 @@ SehBiometricsFingerprint::SehBiometricsFingerprint() : mClientCallback(nullptr)
if (in) if (in)
in.close(); in.close();
#ifdef HAS_FINGERPRINT_GESTURES
request(FINGERPRINT_REQUEST_NAVIGATION_MODE_START, 1);
uinputFd = open("/dev/uinput", O_WRONLY | O_NONBLOCK);
if (uinputFd < 0) {
LOG(ERROR) << "Unable to open uinput node";
return;
}
int err = ioctl(uinputFd, UI_SET_EVBIT, EV_KEY) |
ioctl(uinputFd, UI_SET_KEYBIT, KEY_UP) |
ioctl(uinputFd, UI_SET_KEYBIT, KEY_DOWN);
if (err != 0) {
LOG(ERROR) << "Unable to enable key events";
return;
}
struct uinput_user_dev uidev;
sprintf(uidev.name, "uinput-sec-fp");
uidev.id.bustype = BUS_VIRTUAL;
err = write(uinputFd, &uidev, sizeof(uidev));
if (err < 0) {
LOG(ERROR) << "Write user device to uinput node failed";
return;
}
err = ioctl(uinputFd, UI_DEV_CREATE);
if (err < 0) {
LOG(ERROR) << "Unable to create uinput device";
return;
}
LOG(INFO) << "Successfully registered uinput-sec-fp for fingerprint gestures";
#endif
set(TSP_CMD_PATH, "fod_enable,1,1,0"); set(TSP_CMD_PATH, "fod_enable,1,1,0");
} }
SehBiometricsFingerprint::~SehBiometricsFingerprint() { BiometricsFingerprint::~BiometricsFingerprint() {
if (ss_fingerprint_close() != 0) { if (ss_fingerprint_close() != 0) {
LOG(ERROR) << "Can't close HAL module"; LOG(ERROR) << "Can't close HAL module";
} }
} }
Return<bool> SehBiometricsFingerprint::isUdfps(uint32_t) { Return<bool> BiometricsFingerprint::isUdfps(uint32_t) {
return mIsUdfps; return mIsUdfps;
} }
void SehBiometricsFingerprint::requestResult(int, const hidl_vec<int8_t>&) { Return<void> BiometricsFingerprint::onFingerDown(uint32_t, uint32_t, float, float) {
// Ignore all results
}
static hidl_vec<int8_t> stringToVec(const std::string& str) {
auto vec = hidl_vec<int8_t>();
vec.resize(str.size() + 1);
for (size_t i = 0; i < str.size(); ++i) {
vec[i] = (int8_t) str[i];
}
vec[str.size()] = '\0';
return vec;
}
Return<void> SehBiometricsFingerprint::onFingerDown(uint32_t, uint32_t, float, float) {
std::thread([this]() { std::thread([this]() {
std::this_thread::sleep_for(std::chrono::milliseconds(35)); std::this_thread::sleep_for(std::chrono::milliseconds(35));
set(HBM_PATH, "331"); set(HBM_PATH, "331");
}).detach(); }).detach();
sehRequest(SEH_FINGER_STATE, SEH_PARAM_PRESSED, request(SEM_REQUEST_TOUCH_EVENT, FINGERPRINT_REQUEST_SESSION_OPEN);
stringToVec(SEH_AOSP_FQNAME), SehBiometricsFingerprint::requestResult);
return Void(); return Void();
} }
Return<void> SehBiometricsFingerprint::onFingerUp() { Return<void> BiometricsFingerprint::onFingerUp() {
sehRequest(SEH_FINGER_STATE, SEH_PARAM_RELEASED, request(SEM_REQUEST_TOUCH_EVENT, FINGERPRINT_REQUEST_RESUME);
stringToVec(SEH_AOSP_FQNAME), SehBiometricsFingerprint::requestResult);
set(HBM_PATH, "0"); set(HBM_PATH, "0");
return Void(); return Void();
} }
Return<RequestStatus> SehBiometricsFingerprint::ErrorFilter(int32_t error) { Return<RequestStatus> BiometricsFingerprint::ErrorFilter(int32_t error) {
switch (error) { switch (error) {
case 0: case 0:
return RequestStatus::SYS_OK; return RequestStatus::SYS_OK;
@ -168,7 +177,7 @@ Return<RequestStatus> SehBiometricsFingerprint::ErrorFilter(int32_t error) {
// Translate from errors returned by traditional HAL (see fingerprint.h) to // Translate from errors returned by traditional HAL (see fingerprint.h) to
// HIDL-compliant FingerprintError. // HIDL-compliant FingerprintError.
FingerprintError SehBiometricsFingerprint::VendorErrorFilter(int32_t error, int32_t* vendorCode) { FingerprintError BiometricsFingerprint::VendorErrorFilter(int32_t error, int32_t* vendorCode) {
*vendorCode = 0; *vendorCode = 0;
switch (error) { switch (error) {
case FINGERPRINT_ERROR_HW_UNAVAILABLE: case FINGERPRINT_ERROR_HW_UNAVAILABLE:
@ -198,7 +207,7 @@ FingerprintError SehBiometricsFingerprint::VendorErrorFilter(int32_t error, int3
// Translate acquired messages returned by traditional HAL (see fingerprint.h) // Translate acquired messages returned by traditional HAL (see fingerprint.h)
// to HIDL-compliant FingerprintAcquiredInfo. // to HIDL-compliant FingerprintAcquiredInfo.
FingerprintAcquiredInfo SehBiometricsFingerprint::VendorAcquiredFilter(int32_t info, FingerprintAcquiredInfo BiometricsFingerprint::VendorAcquiredFilter(int32_t info,
int32_t* vendorCode) { int32_t* vendorCode) {
*vendorCode = 0; *vendorCode = 0;
switch (info) { switch (info) {
@ -225,7 +234,7 @@ FingerprintAcquiredInfo SehBiometricsFingerprint::VendorAcquiredFilter(int32_t i
return FingerprintAcquiredInfo::ACQUIRED_INSUFFICIENT; return FingerprintAcquiredInfo::ACQUIRED_INSUFFICIENT;
} }
Return<uint64_t> SehBiometricsFingerprint::setNotify( Return<uint64_t> BiometricsFingerprint::setNotify(
const sp<IBiometricsFingerprintClientCallback>& clientCallback) { const sp<IBiometricsFingerprintClientCallback>& clientCallback) {
std::lock_guard<std::mutex> lock(mClientCallbackMutex); std::lock_guard<std::mutex> lock(mClientCallbackMutex);
mClientCallback = clientCallback; mClientCallback = clientCallback;
@ -236,30 +245,45 @@ Return<uint64_t> SehBiometricsFingerprint::setNotify(
return reinterpret_cast<uint64_t>(this); return reinterpret_cast<uint64_t>(this);
} }
Return<uint64_t> SehBiometricsFingerprint::preEnroll() { Return<uint64_t> BiometricsFingerprint::preEnroll() {
return ss_fingerprint_pre_enroll(); return ss_fingerprint_pre_enroll();
} }
Return<RequestStatus> SehBiometricsFingerprint::enroll(const hidl_array<uint8_t, 69>& hat, Return<RequestStatus> BiometricsFingerprint::enroll(const hidl_array<uint8_t, 69>& hat,
uint32_t gid, uint32_t timeoutSec) { uint32_t gid, uint32_t timeoutSec) {
const hw_auth_token_t* authToken = reinterpret_cast<const hw_auth_token_t*>(hat.data()); const hw_auth_token_t* authToken = reinterpret_cast<const hw_auth_token_t*>(hat.data());
#ifdef REQUEST_FORCE_CALIBRATE
request(SEM_REQUEST_FORCE_CBGE, 1);
#endif
return ErrorFilter(ss_fingerprint_enroll(authToken, gid, timeoutSec)); return ErrorFilter(ss_fingerprint_enroll(authToken, gid, timeoutSec));
} }
Return<RequestStatus> SehBiometricsFingerprint::postEnroll() { Return<RequestStatus> BiometricsFingerprint::postEnroll() {
return ErrorFilter(ss_fingerprint_post_enroll()); return ErrorFilter(ss_fingerprint_post_enroll());
} }
Return<uint64_t> SehBiometricsFingerprint::getAuthenticatorId() { Return<uint64_t> BiometricsFingerprint::getAuthenticatorId() {
return ss_fingerprint_get_auth_id(); return ss_fingerprint_get_auth_id();
} }
Return<RequestStatus> SehBiometricsFingerprint::cancel() { Return<RequestStatus> BiometricsFingerprint::cancel() {
return ErrorFilter(ss_fingerprint_cancel()); int32_t ret = ss_fingerprint_cancel();
#ifdef CALL_NOTIFY_ON_CANCEL
if (ret == 0) {
fingerprint_msg_t msg{};
msg.type = FINGERPRINT_ERROR;
msg.data.error = FINGERPRINT_ERROR_CANCELED;
notify(&msg);
}
#endif
return ErrorFilter(ret);
} }
Return<RequestStatus> SehBiometricsFingerprint::enumerate() { Return<RequestStatus> BiometricsFingerprint::enumerate() {
if (ss_fingerprint_enumerate != nullptr) { if (ss_fingerprint_enumerate != nullptr) {
return ErrorFilter(ss_fingerprint_enumerate()); return ErrorFilter(ss_fingerprint_enumerate());
} }
@ -267,62 +291,36 @@ Return<RequestStatus> SehBiometricsFingerprint::enumerate() {
return RequestStatus::SYS_UNKNOWN; return RequestStatus::SYS_UNKNOWN;
} }
Return<RequestStatus> SehBiometricsFingerprint::remove(uint32_t gid, uint32_t fid) { Return<RequestStatus> BiometricsFingerprint::remove(uint32_t gid, uint32_t fid) {
return ErrorFilter(ss_fingerprint_remove(gid, fid)); return ErrorFilter(ss_fingerprint_remove(gid, fid));
} }
Return<RequestStatus> SehBiometricsFingerprint::setActiveGroup(uint32_t gid, Return<RequestStatus> BiometricsFingerprint::setActiveGroup(uint32_t gid,
const hidl_string&) { const hidl_string& storePath) {
std::string storePath = "/data/vendor/biometrics/fp/User_" + std::to_string(gid); if (storePath.size() >= PATH_MAX || storePath.size() <= 0) {
LOG(ERROR) << "setActiveGroup " << gid << " " << storePath; LOG(ERROR) << "Bad path length: " << storePath.size();
return ErrorFilter(ss_fingerprint_set_active_group(gid, storePath.c_str())); return RequestStatus::SYS_EINVAL;
}
Return<RequestStatus> SehBiometricsFingerprint::authenticate(uint64_t operationId, uint32_t gid) {
return ErrorFilter(ss_fingerprint_authenticate(operationId, gid));
}
Return<void> SehBiometricsFingerprint::sehRequest(int32_t cmd_id,
int32_t inParam, const hidl_vec<int8_t>& inputBuf, sehRequest_cb _hidl_cb) {
size_t inputSize = 0;
for (; inputBuf[inputSize] != '\0'; ++inputSize);
int8_t input[inputSize + 1];
// HACK: SehBiometrics 3.0 doesn't have the len parameter like the older 2.1 HAL has. Set it to 10 for now
int8_t output[10];
for (size_t i = 0; i < inputSize; ++i) {
input[i] = inputBuf[i];
}
input[inputSize] = '\0';
for (size_t i = 0; i < static_cast<size_t>(10); ++i) {
output[i] = '\0';
} }
LOG(ERROR) << "request(cmd_id=" << cmd_id if (access(storePath.c_str(), W_OK)) {
<< ", len=" << 10 return RequestStatus::SYS_EINVAL;
<< ", inParam=" << inParam }
<< ", inputBuf=" << input
<< ")";
int ret = ss_fingerprint_request(cmd_id, input, 0, 10 == 0 ? nullptr : output, 10, inParam);
auto outBuf = hidl_vec<int8_t>(); return ErrorFilter(ss_fingerprint_set_active_group(gid, storePath.c_str()));
outBuf.setToExternal(output, 10); }
_hidl_cb(ret, outBuf); Return<RequestStatus> BiometricsFingerprint::authenticate(uint64_t operationId, uint32_t gid) {
return Void(); return ErrorFilter(ss_fingerprint_authenticate(operationId, gid));
} }
ISehBiometricsFingerprint* SehBiometricsFingerprint::getInstance() { IBiometricsFingerprint* BiometricsFingerprint::getInstance() {
if (!sInstance) { if (!sInstance) {
sInstance = new SehBiometricsFingerprint(); sInstance = new BiometricsFingerprint();
} }
return sInstance; return sInstance;
} }
bool SehBiometricsFingerprint::openHal() { bool BiometricsFingerprint::openHal() {
void* handle = dlopen("libbauthserver.so", RTLD_NOW); void* handle = dlopen("libbauthserver.so", RTLD_NOW);
if (handle) { if (handle) {
int err; int err;
@ -360,7 +358,7 @@ bool SehBiometricsFingerprint::openHal() {
return false; return false;
} }
if ((err = ss_set_notify_callback(SehBiometricsFingerprint::notify)) != 0) { if ((err = ss_set_notify_callback(BiometricsFingerprint::notify)) != 0) {
LOG(ERROR) << "Can't register fingerprint module callback, error: " << err; LOG(ERROR) << "Can't register fingerprint module callback, error: " << err;
return false; return false;
} }
@ -371,9 +369,9 @@ bool SehBiometricsFingerprint::openHal() {
return false; return false;
} }
void SehBiometricsFingerprint::notify(const fingerprint_msg_t* msg) { void BiometricsFingerprint::notify(const fingerprint_msg_t* msg) {
SehBiometricsFingerprint* thisPtr = BiometricsFingerprint* thisPtr =
static_cast<SehBiometricsFingerprint*>(SehBiometricsFingerprint::getInstance()); static_cast<BiometricsFingerprint*>(BiometricsFingerprint::getInstance());
std::lock_guard<std::mutex> lock(thisPtr->mClientCallbackMutex); std::lock_guard<std::mutex> lock(thisPtr->mClientCallbackMutex);
if (thisPtr == nullptr || thisPtr->mClientCallback == nullptr) { if (thisPtr == nullptr || thisPtr->mClientCallback == nullptr) {
LOG(ERROR) << "Receiving callbacks before the client callback is registered."; LOG(ERROR) << "Receiving callbacks before the client callback is registered.";
@ -391,6 +389,10 @@ void SehBiometricsFingerprint::notify(const fingerprint_msg_t* msg) {
getInstance()->onFingerUp(); getInstance()->onFingerUp();
} break; } break;
case FINGERPRINT_ACQUIRED: { case FINGERPRINT_ACQUIRED: {
if (msg->data.acquired.acquired_info > SEM_FINGERPRINT_EVENT_BASE) {
thisPtr->handleEvent(msg->data.acquired.acquired_info);
return;
}
int32_t vendorCode = 0; int32_t vendorCode = 0;
FingerprintAcquiredInfo result = FingerprintAcquiredInfo result =
VendorAcquiredFilter(msg->data.acquired.acquired_info, &vendorCode); VendorAcquiredFilter(msg->data.acquired.acquired_info, &vendorCode);
@ -400,20 +402,23 @@ void SehBiometricsFingerprint::notify(const fingerprint_msg_t* msg) {
} }
} break; } break;
case FINGERPRINT_TEMPLATE_ENROLLING: case FINGERPRINT_TEMPLATE_ENROLLING:
#ifdef USES_PERCENTAGE_SAMPLES
const_cast<fingerprint_msg_t*>(msg)->data.enroll.samples_remaining =
100 - msg->data.enroll.samples_remaining;
#endif
if(msg->data.enroll.samples_remaining == 0) { if(msg->data.enroll.samples_remaining == 0) {
set(HBM_PATH, "0"); set(HBM_PATH, "0");
#ifdef CALL_CANCEL_ON_ENROLL_COMPLETION
thisPtr->ss_fingerprint_cancel();
#endif
} }
LOG(DEBUG) << "onEnrollResult(fid=" << msg->data.enroll.finger.fid LOG(DEBUG) << "onEnrollResult(fid=" << msg->data.enroll.finger.fid
<< ", gid=" << msg->data.enroll.finger.gid << ", gid=" << msg->data.enroll.finger.gid
<< ", rem=" << msg->data.enroll.samples_remaining << ")"; << ", rem=" << msg->data.enroll.samples_remaining << ")";
if (thisPtr->mClientCallback if (!thisPtr->mClientCallback
->onEnrollResult(devId, msg->data.enroll.finger.fid, ->onEnrollResult(devId, msg->data.enroll.finger.fid,
msg->data.enroll.finger.gid, msg->data.enroll.samples_remaining) msg->data.enroll.finger.gid, msg->data.enroll.samples_remaining)
.isOk()) { .isOk()) {
fingerprint_msg_t* newMsg = (fingerprint_msg_t*)msg;
newMsg->data.enroll.samples_remaining = 100 - msg->data.enroll.samples_remaining;
msg = newMsg;
} else {
LOG(ERROR) << "failed to invoke fingerprint onEnrollResult callback"; LOG(ERROR) << "failed to invoke fingerprint onEnrollResult callback";
} }
break; break;
@ -467,10 +472,84 @@ void SehBiometricsFingerprint::notify(const fingerprint_msg_t* msg) {
} }
} }
void BiometricsFingerprint::handleEvent(int eventCode) {
switch (eventCode) {
#ifdef HAS_FINGERPRINT_GESTURES
case SEM_FINGERPRINT_EVENT_GESTURE_SWIPE_DOWN:
case SEM_FINGERPRINT_EVENT_GESTURE_SWIPE_UP:
struct input_event event {};
int keycode = eventCode == SEM_FINGERPRINT_EVENT_GESTURE_SWIPE_UP ?
KEY_UP : KEY_DOWN;
// Report the key
event.type = EV_KEY;
event.code = keycode;
event.value = 1;
if (write(uinputFd, &event, sizeof(event)) < 0) {
LOG(ERROR) << "Write EV_KEY to uinput node failed";
return;
}
// Force a flush with an EV_SYN
event.type = EV_SYN;
event.code = SYN_REPORT;
event.value = 0;
if (write(uinputFd, &event, sizeof(event)) < 0) {
LOG(ERROR) << "Write EV_SYN to uinput node failed";
return;
}
// Report the key
event.type = EV_KEY;
event.code = keycode;
event.value = 0;
if (write(uinputFd, &event, sizeof(event)) < 0) {
LOG(ERROR) << "Write EV_KEY to uinput node failed";
return;
}
// Force a flush with an EV_SYN
event.type = EV_SYN;
event.code = SYN_REPORT;
event.value = 0;
if (write(uinputFd, &event, sizeof(event)) < 0) {
LOG(ERROR) << "Write EV_SYN to uinput node failed";
return;
}
break;
#endif
}
}
int BiometricsFingerprint::request(int cmd, int param) {
// TO-DO: input, output handling not implemented
int result = ss_fingerprint_request(cmd, nullptr, 0, nullptr, 0, param);
LOG(INFO) << "request(cmd=" << cmd << ", param=" << param << ", result=" << result << ")";
return result;
}
int BiometricsFingerprint::waitForSensor(std::chrono::milliseconds pollWait,
std::chrono::milliseconds timeOut) {
int sensorStatus = SEM_SENSOR_STATUS_WORKING;
std::chrono::milliseconds timeWaited = 0ms;
while (sensorStatus != SEM_SENSOR_STATUS_OK) {
if (sensorStatus == SEM_SENSOR_STATUS_CALIBRATION_ERROR
|| sensorStatus == SEM_SENSOR_STATUS_ERROR){
return -1;
}
if (timeWaited >= timeOut) {
return -2;
}
sensorStatus = request(FINGERPRINT_REQUEST_GET_SENSOR_STATUS, 0);
std::this_thread::sleep_for(pollWait);
timeWaited += pollWait;
}
return 0;
}
} // namespace implementation } // namespace implementation
} // namespace V3_0 } // namespace V2_3
} // namespace fingerprint } // namespace fingerprint
} // namespace biometrics } // namespace biometrics
} // namespace hardware } // namespace hardware
} // namespace samsung } // namespace android
} // namespace vendor

@ -1,5 +1,5 @@
/* /*
* Copyright (C) 2019 The LineageOS Project * Copyright (C) 2019-2022 The LineageOS Project
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -14,41 +14,50 @@
* limitations under the License. * limitations under the License.
*/ */
#ifndef ANDROID_HARDWARE_BIOMETRICS_FINGERPRINT_V2_3_BIOMETRICSFINGERPRINT_H #pragma once
#define ANDROID_HARDWARE_BIOMETRICS_FINGERPRINT_V2_3_BIOMETRICSFINGERPRINT_H
#include <chrono>
#include <thread>
#ifdef HAS_FINGERPRINT_GESTURES
#include <linux/uinput.h>
#endif
#include <vendor/samsung/hardware/biometrics/fingerprint/3.0/ISehBiometricsFingerprint.h>
#include <hardware/fingerprint.h> #include <hardware/fingerprint.h>
#include <hardware/hardware.h> #include <hardware/hardware.h>
#include <hidl/MQDescriptor.h> #include <hidl/MQDescriptor.h>
#include <hidl/Status.h> #include <hidl/Status.h>
#include <android/hardware/biometrics/fingerprint/2.3/IBiometricsFingerprint.h>
#include <android/hardware/biometrics/fingerprint/2.1/types.h>
#include "VendorConstants.h"
namespace vendor { namespace android {
namespace samsung {
namespace hardware { namespace hardware {
namespace biometrics { namespace biometrics {
namespace fingerprint { namespace fingerprint {
namespace V3_0 { namespace V2_3 {
namespace implementation { namespace implementation {
using namespace std::chrono_literals;
using ::android::sp; using ::android::sp;
using ::android::hardware::hidl_string; using ::android::hardware::hidl_string;
using ::android::hardware::hidl_vec; using ::android::hardware::hidl_vec;
using ::android::hardware::Return; using ::android::hardware::Return;
using ::android::hardware::Void; using ::android::hardware::Void;
using ::android::hardware::hidl_array; using ::android::hardware::biometrics::fingerprint::V2_3::IBiometricsFingerprint;
using ::android::hardware::biometrics::fingerprint::V2_1::IBiometricsFingerprintClientCallback; using ::android::hardware::biometrics::fingerprint::V2_1::IBiometricsFingerprintClientCallback;
using ::android::hardware::biometrics::fingerprint::V2_1::RequestStatus;
using ::android::hardware::biometrics::fingerprint::V2_1::FingerprintError;
using ::android::hardware::biometrics::fingerprint::V2_1::FingerprintAcquiredInfo; using ::android::hardware::biometrics::fingerprint::V2_1::FingerprintAcquiredInfo;
using ::android::hardware::biometrics::fingerprint::V2_1::FingerprintError;
using ::android::hardware::biometrics::fingerprint::V2_1::RequestStatus;
struct SehBiometricsFingerprint : public ISehBiometricsFingerprint { struct BiometricsFingerprint : public IBiometricsFingerprint {
public: BiometricsFingerprint();
SehBiometricsFingerprint(); ~BiometricsFingerprint();
~SehBiometricsFingerprint();
// Method to wrap legacy HAL with BiometricsFingerprint class // Method to wrap legacy HAL with BiometricsFingerprint class
static ISehBiometricsFingerprint* getInstance(); static IBiometricsFingerprint* getInstance();
// Methods from ::android::hardware::biometrics::fingerprint::V2_3::IBiometricsFingerprint follow. // Methods from ::android::hardware::biometrics::fingerprint::V2_3::IBiometricsFingerprint follow.
Return<uint64_t> setNotify( Return<uint64_t> setNotify(
@ -67,21 +76,24 @@ public:
Return<void> onFingerDown(uint32_t x, uint32_t y, float minor, float major) override; Return<void> onFingerDown(uint32_t x, uint32_t y, float minor, float major) override;
Return<void> onFingerUp() override; Return<void> onFingerUp() override;
// Methods from ::vendor::samsung::hardware::biometrics::fingerprint::V3_0::ISehBiometricsFingerprint follow.
Return<void> sehRequest(int32_t cmd_id, int32_t inParam, const hidl_vec<int8_t>& inputBuf, sehRequest_cb _hidl_cb) override;
private: private:
bool openHal(); bool openHal();
int request(int cmd, int param);
int waitForSensor(std::chrono::milliseconds pollWait, std::chrono::milliseconds timeOut);
static void notify( static void notify(
const fingerprint_msg_t* msg); /* Static callback for legacy HAL implementation */ const fingerprint_msg_t* msg); /* Static callback for legacy HAL implementation */
void handleEvent(int eventCode);
static Return<RequestStatus> ErrorFilter(int32_t error); static Return<RequestStatus> ErrorFilter(int32_t error);
static FingerprintError VendorErrorFilter(int32_t error, int32_t* vendorCode); static FingerprintError VendorErrorFilter(int32_t error, int32_t* vendorCode);
static FingerprintAcquiredInfo VendorAcquiredFilter(int32_t error, int32_t* vendorCode); static FingerprintAcquiredInfo VendorAcquiredFilter(int32_t error, int32_t* vendorCode);
static ISehBiometricsFingerprint* sInstance; static BiometricsFingerprint* sInstance;
std::mutex mClientCallbackMutex; std::mutex mClientCallbackMutex;
sp<IBiometricsFingerprintClientCallback> mClientCallback; sp<IBiometricsFingerprintClientCallback> mClientCallback;
bool mIsUdfps; bool mIsUdfps;
#ifdef HAS_FINGERPRINT_GESTURES
int uinputFd;
#endif
int (*ss_fingerprint_close)(); int (*ss_fingerprint_close)();
int (*ss_fingerprint_open)(const char* id); int (*ss_fingerprint_open)(const char* id);
@ -96,17 +108,12 @@ public:
int (*ss_fingerprint_remove)(uint32_t gid, uint32_t fid); int (*ss_fingerprint_remove)(uint32_t gid, uint32_t fid);
int (*ss_fingerprint_set_active_group)(uint32_t gid, const char* store_path); int (*ss_fingerprint_set_active_group)(uint32_t gid, const char* store_path);
int (*ss_fingerprint_authenticate)(uint64_t operation_id, uint32_t gid); int (*ss_fingerprint_authenticate)(uint64_t operation_id, uint32_t gid);
int (*ss_fingerprint_request)(int32_t cmd_id, const int8_t* inputBuf, uint32_t value, int8_t* outBuf, uint32_t len, uint32_t inParam); int (*ss_fingerprint_request)(uint32_t cmd, char *inBuf, uint32_t inBuf_length, char *outBuf, uint32_t outBuf_length, uint32_t param);
static void requestResult(int retval, const hidl_vec<int8_t>& outBuf);
}; };
} // namespace implementation } // namespace implementation
} // namespace V3_0 } // namespace V2_3
} // namespace fingerprint } // namespace fingerprint
} // namespace biometrics } // namespace biometrics
} // namespace hardware } // namespace hardware
} // namespace samsung } // namespace android
} // namespace vendor
#endif // ANDROID_HARDWARE_BIOMETRICS_FINGERPRINT_V2_3_BIOMETRICSFINGERPRINT_H

@ -0,0 +1,101 @@
// SPDX-License-Identifier: Apache-2.0
// Copyright (C) 2020 The LineageOS Project
#pragma once
// Fingerprint requests
#define FINGERPRINT_REQUEST_ENROLL_SESSION 1002
#define FINGERPRINT_REQUEST_ENROLL_TYPE 18
#define FINGERPRINT_REQUEST_ENUMERATE 11
#define FINGERPRINT_REQUEST_GET_FP_IDS 1003
#define FINGERPRINT_REQUEST_GET_MAX_TEMPLATE_NUMBER 1004
#define FINGERPRINT_REQUEST_GET_SENSOR_INFO 5
#define FINGERPRINT_REQUEST_GET_SENSOR_STATUS 6
#define FINGERPRINT_REQUEST_GET_TOUCH_CNT 1007
#define FINGERPRINT_REQUEST_GET_UNIQUE_ID 7
#define FINGERPRINT_REQUEST_GET_USERIDS 12
#define FINGERPRINT_REQUEST_GET_VERSION 4
#define FINGERPRINT_REQUEST_HAS_FEATURE 1006
#define FINGERPRINT_REQUEST_LOCKOUT 1001
#define FINGERPRINT_REQUEST_NAVIGATION_LCD_ONOFF 17
#define FINGERPRINT_REQUEST_NAVIGATION_MODE_END 16
#define FINGERPRINT_REQUEST_NAVIGATION_MODE_START 15
#define FINGERPRINT_REQUEST_PAUSE 0
#define FINGERPRINT_REQUEST_PROCESS_FIDO 9
#define FINGERPRINT_REQUEST_REMOVE_FINGER 1000
#define FINGERPRINT_REQUEST_RESUME 1
#define FINGERPRINT_REQUEST_SENSOR_TEST_NORMALSCAN 3
#define FINGERPRINT_REQUEST_SESSION_OPEN 2
#define FINGERPRINT_REQUEST_SET_ACTIVE_GROUP 8
#define FINGERPRINT_REQUEST_UPDATE_SID 10
#define SEM_REQUEST_FORCE_CBGE 21
#define SEM_REQUEST_GET_FINGER_ICON_REMAIN_TIME 1010
#define SEM_REQUEST_GET_SECURITY_LEVEL 30
#define SEM_REQUEST_GET_SENSOR_TEST_RESULT 19
#define SEM_REQUEST_GET_TA_VERSION 10000
#define SEM_REQUEST_GET_TSP_BLOCK_STATUS 0x3F9
#define SEM_REQUEST_HIDE_INDISPLAY_AUTH_ANIMATION 0x3F4
#define SEM_REQUEST_INSTALL_TA 10001
#define SEM_REQUEST_IS_NEW_MATCHER 27
#define SEM_REQUEST_IS_TEMPLATE_CHANGED 25
#define SEM_REQUEST_MASK_CTL 0x3F5
#define SEM_REQUEST_MOVE_INDISPLAY_ICON 0x3F3
#define SEM_REQUEST_OPTICAL_CALIBRATION 0x3F8
#define SEM_REQUEST_REMOVE_ALL_USER 0x3F6
#define SEM_REQUEST_SET_ASP_LEVEL 20
#define SEM_REQUEST_SET_BOUNCER_SCREEN_STATUS 0x3FA
#define SEM_REQUEST_SET_SCREEN_STATUS 0x3F0
#define SEM_REQUEST_SHOW_INDISPLAY_AUTH_ANIMATION 1009
#define SEM_REQUEST_TOUCH_EVENT 22
#define SEM_REQUEST_TOUCH_SENSITIVE_CHANGE 0x3F7
#define SEM_REQUEST_UPDATE_MATCHER 28
#define SEM_REQUEST_VENDOR_EGIS_CALIBRATION 23
#define SEM_REQUEST_VENDOR_QCOM_REMOVE_CBGE 24
#define SEM_REQUEST_WIRELESS_CHARGER_STATUS 29
// Fingerprint aquired codes
#define SEM_FINGERPRINT_ACQUIRED_DUPLICATED_IMAGE 1002
#define SEM_FINGERPRINT_ACQUIRED_LIGHT_TOUCH 1003
#define SEM_FINGERPRINT_ACQUIRED_TSP_BLOCK 1004
#define SEM_FINGERPRINT_ACQUIRED_TSP_UNBLOCK 1005
#define SEM_FINGERPRINT_ACQUIRED_WET_FINGER 1001
// Fingerprint errors
#define SEM_FINGERPRINT_ERROR_CALIBRATION 1001
#define SEM_FINGERPRINT_ERROR_DISABLED_BIOMETRICS 5002
#define SEM_FINGERPRINT_ERROR_INVALID_HW 1005
#define SEM_FINGERPRINT_ERROR_NEED_TO_RETRY 5000
#define SEM_FINGERPRINT_ERROR_ONE_HAND_MODE 5001
#define SEM_FINGERPRINT_ERROR_PATTERN_DETECTED 1007
#define SEM_FINGERPRINT_ERROR_SERVICE_FAILURE 1003
#define SEM_FINGERPRINT_ERROR_SMART_VIEW 5003
#define SEM_FINGERPRINT_ERROR_SYSTEM_FAILURE 1002
#define SEM_FINGERPRINT_ERROR_TA_UPDATE -100
#define SEM_FINGERPRINT_ERROR_TEMPLATE_CORRUPTED 1004
#define SEM_FINGERPRINT_ERROR_TEMPLATE_FORMAT_CHANGED 1006
#define SEM_FINGERPRINT_ERROR_WIRELESS_CHARGING 5004
// Fingerprint events
#define SEM_FINGERPRINT_EVENT_BASE 10000
#define SEM_FINGERPRINT_EVENT_CAPTURE_COMPLETED 10003
#define SEM_FINGERPRINT_EVENT_CAPTURE_FAILED 10006
#define SEM_FINGERPRINT_EVENT_CAPTURE_READY 10001
#define SEM_FINGERPRINT_EVENT_CAPTURE_STARTED 10002
#define SEM_FINGERPRINT_EVENT_CAPTURE_SUCCESS 10005
#define SEM_FINGERPRINT_EVENT_FACTORY_SNSR_SCRIPT_END 10009
#define SEM_FINGERPRINT_EVENT_FACTORY_SNSR_SCRIPT_START 10008
#define SEM_FINGERPRINT_EVENT_FINGER_LEAVE 10004
#define SEM_FINGERPRINT_EVENT_FINGER_LEAVE_TIMEOUT 10007
#define SEM_FINGERPRINT_EVENT_GESTURE_DTAP 20003
#define SEM_FINGERPRINT_EVENT_GESTURE_LPRESS 20004
#define SEM_FINGERPRINT_EVENT_GESTURE_SWIPE_DOWN 20002
#define SEM_FINGERPRINT_EVENT_GESTURE_SWIPE_UP 20001
#define SEM_FINGERPRINT_EVENT_SPEN_CONTROL_OFF 30002
#define SEM_FINGERPRINT_EVENT_SPEN_CONTROL_ON 30001
// Fingerprint sensor status codes
#define SEM_SENSOR_STATUS_CALIBRATION_ERROR 100045
#define SEM_SENSOR_STATUS_ERROR 100042
#define SEM_SENSOR_STATUS_OK 100040
#define SEM_SENSOR_STATUS_WORKING 100041

@ -1,4 +1,4 @@
service vendor.fps_hal /vendor/bin/hw/vendor.samsung.hardware.biometrics.fingerprint@3.0-service.sm7125 service vendor.fps_hal /vendor/bin/hw/android.hardware.biometrics.fingerprint@2.3-service-samsung.sm7125
# "class hal" causes a race condition on some devices due to files created # "class hal" causes a race condition on some devices due to files created
# in /data. As a workaround, postpone startup until later in boot once # in /data. As a workaround, postpone startup until later in boot once
# /data is mounted. # /data is mounted.

@ -9,14 +9,4 @@
</interface> </interface>
<fqname>@2.3::IBiometricsFingerprint/default</fqname> <fqname>@2.3::IBiometricsFingerprint/default</fqname>
</hal> </hal>
<hal format="hidl" override="true">
<name>vendor.samsung.hardware.biometrics.fingerprint</name>
<transport>hwbinder</transport>
<version>3.0</version>
<interface>
<name>ISehBiometricsFingerprint</name>
<instance>default</instance>
</interface>
<fqname>@3.0::ISehBiometricsFingerprint/default</fqname>
</hal>
</manifest> </manifest>

@ -14,7 +14,7 @@
* limitations under the License. * limitations under the License.
*/ */
#define LOG_TAG "vendor.samsung.hardware.biometrics.fingerprint@3.0-service.sm7125" #define LOG_TAG "android.hardware.biometrics.fingerprint@2.3-service-samsung.sm7125"
#include <android-base/logging.h> #include <android-base/logging.h>
#include <hidl/HidlTransportSupport.h> #include <hidl/HidlTransportSupport.h>
@ -25,14 +25,14 @@
using android::hardware::configureRpcThreadpool; using android::hardware::configureRpcThreadpool;
using android::hardware::joinRpcThreadpool; using android::hardware::joinRpcThreadpool;
using vendor::samsung::hardware::biometrics::fingerprint::V3_0::ISehBiometricsFingerprint; using android::hardware::biometrics::fingerprint::V2_3::IBiometricsFingerprint;
using vendor::samsung::hardware::biometrics::fingerprint::V3_0::implementation::SehBiometricsFingerprint; using android::hardware::biometrics::fingerprint::V2_3::implementation::BiometricsFingerprint;
using android::OK; using android::OK;
using android::sp; using android::sp;
int main() { int main() {
android::sp<ISehBiometricsFingerprint> bio = SehBiometricsFingerprint::getInstance(); android::sp<IBiometricsFingerprint> bio = BiometricsFingerprint::getInstance();
configureRpcThreadpool(1, true); configureRpcThreadpool(1, true);

@ -1,4 +0,0 @@
hidl_package_root {
name: "vendor.samsung.hardware",
path: "device/samsung/sm7125-common/interfaces",
}

@ -1,16 +0,0 @@
// This file is autogenerated by hidl-gen -Landroidbp.
hidl_interface {
name: "vendor.samsung.hardware.biometrics.fingerprint@3.0",
root: "vendor.samsung.hardware",
srcs: [
"ISehBiometricsFingerprint.hal",
],
interfaces: [
"android.hardware.biometrics.fingerprint@2.1",
"android.hardware.biometrics.fingerprint@2.2",
"android.hardware.biometrics.fingerprint@2.3",
"android.hidl.base@1.0",
],
gen_java: true,
}

@ -1,7 +0,0 @@
package vendor.samsung.hardware.biometrics.fingerprint@3.0;
import android.hardware.biometrics.fingerprint@2.3::IBiometricsFingerprint;
interface ISehBiometricsFingerprint extends android.hardware.biometrics.fingerprint@2.3::IBiometricsFingerprint {
sehRequest(int32_t cmdId, int32_t inParam, vec<int8_t> inBuf) generates (int32_t retval, vec<int8_t> outBuf);
};

@ -60,7 +60,7 @@
/(vendor|system/vendor)/bin/hw/vendor\.lineage\.touch\@[0-9]\.[0-9]-service.samsung u:object_r:hal_lineage_touch_default_exec:s0 /(vendor|system/vendor)/bin/hw/vendor\.lineage\.touch\@[0-9]\.[0-9]-service.samsung u:object_r:hal_lineage_touch_default_exec:s0
/(vendor|system/vendor)/bin/secril_config_svc u:object_r:secril_config_svc_exec:s0 /(vendor|system/vendor)/bin/secril_config_svc u:object_r:secril_config_svc_exec:s0
/(vendor|system/vendor)/bin/hw/vendor\.lineage\.livedisplay@2\.0-service.samsung-qcom\.sm7125 u:object_r:hal_lineage_livedisplay_sysfs_exec:s0 /(vendor|system/vendor)/bin/hw/vendor\.lineage\.livedisplay@2\.0-service.samsung-qcom\.sm7125 u:object_r:hal_lineage_livedisplay_sysfs_exec:s0
/(vendor|system/vendor)/bin/hw/vendor.samsung.hardware.biometrics.fingerprint@3.0-service.sm7125 u:object_r:hal_fingerprint_default_exec:s0 /(vendor|system/vendor)/bin/hw/android.hardware.biometrics.fingerprint@2.3-service-samsung.sm7125 u:object_r:hal_fingerprint_default_exec:s0
/(vendor|system/vendor)/bin/hw/android.hardware.sensors@[0-9].[0-9]-service.samsung-multihal u:object_r:hal_sensors_default_exec:s0 /(vendor|system/vendor)/bin/hw/android.hardware.sensors@[0-9].[0-9]-service.samsung-multihal u:object_r:hal_sensors_default_exec:s0
/(vendor|system/vendor)/bin/hw/android.hardware.vibrator-service.sm7125 u:object_r:hal_vibrator_default_exec:s0 /(vendor|system/vendor)/bin/hw/android.hardware.vibrator-service.sm7125 u:object_r:hal_vibrator_default_exec:s0
/(vendor|system/vendor)/bin/hw/android\.hardware\.health@2\.1-service-samsung u:object_r:hal_health_default_exec:s0 /(vendor|system/vendor)/bin/hw/android\.hardware\.health@2\.1-service-samsung u:object_r:hal_health_default_exec:s0

@ -4,9 +4,6 @@ vendor.samsung.hardware.bluetooth.a2dp::ISehBluetoothAudioOffload
vendor.samsung.hardware.bluetooth.a2dpsink::ISehBluetoothA2dpSinkProvidersFactory u:object_r:hal_bluetooth_a2dp_hwservice:s0 vendor.samsung.hardware.bluetooth.a2dpsink::ISehBluetoothA2dpSinkProvidersFactory u:object_r:hal_bluetooth_a2dp_hwservice:s0
vendor.samsung.hardware.bluetooth.audio::ISehBluetoothAudioProvidersFactory u:object_r:hal_audio_hwservice:s0 vendor.samsung.hardware.bluetooth.audio::ISehBluetoothAudioProvidersFactory u:object_r:hal_audio_hwservice:s0
# Fingerprint
vendor.samsung.hardware.biometrics.fingerprint::ISehBiometricsFingerprint u:object_r:hal_fingerprint_hwservice:s0
# GNSS # GNSS
vendor.samsung.hardware.gnss::ISehGnss u:object_r:hal_gnss_hwservice:s0 vendor.samsung.hardware.gnss::ISehGnss u:object_r:hal_gnss_hwservice:s0

Loading…
Cancel
Save