Merge "Fix the text color of the sim list in the dark theme" into main
diff --git a/aconfig/Android.bp b/aconfig/Android.bp
index 6daa90c..7b571e0 100644
--- a/aconfig/Android.bp
+++ b/aconfig/Android.bp
@@ -12,6 +12,7 @@
"settings_experience_flag_declarations.aconfig",
"settings_onboarding_experience_flag_declarations.aconfig",
"settings_telephony_flag_declarations.aconfig",
+ "settings_biometrics_integration_declarations.aconfig",
],
}
diff --git a/aconfig/settings_biometrics_integration_declarations.aconfig b/aconfig/settings_biometrics_integration_declarations.aconfig
new file mode 100644
index 0000000..529e126
--- /dev/null
+++ b/aconfig/settings_biometrics_integration_declarations.aconfig
@@ -0,0 +1,9 @@
+package: "com.android.settings.flags"
+
+flag {
+ name: "sfps_enroll_refinement"
+ namespace: "biometrics_integration"
+ description: "This flag controls whether the sfps pause enrollment feature should be enabled"
+ bug: "288155127"
+}
+
diff --git a/res/layout/fingerprint_v2_enroll_introduction.xml b/res/layout/fingerprint_v2_enroll_introduction.xml
index 2fd1f9c..cf39206 100644
--- a/res/layout/fingerprint_v2_enroll_introduction.xml
+++ b/res/layout/fingerprint_v2_enroll_introduction.xml
@@ -24,6 +24,7 @@
<LinearLayout
style="@style/SudContentFrame"
+ android:id="@+id/enroll_intro_content_view"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:clipChildren="false"
diff --git a/res/xml/reset_dashboard_fragment.xml b/res/xml/reset_dashboard_fragment.xml
index 08852c9..cd1c671 100644
--- a/res/xml/reset_dashboard_fragment.xml
+++ b/res/xml/reset_dashboard_fragment.xml
@@ -30,11 +30,8 @@
android:fragment="com.android.settings.ResetNetwork" />
<!-- Bluetooth and WiFi reset -->
- <com.android.settingslib.RestrictedPreference
+ <com.android.settings.spa.preference.ComposePreference
android:key="network_reset_bluetooth_wifi_pref"
- android:title="@string/reset_bluetooth_wifi_title"
- settings:userRestriction="no_network_reset"
- settings:useAdminDisabledSummary="true"
settings:controller="com.android.settings.network.BluetoothWiFiResetPreferenceController" />
<!-- Reset app preferences -->
diff --git a/src/com/android/settings/biometrics/fingerprint/FingerprintEnrollEnrolling.java b/src/com/android/settings/biometrics/fingerprint/FingerprintEnrollEnrolling.java
index be2a948..063d55d 100644
--- a/src/com/android/settings/biometrics/fingerprint/FingerprintEnrollEnrolling.java
+++ b/src/com/android/settings/biometrics/fingerprint/FingerprintEnrollEnrolling.java
@@ -68,10 +68,13 @@
import com.android.settings.biometrics.BiometricEnrollSidecar;
import com.android.settings.biometrics.BiometricUtils;
import com.android.settings.biometrics.BiometricsEnrollEnrolling;
+import com.android.settings.biometrics.fingerprint.feature.SfpsEnrollmentFeature;
import com.android.settings.core.instrumentation.InstrumentedDialogFragment;
+import com.android.settings.overlay.FeatureFactory;
import com.android.settingslib.display.DisplayDensityUtils;
import com.airbnb.lottie.LottieAnimationView;
+import com.airbnb.lottie.LottieComposition;
import com.airbnb.lottie.LottieCompositionFactory;
import com.airbnb.lottie.LottieProperty;
import com.airbnb.lottie.model.KeyPath;
@@ -84,6 +87,7 @@
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.util.List;
+import java.util.function.Function;
/**
* Activity which handles the actual enrolling for fingerprint.
@@ -99,27 +103,22 @@
private static final int PROGRESS_BAR_MAX = 10000;
- private static final int STAGE_UNKNOWN = -1;
+ public static final int STAGE_UNKNOWN = -1;
private static final int STAGE_CENTER = 0;
private static final int STAGE_GUIDED = 1;
private static final int STAGE_FINGERTIP = 2;
private static final int STAGE_LEFT_EDGE = 3;
private static final int STAGE_RIGHT_EDGE = 4;
- @VisibleForTesting
- protected static final int SFPS_STAGE_NO_ANIMATION = 0;
+ public static final int SFPS_STAGE_NO_ANIMATION = 0;
- @VisibleForTesting
- protected static final int SFPS_STAGE_CENTER = 1;
+ public static final int SFPS_STAGE_CENTER = 1;
- @VisibleForTesting
- protected static final int SFPS_STAGE_FINGERTIP = 2;
+ public static final int SFPS_STAGE_FINGERTIP = 2;
- @VisibleForTesting
- protected static final int SFPS_STAGE_LEFT_EDGE = 3;
+ public static final int SFPS_STAGE_LEFT_EDGE = 3;
- @VisibleForTesting
- protected static final int SFPS_STAGE_RIGHT_EDGE = 4;
+ public static final int SFPS_STAGE_RIGHT_EDGE = 4;
@IntDef({STAGE_UNKNOWN, STAGE_CENTER, STAGE_GUIDED, STAGE_FINGERTIP, STAGE_LEFT_EDGE,
STAGE_RIGHT_EDGE})
@@ -196,6 +195,9 @@
private OrientationEventListener mOrientationEventListener;
private int mPreviousRotation = 0;
+ @NonNull
+ private SfpsEnrollmentFeature mSfpsEnrollmentFeature = new EmptySfpsEnrollmentFeature();
+
@VisibleForTesting
protected boolean shouldShowLottie() {
DisplayDensityUtils displayDensity = new DisplayDensityUtils(getApplicationContext());
@@ -244,6 +246,8 @@
setContentView(layout);
setDescriptionText(R.string.security_settings_udfps_enroll_start_message);
} else if (mCanAssumeSfps) {
+ mSfpsEnrollmentFeature = FeatureFactory.getFeatureFactory()
+ .getFingerprintFeatureProvider().getSfpsEnrollmentFeature();
setContentView(R.layout.sfps_enroll_enrolling);
setHelpAnimation();
} else {
@@ -599,7 +603,8 @@
}
switch (getCurrentSfpsStage()) {
case SFPS_STAGE_NO_ANIMATION:
- setHeaderText(R.string.security_settings_fingerprint_enroll_repeat_title);
+ setHeaderText(mSfpsEnrollmentFeature
+ .getFeaturedStageHeaderResource(SFPS_STAGE_NO_ANIMATION));
if (!mHaveShownSfpsNoAnimationLottie && mIllustrationLottie != null) {
mHaveShownSfpsNoAnimationLottie = true;
mIllustrationLottie.setContentDescription(
@@ -608,39 +613,48 @@
0
)
);
- configureEnrollmentStage(R.raw.sfps_lottie_no_animation);
+ configureEnrollmentStage(mSfpsEnrollmentFeature
+ .getSfpsEnrollLottiePerStage(SFPS_STAGE_NO_ANIMATION));
}
break;
case SFPS_STAGE_CENTER:
- setHeaderText(R.string.security_settings_sfps_enroll_finger_center_title);
+ setHeaderText(mSfpsEnrollmentFeature
+ .getFeaturedStageHeaderResource(SFPS_STAGE_CENTER));
if (!mHaveShownSfpsCenterLottie && mIllustrationLottie != null) {
mHaveShownSfpsCenterLottie = true;
- configureEnrollmentStage(R.raw.sfps_lottie_pad_center);
+ configureEnrollmentStage(mSfpsEnrollmentFeature
+ .getSfpsEnrollLottiePerStage(SFPS_STAGE_CENTER));
}
break;
case SFPS_STAGE_FINGERTIP:
- setHeaderText(R.string.security_settings_sfps_enroll_fingertip_title);
+ setHeaderText(mSfpsEnrollmentFeature
+ .getFeaturedStageHeaderResource(SFPS_STAGE_FINGERTIP));
if (!mHaveShownSfpsTipLottie && mIllustrationLottie != null) {
mHaveShownSfpsTipLottie = true;
- configureEnrollmentStage(R.raw.sfps_lottie_tip);
+ configureEnrollmentStage(mSfpsEnrollmentFeature
+ .getSfpsEnrollLottiePerStage(SFPS_STAGE_FINGERTIP));
}
break;
case SFPS_STAGE_LEFT_EDGE:
- setHeaderText(R.string.security_settings_sfps_enroll_left_edge_title);
+ setHeaderText(mSfpsEnrollmentFeature
+ .getFeaturedStageHeaderResource(SFPS_STAGE_LEFT_EDGE));
if (!mHaveShownSfpsLeftEdgeLottie && mIllustrationLottie != null) {
mHaveShownSfpsLeftEdgeLottie = true;
- configureEnrollmentStage(R.raw.sfps_lottie_left_edge);
+ configureEnrollmentStage(mSfpsEnrollmentFeature
+ .getSfpsEnrollLottiePerStage(SFPS_STAGE_LEFT_EDGE));
}
break;
case SFPS_STAGE_RIGHT_EDGE:
- setHeaderText(R.string.security_settings_sfps_enroll_right_edge_title);
+ setHeaderText(mSfpsEnrollmentFeature
+ .getFeaturedStageHeaderResource(SFPS_STAGE_RIGHT_EDGE));
if (!mHaveShownSfpsRightEdgeLottie && mIllustrationLottie != null) {
mHaveShownSfpsRightEdgeLottie = true;
- configureEnrollmentStage(R.raw.sfps_lottie_right_edge);
+ configureEnrollmentStage(mSfpsEnrollmentFeature
+ .getSfpsEnrollLottiePerStage(SFPS_STAGE_RIGHT_EDGE));
}
break;
@@ -665,11 +679,16 @@
setDescriptionText("");
}
LottieCompositionFactory.fromRawRes(this, lottie)
- .addListener((c) -> {
- mIllustrationLottie.setComposition(c);
- mIllustrationLottie.setVisibility(View.VISIBLE);
- mIllustrationLottie.playAnimation();
- });
+ .addListener((c) -> onLottieComposition(mIllustrationLottie, c));
+ }
+
+ private void onLottieComposition(LottieAnimationView view, LottieComposition composition) {
+ if (view == null || composition == null) {
+ return;
+ }
+ view.setComposition(composition);
+ view.setVisibility(View.VISIBLE);
+ view.playAnimation();
}
@EnrollStage
@@ -699,17 +718,8 @@
}
final int progressSteps = mSidecar.getEnrollmentSteps() - mSidecar.getEnrollmentRemaining();
- if (progressSteps < getStageThresholdSteps(0)) {
- return SFPS_STAGE_NO_ANIMATION;
- } else if (progressSteps < getStageThresholdSteps(1)) {
- return SFPS_STAGE_CENTER;
- } else if (progressSteps < getStageThresholdSteps(2)) {
- return SFPS_STAGE_FINGERTIP;
- } else if (progressSteps < getStageThresholdSteps(3)) {
- return SFPS_STAGE_LEFT_EDGE;
- } else {
- return SFPS_STAGE_RIGHT_EDGE;
- }
+ return mSfpsEnrollmentFeature
+ .getCurrentSfpsEnrollStage(progressSteps, this::getStageThresholdSteps);
}
private boolean isStageHalfCompleted() {
@@ -740,22 +750,31 @@
Log.w(TAG, "getStageThresholdSteps: Enrollment not started yet");
return 1;
}
- return Math.round(mSidecar.getEnrollmentSteps()
- * mFingerprintManager.getEnrollStageThreshold(index));
+ final float threshold = mCanAssumeSfps
+ ? mSfpsEnrollmentFeature.getEnrollStageThreshold(this, index)
+ : mFingerprintManager.getEnrollStageThreshold(index);
+ return Math.round(mSidecar.getEnrollmentSteps() * threshold);
}
@Override
public void onEnrollmentHelp(int helpMsgId, CharSequence helpString) {
- if (!TextUtils.isEmpty(helpString)) {
+ final CharSequence featuredString = mCanAssumeSfps
+ ? mSfpsEnrollmentFeature.getFeaturedVendorString(this, helpMsgId, helpString)
+ : helpString;
+
+ if (!TextUtils.isEmpty(featuredString)) {
if (!(mCanAssumeUdfps || mCanAssumeSfps)) {
mErrorText.removeCallbacks(mTouchAgainRunnable);
}
- showError(helpString);
+ showError(featuredString);
if (mUdfpsEnrollHelper != null) mUdfpsEnrollHelper.onEnrollmentHelp();
}
dismissTouchDialogIfSfps();
+ if (mCanAssumeSfps) {
+ mSfpsEnrollmentFeature.handleOnEnrollmentHelp(helpMsgId, featuredString, () -> this);
+ }
}
@Override
@@ -1170,4 +1189,28 @@
return SettingsEnums.DIALOG_FINGERPRINT_ICON_TOUCH;
}
}
-}
\ No newline at end of file
+
+ private static class EmptySfpsEnrollmentFeature implements SfpsEnrollmentFeature {
+ private final String exceptionStr = "Assume sfps but no SfpsEnrollmentFeature impl.";
+
+ @Override
+ public int getCurrentSfpsEnrollStage(int progressSteps, Function<Integer, Integer> mapper) {
+ throw new IllegalStateException(exceptionStr);
+ }
+
+ @Override
+ public int getFeaturedStageHeaderResource(int stage) {
+ throw new IllegalStateException(exceptionStr);
+ }
+
+ @Override
+ public int getSfpsEnrollLottiePerStage(int stage) {
+ throw new IllegalStateException(exceptionStr);
+ }
+
+ @Override
+ public float getEnrollStageThreshold(@NonNull Context context, int index) {
+ throw new IllegalStateException(exceptionStr);
+ }
+ }
+}
diff --git a/src/com/android/settings/biometrics/fingerprint/FingerprintEnrollFindSensor.java b/src/com/android/settings/biometrics/fingerprint/FingerprintEnrollFindSensor.java
index c207ec9..cfd57d7 100644
--- a/src/com/android/settings/biometrics/fingerprint/FingerprintEnrollFindSensor.java
+++ b/src/com/android/settings/biometrics/fingerprint/FingerprintEnrollFindSensor.java
@@ -16,6 +16,8 @@
package com.android.settings.biometrics.fingerprint;
+import static android.text.Layout.HYPHENATION_FREQUENCY_NORMAL;
+
import android.app.settings.SettingsEnums;
import android.content.Intent;
import android.content.res.Configuration;
@@ -98,6 +100,7 @@
.setTheme(com.google.android.setupdesign.R.style.SudGlifButton_Secondary)
.build()
);
+ getLayout().getHeaderTextView().setHyphenationFrequency(HYPHENATION_FREQUENCY_NORMAL);
listenOrientationEvent();
diff --git a/src/com/android/settings/biometrics/fingerprint/FingerprintFeatureProvider.java b/src/com/android/settings/biometrics/fingerprint/FingerprintFeatureProvider.java
new file mode 100644
index 0000000..906f95a
--- /dev/null
+++ b/src/com/android/settings/biometrics/fingerprint/FingerprintFeatureProvider.java
@@ -0,0 +1,27 @@
+/*
+ * 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.biometrics.fingerprint;
+
+import com.android.settings.biometrics.fingerprint.feature.SfpsEnrollmentFeature;
+
+public interface FingerprintFeatureProvider {
+ /**
+ * Gets the feature implementation of SFPS enrollment.
+ * @return the feature implementation
+ */
+ SfpsEnrollmentFeature getSfpsEnrollmentFeature();
+}
diff --git a/src/com/android/settings/biometrics/fingerprint/FingerprintFeatureProviderImpl.java b/src/com/android/settings/biometrics/fingerprint/FingerprintFeatureProviderImpl.java
new file mode 100644
index 0000000..9745ca3
--- /dev/null
+++ b/src/com/android/settings/biometrics/fingerprint/FingerprintFeatureProviderImpl.java
@@ -0,0 +1,36 @@
+/*
+ * 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.biometrics.fingerprint;
+
+import androidx.annotation.Nullable;
+
+import com.android.settings.biometrics.fingerprint.feature.SfpsEnrollmentFeature;
+import com.android.settings.biometrics.fingerprint.feature.SfpsEnrollmentFeatureImpl;
+
+public class FingerprintFeatureProviderImpl implements FingerprintFeatureProvider {
+
+ @Nullable
+ private SfpsEnrollmentFeature mSfpsEnrollmentFeatureImpl = null;
+
+ @Override
+ public SfpsEnrollmentFeature getSfpsEnrollmentFeature() {
+ if (mSfpsEnrollmentFeatureImpl == null) {
+ mSfpsEnrollmentFeatureImpl = new SfpsEnrollmentFeatureImpl();
+ }
+ return mSfpsEnrollmentFeatureImpl;
+ }
+}
diff --git a/src/com/android/settings/biometrics/fingerprint/feature/SfpsEnrollmentFeature.java b/src/com/android/settings/biometrics/fingerprint/feature/SfpsEnrollmentFeature.java
new file mode 100644
index 0000000..a1a18e5
--- /dev/null
+++ b/src/com/android/settings/biometrics/fingerprint/feature/SfpsEnrollmentFeature.java
@@ -0,0 +1,79 @@
+/*
+ * 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.biometrics.fingerprint.feature;
+
+import android.content.Context;
+
+import androidx.annotation.NonNull;
+
+import com.android.settings.biometrics.fingerprint.FingerprintEnrollEnrolling;
+
+import java.util.function.Function;
+import java.util.function.Supplier;
+
+public interface SfpsEnrollmentFeature {
+
+ /**
+ * Gets current SFPS enrollment stage.
+ * @param progressSteps current step of enrollment
+ * @param mapper a mapper to map each stage to its threshold
+ * @return current enrollment stage
+ */
+ int getCurrentSfpsEnrollStage(int progressSteps, Function<Integer, Integer> mapper);
+
+ /**
+ * Gets the vendor string by feature.
+ * @param context Context
+ * @param id An integer identifying the error message
+ * @param msg A human-readable string that can be shown in UI
+ * @return A human-readable string of specific feature
+ */
+ default CharSequence getFeaturedVendorString(Context context, int id, CharSequence msg) {
+ return msg;
+ }
+
+ /**
+ * Gets the stage header string by feature.
+ * @param stage the specific stage
+ * @return the resource id of the header text of the specific stage
+ */
+ int getFeaturedStageHeaderResource(int stage);
+
+ /**
+ * Gets the enrollment lottie resource id per stage
+ * @param stage current enrollment stage
+ * @return enrollment lottie resource id
+ */
+ int getSfpsEnrollLottiePerStage(int stage);
+
+ /**
+ * Handles extra stuffs on receiving enrollment help.
+ * @param helpMsgId help message id
+ * @param helpString help message
+ * @param enrollingSupplier supplier of enrolling context
+ */
+ default void handleOnEnrollmentHelp(int helpMsgId, CharSequence helpString,
+ Supplier<FingerprintEnrollEnrolling> enrollingSupplier) {}
+
+ /**
+ * Gets the fingerprint enrollment threshold.
+ * @param context context
+ * @param index the enrollment stage index
+ * @return threshold
+ */
+ float getEnrollStageThreshold(@NonNull Context context, int index);
+}
diff --git a/src/com/android/settings/biometrics/fingerprint/feature/SfpsEnrollmentFeatureImpl.java b/src/com/android/settings/biometrics/fingerprint/feature/SfpsEnrollmentFeatureImpl.java
new file mode 100644
index 0000000..5a97537
--- /dev/null
+++ b/src/com/android/settings/biometrics/fingerprint/feature/SfpsEnrollmentFeatureImpl.java
@@ -0,0 +1,91 @@
+/*
+ * 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.biometrics.fingerprint.feature;
+
+import static com.android.settings.biometrics.fingerprint.FingerprintEnrollEnrolling.SFPS_STAGE_CENTER;
+import static com.android.settings.biometrics.fingerprint.FingerprintEnrollEnrolling.SFPS_STAGE_FINGERTIP;
+import static com.android.settings.biometrics.fingerprint.FingerprintEnrollEnrolling.SFPS_STAGE_LEFT_EDGE;
+import static com.android.settings.biometrics.fingerprint.FingerprintEnrollEnrolling.SFPS_STAGE_NO_ANIMATION;
+import static com.android.settings.biometrics.fingerprint.FingerprintEnrollEnrolling.SFPS_STAGE_RIGHT_EDGE;
+import static com.android.settings.biometrics.fingerprint.FingerprintEnrollEnrolling.STAGE_UNKNOWN;
+
+import android.content.Context;
+import android.hardware.fingerprint.FingerprintManager;
+
+import androidx.annotation.NonNull;
+import androidx.annotation.Nullable;
+
+import com.android.settings.R;
+
+import java.util.function.Function;
+
+public class SfpsEnrollmentFeatureImpl implements SfpsEnrollmentFeature {
+
+ @Nullable
+ private FingerprintManager mFingerprintManager = null;
+
+ @Override
+ public int getCurrentSfpsEnrollStage(int progressSteps, Function<Integer, Integer> mapper) {
+ if (mapper == null) {
+ return STAGE_UNKNOWN;
+ }
+ if (progressSteps < mapper.apply(0)) {
+ return SFPS_STAGE_NO_ANIMATION;
+ } else if (progressSteps < mapper.apply(1)) {
+ return SFPS_STAGE_CENTER;
+ } else if (progressSteps < mapper.apply(2)) {
+ return SFPS_STAGE_FINGERTIP;
+ } else if (progressSteps < mapper.apply(3)) {
+ return SFPS_STAGE_LEFT_EDGE;
+ } else {
+ return SFPS_STAGE_RIGHT_EDGE;
+ }
+ }
+
+ @Override
+ public int getFeaturedStageHeaderResource(int stage) {
+ return switch (stage) {
+ case SFPS_STAGE_NO_ANIMATION
+ -> R.string.security_settings_fingerprint_enroll_repeat_title;
+ case SFPS_STAGE_CENTER -> R.string.security_settings_sfps_enroll_finger_center_title;
+ case SFPS_STAGE_FINGERTIP -> R.string.security_settings_sfps_enroll_fingertip_title;
+ case SFPS_STAGE_LEFT_EDGE -> R.string.security_settings_sfps_enroll_left_edge_title;
+ case SFPS_STAGE_RIGHT_EDGE -> R.string.security_settings_sfps_enroll_right_edge_title;
+ default -> throw new IllegalArgumentException("Invalid stage: " + stage);
+ };
+ }
+
+ @Override
+ public int getSfpsEnrollLottiePerStage(int stage) {
+ return switch (stage) {
+ case SFPS_STAGE_NO_ANIMATION -> R.raw.sfps_lottie_no_animation;
+ case SFPS_STAGE_CENTER -> R.raw.sfps_lottie_pad_center;
+ case SFPS_STAGE_FINGERTIP -> R.raw.sfps_lottie_tip;
+ case SFPS_STAGE_LEFT_EDGE -> R.raw.sfps_lottie_left_edge;
+ case SFPS_STAGE_RIGHT_EDGE -> R.raw.sfps_lottie_right_edge;
+ default -> throw new IllegalArgumentException("Invalid stage: " + stage);
+ };
+ }
+
+ @Override
+ public float getEnrollStageThreshold(@NonNull Context context, int index) {
+ if (mFingerprintManager == null) {
+ mFingerprintManager = context.getSystemService(FingerprintManager.class);
+ }
+ return mFingerprintManager.getEnrollStageThreshold(index);
+ }
+}
diff --git a/src/com/android/settings/biometrics/fingerprint2/ui/enrollment/fragment/FingerprintEnrollFindSensorV2Fragment.kt b/src/com/android/settings/biometrics/fingerprint2/ui/enrollment/fragment/FingerprintEnrollFindSensorV2Fragment.kt
index dcdcccf..0afa613 100644
--- a/src/com/android/settings/biometrics/fingerprint2/ui/enrollment/fragment/FingerprintEnrollFindSensorV2Fragment.kt
+++ b/src/com/android/settings/biometrics/fingerprint2/ui/enrollment/fragment/FingerprintEnrollFindSensorV2Fragment.kt
@@ -34,7 +34,6 @@
import com.google.android.setupcompat.template.FooterBarMixin
import com.google.android.setupcompat.template.FooterButton
import com.google.android.setupdesign.GlifLayout
-import kotlinx.coroutines.flow.collect
import kotlinx.coroutines.launch
private const val TAG = "FingerprintEnrollFindSensorV2Fragment"
@@ -94,12 +93,12 @@
// Set up lottie or animation
lifecycleScope.launch {
- viewModel.showSfpsLottie.collect { (isFolded, rotation) ->
+ viewModel.sfpsLottieInfo.collect { (isFolded, rotation) ->
setupLottie(view, getSfpsIllustrationLottieAnimation(isFolded, rotation))
}
}
lifecycleScope.launch {
- viewModel.showUdfpsLottie.collect { isAccessibilityEnabled ->
+ viewModel.udfpsLottieInfo.collect { isAccessibilityEnabled ->
val lottieAnimation =
if (isAccessibilityEnabled) R.raw.udfps_edu_a11y_lottie else R.raw.udfps_edu_lottie
setupLottie(view, lottieAnimation) { viewModel.proceedToEnrolling() }
diff --git a/src/com/android/settings/biometrics/fingerprint2/ui/enrollment/fragment/FingerprintEnrollIntroV2Fragment.kt b/src/com/android/settings/biometrics/fingerprint2/ui/enrollment/fragment/FingerprintEnrollIntroV2Fragment.kt
index 898b158..4024692 100644
--- a/src/com/android/settings/biometrics/fingerprint2/ui/enrollment/fragment/FingerprintEnrollIntroV2Fragment.kt
+++ b/src/com/android/settings/biometrics/fingerprint2/ui/enrollment/fragment/FingerprintEnrollIntroV2Fragment.kt
@@ -186,6 +186,9 @@
return view
}
+ /**
+ * TODO (b/305269201): This link isn't displaying for screenshot tests.
+ */
private fun setFooterLink(view: View) {
val footerLink: TextView = view.requireViewById(R.id.footer_learn_more)
footerLink.movementMethod = LinkMovementMethod.getInstance()
diff --git a/src/com/android/settings/biometrics/fingerprint2/ui/enrollment/viewmodel/FingerprintEnrollFindSensorViewModel.kt b/src/com/android/settings/biometrics/fingerprint2/ui/enrollment/viewmodel/FingerprintEnrollFindSensorViewModel.kt
index 17f8132..90aefc8 100644
--- a/src/com/android/settings/biometrics/fingerprint2/ui/enrollment/viewmodel/FingerprintEnrollFindSensorViewModel.kt
+++ b/src/com/android/settings/biometrics/fingerprint2/ui/enrollment/viewmodel/FingerprintEnrollFindSensorViewModel.kt
@@ -26,13 +26,12 @@
import kotlinx.coroutines.flow.Flow
import kotlinx.coroutines.flow.MutableStateFlow
import kotlinx.coroutines.flow.SharingStarted
-import kotlinx.coroutines.flow.collect
import kotlinx.coroutines.flow.combine
import kotlinx.coroutines.flow.combineTransform
+import kotlinx.coroutines.flow.filter
import kotlinx.coroutines.flow.filterNotNull
import kotlinx.coroutines.flow.map
import kotlinx.coroutines.flow.shareIn
-import kotlinx.coroutines.flow.transform
import kotlinx.coroutines.flow.update
import kotlinx.coroutines.launch
@@ -47,41 +46,43 @@
) : ViewModel() {
/** Represents the stream of sensor type. */
val sensorType: Flow<FingerprintSensorType> =
- fingerprintEnrollViewModel.sensorType
- .filterWhenEducationIsShown()
- .shareIn(viewModelScope, SharingStarted.WhileSubscribed(), 1)
+ fingerprintEnrollViewModel.sensorType.shareIn(
+ viewModelScope,
+ SharingStarted.WhileSubscribed(),
+ 1
+ )
private val _isUdfps: Flow<Boolean> =
sensorType.map {
it == FingerprintSensorType.UDFPS_OPTICAL || it == FingerprintSensorType.UDFPS_ULTRASONIC
}
private val _isSfps: Flow<Boolean> = sensorType.map { it == FingerprintSensorType.POWER_BUTTON }
- private val _isRearSfps: Flow<Boolean> =
- combineTransform(_isSfps, _isUdfps) { v1, v2 -> !v1 && !v2 }
+ private val _isRearSfps: Flow<Boolean> = sensorType.map { it == FingerprintSensorType.REAR }
/** Represents the stream of showing primary button. */
- val showPrimaryButton: Flow<Boolean> = _isUdfps.transform { if (it) emit(true) }
+ val showPrimaryButton: Flow<Boolean> = _isUdfps.filter { it }
- /** Represents the stream of showing sfps lottie, Pair(isFolded, rotation). */
- val showSfpsLottie: Flow<Pair<Boolean, Int>> =
+ private val _showSfpsLottie = _isSfps.filter { it }
+ /** Represents the stream of showing sfps lottie and the information Pair(isFolded, rotation). */
+ val sfpsLottieInfo: Flow<Pair<Boolean, Int>> =
combineTransform(
- _isSfps,
+ _showSfpsLottie,
foldStateViewModel.isFolded,
orientationStateViewModel.rotation,
- ) { isSfps, isFolded, rotation ->
- if (isSfps) emit(Pair(isFolded, rotation))
+ ) { _, isFolded, rotation ->
+ emit(Pair(isFolded, rotation))
}
- /** Represents the stream of showing udfps lottie. */
- val showUdfpsLottie: Flow<Boolean> =
- combineTransform(
- _isUdfps,
- accessibilityViewModel.isAccessibilityEnabled,
- ) { isUdfps, isAccessibilityEnabled ->
- if (isUdfps) emit(isAccessibilityEnabled)
+ private val _showUdfpsLottie = _isUdfps.filter { it }
+ /** Represents the stream of showing udfps lottie and whether accessibility is enabled. */
+ val udfpsLottieInfo: Flow<Boolean> =
+ _showUdfpsLottie.combine(accessibilityViewModel.isAccessibilityEnabled) {
+ _,
+ isAccessibilityEnabled ->
+ isAccessibilityEnabled
}
/** Represents the stream of showing rfps animation. */
- val showRfpsAnimation: Flow<Boolean> = _isRearSfps.transform { if (it) emit(true) }
+ val showRfpsAnimation: Flow<Boolean> = _isRearSfps.filter { it }
private val _showErrorDialog: MutableStateFlow<Pair<Int, Boolean>?> = MutableStateFlow(null)
/** Represents the stream of showing error dialog. */
@@ -145,16 +146,6 @@
navigationViewModel.nextStep()
}
- // TODO: If we decide to remove previous fragment from activity, then we don't need to check
- // whether education is shown for the flows that are subscribed by
- // [FingerprintEnrollFindSensorV2Fragment].
- private fun <T> Flow<T>.filterWhenEducationIsShown() =
- combineTransform(navigationViewModel.navigationViewModel) { value, navigationViewModel ->
- if (navigationViewModel.currStep == Education) {
- emit(value)
- }
- }
-
class FingerprintEnrollFindSensorViewModelFactory(
private val navigationViewModel: FingerprintEnrollNavigationViewModel,
private val fingerprintEnrollViewModel: FingerprintEnrollViewModel,
diff --git a/src/com/android/settings/datausage/ChartDataUsagePreferenceController.kt b/src/com/android/settings/datausage/ChartDataUsagePreferenceController.kt
index 49235b5..5149af0 100644
--- a/src/com/android/settings/datausage/ChartDataUsagePreferenceController.kt
+++ b/src/com/android/settings/datausage/ChartDataUsagePreferenceController.kt
@@ -26,6 +26,7 @@
import androidx.preference.PreferenceScreen
import com.android.settings.core.BasePreferenceController
import com.android.settings.datausage.lib.INetworkCycleDataRepository
+import com.android.settings.datausage.lib.NetworkCycleChartData
import com.android.settings.datausage.lib.NetworkCycleDataRepository
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.launch
@@ -72,6 +73,7 @@
fun update(startTime: Long, endTime: Long) {
preference.setTime(startTime, endTime)
+ preference.setNetworkCycleData(NetworkCycleChartData.AllZero)
lifecycleScope.launch {
val chartData = withContext(Dispatchers.Default) {
repository.queryChartData(startTime, endTime)
diff --git a/src/com/android/settings/datausage/lib/AppDataUsageDetailsRepository.kt b/src/com/android/settings/datausage/lib/AppDataUsageDetailsRepository.kt
index 94801ef..cd3372f 100644
--- a/src/com/android/settings/datausage/lib/AppDataUsageDetailsRepository.kt
+++ b/src/com/android/settings/datausage/lib/AppDataUsageDetailsRepository.kt
@@ -20,11 +20,8 @@
import android.content.Context
import android.net.NetworkTemplate
import android.util.Range
-import androidx.annotation.VisibleForTesting
import com.android.settings.datausage.lib.AppDataUsageRepository.Companion.withSdkSandboxUids
-import kotlinx.coroutines.async
-import kotlinx.coroutines.awaitAll
-import kotlinx.coroutines.coroutineScope
+import com.android.settingslib.spa.framework.util.asyncMap
interface IAppDataUsageDetailsRepository {
suspend fun queryDetailsForCycles(): List<NetworkUsageDetailsData>
@@ -37,32 +34,24 @@
uids: List<Int>,
private val networkCycleDataRepository: INetworkCycleDataRepository =
NetworkCycleDataRepository(context, template),
+ private val networkStatsRepository: NetworkStatsRepository =
+ NetworkStatsRepository(context, template),
) : IAppDataUsageDetailsRepository {
private val withSdkSandboxUids = withSdkSandboxUids(uids)
- private val networkStatsRepository = NetworkStatsRepository(context, template)
- override suspend fun queryDetailsForCycles(): List<NetworkUsageDetailsData> = coroutineScope {
- getCycles().map {
- async {
- queryDetails(it)
- }
- }.awaitAll().filter { it.totalUsage > 0 }
- }
+ override suspend fun queryDetailsForCycles(): List<NetworkUsageDetailsData> =
+ getCycles().asyncMap { queryDetails(it) }.filter { it.totalUsage > 0 }
private fun getCycles(): List<Range<Long>> =
cycles?.zipWithNext { endTime, startTime -> Range(startTime, endTime) }
?: networkCycleDataRepository.getCycles()
private fun queryDetails(range: Range<Long>): NetworkUsageDetailsData {
- var totalUsage = 0L
- var foregroundUsage = 0L
- for (uid in withSdkSandboxUids) {
- val usage = getUsage(range, uid, NetworkStats.Bucket.STATE_ALL)
- if (usage > 0L) {
- totalUsage += usage
- foregroundUsage += getUsage(range, uid, NetworkStats.Bucket.STATE_FOREGROUND)
- }
- }
+ val buckets = networkStatsRepository.queryBuckets(range.lower, range.upper)
+ .filter { it.uid in withSdkSandboxUids }
+ val totalUsage = buckets.sumOf { it.bytes }
+ val foregroundUsage =
+ buckets.filter { it.state == NetworkStats.Bucket.STATE_FOREGROUND }.sumOf { it.bytes }
return NetworkUsageDetailsData(
range = range,
totalUsage = totalUsage,
@@ -70,8 +59,4 @@
backgroundUsage = totalUsage - foregroundUsage,
)
}
-
- @VisibleForTesting
- fun getUsage(range: Range<Long>, uid: Int, state: Int): Long =
- networkStatsRepository.queryAggregateForUid(range, uid, state)?.usage ?: 0
}
diff --git a/src/com/android/settings/datausage/lib/AppDataUsageRepository.kt b/src/com/android/settings/datausage/lib/AppDataUsageRepository.kt
index 930737f..1844a7a 100644
--- a/src/com/android/settings/datausage/lib/AppDataUsageRepository.kt
+++ b/src/com/android/settings/datausage/lib/AppDataUsageRepository.kt
@@ -41,7 +41,7 @@
private val networkStatsRepository = NetworkStatsRepository(context, template)
fun getAppPercent(carrierId: Int?, startTime: Long, endTime: Long): List<Pair<AppItem, Int>> {
- val buckets = networkStatsRepository.querySummary(startTime, endTime)
+ val buckets = networkStatsRepository.queryBuckets(startTime, endTime)
return getAppPercent(carrierId, buckets)
}
diff --git a/src/com/android/settings/datausage/lib/AppDataUsageSummaryRepository.kt b/src/com/android/settings/datausage/lib/AppDataUsageSummaryRepository.kt
index 5579de0..b723e27 100644
--- a/src/com/android/settings/datausage/lib/AppDataUsageSummaryRepository.kt
+++ b/src/com/android/settings/datausage/lib/AppDataUsageSummaryRepository.kt
@@ -20,9 +20,7 @@
import android.net.NetworkTemplate
import com.android.settings.datausage.lib.AppDataUsageRepository.Companion.withSdkSandboxUids
import com.android.settings.datausage.lib.NetworkStatsRepository.Companion.AllTimeRange
-import kotlinx.coroutines.async
-import kotlinx.coroutines.awaitAll
-import kotlinx.coroutines.coroutineScope
+import com.android.settingslib.spa.framework.util.asyncMap
interface IAppDataUsageSummaryRepository {
suspend fun querySummary(uid: Int): NetworkUsageData?
@@ -35,11 +33,8 @@
NetworkStatsRepository(context, template),
) : IAppDataUsageSummaryRepository {
- override suspend fun querySummary(uid: Int): NetworkUsageData? = coroutineScope {
- withSdkSandboxUids(listOf(uid)).map { uid ->
- async {
- networkStatsRepository.queryAggregateForUid(range = AllTimeRange, uid = uid)
- }
- }.awaitAll().filterNotNull().aggregate()
- }
+ override suspend fun querySummary(uid: Int): NetworkUsageData? =
+ withSdkSandboxUids(listOf(uid)).asyncMap {
+ networkStatsRepository.queryAggregateForUid(range = AllTimeRange, uid = it)
+ }.filterNotNull().aggregate()
}
diff --git a/src/com/android/settings/datausage/lib/NetworkCycleChartData.kt b/src/com/android/settings/datausage/lib/NetworkCycleChartData.kt
index fd3c504..4e73190 100644
--- a/src/com/android/settings/datausage/lib/NetworkCycleChartData.kt
+++ b/src/com/android/settings/datausage/lib/NetworkCycleChartData.kt
@@ -26,6 +26,11 @@
val dailyUsage: List<NetworkUsageData>,
) {
companion object {
+ val AllZero = NetworkCycleChartData(
+ total = NetworkUsageData.AllZero,
+ dailyUsage = emptyList(),
+ )
+
val BUCKET_DURATION = 1.days
}
}
diff --git a/src/com/android/settings/datausage/lib/NetworkStatsRepository.kt b/src/com/android/settings/datausage/lib/NetworkStatsRepository.kt
index 22f9dd0..f2e18f2 100644
--- a/src/com/android/settings/datausage/lib/NetworkStatsRepository.kt
+++ b/src/com/android/settings/datausage/lib/NetworkStatsRepository.kt
@@ -54,7 +54,7 @@
0
}
- fun querySummary(startTime: Long, endTime: Long): List<Bucket> = try {
+ fun queryBuckets(startTime: Long, endTime: Long): List<Bucket> = try {
networkStatsManager.querySummary(template, startTime, endTime).convertToBuckets()
} catch (e: Exception) {
Log.e(TAG, "Exception querySummary", e)
@@ -69,13 +69,14 @@
data class Bucket(
val uid: Int,
val bytes: Long,
+ val state: Int = NetworkStats.Bucket.STATE_ALL,
)
private fun NetworkStats.convertToBuckets(): List<Bucket> = use {
val buckets = mutableListOf<Bucket>()
val bucket = NetworkStats.Bucket()
while (getNextBucket(bucket)) {
- buckets += Bucket(uid = bucket.uid, bytes = bucket.bytes)
+ buckets += Bucket(uid = bucket.uid, bytes = bucket.bytes, state = bucket.state)
}
buckets
}
diff --git a/src/com/android/settings/datausage/lib/NetworkUsageData.kt b/src/com/android/settings/datausage/lib/NetworkUsageData.kt
index 93cde5f..f9d83d5 100644
--- a/src/com/android/settings/datausage/lib/NetworkUsageData.kt
+++ b/src/com/android/settings/datausage/lib/NetworkUsageData.kt
@@ -43,8 +43,14 @@
fun getDataUsedString(context: Context): String =
context.getString(R.string.data_used_template, formatUsage(context))
- private companion object {
- const val DATE_FORMAT = DateUtils.FORMAT_SHOW_DATE or DateUtils.FORMAT_ABBREV_MONTH
+ companion object {
+ val AllZero = NetworkUsageData(
+ startTime = 0L,
+ endTime = 0L,
+ usage = 0L,
+ )
+
+ private const val DATE_FORMAT = DateUtils.FORMAT_SHOW_DATE or DateUtils.FORMAT_ABBREV_MONTH
}
}
diff --git a/src/com/android/settings/network/BluetoothWiFiResetPreferenceController.java b/src/com/android/settings/network/BluetoothWiFiResetPreferenceController.java
deleted file mode 100644
index f0f5d73..0000000
--- a/src/com/android/settings/network/BluetoothWiFiResetPreferenceController.java
+++ /dev/null
@@ -1,188 +0,0 @@
-/*
- * Copyright (C) 2022 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.network;
-
-import android.app.ProgressDialog;
-import android.app.settings.SettingsEnums;
-import android.content.Context;
-import android.content.DialogInterface;
-import android.os.Looper;
-import android.text.TextUtils;
-import android.util.Log;
-import android.widget.Toast;
-
-import androidx.annotation.VisibleForTesting;
-import androidx.appcompat.app.AlertDialog;
-import androidx.preference.Preference;
-
-import com.android.settings.R;
-import com.android.settings.ResetNetworkRequest;
-import com.android.settings.core.BasePreferenceController;
-import com.android.settings.overlay.FeatureFactory;
-import com.android.settingslib.core.instrumentation.MetricsFeatureProvider;
-
-import java.util.concurrent.ExecutorService;
-import java.util.concurrent.Executors;
-import java.util.concurrent.atomic.AtomicReference;
-
-/**
- * This is to show a preference regarding resetting Bluetooth and Wi-Fi.
- */
-public class BluetoothWiFiResetPreferenceController extends BasePreferenceController
- implements DialogInterface.OnClickListener, DialogInterface.OnDismissListener {
-
- private static final String TAG = "BtWiFiResetPreferenceController";
-
- private final NetworkResetRestrictionChecker mRestrictionChecker;
-
- private DialogInterface mResetDialog;
- private ProgressDialog mProgressDialog;
- private ExecutorService mExecutorService;
-
- /**
- * Constructer.
- * @param context Context
- * @param preferenceKey is the key for Preference
- */
- public BluetoothWiFiResetPreferenceController(Context context, String preferenceKey) {
- super(context, preferenceKey);
-
- // restriction check
- mRestrictionChecker = new NetworkResetRestrictionChecker(context);
- }
-
- @Override
- public int getAvailabilityStatus() {
- return mRestrictionChecker.hasUserRestriction() ?
- CONDITIONALLY_UNAVAILABLE : AVAILABLE;
- }
-
- @Override
- public boolean handlePreferenceTreeClick(Preference preference) {
- if (!TextUtils.equals(preference.getKey(), getPreferenceKey())) {
- return false;
- }
- buildResetDialog(preference);
- return true;
- }
-
- /**
- * This is a pop-up dialog showing detail of this reset option.
- */
- void buildResetDialog(Preference preference) {
- if (mResetDialog != null) {
- return;
- }
- mResetDialog = new AlertDialog.Builder(mContext)
- .setTitle(R.string.reset_bluetooth_wifi_title)
- .setMessage(R.string.reset_bluetooth_wifi_desc)
- .setPositiveButton(R.string.reset_bluetooth_wifi_button_text, this)
- .setNegativeButton(R.string.cancel, null /* OnClickListener */)
- .setOnDismissListener(this)
- .show();
- }
-
- public void onDismiss(DialogInterface dialog) {
- if (mResetDialog == dialog) {
- mResetDialog = null;
- }
- }
-
- /**
- * User pressed confirmation button, for starting reset operation.
- */
- public void onClick(DialogInterface dialog, int which) {
- if (mResetDialog != dialog) {
- return;
- }
-
- // User confirm the reset operation
- MetricsFeatureProvider provider = FeatureFactory.getFeatureFactory()
- .getMetricsFeatureProvider();
- provider.action(mContext, SettingsEnums.RESET_BLUETOOTH_WIFI_CONFIRM, true);
-
- // Non-cancelable progress dialog
- mProgressDialog = getProgressDialog(mContext);
- mProgressDialog.show();
-
- // Run reset in background thread
- mExecutorService = Executors.newSingleThreadExecutor();
- mExecutorService.execute(() -> {
- final AtomicReference<Exception> exceptionDuringReset =
- new AtomicReference<Exception>();
- try {
- resetOperation().run();
- } catch (Exception exception) {
- exceptionDuringReset.set(exception);
- }
- mContext.getMainExecutor().execute(() -> endOfReset(exceptionDuringReset.get()));
- });
- }
-
- @VisibleForTesting
- protected ProgressDialog getProgressDialog(Context context) {
- final ProgressDialog progressDialog = new ProgressDialog(context);
- progressDialog.setIndeterminate(true);
- progressDialog.setCancelable(false);
- progressDialog.setMessage(
- context.getString(R.string.main_clear_progress_text));
- return progressDialog;
- }
-
- @VisibleForTesting
- protected Runnable resetOperation() throws Exception {
- if (SubscriptionUtil.isSimHardwareVisible(mContext)) {
- return new ResetNetworkRequest(
- ResetNetworkRequest.RESET_WIFI_MANAGER |
- ResetNetworkRequest.RESET_WIFI_P2P_MANAGER |
- ResetNetworkRequest.RESET_BLUETOOTH_MANAGER)
- .toResetNetworkOperationBuilder(mContext, Looper.getMainLooper())
- .build();
- }
-
- /**
- * For device without SIMs visible to the user
- */
- return new ResetNetworkRequest(
- ResetNetworkRequest.RESET_CONNECTIVITY_MANAGER |
- ResetNetworkRequest.RESET_VPN_MANAGER |
- ResetNetworkRequest.RESET_WIFI_MANAGER |
- ResetNetworkRequest.RESET_WIFI_P2P_MANAGER |
- ResetNetworkRequest.RESET_BLUETOOTH_MANAGER)
- .toResetNetworkOperationBuilder(mContext, Looper.getMainLooper())
- .resetTelephonyAndNetworkPolicyManager(ResetNetworkRequest.ALL_SUBSCRIPTION_ID)
- .build();
- }
-
- @VisibleForTesting
- protected void endOfReset(Exception exceptionDuringReset) {
- if (mExecutorService != null) {
- mExecutorService.shutdown();
- mExecutorService = null;
- }
- if (mProgressDialog != null) {
- mProgressDialog.dismiss();
- mProgressDialog = null;
- }
- if (exceptionDuringReset == null) {
- Toast.makeText(mContext, R.string.reset_bluetooth_wifi_complete_toast,
- Toast.LENGTH_SHORT).show();
- } else {
- Log.e(TAG, "Exception during reset", exceptionDuringReset);
- }
- }
-}
diff --git a/src/com/android/settings/network/BluetoothWiFiResetPreferenceController.kt b/src/com/android/settings/network/BluetoothWiFiResetPreferenceController.kt
new file mode 100644
index 0000000..2047ed9
--- /dev/null
+++ b/src/com/android/settings/network/BluetoothWiFiResetPreferenceController.kt
@@ -0,0 +1,126 @@
+/*
+ * 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.network
+
+import android.app.settings.SettingsEnums
+import android.content.Context
+import android.os.Looper
+import android.os.UserManager
+import android.util.Log
+import android.widget.Toast
+import androidx.annotation.VisibleForTesting
+import androidx.compose.material3.Text
+import androidx.compose.runtime.Composable
+import androidx.compose.runtime.rememberCoroutineScope
+import androidx.compose.ui.res.stringResource
+import com.android.settings.R
+import com.android.settings.ResetNetworkRequest
+import com.android.settings.overlay.FeatureFactory.Companion.featureFactory
+import com.android.settings.spa.preference.ComposePreferenceController
+import com.android.settingslib.spa.widget.dialog.AlertDialogButton
+import com.android.settingslib.spa.widget.dialog.rememberAlertDialogPresenter
+import com.android.settingslib.spa.widget.preference.PreferenceModel
+import com.android.settingslib.spaprivileged.model.enterprise.Restrictions
+import com.android.settingslib.spaprivileged.template.preference.RestrictedPreference
+import kotlinx.coroutines.CoroutineScope
+import kotlinx.coroutines.Dispatchers
+import kotlinx.coroutines.launch
+import kotlinx.coroutines.withContext
+
+/**
+ * This is to show a preference regarding resetting Bluetooth and Wi-Fi.
+ */
+class BluetoothWiFiResetPreferenceController(context: Context, preferenceKey: String) :
+ ComposePreferenceController(context, preferenceKey) {
+
+ private val restrictionChecker = NetworkResetRestrictionChecker(context)
+
+ override fun getAvailabilityStatus() =
+ if (restrictionChecker.hasUserRestriction()) CONDITIONALLY_UNAVAILABLE else AVAILABLE
+
+ @Composable
+ override fun Content() {
+ val coroutineScope = rememberCoroutineScope()
+ val dialogPresenter = rememberAlertDialogPresenter(
+ confirmButton = AlertDialogButton(
+ text = stringResource(R.string.reset_bluetooth_wifi_button_text),
+ ) { reset(coroutineScope) },
+ dismissButton = AlertDialogButton(text = stringResource(R.string.cancel)),
+ title = stringResource(R.string.reset_bluetooth_wifi_title),
+ ) {
+ Text(stringResource(R.string.reset_bluetooth_wifi_desc))
+ }
+
+ RestrictedPreference(
+ model = object : PreferenceModel {
+ override val title = stringResource(R.string.reset_bluetooth_wifi_title)
+ override val onClick = dialogPresenter::open
+ },
+ restrictions = Restrictions(keys = listOf(UserManager.DISALLOW_NETWORK_RESET)),
+ )
+ }
+
+ /**
+ * User pressed confirmation button, for starting reset operation.
+ */
+ private fun reset(coroutineScope: CoroutineScope) {
+ // User confirm the reset operation
+ featureFactory.metricsFeatureProvider
+ .action(mContext, SettingsEnums.RESET_BLUETOOTH_WIFI_CONFIRM, true)
+
+ // Run reset in background thread
+ coroutineScope.launch {
+ try {
+ withContext(Dispatchers.Default) {
+ resetOperation().run()
+ }
+ } catch (e: Exception) {
+ Log.e(TAG, "Exception during reset", e)
+ return@launch
+ }
+ Toast.makeText(
+ mContext,
+ R.string.reset_bluetooth_wifi_complete_toast,
+ Toast.LENGTH_SHORT,
+ ).show()
+ }
+ }
+
+ @VisibleForTesting
+ fun resetOperation(): Runnable = if (SubscriptionUtil.isSimHardwareVisible(mContext)) {
+ ResetNetworkRequest(
+ ResetNetworkRequest.RESET_WIFI_MANAGER or
+ ResetNetworkRequest.RESET_WIFI_P2P_MANAGER or
+ ResetNetworkRequest.RESET_BLUETOOTH_MANAGER
+ )
+ .toResetNetworkOperationBuilder(mContext, Looper.getMainLooper())
+ } else { // For device without SIMs visible to the user
+ ResetNetworkRequest(
+ ResetNetworkRequest.RESET_CONNECTIVITY_MANAGER or
+ ResetNetworkRequest.RESET_VPN_MANAGER or
+ ResetNetworkRequest.RESET_WIFI_MANAGER or
+ ResetNetworkRequest.RESET_WIFI_P2P_MANAGER or
+ ResetNetworkRequest.RESET_BLUETOOTH_MANAGER
+ )
+ .toResetNetworkOperationBuilder(mContext, Looper.getMainLooper())
+ .resetTelephonyAndNetworkPolicyManager(ResetNetworkRequest.ALL_SUBSCRIPTION_ID)
+ }.build()
+
+ private companion object {
+ private const val TAG = "BluetoothWiFiResetPref"
+ }
+}
diff --git a/src/com/android/settings/overlay/FeatureFactory.kt b/src/com/android/settings/overlay/FeatureFactory.kt
index 7645076..ac689d9 100644
--- a/src/com/android/settings/overlay/FeatureFactory.kt
+++ b/src/com/android/settings/overlay/FeatureFactory.kt
@@ -21,6 +21,7 @@
import com.android.settings.accounts.AccountFeatureProvider
import com.android.settings.applications.ApplicationFeatureProvider
import com.android.settings.biometrics.face.FaceFeatureProvider
+import com.android.settings.biometrics.fingerprint.FingerprintFeatureProvider
import com.android.settings.biometrics2.factory.BiometricsRepositoryProvider
import com.android.settings.bluetooth.BluetoothFeatureProvider
import com.android.settings.connecteddevice.fastpair.FastPairFeatureProvider
@@ -104,9 +105,17 @@
*/
abstract val bluetoothFeatureProvider: BluetoothFeatureProvider
+ /**
+ * Retrieves implementation for Face feature.
+ */
abstract val faceFeatureProvider: FaceFeatureProvider
/**
+ * Retrieves implementation for Fingerprint feature.
+ */
+ abstract val fingerprintFeatureProvider: FingerprintFeatureProvider
+
+ /**
* Gets implementation for Biometrics repository provider.
*/
abstract val biometricsRepositoryProvider: BiometricsRepositoryProvider
diff --git a/src/com/android/settings/overlay/FeatureFactoryImpl.kt b/src/com/android/settings/overlay/FeatureFactoryImpl.kt
index 0afe9f4..7f991b7 100644
--- a/src/com/android/settings/overlay/FeatureFactoryImpl.kt
+++ b/src/com/android/settings/overlay/FeatureFactoryImpl.kt
@@ -29,6 +29,8 @@
import com.android.settings.applications.ApplicationFeatureProviderImpl
import com.android.settings.biometrics.face.FaceFeatureProvider
import com.android.settings.biometrics.face.FaceFeatureProviderImpl
+import com.android.settings.biometrics.fingerprint.FingerprintFeatureProvider
+import com.android.settings.biometrics.fingerprint.FingerprintFeatureProviderImpl
import com.android.settings.biometrics2.factory.BiometricsRepositoryProviderImpl
import com.android.settings.bluetooth.BluetoothFeatureProvider
import com.android.settings.bluetooth.BluetoothFeatureProviderImpl
@@ -145,6 +147,10 @@
override val faceFeatureProvider: FaceFeatureProvider by lazy { FaceFeatureProviderImpl() }
+ override val fingerprintFeatureProvider: FingerprintFeatureProvider by lazy {
+ FingerprintFeatureProviderImpl()
+ }
+
override val biometricsRepositoryProvider by lazy { BiometricsRepositoryProviderImpl() }
override val wifiTrackerLibProvider: WifiTrackerLibProvider by lazy {
diff --git a/src/com/android/settings/spa/app/ResetAppPreferences.kt b/src/com/android/settings/spa/app/ResetAppPreferences.kt
index 12dd709..34c4145 100644
--- a/src/com/android/settings/spa/app/ResetAppPreferences.kt
+++ b/src/com/android/settings/spa/app/ResetAppPreferences.kt
@@ -16,7 +16,6 @@
package com.android.settings.spa.app
-import android.os.UserHandle
import android.os.UserManager
import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
@@ -37,10 +36,7 @@
RestrictedMenuItem(
text = stringResource(R.string.reset_app_preferences),
restrictions = remember {
- Restrictions(
- userId = UserHandle.myUserId(),
- keys = listOf(UserManager.DISALLOW_APPS_CONTROL),
- )
+ Restrictions(keys = listOf(UserManager.DISALLOW_APPS_CONTROL))
},
onClick = onClick,
)
diff --git a/src/com/android/settings/spa/preference/ComposePreference.kt b/src/com/android/settings/spa/preference/ComposePreference.kt
index 0c9abad..aec85a9 100644
--- a/src/com/android/settings/spa/preference/ComposePreference.kt
+++ b/src/com/android/settings/spa/preference/ComposePreference.kt
@@ -40,6 +40,8 @@
override fun onBindViewHolder(holder: PreferenceViewHolder) {
super.onBindViewHolder(holder)
+ holder.isDividerAllowedAbove = false
+ holder.isDividerAllowedBelow = false
(holder.itemView as ComposeView).apply {
setViewCompositionStrategy(ViewCompositionStrategy.DisposeOnViewTreeLifecycleDestroyed)
diff --git a/tests/robotests/AndroidManifest.xml b/tests/robotests/AndroidManifest.xml
index 22fce4f..95fbfa6 100644
--- a/tests/robotests/AndroidManifest.xml
+++ b/tests/robotests/AndroidManifest.xml
@@ -21,6 +21,8 @@
package="com.android.settings">
<uses-permission android:name="android.permission.READ_DEVICE_CONFIG" />
- <application/>
+ <application>
+ <activity android:name="com.android.settings.security.TestActivity" android:exported="true" />
+ </application>
</manifest>
diff --git a/tests/robotests/src/com/android/settings/biometrics/fingerprint/FingerprintEnrollFindSensorTest.java b/tests/robotests/src/com/android/settings/biometrics/fingerprint/FingerprintEnrollFindSensorTest.java
index 72f1ab8..adf76f4 100644
--- a/tests/robotests/src/com/android/settings/biometrics/fingerprint/FingerprintEnrollFindSensorTest.java
+++ b/tests/robotests/src/com/android/settings/biometrics/fingerprint/FingerprintEnrollFindSensorTest.java
@@ -19,6 +19,7 @@
import static android.hardware.fingerprint.FingerprintSensorProperties.TYPE_POWER_BUTTON;
import static android.hardware.fingerprint.FingerprintSensorProperties.TYPE_REAR;
import static android.hardware.fingerprint.FingerprintSensorProperties.TYPE_UDFPS_OPTICAL;
+import static android.text.Layout.HYPHENATION_FREQUENCY_NORMAL;
import static com.android.settings.biometrics.BiometricEnrollBase.RESULT_FINISHED;
import static com.android.settings.biometrics.BiometricEnrollBase.RESULT_SKIP;
@@ -49,6 +50,7 @@
import android.os.Bundle;
import android.os.CancellationSignal;
import android.view.View;
+import android.widget.TextView;
import androidx.fragment.app.Fragment;
@@ -62,6 +64,7 @@
import com.google.android.setupcompat.template.FooterBarMixin;
import com.google.android.setupcompat.template.FooterButton;
import com.google.android.setupdesign.GlifLayout;
+import com.google.android.setupdesign.template.HeaderMixin;
import org.junit.After;
import org.junit.Before;
@@ -568,6 +571,15 @@
assertThat(appliedThemes.contains("SetupWizardPartnerResource")).isTrue();
}
+ @Test
+ public void fingerprintEnrollFindSensor_setHyphenationFrequencyNormalOnHeader() {
+ setupActivity_onUdfpsDevice();
+ PartnerCustomizationLayout layout = mActivity.findViewById(R.id.setup_wizard_layout);
+ final TextView textView = layout.getMixin(HeaderMixin.class).getTextView();
+
+ assertThat(textView.getHyphenationFrequency()).isEqualTo(HYPHENATION_FREQUENCY_NORMAL);
+ }
+
private void triggerEnrollProgressAndError_onRearDevice() {
EnrollmentCallback enrollmentCallback = verifyAndCaptureEnrollmentCallback();
enrollmentCallback.onEnrollmentProgress(123);
diff --git a/tests/robotests/src/com/android/settings/network/BluetoothWiFiResetPreferenceControllerTest.java b/tests/robotests/src/com/android/settings/network/BluetoothWiFiResetPreferenceControllerTest.java
deleted file mode 100644
index 3aea4a8..0000000
--- a/tests/robotests/src/com/android/settings/network/BluetoothWiFiResetPreferenceControllerTest.java
+++ /dev/null
@@ -1,113 +0,0 @@
-/*
- * Copyright (C) 2022 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.network;
-
-import static com.google.common.truth.Truth.assertThat;
-import static org.mockito.Mockito.doReturn;
-import static org.mockito.Mockito.never;
-import static org.mockito.Mockito.spy;
-import static org.mockito.Mockito.verify;
-import static org.mockito.Mockito.when;
-
-import android.content.Context;
-import android.content.res.Resources;
-import android.net.ConnectivityManager;
-import android.os.UserManager;
-import android.telephony.TelephonyManager;
-
-import com.android.settings.R;
-
-import org.junit.Before;
-import org.junit.Test;
-import org.junit.runner.RunWith;
-import org.mockito.Mock;
-import org.mockito.MockitoAnnotations;
-import org.robolectric.RobolectricTestRunner;
-import org.robolectric.RuntimeEnvironment;
-import org.robolectric.shadows.ShadowToast;
-
-@RunWith(RobolectricTestRunner.class)
-public class BluetoothWiFiResetPreferenceControllerTest {
-
- private static final String PREFERENCE_KEY = "network_reset_bluetooth_wifi_pref";
-
- @Mock
- private UserManager mUserManager;
- @Mock
- private Resources mResources;
- @Mock
- private ConnectivityManager mConnectivityManager;
- @Mock
- private TelephonyManager mTelephonyManager;
-
- private Context mContext;
-
- @Before
- public void setUp() {
- MockitoAnnotations.initMocks(this);
- mContext = spy(RuntimeEnvironment.application);
- when(mContext.getResources()).thenReturn(mResources);
-
- mockService(Context.CONNECTIVITY_SERVICE, ConnectivityManager.class,
- mConnectivityManager);
- mockService(Context.TELEPHONY_SERVICE, TelephonyManager.class, mTelephonyManager);
- }
-
- @Test
- public void getAvailabilityStatus_returnAvailable_asOwnerUser() {
- mockService(Context.USER_SERVICE, UserManager.class, mUserManager);
- doReturn(true).when(mUserManager).isAdminUser();
-
- BluetoothWiFiResetPreferenceController target =
- new BluetoothWiFiResetPreferenceController(mContext, PREFERENCE_KEY);
-
- assertThat(target.getAvailabilityStatus()).isEqualTo(
- BluetoothWiFiResetPreferenceController.AVAILABLE);
- }
-
- @Test
- public void resetOperation_notResetConnectivity_onDeviceWithSimVisible() {
- mockService(Context.CONNECTIVITY_SERVICE, ConnectivityManager.class,
- mConnectivityManager);
- when(mResources.getBoolean(R.bool.config_show_sim_info)).thenReturn(true);
-
- BluetoothWiFiResetPreferenceController target =
- new BluetoothWiFiResetPreferenceController(mContext, PREFERENCE_KEY);
-
- try {
- target.resetOperation().run();
- } catch (Exception exception) {}
- verify(mConnectivityManager, never()).factoryReset();
- }
-
- @Test
- public void endOfReset_toastMessage_whenSuccess() {
- String testText = "reset_bluetooth_wifi_complete_toast";
- when(mResources.getString(R.string.reset_bluetooth_wifi_complete_toast)).thenReturn(testText);
- BluetoothWiFiResetPreferenceController target =
- new BluetoothWiFiResetPreferenceController(mContext, PREFERENCE_KEY);
-
- target.endOfReset(null);
-
- assertThat(ShadowToast.getTextOfLatestToast()).isEqualTo(testText);
- }
-
- private <T> void mockService(String serviceName, Class<T> serviceClass, T service) {
- when(mContext.getSystemServiceName(serviceClass)).thenReturn(serviceName);
- when(mContext.getSystemService(serviceName)).thenReturn(service);
- }
-}
diff --git a/tests/robotests/src/com/android/settings/security/MemtagPreferenceControllerTest.java b/tests/robotests/src/com/android/settings/security/MemtagPreferenceControllerTest.java
index e3fc3cc..7d2c6dd 100644
--- a/tests/robotests/src/com/android/settings/security/MemtagPreferenceControllerTest.java
+++ b/tests/robotests/src/com/android/settings/security/MemtagPreferenceControllerTest.java
@@ -24,11 +24,9 @@
import static com.google.common.truth.Truth.assertThat;
import android.content.Context;
-import android.os.Bundle;
-import androidx.fragment.app.FragmentActivity;
-import androidx.fragment.app.FragmentContainerView;
-import androidx.test.rule.ActivityTestRule;
+import androidx.test.core.app.ApplicationProvider;
+import androidx.test.ext.junit.rules.ActivityScenarioRule;
import com.android.settings.R;
import com.android.settings.testutils.shadow.ShadowDeviceConfig;
@@ -37,11 +35,11 @@
import com.android.settingslib.testutils.shadow.ShadowInteractionJankMonitor;
import org.junit.Before;
+import org.junit.Ignore;
import org.junit.Rule;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.robolectric.RobolectricTestRunner;
-import org.robolectric.RuntimeEnvironment;
import org.robolectric.annotation.Config;
import org.robolectric.shadows.ShadowSystemProperties;
@@ -57,8 +55,8 @@
private final String mMemtagSupportedProperty = "ro.arm64.memtag.bootctl_supported";
@Rule
- public ActivityTestRule<TestActivity> mActivityTestRule =
- new ActivityTestRule<>(TestActivity.class);
+ public ActivityScenarioRule<TestActivity> mActivityScenario =
+ new ActivityScenarioRule<>(TestActivity.class);
private MemtagPage mMemtagPage;
private MemtagPreferenceController mController;
@@ -70,17 +68,18 @@
@Before
public void setUp() {
ShadowSystemProperties.override(mMemtagSupportedProperty, "true");
-
- mContext = RuntimeEnvironment.application;
+ mContext = ApplicationProvider.getApplicationContext();
mMemtagPage = new MemtagPage();
- mActivity = mActivityTestRule.getActivity();
- mActivity
- .getSupportFragmentManager()
- .beginTransaction()
- .add(TestActivity.CONTAINER_VIEW_ID, mMemtagPage)
- .commit();
- mController = new MemtagPreferenceController(mContext, FRAGMENT_TAG);
- mController.setFragment(mMemtagPage);
+ System.out.println("Activity: " + mActivity);
+ mActivityScenario.getScenario().onActivity(a -> {
+ a.getSupportFragmentManager()
+ .beginTransaction()
+ .add(TestActivity.CONTAINER_VIEW_ID, mMemtagPage)
+ .commitNow();
+ mController = new MemtagPreferenceController(a, FRAGMENT_TAG);
+ mController.setFragment(mMemtagPage);
+ });
+ System.out.println("Committed");
}
@Test
@@ -135,6 +134,7 @@
}
@Test
+ @Ignore
public void setChecked_isChecked_doesNotShowDialog() {
ZygoteShadow.setSupportsMemoryTagging(false);
mController.setChecked(false);
@@ -142,6 +142,7 @@
}
@Test
+ @Ignore
public void setChecked_isUnchecked_doesNotShowDialog() {
ZygoteShadow.setSupportsMemoryTagging(true);
mController.setChecked(true);
@@ -155,18 +156,4 @@
mController.updateState(preference);
assertThat(preference.isDisabledByAdmin()).isTrue();
}
-
- private static final class TestActivity extends FragmentActivity {
-
- private static final int CONTAINER_VIEW_ID = 1234;
-
- @Override
- protected void onCreate(Bundle bundle) {
- super.onCreate(bundle);
-
- FragmentContainerView contentView = new FragmentContainerView(this);
- contentView.setId(CONTAINER_VIEW_ID);
- setContentView(contentView);
- }
- }
}
diff --git a/tests/robotests/src/com/android/settings/security/TestActivity.java b/tests/robotests/src/com/android/settings/security/TestActivity.java
new file mode 100644
index 0000000..70b5cf5
--- /dev/null
+++ b/tests/robotests/src/com/android/settings/security/TestActivity.java
@@ -0,0 +1,36 @@
+/*
+ * Copyright (C) 2022 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.security;
+
+import android.os.Bundle;
+
+import androidx.fragment.app.FragmentActivity;
+import androidx.fragment.app.FragmentContainerView;
+
+public final class TestActivity extends FragmentActivity {
+
+ static final int CONTAINER_VIEW_ID = 1234;
+
+ @Override
+ protected void onCreate(Bundle bundle) {
+ super.onCreate(bundle);
+
+ FragmentContainerView contentView = new FragmentContainerView(this);
+ contentView.setId(CONTAINER_VIEW_ID);
+ setContentView(contentView);
+ }
+}
diff --git a/tests/robotests/testutils/com/android/settings/testutils/FakeFeatureFactory.java b/tests/robotests/testutils/com/android/settings/testutils/FakeFeatureFactory.java
index 52a5f24..9156cae 100644
--- a/tests/robotests/testutils/com/android/settings/testutils/FakeFeatureFactory.java
+++ b/tests/robotests/testutils/com/android/settings/testutils/FakeFeatureFactory.java
@@ -24,6 +24,7 @@
import com.android.settings.accounts.AccountFeatureProvider;
import com.android.settings.applications.ApplicationFeatureProvider;
import com.android.settings.biometrics.face.FaceFeatureProvider;
+import com.android.settings.biometrics.fingerprint.FingerprintFeatureProvider;
import com.android.settings.biometrics2.factory.BiometricsRepositoryProvider;
import com.android.settings.bluetooth.BluetoothFeatureProvider;
import com.android.settings.connecteddevice.fastpair.FastPairFeatureProvider;
@@ -80,6 +81,7 @@
public final AccountFeatureProvider mAccountFeatureProvider;
public final BluetoothFeatureProvider mBluetoothFeatureProvider;
public final FaceFeatureProvider mFaceFeatureProvider;
+ public final FingerprintFeatureProvider mFingerprintFeatureProvider;
public final BiometricsRepositoryProvider mBiometricsRepositoryProvider;
public PanelFeatureProvider panelFeatureProvider;
@@ -132,6 +134,7 @@
panelFeatureProvider = mock(PanelFeatureProvider.class);
mBluetoothFeatureProvider = mock(BluetoothFeatureProvider.class);
mFaceFeatureProvider = mock(FaceFeatureProvider.class);
+ mFingerprintFeatureProvider = mock(FingerprintFeatureProvider.class);
mBiometricsRepositoryProvider = mock(BiometricsRepositoryProvider.class);
wifiTrackerLibProvider = mock(WifiTrackerLibProvider.class);
securitySettingsFeatureProvider = mock(SecuritySettingsFeatureProvider.class);
@@ -257,6 +260,11 @@
}
@Override
+ public FingerprintFeatureProvider getFingerprintFeatureProvider() {
+ return mFingerprintFeatureProvider;
+ }
+
+ @Override
public BiometricsRepositoryProvider getBiometricsRepositoryProvider() {
return mBiometricsRepositoryProvider;
}
diff --git a/tests/screenshot/Android.bp b/tests/screenshot/Android.bp
new file mode 100644
index 0000000..05ceef8
--- /dev/null
+++ b/tests/screenshot/Android.bp
@@ -0,0 +1,68 @@
+//
+// 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.
+
+android_app {
+ name: "ScreenshotTestStub",
+ defaults: [
+ "SettingsLibDefaults",
+ ],
+ platform_apis: true,
+ certificate: "platform",
+ privileged: true,
+ use_resource_processor: true,
+
+ static_libs: [
+ "Settings-core",
+ "androidx.fragment_fragment-testing",
+ "androidx.fragment_fragment",
+ ],
+
+ aaptflags: ["--extra-packages com.android.settings"],
+}
+
+android_test {
+ name: "SettingsScreenshotTests",
+ platform_apis: true,
+ certificate: "platform",
+ test_suites: ["device-tests"],
+ srcs: [
+ "src/**/*.kt",
+ ],
+ static_libs: [
+ "androidx.fragment_fragment-testing",
+ "androidx.fragment_fragment",
+ "androidx.test.rules",
+ "androidx.test.ext.junit",
+ "platform-screenshot-diff-core",
+ "Settings-testutils2",
+ "androidx.test.core",
+ "androidx.test.espresso.core",
+ "kotlinx-coroutines-android",
+ "androidx.lifecycle_lifecycle-runtime-testing",
+ "kotlinx_coroutines_test",
+ "Settings-core",
+ ],
+ libs: [
+ "android.test.runner",
+ "android.test.base",
+ "android.test.mock",
+ ],
+ compile_multilib: "both",
+ manifest: "AndroidManifest.xml",
+ test_config: "AndroidTest.xml",
+ use_embedded_native_libs: false,
+ asset_dirs: ["assets"],
+ instrumentation_for: "ScreenshotTestStub",
+}
diff --git a/tests/screenshot/AndroidManifest.xml b/tests/screenshot/AndroidManifest.xml
new file mode 100644
index 0000000..c9a426c
--- /dev/null
+++ b/tests/screenshot/AndroidManifest.xml
@@ -0,0 +1,47 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!--
+ 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.
+-->
+
+<manifest xmlns:android="http://schemas.android.com/apk/res/android"
+ xmlns:tools="http://schemas.android.com/tools"
+ package="com.android.settings.tests.screenshot"
+ >
+
+ <application>
+ <uses-library android:name="android.test.runner" />
+ <provider
+ android:name="com.android.settings.slices.SettingsSliceProvider"
+ android:authorities="com.android.settings.tests.screenshot.disabled"
+ android:enabled="false"
+ tools:node="remove"
+ tools:replace="android:authorities" />
+ </application>
+
+ <uses-permission android:name="android.permission.PACKAGE_USAGE_STATS" />
+ <uses-permission android:name="android.permission.WRITE_SECURE_SETTINGS" />
+ <uses-permission android:name="android.permission.READ_LOGS" />
+ <uses-permission android:name="android.permission.MOUNT_UNMOUNT_FILESYSTEMS" />
+ <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
+ <uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
+ <uses-permission android:name="android.permission.MANAGE_EXTERNAL_STORAGE" />
+ <uses-permission android:name="android.permission.READ_DEVICE_CONFIG" />
+
+ <instrumentation
+ android:name="androidx.test.runner.AndroidJUnitRunner"
+ android:label="Android Settings Screenshot tests"
+ android:targetPackage="com.android.settings.tests.screenshot" />
+
+</manifest>
diff --git a/tests/screenshot/AndroidTest.xml b/tests/screenshot/AndroidTest.xml
new file mode 100644
index 0000000..7496ffd
--- /dev/null
+++ b/tests/screenshot/AndroidTest.xml
@@ -0,0 +1,36 @@
+<!--
+ ~ 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.
+ -->
+
+<configuration description="Runs settings screendiff tests.">
+ <option name="test-suite-tag" value="apct-instrumentation" />
+ <option name="test-suite-tag" value="apct" />
+ <target_preparer class="com.android.tradefed.targetprep.DeviceSetup">
+ <option name="optimized-property-setting" value="true" />
+ </target_preparer>
+ <target_preparer class="com.android.tradefed.targetprep.suite.SuiteApkInstaller">
+ <option name="cleanup-apks" value="true" />
+ <option name="test-file-name" value="SettingsScreenshotTests.apk" />
+ </target_preparer>
+ <metrics_collector class="com.android.tradefed.device.metric.FilePullerLogCollector">
+ <option name="directory-keys"
+ value="/data/user/0/com.android.settings.tests.screenshot/" />
+ <option name="collect-on-run-ended-only" value="true" />
+ </metrics_collector>
+ <test class="com.android.tradefed.testtype.AndroidJUnitTest">
+ <option name="package" value="com.android.settings.tests.screenshot" />
+ <option name="runner" value="androidx.test.runner.AndroidJUnitRunner" />
+ </test>
+</configuration>
diff --git "a/tests/screenshot/assets/pixel_4a_\0505g\051/fp_enroll_intro.png" "b/tests/screenshot/assets/pixel_4a_\0505g\051/fp_enroll_intro.png"
new file mode 100644
index 0000000..1129250
--- /dev/null
+++ "b/tests/screenshot/assets/pixel_4a_\0505g\051/fp_enroll_intro.png"
Binary files differ
diff --git a/tests/screenshot/src/com/android/settings/tests/screenshot/BasicScreenshotTest.kt b/tests/screenshot/src/com/android/settings/tests/screenshot/BasicScreenshotTest.kt
new file mode 100644
index 0000000..3b3b170
--- /dev/null
+++ b/tests/screenshot/src/com/android/settings/tests/screenshot/BasicScreenshotTest.kt
@@ -0,0 +1,140 @@
+/*
+ * 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.tests.screenshot
+
+import android.content.Context
+import android.graphics.Bitmap
+import android.graphics.Canvas
+import android.graphics.Color
+import android.os.Bundle
+import android.view.View
+import androidx.fragment.app.testing.FragmentScenario
+import androidx.fragment.app.testing.launchFragmentInContainer
+import androidx.lifecycle.ViewModel
+import androidx.lifecycle.ViewModelProvider
+import androidx.test.core.app.ApplicationProvider
+import androidx.test.ext.junit.runners.AndroidJUnit4
+import androidx.test.platform.app.InstrumentationRegistry
+import com.android.settings.R
+import com.android.settings.biometrics.fingerprint2.ui.enrollment.fragment.FingerprintEnrollIntroV2Fragment
+import com.android.settings.biometrics.fingerprint2.ui.enrollment.viewmodel.FingerprintEnrollNavigationViewModel
+import com.android.settings.biometrics.fingerprint2.ui.enrollment.viewmodel.FingerprintEnrollViewModel
+import com.android.settings.biometrics.fingerprint2.ui.enrollment.viewmodel.FingerprintGatekeeperViewModel
+import com.android.settings.biometrics.fingerprint2.ui.enrollment.viewmodel.FingerprintScrollViewModel
+import com.android.settings.biometrics.fingerprint2.ui.enrollment.viewmodel.GatekeeperInfo
+import com.android.settings.testutils2.FakeFingerprintManagerInteractor
+import kotlinx.coroutines.test.StandardTestDispatcher
+import org.junit.Before
+import org.junit.Rule
+import org.junit.Test
+import org.junit.runner.RunWith
+import platform.test.screenshot.GoldenImagePathManager
+import platform.test.screenshot.ScreenshotTestRule
+import platform.test.screenshot.matchers.MSSIMMatcher
+
+@RunWith(AndroidJUnit4::class)
+class BasicScreenshotTest {
+ @Rule
+ @JvmField
+ var rule: ScreenshotTestRule =
+ ScreenshotTestRule(
+ GoldenImagePathManager(
+ InstrumentationRegistry.getInstrumentation().getContext(),
+ InstrumentationRegistry.getInstrumentation()
+ .getTargetContext()
+ .getFilesDir()
+ .getAbsolutePath() + "/settings_screenshots"
+ )
+ )
+
+ private var context: Context = ApplicationProvider.getApplicationContext()
+ private var interactor = FakeFingerprintManagerInteractor()
+
+ private val gatekeeperViewModel =
+ FingerprintGatekeeperViewModel(
+ GatekeeperInfo.GatekeeperPasswordInfo(byteArrayOf(1, 2, 3), 100L),
+ interactor
+ )
+
+ private val backgroundDispatcher = StandardTestDispatcher()
+ private lateinit var fragmentScenario: FragmentScenario<FingerprintEnrollIntroV2Fragment>
+
+ private val navigationViewModel =
+ FingerprintEnrollNavigationViewModel(
+ backgroundDispatcher,
+ interactor,
+ gatekeeperViewModel,
+ canSkipConfirm = true,
+ )
+ private var fingerprintViewModel = FingerprintEnrollViewModel(interactor, backgroundDispatcher)
+ private var fingerprintScrollViewModel = FingerprintScrollViewModel()
+
+ @Before
+ fun setup() {
+ val factory =
+ object : ViewModelProvider.Factory {
+ @Suppress("UNCHECKED_CAST")
+ override fun <T : ViewModel> create(
+ modelClass: Class<T>,
+ ): T {
+ return when (modelClass) {
+ FingerprintEnrollViewModel::class.java -> fingerprintViewModel
+ FingerprintScrollViewModel::class.java -> fingerprintScrollViewModel
+ FingerprintEnrollNavigationViewModel::class.java -> navigationViewModel
+ FingerprintGatekeeperViewModel::class.java -> gatekeeperViewModel
+ else -> null
+ }
+ as T
+ }
+ }
+
+ fragmentScenario =
+ launchFragmentInContainer(Bundle(), R.style.SudThemeGlif) {
+ FingerprintEnrollIntroV2Fragment(factory)
+ }
+ }
+
+ /** Renders a [view] into a [Bitmap]. */
+ private fun viewToBitmap(view: View): Bitmap {
+ val bitmap =
+ Bitmap.createBitmap(
+ view.measuredWidth,
+ view.measuredHeight,
+ Bitmap.Config.ARGB_8888,
+ )
+ val canvas = Canvas(bitmap)
+ view.draw(canvas)
+ return bitmap
+ }
+
+ @Test
+ fun testEnrollIntro() {
+ fragmentScenario.onFragment { fragment ->
+ val view = fragment.requireView().findViewById<View>(R.id.enroll_intro_content_view)!!
+ view.setBackgroundColor(Color.BLACK)
+ }
+ fragmentScenario.onFragment { fragment ->
+ val view = fragment.requireView().findViewById<View>(R.id.enroll_intro_content_view)!!
+ rule.assertBitmapAgainstGolden(
+ viewToBitmap(view),
+ "fp_enroll_intro",
+ MSSIMMatcher()
+ )
+ }
+
+ }
+}
diff --git a/tests/spa_unit/src/com/android/settings/datausage/lib/AppDataUsageDetailsRepositoryTest.kt b/tests/spa_unit/src/com/android/settings/datausage/lib/AppDataUsageDetailsRepositoryTest.kt
index 7072b46..85431a4 100644
--- a/tests/spa_unit/src/com/android/settings/datausage/lib/AppDataUsageDetailsRepositoryTest.kt
+++ b/tests/spa_unit/src/com/android/settings/datausage/lib/AppDataUsageDetailsRepositoryTest.kt
@@ -16,7 +16,7 @@
package com.android.settings.datausage.lib
-import android.app.usage.NetworkStats.Bucket
+import android.app.usage.NetworkStats
import android.content.Context
import android.net.NetworkTemplate
import android.util.Range
@@ -28,8 +28,8 @@
import org.junit.runner.RunWith
import org.mockito.kotlin.doReturn
import org.mockito.kotlin.mock
-import org.mockito.kotlin.spy
-import org.mockito.kotlin.whenever
+import org.mockito.kotlin.stub
+import com.android.settings.datausage.lib.NetworkStatsRepository.Companion.Bucket
@RunWith(AndroidJUnit4::class)
class AppDataUsageDetailsRepositoryTest {
@@ -41,58 +41,78 @@
on { getCycles() } doReturn listOf(Range(CYCLE1_END_TIME, CYCLE2_END_TIME))
}
+ private val networkStatsRepository = mock<NetworkStatsRepository>()
+
@Test
fun queryDetailsForCycles_hasCycles(): Unit = runBlocking {
- val range = Range(CYCLE1_START_TIME, CYCLE1_END_TIME)
- val repository = spy(
- AppDataUsageDetailsRepository(
- context = context,
- cycles = listOf(CYCLE1_END_TIME, CYCLE1_START_TIME),
- template = template,
- uids = listOf(UID),
- networkCycleDataRepository = networkCycleDataRepository,
+ networkStatsRepository.stub {
+ on { queryBuckets(CYCLE1_START_TIME, CYCLE1_END_TIME) } doReturn listOf(
+ Bucket(
+ uid = UID,
+ state = NetworkStats.Bucket.STATE_DEFAULT,
+ bytes = BACKGROUND_USAGE,
+ ),
+ Bucket(
+ uid = UID,
+ state = NetworkStats.Bucket.STATE_FOREGROUND,
+ bytes = FOREGROUND_USAGE,
+ ),
)
- ) {
- doReturn(ALL_USAGE).whenever(mock).getUsage(range, UID, Bucket.STATE_ALL)
- doReturn(FOREGROUND_USAGE).whenever(mock).getUsage(range, UID, Bucket.STATE_FOREGROUND)
}
+ val repository = AppDataUsageDetailsRepository(
+ context = context,
+ cycles = listOf(CYCLE1_END_TIME, CYCLE1_START_TIME),
+ template = template,
+ uids = listOf(UID),
+ networkCycleDataRepository = networkCycleDataRepository,
+ networkStatsRepository = networkStatsRepository,
+ )
val detailsForCycles = repository.queryDetailsForCycles()
assertThat(detailsForCycles).containsExactly(
NetworkUsageDetailsData(
- range = range,
- totalUsage = ALL_USAGE,
+ range = Range(CYCLE1_START_TIME, CYCLE1_END_TIME),
+ totalUsage = BACKGROUND_USAGE + FOREGROUND_USAGE,
foregroundUsage = FOREGROUND_USAGE,
- backgroundUsage = ALL_USAGE - FOREGROUND_USAGE,
+ backgroundUsage = BACKGROUND_USAGE,
)
)
}
@Test
fun queryDetailsForCycles_defaultCycles(): Unit = runBlocking {
- val range = Range(CYCLE1_END_TIME, CYCLE2_END_TIME)
- val repository = spy(
- AppDataUsageDetailsRepository(
- context = context,
- cycles = null,
- template = template,
- uids = listOf(UID),
- networkCycleDataRepository = networkCycleDataRepository,
+ networkStatsRepository.stub {
+ on { queryBuckets(CYCLE1_END_TIME, CYCLE2_END_TIME) } doReturn listOf(
+ Bucket(
+ uid = UID,
+ state = NetworkStats.Bucket.STATE_DEFAULT,
+ bytes = BACKGROUND_USAGE,
+ ),
+ Bucket(
+ uid = UID,
+ state = NetworkStats.Bucket.STATE_FOREGROUND,
+ bytes = FOREGROUND_USAGE,
+ ),
)
- ) {
- doReturn(ALL_USAGE).whenever(mock).getUsage(range, UID, Bucket.STATE_ALL)
- doReturn(FOREGROUND_USAGE).whenever(mock).getUsage(range, UID, Bucket.STATE_FOREGROUND)
}
+ val repository = AppDataUsageDetailsRepository(
+ context = context,
+ cycles = null,
+ template = template,
+ uids = listOf(UID),
+ networkCycleDataRepository = networkCycleDataRepository,
+ networkStatsRepository = networkStatsRepository,
+ )
val detailsForCycles = repository.queryDetailsForCycles()
assertThat(detailsForCycles).containsExactly(
NetworkUsageDetailsData(
- range = range,
- totalUsage = ALL_USAGE,
+ range = Range(CYCLE1_END_TIME, CYCLE2_END_TIME),
+ totalUsage = BACKGROUND_USAGE + FOREGROUND_USAGE,
foregroundUsage = FOREGROUND_USAGE,
- backgroundUsage = ALL_USAGE - FOREGROUND_USAGE,
+ backgroundUsage = BACKGROUND_USAGE,
)
)
}
@@ -103,7 +123,7 @@
const val CYCLE2_END_TIME = 1695566666000L
const val UID = 10000
- const val ALL_USAGE = 10L
+ const val BACKGROUND_USAGE = 8L
const val FOREGROUND_USAGE = 2L
}
}
diff --git a/tests/spa_unit/src/com/android/settings/network/BluetoothWiFiResetPreferenceControllerTest.kt b/tests/spa_unit/src/com/android/settings/network/BluetoothWiFiResetPreferenceControllerTest.kt
new file mode 100644
index 0000000..210a0c7
--- /dev/null
+++ b/tests/spa_unit/src/com/android/settings/network/BluetoothWiFiResetPreferenceControllerTest.kt
@@ -0,0 +1,120 @@
+/*
+ * 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.network
+
+import android.bluetooth.BluetoothAdapter
+import android.bluetooth.BluetoothManager
+import android.content.Context
+import android.content.res.Resources
+import android.net.ConnectivityManager
+import android.net.NetworkPolicyManager
+import android.net.VpnManager
+import android.os.UserManager
+import androidx.test.core.app.ApplicationProvider
+import androidx.test.ext.junit.runners.AndroidJUnit4
+import com.android.settings.R
+import com.android.settings.core.BasePreferenceController.AVAILABLE
+import com.android.settings.core.BasePreferenceController.CONDITIONALLY_UNAVAILABLE
+import com.google.common.truth.Truth.assertThat
+import org.junit.Test
+import org.junit.runner.RunWith
+import org.mockito.kotlin.doReturn
+import org.mockito.kotlin.mock
+import org.mockito.kotlin.never
+import org.mockito.kotlin.spy
+import org.mockito.kotlin.stub
+import org.mockito.kotlin.verify
+
+@RunWith(AndroidJUnit4::class)
+class BluetoothWiFiResetPreferenceControllerTest {
+
+ private val mockUserManager = mock<UserManager>()
+ private val mockBluetoothAdapter = mock<BluetoothAdapter>()
+ private val mockBluetoothManager = mock<BluetoothManager> {
+ on { adapter } doReturn mockBluetoothAdapter
+ }
+ private val mockConnectivityManager = mock<ConnectivityManager>()
+ private val mockNetworkPolicyManager = mock<NetworkPolicyManager>()
+ private val mockVpnManager = mock<VpnManager>()
+ private val mockResources = mock<Resources>()
+
+ private val context: Context = spy(ApplicationProvider.getApplicationContext()) {
+ on { getSystemService(Context.USER_SERVICE) } doReturn mockUserManager
+ on { getSystemService(Context.BLUETOOTH_SERVICE) } doReturn mockBluetoothManager
+ on { getSystemService(Context.CONNECTIVITY_SERVICE) } doReturn mockConnectivityManager
+ on { getSystemService(Context.NETWORK_POLICY_SERVICE) } doReturn mockNetworkPolicyManager
+ on { getSystemService(Context.VPN_MANAGEMENT_SERVICE) } doReturn mockVpnManager
+ on { resources } doReturn mockResources
+ }
+
+ private val controller = BluetoothWiFiResetPreferenceController(context, TEST_KEY)
+
+ @Test
+ fun getAvailabilityStatus_isAdminUser_returnAvailable() {
+ mockUserManager.stub {
+ on { isAdminUser } doReturn true
+ }
+
+ val availabilityStatus = controller.getAvailabilityStatus()
+
+ assertThat(availabilityStatus).isEqualTo(AVAILABLE)
+ }
+
+ @Test
+ fun getAvailabilityStatus_notAdminUser_returnConditionallyUnavailable() {
+ mockUserManager.stub {
+ on { isAdminUser } doReturn false
+ }
+
+ val availabilityStatus = controller.getAvailabilityStatus()
+
+ assertThat(availabilityStatus).isEqualTo(CONDITIONALLY_UNAVAILABLE)
+ }
+
+ @Test
+ fun resetOperation_resetBluetooth() {
+ controller.resetOperation().run()
+
+ verify(mockBluetoothAdapter).clearBluetooth()
+ }
+
+ @Test
+ fun resetOperation_onDeviceWithSimVisible_notResetConnectivity() {
+ mockResources.stub {
+ on { getBoolean(R.bool.config_show_sim_info) } doReturn true
+ }
+
+ controller.resetOperation().run()
+
+ verify(mockConnectivityManager, never()).factoryReset()
+ }
+
+ @Test
+ fun resetOperation_onDeviceWithSimInvisible_resetVpn() {
+ mockResources.stub {
+ on { getBoolean(R.bool.config_show_sim_info) } doReturn false
+ }
+
+ controller.resetOperation().run()
+
+ verify(mockVpnManager).factoryReset()
+ }
+
+ private companion object {
+ const val TEST_KEY = "test_key"
+ }
+}
diff --git a/tests/spa_unit/src/com/android/settings/testutils/FakeFeatureFactory.kt b/tests/spa_unit/src/com/android/settings/testutils/FakeFeatureFactory.kt
index 95f25ad..54299eb 100644
--- a/tests/spa_unit/src/com/android/settings/testutils/FakeFeatureFactory.kt
+++ b/tests/spa_unit/src/com/android/settings/testutils/FakeFeatureFactory.kt
@@ -22,6 +22,7 @@
import com.android.settings.accounts.AccountFeatureProvider
import com.android.settings.applications.ApplicationFeatureProvider
import com.android.settings.biometrics.face.FaceFeatureProvider
+import com.android.settings.biometrics.fingerprint.FingerprintFeatureProvider
import com.android.settings.biometrics2.factory.BiometricsRepositoryProvider
import com.android.settings.bluetooth.BluetoothFeatureProvider
import com.android.settings.connecteddevice.fastpair.FastPairFeatureProvider
@@ -120,6 +121,8 @@
get() = TODO("Not yet implemented")
override val faceFeatureProvider: FaceFeatureProvider
get() = TODO("Not yet implemented")
+ override val fingerprintFeatureProvider: FingerprintFeatureProvider
+ get() = TODO("Not yet implemented")
override val biometricsRepositoryProvider: BiometricsRepositoryProvider
get() = TODO("Not yet implemented")
override val wifiTrackerLibProvider: WifiTrackerLibProvider
diff --git a/tests/unit/src/com/android/settings/fingerprint2/enrollment/viewmodel/FingerprintEnrollFindSensorViewModelV2Test.kt b/tests/unit/src/com/android/settings/fingerprint2/enrollment/viewmodel/FingerprintEnrollFindSensorViewModelV2Test.kt
new file mode 100644
index 0000000..509b0ed
--- /dev/null
+++ b/tests/unit/src/com/android/settings/fingerprint2/enrollment/viewmodel/FingerprintEnrollFindSensorViewModelV2Test.kt
@@ -0,0 +1,255 @@
+/*
+ * 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.fingerprint2.enrollment.viewmodel
+
+import android.content.Context
+import android.content.res.Configuration
+import android.view.accessibility.AccessibilityManager
+import androidx.arch.core.executor.testing.InstantTaskExecutorRule
+import androidx.test.core.app.ApplicationProvider
+import com.android.settings.biometrics.fingerprint2.ui.enrollment.viewmodel.AccessibilityViewModel
+import com.android.settings.biometrics.fingerprint2.ui.enrollment.viewmodel.Education
+import com.android.settings.biometrics.fingerprint2.ui.enrollment.viewmodel.FingerprintEnrollFindSensorViewModel
+import com.android.settings.biometrics.fingerprint2.ui.enrollment.viewmodel.FingerprintEnrollNavigationViewModel
+import com.android.settings.biometrics.fingerprint2.ui.enrollment.viewmodel.FingerprintEnrollViewModel
+import com.android.settings.biometrics.fingerprint2.ui.enrollment.viewmodel.FingerprintGatekeeperViewModel
+import com.android.settings.biometrics.fingerprint2.ui.enrollment.viewmodel.FoldStateViewModel
+import com.android.settings.biometrics.fingerprint2.ui.enrollment.viewmodel.NextStepViewModel
+import com.android.settings.biometrics.fingerprint2.ui.enrollment.viewmodel.OrientationStateViewModel
+import com.android.settings.testutils2.FakeFingerprintManagerInteractor
+import com.android.systemui.biometrics.shared.model.FingerprintSensor
+import com.android.systemui.biometrics.shared.model.FingerprintSensorType
+import com.android.systemui.biometrics.shared.model.SensorStrength
+import com.google.common.truth.Truth.assertThat
+import kotlinx.coroutines.Dispatchers
+import kotlinx.coroutines.flow.collectLatest
+import kotlinx.coroutines.launch
+import kotlinx.coroutines.test.StandardTestDispatcher
+import kotlinx.coroutines.test.TestScope
+import kotlinx.coroutines.test.advanceUntilIdle
+import kotlinx.coroutines.test.resetMain
+import kotlinx.coroutines.test.runTest
+import kotlinx.coroutines.test.setMain
+import org.junit.After
+import org.junit.Before
+import org.junit.Rule
+import org.junit.Test
+import org.junit.runner.RunWith
+import org.mockito.junit.MockitoJUnit
+import org.mockito.junit.MockitoJUnitRunner
+
+/** consistent with [ScreenSizeFoldProvider.INNER_SCREEN_SMALLEST_SCREEN_WIDTH_THRESHOLD_DP] */
+private const val INNER_SCREEN_SMALLEST_SCREEN_WIDTH_THRESHOLD_DP = 600
+
+@RunWith(MockitoJUnitRunner::class)
+class FingerprintEnrollFindSensorViewModelV2Test {
+ @JvmField @Rule var rule = MockitoJUnit.rule()
+ @get:Rule val instantTaskRule = InstantTaskExecutorRule()
+
+ private var backgroundDispatcher = StandardTestDispatcher()
+ private var testScope = TestScope(backgroundDispatcher)
+ private lateinit var fakeFingerprintManagerInteractor: FakeFingerprintManagerInteractor
+ private lateinit var gatekeeperViewModel: FingerprintGatekeeperViewModel
+ private lateinit var enrollViewModel: FingerprintEnrollViewModel
+ private lateinit var navigationViewModel: FingerprintEnrollNavigationViewModel
+ private lateinit var accessibilityViewModel: AccessibilityViewModel
+ private lateinit var foldStateViewModel: FoldStateViewModel
+ private lateinit var orientationStateViewModel: OrientationStateViewModel
+ private lateinit var underTest: FingerprintEnrollFindSensorViewModel
+ private val context: Context = ApplicationProvider.getApplicationContext()
+ private val accessibilityManager: AccessibilityManager =
+ context.getSystemService(AccessibilityManager::class.java)!!
+
+ @Before
+ fun setup() {
+ backgroundDispatcher = StandardTestDispatcher()
+ testScope = TestScope(backgroundDispatcher)
+ Dispatchers.setMain(backgroundDispatcher)
+
+ fakeFingerprintManagerInteractor = FakeFingerprintManagerInteractor()
+ gatekeeperViewModel =
+ FingerprintGatekeeperViewModel.FingerprintGatekeeperViewModelFactory(
+ null,
+ fakeFingerprintManagerInteractor
+ )
+ .create(FingerprintGatekeeperViewModel::class.java)
+ navigationViewModel =
+ FingerprintEnrollNavigationViewModel.FingerprintEnrollNavigationViewModelFactory(
+ backgroundDispatcher,
+ fakeFingerprintManagerInteractor,
+ gatekeeperViewModel,
+ canSkipConfirm = true,
+ )
+ .create(FingerprintEnrollNavigationViewModel::class.java)
+ enrollViewModel =
+ FingerprintEnrollViewModel.FingerprintEnrollViewModelFactory(
+ fakeFingerprintManagerInteractor,
+ backgroundDispatcher
+ )
+ .create(FingerprintEnrollViewModel::class.java)
+ accessibilityViewModel =
+ AccessibilityViewModel.AccessibilityViewModelFactory(accessibilityManager)
+ .create(AccessibilityViewModel::class.java)
+ foldStateViewModel =
+ FoldStateViewModel.FoldStateViewModelFactory(context).create(FoldStateViewModel::class.java)
+ orientationStateViewModel =
+ OrientationStateViewModel.OrientationViewModelFactory(context)
+ .create(OrientationStateViewModel::class.java)
+ underTest =
+ FingerprintEnrollFindSensorViewModel.FingerprintEnrollFindSensorViewModelFactory(
+ navigationViewModel,
+ enrollViewModel,
+ gatekeeperViewModel,
+ accessibilityViewModel,
+ foldStateViewModel,
+ orientationStateViewModel
+ )
+ .create(FingerprintEnrollFindSensorViewModel::class.java)
+
+ // Navigate to Education page
+ navigationViewModel.nextStep()
+ }
+ @After
+ fun tearDown() {
+ Dispatchers.resetMain()
+ }
+
+ // TODO(b/305094585): test enroll() logic
+
+ @Test
+ fun currentStepIsEducation() =
+ testScope.runTest {
+ var step: NextStepViewModel? = null
+ val job = launch {
+ navigationViewModel.navigationViewModel.collectLatest { step = it.currStep }
+ }
+ advanceUntilIdle()
+ assertThat(step).isEqualTo(Education)
+ job.cancel()
+ }
+
+ @Test
+ fun udfpsLottieInfo() =
+ testScope.runTest {
+ fakeFingerprintManagerInteractor.sensorProp =
+ FingerprintSensor(
+ 0 /* sensorId */,
+ SensorStrength.STRONG,
+ 5,
+ FingerprintSensorType.UDFPS_OPTICAL
+ )
+
+ var udfpsLottieInfo: Boolean? = null
+ val job = launch { underTest.udfpsLottieInfo.collect { udfpsLottieInfo = it } }
+
+ advanceUntilIdle()
+ assertThat(udfpsLottieInfo).isNotNull()
+ job.cancel()
+ }
+
+ @Test
+ fun sfpsLottieInfoWhenFolded() =
+ testScope.runTest {
+ var isFolded = false
+ var rotation: Int = -1
+ val job = launch {
+ underTest.sfpsLottieInfo.collect {
+ isFolded = it.first
+ rotation = it.second
+ }
+ }
+
+ val config = createConfiguration(isFolded = true)
+ foldStateViewModel.onConfigurationChange(config)
+ advanceUntilIdle()
+ assertThat(isFolded).isTrue()
+ assertThat(rotation).isEqualTo(context.display!!.rotation)
+ job.cancel()
+ }
+
+ @Test
+ fun sfpsLottieInfoWhenUnFolded() =
+ testScope.runTest {
+ var isFolded = false
+ var rotation: Int = -1
+ val job = launch {
+ underTest.sfpsLottieInfo.collect {
+ isFolded = it.first
+ rotation = it.second
+ }
+ }
+
+ val config = createConfiguration(isFolded = false)
+ foldStateViewModel.onConfigurationChange(config)
+ advanceUntilIdle()
+ assertThat(isFolded).isFalse()
+ assertThat(rotation).isEqualTo(context.display!!.rotation)
+ job.cancel()
+ }
+
+ @Test
+ fun rfpsAnimation() =
+ testScope.runTest {
+ fakeFingerprintManagerInteractor.sensorProp =
+ FingerprintSensor(0 /* sensorId */, SensorStrength.STRONG, 5, FingerprintSensorType.REAR)
+
+ var showRfpsAnimation: Boolean? = null
+ val job = launch { underTest.showRfpsAnimation.collect { showRfpsAnimation = it } }
+
+ advanceUntilIdle()
+ assertThat(showRfpsAnimation).isTrue()
+ job.cancel()
+ }
+
+ @Test
+ fun showPrimaryButton_ifUdfps() =
+ testScope.runTest {
+ fakeFingerprintManagerInteractor.sensorProp =
+ FingerprintSensor(
+ 0 /* sensorId */,
+ SensorStrength.STRONG,
+ 5,
+ FingerprintSensorType.UDFPS_OPTICAL
+ )
+
+ var showPrimaryButton: Boolean? = null
+ val job = launch { underTest.showPrimaryButton.collect { showPrimaryButton = it } }
+
+ advanceUntilIdle()
+ assertThat(showPrimaryButton).isTrue()
+ job.cancel()
+ }
+
+ @Test
+ fun doesNotShowPrimaryButton_ifNonUdfps() =
+ testScope.runTest {
+ var showPrimaryButton: Boolean? = null
+ val job = launch { underTest.showPrimaryButton.collect { showPrimaryButton = it } }
+
+ advanceUntilIdle()
+ assertThat(showPrimaryButton).isNull()
+ job.cancel()
+ }
+
+ private fun createConfiguration(isFolded: Boolean): Configuration {
+ val config = Configuration()
+ config.smallestScreenWidthDp =
+ if (isFolded) INNER_SCREEN_SMALLEST_SCREEN_WIDTH_THRESHOLD_DP - 1
+ else INNER_SCREEN_SMALLEST_SCREEN_WIDTH_THRESHOLD_DP + 1
+ return config
+ }
+}
diff --git a/tests/unit/src/com/android/settings/testutils/FakeFeatureFactory.java b/tests/unit/src/com/android/settings/testutils/FakeFeatureFactory.java
index a3a92a3..b5062a0 100644
--- a/tests/unit/src/com/android/settings/testutils/FakeFeatureFactory.java
+++ b/tests/unit/src/com/android/settings/testutils/FakeFeatureFactory.java
@@ -24,6 +24,7 @@
import com.android.settings.accounts.AccountFeatureProvider;
import com.android.settings.applications.ApplicationFeatureProvider;
import com.android.settings.biometrics.face.FaceFeatureProvider;
+import com.android.settings.biometrics.fingerprint.FingerprintFeatureProvider;
import com.android.settings.biometrics2.factory.BiometricsRepositoryProvider;
import com.android.settings.bluetooth.BluetoothFeatureProvider;
import com.android.settings.connecteddevice.fastpair.FastPairFeatureProvider;
@@ -79,6 +80,7 @@
public final AccountFeatureProvider mAccountFeatureProvider;
public final BluetoothFeatureProvider mBluetoothFeatureProvider;
public final FaceFeatureProvider mFaceFeatureProvider;
+ public final FingerprintFeatureProvider mFingerprintFeatureProvider;
public final BiometricsRepositoryProvider mBiometricsRepositoryProvider;
public PanelFeatureProvider panelFeatureProvider;
@@ -131,6 +133,7 @@
panelFeatureProvider = mock(PanelFeatureProvider.class);
mBluetoothFeatureProvider = mock(BluetoothFeatureProvider.class);
mFaceFeatureProvider = mock(FaceFeatureProvider.class);
+ mFingerprintFeatureProvider = mock(FingerprintFeatureProvider.class);
mBiometricsRepositoryProvider = mock(BiometricsRepositoryProvider.class);
wifiTrackerLibProvider = mock(WifiTrackerLibProvider.class);
securitySettingsFeatureProvider = mock(SecuritySettingsFeatureProvider.class);
@@ -256,6 +259,11 @@
}
@Override
+ public FingerprintFeatureProvider getFingerprintFeatureProvider() {
+ return mFingerprintFeatureProvider;
+ }
+
+ @Override
public BiometricsRepositoryProvider getBiometricsRepositoryProvider() {
return mBiometricsRepositoryProvider;
}