Snap for 12910931 from 9e17ca61f4 to 25Q2-release

Change-Id: I309b9c2cce4c53154ddbce45125251cbff5d2f60
This commit is contained in:
Android Build Coastguard Worker
2025-01-13 18:18:04 -08:00
30 changed files with 1610 additions and 257 deletions

View File

@@ -55,7 +55,7 @@
android:text="@string/input_setting_keys_dialog_option_200" android:text="@string/input_setting_keys_dialog_option_200"
android:paddingStart="12dp" android:paddingStart="12dp"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="48dp"
android:layout_gravity="start|center_vertical" android:layout_gravity="start|center_vertical"
android:background="@null"/> android:background="@null"/>
<RadioButton <RadioButton
@@ -63,30 +63,30 @@
android:text="@string/input_setting_keys_dialog_option_400" android:text="@string/input_setting_keys_dialog_option_400"
android:paddingStart="12dp" android:paddingStart="12dp"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="48dp"
android:layout_gravity="start|center_vertical" android:layout_gravity="start|center_vertical"
android:layout_marginTop="12dp" android:layout_marginTop="6dp"
android:background="@null"/> android:background="@null"/>
<RadioButton <RadioButton
android:id="@+id/input_setting_keys_value_600" android:id="@+id/input_setting_keys_value_600"
android:text="@string/input_setting_keys_dialog_option_600" android:text="@string/input_setting_keys_dialog_option_600"
android:paddingStart="12dp" android:paddingStart="12dp"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="48dp"
android:layout_gravity="start|center_vertical" android:layout_gravity="start|center_vertical"
android:layout_marginTop="12dp" android:layout_marginTop="6dp"
android:background="@null"/> android:background="@null"/>
<LinearLayout <LinearLayout
android:orientation="horizontal" android:orientation="horizontal"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_marginVertical="12dp"> android:layout_marginVertical="6dp">
<RadioButton <RadioButton
android:id="@+id/input_setting_keys_value_custom" android:id="@+id/input_setting_keys_value_custom"
android:paddingStart="12dp" android:paddingStart="12dp"
android:layout_width="wrap_content" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_height="48dp"
android:layout_gravity="center_vertical" android:layout_gravity="center_vertical"
android:background="@null"/> android:background="@null"/>
<LinearLayout <LinearLayout
@@ -94,6 +94,7 @@
android:orientation="vertical" android:orientation="vertical"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:minHeight="48dp"
android:layout_gravity="center_vertical" android:layout_gravity="center_vertical"
android:gravity="center_vertical" android:gravity="center_vertical"
android:paddingEnd="16dp"> android:paddingEnd="16dp">
@@ -123,8 +124,7 @@
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_gravity="center_vertical" android:layout_gravity="center_vertical"
android:layout_marginTop="8dp" android:layout_marginTop="8dp"
android:visibility="gone" android:visibility="gone"/>
android:background="@null"/>
</LinearLayout> </LinearLayout>
</LinearLayout> </LinearLayout>
</RadioGroup> </RadioGroup>

View File

@@ -809,6 +809,12 @@
<!-- Message shown in summary field when Face Unlock is not set up. [CHAR LIMIT=54] --> <!-- Message shown in summary field when Face Unlock is not set up. [CHAR LIMIT=54] -->
<string name="security_settings_face_preference_summary_none">Setup needed</string> <string name="security_settings_face_preference_summary_none">Setup needed</string>
<!-- Title shown for menu item that launches face settings or enrollment. [CHAR LIMIT=32] --> <!-- Title shown for menu item that launches face settings or enrollment. [CHAR LIMIT=32] -->
<string name="security_settings_face_preference_title_new">Face</string>
<!-- Title shown for menu item that launches face settings or enrollment, for work profile. [CHAR LIMIT=50] -->
<string name="security_settings_face_profile_preference_title_new">Face for work</string>
<!-- Title shown for menu item that launches face settings or enrollment. [CHAR LIMIT=32] -->
<string name="private_space_face_unlock_title_new">Face for private space</string>
<!-- Title shown for menu item that launches face settings or enrollment. [CHAR LIMIT=32] -->
<string name="security_settings_face_preference_title">Face Unlock</string> <string name="security_settings_face_preference_title">Face Unlock</string>
<!-- Title shown for menu item that launches face settings or enrollment, for work profile [CHAR LIMIT=50] --> <!-- Title shown for menu item that launches face settings or enrollment, for work profile [CHAR LIMIT=50] -->
<string name="security_settings_face_profile_preference_title">Face Unlock for work</string> <string name="security_settings_face_profile_preference_title">Face Unlock for work</string>
@@ -938,6 +944,8 @@
<string name="security_settings_fingerprint_settings_preferences_category">When using Fingerprint Unlock</string> <string name="security_settings_fingerprint_settings_preferences_category">When using Fingerprint Unlock</string>
<!-- Title shown for work menu item that launches fingerprint settings or enrollment [CHAR LIMIT=22] --> <!-- Title shown for work menu item that launches fingerprint settings or enrollment [CHAR LIMIT=22] -->
<string name="security_settings_work_fingerprint_preference_title">Fingerprint for work</string> <string name="security_settings_work_fingerprint_preference_title">Fingerprint for work</string>
<!-- Title shown for work menu item that launches fingerprint settings or enrollment [CHAR LIMIT=22] -->
<string name="security_settings_work_fingerprint_preference_title_new">Fingerprint for work</string>
<!-- Preference to check enrolled fingerprints --> <!-- Preference to check enrolled fingerprints -->
<string name="fingerprint_check_enrolled_title">Check enrolled fingerprints</string> <string name="fingerprint_check_enrolled_title">Check enrolled fingerprints</string>
<!-- Preference to add another fingerprint --> <!-- Preference to add another fingerprint -->
@@ -1381,6 +1389,8 @@
<string name="private_space_biometric_summary">Tap to set up</string> <string name="private_space_biometric_summary">Tap to set up</string>
<!-- Title for the Fingerprint unlock for private space preference. [CHAR LIMIT=60] --> <!-- Title for the Fingerprint unlock for private space preference. [CHAR LIMIT=60] -->
<string name="private_space_fingerprint_unlock_title">Fingerprint Unlock for private space</string> <string name="private_space_fingerprint_unlock_title">Fingerprint Unlock for private space</string>
<!-- Title for the Fingerprint unlock for private space preference. [CHAR LIMIT=60] -->
<string name="private_space_fingerprint_unlock_title_new">Fingerprint for private space</string>
<!-- Title for the Face unlock for private space preference. [CHAR LIMIT=60] --> <!-- Title for the Face unlock for private space preference. [CHAR LIMIT=60] -->
<string name="private_space_face_unlock_title">Face Unlock for private space</string> <string name="private_space_face_unlock_title">Face Unlock for private space</string>
<!-- Title for the Face and Fingerprint preference for private space. [CHAR LIMIT=60] --> <!-- Title for the Face and Fingerprint preference for private space. [CHAR LIMIT=60] -->
@@ -5594,6 +5604,9 @@
<!-- Summary for the seekbar that adjust auto click cursor area size. [CHAR_LIMIT=NONE] --> <!-- Summary for the seekbar that adjust auto click cursor area size. [CHAR_LIMIT=NONE] -->
<!-- TODO(b/383901288): Update string to translatable once approved by UXW. --> <!-- TODO(b/383901288): Update string to translatable once approved by UXW. -->
<string name="autoclick_cursor_area_size_summary" translatable="false">Adjust the autoclick ring indicator area size</string> <string name="autoclick_cursor_area_size_summary" translatable="false">Adjust the autoclick ring indicator area size</string>
<!-- Title for the toggle button that turns on/off the autoclick setting of ignoring minor cursor movement. [CHAR_LIMIT=NONE] -->
<!-- TODO(b/388845718): Update string to translatable once approved by UXW. -->
<string name="autoclick_ignore_minor_cursor_movement_title" translatable="false">Ignore minor cursor movement</string>
<!-- Title for preference screen for configuring vibrations. [CHAR LIMIT=NONE] --> <!-- Title for preference screen for configuring vibrations. [CHAR LIMIT=NONE] -->
<string name="accessibility_vibration_settings_title">Vibration &amp; haptics</string> <string name="accessibility_vibration_settings_title">Vibration &amp; haptics</string>
<!-- Summary for preference screen for configuring vibrations. [CHAR LIMIT=NONE] --> <!-- Summary for preference screen for configuring vibrations. [CHAR LIMIT=NONE] -->
@@ -11301,19 +11314,19 @@
<string name="double_tap_power_for_camera_summary">To quickly open camera, press the power button twice. Works from any screen.</string> <string name="double_tap_power_for_camera_summary">To quickly open camera, press the power button twice. Works from any screen.</string>
<!-- Title text for double tap power gesture [CHAR LIMIT=80]--> <!-- Title text for double tap power gesture [CHAR LIMIT=80]-->
<string name="double_tap_power_title">Double tap power button</string> <string name="double_tap_power_title">Double press power button</string>
<!-- Summary for double tap power settings [DO NOT TRANSLATE] --> <!-- Summary for double tap power settings [DO NOT TRANSLATE] -->
<string name="double_tap_power_summary" translatable="false"><xliff:g id="double_tap_power_on_off" example="On">%1$s</xliff:g> / <xliff:g id="double_tap_power_actions" example="Access Wallet">%2$s</xliff:g></string> <string name="double_tap_power_summary" translatable="false"><xliff:g id="double_tap_power_on_off" example="On">%1$s</xliff:g> / <xliff:g id="double_tap_power_actions" example="Access Wallet">%2$s</xliff:g></string>
<!-- Switch label to enable/disable double tap power button gesture [CHAR LIMIT=60] --> <!-- Switch label to enable/disable double tap power button gesture [CHAR LIMIT=60] -->
<string name="double_tap_power_enabled">Use double tap</string> <string name="double_tap_power_enabled">Use double press</string>
<!-- Category title for double tap power gesture [CHAR_LIMIT=80] --> <!-- Category title for double tap power gesture [CHAR_LIMIT=80] -->
<string name="double_tap_power_target_action_category">Double Tap Power Button</string> <string name="double_tap_power_target_action_category">Double press power button to open</string>
<!-- Double Tap Power Gesture camera launch action title [CHAR_LIMIT=60] --> <!-- Double Tap Power Gesture camera launch action title [CHAR_LIMIT=60] -->
<string name="double_tap_power_camera_action_title">Open Camera</string> <string name="double_tap_power_camera_action_title">Camera</string>
<!-- Setting summary to describe double tap power button will open camera. [CHAR LIMIT=NONE] --> <!-- Setting summary to describe double tap power button will open camera. [CHAR LIMIT=NONE] -->
<string name="double_tap_power_camera_action_summary">Access Camera</string> <string name="double_tap_power_camera_action_summary">Access Camera</string>
<!-- Double Tap Power Gesture wallet launch action title [CHAR_LIMIT=60] --> <!-- Double Tap Power Gesture wallet launch action title [CHAR_LIMIT=60] -->
<string name="double_tap_power_wallet_action_title">Open Wallet</string> <string name="double_tap_power_wallet_action_title">Wallet</string>
<!-- Setting summary to describe double tap power button will open wallet. [CHAR LIMIT=NONE] --> <!-- Setting summary to describe double tap power button will open wallet. [CHAR LIMIT=NONE] -->
<string name="double_tap_power_wallet_action_summary">Access Wallet</string> <string name="double_tap_power_wallet_action_summary">Access Wallet</string>

View File

@@ -84,6 +84,11 @@
settings:searchable="false" settings:searchable="false"
settings:controller="com.android.settings.accessibility.ToggleAutoclickCursorAreaSizeController"/> settings:controller="com.android.settings.accessibility.ToggleAutoclickCursorAreaSizeController"/>
<SwitchPreferenceCompat
android:key="accessibility_control_autoclick_ignore_minor_cursor_movement"
android:title="@string/autoclick_ignore_minor_cursor_movement_title"
settings:controller="com.android.settings.accessibility.ToggleAutoclickIgnoreMinorCursorMovementController"/>
<com.android.settings.accessibility.AccessibilityFooterPreference <com.android.settings.accessibility.AccessibilityFooterPreference
android:key="accessibility_autoclick_footer" android:key="accessibility_autoclick_footer"
android:title="@string/accessibility_autoclick_description" android:title="@string/accessibility_autoclick_description"

View File

@@ -0,0 +1,58 @@
/*
* Copyright 2025 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.accessibility;
import android.content.Context;
import androidx.annotation.NonNull;
import com.android.server.accessibility.Flags;
import com.android.settings.R;
import com.android.settings.core.TogglePreferenceController;
public class ToggleAutoclickIgnoreMinorCursorMovementController extends TogglePreferenceController {
private static final String TAG =
ToggleAutoclickIgnoreMinorCursorMovementController.class.getSimpleName();
public ToggleAutoclickIgnoreMinorCursorMovementController(
@NonNull Context context, @NonNull String key) {
super(context, key);
}
@Override
public int getAvailabilityStatus() {
return Flags.enableAutoclickIndicator() ? AVAILABLE : CONDITIONALLY_UNAVAILABLE;
}
@Override
public boolean isChecked() {
// TODO(b/388845718): retrieve check status from settings.
return false;
}
@Override
public boolean setChecked(boolean isChecked) {
// TODO(b/388845718): Update settings.
return true;
}
@Override
public int getSliceHighlightMenuRes() {
return R.string.menu_key_accessibility;
}
}

View File

@@ -17,7 +17,6 @@
package com.android.settings.applications; package com.android.settings.applications;
import android.content.Context; import android.content.Context;
import android.text.format.Formatter;
import androidx.annotation.Nullable; import androidx.annotation.Nullable;
import androidx.annotation.StringRes; import androidx.annotation.StringRes;
@@ -25,6 +24,7 @@ import androidx.preference.Preference;
import com.android.internal.util.Preconditions; import com.android.internal.util.Preconditions;
import com.android.settingslib.applications.StorageStatsSource; import com.android.settingslib.applications.StorageStatsSource;
import com.android.settingslib.spaprivileged.model.app.AppStorageRepositoryImpl;
/** /**
* Handles setting the sizes for the app info screen. * Handles setting the sizes for the app info screen.
@@ -70,27 +70,28 @@ public class AppStorageSizesController {
mCacheSize.setSummary(errorRes); mCacheSize.setSummary(errorRes);
mTotalSize.setSummary(errorRes); mTotalSize.setSummary(errorRes);
} else { } else {
var appStorageRepository = new AppStorageRepositoryImpl(context);
long codeSize = mLastResult.getCodeBytes(); long codeSize = mLastResult.getCodeBytes();
long dataSize = long dataSize =
mDataCleared ? 0 : mLastResult.getDataBytes() - mLastResult.getCacheBytes(); mDataCleared ? 0 : mLastResult.getDataBytes() - mLastResult.getCacheBytes();
if (mLastCodeSize != codeSize) { if (mLastCodeSize != codeSize) {
mLastCodeSize = codeSize; mLastCodeSize = codeSize;
mAppSize.setSummary(getSizeStr(context, codeSize)); mAppSize.setSummary(appStorageRepository.formatSizeBytes(codeSize));
} }
if (mLastDataSize != dataSize) { if (mLastDataSize != dataSize) {
mLastDataSize = dataSize; mLastDataSize = dataSize;
mDataSize.setSummary(getSizeStr(context, dataSize)); mDataSize.setSummary(appStorageRepository.formatSizeBytes(dataSize));
} }
long cacheSize = (mDataCleared || mCachedCleared) ? 0 : mLastResult.getCacheBytes(); long cacheSize = (mDataCleared || mCachedCleared) ? 0 : mLastResult.getCacheBytes();
if (mLastCacheSize != cacheSize) { if (mLastCacheSize != cacheSize) {
mLastCacheSize = cacheSize; mLastCacheSize = cacheSize;
mCacheSize.setSummary(getSizeStr(context, cacheSize)); mCacheSize.setSummary(appStorageRepository.formatSizeBytes(cacheSize));
} }
long totalSize = codeSize + dataSize + cacheSize; long totalSize = codeSize + dataSize + cacheSize;
if (mLastTotalSize != totalSize) { if (mLastTotalSize != totalSize) {
mLastTotalSize = totalSize; mLastTotalSize = totalSize;
mTotalSize.setSummary(getSizeStr(context, totalSize)); mTotalSize.setSummary(appStorageRepository.formatSizeBytes(totalSize));
} }
} }
} }
@@ -129,10 +130,6 @@ public class AppStorageSizesController {
return mLastResult; return mLastResult;
} }
private String getSizeStr(Context context, long size) {
return Formatter.formatFileSize(context, size);
}
public static class Builder { public static class Builder {
private Preference mTotalSize; private Preference mTotalSize;
private Preference mAppSize; private Preference mAppSize;

View File

@@ -26,12 +26,11 @@ import com.android.settings.R;
import com.android.settings.Settings; import com.android.settings.Settings;
import com.android.settings.Utils; import com.android.settings.Utils;
import com.android.settings.biometrics.ParentalControlsUtils; import com.android.settings.biometrics.ParentalControlsUtils;
import com.android.settings.flags.Flags;
import com.android.settingslib.RestrictedLockUtils.EnforcedAdmin; import com.android.settingslib.RestrictedLockUtils.EnforcedAdmin;
import com.android.settingslib.RestrictedLockUtilsInternal; import com.android.settingslib.RestrictedLockUtilsInternal;
/** /** Utilities for face details shared between Security Settings and Safety Center. */
* Utilities for face details shared between Security Settings and Safety Center.
*/
public class FaceStatusUtils { public class FaceStatusUtils {
private final int mUserId; private final int mUserId;
@@ -44,9 +43,7 @@ public class FaceStatusUtils {
mUserId = userId; mUserId = userId;
} }
/** /** Returns whether the face settings entity should be shown. */
* Returns whether the face settings entity should be shown.
*/
public boolean isAvailable() { public boolean isAvailable() {
return !Utils.isMultipleBiometricsSupported(mContext) && Utils.hasFaceHardware(mContext); return !Utils.isMultipleBiometricsSupported(mContext) && Utils.hasFaceHardware(mContext);
} }
@@ -61,55 +58,70 @@ public class FaceStatusUtils {
mContext, BiometricAuthenticator.TYPE_FACE); mContext, BiometricAuthenticator.TYPE_FACE);
} }
/** /** Returns the title of face settings entity. */
* Returns the title of face settings entity.
*/
public String getTitle() { public String getTitle() {
UserManager userManager = mContext.getSystemService(UserManager.class); UserManager userManager = mContext.getSystemService(UserManager.class);
if (userManager != null && userManager.isProfile()) { if (userManager != null && userManager.isProfile()) {
return mContext.getString( return mContext.getString(
Utils.isPrivateProfile(mUserId, mContext) Utils.isPrivateProfile(mUserId, mContext)
? R.string.private_space_face_unlock_title ? getPrivateSpaceTitle()
: R.string.security_settings_face_profile_preference_title); : getWorkProfileTitle());
} else { } else {
return mContext.getString(R.string.security_settings_face_preference_title); return mContext.getString(getRegularTitle());
} }
} }
/** private int getPrivateSpaceTitle() {
* Returns the summary of face settings entity. if (Flags.biometricsOnboardingEducation()) {
*/ return R.string.private_space_face_unlock_title_new;
}
return R.string.private_space_face_unlock_title;
}
private int getWorkProfileTitle() {
if (Flags.biometricsOnboardingEducation()) {
return R.string.security_settings_face_profile_preference_title_new;
}
return R.string.security_settings_face_profile_preference_title;
}
private int getRegularTitle() {
if (Flags.biometricsOnboardingEducation()) {
return R.string.security_settings_face_preference_title_new;
}
return R.string.security_settings_face_preference_title;
}
/** Returns the summary of face settings entity. */
public String getSummary() { public String getSummary() {
if (shouldShowDisabledByAdminStr()) { if (shouldShowDisabledByAdminStr()) {
return mContext.getString( return mContext.getString(
com.android.settingslib.widget.restricted.R.string.disabled_by_admin); com.android.settingslib.widget.restricted.R.string.disabled_by_admin);
} else { } else {
return mContext.getResources().getString(hasEnrolled() return mContext.getResources()
? R.string.security_settings_face_preference_summary .getString(
: R.string.security_settings_face_preference_summary_none); hasEnrolled()
? R.string.security_settings_face_preference_summary
: R.string.security_settings_face_preference_summary_none);
} }
} }
/** /** Returns the class name of the Settings page corresponding to face settings. */
* Returns the class name of the Settings page corresponding to face settings.
*/
public String getSettingsClassName() { public String getSettingsClassName() {
return hasEnrolled() ? Settings.FaceSettingsInternalActivity.class.getName() return hasEnrolled()
? Settings.FaceSettingsInternalActivity.class.getName()
: FaceEnrollIntroductionInternal.class.getName(); : FaceEnrollIntroductionInternal.class.getName();
} }
/** /** Returns whether at least one face template has been enrolled. */
* Returns whether at least one face template has been enrolled.
*/
public boolean hasEnrolled() { public boolean hasEnrolled() {
return mFaceManager.hasEnrolledTemplates(mUserId); return mFaceManager.hasEnrolledTemplates(mUserId);
} }
/** /** Indicates if the face feature is enabled or disabled by the Device Admin. */
* Indicates if the face feature is enabled or disabled by the Device Admin.
*/
private boolean shouldShowDisabledByAdminStr() { private boolean shouldShowDisabledByAdminStr() {
return RestrictedLockUtilsInternal.checkIfKeyguardFeaturesDisabled( return RestrictedLockUtilsInternal.checkIfKeyguardFeaturesDisabled(
mContext, DevicePolicyManager.KEYGUARD_DISABLE_FACE, mUserId) != null; mContext, DevicePolicyManager.KEYGUARD_DISABLE_FACE, mUserId)
!= null;
} }
} }

View File

@@ -29,7 +29,9 @@ import androidx.annotation.Nullable;
import com.android.settings.Utils; import com.android.settings.Utils;
import com.android.settings.biometrics.BiometricUtils; import com.android.settings.biometrics.BiometricUtils;
import com.android.settings.flags.Flags;
import com.android.settings.safetycenter.BiometricsSafetySource; import com.android.settings.safetycenter.BiometricsSafetySource;
import com.android.settings.safetycenter.FaceSafetySource;
/** /**
* Responsible for making {@link FaceManager#enroll} and {@link FaceManager#remove} calls and thus * Responsible for making {@link FaceManager#enroll} and {@link FaceManager#remove} calls and thus
@@ -51,20 +53,43 @@ public class FaceUpdater {
} }
/** Wrapper around the {@link FaceManager#enroll} method. */ /** Wrapper around the {@link FaceManager#enroll} method. */
public void enroll(int userId, byte[] hardwareAuthToken, CancellationSignal cancel, public void enroll(
FaceManager.EnrollmentCallback callback, int[] disabledFeatures, Intent intent) { int userId,
this.enroll(userId, hardwareAuthToken, cancel, byte[] hardwareAuthToken,
new NotifyingEnrollmentCallback(mContext, callback), disabledFeatures, CancellationSignal cancel,
null, false, intent); FaceManager.EnrollmentCallback callback,
int[] disabledFeatures,
Intent intent) {
this.enroll(
userId,
hardwareAuthToken,
cancel,
new NotifyingEnrollmentCallback(mContext, callback),
disabledFeatures,
null,
false,
intent);
} }
/** Wrapper around the {@link FaceManager#enroll} method. */ /** Wrapper around the {@link FaceManager#enroll} method. */
public void enroll(int userId, byte[] hardwareAuthToken, CancellationSignal cancel, public void enroll(
FaceManager.EnrollmentCallback callback, int[] disabledFeatures, int userId,
@Nullable Surface previewSurface, boolean debugConsent, Intent intent) { byte[] hardwareAuthToken,
mFaceManager.enroll(userId, hardwareAuthToken, cancel, CancellationSignal cancel,
new NotifyingEnrollmentCallback(mContext, callback), disabledFeatures, FaceManager.EnrollmentCallback callback,
previewSurface, debugConsent, toFaceEnrollOptions(intent)); int[] disabledFeatures,
@Nullable Surface previewSurface,
boolean debugConsent,
Intent intent) {
mFaceManager.enroll(
userId,
hardwareAuthToken,
cancel,
new NotifyingEnrollmentCallback(mContext, callback),
disabledFeatures,
previewSurface,
debugConsent,
toFaceEnrollOptions(intent));
} }
/** Wrapper around the {@link FaceManager#remove} method. */ /** Wrapper around the {@link FaceManager#remove} method. */
@@ -73,17 +98,15 @@ public class FaceUpdater {
} }
/** /**
* Decorator of the {@link FaceManager.EnrollmentCallback} class that notifies other * Decorator of the {@link FaceManager.EnrollmentCallback} class that notifies other interested
* interested parties that a face setting has changed. * parties that a face setting has changed.
*/ */
private static class NotifyingEnrollmentCallback private static class NotifyingEnrollmentCallback extends FaceManager.EnrollmentCallback {
extends FaceManager.EnrollmentCallback {
private final Context mContext; private final Context mContext;
private final FaceManager.EnrollmentCallback mCallback; private final FaceManager.EnrollmentCallback mCallback;
NotifyingEnrollmentCallback(Context context, NotifyingEnrollmentCallback(Context context, FaceManager.EnrollmentCallback callback) {
FaceManager.EnrollmentCallback callback) {
mContext = context; mContext = context;
mCallback = callback; mCallback = callback;
} }
@@ -99,8 +122,14 @@ public class FaceUpdater {
} }
@Override @Override
public void onEnrollmentFrame(int helpCode, @Nullable CharSequence helpMessage, public void onEnrollmentFrame(
@Nullable FaceEnrollCell cell, int stage, float pan, float tilt, float distance) { int helpCode,
@Nullable CharSequence helpMessage,
@Nullable FaceEnrollCell cell,
int stage,
float pan,
float tilt,
float distance) {
mCallback.onEnrollmentFrame(helpCode, helpMessage, cell, stage, pan, tilt, distance); mCallback.onEnrollmentFrame(helpCode, helpMessage, cell, stage, pan, tilt, distance);
} }
@@ -108,14 +137,18 @@ public class FaceUpdater {
public void onEnrollmentProgress(int remaining) { public void onEnrollmentProgress(int remaining) {
mCallback.onEnrollmentProgress(remaining); mCallback.onEnrollmentProgress(remaining);
if (remaining == 0) { if (remaining == 0) {
BiometricsSafetySource.onBiometricsChanged(mContext); // biometrics data changed if (Flags.biometricsOnboardingEducation()) {
FaceSafetySource.onBiometricsChanged(mContext);
} else {
BiometricsSafetySource.onBiometricsChanged(mContext); // biometrics data changed
}
} }
} }
} }
/** /**
* Decorator of the {@link FaceManager.RemovalCallback} class that notifies other * Decorator of the {@link FaceManager.RemovalCallback} class that notifies other interested
* interested parties that a face setting has changed. * parties that a face setting has changed.
*/ */
private static class NotifyingRemovalCallback extends FaceManager.RemovalCallback { private static class NotifyingRemovalCallback extends FaceManager.RemovalCallback {
@@ -135,7 +168,11 @@ public class FaceUpdater {
@Override @Override
public void onRemovalSucceeded(@Nullable Face fp, int remaining) { public void onRemovalSucceeded(@Nullable Face fp, int remaining) {
mCallback.onRemovalSucceeded(fp, remaining); mCallback.onRemovalSucceeded(fp, remaining);
BiometricsSafetySource.onBiometricsChanged(mContext); // biometrics data changed if (Flags.biometricsOnboardingEducation()) {
FaceSafetySource.onBiometricsChanged(mContext);
} else {
BiometricsSafetySource.onBiometricsChanged(mContext); // biometrics data changed
}
} }
} }

View File

@@ -25,29 +25,26 @@ import android.os.UserManager;
import com.android.settings.R; import com.android.settings.R;
import com.android.settings.Utils; import com.android.settings.Utils;
import com.android.settings.biometrics.ParentalControlsUtils; import com.android.settings.biometrics.ParentalControlsUtils;
import com.android.settings.flags.Flags;
import com.android.settingslib.RestrictedLockUtils.EnforcedAdmin; import com.android.settingslib.RestrictedLockUtils.EnforcedAdmin;
import com.android.settingslib.RestrictedLockUtilsInternal; import com.android.settingslib.RestrictedLockUtilsInternal;
import com.android.settingslib.utils.StringUtil; import com.android.settingslib.utils.StringUtil;
/** /** Utilities for fingerprint details shared between Security Settings and Safety Center. */
* Utilities for fingerprint details shared between Security Settings and Safety Center.
*/
public class FingerprintStatusUtils { public class FingerprintStatusUtils {
private final int mUserId; private final int mUserId;
private final Context mContext; private final Context mContext;
private final FingerprintManager mFingerprintManager; private final FingerprintManager mFingerprintManager;
public FingerprintStatusUtils(Context context, FingerprintManager fingerprintManager, public FingerprintStatusUtils(
int userId) { Context context, FingerprintManager fingerprintManager, int userId) {
mContext = context; mContext = context;
mFingerprintManager = fingerprintManager; mFingerprintManager = fingerprintManager;
mUserId = userId; mUserId = userId;
} }
/** /** Returns whether the fingerprint settings entity should be shown. */
* Returns whether the fingerprint settings entity should be shown.
*/
public boolean isAvailable() { public boolean isAvailable() {
return !Utils.isMultipleBiometricsSupported(mContext) return !Utils.isMultipleBiometricsSupported(mContext)
&& Utils.hasFingerprintHardware(mContext); && Utils.hasFingerprintHardware(mContext);
@@ -62,24 +59,42 @@ public class FingerprintStatusUtils {
return ParentalControlsUtils.parentConsentRequired( return ParentalControlsUtils.parentConsentRequired(
mContext, BiometricAuthenticator.TYPE_FINGERPRINT); mContext, BiometricAuthenticator.TYPE_FINGERPRINT);
} }
/**
* Returns the title of fingerprint settings entity. /** Returns the title of fingerprint settings entity. */
*/
public String getTitle() { public String getTitle() {
UserManager userManager = mContext.getSystemService(UserManager.class); UserManager userManager = mContext.getSystemService(UserManager.class);
if (userManager != null && userManager.isProfile()) { if (userManager != null && userManager.isProfile()) {
return mContext.getString( return mContext.getString(
Utils.isPrivateProfile(mUserId, mContext) Utils.isPrivateProfile(mUserId, mContext)
? R.string.private_space_fingerprint_unlock_title ? getPrivateSpaceTitle()
: R.string.security_settings_work_fingerprint_preference_title); : getWorkProfileTitle());
} else { } else {
return mContext.getString(R.string.security_settings_fingerprint_preference_title); return mContext.getString(getRegularTitle());
} }
} }
/** private int getPrivateSpaceTitle() {
* Returns the summary of fingerprint settings entity. if (Flags.biometricsOnboardingEducation()) {
*/ return R.string.private_space_fingerprint_unlock_title_new;
}
return R.string.private_space_fingerprint_unlock_title;
}
private int getWorkProfileTitle() {
if (Flags.biometricsOnboardingEducation()) {
return R.string.security_settings_work_fingerprint_preference_title_new;
}
return R.string.security_settings_work_fingerprint_preference_title;
}
private int getRegularTitle() {
if (Flags.biometricsOnboardingEducation()) {
return R.string.security_settings_fingerprint; // doesn't have an overlay
}
return R.string.security_settings_fingerprint_preference_title;
}
/** Returns the summary of fingerprint settings entity. */
public String getSummary() { public String getSummary() {
if (shouldShowDisabledByAdminStr()) { if (shouldShowDisabledByAdminStr()) {
return mContext.getString( return mContext.getString(
@@ -87,7 +102,9 @@ public class FingerprintStatusUtils {
} }
if (hasEnrolled()) { if (hasEnrolled()) {
final int numEnrolled = mFingerprintManager.getEnrolledFingerprints(mUserId).size(); final int numEnrolled = mFingerprintManager.getEnrolledFingerprints(mUserId).size();
return StringUtil.getIcuPluralsString(mContext, numEnrolled, return StringUtil.getIcuPluralsString(
mContext,
numEnrolled,
R.string.security_settings_fingerprint_preference_summary); R.string.security_settings_fingerprint_preference_summary);
} else { } else {
return mContext.getString( return mContext.getString(
@@ -95,25 +112,20 @@ public class FingerprintStatusUtils {
} }
} }
/** /** Returns the class name of the Settings page corresponding to fingerprint settings. */
* Returns the class name of the Settings page corresponding to fingerprint settings.
*/
public String getSettingsClassName() { public String getSettingsClassName() {
return FingerprintSettings.class.getName(); return FingerprintSettings.class.getName();
} }
/** /** Returns whether at least one fingerprint has been enrolled. */
* Returns whether at least one fingerprint has been enrolled.
*/
public boolean hasEnrolled() { public boolean hasEnrolled() {
return mFingerprintManager.hasEnrolledFingerprints(mUserId); return mFingerprintManager.hasEnrolledFingerprints(mUserId);
} }
/** /** Indicates if the fingerprint feature should show the "Disabled by Admin" string. */
* Indicates if the fingerprint feature should show the "Disabled by Admin" string.
*/
private boolean shouldShowDisabledByAdminStr() { private boolean shouldShowDisabledByAdminStr() {
return RestrictedLockUtilsInternal.checkIfKeyguardFeaturesDisabled( return RestrictedLockUtilsInternal.checkIfKeyguardFeaturesDisabled(
mContext, DevicePolicyManager.KEYGUARD_DISABLE_FINGERPRINT, mUserId) != null; mContext, DevicePolicyManager.KEYGUARD_DISABLE_FINGERPRINT, mUserId)
!= null;
} }
} }

View File

@@ -27,7 +27,9 @@ import androidx.annotation.Nullable;
import com.android.settings.Utils; import com.android.settings.Utils;
import com.android.settings.biometrics.BiometricUtils; import com.android.settings.biometrics.BiometricUtils;
import com.android.settings.flags.Flags;
import com.android.settings.safetycenter.BiometricsSafetySource; import com.android.settings.safetycenter.BiometricsSafetySource;
import com.android.settings.safetycenter.FingerprintSafetySource;
/** /**
* Responsible for making {@link FingerprintManager#enroll} and {@link FingerprintManager#remove} * Responsible for making {@link FingerprintManager#enroll} and {@link FingerprintManager#remove}
@@ -49,11 +51,19 @@ public class FingerprintUpdater {
} }
/** Wrapper around the {@link FingerprintManager#enroll} method. */ /** Wrapper around the {@link FingerprintManager#enroll} method. */
public void enroll(byte [] hardwareAuthToken, CancellationSignal cancel, int userId, public void enroll(
byte[] hardwareAuthToken,
CancellationSignal cancel,
int userId,
FingerprintManager.EnrollmentCallback callback, FingerprintManager.EnrollmentCallback callback,
@FingerprintManager.EnrollReason int enrollReason, Intent intent) { @FingerprintManager.EnrollReason int enrollReason,
mFingerprintManager.enroll(hardwareAuthToken, cancel, userId, Intent intent) {
new NotifyingEnrollmentCallback(mContext, callback), enrollReason, mFingerprintManager.enroll(
hardwareAuthToken,
cancel,
userId,
new NotifyingEnrollmentCallback(mContext, callback),
enrollReason,
toFingerprintEnrollOptions(intent)); toFingerprintEnrollOptions(intent));
} }
@@ -66,14 +76,13 @@ public class FingerprintUpdater {
* Decorator of the {@link FingerprintManager.EnrollmentCallback} class that notifies other * Decorator of the {@link FingerprintManager.EnrollmentCallback} class that notifies other
* interested parties that a fingerprint setting has changed. * interested parties that a fingerprint setting has changed.
*/ */
private static class NotifyingEnrollmentCallback private static class NotifyingEnrollmentCallback extends FingerprintManager.EnrollmentCallback {
extends FingerprintManager.EnrollmentCallback {
private final Context mContext; private final Context mContext;
private final FingerprintManager.EnrollmentCallback mCallback; private final FingerprintManager.EnrollmentCallback mCallback;
NotifyingEnrollmentCallback(Context context, NotifyingEnrollmentCallback(
FingerprintManager.EnrollmentCallback callback) { Context context, FingerprintManager.EnrollmentCallback callback) {
mContext = context; mContext = context;
mCallback = callback; mCallback = callback;
} }
@@ -92,7 +101,11 @@ public class FingerprintUpdater {
public void onEnrollmentProgress(int remaining) { public void onEnrollmentProgress(int remaining) {
mCallback.onEnrollmentProgress(remaining); mCallback.onEnrollmentProgress(remaining);
if (remaining == 0) { if (remaining == 0) {
BiometricsSafetySource.onBiometricsChanged(mContext); // biometrics data changed if (Flags.biometricsOnboardingEducation()) {
FingerprintSafetySource.onBiometricsChanged(mContext);
} else {
BiometricsSafetySource.onBiometricsChanged(mContext); // biometrics data changed
}
} }
} }
@@ -139,7 +152,11 @@ public class FingerprintUpdater {
@Override @Override
public void onRemovalSucceeded(@Nullable Fingerprint fp, int remaining) { public void onRemovalSucceeded(@Nullable Fingerprint fp, int remaining) {
mCallback.onRemovalSucceeded(fp, remaining); mCallback.onRemovalSucceeded(fp, remaining);
BiometricsSafetySource.onBiometricsChanged(mContext); // biometrics data changed if (Flags.biometricsOnboardingEducation()) {
FingerprintSafetySource.onBiometricsChanged(mContext);
} else {
BiometricsSafetySource.onBiometricsChanged(mContext); // biometrics data changed
}
} }
} }

View File

@@ -40,7 +40,8 @@ public class BluetoothKeyMissingDialog extends FragmentActivity {
finish(); finish();
return; return;
} }
BluetoothKeyMissingDialogFragment fragment = new BluetoothKeyMissingDialogFragment(device); BluetoothKeyMissingDialogFragment fragment =
BluetoothKeyMissingDialogFragment.newInstance(device);
fragment.show(getSupportFragmentManager(), FRAGMENT_TAG); fragment.show(getSupportFragmentManager(), FRAGMENT_TAG);
closeSystemDialogs(); closeSystemDialogs();
} }

View File

@@ -31,6 +31,7 @@ import androidx.appcompat.app.AlertDialog;
import com.android.settings.R; import com.android.settings.R;
import com.android.settings.core.instrumentation.InstrumentedDialogFragment; import com.android.settings.core.instrumentation.InstrumentedDialogFragment;
import com.android.settingslib.bluetooth.LocalBluetoothManager;
/** /**
* A dialogFragment used by {@link BluetoothKeyMissingDialog} to create a dialog for the * A dialogFragment used by {@link BluetoothKeyMissingDialog} to create a dialog for the
@@ -40,16 +41,26 @@ public class BluetoothKeyMissingDialogFragment extends InstrumentedDialogFragmen
implements OnClickListener { implements OnClickListener {
private static final String TAG = "BTKeyMissingDialogFragment"; private static final String TAG = "BTKeyMissingDialogFragment";
private static final String KEY_CACHED_DEVICE_ADDRESS = "cached_device";
private BluetoothDevice mBluetoothDevice; private BluetoothDevice mBluetoothDevice;
public BluetoothKeyMissingDialogFragment(@NonNull BluetoothDevice bluetoothDevice) { /** Creates a new instant of the fragment. */
mBluetoothDevice = bluetoothDevice; public static BluetoothKeyMissingDialogFragment newInstance(BluetoothDevice device) {
Bundle args = new Bundle(1);
args.putString(KEY_CACHED_DEVICE_ADDRESS, device.getAddress());
BluetoothKeyMissingDialogFragment fragment = new BluetoothKeyMissingDialogFragment();
fragment.setArguments(args);
return fragment;
} }
@NonNull @NonNull
@Override @Override
public Dialog onCreateDialog(@Nullable Bundle savedInstanceState) { public Dialog onCreateDialog(@Nullable Bundle savedInstanceState) {
String deviceAddress = getArguments().getString(KEY_CACHED_DEVICE_ADDRESS);
LocalBluetoothManager manager = Utils.getLocalBtManager(getContext());
mBluetoothDevice = manager.getBluetoothAdapter().getRemoteDevice(deviceAddress);
AlertDialog.Builder builder = new AlertDialog.Builder(getActivity()); AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
View view = getActivity().getLayoutInflater().inflate(R.layout.bluetooth_key_missing, null); View view = getActivity().getLayoutInflater().inflate(R.layout.bluetooth_key_missing, null);
TextView keyMissingTitle = view.findViewById(R.id.bluetooth_key_missing_title); TextView keyMissingTitle = view.findViewById(R.id.bluetooth_key_missing_title);
@@ -66,7 +77,7 @@ public class BluetoothKeyMissingDialogFragment extends InstrumentedDialogFragmen
@Override @Override
public void onDestroy() { public void onDestroy() {
super.onDestroy(); super.onDestroy();
if (!getActivity().isFinishing()) { if (!getActivity().isChangingConfigurations() && !getActivity().isFinishing()) {
getActivity().finish(); getActivity().finish();
} }
} }

View File

@@ -18,9 +18,12 @@ package com.android.settings.connecteddevice.audiosharing.audiostreams;
import android.app.AlertDialog; import android.app.AlertDialog;
import android.bluetooth.BluetoothLeBroadcastMetadata; import android.bluetooth.BluetoothLeBroadcastMetadata;
import android.text.Editable;
import android.text.TextWatcher;
import android.util.Log; import android.util.Log;
import android.view.LayoutInflater; import android.view.LayoutInflater;
import android.view.View; import android.view.View;
import android.widget.Button;
import android.widget.EditText; import android.widget.EditText;
import android.widget.TextView; import android.widget.TextView;
@@ -109,6 +112,20 @@ class SyncedState extends AudioStreamStateHandler {
controller.handleSourceAddRequest(preference, metadata); controller.handleSourceAddRequest(preference, metadata);
}) })
.create(); .create();
EditText editText = layout.requireViewById(R.id.broadcast_edit_text);
editText.addTextChangedListener(new TextWatcher() {
@Override
public void onTextChanged(CharSequence s, int start, int before, int count) {
alertDialog.getButton(AlertDialog.BUTTON_POSITIVE)
.setEnabled(s.length() >= 4 && s.length() <= 16);
}
@Override
public void beforeTextChanged(CharSequence s, int start, int count, int after) {}
@Override
public void afterTextChanged(Editable s) {}
});
alertDialog.show(); alertDialog.show();
Button positiveButton = alertDialog.getButton(AlertDialog.BUTTON_POSITIVE);
positiveButton.setEnabled(false);
} }
} }

View File

@@ -120,7 +120,9 @@ public abstract class BasePreferenceController extends AbstractPreferenceControl
*/ */
public static final int DISABLED_DEPENDENT_SETTING = 5; public static final int DISABLED_DEPENDENT_SETTING = 5;
@NonNull
protected final String mPreferenceKey; protected final String mPreferenceKey;
@Nullable
protected UiBlockListener mUiBlockListener; protected UiBlockListener mUiBlockListener;
protected boolean mUiBlockerFinished; protected boolean mUiBlockerFinished;
private boolean mIsForWork; private boolean mIsForWork;

View File

@@ -0,0 +1,68 @@
/*
* Copyright (C) 2025 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.safetycenter;
import android.app.PendingIntent;
import android.content.Context;
import android.content.Intent;
import android.safetycenter.SafetyEvent;
import android.safetycenter.SafetySourceData;
import android.safetycenter.SafetySourceStatus;
/** Static helpers for setting SafetyCenter data for biometric safety sources. */
public final class BiometricSourcesUtils {
public static final int REQUEST_CODE_COMBINED_BIOMETRIC_SETTING = 10;
public static final int REQUEST_CODE_FACE_SETTING = 20;
public static final int REQUEST_CODE_FINGERPRINT_SETTING = 30;
private BiometricSourcesUtils() {}
/** Sets data for one of the biometrics sources */
public static void setBiometricSafetySourceData(
String safetySourceId,
Context context,
String title,
String summary,
PendingIntent pendingIntent,
boolean enabled,
boolean hasEnrolled,
SafetyEvent safetyEvent) {
int severityLevel =
enabled && hasEnrolled
? SafetySourceData.SEVERITY_LEVEL_INFORMATION
: SafetySourceData.SEVERITY_LEVEL_UNSPECIFIED;
SafetySourceStatus status =
new SafetySourceStatus.Builder(title, summary, severityLevel)
.setPendingIntent(pendingIntent)
.setEnabled(enabled)
.build();
SafetySourceData safetySourceData =
new SafetySourceData.Builder().setStatus(status).build();
SafetyCenterManagerWrapper.get()
.setSafetySourceData(context, safetySourceId, safetySourceData, safetyEvent);
}
/** Helper method for creating a pending intent. */
public static PendingIntent createPendingIntent(
Context context, Intent intent, int requestCode) {
return PendingIntent.getActivity(
context, requestCode, intent, PendingIntent.FLAG_IMMUTABLE);
}
}

View File

@@ -16,9 +16,11 @@
package com.android.settings.safetycenter; package com.android.settings.safetycenter;
import android.app.PendingIntent; import static com.android.settings.safetycenter.BiometricSourcesUtils.REQUEST_CODE_COMBINED_BIOMETRIC_SETTING;
import static com.android.settings.safetycenter.BiometricSourcesUtils.REQUEST_CODE_FACE_SETTING;
import static com.android.settings.safetycenter.BiometricSourcesUtils.REQUEST_CODE_FINGERPRINT_SETTING;
import android.content.Context; import android.content.Context;
import android.content.Intent;
import android.hardware.face.FaceManager; import android.hardware.face.FaceManager;
import android.hardware.fingerprint.FingerprintManager; import android.hardware.fingerprint.FingerprintManager;
import android.os.Bundle; import android.os.Bundle;
@@ -26,8 +28,6 @@ import android.os.Process;
import android.os.UserHandle; import android.os.UserHandle;
import android.os.UserManager; import android.os.UserManager;
import android.safetycenter.SafetyEvent; import android.safetycenter.SafetyEvent;
import android.safetycenter.SafetySourceData;
import android.safetycenter.SafetySourceStatus;
import com.android.settings.Utils; import com.android.settings.Utils;
import com.android.settings.biometrics.BiometricNavigationUtils; import com.android.settings.biometrics.BiometricNavigationUtils;
@@ -41,9 +41,6 @@ import com.android.settingslib.RestrictedLockUtils;
public final class BiometricsSafetySource { public final class BiometricsSafetySource {
public static final String SAFETY_SOURCE_ID = "AndroidBiometrics"; public static final String SAFETY_SOURCE_ID = "AndroidBiometrics";
private static final int REQUEST_CODE_COMBINED_BIOMETRIC_SETTING = 10;
private static final int REQUEST_CODE_FACE_SETTING = 20;
private static final int REQUEST_CODE_FINGERPRINT_SETTING = 30;
private BiometricsSafetySource() {} private BiometricsSafetySource() {}
@@ -53,42 +50,38 @@ public final class BiometricsSafetySource {
return; return;
} }
final UserHandle userHandle = Process.myUserHandle(); UserHandle userHandle = Process.myUserHandle();
final int userId = userHandle.getIdentifier(); int userId = userHandle.getIdentifier();
final UserManager userManager = UserManager.get(context); UserManager userManager = UserManager.get(context);
UserHandle profileParentUserHandle = userManager.getProfileParent(userHandle); UserHandle profileParentUserHandle = userManager.getProfileParent(userHandle);
if (profileParentUserHandle == null) { if (profileParentUserHandle == null) {
profileParentUserHandle = userHandle; profileParentUserHandle = userHandle;
} }
final Context profileParentContext = Context profileParentContext = context.createContextAsUser(profileParentUserHandle, 0);
context.createContextAsUser(profileParentUserHandle, 0);
if (android.os.Flags.allowPrivateProfile() if (android.os.Flags.allowPrivateProfile()
&& android.multiuser.Flags.enablePrivateSpaceFeatures() && android.multiuser.Flags.enablePrivateSpaceFeatures()
&& userManager.isPrivateProfile()) { && userManager.isPrivateProfile()) {
// SC always expects a response from the source if the broadcast has been sent for this // SC always expects a response from the source if the broadcast has been sent for this
// source, therefore, we need to send a null SafetySourceData. // source, therefore, we need to send a null SafetySourceData.
SafetyCenterManagerWrapper.get().setSafetySourceData( SafetyCenterManagerWrapper.get()
context, .setSafetySourceData(
SAFETY_SOURCE_ID, context, SAFETY_SOURCE_ID, /* safetySourceData= */ null, safetyEvent);
/* safetySourceData= */ null,
safetyEvent);
return; return;
} }
final BiometricNavigationUtils biometricNavigationUtils = BiometricNavigationUtils biometricNavigationUtils = new BiometricNavigationUtils(userId);
new BiometricNavigationUtils(userId); CombinedBiometricStatusUtils combinedBiometricStatusUtils =
final CombinedBiometricStatusUtils combinedBiometricStatusUtils =
new CombinedBiometricStatusUtils(context, userId); new CombinedBiometricStatusUtils(context, userId);
final ActiveUnlockStatusUtils activeUnlockStatusUtils = ActiveUnlockStatusUtils activeUnlockStatusUtils = new ActiveUnlockStatusUtils(context);
new ActiveUnlockStatusUtils(context);
if (!userManager.isProfile() && activeUnlockStatusUtils.isAvailable()) { if (!userManager.isProfile() && activeUnlockStatusUtils.isAvailable()) {
final RestrictedLockUtils.EnforcedAdmin disablingAdmin = RestrictedLockUtils.EnforcedAdmin disablingAdmin =
combinedBiometricStatusUtils.getDisablingAdmin(); combinedBiometricStatusUtils.getDisablingAdmin();
setBiometricSafetySourceData( BiometricSourcesUtils.setBiometricSafetySourceData(
SAFETY_SOURCE_ID,
context, context,
activeUnlockStatusUtils.getTitleForActiveUnlock(), activeUnlockStatusUtils.getTitleForActiveUnlock(),
combinedBiometricStatusUtils.getSummary(), combinedBiometricStatusUtils.getSummary(),
createPendingIntent( BiometricSourcesUtils.createPendingIntent(
context, context,
biometricNavigationUtils.getBiometricSettingsIntent( biometricNavigationUtils.getBiometricSettingsIntent(
context, context,
@@ -102,13 +95,14 @@ public final class BiometricsSafetySource {
return; return;
} }
if (combinedBiometricStatusUtils.isAvailable()) { if (combinedBiometricStatusUtils.isAvailable()) {
final RestrictedLockUtils.EnforcedAdmin disablingAdmin = RestrictedLockUtils.EnforcedAdmin disablingAdmin =
combinedBiometricStatusUtils.getDisablingAdmin(); combinedBiometricStatusUtils.getDisablingAdmin();
setBiometricSafetySourceData( BiometricSourcesUtils.setBiometricSafetySourceData(
SAFETY_SOURCE_ID,
context, context,
combinedBiometricStatusUtils.getTitle(), combinedBiometricStatusUtils.getTitle(),
combinedBiometricStatusUtils.getSummary(), combinedBiometricStatusUtils.getSummary(),
createPendingIntent( BiometricSourcesUtils.createPendingIntent(
profileParentContext, profileParentContext,
biometricNavigationUtils biometricNavigationUtils
.getBiometricSettingsIntent( .getBiometricSettingsIntent(
@@ -125,17 +119,17 @@ public final class BiometricsSafetySource {
return; return;
} }
final FaceManager faceManager = Utils.getFaceManagerOrNull(context); FaceManager faceManager = Utils.getFaceManagerOrNull(context);
final FaceStatusUtils faceStatusUtils = new FaceStatusUtils(context, faceManager, userId); FaceStatusUtils faceStatusUtils = new FaceStatusUtils(context, faceManager, userId);
if (faceStatusUtils.isAvailable()) { if (faceStatusUtils.isAvailable()) {
final RestrictedLockUtils.EnforcedAdmin disablingAdmin = RestrictedLockUtils.EnforcedAdmin disablingAdmin = faceStatusUtils.getDisablingAdmin();
faceStatusUtils.getDisablingAdmin(); BiometricSourcesUtils.setBiometricSafetySourceData(
setBiometricSafetySourceData( SAFETY_SOURCE_ID,
context, context,
faceStatusUtils.getTitle(), faceStatusUtils.getTitle(),
faceStatusUtils.getSummary(), faceStatusUtils.getSummary(),
createPendingIntent( BiometricSourcesUtils.createPendingIntent(
profileParentContext, profileParentContext,
biometricNavigationUtils biometricNavigationUtils
.getBiometricSettingsIntent( .getBiometricSettingsIntent(
@@ -152,18 +146,19 @@ public final class BiometricsSafetySource {
return; return;
} }
final FingerprintManager fingerprintManager = Utils.getFingerprintManagerOrNull(context); FingerprintManager fingerprintManager = Utils.getFingerprintManagerOrNull(context);
final FingerprintStatusUtils fingerprintStatusUtils = FingerprintStatusUtils fingerprintStatusUtils =
new FingerprintStatusUtils(context, fingerprintManager, userId); new FingerprintStatusUtils(context, fingerprintManager, userId);
if (fingerprintStatusUtils.isAvailable()) { if (fingerprintStatusUtils.isAvailable()) {
final RestrictedLockUtils.EnforcedAdmin disablingAdmin = RestrictedLockUtils.EnforcedAdmin disablingAdmin =
fingerprintStatusUtils.getDisablingAdmin(); fingerprintStatusUtils.getDisablingAdmin();
setBiometricSafetySourceData( BiometricSourcesUtils.setBiometricSafetySourceData(
SAFETY_SOURCE_ID,
context, context,
fingerprintStatusUtils.getTitle(), fingerprintStatusUtils.getTitle(),
fingerprintStatusUtils.getSummary(), fingerprintStatusUtils.getSummary(),
createPendingIntent( BiometricSourcesUtils.createPendingIntent(
profileParentContext, profileParentContext,
biometricNavigationUtils biometricNavigationUtils
.getBiometricSettingsIntent( .getBiometricSettingsIntent(
@@ -191,35 +186,4 @@ public final class BiometricsSafetySource {
new SafetyEvent.Builder(SafetyEvent.SAFETY_EVENT_TYPE_SOURCE_STATE_CHANGED) new SafetyEvent.Builder(SafetyEvent.SAFETY_EVENT_TYPE_SOURCE_STATE_CHANGED)
.build()); .build());
} }
private static void setBiometricSafetySourceData(
Context context,
String title,
String summary,
PendingIntent pendingIntent,
boolean enabled,
boolean hasEnrolled,
SafetyEvent safetyEvent) {
final int severityLevel =
enabled && hasEnrolled
? SafetySourceData.SEVERITY_LEVEL_INFORMATION
: SafetySourceData.SEVERITY_LEVEL_UNSPECIFIED;
final SafetySourceStatus status =
new SafetySourceStatus.Builder(title, summary, severityLevel)
.setPendingIntent(pendingIntent)
.setEnabled(enabled)
.build();
final SafetySourceData safetySourceData =
new SafetySourceData.Builder().setStatus(status).build();
SafetyCenterManagerWrapper.get()
.setSafetySourceData(context, SAFETY_SOURCE_ID, safetySourceData, safetyEvent);
}
private static PendingIntent createPendingIntent(
Context context, Intent intent, int requestCode) {
return PendingIntent.getActivity(
context, requestCode, intent, PendingIntent.FLAG_IMMUTABLE);
}
} }

View File

@@ -0,0 +1,107 @@
/*
* Copyright (C) 2025 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.safetycenter;
import static com.android.settings.safetycenter.BiometricSourcesUtils.REQUEST_CODE_FACE_SETTING;
import android.content.Context;
import android.hardware.face.FaceManager;
import android.os.Bundle;
import android.os.Process;
import android.os.UserHandle;
import android.os.UserManager;
import android.safetycenter.SafetyEvent;
import com.android.settings.Utils;
import com.android.settings.biometrics.BiometricNavigationUtils;
import com.android.settings.biometrics.face.FaceStatusUtils;
import com.android.settingslib.RestrictedLockUtils;
/** Face biometrics Safety Source for Safety Center. */
public final class FaceSafetySource {
public static final String SAFETY_SOURCE_ID = "AndroidFaceUnlock";
private FaceSafetySource() {}
/** Sets biometric safety data for Safety Center. */
public static void setSafetySourceData(Context context, SafetyEvent safetyEvent) {
if (!SafetyCenterManagerWrapper.get().isEnabled(context)) {
return;
}
// Handle private profile case
UserManager userManager = UserManager.get(context);
if (android.os.Flags.allowPrivateProfile()
&& android.multiuser.Flags.enablePrivateSpaceFeatures()
&& userManager.isPrivateProfile()) {
// SC always expects a response from the source if the broadcast has been sent for this
// source, therefore, we need to send a null SafetySourceData.
SafetyCenterManagerWrapper.get()
.setSafetySourceData(
context, SAFETY_SOURCE_ID, /* safetySourceData= */ null, safetyEvent);
return;
}
UserHandle userHandle = Process.myUserHandle();
int userId = userHandle.getIdentifier();
FaceManager faceManager = Utils.getFaceManagerOrNull(context);
FaceStatusUtils faceStatusUtils = new FaceStatusUtils(context, faceManager, userId);
BiometricNavigationUtils biometricNavigationUtils = new BiometricNavigationUtils(userId);
UserHandle profileParentUserHandle = userManager.getProfileParent(userHandle);
if (profileParentUserHandle == null) {
profileParentUserHandle = userHandle;
}
Context profileParentContext = context.createContextAsUser(profileParentUserHandle, 0);
if (Utils.hasFaceHardware(context)) {
RestrictedLockUtils.EnforcedAdmin disablingAdmin = faceStatusUtils.getDisablingAdmin();
BiometricSourcesUtils.setBiometricSafetySourceData(
SAFETY_SOURCE_ID,
context,
faceStatusUtils.getTitle(),
faceStatusUtils.getSummary(),
BiometricSourcesUtils.createPendingIntent(
profileParentContext,
biometricNavigationUtils
.getBiometricSettingsIntent(
context,
faceStatusUtils.getSettingsClassName(),
disablingAdmin,
Bundle.EMPTY)
.setIdentifier(Integer.toString(userId)),
REQUEST_CODE_FACE_SETTING),
disablingAdmin == null /* enabled */,
faceStatusUtils.hasEnrolled(),
safetyEvent);
return;
}
SafetyCenterManagerWrapper.get()
.setSafetySourceData(
context, SAFETY_SOURCE_ID, /* safetySourceData= */ null, safetyEvent);
}
/** Notifies Safety Center of a change in face biometrics settings. */
public static void onBiometricsChanged(Context context) {
setSafetySourceData(
context,
new SafetyEvent.Builder(SafetyEvent.SAFETY_EVENT_TYPE_SOURCE_STATE_CHANGED)
.build());
}
}

View File

@@ -0,0 +1,108 @@
/*
* Copyright (C) 2025 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.safetycenter;
import static com.android.settings.safetycenter.BiometricSourcesUtils.REQUEST_CODE_FINGERPRINT_SETTING;
import android.content.Context;
import android.hardware.fingerprint.FingerprintManager;
import android.os.Bundle;
import android.os.Process;
import android.os.UserHandle;
import android.os.UserManager;
import android.safetycenter.SafetyEvent;
import com.android.settings.Utils;
import com.android.settings.biometrics.BiometricNavigationUtils;
import com.android.settings.biometrics.fingerprint.FingerprintStatusUtils;
import com.android.settingslib.RestrictedLockUtils;
/** Fingerprint biometrics Safety Source for Safety Center. */
public final class FingerprintSafetySource {
public static final String SAFETY_SOURCE_ID = "AndroidFingerprintUnlock";
private FingerprintSafetySource() {}
/** Sets biometric safety data for Safety Center. */
public static void setSafetySourceData(Context context, SafetyEvent safetyEvent) {
if (!SafetyCenterManagerWrapper.get().isEnabled(context)) {
return;
}
// Handle private profile case
UserManager userManager = UserManager.get(context);
if (android.os.Flags.allowPrivateProfile()
&& android.multiuser.Flags.enablePrivateSpaceFeatures()
&& userManager.isPrivateProfile()) {
// SC always expects a response from the source if the broadcast has been sent for this
// source, therefore, we need to send a null SafetySourceData.
SafetyCenterManagerWrapper.get()
.setSafetySourceData(
context, SAFETY_SOURCE_ID, /* safetySourceData= */ null, safetyEvent);
return;
}
UserHandle userHandle = Process.myUserHandle();
int userId = userHandle.getIdentifier();
FingerprintManager fingerprintManager = Utils.getFingerprintManagerOrNull(context);
FingerprintStatusUtils fingerprintStatusUtils =
new FingerprintStatusUtils(context, fingerprintManager, userId);
BiometricNavigationUtils biometricNavigationUtils = new BiometricNavigationUtils(userId);
UserHandle profileParentUserHandle = userManager.getProfileParent(userHandle);
if (profileParentUserHandle == null) {
profileParentUserHandle = userHandle;
}
Context profileParentContext = context.createContextAsUser(profileParentUserHandle, 0);
if (Utils.hasFingerprintHardware(context)) {
RestrictedLockUtils.EnforcedAdmin disablingAdmin =
fingerprintStatusUtils.getDisablingAdmin();
BiometricSourcesUtils.setBiometricSafetySourceData(
SAFETY_SOURCE_ID,
context,
fingerprintStatusUtils.getTitle(),
fingerprintStatusUtils.getSummary(),
BiometricSourcesUtils.createPendingIntent(
profileParentContext,
biometricNavigationUtils
.getBiometricSettingsIntent(
context,
fingerprintStatusUtils.getSettingsClassName(),
disablingAdmin,
Bundle.EMPTY)
.setIdentifier(Integer.toString(userId)),
REQUEST_CODE_FINGERPRINT_SETTING),
disablingAdmin == null /* enabled */,
fingerprintStatusUtils.hasEnrolled(),
safetyEvent);
return;
}
SafetyCenterManagerWrapper.get()
.setSafetySourceData(
context, SAFETY_SOURCE_ID, /* safetySourceData= */ null, safetyEvent);
}
/** Notifies Safety Center of a change in fingerprint biometrics settings. */
public static void onBiometricsChanged(Context context) {
setSafetySourceData(
context,
new SafetyEvent.Builder(SafetyEvent.SAFETY_EVENT_TYPE_SOURCE_STATE_CHANGED)
.build());
}
}

View File

@@ -31,6 +31,7 @@ import android.safetycenter.SafetySourceStatus;
import android.safetycenter.SafetySourceStatus.IconAction; import android.safetycenter.SafetySourceStatus.IconAction;
import com.android.settings.R; import com.android.settings.R;
import com.android.settings.flags.Flags;
import com.android.settings.security.ScreenLockPreferenceDetailsUtils; import com.android.settings.security.ScreenLockPreferenceDetailsUtils;
import com.android.settingslib.RestrictedLockUtils; import com.android.settingslib.RestrictedLockUtils;
import com.android.settingslib.RestrictedLockUtilsInternal; import com.android.settingslib.RestrictedLockUtilsInternal;
@@ -122,7 +123,12 @@ public final class LockScreenSafetySource {
// Also send refreshed safety center data for biometrics, since changing lockscreen settings // Also send refreshed safety center data for biometrics, since changing lockscreen settings
// can unset biometrics. // can unset biometrics.
BiometricsSafetySource.onBiometricsChanged(context); if (Flags.biometricsOnboardingEducation()) {
FaceSafetySource.onBiometricsChanged(context);
FingerprintSafetySource.onBiometricsChanged(context);
} else {
BiometricsSafetySource.onBiometricsChanged(context);
}
} }
private static IconAction createGearMenuIconAction( private static IconAction createGearMenuIconAction(

View File

@@ -28,6 +28,7 @@ import android.content.Intent;
import android.safetycenter.SafetyCenterManager; import android.safetycenter.SafetyCenterManager;
import android.safetycenter.SafetyEvent; import android.safetycenter.SafetyEvent;
import com.android.settings.flags.Flags;
import com.android.settings.privatespace.PrivateSpaceSafetySource; import com.android.settings.privatespace.PrivateSpaceSafetySource;
import com.android.settings.security.ScreenLockPreferenceDetailsUtils; import com.android.settings.security.ScreenLockPreferenceDetailsUtils;
@@ -48,48 +49,60 @@ public class SafetySourceBroadcastReceiver extends BroadcastReceiver {
} }
if (ACTION_REFRESH_SAFETY_SOURCES.equals(intent.getAction())) { if (ACTION_REFRESH_SAFETY_SOURCES.equals(intent.getAction())) {
String[] sourceIdsExtra = String[] sourceIdsExtra = intent.getStringArrayExtra(EXTRA_REFRESH_SAFETY_SOURCE_IDS);
intent.getStringArrayExtra(EXTRA_REFRESH_SAFETY_SOURCE_IDS); final String refreshBroadcastId =
final String refreshBroadcastId = intent.getStringExtra( intent.getStringExtra(
SafetyCenterManager.EXTRA_REFRESH_SAFETY_SOURCES_BROADCAST_ID); SafetyCenterManager.EXTRA_REFRESH_SAFETY_SOURCES_BROADCAST_ID);
if (sourceIdsExtra != null && sourceIdsExtra.length > 0 && refreshBroadcastId != null) { if (sourceIdsExtra != null && sourceIdsExtra.length > 0 && refreshBroadcastId != null) {
final SafetyEvent safetyEvent = new SafetyEvent.Builder( final SafetyEvent safetyEvent =
SAFETY_EVENT_TYPE_REFRESH_REQUESTED) new SafetyEvent.Builder(SAFETY_EVENT_TYPE_REFRESH_REQUESTED)
.setRefreshBroadcastId(refreshBroadcastId).build(); .setRefreshBroadcastId(refreshBroadcastId)
refreshSafetySources( .build();
context, refreshSafetySources(context, ImmutableList.copyOf(sourceIdsExtra), safetyEvent);
ImmutableList.copyOf(sourceIdsExtra),
safetyEvent);
} }
return; return;
} }
if (ACTION_BOOT_COMPLETED.equals(intent.getAction())) { if (ACTION_BOOT_COMPLETED.equals(intent.getAction())) {
refreshAllSafetySources(context, EVENT_DEVICE_REBOOTED); refreshAllSafetySources(context, EVENT_DEVICE_REBOOTED);
} }
} }
private static void refreshSafetySources(Context context, List<String> sourceIds, private static void refreshSafetySources(
SafetyEvent safetyEvent) { Context context, List<String> sourceIds, SafetyEvent safetyEvent) {
if (sourceIds.contains(LockScreenSafetySource.SAFETY_SOURCE_ID)) { if (sourceIds.contains(LockScreenSafetySource.SAFETY_SOURCE_ID)) {
LockScreenSafetySource.setSafetySourceData(context, LockScreenSafetySource.setSafetySourceData(
new ScreenLockPreferenceDetailsUtils(context), safetyEvent); context, new ScreenLockPreferenceDetailsUtils(context), safetyEvent);
} }
if (sourceIds.contains(BiometricsSafetySource.SAFETY_SOURCE_ID)) { if (sourceIds.contains(BiometricsSafetySource.SAFETY_SOURCE_ID)
&& !Flags.biometricsOnboardingEducation()) {
BiometricsSafetySource.setSafetySourceData(context, safetyEvent); BiometricsSafetySource.setSafetySourceData(context, safetyEvent);
} }
if (sourceIds.contains(PrivateSpaceSafetySource.SAFETY_SOURCE_ID)) { if (sourceIds.contains(PrivateSpaceSafetySource.SAFETY_SOURCE_ID)) {
PrivateSpaceSafetySource.setSafetySourceData(context, safetyEvent); PrivateSpaceSafetySource.setSafetySourceData(context, safetyEvent);
} }
if (sourceIds.contains(FaceSafetySource.SAFETY_SOURCE_ID)
&& Flags.biometricsOnboardingEducation()) {
FaceSafetySource.setSafetySourceData(context, safetyEvent);
}
if (sourceIds.contains(FingerprintSafetySource.SAFETY_SOURCE_ID)
&& Flags.biometricsOnboardingEducation()) {
FingerprintSafetySource.setSafetySourceData(context, safetyEvent);
}
} }
private static void refreshAllSafetySources(Context context, SafetyEvent safetyEvent) { private static void refreshAllSafetySources(Context context, SafetyEvent safetyEvent) {
LockScreenSafetySource.setSafetySourceData(context, LockScreenSafetySource.setSafetySourceData(
new ScreenLockPreferenceDetailsUtils(context), safetyEvent); context, new ScreenLockPreferenceDetailsUtils(context), safetyEvent);
BiometricsSafetySource.setSafetySourceData(context, safetyEvent); if (!Flags.biometricsOnboardingEducation()) {
BiometricsSafetySource.setSafetySourceData(context, safetyEvent);
}
PrivateSpaceSafetySource.setSafetySourceData(context, safetyEvent); PrivateSpaceSafetySource.setSafetySourceData(context, safetyEvent);
if (Flags.biometricsOnboardingEducation()) {
FaceSafetySource.setSafetySourceData(context, safetyEvent);
FingerprintSafetySource.setSafetySourceData(context, safetyEvent);
}
} }
} }

View File

@@ -34,12 +34,12 @@ import com.android.settingslib.spa.framework.util.mapItem
import com.android.settingslib.spaprivileged.model.app.AppEntry import com.android.settingslib.spaprivileged.model.app.AppEntry
import com.android.settingslib.spaprivileged.model.app.AppListModel import com.android.settingslib.spaprivileged.model.app.AppListModel
import com.android.settingslib.spaprivileged.model.app.AppRecord import com.android.settingslib.spaprivileged.model.app.AppRecord
import com.android.settingslib.spaprivileged.model.app.AppStorageRepositoryImpl
import com.android.settingslib.spaprivileged.template.app.AppList import com.android.settingslib.spaprivileged.template.app.AppList
import com.android.settingslib.spaprivileged.template.app.AppListInput import com.android.settingslib.spaprivileged.template.app.AppListInput
import com.android.settingslib.spaprivileged.template.app.AppListItem import com.android.settingslib.spaprivileged.template.app.AppListItem
import com.android.settingslib.spaprivileged.template.app.AppListItemModel import com.android.settingslib.spaprivileged.template.app.AppListItemModel
import com.android.settingslib.spaprivileged.template.app.AppListPage import com.android.settingslib.spaprivileged.template.app.AppListPage
import com.android.settingslib.spaprivileged.template.app.calculateSizeBytes
import com.android.settingslib.spaprivileged.template.app.getStorageSize import com.android.settingslib.spaprivileged.template.app.getStorageSize
import kotlinx.coroutines.flow.Flow import kotlinx.coroutines.flow.Flow
@@ -109,9 +109,11 @@ class StorageAppListModel(
getStorageSize() getStorageSize()
} }
) : AppListModel<AppRecordWithSize> { ) : AppListModel<AppRecordWithSize> {
private val appStorageRepository = AppStorageRepositoryImpl(context)
override fun transform(userIdFlow: Flow<Int>, appListFlow: Flow<List<ApplicationInfo>>) = override fun transform(userIdFlow: Flow<Int>, appListFlow: Flow<List<ApplicationInfo>>) =
appListFlow.mapItem { appListFlow.mapItem { app ->
AppRecordWithSize(it, it.calculateSizeBytes(context) ?: 0L) AppRecordWithSize(app, appStorageRepository.calculateSizeBytes(app) ?: 0L)
} }
override fun filter( override fun filter(

View File

@@ -0,0 +1,69 @@
/*
* Copyright 2025 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.accessibility;
import static com.google.common.truth.Truth.assertThat;
import android.content.Context;
import android.platform.test.annotations.DisableFlags;
import android.platform.test.annotations.EnableFlags;
import android.platform.test.flag.junit.SetFlagsRule;
import androidx.test.core.app.ApplicationProvider;
import com.android.settings.core.BasePreferenceController;
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.MockitoRule;
import org.robolectric.RobolectricTestRunner;
/** Tests for {@link ToggleAutoclickIgnoreMinorCursorMovementController}. */
@RunWith(RobolectricTestRunner.class)
public class ToggleAutoclickIgnoreMinorCursorMovementControllerTest {
private static final String PREFERENCE_KEY =
"accessibility_control_autoclick_ignore_minor_cursor_movement";
@Rule public final SetFlagsRule mSetFlagsRule = new SetFlagsRule();
@Rule public final MockitoRule mMockitoRule = MockitoJUnit.rule();
private final Context mContext = ApplicationProvider.getApplicationContext();
private ToggleAutoclickIgnoreMinorCursorMovementController mController;
@Before
public void setUp() {
mController =
new ToggleAutoclickIgnoreMinorCursorMovementController(mContext, PREFERENCE_KEY);
}
@Test
@EnableFlags(com.android.server.accessibility.Flags.FLAG_ENABLE_AUTOCLICK_INDICATOR)
public void getAvailabilityStatus_availableWhenFlagOn() {
assertThat(mController.getAvailabilityStatus())
.isEqualTo(BasePreferenceController.AVAILABLE);
}
@Test
@DisableFlags(com.android.server.accessibility.Flags.FLAG_ENABLE_AUTOCLICK_INDICATOR)
public void getAvailabilityStatus_conditionallyUnavailableWhenFlagOn() {
assertThat(mController.getAvailabilityStatus())
.isEqualTo(BasePreferenceController.CONDITIONALLY_UNAVAILABLE);
}
}

View File

@@ -83,10 +83,10 @@ public class AppStorageSizesControllerTest {
mController.setResult(result); mController.setResult(result);
mController.updateUi(mContext); mController.updateUi(mContext);
assertThat(mAppPreference.getSummary()).isEqualTo("1 B"); assertThat(mAppPreference.getSummary()).isEqualTo("1 byte");
assertThat(mCachePreference.getSummary()).isEqualTo("10 B"); assertThat(mCachePreference.getSummary()).isEqualTo("10 byte");
assertThat(mDataPreference.getSummary()).isEqualTo("90 B"); assertThat(mDataPreference.getSummary()).isEqualTo("90 byte");
assertThat(mTotalPreference.getSummary()).isEqualTo("101 B"); assertThat(mTotalPreference.getSummary()).isEqualTo("101 byte");
} }
@Test @Test
@@ -101,10 +101,10 @@ public class AppStorageSizesControllerTest {
mController.setCacheCleared(true); mController.setCacheCleared(true);
mController.updateUi(mContext); mController.updateUi(mContext);
assertThat(mAppPreference.getSummary()).isEqualTo("1 B"); assertThat(mAppPreference.getSummary()).isEqualTo("1 byte");
assertThat(mCachePreference.getSummary()).isEqualTo("0 B"); assertThat(mCachePreference.getSummary()).isEqualTo("0 byte");
assertThat(mDataPreference.getSummary()).isEqualTo("90 B"); assertThat(mDataPreference.getSummary()).isEqualTo("90 byte");
assertThat(mTotalPreference.getSummary()).isEqualTo("91 B"); assertThat(mTotalPreference.getSummary()).isEqualTo("91 byte");
} }
@Test @Test
@@ -119,9 +119,9 @@ public class AppStorageSizesControllerTest {
mController.setDataCleared(true); mController.setDataCleared(true);
mController.updateUi(mContext); mController.updateUi(mContext);
assertThat(mAppPreference.getSummary()).isEqualTo("1 B"); assertThat(mAppPreference.getSummary()).isEqualTo("1 byte");
assertThat(mCachePreference.getSummary()).isEqualTo("0 B"); assertThat(mCachePreference.getSummary()).isEqualTo("0 byte");
assertThat(mDataPreference.getSummary()).isEqualTo("0 B"); assertThat(mDataPreference.getSummary()).isEqualTo("0 byte");
assertThat(mTotalPreference.getSummary()).isEqualTo("1 B"); assertThat(mTotalPreference.getSummary()).isEqualTo("1 byte");
} }
} }

View File

@@ -19,6 +19,7 @@ import static com.google.common.truth.Truth.assertThat;
import static org.mockito.Mockito.never; import static org.mockito.Mockito.never;
import static org.mockito.Mockito.verify; import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
import static org.robolectric.shadows.ShadowLooper.shadowMainLooper; import static org.robolectric.shadows.ShadowLooper.shadowMainLooper;
import android.bluetooth.BluetoothDevice; import android.bluetooth.BluetoothDevice;
@@ -27,10 +28,13 @@ import androidx.appcompat.app.AlertDialog;
import androidx.fragment.app.FragmentActivity; import androidx.fragment.app.FragmentActivity;
import com.android.settings.testutils.shadow.ShadowAlertDialogCompat; import com.android.settings.testutils.shadow.ShadowAlertDialogCompat;
import com.android.settings.testutils.shadow.ShadowBluetoothUtils;
import com.android.settingslib.bluetooth.LocalBluetoothManager;
import org.junit.Before; import org.junit.Before;
import org.junit.Test; import org.junit.Test;
import org.junit.runner.RunWith; import org.junit.runner.RunWith;
import org.mockito.Answers;
import org.mockito.Mock; import org.mockito.Mock;
import org.mockito.MockitoAnnotations; import org.mockito.MockitoAnnotations;
import org.robolectric.Robolectric; import org.robolectric.Robolectric;
@@ -38,18 +42,26 @@ import org.robolectric.RobolectricTestRunner;
import org.robolectric.annotation.Config; import org.robolectric.annotation.Config;
@RunWith(RobolectricTestRunner.class) @RunWith(RobolectricTestRunner.class)
@Config(shadows = ShadowAlertDialogCompat.class) @Config(shadows = {ShadowAlertDialogCompat.class, ShadowBluetoothUtils.class})
public class BluetoothKeyMissingDialogTest { public class BluetoothKeyMissingDialogTest {
@Mock private BluetoothDevice mBluetoothDevice; @Mock private BluetoothDevice mBluetoothDevice;
@Mock(answer = Answers.RETURNS_DEEP_STUBS)
private LocalBluetoothManager mLocalBtManager;
private BluetoothKeyMissingDialogFragment mFragment = null; private BluetoothKeyMissingDialogFragment mFragment = null;
private FragmentActivity mActivity = null; private FragmentActivity mActivity = null;
private static final String MAC_ADDRESS = "12:34:56:78:90:12";
@Before @Before
public void setUp() { public void setUp() {
MockitoAnnotations.initMocks(this); MockitoAnnotations.initMocks(this);
when(mBluetoothDevice.getAddress()).thenReturn(MAC_ADDRESS);
when(mLocalBtManager.getBluetoothAdapter().getRemoteDevice(MAC_ADDRESS))
.thenReturn(mBluetoothDevice);
ShadowBluetoothUtils.sLocalBluetoothManager = mLocalBtManager;
mActivity = Robolectric.setupActivity(FragmentActivity.class); mActivity = Robolectric.setupActivity(FragmentActivity.class);
mFragment = new BluetoothKeyMissingDialogFragment(mBluetoothDevice); mFragment = BluetoothKeyMissingDialogFragment.newInstance(mBluetoothDevice);
mActivity mActivity
.getSupportFragmentManager() .getSupportFragmentManager()
.beginTransaction() .beginTransaction()

View File

@@ -30,6 +30,7 @@ import android.bluetooth.BluetoothLeBroadcastMetadata;
import android.content.Context; import android.content.Context;
import android.content.DialogInterface; import android.content.DialogInterface;
import android.widget.Button; import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView; import android.widget.TextView;
import androidx.preference.Preference; import androidx.preference.Preference;
@@ -59,6 +60,8 @@ import org.robolectric.shadows.ShadowLooper;
}) })
public class SyncedStateTest { public class SyncedStateTest {
@Rule public final MockitoRule mMockitoRule = MockitoJUnit.rule(); @Rule public final MockitoRule mMockitoRule = MockitoJUnit.rule();
private static final String INVALID_PASSWORD = "PAS";
private static final String VALID_PASSWORD = "PASSWORD";
private static final String ENCRYPTED_METADATA = private static final String ENCRYPTED_METADATA =
"BLUETOOTH:UUID:184F;BN:VGVzdA==;AT:1;AD:00A1A1A1A1A1;BI:1E240;BC:VGVzdENvZGU=;" "BLUETOOTH:UUID:184F;BN:VGVzdA==;AT:1;AD:00A1A1A1A1A1;BI:1E240;BC:VGVzdENvZGU=;"
+ "MD:BgNwVGVzdA==;AS:1;PI:A0;NS:1;BS:3;NB:2;SM:BQNUZXN0BARlbmc=;;"; + "MD:BgNwVGVzdA==;AS:1;PI:A0;NS:1;BS:3;NB:2;SM:BQNUZXN0BARlbmc=;;";
@@ -143,15 +146,24 @@ public class SyncedStateTest {
Button positiveButton = dialog.getButton(DialogInterface.BUTTON_POSITIVE); Button positiveButton = dialog.getButton(DialogInterface.BUTTON_POSITIVE);
assertThat(positiveButton).isNotNull(); assertThat(positiveButton).isNotNull();
assertThat(positiveButton.isEnabled()).isFalse();
assertThat(positiveButton.getText().toString()) assertThat(positiveButton.getText().toString())
.isEqualTo( .isEqualTo(
mMockContext.getString(R.string.bluetooth_connect_access_dialog_positive)); mMockContext.getString(R.string.bluetooth_connect_access_dialog_positive));
ShadowAlertDialog shadowDialog = Shadow.extract(dialog);
EditText editText = shadowDialog.getView().findViewById(R.id.broadcast_edit_text);
assertThat(editText).isNotNull();
editText.setText(VALID_PASSWORD);
assertThat(positiveButton.isEnabled()).isTrue();
editText.setText(INVALID_PASSWORD);
assertThat(positiveButton.isEnabled()).isFalse();
editText.setText(VALID_PASSWORD);
positiveButton.callOnClick(); positiveButton.callOnClick();
ShadowLooper.idleMainLooper(); ShadowLooper.idleMainLooper();
verify(mMockController).handleSourceAddRequest(any(), any()); verify(mMockController).handleSourceAddRequest(any(), any());
ShadowAlertDialog shadowDialog = Shadow.extract(dialog);
TextView title = shadowDialog.getView().findViewById(R.id.broadcast_name_text); TextView title = shadowDialog.getView().findViewById(R.id.broadcast_name_text);
assertThat(title).isNotNull(); assertThat(title).isNotNull();
assertThat(title.getText().toString()).isEqualTo(BROADCAST_TITLE); assertThat(title.getText().toString()).isEqualTo(BROADCAST_TITLE);

View File

@@ -89,7 +89,7 @@ class AppStoragePreferenceTest {
composeTestRule.onNodeWithText(context.getString(R.string.storage_settings_for_app)) composeTestRule.onNodeWithText(context.getString(R.string.storage_settings_for_app))
.assertIsDisplayed() .assertIsDisplayed()
composeTestRule.waitUntilExists(hasText("120 B used in internal storage")) composeTestRule.waitUntilExists(hasText("120 byte used in internal storage"))
} }
@Test @Test
@@ -104,7 +104,7 @@ class AppStoragePreferenceTest {
composeTestRule.onNodeWithText(context.getString(R.string.storage_settings_for_app)) composeTestRule.onNodeWithText(context.getString(R.string.storage_settings_for_app))
.assertIsDisplayed() .assertIsDisplayed()
composeTestRule.waitUntilExists(hasText("120 B used in external storage")) composeTestRule.waitUntilExists(hasText("120 byte used in external storage"))
} }
private fun setContent(app: ApplicationInfo) { private fun setContent(app: ApplicationInfo) {
@@ -122,7 +122,6 @@ class AppStoragePreferenceTest {
private val STATS = StorageStats().apply { private val STATS = StorageStats().apply {
codeBytes = 100 codeBytes = 100
dataBytes = 20 dataBytes = 20
cacheBytes = 3
} }
} }
} }

View File

@@ -39,6 +39,9 @@ import android.hardware.face.FaceManager;
import android.hardware.fingerprint.Fingerprint; import android.hardware.fingerprint.Fingerprint;
import android.hardware.fingerprint.FingerprintManager; import android.hardware.fingerprint.FingerprintManager;
import android.os.UserHandle; import android.os.UserHandle;
import android.platform.test.annotations.RequiresFlagsDisabled;
import android.platform.test.flag.junit.CheckFlagsRule;
import android.platform.test.flag.junit.DeviceFlagsValueProvider;
import android.safetycenter.SafetyEvent; import android.safetycenter.SafetyEvent;
import android.safetycenter.SafetySourceData; import android.safetycenter.SafetySourceData;
import android.safetycenter.SafetySourceStatus; import android.safetycenter.SafetySourceStatus;
@@ -50,6 +53,7 @@ import com.android.internal.widget.LockPatternUtils;
import com.android.settings.Settings; import com.android.settings.Settings;
import com.android.settings.biometrics.face.FaceEnrollIntroductionInternal; import com.android.settings.biometrics.face.FaceEnrollIntroductionInternal;
import com.android.settings.biometrics.fingerprint.FingerprintSettings; import com.android.settings.biometrics.fingerprint.FingerprintSettings;
import com.android.settings.flags.Flags;
import com.android.settings.testutils.ActiveUnlockTestUtils; import com.android.settings.testutils.ActiveUnlockTestUtils;
import com.android.settings.testutils.FakeFeatureFactory; import com.android.settings.testutils.FakeFeatureFactory;
import com.android.settings.testutils.ResourcesUtils; import com.android.settings.testutils.ResourcesUtils;
@@ -57,6 +61,7 @@ import com.android.settingslib.utils.StringUtil;
import org.junit.After; import org.junit.After;
import org.junit.Before; import org.junit.Before;
import org.junit.Rule;
import org.junit.Test; import org.junit.Test;
import org.junit.runner.RunWith; import org.junit.runner.RunWith;
import org.mockito.ArgumentCaptor; import org.mockito.ArgumentCaptor;
@@ -67,6 +72,7 @@ import java.util.ArrayList;
import java.util.Collections; import java.util.Collections;
import java.util.List; import java.util.List;
@RequiresFlagsDisabled(Flags.FLAG_BIOMETRICS_ONBOARDING_EDUCATION)
@RunWith(AndroidJUnit4.class) @RunWith(AndroidJUnit4.class)
public class BiometricsSafetySourceTest { public class BiometricsSafetySourceTest {
@@ -75,6 +81,9 @@ public class BiometricsSafetySourceTest {
private static final SafetyEvent EVENT_SOURCE_STATE_CHANGED = private static final SafetyEvent EVENT_SOURCE_STATE_CHANGED =
new SafetyEvent.Builder(SAFETY_EVENT_TYPE_SOURCE_STATE_CHANGED).build(); new SafetyEvent.Builder(SAFETY_EVENT_TYPE_SOURCE_STATE_CHANGED).build();
@Rule
public final CheckFlagsRule mCheckFlagsRule = DeviceFlagsValueProvider.createCheckFlagsRule();
private Context mApplicationContext; private Context mApplicationContext;
@Mock private PackageManager mPackageManager; @Mock private PackageManager mPackageManager;
@@ -196,7 +205,7 @@ public class BiometricsSafetySourceTest {
@Test @Test
public void setSafetySourceData_withFingerprintsEnrolled_whenDisabledByAdmin_setsData() { public void setSafetySourceData_withFingerprintsEnrolled_whenDisabledByAdmin_setsData() {
final int enrolledFingerprintsCount = 2; int enrolledFingerprintsCount = 2;
when(mSafetyCenterManagerWrapper.isEnabled(mApplicationContext)).thenReturn(true); when(mSafetyCenterManagerWrapper.isEnabled(mApplicationContext)).thenReturn(true);
when(mFingerprintManager.isHardwareDetected()).thenReturn(true); when(mFingerprintManager.isHardwareDetected()).thenReturn(true);
when(mFaceManager.isHardwareDetected()).thenReturn(false); when(mFaceManager.isHardwareDetected()).thenReturn(false);
@@ -216,7 +225,7 @@ public class BiometricsSafetySourceTest {
@Test @Test
public void setSafetySourceData_withFingerprintsEnrolled_whenNotDisabledByAdmin_setsData() { public void setSafetySourceData_withFingerprintsEnrolled_whenNotDisabledByAdmin_setsData() {
final int enrolledFingerprintsCount = 2; int enrolledFingerprintsCount = 2;
when(mSafetyCenterManagerWrapper.isEnabled(mApplicationContext)).thenReturn(true); when(mSafetyCenterManagerWrapper.isEnabled(mApplicationContext)).thenReturn(true);
when(mFingerprintManager.isHardwareDetected()).thenReturn(true); when(mFingerprintManager.isHardwareDetected()).thenReturn(true);
when(mFaceManager.isHardwareDetected()).thenReturn(false); when(mFaceManager.isHardwareDetected()).thenReturn(false);
@@ -364,7 +373,7 @@ public class BiometricsSafetySourceTest {
@Test @Test
public void setSafetySourceData_faceAndFingerprint_whenFaceEnrolled_withMpFingers_setsData() { public void setSafetySourceData_faceAndFingerprint_whenFaceEnrolled_withMpFingers_setsData() {
final int enrolledFingerprintsCount = 2; int enrolledFingerprintsCount = 2;
when(mSafetyCenterManagerWrapper.isEnabled(mApplicationContext)).thenReturn(true); when(mSafetyCenterManagerWrapper.isEnabled(mApplicationContext)).thenReturn(true);
when(mFingerprintManager.isHardwareDetected()).thenReturn(true); when(mFingerprintManager.isHardwareDetected()).thenReturn(true);
when(mFaceManager.isHardwareDetected()).thenReturn(true); when(mFaceManager.isHardwareDetected()).thenReturn(true);
@@ -382,7 +391,7 @@ public class BiometricsSafetySourceTest {
@Test @Test
public void setSafetySourceData_faceAndFingerprint_whenFaceEnrolled_withOneFinger_setsData() { public void setSafetySourceData_faceAndFingerprint_whenFaceEnrolled_withOneFinger_setsData() {
final int enrolledFingerprintsCount = 1; int enrolledFingerprintsCount = 1;
when(mSafetyCenterManagerWrapper.isEnabled(mApplicationContext)).thenReturn(true); when(mSafetyCenterManagerWrapper.isEnabled(mApplicationContext)).thenReturn(true);
when(mFingerprintManager.isHardwareDetected()).thenReturn(true); when(mFingerprintManager.isHardwareDetected()).thenReturn(true);
when(mFaceManager.isHardwareDetected()).thenReturn(true); when(mFaceManager.isHardwareDetected()).thenReturn(true);
@@ -417,7 +426,7 @@ public class BiometricsSafetySourceTest {
@Test @Test
public void setSafetySourceData_activeUnlockEnabled_withFingerprintOnly_setsData() { public void setSafetySourceData_activeUnlockEnabled_withFingerprintOnly_setsData() {
final int enrolledFingerprintsCount = 1; int enrolledFingerprintsCount = 1;
when(mSafetyCenterManagerWrapper.isEnabled(mApplicationContext)).thenReturn(true); when(mSafetyCenterManagerWrapper.isEnabled(mApplicationContext)).thenReturn(true);
when(mFingerprintManager.isHardwareDetected()).thenReturn(true); when(mFingerprintManager.isHardwareDetected()).thenReturn(true);
when(mFaceManager.isHardwareDetected()).thenReturn(false); when(mFaceManager.isHardwareDetected()).thenReturn(false);
@@ -453,7 +462,7 @@ public class BiometricsSafetySourceTest {
@Test @Test
public void setSafetySourceData_activeUnlockEnabled_withFaceAndFingerprint_setsData() { public void setSafetySourceData_activeUnlockEnabled_withFaceAndFingerprint_setsData() {
final int enrolledFingerprintsCount = 1; int enrolledFingerprintsCount = 1;
when(mSafetyCenterManagerWrapper.isEnabled(mApplicationContext)).thenReturn(true); when(mSafetyCenterManagerWrapper.isEnabled(mApplicationContext)).thenReturn(true);
when(mFingerprintManager.isHardwareDetected()).thenReturn(true); when(mFingerprintManager.isHardwareDetected()).thenReturn(true);
when(mFaceManager.isHardwareDetected()).thenReturn(true); when(mFaceManager.isHardwareDetected()).thenReturn(true);
@@ -472,7 +481,7 @@ public class BiometricsSafetySourceTest {
@Test @Test
public void setSafetySourceData_faceAndFingerprint_whenNoFaceEnrolled_withFingers_setsData() { public void setSafetySourceData_faceAndFingerprint_whenNoFaceEnrolled_withFingers_setsData() {
final int enrolledFingerprintsCount = 1; int enrolledFingerprintsCount = 1;
when(mSafetyCenterManagerWrapper.isEnabled(mApplicationContext)).thenReturn(true); when(mSafetyCenterManagerWrapper.isEnabled(mApplicationContext)).thenReturn(true);
when(mFingerprintManager.isHardwareDetected()).thenReturn(true); when(mFingerprintManager.isHardwareDetected()).thenReturn(true);
when(mFaceManager.isHardwareDetected()).thenReturn(true); when(mFaceManager.isHardwareDetected()).thenReturn(true);
@@ -660,7 +669,7 @@ public class BiometricsSafetySourceTest {
String expectedTitleResName, String expectedTitleResName,
String expectedSummaryResName, String expectedSummaryResName,
int expectedSummaryQuantity) { int expectedSummaryQuantity) {
final int stringResId = int stringResId =
ResourcesUtils.getResourcesId( ResourcesUtils.getResourcesId(
ApplicationProvider.getApplicationContext(), ApplicationProvider.getApplicationContext(),
"string", "string",
@@ -676,7 +685,7 @@ public class BiometricsSafetySourceTest {
String expectedSummaryResName, String expectedSummaryResName,
int expectedSummaryQuantity, int expectedSummaryQuantity,
String expectedSettingsClassName) { String expectedSettingsClassName) {
final int stringResId = int stringResId =
ResourcesUtils.getResourcesId( ResourcesUtils.getResourcesId(
ApplicationProvider.getApplicationContext(), ApplicationProvider.getApplicationContext(),
"string", "string",
@@ -705,7 +714,7 @@ public class BiometricsSafetySourceTest {
assertThat(safetySourceStatus.getSeverityLevel()) assertThat(safetySourceStatus.getSeverityLevel())
.isEqualTo(SafetySourceData.SEVERITY_LEVEL_UNSPECIFIED); .isEqualTo(SafetySourceData.SEVERITY_LEVEL_UNSPECIFIED);
final Intent clickIntent = safetySourceStatus.getPendingIntent().getIntent(); Intent clickIntent = safetySourceStatus.getPendingIntent().getIntent();
assertThat(clickIntent).isNotNull(); assertThat(clickIntent).isNotNull();
assertThat(clickIntent.getAction()).isEqualTo(ACTION_SHOW_ADMIN_SUPPORT_DETAILS); assertThat(clickIntent.getAction()).isEqualTo(ACTION_SHOW_ADMIN_SUPPORT_DETAILS);
} }
@@ -725,14 +734,14 @@ public class BiometricsSafetySourceTest {
assertThat(safetySourceStatus.getTitle().toString()).isEqualTo(expectedTitle); assertThat(safetySourceStatus.getTitle().toString()).isEqualTo(expectedTitle);
assertThat(safetySourceStatus.getSummary().toString()).isEqualTo(expectedSummary); assertThat(safetySourceStatus.getSummary().toString()).isEqualTo(expectedSummary);
assertThat(safetySourceStatus.isEnabled()).isTrue(); assertThat(safetySourceStatus.isEnabled()).isTrue();
final Intent clickIntent = safetySourceStatus.getPendingIntent().getIntent(); Intent clickIntent = safetySourceStatus.getPendingIntent().getIntent();
assertThat(clickIntent).isNotNull(); assertThat(clickIntent).isNotNull();
assertThat(clickIntent.getComponent().getPackageName()).isEqualTo("com.android.settings"); assertThat(clickIntent.getComponent().getPackageName()).isEqualTo("com.android.settings");
assertThat(clickIntent.getComponent().getClassName()).isEqualTo(expectedSettingsClassName); assertThat(clickIntent.getComponent().getClassName()).isEqualTo(expectedSettingsClassName);
} }
private List<Fingerprint> createFingerprintList(int size) { private List<Fingerprint> createFingerprintList(int size) {
final List<Fingerprint> fingerprintList = new ArrayList<>(size); List<Fingerprint> fingerprintList = new ArrayList<>(size);
for (int i = 0; i < size; i++) { for (int i = 0; i < size; i++) {
fingerprintList.add(new Fingerprint("fingerprint" + i, 0, 0)); fingerprintList.add(new Fingerprint("fingerprint" + i, 0, 0));
} }

View File

@@ -0,0 +1,302 @@
/*
* 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.safetycenter;
import static android.provider.Settings.ACTION_SHOW_ADMIN_SUPPORT_DETAILS;
import static android.safetycenter.SafetyEvent.SAFETY_EVENT_TYPE_SOURCE_STATE_CHANGED;
import static com.google.common.truth.Truth.assertThat;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.ArgumentMatchers.anyInt;
import static org.mockito.ArgumentMatchers.eq;
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.app.admin.DevicePolicyManager;
import android.content.ComponentName;
import android.content.Context;
import android.content.Intent;
import android.content.pm.PackageManager;
import android.hardware.face.FaceManager;
import android.os.UserHandle;
import android.platform.test.annotations.RequiresFlagsEnabled;
import android.platform.test.flag.junit.CheckFlagsRule;
import android.platform.test.flag.junit.DeviceFlagsValueProvider;
import android.safetycenter.SafetyEvent;
import android.safetycenter.SafetySourceData;
import android.safetycenter.SafetySourceStatus;
import androidx.test.core.app.ApplicationProvider;
import androidx.test.ext.junit.runners.AndroidJUnit4;
import com.android.internal.widget.LockPatternUtils;
import com.android.settings.Settings;
import com.android.settings.biometrics.face.FaceEnrollIntroductionInternal;
import com.android.settings.flags.Flags;
import com.android.settings.testutils.FakeFeatureFactory;
import com.android.settings.testutils.ResourcesUtils;
import org.junit.After;
import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.ArgumentCaptor;
import org.mockito.Mock;
import org.mockito.MockitoAnnotations;
@RequiresFlagsEnabled(Flags.FLAG_BIOMETRICS_ONBOARDING_EDUCATION)
@RunWith(AndroidJUnit4.class)
public class FaceSafetySourceTest {
private static final ComponentName COMPONENT_NAME = new ComponentName("package", "class");
private static final UserHandle USER_HANDLE = new UserHandle(UserHandle.myUserId());
private static final SafetyEvent EVENT_SOURCE_STATE_CHANGED =
new SafetyEvent.Builder(SAFETY_EVENT_TYPE_SOURCE_STATE_CHANGED).build();
@Rule
public final CheckFlagsRule mCheckFlagsRule = DeviceFlagsValueProvider.createCheckFlagsRule();
private Context mApplicationContext;
@Mock private PackageManager mPackageManager;
@Mock private DevicePolicyManager mDevicePolicyManager;
@Mock private FaceManager mFaceManager;
@Mock private LockPatternUtils mLockPatternUtils;
@Mock private SafetyCenterManagerWrapper mSafetyCenterManagerWrapper;
@Before
public void setUp() {
MockitoAnnotations.initMocks(this);
mApplicationContext = spy(ApplicationProvider.getApplicationContext());
when(mApplicationContext.getPackageManager()).thenReturn(mPackageManager);
when(mPackageManager.hasSystemFeature(PackageManager.FEATURE_FINGERPRINT)).thenReturn(true);
when(mPackageManager.hasSystemFeature(PackageManager.FEATURE_FACE)).thenReturn(true);
when(mDevicePolicyManager.getProfileOwnerOrDeviceOwnerSupervisionComponent(USER_HANDLE))
.thenReturn(COMPONENT_NAME);
when(mApplicationContext.getSystemService(Context.DEVICE_POLICY_SERVICE))
.thenReturn(mDevicePolicyManager);
when(mApplicationContext.getSystemService(Context.FACE_SERVICE)).thenReturn(mFaceManager);
FakeFeatureFactory featureFactory = FakeFeatureFactory.setupForTest();
when(featureFactory.securityFeatureProvider.getLockPatternUtils(mApplicationContext))
.thenReturn(mLockPatternUtils);
doReturn(true).when(mLockPatternUtils).isSecure(anyInt());
SafetyCenterManagerWrapper.sInstance = mSafetyCenterManagerWrapper;
}
@After
public void tearDown() {
SafetyCenterManagerWrapper.sInstance = null;
}
@Test
public void setSafetyData_whenSafetyCenterIsDisabled_doesNotSetData() {
when(mSafetyCenterManagerWrapper.isEnabled(mApplicationContext)).thenReturn(false);
FaceSafetySource.setSafetySourceData(mApplicationContext, EVENT_SOURCE_STATE_CHANGED);
verify(mSafetyCenterManagerWrapper, never())
.setSafetySourceData(any(), any(), any(), any());
}
@Test
public void setSafetySourceData_whenSafetyCenterIsEnabled_withoutFaceHardware_setsNullData() {
when(mSafetyCenterManagerWrapper.isEnabled(mApplicationContext)).thenReturn(true);
when(mFaceManager.isHardwareDetected()).thenReturn(false);
FaceSafetySource.setSafetySourceData(mApplicationContext, EVENT_SOURCE_STATE_CHANGED);
verify(mSafetyCenterManagerWrapper)
.setSafetySourceData(any(), eq(FaceSafetySource.SAFETY_SOURCE_ID), eq(null), any());
}
@Test
public void setSafetySourceData_setsDataForFaceSource() {
when(mSafetyCenterManagerWrapper.isEnabled(mApplicationContext)).thenReturn(true);
when(mFaceManager.isHardwareDetected()).thenReturn(true);
when(mDevicePolicyManager.getKeyguardDisabledFeatures(COMPONENT_NAME)).thenReturn(0);
FaceSafetySource.setSafetySourceData(mApplicationContext, EVENT_SOURCE_STATE_CHANGED);
verify(mSafetyCenterManagerWrapper)
.setSafetySourceData(any(), eq(FaceSafetySource.SAFETY_SOURCE_ID), any(), any());
}
@Test
public void setSafetySourceData_setsDataWithCorrectSafetyEvent() {
when(mSafetyCenterManagerWrapper.isEnabled(mApplicationContext)).thenReturn(true);
when(mFaceManager.isHardwareDetected()).thenReturn(true);
when(mDevicePolicyManager.getKeyguardDisabledFeatures(COMPONENT_NAME)).thenReturn(0);
FaceSafetySource.setSafetySourceData(mApplicationContext, EVENT_SOURCE_STATE_CHANGED);
verify(mSafetyCenterManagerWrapper)
.setSafetySourceData(any(), any(), any(), eq(EVENT_SOURCE_STATE_CHANGED));
}
@Test
public void setSafetySourceData_withFaceNotEnrolled_whenDisabledByAdmin_setsData() {
when(mSafetyCenterManagerWrapper.isEnabled(mApplicationContext)).thenReturn(true);
when(mFaceManager.isHardwareDetected()).thenReturn(true);
when(mFaceManager.hasEnrolledTemplates(anyInt())).thenReturn(false);
when(mDevicePolicyManager.getKeyguardDisabledFeatures(COMPONENT_NAME))
.thenReturn(DevicePolicyManager.KEYGUARD_DISABLE_FACE);
FaceSafetySource.setSafetySourceData(mApplicationContext, EVENT_SOURCE_STATE_CHANGED);
assertSafetySourceDisabledDataSetWithSingularSummary(
"security_settings_face_preference_title_new",
"security_settings_face_preference_summary_none");
}
@Test
public void setSafetySourceData_withFaceNotEnrolled_whenNotDisabledByAdmin_setsData() {
when(mSafetyCenterManagerWrapper.isEnabled(mApplicationContext)).thenReturn(true);
when(mFaceManager.isHardwareDetected()).thenReturn(true);
when(mFaceManager.hasEnrolledTemplates(anyInt())).thenReturn(false);
when(mDevicePolicyManager.getKeyguardDisabledFeatures(COMPONENT_NAME)).thenReturn(0);
FaceSafetySource.setSafetySourceData(mApplicationContext, EVENT_SOURCE_STATE_CHANGED);
assertSafetySourceEnabledDataSetWithSingularSummary(
"security_settings_face_preference_title_new",
"security_settings_face_preference_summary_none",
FaceEnrollIntroductionInternal.class.getName());
}
@Test
public void setSafetySourceData_withFaceEnrolled_whenDisabledByAdmin_setsData() {
when(mSafetyCenterManagerWrapper.isEnabled(mApplicationContext)).thenReturn(true);
when(mFaceManager.isHardwareDetected()).thenReturn(true);
when(mFaceManager.hasEnrolledTemplates(anyInt())).thenReturn(true);
when(mDevicePolicyManager.getKeyguardDisabledFeatures(COMPONENT_NAME))
.thenReturn(DevicePolicyManager.KEYGUARD_DISABLE_FACE);
FaceSafetySource.setSafetySourceData(mApplicationContext, EVENT_SOURCE_STATE_CHANGED);
assertSafetySourceDisabledDataSetWithSingularSummary(
"security_settings_face_preference_title_new",
"security_settings_face_preference_summary");
}
@Test
public void setSafetySourceData_withFaceEnrolled_whenNotDisabledByAdmin_setsData() {
when(mSafetyCenterManagerWrapper.isEnabled(mApplicationContext)).thenReturn(true);
when(mFaceManager.isHardwareDetected()).thenReturn(true);
when(mFaceManager.hasEnrolledTemplates(anyInt())).thenReturn(true);
when(mDevicePolicyManager.getKeyguardDisabledFeatures(COMPONENT_NAME)).thenReturn(0);
FaceSafetySource.setSafetySourceData(mApplicationContext, EVENT_SOURCE_STATE_CHANGED);
assertSafetySourceEnabledDataSetWithSingularSummary(
"security_settings_face_preference_title_new",
"security_settings_face_preference_summary",
Settings.FaceSettingsInternalActivity.class.getName());
}
@Test
public void setSafetySourceData_face_whenEnrolled_setsInfoSeverity() {
when(mSafetyCenterManagerWrapper.isEnabled(mApplicationContext)).thenReturn(true);
when(mFaceManager.isHardwareDetected()).thenReturn(true);
when(mFaceManager.hasEnrolledTemplates(anyInt())).thenReturn(true);
FaceSafetySource.setSafetySourceData(mApplicationContext, EVENT_SOURCE_STATE_CHANGED);
ArgumentCaptor<SafetySourceData> captor = ArgumentCaptor.forClass(SafetySourceData.class);
verify(mSafetyCenterManagerWrapper)
.setSafetySourceData(
any(), eq(FaceSafetySource.SAFETY_SOURCE_ID), captor.capture(), any());
SafetySourceStatus safetySourceStatus = captor.getValue().getStatus();
assertThat(safetySourceStatus.getSeverityLevel())
.isEqualTo(SafetySourceData.SEVERITY_LEVEL_INFORMATION);
}
@Test
public void setSafetySourceData_face_whenNotEnrolled_setsUnspSeverity() {
when(mSafetyCenterManagerWrapper.isEnabled(mApplicationContext)).thenReturn(true);
when(mFaceManager.isHardwareDetected()).thenReturn(true);
when(mFaceManager.hasEnrolledTemplates(anyInt())).thenReturn(false);
FaceSafetySource.setSafetySourceData(mApplicationContext, EVENT_SOURCE_STATE_CHANGED);
ArgumentCaptor<SafetySourceData> captor = ArgumentCaptor.forClass(SafetySourceData.class);
verify(mSafetyCenterManagerWrapper)
.setSafetySourceData(
any(), eq(FaceSafetySource.SAFETY_SOURCE_ID), captor.capture(), any());
SafetySourceStatus safetySourceStatus = captor.getValue().getStatus();
assertThat(safetySourceStatus.getSeverityLevel())
.isEqualTo(SafetySourceData.SEVERITY_LEVEL_UNSPECIFIED);
}
private void assertSafetySourceDisabledDataSetWithSingularSummary(
String expectedTitleResName, String expectedSummaryResName) {
assertSafetySourceDisabledDataSet(
ResourcesUtils.getResourcesString(mApplicationContext, expectedTitleResName),
ResourcesUtils.getResourcesString(mApplicationContext, expectedSummaryResName));
}
private void assertSafetySourceEnabledDataSetWithSingularSummary(
String expectedTitleResName,
String expectedSummaryResName,
String expectedSettingsClassName) {
assertSafetySourceEnabledDataSet(
ResourcesUtils.getResourcesString(mApplicationContext, expectedTitleResName),
ResourcesUtils.getResourcesString(mApplicationContext, expectedSummaryResName),
expectedSettingsClassName);
}
private void assertSafetySourceDisabledDataSet(String expectedTitle, String expectedSummary) {
ArgumentCaptor<SafetySourceData> captor = ArgumentCaptor.forClass(SafetySourceData.class);
verify(mSafetyCenterManagerWrapper)
.setSafetySourceData(
any(), eq(FaceSafetySource.SAFETY_SOURCE_ID), captor.capture(), any());
SafetySourceData safetySourceData = captor.getValue();
SafetySourceStatus safetySourceStatus = safetySourceData.getStatus();
assertThat(safetySourceStatus.getTitle().toString()).isEqualTo(expectedTitle);
assertThat(safetySourceStatus.getSummary().toString()).isEqualTo(expectedSummary);
assertThat(safetySourceStatus.isEnabled()).isFalse();
assertThat(safetySourceStatus.getSeverityLevel())
.isEqualTo(SafetySourceData.SEVERITY_LEVEL_UNSPECIFIED);
Intent clickIntent = safetySourceStatus.getPendingIntent().getIntent();
assertThat(clickIntent).isNotNull();
assertThat(clickIntent.getAction()).isEqualTo(ACTION_SHOW_ADMIN_SUPPORT_DETAILS);
}
private void assertSafetySourceEnabledDataSet(
String expectedTitle, String expectedSummary, String expectedSettingsClassName) {
ArgumentCaptor<SafetySourceData> captor = ArgumentCaptor.forClass(SafetySourceData.class);
verify(mSafetyCenterManagerWrapper)
.setSafetySourceData(
any(), eq(FaceSafetySource.SAFETY_SOURCE_ID), captor.capture(), any());
SafetySourceData safetySourceData = captor.getValue();
SafetySourceStatus safetySourceStatus = safetySourceData.getStatus();
assertThat(safetySourceStatus.getTitle().toString()).isEqualTo(expectedTitle);
assertThat(safetySourceStatus.getSummary().toString()).isEqualTo(expectedSummary);
assertThat(safetySourceStatus.isEnabled()).isTrue();
Intent clickIntent = safetySourceStatus.getPendingIntent().getIntent();
assertThat(clickIntent).isNotNull();
assertThat(clickIntent.getComponent().getPackageName()).isEqualTo("com.android.settings");
assertThat(clickIntent.getComponent().getClassName()).isEqualTo(expectedSettingsClassName);
}
}

View File

@@ -0,0 +1,381 @@
/*
* 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.safetycenter;
import static android.provider.Settings.ACTION_SHOW_ADMIN_SUPPORT_DETAILS;
import static android.safetycenter.SafetyEvent.SAFETY_EVENT_TYPE_SOURCE_STATE_CHANGED;
import static com.google.common.truth.Truth.assertThat;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.ArgumentMatchers.anyInt;
import static org.mockito.ArgumentMatchers.eq;
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.app.admin.DevicePolicyManager;
import android.content.ComponentName;
import android.content.Context;
import android.content.Intent;
import android.content.pm.PackageManager;
import android.hardware.fingerprint.Fingerprint;
import android.hardware.fingerprint.FingerprintManager;
import android.os.UserHandle;
import android.platform.test.annotations.RequiresFlagsEnabled;
import android.platform.test.flag.junit.CheckFlagsRule;
import android.platform.test.flag.junit.DeviceFlagsValueProvider;
import android.safetycenter.SafetyEvent;
import android.safetycenter.SafetySourceData;
import android.safetycenter.SafetySourceStatus;
import androidx.test.core.app.ApplicationProvider;
import androidx.test.ext.junit.runners.AndroidJUnit4;
import com.android.internal.widget.LockPatternUtils;
import com.android.settings.biometrics.fingerprint.FingerprintSettings;
import com.android.settings.flags.Flags;
import com.android.settings.testutils.FakeFeatureFactory;
import com.android.settings.testutils.ResourcesUtils;
import com.android.settingslib.utils.StringUtil;
import org.junit.After;
import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.ArgumentCaptor;
import org.mockito.Mock;
import org.mockito.MockitoAnnotations;
import java.util.ArrayList;
import java.util.List;
@RequiresFlagsEnabled(Flags.FLAG_BIOMETRICS_ONBOARDING_EDUCATION)
@RunWith(AndroidJUnit4.class)
public class FingerprintSafetySourceTest {
private static final ComponentName COMPONENT_NAME = new ComponentName("package", "class");
private static final UserHandle USER_HANDLE = new UserHandle(UserHandle.myUserId());
private static final SafetyEvent EVENT_SOURCE_STATE_CHANGED =
new SafetyEvent.Builder(SAFETY_EVENT_TYPE_SOURCE_STATE_CHANGED).build();
@Rule
public final CheckFlagsRule mCheckFlagsRule = DeviceFlagsValueProvider.createCheckFlagsRule();
private Context mApplicationContext;
@Mock private PackageManager mPackageManager;
@Mock private DevicePolicyManager mDevicePolicyManager;
@Mock private FingerprintManager mFingerprintManager;
@Mock private LockPatternUtils mLockPatternUtils;
@Mock private SafetyCenterManagerWrapper mSafetyCenterManagerWrapper;
@Before
public void setUp() {
MockitoAnnotations.initMocks(this);
mApplicationContext = spy(ApplicationProvider.getApplicationContext());
when(mApplicationContext.getPackageManager()).thenReturn(mPackageManager);
when(mPackageManager.hasSystemFeature(PackageManager.FEATURE_FINGERPRINT)).thenReturn(true);
when(mPackageManager.hasSystemFeature(PackageManager.FEATURE_FACE)).thenReturn(true);
when(mDevicePolicyManager.getProfileOwnerOrDeviceOwnerSupervisionComponent(USER_HANDLE))
.thenReturn(COMPONENT_NAME);
when(mApplicationContext.getSystemService(Context.FINGERPRINT_SERVICE))
.thenReturn(mFingerprintManager);
when(mApplicationContext.getSystemService(Context.DEVICE_POLICY_SERVICE))
.thenReturn(mDevicePolicyManager);
FakeFeatureFactory featureFactory = FakeFeatureFactory.setupForTest();
when(featureFactory.securityFeatureProvider.getLockPatternUtils(mApplicationContext))
.thenReturn(mLockPatternUtils);
doReturn(true).when(mLockPatternUtils).isSecure(anyInt());
SafetyCenterManagerWrapper.sInstance = mSafetyCenterManagerWrapper;
}
@After
public void tearDown() {
SafetyCenterManagerWrapper.sInstance = null;
}
@Test
public void setSafetyData_whenSafetyCenterIsDisabled_doesNotSetData() {
when(mSafetyCenterManagerWrapper.isEnabled(mApplicationContext)).thenReturn(false);
FingerprintSafetySource.setSafetySourceData(
mApplicationContext, EVENT_SOURCE_STATE_CHANGED);
verify(mSafetyCenterManagerWrapper, never())
.setSafetySourceData(any(), any(), any(), any());
}
@Test
public void setSafetySourceData_whenSafetyCenterIsEnabled_withoutFingerprint_setsNullData() {
when(mSafetyCenterManagerWrapper.isEnabled(mApplicationContext)).thenReturn(true);
when(mFingerprintManager.isHardwareDetected()).thenReturn(false);
FingerprintSafetySource.setSafetySourceData(
mApplicationContext, EVENT_SOURCE_STATE_CHANGED);
verify(mSafetyCenterManagerWrapper)
.setSafetySourceData(
any(), eq(FingerprintSafetySource.SAFETY_SOURCE_ID), eq(null), any());
}
@Test
public void setSafetySourceData_setsDataForFingerprintSource() {
when(mSafetyCenterManagerWrapper.isEnabled(mApplicationContext)).thenReturn(true);
when(mFingerprintManager.isHardwareDetected()).thenReturn(true);
when(mFingerprintManager.hasEnrolledFingerprints(anyInt())).thenReturn(false);
when(mDevicePolicyManager.getKeyguardDisabledFeatures(COMPONENT_NAME)).thenReturn(0);
FingerprintSafetySource.setSafetySourceData(
mApplicationContext, EVENT_SOURCE_STATE_CHANGED);
verify(mSafetyCenterManagerWrapper)
.setSafetySourceData(
any(), eq(FingerprintSafetySource.SAFETY_SOURCE_ID), any(), any());
}
@Test
public void setSafetySourceData_setsDataWithCorrectSafetyEvent() {
when(mSafetyCenterManagerWrapper.isEnabled(mApplicationContext)).thenReturn(true);
when(mFingerprintManager.isHardwareDetected()).thenReturn(true);
when(mFingerprintManager.hasEnrolledFingerprints(anyInt())).thenReturn(false);
when(mDevicePolicyManager.getKeyguardDisabledFeatures(COMPONENT_NAME)).thenReturn(0);
FingerprintSafetySource.setSafetySourceData(
mApplicationContext, EVENT_SOURCE_STATE_CHANGED);
verify(mSafetyCenterManagerWrapper)
.setSafetySourceData(any(), any(), any(), eq(EVENT_SOURCE_STATE_CHANGED));
}
@Test
public void setSafetySourceData_withFingerprintNotEnrolled_whenDisabledByAdmin_setsData() {
when(mSafetyCenterManagerWrapper.isEnabled(mApplicationContext)).thenReturn(true);
when(mFingerprintManager.isHardwareDetected()).thenReturn(true);
when(mFingerprintManager.hasEnrolledFingerprints(anyInt())).thenReturn(false);
when(mDevicePolicyManager.getKeyguardDisabledFeatures(COMPONENT_NAME))
.thenReturn(DevicePolicyManager.KEYGUARD_DISABLE_FINGERPRINT);
FingerprintSafetySource.setSafetySourceData(
mApplicationContext, EVENT_SOURCE_STATE_CHANGED);
assertSafetySourceDisabledDataSetWithSingularSummary(
"security_settings_fingerprint",
"security_settings_fingerprint_preference_summary_none");
}
@Test
public void setSafetySourceData_withFingerprintNotEnrolled_whenNotDisabledByAdmin_setsData() {
when(mSafetyCenterManagerWrapper.isEnabled(mApplicationContext)).thenReturn(true);
when(mFingerprintManager.isHardwareDetected()).thenReturn(true);
when(mFingerprintManager.hasEnrolledFingerprints(anyInt())).thenReturn(false);
when(mDevicePolicyManager.getKeyguardDisabledFeatures(COMPONENT_NAME)).thenReturn(0);
FingerprintSafetySource.setSafetySourceData(
mApplicationContext, EVENT_SOURCE_STATE_CHANGED);
assertSafetySourceEnabledDataSetWithSingularSummary(
"security_settings_fingerprint",
"security_settings_fingerprint_preference_summary_none",
FingerprintSettings.class.getName());
}
@Test
public void setSafetySourceData_withFingerprintsEnrolled_whenDisabledByAdmin_setsData() {
int enrolledFingerprintsCount = 2;
when(mSafetyCenterManagerWrapper.isEnabled(mApplicationContext)).thenReturn(true);
when(mFingerprintManager.isHardwareDetected()).thenReturn(true);
when(mFingerprintManager.hasEnrolledFingerprints(anyInt())).thenReturn(true);
when(mFingerprintManager.getEnrolledFingerprints(anyInt()))
.thenReturn(createFingerprintList(enrolledFingerprintsCount));
when(mDevicePolicyManager.getKeyguardDisabledFeatures(COMPONENT_NAME))
.thenReturn(DevicePolicyManager.KEYGUARD_DISABLE_FINGERPRINT);
FingerprintSafetySource.setSafetySourceData(
mApplicationContext, EVENT_SOURCE_STATE_CHANGED);
assertSafetySourceDisabledDataSetWithPluralSummary(
"security_settings_fingerprint",
"security_settings_fingerprint_preference_summary",
enrolledFingerprintsCount);
}
@Test
public void setSafetySourceData_withFingerprintsEnrolled_whenNotDisabledByAdmin_setsData() {
int enrolledFingerprintsCount = 2;
when(mSafetyCenterManagerWrapper.isEnabled(mApplicationContext)).thenReturn(true);
when(mFingerprintManager.isHardwareDetected()).thenReturn(true);
when(mFingerprintManager.hasEnrolledFingerprints(anyInt())).thenReturn(true);
when(mFingerprintManager.getEnrolledFingerprints(anyInt()))
.thenReturn(createFingerprintList(enrolledFingerprintsCount));
when(mDevicePolicyManager.getKeyguardDisabledFeatures(COMPONENT_NAME)).thenReturn(0);
FingerprintSafetySource.setSafetySourceData(
mApplicationContext, EVENT_SOURCE_STATE_CHANGED);
assertSafetySourceEnabledDataSetWithPluralSummary(
"security_settings_fingerprint",
"security_settings_fingerprint_preference_summary",
enrolledFingerprintsCount,
FingerprintSettings.class.getName());
}
@Test
public void setSafetySourceData_fingerprint_whenEnrolled_setsInfoSeverity() {
when(mSafetyCenterManagerWrapper.isEnabled(mApplicationContext)).thenReturn(true);
when(mFingerprintManager.isHardwareDetected()).thenReturn(true);
when(mFingerprintManager.hasEnrolledFingerprints(anyInt())).thenReturn(true);
FingerprintSafetySource.setSafetySourceData(
mApplicationContext, EVENT_SOURCE_STATE_CHANGED);
ArgumentCaptor<SafetySourceData> captor = ArgumentCaptor.forClass(SafetySourceData.class);
verify(mSafetyCenterManagerWrapper)
.setSafetySourceData(
any(),
eq(FingerprintSafetySource.SAFETY_SOURCE_ID),
captor.capture(),
any());
SafetySourceStatus safetySourceStatus = captor.getValue().getStatus();
assertThat(safetySourceStatus.getSeverityLevel())
.isEqualTo(SafetySourceData.SEVERITY_LEVEL_INFORMATION);
}
@Test
public void setSafetySourceData_fingerprint_whenNotEnrolled_setsUnspSeverity() {
when(mSafetyCenterManagerWrapper.isEnabled(mApplicationContext)).thenReturn(true);
when(mFingerprintManager.isHardwareDetected()).thenReturn(true);
when(mFingerprintManager.hasEnrolledFingerprints(anyInt())).thenReturn(false);
FingerprintSafetySource.setSafetySourceData(
mApplicationContext, EVENT_SOURCE_STATE_CHANGED);
ArgumentCaptor<SafetySourceData> captor = ArgumentCaptor.forClass(SafetySourceData.class);
verify(mSafetyCenterManagerWrapper)
.setSafetySourceData(
any(),
eq(FingerprintSafetySource.SAFETY_SOURCE_ID),
captor.capture(),
any());
SafetySourceStatus safetySourceStatus = captor.getValue().getStatus();
assertThat(safetySourceStatus.getSeverityLevel())
.isEqualTo(SafetySourceData.SEVERITY_LEVEL_UNSPECIFIED);
}
private void assertSafetySourceDisabledDataSetWithSingularSummary(
String expectedTitleResName, String expectedSummaryResName) {
assertSafetySourceDisabledDataSet(
ResourcesUtils.getResourcesString(mApplicationContext, expectedTitleResName),
ResourcesUtils.getResourcesString(mApplicationContext, expectedSummaryResName));
}
private void assertSafetySourceEnabledDataSetWithSingularSummary(
String expectedTitleResName,
String expectedSummaryResName,
String expectedSettingsClassName) {
assertSafetySourceEnabledDataSet(
ResourcesUtils.getResourcesString(mApplicationContext, expectedTitleResName),
ResourcesUtils.getResourcesString(mApplicationContext, expectedSummaryResName),
expectedSettingsClassName);
}
private void assertSafetySourceDisabledDataSetWithPluralSummary(
String expectedTitleResName,
String expectedSummaryResName,
int expectedSummaryQuantity) {
int stringResId =
ResourcesUtils.getResourcesId(
ApplicationProvider.getApplicationContext(),
"string",
expectedSummaryResName);
assertSafetySourceDisabledDataSet(
ResourcesUtils.getResourcesString(mApplicationContext, expectedTitleResName),
StringUtil.getIcuPluralsString(
mApplicationContext, expectedSummaryQuantity, stringResId));
}
private void assertSafetySourceEnabledDataSetWithPluralSummary(
String expectedTitleResName,
String expectedSummaryResName,
int expectedSummaryQuantity,
String expectedSettingsClassName) {
int stringResId =
ResourcesUtils.getResourcesId(
ApplicationProvider.getApplicationContext(),
"string",
expectedSummaryResName);
assertSafetySourceEnabledDataSet(
ResourcesUtils.getResourcesString(mApplicationContext, expectedTitleResName),
StringUtil.getIcuPluralsString(
mApplicationContext, expectedSummaryQuantity, stringResId),
expectedSettingsClassName);
}
private void assertSafetySourceDisabledDataSet(String expectedTitle, String expectedSummary) {
ArgumentCaptor<SafetySourceData> captor = ArgumentCaptor.forClass(SafetySourceData.class);
verify(mSafetyCenterManagerWrapper)
.setSafetySourceData(
any(),
eq(FingerprintSafetySource.SAFETY_SOURCE_ID),
captor.capture(),
any());
SafetySourceData safetySourceData = captor.getValue();
SafetySourceStatus safetySourceStatus = safetySourceData.getStatus();
assertThat(safetySourceStatus.getTitle().toString()).isEqualTo(expectedTitle);
assertThat(safetySourceStatus.getSummary().toString()).isEqualTo(expectedSummary);
assertThat(safetySourceStatus.isEnabled()).isFalse();
assertThat(safetySourceStatus.getSeverityLevel())
.isEqualTo(SafetySourceData.SEVERITY_LEVEL_UNSPECIFIED);
Intent clickIntent = safetySourceStatus.getPendingIntent().getIntent();
assertThat(clickIntent).isNotNull();
assertThat(clickIntent.getAction()).isEqualTo(ACTION_SHOW_ADMIN_SUPPORT_DETAILS);
}
private void assertSafetySourceEnabledDataSet(
String expectedTitle, String expectedSummary, String expectedSettingsClassName) {
ArgumentCaptor<SafetySourceData> captor = ArgumentCaptor.forClass(SafetySourceData.class);
verify(mSafetyCenterManagerWrapper)
.setSafetySourceData(
any(),
eq(FingerprintSafetySource.SAFETY_SOURCE_ID),
captor.capture(),
any());
SafetySourceData safetySourceData = captor.getValue();
SafetySourceStatus safetySourceStatus = safetySourceData.getStatus();
assertThat(safetySourceStatus.getTitle().toString()).isEqualTo(expectedTitle);
assertThat(safetySourceStatus.getSummary().toString()).isEqualTo(expectedSummary);
assertThat(safetySourceStatus.isEnabled()).isTrue();
Intent clickIntent = safetySourceStatus.getPendingIntent().getIntent();
assertThat(clickIntent).isNotNull();
assertThat(clickIntent.getComponent().getPackageName()).isEqualTo("com.android.settings");
assertThat(clickIntent.getComponent().getClassName()).isEqualTo(expectedSettingsClassName);
}
private List<Fingerprint> createFingerprintList(int size) {
List<Fingerprint> fingerprintList = new ArrayList<>(size);
for (int i = 0; i < size; i++) {
fingerprintList.add(new Fingerprint("fingerprint" + i, 0, 0));
}
return fingerprintList;
}
}

View File

@@ -29,6 +29,10 @@ import static org.mockito.Mockito.when;
import android.content.Context; import android.content.Context;
import android.content.Intent; import android.content.Intent;
import android.platform.test.annotations.RequiresFlagsDisabled;
import android.platform.test.annotations.RequiresFlagsEnabled;
import android.platform.test.flag.junit.CheckFlagsRule;
import android.platform.test.flag.junit.DeviceFlagsValueProvider;
import android.safetycenter.SafetyEvent; import android.safetycenter.SafetyEvent;
import android.safetycenter.SafetySourceData; import android.safetycenter.SafetySourceData;
import android.safetycenter.SafetySourceIssue; import android.safetycenter.SafetySourceIssue;
@@ -39,12 +43,14 @@ import androidx.test.core.app.ApplicationProvider;
import androidx.test.ext.junit.runners.AndroidJUnit4; import androidx.test.ext.junit.runners.AndroidJUnit4;
import com.android.internal.widget.LockPatternUtils; import com.android.internal.widget.LockPatternUtils;
import com.android.settings.flags.Flags;
import com.android.settings.security.ScreenLockPreferenceDetailsUtils; import com.android.settings.security.ScreenLockPreferenceDetailsUtils;
import com.android.settings.testutils.FakeFeatureFactory; import com.android.settings.testutils.FakeFeatureFactory;
import com.android.settings.testutils.ResourcesUtils; import com.android.settings.testutils.ResourcesUtils;
import org.junit.After; import org.junit.After;
import org.junit.Before; import org.junit.Before;
import org.junit.Rule;
import org.junit.Test; import org.junit.Test;
import org.junit.runner.RunWith; import org.junit.runner.RunWith;
import org.mockito.ArgumentCaptor; import org.mockito.ArgumentCaptor;
@@ -62,6 +68,9 @@ public class LockScreenSafetySourceTest {
private static final SafetyEvent EVENT_SOURCE_STATE_CHANGED = private static final SafetyEvent EVENT_SOURCE_STATE_CHANGED =
new SafetyEvent.Builder(SAFETY_EVENT_TYPE_SOURCE_STATE_CHANGED).build(); new SafetyEvent.Builder(SAFETY_EVENT_TYPE_SOURCE_STATE_CHANGED).build();
@Rule
public final CheckFlagsRule mCheckFlagsRule = DeviceFlagsValueProvider.createCheckFlagsRule();
private Context mApplicationContext; private Context mApplicationContext;
@Mock private SafetyCenterManagerWrapper mSafetyCenterManagerWrapper; @Mock private SafetyCenterManagerWrapper mSafetyCenterManagerWrapper;
@@ -486,7 +495,9 @@ public class LockScreenSafetySourceTest {
} }
@Test @Test
public void onLockScreenChange_whenSafetyCenterEnabled_setsLockscreenAndBiometricData() { @RequiresFlagsDisabled(Flags.FLAG_BIOMETRICS_ONBOARDING_EDUCATION)
public void
onLockScreenChange_whenSafetyCenterEnabled_flagOff_setsLockscreenAndBiometricData() {
whenScreenLockIsEnabled(); whenScreenLockIsEnabled();
when(mSafetyCenterManagerWrapper.isEnabled(mApplicationContext)).thenReturn(true); when(mSafetyCenterManagerWrapper.isEnabled(mApplicationContext)).thenReturn(true);
@@ -500,6 +511,24 @@ public class LockScreenSafetySourceTest {
any(), eq(BiometricsSafetySource.SAFETY_SOURCE_ID), any(), any()); any(), eq(BiometricsSafetySource.SAFETY_SOURCE_ID), any(), any());
} }
@Test
@RequiresFlagsEnabled(Flags.FLAG_BIOMETRICS_ONBOARDING_EDUCATION)
public void onLockScreenChange_whenSafetyCenterEnabled_flagOn_setsLockscreenAndBiometricData() {
whenScreenLockIsEnabled();
when(mSafetyCenterManagerWrapper.isEnabled(mApplicationContext)).thenReturn(true);
LockScreenSafetySource.onLockScreenChange(mApplicationContext);
verify(mSafetyCenterManagerWrapper)
.setSafetySourceData(
any(), eq(LockScreenSafetySource.SAFETY_SOURCE_ID), any(), any());
verify(mSafetyCenterManagerWrapper)
.setSafetySourceData(any(), eq(FaceSafetySource.SAFETY_SOURCE_ID), any(), any());
verify(mSafetyCenterManagerWrapper)
.setSafetySourceData(
any(), eq(FingerprintSafetySource.SAFETY_SOURCE_ID), any(), any());
}
@Test @Test
public void onLockScreenChange_whenSafetyCenterDisabled_doesNotSetData() { public void onLockScreenChange_whenSafetyCenterDisabled_doesNotSetData() {
whenScreenLockIsEnabled(); whenScreenLockIsEnabled();

View File

@@ -21,8 +21,11 @@ import static android.safetycenter.SafetyCenterManager.EXTRA_REFRESH_SAFETY_SOUR
import static android.safetycenter.SafetyCenterManager.EXTRA_REFRESH_SAFETY_SOURCE_IDS; import static android.safetycenter.SafetyCenterManager.EXTRA_REFRESH_SAFETY_SOURCE_IDS;
import static android.safetycenter.SafetyEvent.SAFETY_EVENT_TYPE_DEVICE_REBOOTED; import static android.safetycenter.SafetyEvent.SAFETY_EVENT_TYPE_DEVICE_REBOOTED;
import static android.safetycenter.SafetyEvent.SAFETY_EVENT_TYPE_REFRESH_REQUESTED; import static android.safetycenter.SafetyEvent.SAFETY_EVENT_TYPE_REFRESH_REQUESTED;
import static com.google.common.truth.Truth.assertThat; import static com.google.common.truth.Truth.assertThat;
import static org.mockito.ArgumentMatchers.any; import static org.mockito.ArgumentMatchers.any;
import static org.mockito.Mockito.atLeastOnce;
import static org.mockito.Mockito.never; import static org.mockito.Mockito.never;
import static org.mockito.Mockito.times; import static org.mockito.Mockito.times;
import static org.mockito.Mockito.verify; import static org.mockito.Mockito.verify;
@@ -30,7 +33,10 @@ import static org.mockito.Mockito.when;
import android.content.Context; import android.content.Context;
import android.content.Intent; import android.content.Intent;
import android.os.Flags; import android.platform.test.annotations.RequiresFlagsDisabled;
import android.platform.test.annotations.RequiresFlagsEnabled;
import android.platform.test.flag.junit.CheckFlagsRule;
import android.platform.test.flag.junit.DeviceFlagsValueProvider;
import android.platform.test.flag.junit.SetFlagsRule; import android.platform.test.flag.junit.SetFlagsRule;
import android.safetycenter.SafetyEvent; import android.safetycenter.SafetyEvent;
import android.safetycenter.SafetySourceData; import android.safetycenter.SafetySourceData;
@@ -39,6 +45,7 @@ import androidx.test.core.app.ApplicationProvider;
import androidx.test.ext.junit.runners.AndroidJUnit4; import androidx.test.ext.junit.runners.AndroidJUnit4;
import com.android.internal.widget.LockPatternUtils; import com.android.internal.widget.LockPatternUtils;
import com.android.settings.flags.Flags;
import com.android.settings.privatespace.PrivateSpaceSafetySource; import com.android.settings.privatespace.PrivateSpaceSafetySource;
import com.android.settings.testutils.FakeFeatureFactory; import com.android.settings.testutils.FakeFeatureFactory;
@@ -51,7 +58,6 @@ import org.mockito.ArgumentCaptor;
import org.mockito.Mock; import org.mockito.Mock;
import org.mockito.MockitoAnnotations; import org.mockito.MockitoAnnotations;
import java.util.Arrays;
import java.util.List; import java.util.List;
@RunWith(AndroidJUnit4.class) @RunWith(AndroidJUnit4.class)
@@ -61,6 +67,9 @@ public class SafetySourceBroadcastReceiverTest {
private Context mApplicationContext; private Context mApplicationContext;
@Rule
public final CheckFlagsRule mCheckFlagsRule = DeviceFlagsValueProvider.createCheckFlagsRule();
@Mock private SafetyCenterManagerWrapper mSafetyCenterManagerWrapper; @Mock private SafetyCenterManagerWrapper mSafetyCenterManagerWrapper;
@Mock private LockPatternUtils mLockPatternUtils; @Mock private LockPatternUtils mLockPatternUtils;
@@ -202,6 +211,7 @@ public class SafetySourceBroadcastReceiverTest {
} }
@Test @Test
@RequiresFlagsDisabled(Flags.FLAG_BIOMETRICS_ONBOARDING_EDUCATION)
public void onReceive_onRefresh_withBiometricsSourceId_setsBiometricData() { public void onReceive_onRefresh_withBiometricsSourceId_setsBiometricData() {
when(mSafetyCenterManagerWrapper.isEnabled(mApplicationContext)).thenReturn(true); when(mSafetyCenterManagerWrapper.isEnabled(mApplicationContext)).thenReturn(true);
Intent intent = Intent intent =
@@ -220,9 +230,49 @@ public class SafetySourceBroadcastReceiverTest {
assertThat(captor.getValue()).isEqualTo(BiometricsSafetySource.SAFETY_SOURCE_ID); assertThat(captor.getValue()).isEqualTo(BiometricsSafetySource.SAFETY_SOURCE_ID);
} }
@Test
@RequiresFlagsEnabled(Flags.FLAG_BIOMETRICS_ONBOARDING_EDUCATION)
public void onReceive_onRefresh_withFaceUnlockSourceId_setsFaceUnlockData() {
when(mSafetyCenterManagerWrapper.isEnabled(mApplicationContext)).thenReturn(true);
Intent intent =
new Intent()
.setAction(ACTION_REFRESH_SAFETY_SOURCES)
.putExtra(
EXTRA_REFRESH_SAFETY_SOURCE_IDS,
new String[] {FaceSafetySource.SAFETY_SOURCE_ID})
.putExtra(EXTRA_REFRESH_SAFETY_SOURCES_BROADCAST_ID, REFRESH_BROADCAST_ID);
new SafetySourceBroadcastReceiver().onReceive(mApplicationContext, intent);
ArgumentCaptor<String> captor = ArgumentCaptor.forClass(String.class);
verify(mSafetyCenterManagerWrapper, times(1))
.setSafetySourceData(any(), captor.capture(), any(), any());
assertThat(captor.getValue()).isEqualTo(FaceSafetySource.SAFETY_SOURCE_ID);
}
@Test
@RequiresFlagsEnabled(Flags.FLAG_BIOMETRICS_ONBOARDING_EDUCATION)
public void onReceive_onRefresh_withFingerprintUnlockSourceId_setsFingerprintUnlockData() {
when(mSafetyCenterManagerWrapper.isEnabled(mApplicationContext)).thenReturn(true);
Intent intent =
new Intent()
.setAction(ACTION_REFRESH_SAFETY_SOURCES)
.putExtra(
EXTRA_REFRESH_SAFETY_SOURCE_IDS,
new String[] {FingerprintSafetySource.SAFETY_SOURCE_ID})
.putExtra(EXTRA_REFRESH_SAFETY_SOURCES_BROADCAST_ID, REFRESH_BROADCAST_ID);
new SafetySourceBroadcastReceiver().onReceive(mApplicationContext, intent);
ArgumentCaptor<String> captor = ArgumentCaptor.forClass(String.class);
verify(mSafetyCenterManagerWrapper, times(1))
.setSafetySourceData(any(), captor.capture(), any(), any());
assertThat(captor.getValue()).isEqualTo(FingerprintSafetySource.SAFETY_SOURCE_ID);
}
/** /**
* Tests that on receiving the refresh broadcast request with the PS source id, the PS data * Tests that on receiving the refresh broadcast request with the PS source id, the PS data is
* is set. * set.
*/ */
@Test @Test
public void onReceive_onRefresh_withPrivateSpaceSourceId_setsPrivateSpaceData() { public void onReceive_onRefresh_withPrivateSpaceSourceId_setsPrivateSpaceData() {
@@ -247,7 +297,8 @@ public class SafetySourceBroadcastReceiverTest {
@Test @Test
public void onReceive_onRefresh_withPrivateSpaceFeatureDisabled_setsNullData() { public void onReceive_onRefresh_withPrivateSpaceFeatureDisabled_setsNullData() {
when(mSafetyCenterManagerWrapper.isEnabled(mApplicationContext)).thenReturn(true); when(mSafetyCenterManagerWrapper.isEnabled(mApplicationContext)).thenReturn(true);
mSetFlagsRule.disableFlags(Flags.FLAG_ALLOW_PRIVATE_PROFILE, mSetFlagsRule.disableFlags(
android.os.Flags.FLAG_ALLOW_PRIVATE_PROFILE,
android.multiuser.Flags.FLAG_ENABLE_PRIVATE_SPACE_FEATURES); android.multiuser.Flags.FLAG_ENABLE_PRIVATE_SPACE_FEATURES);
Intent intent = Intent intent =
@@ -273,16 +324,48 @@ public class SafetySourceBroadcastReceiverTest {
new SafetySourceBroadcastReceiver().onReceive(mApplicationContext, intent); new SafetySourceBroadcastReceiver().onReceive(mApplicationContext, intent);
ArgumentCaptor<SafetyEvent> captor = ArgumentCaptor.forClass(SafetyEvent.class); ArgumentCaptor<SafetyEvent> captor = ArgumentCaptor.forClass(SafetyEvent.class);
verify(mSafetyCenterManagerWrapper, times(3)) verify(mSafetyCenterManagerWrapper, atLeastOnce())
.setSafetySourceData(any(), any(), any(), captor.capture()); .setSafetySourceData(any(), any(), any(), captor.capture());
SafetyEvent bootEvent = new SafetyEvent.Builder(SAFETY_EVENT_TYPE_DEVICE_REBOOTED).build(); SafetyEvent bootEvent = new SafetyEvent.Builder(SAFETY_EVENT_TYPE_DEVICE_REBOOTED).build();
assertThat(captor.getAllValues()) assertThat(captor.getAllValues()).contains(bootEvent);
.containsExactlyElementsIn(Arrays.asList(bootEvent, bootEvent, bootEvent));
} }
@Test @Test
public void onReceive_onBootCompleted_sendsAllSafetySourcesData() { @RequiresFlagsEnabled(Flags.FLAG_BIOMETRICS_ONBOARDING_EDUCATION)
public void onReceive_onBootCompleted_flagOn_sendsAllSafetySourcesData() {
when(mSafetyCenterManagerWrapper.isEnabled(mApplicationContext)).thenReturn(true);
Intent intent = new Intent().setAction(Intent.ACTION_BOOT_COMPLETED);
new SafetySourceBroadcastReceiver().onReceive(mApplicationContext, intent);
ArgumentCaptor<String> captor = ArgumentCaptor.forClass(String.class);
verify(mSafetyCenterManagerWrapper, times(4))
.setSafetySourceData(any(), captor.capture(), any(), any());
List<String> safetySourceIdList = captor.getAllValues();
assertThat(
safetySourceIdList.stream()
.anyMatch(id -> id.equals(LockScreenSafetySource.SAFETY_SOURCE_ID)))
.isTrue();
assertThat(
safetySourceIdList.stream()
.anyMatch(id -> id.equals(FaceSafetySource.SAFETY_SOURCE_ID)))
.isTrue();
assertThat(
safetySourceIdList.stream()
.anyMatch(
id -> id.equals(FingerprintSafetySource.SAFETY_SOURCE_ID)))
.isTrue();
assertThat(
safetySourceIdList.stream()
.anyMatch(
id -> id.equals(PrivateSpaceSafetySource.SAFETY_SOURCE_ID)))
.isTrue();
}
@Test
@RequiresFlagsDisabled(Flags.FLAG_BIOMETRICS_ONBOARDING_EDUCATION)
public void onReceive_onBootCompleted_flagOff_sendsAllSafetySourcesData() {
when(mSafetyCenterManagerWrapper.isEnabled(mApplicationContext)).thenReturn(true); when(mSafetyCenterManagerWrapper.isEnabled(mApplicationContext)).thenReturn(true);
Intent intent = new Intent().setAction(Intent.ACTION_BOOT_COMPLETED); Intent intent = new Intent().setAction(Intent.ACTION_BOOT_COMPLETED);
@@ -292,11 +375,18 @@ public class SafetySourceBroadcastReceiverTest {
.setSafetySourceData(any(), captor.capture(), any(), any()); .setSafetySourceData(any(), captor.capture(), any(), any());
List<String> safetySourceIdList = captor.getAllValues(); List<String> safetySourceIdList = captor.getAllValues();
assertThat(safetySourceIdList.stream().anyMatch( assertThat(
id -> id.equals(LockScreenSafetySource.SAFETY_SOURCE_ID))).isTrue(); safetySourceIdList.stream()
assertThat(safetySourceIdList.stream().anyMatch( .anyMatch(id -> id.equals(LockScreenSafetySource.SAFETY_SOURCE_ID)))
id -> id.equals(BiometricsSafetySource.SAFETY_SOURCE_ID))).isTrue(); .isTrue();
assertThat(safetySourceIdList.stream().anyMatch( assertThat(
id -> id.equals(PrivateSpaceSafetySource.SAFETY_SOURCE_ID))).isTrue(); safetySourceIdList.stream()
.anyMatch(id -> id.equals(BiometricsSafetySource.SAFETY_SOURCE_ID)))
.isTrue();
assertThat(
safetySourceIdList.stream()
.anyMatch(
id -> id.equals(PrivateSpaceSafetySource.SAFETY_SOURCE_ID)))
.isTrue();
} }
} }