summaryrefslogtreecommitdiffstats
path: root/hidl/fingerprint/inscreen/FingerprintInscreen.cpp
blob: 47211b1645603b609513f98e8ba85662aa99a6e5 (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
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
/*
 * Copyright (C) 2020 The LineageOS Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

#define LOG_TAG "FingerprintInscreenService"

#include "FingerprintInscreen.h"

#include <android-base/logging.h>
#include <hidl/HidlTransportSupport.h>

#include <fstream>

namespace vendor {
namespace lineage {
namespace biometrics {
namespace fingerprint {
namespace inscreen {
namespace V1_0 {
namespace implementation {

/*
 * Write value to path and close file.
 */
template <typename T>
static void set(const std::string& path, const T& value) {
    std::ofstream file(path);

    if (!file) {
        PLOG(ERROR) << "Failed to open: " << path;
        return;
    }

    LOG(DEBUG) << "write: " << path << " value: " << value;

    file << value << std::endl;

    if (!file) {
        PLOG(ERROR) << "Failed to write: " << path << " value: " << value;
    }
}

template <typename T>
static T get(const std::string& path, const T& def) {
    std::ifstream file(path);

    if (!file) {
        PLOG(ERROR) << "Failed to open: " << path;
        return def;
    }

    T result;

    file >> result;

    if (file.fail()) {
        PLOG(ERROR) << "Failed to read: " << path;
        return def;
    } else {
        LOG(DEBUG) << "read: " << path << " value: " << result;
        return result;
    }
}

FingerprintInscreen::FingerprintInscreen() {}

Return<void> FingerprintInscreen::onStartEnroll() { return Void(); }

Return<void> FingerprintInscreen::onFinishEnroll() { return Void(); }

Return<void> FingerprintInscreen::onPress() {
    set(TSP_CMD_PATH, FOD_ENABLE);
    return Void();
}

Return<void> FingerprintInscreen::onRelease() {
    set(TSP_CMD_PATH, FOD_DISABLE);
    return Void();
}

Return<void> FingerprintInscreen::onShowFODView() { return Void(); }

Return<void> FingerprintInscreen::onHideFODView() {
    set(TSP_CMD_PATH, FOD_DISABLE);
    return Void();
}

Return<bool> FingerprintInscreen::handleAcquired(int32_t acquiredInfo, int32_t vendorCode) {
    std::lock_guard<std::mutex> _lock(mCallbackLock);

    if (mCallback == nullptr) {
        return false;
    }

    if (acquiredInfo == FINGERPRINT_ACQUIRED_VENDOR) {
        if (vendorCode == VENDORCODE_FINGER_DOWN) {
            Return<void> ret = mCallback->onFingerDown();
            if (!ret.isOk()) {
                LOG(ERROR) << "FingerDown() error: " << ret.description();
            }
            return true;
        } else if (vendorCode == VENDORCODE_FINGER_UP) {
            Return<void> ret = mCallback->onFingerUp();
            if (!ret.isOk()) {
                LOG(ERROR) << "FingerUp() error: " << ret.description();
            }
            return true;
        }
    }

    return false;
}

Return<bool> FingerprintInscreen::handleError(int32_t, int32_t) { return false; }

Return<void> FingerprintInscreen::setLongPressEnabled(bool) { return Void(); }

Return<int32_t> FingerprintInscreen::getDimAmount(int32_t cur_brightness) {
    return cur_brightness / 2;
}

Return<bool> FingerprintInscreen::shouldBoostBrightness() { return false; }

Return<void> FingerprintInscreen::setCallback(const sp<IFingerprintInscreenCallback>& callback) {
    mCallback = callback;

    return Void();
}

Return<int32_t> FingerprintInscreen::getPositionX() { return FOD_SENSOR_X; }

Return<int32_t> FingerprintInscreen::getPositionY() { return FOD_SENSOR_Y; }

Return<int32_t> FingerprintInscreen::getSize() { return FOD_SENSOR_SIZE; }

}  // namespace implementation
}  // namespace V1_0
}  // namespace inscreen
}  // namespace fingerprint
}  // namespace biometrics
}  // namespace lineage
}  // namespace vendor