Snap for 9491836 from 5575379610 to udc-release

Change-Id: I683f98b3acdcb225f65c2808742716e2dbb8681b
This commit is contained in:
Android Build Coastguard Worker
2023-01-15 02:27:14 +00:00
7 changed files with 293 additions and 9 deletions

View File

@@ -16,8 +16,8 @@
-->
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="300dp"
android:height="300dp"
android:width="@dimen/face_enroll_icon_large_width"
android:height="@dimen/face_enroll_icon_large_height"
android:viewportWidth="300"
android:viewportHeight="300"
android:tint="@color/face_enroll_icon_color">

View File

@@ -39,7 +39,7 @@
<FrameLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="-24dp">
android:layout_marginTop="@dimen/face_enroll_education_lottie_frame_margin_top">
<com.google.android.setupdesign.view.IllustrationVideoView
android:id="@+id/illustration_default"
@@ -52,8 +52,8 @@
<com.airbnb.lottie.LottieAnimationView
android:id="@+id/illustration_lottie"
android:layout_width="match_parent"
android:layout_height="440dp"
android:layout_marginTop="-52dp"
android:layout_height="@dimen/illustration_lottie_height"
android:layout_marginTop="@dimen/lottie_animation_view_margin_top"
android:scaleType="centerInside"
android:visibility="gone"
app:lottie_autoPlay="true"
@@ -66,6 +66,7 @@
android:layout_height="wrap_content"
android:layout_gravity="center"
android:visibility="invisible"
android:layout_marginTop="@dimen/illustration_accessibility_margin_top"
android:src="@drawable/face_enroll_icon_large"/>
</FrameLayout>
@@ -84,7 +85,7 @@
<FrameLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="-24dp">
android:layout_marginTop="@dimen/limited_vision_button_frame_margin_top">
<Button
android:id="@+id/accessibility_button"
@@ -92,12 +93,15 @@
android:layout_gravity="center"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="@dimen/limited_vision_button_margin_top"
android:layout_marginBottom="@dimen/limited_vision_button_margin_bottom"
android:text="@string/security_settings_face_enroll_introduction_accessibility"/>
<com.android.settings.biometrics.face.FaceEnrollAccessibilityToggle
android:id="@+id/toggle_diversity"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="@dimen/limited_vision_button_toggle_margin_top"
android:visibility="gone"
app:messageText="@string/security_settings_face_enroll_introduction_accessibility"/>

View File

@@ -395,4 +395,16 @@
<dimen name="qrcode_icon_size">27dp</dimen>
<!-- Margin for SD card setup completion Image -->
<dimen name="setup_completion_margin_top">88dp</dimen>
<!-- Biometrics Face enroll education dimensions-->
<dimen name="face_enroll_icon_large_width">300dp</dimen>
<dimen name="face_enroll_icon_large_height">300dp</dimen>
<dimen name="illustration_lottie_height">440dp</dimen>
<dimen name="illustration_accessibility_margin_top">0dp</dimen>
<dimen name="face_enroll_education_lottie_frame_margin_top">-24dp</dimen>
<dimen name="lottie_animation_view_margin_top">-52dp</dimen>
<dimen name="limited_vision_button_frame_margin_top">-24dp</dimen>
<dimen name="limited_vision_button_margin_top">0dp</dimen>
<dimen name="limited_vision_button_margin_bottom">0dp</dimen>
<dimen name="limited_vision_button_toggle_margin_top">0dp</dimen>
</resources>

View File

@@ -26,6 +26,8 @@ import android.graphics.SurfaceTexture;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.os.VibrationEffect;
import android.os.Vibrator;
import android.util.Log;
import android.util.Size;
import android.view.LayoutInflater;
@@ -45,6 +47,8 @@ import com.android.settingslib.bluetooth.BluetoothBroadcastUtils;
import com.android.settingslib.bluetooth.BluetoothUtils;
import com.android.settingslib.qrcode.QrCamera;
import java.time.Duration;
public class QrCodeScanModeFragment extends InstrumentedFragment implements
TextureView.SurfaceTextureListener,
QrCamera.ScannerCallback {
@@ -61,6 +65,8 @@ public class QrCodeScanModeFragment extends InstrumentedFragment implements
private static final long SHOW_ERROR_MESSAGE_INTERVAL = 10000;
private static final long SHOW_SUCCESS_SQUARE_INTERVAL = 1000;
private static final Duration VIBRATE_DURATION_QR_CODE_RECOGNITION = Duration.ofMillis(3);
private boolean mIsGroupOp;
private int mCornerRadius;
private BluetoothDevice mSink;
@@ -209,16 +215,39 @@ public class QrCodeScanModeFragment extends InstrumentedFragment implements
break;
case MESSAGE_SCAN_BROADCAST_SUCCESS:
/* TODO(b/265281156) : Move the logic to BluetoothFindBroadcastsFragment.
* We only pass the QR code string to the previous page.
*/
mController.addSource(mSink, mBroadcastMetadata, mIsGroupOp);
updateSummary();
mSummary.sendAccessibilityEvent(
AccessibilityEvent.TYPE_WINDOW_STATE_CHANGED);
notifyUserForQrCodeRecognition();
break;
default:
}
}
};
private void notifyUserForQrCodeRecognition() {
if (mCamera != null) {
mCamera.stop();
}
mErrorMessage.setVisibility(View.INVISIBLE);
triggerVibrationForQrCodeRecognition(getContext());
getActivity().finish();
}
private static void triggerVibrationForQrCodeRecognition(Context context) {
Vibrator vibrator = context.getSystemService(Vibrator.class);
if (vibrator == null) {
return;
}
vibrator.vibrate(VibrationEffect.createOneShot(
VIBRATE_DURATION_QR_CODE_RECOGNITION.toMillis(),
VibrationEffect.DEFAULT_AMPLITUDE));
}
private void showErrorMessage(@StringRes int messageResId) {
final Message message = mHandler.obtainMessage(MESSAGE_SHOW_ERROR_MESSAGE,
getString(messageResId));

View File

@@ -0,0 +1 @@
include /src/com/android/settings/biometrics/OWNERS

View File

@@ -0,0 +1,179 @@
/*
* Copyright (C) 2023 The Android Open Source 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.
*/
package com.android.settings.biometrics2.ui.viewmodel;
import static android.hardware.fingerprint.FingerprintManager.ENROLL_ENROLL;
import static android.hardware.fingerprint.FingerprintManager.ENROLL_FIND_SENSOR;
import static android.hardware.fingerprint.FingerprintManager.EnrollReason;
import static android.hardware.fingerprint.FingerprintManager.EnrollmentCallback;
import static com.android.settings.biometrics2.ui.model.EnrollmentProgress.INITIAL_STEPS;
import static com.google.common.truth.Truth.assertThat;
import static org.mockito.ArgumentMatchers.anyInt;
import static org.mockito.Mockito.any;
import static org.mockito.Mockito.doAnswer;
import static org.mockito.Mockito.eq;
import static org.mockito.Mockito.never;
import static org.mockito.Mockito.only;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
import android.app.Application;
import android.content.res.Resources;
import android.os.CancellationSignal;
import com.android.settings.R;
import com.android.settings.biometrics.fingerprint.FingerprintUpdater;
import com.android.settings.biometrics2.ui.model.EnrollmentProgress;
import com.android.settings.testutils.InstantTaskExecutorRule;
import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.Mock;
import org.mockito.junit.MockitoJUnit;
import org.mockito.junit.MockitoRule;
import org.robolectric.RobolectricTestRunner;
@RunWith(RobolectricTestRunner.class)
public class FingerprintEnrollProgressViewModelTest {
@Rule public final MockitoRule mockito = MockitoJUnit.rule();
@Rule public final InstantTaskExecutorRule mTaskExecutorRule = new InstantTaskExecutorRule();
@Mock private Application mApplication;
@Mock private Resources mResources;
@Mock private FingerprintUpdater mFingerprintUpdater;
private FingerprintEnrollProgressViewModel mViewModel;
@Before
public void setUp() {
when(mApplication.getResources()).thenReturn(mResources);
when(mResources.getBoolean(R.bool.enrollment_message_display_controller_flag))
.thenReturn(false);
mViewModel = new FingerprintEnrollProgressViewModel(mApplication, mFingerprintUpdater);
}
@Test
public void testStartEnrollment() {
@EnrollReason final int enrollReason = ENROLL_FIND_SENSOR;
final int userId = 334;
final byte[] token = new byte[] { 1, 2, 3 };
mViewModel.setToken(token);
mViewModel.setUserId(userId);
// Start enrollment
final boolean ret = mViewModel.startEnrollment(enrollReason);
assertThat(ret).isTrue();
verify(mFingerprintUpdater, only()).enroll(eq(token), any(CancellationSignal.class),
eq(userId), any(EnrollmentCallback.class), eq(enrollReason));
}
@Test
public void testStartEnrollmentFailBecauseOfNoToken() {
// Start enrollment
final boolean ret = mViewModel.startEnrollment(ENROLL_FIND_SENSOR);
assertThat(ret).isFalse();
verify(mFingerprintUpdater, never()).enroll(any(byte[].class),
any(CancellationSignal.class), anyInt(), any(EnrollmentCallback.class), anyInt());
}
@Test
public void testCancelEnrollment() {
@EnrollReason final int enrollReason = ENROLL_ENROLL;
final int userId = 334;
final byte[] token = new byte[] { 1, 2, 3 };
mViewModel.setToken(token);
mViewModel.setUserId(userId);
final TestWrapper<CancellationSignal> signalWrapper = new TestWrapper<>();
doAnswer(invocation -> {
signalWrapper.mValue = invocation.getArgument(1);
return null;
}).when(mFingerprintUpdater).enroll(any(byte[].class), any(CancellationSignal.class),
eq(userId), any(EnrollmentCallback.class), anyInt());
// Start enrollment
final boolean ret = mViewModel.startEnrollment(enrollReason);
assertThat(ret).isTrue();
assertThat(signalWrapper.mValue).isNotNull();
// Cancel enrollment
mViewModel.cancelEnrollment();
assertThat(signalWrapper.mValue.isCanceled()).isTrue();
}
@Test
public void testProgressUpdate() {
@EnrollReason final int enrollReason = ENROLL_ENROLL;
final int userId = 334;
final byte[] token = new byte[] { 1, 2, 3 };
mViewModel.setToken(token);
mViewModel.setUserId(userId);
final TestWrapper<EnrollmentCallback> callbackWrapper = new TestWrapper<>();
doAnswer(invocation -> {
callbackWrapper.mValue = invocation.getArgument(3);
return null;
}).when(mFingerprintUpdater).enroll(any(byte[].class), any(CancellationSignal.class),
eq(userId), any(EnrollmentCallback.class), anyInt());
// Start enrollment
final boolean ret = mViewModel.startEnrollment(enrollReason);
assertThat(ret).isTrue();
assertThat(callbackWrapper.mValue).isNotNull();
// Update first progress
callbackWrapper.mValue.onEnrollmentProgress(25);
EnrollmentProgress progress = mViewModel.getProgressLiveData().getValue();
assertThat(progress).isNotNull();
assertThat(progress.getSteps()).isEqualTo(25);
// TODO(b/260957933) verify getRemaining() when it is really used
//assertThat(progress.getRemaining()).isEqualTo(25);
// Update second progress
callbackWrapper.mValue.onEnrollmentProgress(20);
progress = mViewModel.getProgressLiveData().getValue();
assertThat(progress).isNotNull();
assertThat(progress.getSteps()).isEqualTo(25);
// TODO(b/260957933) verify getRemaining() when it is really used
//assertThat(progress.getRemaining()).isEqualTo(20);
// Clear progress
mViewModel.clearProgressLiveData();
progress = mViewModel.getProgressLiveData().getValue();
assertThat(progress).isNotNull();
assertThat(progress.getSteps()).isEqualTo(INITIAL_STEPS);
// TODO(b/260957933) verify getRemaining() when it is really used
//assertThat(progress.getRemaining()).isEqualTo(INITIAL_REMAINING);
}
// TODO(b/260957933): FingerprintEnrollProgressViewModel::getErrorLiveData() and
// FingerprintEnrollProgressViewModel::getHelpLiveData() doesn't built into apk because no one
// uses it. We shall test it when new FingerprintEnrollEnrolling has used these 2 methods.
private static class TestWrapper<T> {
T mValue;
}
}

View File

@@ -0,0 +1,59 @@
/*
* Copyright (C) 2023 The Android Open Source 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.
*/
package com.android.settings.testutils;
import androidx.arch.core.executor.ArchTaskExecutor;
import androidx.arch.core.executor.TaskExecutor;
import org.junit.rules.TestWatcher;
import org.junit.runner.Description;
/**
* A JUnit Test Rule that swaps the background executor used by the Architecture Components with a
* different one which executes each task synchronously.
*
* We can't refer it in prebuilt androidX library.
* Copied it from androidx/arch/core/executor/testing/InstantTaskExecutorRule.java
*/
public class InstantTaskExecutorRule extends TestWatcher {
@Override
protected void starting(Description description) {
super.starting(description);
ArchTaskExecutor.getInstance().setDelegate(new TaskExecutor() {
@Override
public void executeOnDiskIO(Runnable runnable) {
runnable.run();
}
@Override
public void postToMainThread(Runnable runnable) {
runnable.run();
}
@Override
public boolean isMainThread() {
return true;
}
});
}
@Override
protected void finished(Description description) {
super.finished(description);
ArchTaskExecutor.getInstance().setDelegate(null);
}
}