blob: 485f401504191dfb3aa6de7430a8487a277cfc5a [file] [log] [blame]
Jeff Pu63f33c72022-07-28 16:06:23 -04001/*
2 * Copyright (C) 2022 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17#include <android/binder_process.h>
18#include <fingerprint.sysprop.h>
19#include <gtest/gtest.h>
20
21#include <android-base/logging.h>
22
23#include "FakeFingerprintEngine.h"
24#include "FakeFingerprintEngineUdfps.h"
25
26using namespace ::android::fingerprint::virt;
27using namespace ::aidl::android::hardware::biometrics::fingerprint;
28using namespace ::aidl::android::hardware::keymaster;
29
30namespace aidl::android::hardware::biometrics::fingerprint {
31
32class FakeFingerprintEngineUdfpsTest : public ::testing::Test {
33 protected:
34 void SetUp() override {}
35
36 void TearDown() override {
37 // reset to default
38 FingerprintHalProperties::sensor_location("");
39 }
40
41 FakeFingerprintEngineUdfps mEngine;
42};
43
44bool isDefaultLocation(SensorLocation& sc) {
45 return (sc.sensorLocationX == FakeFingerprintEngineUdfps::defaultSensorLocationX &&
46 sc.sensorLocationY == FakeFingerprintEngineUdfps::defaultSensorLocationY &&
47 sc.sensorRadius == FakeFingerprintEngineUdfps::defaultSensorRadius && sc.display == "");
48}
49
50TEST_F(FakeFingerprintEngineUdfpsTest, getSensorLocation) {
51 FingerprintHalProperties::sensor_location("");
52 SensorLocation sc = mEngine.getSensorLocation();
53 ASSERT_TRUE(isDefaultLocation(sc));
54
55 auto loc = "100:200:30";
56 FingerprintHalProperties::sensor_location(loc);
57 sc = mEngine.getSensorLocation();
58 ASSERT_TRUE(sc.sensorLocationX == 100);
59 ASSERT_TRUE(sc.sensorLocationY == 200);
60 ASSERT_TRUE(sc.sensorRadius == 30);
61
62 loc = "100:200:30:screen1";
63 FingerprintHalProperties::sensor_location(loc);
64 sc = mEngine.getSensorLocation();
65 ASSERT_TRUE(sc.sensorLocationX == 100);
66 ASSERT_TRUE(sc.sensorLocationY == 200);
67 ASSERT_TRUE(sc.sensorRadius == 30);
68 ASSERT_TRUE(sc.display == "screen1");
69
70 loc = "100";
71 FingerprintHalProperties::sensor_location(loc);
72 sc = mEngine.getSensorLocation();
73 ASSERT_TRUE(isDefaultLocation(sc));
74
75 loc = "10:20";
76 FingerprintHalProperties::sensor_location(loc);
77 sc = mEngine.getSensorLocation();
78 ASSERT_TRUE(isDefaultLocation(sc));
79
80 loc = "10,20,5";
81 FingerprintHalProperties::sensor_location(loc);
82 sc = mEngine.getSensorLocation();
83 ASSERT_TRUE(isDefaultLocation(sc));
84
85 loc = "a:b:c";
86 FingerprintHalProperties::sensor_location(loc);
87 sc = mEngine.getSensorLocation();
88 ASSERT_TRUE(isDefaultLocation(sc));
89}
90
91// More
92} // namespace aidl::android::hardware::biometrics::fingerprint