1 /* 2 * Copyright (C) 2021 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 package com.android.systemui.biometrics; 18 19 import static org.junit.Assert.assertEquals; 20 21 import android.hardware.biometrics.ComponentInfoInternal; 22 import android.hardware.biometrics.SensorLocationInternal; 23 import android.hardware.biometrics.SensorProperties; 24 import android.hardware.fingerprint.FingerprintSensorProperties; 25 import android.hardware.fingerprint.FingerprintSensorPropertiesInternal; 26 27 import androidx.test.ext.junit.runners.AndroidJUnit4; 28 import androidx.test.filters.SmallTest; 29 30 import com.android.systemui.RoboPilotTest; 31 import com.android.systemui.SysuiTestCase; 32 33 import org.junit.Test; 34 import org.junit.runner.RunWith; 35 36 import java.util.ArrayList; 37 import java.util.List; 38 39 @RunWith(AndroidJUnit4.class) 40 @SmallTest 41 @RoboPilotTest 42 public class UdfpsDialogMeasureAdapterTest extends SysuiTestCase { 43 @Test testUdfpsBottomSpacerHeightForPortrait()44 public void testUdfpsBottomSpacerHeightForPortrait() { 45 final int displayHeightPx = 3000; 46 final int navbarHeightPx = 10; 47 final int dialogBottomMarginPx = 20; 48 final int buttonBarHeightPx = 100; 49 final int textIndicatorHeightPx = 200; 50 51 final int sensorLocationX = 540; 52 final int sensorLocationY = 1600; 53 final int sensorRadius = 100; 54 55 final List<ComponentInfoInternal> componentInfo = new ArrayList<>(); 56 componentInfo.add(new ComponentInfoInternal("faceSensor" /* componentId */, 57 "vendor/model/revision" /* hardwareVersion */, "1.01" /* firmwareVersion */, 58 "00000001" /* serialNumber */, "" /* softwareVersion */)); 59 componentInfo.add(new ComponentInfoInternal("matchingAlgorithm" /* componentId */, 60 "" /* hardwareVersion */, "" /* firmwareVersion */, "" /* serialNumber */, 61 "vendor/version/revision" /* softwareVersion */)); 62 63 final FingerprintSensorPropertiesInternal props = new FingerprintSensorPropertiesInternal( 64 0 /* sensorId */, SensorProperties.STRENGTH_STRONG, 5 /* maxEnrollmentsPerUser */, 65 componentInfo, 66 FingerprintSensorProperties.TYPE_UDFPS_OPTICAL, 67 true /* halControlsIllumination */, 68 true /* resetLockoutRequiresHardwareAuthToken */, 69 List.of(new SensorLocationInternal("" /* displayId */, 70 sensorLocationX, sensorLocationY, sensorRadius))); 71 72 assertEquals(970, 73 UdfpsDialogMeasureAdapter.calculateBottomSpacerHeightForPortrait( 74 props, displayHeightPx, textIndicatorHeightPx, buttonBarHeightPx, 75 dialogBottomMarginPx, navbarHeightPx, 1.0f /* resolutionScale */ 76 )); 77 } 78 79 @Test testUdfpsBottomSpacerHeightForLandscape_whenMoreSpaceAboveIcon()80 public void testUdfpsBottomSpacerHeightForLandscape_whenMoreSpaceAboveIcon() { 81 final int titleHeightPx = 320; 82 final int subtitleHeightPx = 240; 83 final int descriptionHeightPx = 200; 84 final int topSpacerHeightPx = 550; 85 final int textIndicatorHeightPx = 190; 86 final int buttonBarHeightPx = 160; 87 final int navbarBottomInsetPx = 75; 88 89 assertEquals(885, 90 UdfpsDialogMeasureAdapter.calculateBottomSpacerHeightForLandscape( 91 titleHeightPx, subtitleHeightPx, descriptionHeightPx, topSpacerHeightPx, 92 textIndicatorHeightPx, buttonBarHeightPx, navbarBottomInsetPx)); 93 } 94 95 @Test testUdfpsBottomSpacerHeightForLandscape_whenMoreSpaceBelowIcon()96 public void testUdfpsBottomSpacerHeightForLandscape_whenMoreSpaceBelowIcon() { 97 final int titleHeightPx = 315; 98 final int subtitleHeightPx = 160; 99 final int descriptionHeightPx = 75; 100 final int topSpacerHeightPx = 220; 101 final int textIndicatorHeightPx = 290; 102 final int buttonBarHeightPx = 360; 103 final int navbarBottomInsetPx = 205; 104 105 assertEquals(-85, 106 UdfpsDialogMeasureAdapter.calculateBottomSpacerHeightForLandscape( 107 titleHeightPx, subtitleHeightPx, descriptionHeightPx, topSpacerHeightPx, 108 textIndicatorHeightPx, buttonBarHeightPx, navbarBottomInsetPx)); 109 } 110 111 @Test testUdfpsHorizontalSpacerWidthForLandscape()112 public void testUdfpsHorizontalSpacerWidthForLandscape() { 113 final int displayWidthPx = 3000; 114 final int dialogMarginPx = 20; 115 final int navbarHorizontalInsetPx = 75; 116 117 final int sensorLocationX = 540; 118 final int sensorLocationY = 1600; 119 final int sensorRadius = 100; 120 121 final List<ComponentInfoInternal> componentInfo = new ArrayList<>(); 122 componentInfo.add(new ComponentInfoInternal("faceSensor" /* componentId */, 123 "vendor/model/revision" /* hardwareVersion */, "1.01" /* firmwareVersion */, 124 "00000001" /* serialNumber */, "" /* softwareVersion */)); 125 componentInfo.add(new ComponentInfoInternal("matchingAlgorithm" /* componentId */, 126 "" /* hardwareVersion */, "" /* firmwareVersion */, "" /* serialNumber */, 127 "vendor/version/revision" /* softwareVersion */)); 128 129 final FingerprintSensorPropertiesInternal props = new FingerprintSensorPropertiesInternal( 130 0 /* sensorId */, SensorProperties.STRENGTH_STRONG, 5 /* maxEnrollmentsPerUser */, 131 componentInfo, 132 FingerprintSensorProperties.TYPE_UDFPS_OPTICAL, 133 true /* halControlsIllumination */, 134 true /* resetLockoutRequiresHardwareAuthToken */, 135 List.of(new SensorLocationInternal("" /* displayId */, 136 sensorLocationX, sensorLocationY, sensorRadius))); 137 138 assertEquals(1205, 139 UdfpsDialogMeasureAdapter.calculateHorizontalSpacerWidthForLandscape( 140 props, displayWidthPx, dialogMarginPx, navbarHorizontalInsetPx, 141 1.0f /* resolutionScale */)); 142 } 143 } 144