Merge "Update string id to use generic 'Done' button" into main
diff --git a/src/com/android/settings/bluetooth/BluetoothDetailsProfilesController.java b/src/com/android/settings/bluetooth/BluetoothDetailsProfilesController.java
index 58d2787..d7f53ca 100644
--- a/src/com/android/settings/bluetooth/BluetoothDetailsProfilesController.java
+++ b/src/com/android/settings/bluetooth/BluetoothDetailsProfilesController.java
@@ -419,32 +419,7 @@
mContext,
SettingsEnums.ACTION_BLUETOOTH_PROFILE_LE_AUDIO_OFF,
isCurrentDeviceInOrByPassAllowList());
-
- LocalBluetoothProfile asha = mProfileManager.getHearingAidProfile();
- LocalBluetoothProfile broadcastAssistant =
- mProfileManager.getLeAudioBroadcastAssistantProfile();
-
- for (CachedBluetoothDevice leAudioDevice : mProfileDeviceMap.get(profile.toString())) {
- Log.d(TAG,
- "device:" + leAudioDevice.getDevice().getAnonymizedAddress()
- + " disable LE profile");
- profile.setEnabled(leAudioDevice.getDevice(), false);
- if (asha != null) {
- asha.setEnabled(leAudioDevice.getDevice(), true);
- }
- if (broadcastAssistant != null) {
- Log.d(TAG,
- "device:" + leAudioDevice.getDevice().getAnonymizedAddress()
- + " disable LE broadcast assistant profile");
- broadcastAssistant.setEnabled(leAudioDevice.getDevice(), false);
- }
- }
-
- if (!SystemProperties.getBoolean(ENABLE_DUAL_MODE_AUDIO, false)) {
- Log.i(TAG, "Enabling classic audio profiles because dual mode is disabled");
- enableProfileAfterUserDisablesLeAudio(mProfileManager.getA2dpProfile());
- enableProfileAfterUserDisablesLeAudio(mProfileManager.getHeadsetProfile());
- }
+ Utils.setLeAudioEnabled(mManager, List.copyOf(mCachedDeviceGroup), false);
}
/**
@@ -462,75 +437,7 @@
mContext,
SettingsEnums.ACTION_BLUETOOTH_PROFILE_LE_AUDIO_ON,
isCurrentDeviceInOrByPassAllowList());
-
- if (!SystemProperties.getBoolean(ENABLE_DUAL_MODE_AUDIO, false)) {
- Log.i(TAG, "Disabling classic audio profiles because dual mode is disabled");
- disableProfileBeforeUserEnablesLeAudio(mProfileManager.getA2dpProfile());
- disableProfileBeforeUserEnablesLeAudio(mProfileManager.getHeadsetProfile());
- }
- LocalBluetoothProfile asha = mProfileManager.getHearingAidProfile();
- LocalBluetoothProfile broadcastAssistant =
- mProfileManager.getLeAudioBroadcastAssistantProfile();
-
- for (CachedBluetoothDevice leAudioDevice : mProfileDeviceMap.get(profile.toString())) {
- Log.d(TAG,
- "device:" + leAudioDevice.getDevice().getAnonymizedAddress()
- + " enable LE profile");
- profile.setEnabled(leAudioDevice.getDevice(), true);
- if (asha != null) {
- asha.setEnabled(leAudioDevice.getDevice(), false);
- }
- if (broadcastAssistant != null) {
- Log.d(TAG,
- "device:" + leAudioDevice.getDevice().getAnonymizedAddress()
- + " enable LE broadcast assistant profile");
- broadcastAssistant.setEnabled(leAudioDevice.getDevice(), true);
- }
- }
- }
-
- private void disableProfileBeforeUserEnablesLeAudio(LocalBluetoothProfile profile) {
- if (profile != null && mProfileDeviceMap.get(profile.toString()) != null) {
- Log.d(TAG, "Disable " + profile.toString() + " before user enables LE");
- for (CachedBluetoothDevice profileDevice : mProfileDeviceMap.get(profile.toString())) {
- if (profile.isEnabled(profileDevice.getDevice())) {
- Log.d(TAG, "The " + profileDevice.getDevice().getAnonymizedAddress() + ":"
- + profile.toString() + " set disable");
- profile.setEnabled(profileDevice.getDevice(), false);
- } else {
- Log.d(TAG, "The " + profileDevice.getDevice().getAnonymizedAddress() + ":"
- + profile.toString() + " profile is disabled. Do nothing.");
- }
- }
- } else {
- if (profile == null) {
- Log.w(TAG, "profile is null");
- } else {
- Log.w(TAG, profile.toString() + " is not in " + mProfileDeviceMap);
- }
- }
- }
-
- private void enableProfileAfterUserDisablesLeAudio(LocalBluetoothProfile profile) {
- if (profile != null && mProfileDeviceMap.get(profile.toString()) != null) {
- Log.d(TAG, "enable " + profile.toString() + "after user disables LE");
- for (CachedBluetoothDevice profileDevice : mProfileDeviceMap.get(profile.toString())) {
- if (!profile.isEnabled(profileDevice.getDevice())) {
- Log.d(TAG, "The " + profileDevice.getDevice().getAnonymizedAddress() + ":"
- + profile.toString() + " set enable");
- profile.setEnabled(profileDevice.getDevice(), true);
- } else {
- Log.d(TAG, "The " + profileDevice.getDevice().getAnonymizedAddress() + ":"
- + profile.toString() + " profile is enabled. Do nothing.");
- }
- }
- } else {
- if (profile == null) {
- Log.w(TAG, "profile is null");
- } else {
- Log.w(TAG, profile.toString() + " is not in " + mProfileDeviceMap);
- }
- }
+ Utils.setLeAudioEnabled(mManager, List.copyOf(mCachedDeviceGroup), true);
}
/**
diff --git a/src/com/android/settings/bluetooth/BluetoothKeyMissingReceiver.java b/src/com/android/settings/bluetooth/BluetoothKeyMissingReceiver.java
index e7e0b4a..cfe9c05 100644
--- a/src/com/android/settings/bluetooth/BluetoothKeyMissingReceiver.java
+++ b/src/com/android/settings/bluetooth/BluetoothKeyMissingReceiver.java
@@ -55,9 +55,18 @@
}
BluetoothDevice device = intent.getParcelableExtra(BluetoothDevice.EXTRA_DEVICE);
+ if (device == null) {
+ return;
+ }
PowerManager powerManager = context.getSystemService(PowerManager.class);
if (TextUtils.equals(action, BluetoothDevice.ACTION_KEY_MISSING)) {
Log.d(TAG, "Receive ACTION_KEY_MISSING");
+ if (device.getBondState() == BluetoothDevice.BOND_NONE) {
+ Log.d(
+ TAG,
+ "Device " + device.getAnonymizedAddress() + " is already unbonded, skip.");
+ return;
+ }
Integer keyMissingCount = BluetoothUtils.getKeyMissingCount(device);
if (keyMissingCount != null && keyMissingCount != 1) {
Log.d(TAG, "Key missing count is " + keyMissingCount + ", skip.");
diff --git a/src/com/android/settings/bluetooth/Utils.java b/src/com/android/settings/bluetooth/Utils.java
index 9f4bb13..76c3ed0 100644
--- a/src/com/android/settings/bluetooth/Utils.java
+++ b/src/com/android/settings/bluetooth/Utils.java
@@ -28,6 +28,7 @@
import android.content.pm.PackageInfo;
import android.content.pm.PackageManager;
import android.content.pm.PackageManager.NameNotFoundException;
+import android.os.SystemProperties;
import android.os.UserHandle;
import android.provider.Settings;
import android.util.Log;
@@ -45,15 +46,20 @@
import com.android.settingslib.bluetooth.BluetoothUtils.ErrorListener;
import com.android.settingslib.bluetooth.CachedBluetoothDevice;
import com.android.settingslib.bluetooth.CachedBluetoothDeviceManager;
+import com.android.settingslib.bluetooth.HearingAidProfile;
+import com.android.settingslib.bluetooth.LeAudioProfile;
import com.android.settingslib.bluetooth.LocalBluetoothLeBroadcast;
import com.android.settingslib.bluetooth.LocalBluetoothLeBroadcastAssistant;
import com.android.settingslib.bluetooth.LocalBluetoothManager;
import com.android.settingslib.bluetooth.LocalBluetoothManager.BluetoothManagerCallback;
+import com.android.settingslib.bluetooth.LocalBluetoothProfile;
+import com.android.settingslib.bluetooth.LocalBluetoothProfileManager;
import com.android.settingslib.utils.ThreadUtils;
import com.google.common.base.Supplier;
import com.google.common.collect.ImmutableList;
+import java.util.ArrayList;
import java.util.Collection;
import java.util.HashSet;
import java.util.List;
@@ -70,6 +76,7 @@
public final class Utils {
private static final String TAG = "BluetoothUtils";
+ private static final String ENABLE_DUAL_MODE_AUDIO = "persist.bluetooth.enable_dual_mode_audio";
static final boolean V = BluetoothUtils.V; // verbose logging
static final boolean D = BluetoothUtils.D; // regular logging
@@ -360,4 +367,119 @@
dialog.show();
return dialog;
}
+
+ /** Enables/disables LE Audio profile for the device. */
+ public static void setLeAudioEnabled(
+ @NonNull LocalBluetoothManager manager,
+ @NonNull CachedBluetoothDevice cachedDevice,
+ boolean enable) {
+ List<CachedBluetoothDevice> devices =
+ List.copyOf(findAllCachedBluetoothDevicesByGroupId(manager, cachedDevice));
+ setLeAudioEnabled(manager, devices, enable);
+ }
+
+ /** Enables/disables LE Audio profile for the devices in the same csip group. */
+ public static void setLeAudioEnabled(
+ @NonNull LocalBluetoothManager manager,
+ @NonNull List<CachedBluetoothDevice> devicesWithSameGroupId,
+ boolean enable) {
+ LocalBluetoothProfileManager profileManager = manager.getProfileManager();
+ LeAudioProfile leAudioProfile = profileManager.getLeAudioProfile();
+ List<CachedBluetoothDevice> leAudioDevices =
+ getDevicesWithProfile(devicesWithSameGroupId, leAudioProfile);
+ if (leAudioDevices.isEmpty()) {
+ Log.i(TAG, "Fail to setLeAudioEnabled, no LE Audio profile found.");
+ }
+ boolean dualModeEnabled = SystemProperties.getBoolean(ENABLE_DUAL_MODE_AUDIO, false);
+
+ if (enable && !dualModeEnabled) {
+ Log.i(TAG, "Disabling classic audio profiles because dual mode is disabled");
+ setProfileEnabledWhenChangingLeAudio(
+ devicesWithSameGroupId, profileManager.getA2dpProfile(), false);
+ setProfileEnabledWhenChangingLeAudio(
+ devicesWithSameGroupId, profileManager.getHeadsetProfile(), false);
+ }
+
+ HearingAidProfile asha = profileManager.getHearingAidProfile();
+ LocalBluetoothLeBroadcastAssistant broadcastAssistant =
+ profileManager.getLeAudioBroadcastAssistantProfile();
+
+ for (CachedBluetoothDevice leAudioDevice : leAudioDevices) {
+ Log.d(
+ TAG,
+ "device:"
+ + leAudioDevice.getDevice().getAnonymizedAddress()
+ + " set LE profile enabled: "
+ + enable);
+ leAudioProfile.setEnabled(leAudioDevice.getDevice(), enable);
+ if (asha != null) {
+ asha.setEnabled(leAudioDevice.getDevice(), !enable);
+ }
+ if (broadcastAssistant != null) {
+ Log.d(
+ TAG,
+ "device:"
+ + leAudioDevice.getDevice().getAnonymizedAddress()
+ + " enable LE broadcast assistant profile: "
+ + enable);
+ broadcastAssistant.setEnabled(leAudioDevice.getDevice(), enable);
+ }
+ }
+
+ if (!enable && !dualModeEnabled) {
+ Log.i(TAG, "Enabling classic audio profiles because dual mode is disabled");
+ setProfileEnabledWhenChangingLeAudio(
+ devicesWithSameGroupId, profileManager.getA2dpProfile(), true);
+ setProfileEnabledWhenChangingLeAudio(
+ devicesWithSameGroupId, profileManager.getHeadsetProfile(), true);
+ }
+ }
+
+ private static List<CachedBluetoothDevice> getDevicesWithProfile(
+ List<CachedBluetoothDevice> devices, LocalBluetoothProfile profile) {
+ List<CachedBluetoothDevice> devicesWithProfile = new ArrayList<>();
+ for (CachedBluetoothDevice device : devices) {
+ for (LocalBluetoothProfile currentProfile : device.getProfiles()) {
+ if (currentProfile.toString().equals(profile.toString())) {
+ devicesWithProfile.add(device);
+ }
+ }
+ }
+ return devicesWithProfile;
+ }
+
+ private static void setProfileEnabledWhenChangingLeAudio(
+ List<CachedBluetoothDevice> devices,
+ @Nullable LocalBluetoothProfile profile,
+ boolean enable) {
+ if (profile == null) {
+ Log.i(TAG, "profile is null");
+ return;
+ }
+ List<CachedBluetoothDevice> deviceWithProfile = getDevicesWithProfile(devices, profile);
+ Log.d(TAG, "Set " + profile + " enabled:" + enable + " when switching LE Audio");
+ for (CachedBluetoothDevice profileDevice : deviceWithProfile) {
+ if (profile.isEnabled(profileDevice.getDevice()) != enable) {
+ Log.d(
+ TAG,
+ "The "
+ + profileDevice.getDevice().getAnonymizedAddress()
+ + ":"
+ + profile
+ + " set to "
+ + enable);
+ profile.setEnabled(profileDevice.getDevice(), enable);
+ } else {
+ Log.d(
+ TAG,
+ "The "
+ + profileDevice.getDevice().getAnonymizedAddress()
+ + ":"
+ + profile
+ + " profile is already "
+ + enable
+ + ". Do nothing.");
+ }
+ }
+ }
}
diff --git a/src/com/android/settings/connecteddevice/audiosharing/AudioSharingSwitchBarController.java b/src/com/android/settings/connecteddevice/audiosharing/AudioSharingSwitchBarController.java
index 92ebc57..f1fcd69 100644
--- a/src/com/android/settings/connecteddevice/audiosharing/AudioSharingSwitchBarController.java
+++ b/src/com/android/settings/connecteddevice/audiosharing/AudioSharingSwitchBarController.java
@@ -192,7 +192,7 @@
Log.d(TAG, "Skip handleOnBroadcastReady, not in starting process");
return;
}
- handleOnBroadcastReady();
+ handleOnBroadcastReady(metadata);
}
@Override
@@ -273,7 +273,7 @@
+ mSinksInAdding);
if (mSinksToWaitFor.contains(sink)) {
mSinksToWaitFor.remove(sink);
- if (mSinksToWaitFor.isEmpty()) {
+ if (mSinksToWaitFor.isEmpty() && mBroadcast != null) {
// To avoid users advance to share then pair flow before the
// primary/active sinks successfully join the audio sharing,
// popup dialog till adding source complete for mSinksToWaitFor.
@@ -284,7 +284,8 @@
/* userTriggered= */ false,
/* deviceCountInSharing= */ 1,
/* candidateDeviceCount= */ 0);
- showAudioSharingDialog(eventData);
+ showJoinAudioSharingDialog(eventData,
+ mBroadcast.getLatestBluetoothLeBroadcastMetadata());
}
}
}
@@ -501,9 +502,10 @@
mBtManager == null ? null : mBtManager.getCachedDeviceManager();
CachedBluetoothDevice cachedDevice =
deviceManager == null ? null : deviceManager.findDevice(device);
- if (cachedDevice != null) {
+ if (cachedDevice != null && mBroadcast != null) {
Log.d(TAG, "handleAutoAddSourceAfterPair, device = " + device.getAnonymizedAddress());
- addSourceToTargetSinks(ImmutableList.of(device), cachedDevice.getName());
+ addSourceToTargetSinks(ImmutableList.of(device), cachedDevice.getName(),
+ mBroadcast.getLatestBluetoothLeBroadcastMetadata());
}
}
@@ -642,7 +644,7 @@
return mAssistant != null && mAssistant.getAllConnectedDevices().isEmpty();
}
- private void handleOnBroadcastReady() {
+ private void handleOnBroadcastReady(@NonNull BluetoothLeBroadcastMetadata metadata) {
List<BluetoothDevice> targetActiveSinks = mTargetActiveItem == null ? ImmutableList.of()
: mGroupedConnectedDevices.getOrDefault(
mTargetActiveItem.getGroupId(), ImmutableList.of());
@@ -656,7 +658,7 @@
// Auto add primary/active sinks w/o user interactions.
if (!targetActiveSinks.isEmpty() && mTargetActiveItem != null) {
Log.d(TAG, "handleOnBroadcastReady: automatically add source to active sinks.");
- addSourceToTargetSinks(targetActiveSinks, mTargetActiveItem.getName());
+ addSourceToTargetSinks(targetActiveSinks, mTargetActiveItem.getName(), metadata);
// To avoid users advance to share then pair flow before the primary/active sinks
// successfully join the audio sharing, save the primary/active sinks in mSinksToWaitFor
// and popup dialog till adding source complete for these sinks.
@@ -677,7 +679,7 @@
AudioSharingDeviceItem target = mDeviceItemsForSharing.get(0);
List<BluetoothDevice> targetSinks = mGroupedConnectedDevices.getOrDefault(
target.getGroupId(), ImmutableList.of());
- addSourceToTargetSinks(targetSinks, target.getName());
+ addSourceToTargetSinks(targetSinks, target.getName(), metadata);
cleanUpStatesForStartSharing();
// TODO: Add metric for auto add by intent
return;
@@ -698,20 +700,21 @@
// successfully join the audio sharing, popup dialog till adding source complete for
// mSinksToWaitFor.
if (mSinksToWaitFor.isEmpty() && !mStoppingSharing.get()) {
- showAudioSharingDialog(eventData);
+ showJoinAudioSharingDialog(eventData, metadata);
}
}
- private void showAudioSharingDialog(Pair<Integer, Object>[] eventData) {
+ private void showJoinAudioSharingDialog(Pair<Integer, Object>[] eventData,
+ @Nullable BluetoothLeBroadcastMetadata metadata) {
if (!BluetoothUtils.isBroadcasting(mBtManager)) {
- Log.d(TAG, "Skip showAudioSharingDialog, broadcast is stopped");
+ Log.d(TAG, "Skip showJoinAudioSharingDialog, broadcast is stopped");
return;
}
AudioSharingDialogFragment.DialogEventListener listener =
new AudioSharingDialogFragment.DialogEventListener() {
@Override
public void onPositiveClick() {
- // Could go to other pages, dismiss the progress dialog.
+ // Could go to other pages (pair new device), dismiss the progress dialog.
dismissProgressDialogIfNeeded();
cleanUpStatesForStartSharing();
}
@@ -720,19 +723,17 @@
public void onItemClick(@NonNull AudioSharingDeviceItem item) {
List<BluetoothDevice> targetSinks = mGroupedConnectedDevices.getOrDefault(
item.getGroupId(), ImmutableList.of());
- addSourceToTargetSinks(targetSinks, item.getName());
+ addSourceToTargetSinks(targetSinks, item.getName(), metadata);
cleanUpStatesForStartSharing();
}
@Override
public void onCancelClick() {
- // Could go to other pages, dismiss the progress dialog.
+ // Could go to other pages (show qr code), dismiss the progress dialog.
dismissProgressDialogIfNeeded();
cleanUpStatesForStartSharing();
}
};
- BluetoothLeBroadcastMetadata metadata = mBroadcast == null ? null
- : mBroadcast.getLatestBluetoothLeBroadcastMetadata();
AudioSharingUtils.postOnMainThread(
mContext,
() -> AudioSharingDialogFragment.show(
@@ -828,13 +829,27 @@
});
}
- private void addSourceToTargetSinks(List<BluetoothDevice> targetActiveSinks,
- @NonNull String sinkName) {
- mSinksInAdding.addAll(targetActiveSinks);
+ private void addSourceToTargetSinks(List<BluetoothDevice> targetGroupedSinks,
+ @NonNull String targetSinkName, @Nullable BluetoothLeBroadcastMetadata metadata) {
+ if (targetGroupedSinks.isEmpty()) {
+ Log.d(TAG, "Skip addSourceToTargetSinks, no sinks.");
+ return;
+ }
+ if (metadata == null) {
+ Log.d(TAG, "Skip addSourceToTargetSinks, metadata is null");
+ return;
+ }
+ if (mAssistant == null) {
+ Log.d(TAG, "skip addSourceToTargetDevices, assistant profile is null.");
+ return;
+ }
+ mSinksInAdding.addAll(targetGroupedSinks);
String progressMessage = mContext.getString(
- R.string.audio_sharing_progress_dialog_add_source_content, sinkName);
+ R.string.audio_sharing_progress_dialog_add_source_content, targetSinkName);
showProgressDialog(progressMessage);
- AudioSharingUtils.addSourceToTargetSinks(targetActiveSinks, mBtManager);
+ for (BluetoothDevice sink : targetGroupedSinks) {
+ mAssistant.addSource(sink, metadata, /* isGroupOp= */ false);
+ }
}
private void showProgressDialog(@NonNull String progressMessage) {
diff --git a/src/com/android/settings/deviceinfo/PhoneNumberPreferenceController.java b/src/com/android/settings/deviceinfo/PhoneNumberPreferenceController.java
index b49d62d..bb39d88 100644
--- a/src/com/android/settings/deviceinfo/PhoneNumberPreferenceController.java
+++ b/src/com/android/settings/deviceinfo/PhoneNumberPreferenceController.java
@@ -65,9 +65,10 @@
@Override
public void displayPreference(PreferenceScreen screen) {
super.displayPreference(screen);
- if (!SubscriptionUtil.isSimHardwareVisible(mContext)) {
+ if (!isAvailable()) {
return;
}
+
final Preference preference = screen.findPreference(getPreferenceKey());
final PreferenceCategory category = screen.findPreference(KEY_PREFERENCE_CATEGORY);
mPreferenceList.add(preference);
diff --git a/src/com/android/settings/display/DeviceStateAutoRotateSettingController.java b/src/com/android/settings/display/DeviceStateAutoRotateSettingController.java
index d3950ee..5c2dec2 100644
--- a/src/com/android/settings/display/DeviceStateAutoRotateSettingController.java
+++ b/src/com/android/settings/display/DeviceStateAutoRotateSettingController.java
@@ -35,7 +35,6 @@
import com.android.settings.overlay.FeatureFactory;
import com.android.settingslib.core.instrumentation.MetricsFeatureProvider;
import com.android.settingslib.devicestate.DeviceStateAutoRotateSettingManager;
-import com.android.settingslib.devicestate.DeviceStateRotationLockSettingsManager;
import com.android.settingslib.search.SearchIndexableRaw;
import java.util.List;
@@ -46,7 +45,7 @@
private TwoStatePreference mPreference;
- private final DeviceStateRotationLockSettingsManager mAutoRotateSettingsManager;
+ private final DeviceStateAutoRotateSettingManager mAutoRotateSettingsManager;
private final int mOrder;
private final DeviceStateAutoRotateSettingManager.DeviceStateAutoRotateSettingListener
mDeviceStateAutoRotateSettingListener = () -> updateState(mPreference);
@@ -62,7 +61,8 @@
mMetricsFeatureProvider = metricsFeatureProvider;
mDeviceState = deviceState;
mDeviceStateDescription = deviceStateDescription;
- mAutoRotateSettingsManager = DeviceStateRotationLockSettingsManager.getInstance(context);
+ mAutoRotateSettingsManager =
+ DeviceStateAutoRotateSettingManagerProvider.getSingletonInstance(context);
mOrder = order;
}
diff --git a/src/com/android/settings/display/DeviceStateAutoRotateSettingManagerProvider.kt b/src/com/android/settings/display/DeviceStateAutoRotateSettingManagerProvider.kt
new file mode 100644
index 0000000..906ffe4
--- /dev/null
+++ b/src/com/android/settings/display/DeviceStateAutoRotateSettingManagerProvider.kt
@@ -0,0 +1,62 @@
+/*
+ * 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.display
+
+import android.content.Context
+import android.hardware.devicestate.DeviceStateManager
+import android.os.Build
+import android.os.Handler
+import android.os.Looper
+import com.android.internal.annotations.VisibleForTesting
+import com.android.settingslib.devicestate.AndroidSecureSettings
+import com.android.settingslib.devicestate.DeviceStateAutoRotateSettingManager
+import com.android.settingslib.devicestate.DeviceStateAutoRotateSettingManagerProvider.createInstance
+import com.android.settingslib.devicestate.PosturesHelper
+import com.android.settingslib.utils.ThreadUtils
+import com.android.window.flags.Flags
+
+/**
+ * Provides appropriate instance of [DeviceStateAutoRotateSettingManager], based on the value of
+ * [Flags.FLAG_ENABLE_DEVICE_STATE_AUTO_ROTATE_SETTING_REFACTOR].
+ */
+object DeviceStateAutoRotateSettingManagerProvider {
+ private var nullableSingletonSettingManager: DeviceStateAutoRotateSettingManager? = null
+
+ /**
+ * Provides a singleton instance of [DeviceStateAutoRotateSettingManager], based on the
+ * value of[Flags.FLAG_ENABLE_DEVICE_STATE_AUTO_ROTATE_SETTING_REFACTOR]. It is supposed to
+ * be used by apps that don't support dagger to provide and manager instance.
+ */
+ @JvmStatic
+ fun getSingletonInstance(context: Context) =
+ nullableSingletonSettingManager ?: createInstance(
+ context,
+ ThreadUtils.getBackgroundExecutor(),
+ AndroidSecureSettings(context.contentResolver),
+ Handler(Looper.getMainLooper()),
+ PosturesHelper(context, context.getSystemService(DeviceStateManager::class.java))
+ ).also {
+ nullableSingletonSettingManager = it
+ }
+
+ /** Resets the singleton instance of [DeviceStateAutoRotateSettingManager]. */
+ @JvmStatic
+ @VisibleForTesting
+ fun resetInstance() {
+ nullableSingletonSettingManager = null
+ }
+}
diff --git a/src/com/android/settings/display/DeviceStateAutoRotationHelper.java b/src/com/android/settings/display/DeviceStateAutoRotationHelper.java
index 3bf9def..7b28524 100644
--- a/src/com/android/settings/display/DeviceStateAutoRotationHelper.java
+++ b/src/com/android/settings/display/DeviceStateAutoRotationHelper.java
@@ -16,6 +16,8 @@
package com.android.settings.display;
+import static com.android.settingslib.devicestate.DeviceStateAutoRotateSettingUtils.isDeviceStateRotationLockEnabled;
+
import android.content.Context;
import android.util.Log;
@@ -25,7 +27,6 @@
import com.android.settings.R;
import com.android.settings.core.BasePreferenceController;
import com.android.settingslib.core.AbstractPreferenceController;
-import com.android.settingslib.devicestate.DeviceStateRotationLockSettingsManager;
import com.android.settingslib.devicestate.SettableDeviceState;
import com.android.settingslib.search.SearchIndexableRaw;
@@ -51,8 +52,8 @@
static ImmutableList<AbstractPreferenceController> createPreferenceControllers(
Context context) {
- List<SettableDeviceState> settableDeviceStates = DeviceStateRotationLockSettingsManager
- .getInstance(context).getSettableDeviceStates();
+ List<SettableDeviceState> settableDeviceStates = DeviceStateAutoRotateSettingManagerProvider
+ .getSingletonInstance(context).getSettableDeviceStates();
int numDeviceStates = settableDeviceStates.size();
if (numDeviceStates == 0) {
return ImmutableList.of();
@@ -99,7 +100,7 @@
/** Returns whether the device state based auto-rotation settings are enabled. */
public static boolean isDeviceStateRotationEnabled(Context context) {
return RotationPolicy.isRotationLockToggleVisible(context)
- && DeviceStateRotationLockSettingsManager.isDeviceStateRotationLockEnabled(context);
+ && isDeviceStateRotationLockEnabled(context);
}
/**
@@ -108,6 +109,6 @@
*/
public static boolean isDeviceStateRotationEnabledForA11y(Context context) {
return RotationPolicy.isRotationSupported(context)
- && DeviceStateRotationLockSettingsManager.isDeviceStateRotationLockEnabled(context);
+ && isDeviceStateRotationLockEnabled(context);
}
}
diff --git a/src/com/android/settings/display/SmartAutoRotateController.java b/src/com/android/settings/display/SmartAutoRotateController.java
index c99b2f8..4bc28ff 100644
--- a/src/com/android/settings/display/SmartAutoRotateController.java
+++ b/src/com/android/settings/display/SmartAutoRotateController.java
@@ -47,7 +47,6 @@
import com.android.settings.overlay.FeatureFactory;
import com.android.settingslib.core.instrumentation.MetricsFeatureProvider;
import com.android.settingslib.devicestate.DeviceStateAutoRotateSettingManager;
-import com.android.settingslib.devicestate.DeviceStateRotationLockSettingsManager;
/**
* SmartAutoRotateController controls whether auto rotation is enabled
@@ -75,7 +74,7 @@
}
};
- private final DeviceStateRotationLockSettingsManager mDeviceStateAutoRotateSettingsManager;
+ private final DeviceStateAutoRotateSettingManager mDeviceStateAutoRotateSettingsManager;
private final DeviceStateAutoRotateSettingManager.DeviceStateAutoRotateSettingListener
mDeviceStateAutoRotateSettingListener = () -> updateState(mPreference);
private RotationPolicy.RotationPolicyListener mRotationPolicyListener;
@@ -85,8 +84,9 @@
mMetricsFeatureProvider = FeatureFactory.getFeatureFactory().getMetricsFeatureProvider();
mPrivacyManager = SensorPrivacyManager.getInstance(context);
mPowerManager = context.getSystemService(PowerManager.class);
- mDeviceStateAutoRotateSettingsManager = DeviceStateRotationLockSettingsManager.getInstance(
- context);
+ mDeviceStateAutoRotateSettingsManager =
+ DeviceStateAutoRotateSettingManagerProvider.getSingletonInstance(
+ context);
}
@Override
diff --git a/src/com/android/settings/localepicker/LocaleListEditor.java b/src/com/android/settings/localepicker/LocaleListEditor.java
index 2f8d203..87deea1 100644
--- a/src/com/android/settings/localepicker/LocaleListEditor.java
+++ b/src/com/android/settings/localepicker/LocaleListEditor.java
@@ -529,7 +529,11 @@
@Nullable Locale defaultLocaleBeforeRemoval) {
Locale currentSystemLocale = LocalePicker.getLocales().get(0);
if (!localeInfo.getLocale().equals(currentSystemLocale)) {
- displayDialogFragment(localeInfo, true);
+ if (Locale.getDefault().equals(localeInfo.getLocale())) {
+ mAdapter.doTheUpdate();
+ } else {
+ displayDialogFragment(localeInfo, true);
+ }
} else {
if (!localeInfo.isTranslated()) {
if (defaultLocaleBeforeRemoval == null) {
diff --git a/src/com/android/settings/regionalpreferences/RegionPickerBaseListPreferenceController.java b/src/com/android/settings/regionalpreferences/RegionPickerBaseListPreferenceController.java
index fc12d1b..5768421 100644
--- a/src/com/android/settings/regionalpreferences/RegionPickerBaseListPreferenceController.java
+++ b/src/com/android/settings/regionalpreferences/RegionPickerBaseListPreferenceController.java
@@ -18,7 +18,6 @@
import android.content.Context;
import android.os.Bundle;
-import android.os.LocaleList;
import android.util.Log;
import androidx.annotation.NonNull;
@@ -92,7 +91,7 @@
? getSuggestedLocaleList()
: getSupportedLocaleList();
if (getPreferenceCategoryKey().contains(KEY_SUGGESTED)) {
- Locale systemLocale = LocaleList.getDefault().get(0);
+ Locale systemLocale = Locale.getDefault();
LocaleStore.LocaleInfo localeInfo = LocaleStore.getLocaleInfo(systemLocale);
result.add(localeInfo);
}
@@ -106,7 +105,7 @@
mPreferenceCategory.addPreference(pref);
pref.setTitle(locale.getFullCountryNameNative());
pref.setKey(locale.toString());
- if (locale.getLocale().equals(LocaleList.getDefault().get(0))) {
+ if (locale.getLocale().equals(Locale.getDefault())) {
pref.setChecked(true);
} else {
pref.setChecked(false);
@@ -154,7 +153,7 @@
private List<LocaleStore.LocaleInfo> getSortedLocaleList(
List<LocaleStore.LocaleInfo> localeInfos) {
- final Locale sortingLocale = LocaleList.getDefault().get(0);
+ final Locale sortingLocale = Locale.getDefault();
final LocaleHelper.LocaleInfoComparator comp =
new LocaleHelper.LocaleInfoComparator(sortingLocale, true);
Collections.sort(localeInfos, comp);
@@ -162,7 +161,7 @@
}
private void switchRegion(LocaleStore.LocaleInfo localeInfo) {
- if (localeInfo.getLocale().equals(LocaleList.getDefault().get(0))) {
+ if (localeInfo.getLocale().equals(Locale.getDefault())) {
return;
}
diff --git a/src/com/android/settings/regionalpreferences/RegionPickerFragment.java b/src/com/android/settings/regionalpreferences/RegionPickerFragment.java
index c064565..cf4d9b9 100644
--- a/src/com/android/settings/regionalpreferences/RegionPickerFragment.java
+++ b/src/com/android/settings/regionalpreferences/RegionPickerFragment.java
@@ -19,7 +19,6 @@
import android.app.settings.SettingsEnums;
import android.content.Context;
import android.os.Bundle;
-import android.os.LocaleList;
import android.provider.Settings;
import androidx.annotation.NonNull;
@@ -84,7 +83,7 @@
private List<AbstractPreferenceController> buildPreferenceControllers(
@NonNull Context context) {
- Locale parentLocale = LocaleStore.getLocaleInfo(LocaleList.getDefault().get(0)).getParent();
+ Locale parentLocale = LocaleStore.getLocaleInfo(Locale.getDefault()).getParent();
LocaleStore.LocaleInfo parentLocaleInfo = LocaleStore.getLocaleInfo(parentLocale);
SystemRegionSuggestedListPreferenceController mSuggestedListPreferenceController =
new SystemRegionSuggestedListPreferenceController(
diff --git a/src/com/android/settings/regionalpreferences/RegionPreferenceController.java b/src/com/android/settings/regionalpreferences/RegionPreferenceController.java
index 345bd75..a9ce120 100644
--- a/src/com/android/settings/regionalpreferences/RegionPreferenceController.java
+++ b/src/com/android/settings/regionalpreferences/RegionPreferenceController.java
@@ -17,7 +17,6 @@
package com.android.settings.regionalpreferences;
import android.content.Context;
-import android.os.LocaleList;
import androidx.annotation.NonNull;
import androidx.preference.Preference;
@@ -27,6 +26,8 @@
import com.android.settings.core.BasePreferenceController;
import com.android.settings.flags.Flags;
+import java.util.Locale;
+
/** A controller for the entry of region picker page */
public class RegionPreferenceController extends BasePreferenceController {
@@ -39,7 +40,7 @@
super.displayPreference(screen);
Preference preference = screen.findPreference(getPreferenceKey());
LocaleStore.LocaleInfo localeInfo = LocaleStore.getLocaleInfo(
- LocaleList.getDefault().get(0));
+ Locale.getDefault());
preference.setSummary(localeInfo.getFullCountryNameNative());
}
diff --git a/src/com/android/settings/safetycenter/BiometricSourcesUtils.java b/src/com/android/settings/safetycenter/BiometricSourcesUtils.java
index 786e3cf..9cadbbb 100644
--- a/src/com/android/settings/safetycenter/BiometricSourcesUtils.java
+++ b/src/com/android/settings/safetycenter/BiometricSourcesUtils.java
@@ -19,15 +19,11 @@
import android.app.PendingIntent;
import android.content.Context;
import android.content.Intent;
-import android.hardware.face.FaceManager;
-import android.hardware.fingerprint.FingerprintManager;
import android.safetycenter.SafetyEvent;
import android.safetycenter.SafetySourceData;
import android.safetycenter.SafetySourceIssue;
import android.safetycenter.SafetySourceStatus;
-import com.android.settings.Utils;
-
/** Static helpers for setting SafetyCenter data for biometric safety sources. */
public final class BiometricSourcesUtils {
@@ -93,15 +89,6 @@
.setSafetySourceData(context, safetySourceId, safetySourceData, safetyEvent);
}
- /** Check whether the multiple biometrics enrollment is needed. */
- public static boolean isMultipleBiometricsEnrollmentNeeded(Context context, int userId) {
- FaceManager faceManager = Utils.getFaceManagerOrNull(context);
- FingerprintManager fingerprintManager = Utils.getFingerprintManagerOrNull(context);
- return Utils.isMultipleBiometricsSupported(context)
- && !faceManager.hasEnrolledTemplates(userId)
- && !fingerprintManager.hasEnrolledFingerprints(userId);
- }
-
/** Helper method for creating a pending intent. */
public static PendingIntent createPendingIntent(
Context context, Intent intent, int requestCode) {
diff --git a/src/com/android/settings/safetycenter/FaceSafetySource.java b/src/com/android/settings/safetycenter/FaceSafetySource.java
index c5bde6e..73b6df5 100644
--- a/src/com/android/settings/safetycenter/FaceSafetySource.java
+++ b/src/com/android/settings/safetycenter/FaceSafetySource.java
@@ -16,7 +16,6 @@
package com.android.settings.safetycenter;
-import static com.android.settings.biometrics.BiometricEnrollActivity.EXTRA_LAUNCH_FACE_ENROLL_FIRST;
import static com.android.settings.safetycenter.BiometricSourcesUtils.REQUEST_CODE_FACE_SETTING;
import android.content.Context;
@@ -28,7 +27,6 @@
import android.safetycenter.SafetyEvent;
import com.android.settings.Utils;
-import com.android.settings.biometrics.BiometricEnrollActivity;
import com.android.settings.biometrics.BiometricNavigationUtils;
import com.android.settings.biometrics.face.FaceStatusUtils;
import com.android.settings.flags.Flags;
@@ -75,16 +73,6 @@
Context profileParentContext = context.createContextAsUser(profileParentUserHandle, 0);
if (Utils.hasFaceHardware(context)) {
- boolean isMultipleBiometricsEnrollmentNeeded =
- BiometricSourcesUtils.isMultipleBiometricsEnrollmentNeeded(context, userId);
- String settingClassName = isMultipleBiometricsEnrollmentNeeded
- ? BiometricEnrollActivity.class.getName()
- : faceStatusUtils.getSettingsClassName();
- Bundle bundle = new Bundle();
- if (isMultipleBiometricsEnrollmentNeeded) {
- // Launch face enrollment first then fingerprint enrollment.
- bundle.putBoolean(EXTRA_LAUNCH_FACE_ENROLL_FIRST, true);
- }
RestrictedLockUtils.EnforcedAdmin disablingAdmin = faceStatusUtils.getDisablingAdmin();
BiometricSourcesUtils.setBiometricSafetySourceData(
SAFETY_SOURCE_ID,
@@ -96,9 +84,9 @@
biometricNavigationUtils
.getBiometricSettingsIntent(
context,
- settingClassName,
+ faceStatusUtils.getSettingsClassName(),
disablingAdmin,
- bundle)
+ Bundle.EMPTY)
.setIdentifier(Integer.toString(userId)),
REQUEST_CODE_FACE_SETTING),
disablingAdmin == null /* enabled */,
diff --git a/src/com/android/settings/safetycenter/FingerprintSafetySource.java b/src/com/android/settings/safetycenter/FingerprintSafetySource.java
index 752fa69..62f218b 100644
--- a/src/com/android/settings/safetycenter/FingerprintSafetySource.java
+++ b/src/com/android/settings/safetycenter/FingerprintSafetySource.java
@@ -27,7 +27,6 @@
import android.safetycenter.SafetyEvent;
import com.android.settings.Utils;
-import com.android.settings.biometrics.BiometricEnrollActivity;
import com.android.settings.biometrics.BiometricNavigationUtils;
import com.android.settings.biometrics.fingerprint.FingerprintStatusUtils;
import com.android.settings.flags.Flags;
@@ -75,11 +74,6 @@
Context profileParentContext = context.createContextAsUser(profileParentUserHandle, 0);
if (Utils.hasFingerprintHardware(context)) {
- boolean isMultipleBiometricsEnrollmentNeeded =
- BiometricSourcesUtils.isMultipleBiometricsEnrollmentNeeded(context, userId);
- String settingClassName = isMultipleBiometricsEnrollmentNeeded
- ? BiometricEnrollActivity.class.getName()
- : fingerprintStatusUtils.getSettingsClassName();
RestrictedLockUtils.EnforcedAdmin disablingAdmin =
fingerprintStatusUtils.getDisablingAdmin();
BiometricSourcesUtils.setBiometricSafetySourceData(
@@ -92,7 +86,7 @@
biometricNavigationUtils
.getBiometricSettingsIntent(
context,
- settingClassName,
+ fingerprintStatusUtils.getSettingsClassName(),
disablingAdmin,
Bundle.EMPTY)
.setIdentifier(Integer.toString(userId)),
diff --git a/tests/robotests/src/com/android/settings/accessibility/LockScreenRotationPreferenceControllerTest.java b/tests/robotests/src/com/android/settings/accessibility/LockScreenRotationPreferenceControllerTest.java
index c98ad3d..88623ac 100644
--- a/tests/robotests/src/com/android/settings/accessibility/LockScreenRotationPreferenceControllerTest.java
+++ b/tests/robotests/src/com/android/settings/accessibility/LockScreenRotationPreferenceControllerTest.java
@@ -16,9 +16,14 @@
package com.android.settings.accessibility;
+import static com.android.settings.testutils.DeviceStateAutoRotateSettingTestUtils.setDeviceStateRotationLockEnabled;
+
import static com.google.common.truth.Truth.assertThat;
+import static org.mockito.Mockito.when;
+
import android.content.Context;
+import android.content.res.Resources;
import android.os.UserHandle;
import android.provider.Settings;
@@ -26,12 +31,14 @@
import com.android.internal.view.RotationPolicy;
import com.android.settings.core.BasePreferenceController;
-import com.android.settings.testutils.shadow.ShadowDeviceStateRotationLockSettingsManager;
import com.android.settings.testutils.shadow.ShadowRotationPolicy;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
+import org.mockito.Mock;
+import org.mockito.Mockito;
+import org.mockito.MockitoAnnotations;
import org.robolectric.RobolectricTestRunner;
import org.robolectric.RuntimeEnvironment;
import org.robolectric.annotation.Config;
@@ -41,48 +48,45 @@
com.android.settings.testutils.shadow.ShadowSystemSettings.class,
})
public class LockScreenRotationPreferenceControllerTest {
-
+ @Mock
+ private Resources mResources;
private Context mContext;
private SwitchPreference mPreference;
private LockScreenRotationPreferenceController mController;
@Before
public void setUp() {
- mContext = RuntimeEnvironment.application;
+ MockitoAnnotations.initMocks(this);
+ mContext = Mockito.spy(RuntimeEnvironment.application);
mPreference = new SwitchPreference(mContext);
+ when(mContext.getResources()).thenReturn(mResources);
+
mController = new LockScreenRotationPreferenceController(mContext, "lock_screen");
}
@Test
- @Config(shadows = {
- ShadowRotationPolicy.class,
- ShadowDeviceStateRotationLockSettingsManager.class
- })
+ @Config(shadows = {ShadowRotationPolicy.class})
public void getAvailabilityStatus_supportedRotation_shouldReturnAvailable() {
ShadowRotationPolicy.setRotationSupported(true /* supported */);
+ setDeviceStateRotationLockEnabled(false, mResources);
assertThat(mController.getAvailabilityStatus()).isEqualTo(
BasePreferenceController.AVAILABLE);
}
@Test
- @Config(shadows = {
- ShadowRotationPolicy.class,
- ShadowDeviceStateRotationLockSettingsManager.class
- })
+ @Config(shadows = {ShadowRotationPolicy.class})
public void getAvailabilityStatus_deviceStateRotationEnabled_returnsUnsupported() {
ShadowRotationPolicy.setRotationSupported(true /* supported */);
- ShadowDeviceStateRotationLockSettingsManager.setDeviceStateRotationLockEnabled(true);
+ setDeviceStateRotationLockEnabled(true, mResources);
assertThat(mController.getAvailabilityStatus()).isEqualTo(
BasePreferenceController.UNSUPPORTED_ON_DEVICE);
}
@Test
- @Config(shadows = {
- ShadowRotationPolicy.class,
- ShadowDeviceStateRotationLockSettingsManager.class
- }) public void getAvailabilityStatus_unsupportedRotation_shouldReturnUnsupportedOnDevice() {
+ @Config(shadows = {ShadowRotationPolicy.class})
+ public void getAvailabilityStatus_unsupportedRotation_shouldReturnUnsupportedOnDevice() {
ShadowRotationPolicy.setRotationSupported(false /* supported */);
assertThat(mController.getAvailabilityStatus()).isEqualTo(
diff --git a/tests/robotests/src/com/android/settings/bluetooth/BluetoothKeyMissingReceiverTest.java b/tests/robotests/src/com/android/settings/bluetooth/BluetoothKeyMissingReceiverTest.java
index a183d8d..42d7105 100644
--- a/tests/robotests/src/com/android/settings/bluetooth/BluetoothKeyMissingReceiverTest.java
+++ b/tests/robotests/src/com/android/settings/bluetooth/BluetoothKeyMissingReceiverTest.java
@@ -127,6 +127,7 @@
public void broadcastReceiver_background_showNotification() {
Intent intent = spy(new Intent(BluetoothDevice.ACTION_KEY_MISSING));
when(intent.getParcelableExtra(BluetoothDevice.EXTRA_DEVICE)).thenReturn(mBluetoothDevice);
+ when(mBluetoothDevice.getBondState()).thenReturn(BluetoothDevice.BOND_BONDED);
BluetoothKeyMissingReceiver bluetoothKeyMissingReceiver = getReceiver(intent);
bluetoothKeyMissingReceiver.onReceive(mContext, intent);
@@ -141,6 +142,7 @@
when(mLocalBtManager.isForegroundActivity()).thenReturn(true);
Intent intent = spy(new Intent(BluetoothDevice.ACTION_KEY_MISSING));
when(intent.getParcelableExtra(BluetoothDevice.EXTRA_DEVICE)).thenReturn(mBluetoothDevice);
+ when(mBluetoothDevice.getBondState()).thenReturn(BluetoothDevice.BOND_BONDED);
BluetoothKeyMissingReceiver bluetoothKeyMissingReceiver = getReceiver(intent);
bluetoothKeyMissingReceiver.onReceive(mContext, intent);
diff --git a/tests/robotests/src/com/android/settings/bluetooth/UtilsTest.java b/tests/robotests/src/com/android/settings/bluetooth/UtilsTest.java
index 8859ebd..176bfa8 100644
--- a/tests/robotests/src/com/android/settings/bluetooth/UtilsTest.java
+++ b/tests/robotests/src/com/android/settings/bluetooth/UtilsTest.java
@@ -18,22 +18,29 @@
import static com.google.common.truth.Truth.assertThat;
import static org.mockito.ArgumentMatchers.any;
+import static org.mockito.ArgumentMatchers.anyBoolean;
import static org.mockito.ArgumentMatchers.anyInt;
import static org.mockito.ArgumentMatchers.anyString;
import static org.mockito.ArgumentMatchers.eq;
import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.never;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
+import android.bluetooth.BluetoothCsipSetCoordinator;
import android.bluetooth.BluetoothDevice;
import android.bluetooth.BluetoothLeBroadcastReceiveState;
import android.content.Context;
+import android.os.SystemProperties;
import com.android.internal.logging.nano.MetricsProto.MetricsEvent;
import com.android.settings.testutils.FakeFeatureFactory;
-import com.android.settings.testutils.shadow.ShadowBluetoothUtils;
+import com.android.settingslib.bluetooth.A2dpProfile;
import com.android.settingslib.bluetooth.CachedBluetoothDevice;
import com.android.settingslib.bluetooth.CachedBluetoothDeviceManager;
+import com.android.settingslib.bluetooth.HeadsetProfile;
+import com.android.settingslib.bluetooth.HearingAidProfile;
+import com.android.settingslib.bluetooth.LeAudioProfile;
import com.android.settingslib.bluetooth.LocalBluetoothLeBroadcast;
import com.android.settingslib.bluetooth.LocalBluetoothLeBroadcastAssistant;
import com.android.settingslib.bluetooth.LocalBluetoothManager;
@@ -41,8 +48,8 @@
import com.android.settingslib.core.instrumentation.MetricsFeatureProvider;
import com.google.common.collect.ImmutableList;
+import com.google.common.collect.ImmutableSet;
-import org.junit.After;
import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
@@ -52,10 +59,8 @@
import org.mockito.junit.MockitoJUnit;
import org.mockito.junit.MockitoRule;
import org.robolectric.RobolectricTestRunner;
-import org.robolectric.annotation.Config;
@RunWith(RobolectricTestRunner.class)
-@Config(shadows = {ShadowBluetoothUtils.class})
public class UtilsTest {
private static final int METADATA_FAST_PAIR_CUSTOMIZED_FIELDS = 25;
private static final String TEMP_BOND_METADATA =
@@ -73,6 +78,14 @@
@Mock
private LocalBluetoothLeBroadcastAssistant mAssistant;
@Mock
+ private A2dpProfile mA2dpProfile;
+ @Mock
+ private HeadsetProfile mHeadsetProfile;
+ @Mock
+ private LeAudioProfile mLeAudioProfile;
+ @Mock
+ private HearingAidProfile mHearingAidProfile;
+ @Mock
private CachedBluetoothDeviceManager mDeviceManager;
private MetricsFeatureProvider mMetricsFeatureProvider;
@@ -80,17 +93,14 @@
@Before
public void setUp() {
mMetricsFeatureProvider = FakeFeatureFactory.setupForTest().getMetricsFeatureProvider();
- ShadowBluetoothUtils.sLocalBluetoothManager = mLocalBtManager;
- mLocalBtManager = Utils.getLocalBtManager(mContext);
when(mLocalBtManager.getProfileManager()).thenReturn(mProfileManager);
when(mLocalBtManager.getCachedDeviceManager()).thenReturn(mDeviceManager);
when(mProfileManager.getLeAudioBroadcastProfile()).thenReturn(mBroadcast);
when(mProfileManager.getLeAudioBroadcastAssistantProfile()).thenReturn(mAssistant);
- }
-
- @After
- public void tearDown() {
- ShadowBluetoothUtils.reset();
+ when(mProfileManager.getA2dpProfile()).thenReturn(mA2dpProfile);
+ when(mProfileManager.getHeadsetProfile()).thenReturn(mHeadsetProfile);
+ when(mProfileManager.getLeAudioProfile()).thenReturn(mLeAudioProfile);
+ when(mProfileManager.getHearingAidProfile()).thenReturn(mHearingAidProfile);
}
@Test
@@ -170,4 +180,148 @@
when(mAssistant.getAllSources(any())).thenReturn(ImmutableList.of(state));
assertThat(Utils.shouldBlockPairingInAudioSharing(mLocalBtManager)).isTrue();
}
+
+ @Test
+ public void enableLeAudioProfile_multipleDeviceInGroup() {
+ CachedBluetoothDevice cachedDevice1 = mock(CachedBluetoothDevice.class);
+ CachedBluetoothDevice cachedDevice2 = mock(CachedBluetoothDevice.class);
+ CachedBluetoothDevice cachedDevice3 = mock(CachedBluetoothDevice.class);
+ BluetoothDevice device1 = mock(BluetoothDevice.class);
+ BluetoothDevice device2 = mock(BluetoothDevice.class);
+ BluetoothDevice device3 = mock(BluetoothDevice.class);
+ when(cachedDevice1.getDevice()).thenReturn(device1);
+ when(cachedDevice2.getDevice()).thenReturn(device2);
+ when(cachedDevice3.getDevice()).thenReturn(device3);
+ when(cachedDevice1.getMemberDevice()).thenReturn(ImmutableSet.of(cachedDevice2));
+ when(mDeviceManager.getCachedDevicesCopy())
+ .thenReturn(ImmutableList.of(cachedDevice1, cachedDevice3));
+ when(cachedDevice1.getGroupId()).thenReturn(1);
+ when(cachedDevice2.getGroupId()).thenReturn(1);
+ when(cachedDevice3.getGroupId()).thenReturn(2);
+ when(cachedDevice1.getProfiles())
+ .thenReturn(ImmutableList.of(mA2dpProfile, mHeadsetProfile, mLeAudioProfile));
+ when(cachedDevice2.getProfiles()).thenReturn(ImmutableList.of(mLeAudioProfile));
+ when(cachedDevice3.getProfiles())
+ .thenReturn(ImmutableList.of(mA2dpProfile, mHeadsetProfile, mLeAudioProfile));
+
+ Utils.setLeAudioEnabled(mLocalBtManager, cachedDevice2, true);
+
+ verify(mLeAudioProfile).setEnabled(device1, true);
+ verify(mLeAudioProfile).setEnabled(device2, true);
+ verify(mHearingAidProfile).setEnabled(device1, false);
+ verify(mAssistant).setEnabled(device1, true);
+ verify(mLeAudioProfile, never()).setEnabled(eq(device3), anyBoolean());
+ verify(mA2dpProfile, never()).setEnabled(eq(device3), anyBoolean());
+ verify(mHeadsetProfile, never()).setEnabled(eq(device3), anyBoolean());
+ }
+
+ @Test
+ public void enableLeAudioProfile_dualModeEnabled_a2dpAndHfpNotChanged() {
+ SystemProperties.set("persist.bluetooth.enable_dual_mode_audio", "true");
+ CachedBluetoothDevice cachedDevice1 = mock(CachedBluetoothDevice.class);
+ BluetoothDevice device1 = mock(BluetoothDevice.class);
+ when(cachedDevice1.getDevice()).thenReturn(device1);
+ when(cachedDevice1.getGroupId()).thenReturn(BluetoothCsipSetCoordinator.GROUP_ID_INVALID);
+ when(cachedDevice1.getProfiles())
+ .thenReturn(ImmutableList.of(mA2dpProfile, mHeadsetProfile, mLeAudioProfile));
+ when(mA2dpProfile.isEnabled(device1)).thenReturn(true);
+ when(mHeadsetProfile.isEnabled(device1)).thenReturn(true);
+
+ Utils.setLeAudioEnabled(mLocalBtManager, cachedDevice1, true);
+
+ verify(mLeAudioProfile).setEnabled(device1, true);
+ verify(mA2dpProfile, never()).setEnabled(device1, false);
+ verify(mHeadsetProfile, never()).setEnabled(device1, false);
+ }
+
+ @Test
+ public void enableLeAudioProfile_dualModeDisabled_disableA2dpAndHfp() {
+ SystemProperties.set("persist.bluetooth.enable_dual_mode_audio", "false");
+ CachedBluetoothDevice cachedDevice1 = mock(CachedBluetoothDevice.class);
+ BluetoothDevice device1 = mock(BluetoothDevice.class);
+ when(cachedDevice1.getDevice()).thenReturn(device1);
+ when(cachedDevice1.getGroupId()).thenReturn(BluetoothCsipSetCoordinator.GROUP_ID_INVALID);
+ when(cachedDevice1.getProfiles())
+ .thenReturn(ImmutableList.of(mA2dpProfile, mHeadsetProfile, mLeAudioProfile));
+ when(mA2dpProfile.isEnabled(device1)).thenReturn(true);
+ when(mHeadsetProfile.isEnabled(device1)).thenReturn(true);
+
+ Utils.setLeAudioEnabled(mLocalBtManager, cachedDevice1, true);
+
+ verify(mLeAudioProfile).setEnabled(device1, true);
+ verify(mA2dpProfile).setEnabled(device1, false);
+ verify(mHeadsetProfile).setEnabled(device1, false);
+ }
+
+ @Test
+ public void disableLeAudioProfile_multipleDeviceInGroup() {
+ CachedBluetoothDevice cachedDevice1 = mock(CachedBluetoothDevice.class);
+ CachedBluetoothDevice cachedDevice2 = mock(CachedBluetoothDevice.class);
+ CachedBluetoothDevice cachedDevice3 = mock(CachedBluetoothDevice.class);
+ BluetoothDevice device1 = mock(BluetoothDevice.class);
+ BluetoothDevice device2 = mock(BluetoothDevice.class);
+ BluetoothDevice device3 = mock(BluetoothDevice.class);
+ when(cachedDevice1.getDevice()).thenReturn(device1);
+ when(cachedDevice2.getDevice()).thenReturn(device2);
+ when(cachedDevice3.getDevice()).thenReturn(device3);
+ when(cachedDevice1.getMemberDevice()).thenReturn(ImmutableSet.of(cachedDevice2));
+ when(mDeviceManager.getCachedDevicesCopy())
+ .thenReturn(ImmutableList.of(cachedDevice1, cachedDevice3));
+ when(cachedDevice1.getGroupId()).thenReturn(1);
+ when(cachedDevice2.getGroupId()).thenReturn(1);
+ when(cachedDevice3.getGroupId()).thenReturn(2);
+ when(cachedDevice1.getProfiles())
+ .thenReturn(ImmutableList.of(mA2dpProfile, mHeadsetProfile, mLeAudioProfile));
+ when(cachedDevice2.getProfiles()).thenReturn(ImmutableList.of(mLeAudioProfile));
+ when(cachedDevice3.getProfiles())
+ .thenReturn(ImmutableList.of(mA2dpProfile, mHeadsetProfile, mLeAudioProfile));
+
+ Utils.setLeAudioEnabled(mLocalBtManager, cachedDevice2, false);
+
+ verify(mLeAudioProfile).setEnabled(device1, false);
+ verify(mLeAudioProfile).setEnabled(device2, false);
+ verify(mHearingAidProfile).setEnabled(device1, true);
+ verify(mAssistant).setEnabled(device1, false);
+ verify(mLeAudioProfile, never()).setEnabled(eq(device3), anyBoolean());
+ verify(mA2dpProfile, never()).setEnabled(eq(device3), anyBoolean());
+ verify(mHeadsetProfile, never()).setEnabled(eq(device3), anyBoolean());
+ }
+
+ @Test
+ public void disableLeAudioProfile_dualModeEnabled_a2dpAndHfpNotChanged() {
+ SystemProperties.set("persist.bluetooth.enable_dual_mode_audio", "true");
+ CachedBluetoothDevice cachedDevice1 = mock(CachedBluetoothDevice.class);
+ BluetoothDevice device1 = mock(BluetoothDevice.class);
+ when(cachedDevice1.getDevice()).thenReturn(device1);
+ when(cachedDevice1.getGroupId()).thenReturn(BluetoothCsipSetCoordinator.GROUP_ID_INVALID);
+ when(cachedDevice1.getProfiles())
+ .thenReturn(ImmutableList.of(mA2dpProfile, mHeadsetProfile, mLeAudioProfile));
+ when(mA2dpProfile.isEnabled(device1)).thenReturn(false);
+ when(mHeadsetProfile.isEnabled(device1)).thenReturn(false);
+
+ Utils.setLeAudioEnabled(mLocalBtManager, cachedDevice1, false);
+
+ verify(mLeAudioProfile).setEnabled(device1, false);
+ verify(mA2dpProfile, never()).setEnabled(device1, true);
+ verify(mHeadsetProfile, never()).setEnabled(device1, true);
+ }
+
+ @Test
+ public void disableLeAudioProfile_dualModeDisabled_enableA2dpAndHfp() {
+ SystemProperties.set("persist.bluetooth.enable_dual_mode_audio", "false");
+ CachedBluetoothDevice cachedDevice1 = mock(CachedBluetoothDevice.class);
+ BluetoothDevice device1 = mock(BluetoothDevice.class);
+ when(cachedDevice1.getDevice()).thenReturn(device1);
+ when(cachedDevice1.getGroupId()).thenReturn(BluetoothCsipSetCoordinator.GROUP_ID_INVALID);
+ when(cachedDevice1.getProfiles())
+ .thenReturn(ImmutableList.of(mA2dpProfile, mHeadsetProfile, mLeAudioProfile));
+ when(mA2dpProfile.isEnabled(device1)).thenReturn(false);
+ when(mHeadsetProfile.isEnabled(device1)).thenReturn(false);
+
+ Utils.setLeAudioEnabled(mLocalBtManager, cachedDevice1, false);
+
+ verify(mLeAudioProfile).setEnabled(device1, false);
+ verify(mA2dpProfile).setEnabled(device1, true);
+ verify(mHeadsetProfile).setEnabled(device1, true);
+ }
}
diff --git a/tests/robotests/src/com/android/settings/display/DeviceStateAutoRotateDetailsFragmentTest.java b/tests/robotests/src/com/android/settings/display/DeviceStateAutoRotateDetailsFragmentTest.java
index d1c32a2..6fce9a8 100644
--- a/tests/robotests/src/com/android/settings/display/DeviceStateAutoRotateDetailsFragmentTest.java
+++ b/tests/robotests/src/com/android/settings/display/DeviceStateAutoRotateDetailsFragmentTest.java
@@ -39,7 +39,6 @@
import com.android.settings.R;
import com.android.settingslib.core.AbstractPreferenceController;
-import com.android.settingslib.devicestate.DeviceStateRotationLockSettingsManager;
import org.junit.Before;
import org.junit.Test;
@@ -144,16 +143,15 @@
}
private void enableDeviceStateSettableRotationStates(String[] settableStates,
- String[] settableStatesDescriptions) {
+ String[] settableStatesDescriptions) {
when(mResources.getStringArray(
com.android.internal.R.array.config_perDeviceStateRotationLockDefaults)).thenReturn(
settableStates);
when(mResources.getStringArray(
R.array.config_settableAutoRotationDeviceStatesDescriptions)).thenReturn(
settableStatesDescriptions);
- DeviceStateRotationLockSettingsManager.resetInstance();
- DeviceStateRotationLockSettingsManager.getInstance(mContext)
- .resetStateForTesting(mResources);
+ DeviceStateAutoRotateSettingManagerProvider.resetInstance();
+ when(mContext.getResources()).thenReturn(mResources);
}
// Sets up posture mappings for PosturesHelper
diff --git a/tests/robotests/src/com/android/settings/display/DeviceStateAutoRotateOverviewControllerTest.java b/tests/robotests/src/com/android/settings/display/DeviceStateAutoRotateOverviewControllerTest.java
index a5416e7..4c2c694 100644
--- a/tests/robotests/src/com/android/settings/display/DeviceStateAutoRotateOverviewControllerTest.java
+++ b/tests/robotests/src/com/android/settings/display/DeviceStateAutoRotateOverviewControllerTest.java
@@ -18,30 +18,48 @@
import static com.android.settings.core.BasePreferenceController.AVAILABLE;
import static com.android.settings.core.BasePreferenceController.UNSUPPORTED_ON_DEVICE;
+import static com.android.settings.testutils.DeviceStateAutoRotateSettingTestUtils.setDeviceStateRotationLockEnabled;
import static com.google.common.truth.Truth.assertThat;
-import com.android.settings.testutils.shadow.ShadowDeviceStateRotationLockSettingsManager;
+import static org.mockito.Mockito.when;
+
+import android.content.Context;
+import android.content.res.Resources;
+
import com.android.settings.testutils.shadow.ShadowRotationPolicy;
+import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
+import org.mockito.Mock;
+import org.mockito.Mockito;
+import org.mockito.MockitoAnnotations;
import org.robolectric.RobolectricTestRunner;
import org.robolectric.RuntimeEnvironment;
import org.robolectric.annotation.Config;
@RunWith(RobolectricTestRunner.class)
-@Config(shadows = {ShadowRotationPolicy.class, ShadowDeviceStateRotationLockSettingsManager.class})
+@Config(shadows = {ShadowRotationPolicy.class})
public class DeviceStateAutoRotateOverviewControllerTest {
+ @Mock
+ private Resources mResources;
+ private DeviceStateAutoRotateOverviewController mController;
- private final DeviceStateAutoRotateOverviewController mController =
- new DeviceStateAutoRotateOverviewController(
- RuntimeEnvironment.application, "device_state_auto_rotate");
+ @Before
+ public void setUp() {
+ MockitoAnnotations.initMocks(this);
+ Context context = Mockito.spy(RuntimeEnvironment.application);
+ when(context.getResources()).thenReturn(mResources);
+
+ mController = new DeviceStateAutoRotateOverviewController(
+ context, "device_state_auto_rotate");
+ }
@Test
public void getAvailabilityStatus_rotationAndDeviceStateRotationEnabled_returnsAvailable() {
ShadowRotationPolicy.setRotationSupported(true);
- ShadowDeviceStateRotationLockSettingsManager.setDeviceStateRotationLockEnabled(true);
+ setDeviceStateRotationLockEnabled(true, mResources);
int availability = mController.getAvailabilityStatus();
@@ -51,7 +69,7 @@
@Test
public void getAvailabilityStatus_rotationNotSupported_returnsUnsupportedOnDevice() {
ShadowRotationPolicy.setRotationSupported(false);
- ShadowDeviceStateRotationLockSettingsManager.setDeviceStateRotationLockEnabled(true);
+ setDeviceStateRotationLockEnabled(true, mResources);
int availability = mController.getAvailabilityStatus();
@@ -61,7 +79,7 @@
@Test
public void getAvailabilityStatus_deviceStateRotationNotSupported_returnsUnsupportedOnDevice() {
ShadowRotationPolicy.setRotationSupported(true);
- ShadowDeviceStateRotationLockSettingsManager.setDeviceStateRotationLockEnabled(false);
+ setDeviceStateRotationLockEnabled(false, mResources);
int availability = mController.getAvailabilityStatus();
diff --git a/tests/robotests/src/com/android/settings/display/DeviceStateAutoRotateSettingControllerTest.java b/tests/robotests/src/com/android/settings/display/DeviceStateAutoRotateSettingControllerTest.java
index cb1be85..63a4af2 100644
--- a/tests/robotests/src/com/android/settings/display/DeviceStateAutoRotateSettingControllerTest.java
+++ b/tests/robotests/src/com/android/settings/display/DeviceStateAutoRotateSettingControllerTest.java
@@ -18,14 +18,17 @@
import static com.android.settings.core.BasePreferenceController.AVAILABLE;
import static com.android.settings.core.BasePreferenceController.UNSUPPORTED_ON_DEVICE;
+import static com.android.settings.testutils.DeviceStateAutoRotateSettingTestUtils.setDeviceStateRotationLockEnabled;
import static com.google.common.truth.Truth.assertThat;
import static org.mockito.Mockito.doReturn;
import static org.mockito.Mockito.verify;
+import static org.mockito.Mockito.when;
import android.app.settings.SettingsEnums;
import android.content.Context;
+import android.content.res.Resources;
import android.hardware.devicestate.DeviceState;
import android.hardware.devicestate.DeviceStateManager;
@@ -34,10 +37,9 @@
import androidx.preference.PreferenceScreen;
import com.android.settings.R;
-import com.android.settings.testutils.shadow.ShadowDeviceStateRotationLockSettingsManager;
import com.android.settings.testutils.shadow.ShadowRotationPolicy;
import com.android.settingslib.core.instrumentation.MetricsFeatureProvider;
-import com.android.settingslib.devicestate.DeviceStateRotationLockSettingsManager;
+import com.android.settingslib.devicestate.DeviceStateAutoRotateSettingManager;
import com.android.settingslib.search.SearchIndexableRaw;
import org.junit.Before;
@@ -54,10 +56,7 @@
import java.util.List;
@RunWith(RobolectricTestRunner.class)
-@Config(shadows = {
- ShadowRotationPolicy.class,
- ShadowDeviceStateRotationLockSettingsManager.class
-})
+@Config(shadows = {ShadowRotationPolicy.class})
public class DeviceStateAutoRotateSettingControllerTest {
private static final DeviceState DEFAULT_DEVICE_STATE = new DeviceState(
@@ -66,10 +65,11 @@
private static final int DEFAULT_ORDER = -10;
private final Context mContext = Mockito.spy(RuntimeEnvironment.application);
- private DeviceStateRotationLockSettingsManager mAutoRotateSettingsManager;
+ private DeviceStateAutoRotateSettingManager mAutoRotateSettingsManager;
@Mock private MetricsFeatureProvider mMetricsFeatureProvider;
@Mock private DeviceStateManager mDeviceStateManager;
+ @Mock private Resources mResources;
private DeviceStateAutoRotateSettingController mController;
@@ -78,11 +78,14 @@
MockitoAnnotations.initMocks(this);
doReturn(mContext).when(mContext).getApplicationContext();
+ when(mContext.getResources()).thenReturn(mResources);
doReturn(mDeviceStateManager).when(mContext).getSystemService(DeviceStateManager.class);
doReturn(List.of(DEFAULT_DEVICE_STATE)).when(
mDeviceStateManager).getSupportedDeviceStates();
+ setDeviceStateRotationLockEnabled(false, mResources);
mAutoRotateSettingsManager =
- DeviceStateRotationLockSettingsManager.getInstance(mContext);
+ DeviceStateAutoRotateSettingManagerProvider.getSingletonInstance(mContext);
+
mController = new DeviceStateAutoRotateSettingController(
mContext,
DEFAULT_DEVICE_STATE.getIdentifier(),
@@ -108,7 +111,7 @@
@Test
public void getAvailabilityStatus_rotationAndDeviceStateRotationEnabled_returnsAvailable() {
ShadowRotationPolicy.setRotationSupported(true);
- ShadowDeviceStateRotationLockSettingsManager.setDeviceStateRotationLockEnabled(true);
+ setDeviceStateRotationLockEnabled(true, mResources);
int availability = mController.getAvailabilityStatus();
@@ -118,7 +121,7 @@
@Test
public void getAvailabilityStatus_deviceStateRotationDisabled_returnsUnsupported() {
ShadowRotationPolicy.setRotationSupported(true);
- ShadowDeviceStateRotationLockSettingsManager.setDeviceStateRotationLockEnabled(false);
+ setDeviceStateRotationLockEnabled(false, mResources);
int availability = mController.getAvailabilityStatus();
@@ -128,7 +131,7 @@
@Test
public void getAvailabilityStatus_rotationDisabled_returnsUnsupported() {
ShadowRotationPolicy.setRotationSupported(false);
- ShadowDeviceStateRotationLockSettingsManager.setDeviceStateRotationLockEnabled(true);
+ setDeviceStateRotationLockEnabled(true, mResources);
int availability = mController.getAvailabilityStatus();
diff --git a/tests/robotests/src/com/android/settings/display/DeviceStateAutoRotateSettingManagerProviderTest.kt b/tests/robotests/src/com/android/settings/display/DeviceStateAutoRotateSettingManagerProviderTest.kt
new file mode 100644
index 0000000..f2e59c5
--- /dev/null
+++ b/tests/robotests/src/com/android/settings/display/DeviceStateAutoRotateSettingManagerProviderTest.kt
@@ -0,0 +1,111 @@
+/*
+ * 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.display;
+
+import android.content.Context
+import android.content.res.Resources
+import android.hardware.devicestate.DeviceStateManager
+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 androidx.test.ext.junit.runners.AndroidJUnit4
+import androidx.test.filters.SmallTest
+import com.android.internal.R
+import com.android.settingslib.devicestate.DeviceStateAutoRotateSettingManagerImpl
+import com.android.settingslib.devicestate.DeviceStateRotationLockSettingsManager
+import com.android.window.flags.Flags
+import com.google.common.truth.Truth.assertThat
+import org.junit.After
+import org.junit.Before
+import org.junit.Assert.assertNotSame
+import org.junit.Assert.assertSame
+import org.junit.Rule
+import org.junit.Test
+import org.junit.runner.RunWith
+import org.mockito.Mock
+import org.mockito.junit.MockitoJUnit
+import org.mockito.Mockito.`when` as whenever
+
+@SmallTest
+@RunWith(AndroidJUnit4::class)
+class DeviceStateAutoRotateSettingManagerProviderTest {
+
+ @get:Rule
+ val setFlagsRule: SetFlagsRule = SetFlagsRule()
+ @get:Rule
+ val rule = MockitoJUnit.rule()
+
+ @Mock
+ private lateinit var mockContext: Context
+ @Mock
+ private lateinit var mockDeviceStateManager: DeviceStateManager
+ @Mock
+ private lateinit var mockResources: Resources
+
+ private val context: Context = ApplicationProvider.getApplicationContext()
+
+ @Before
+ fun setup() {
+ whenever(mockContext.contentResolver).thenReturn(context.contentResolver)
+ whenever(mockContext.getSystemService(DeviceStateManager::class.java)).thenReturn(
+ mockDeviceStateManager
+ )
+ whenever(mockContext.resources).thenReturn(mockResources)
+ whenever(mockResources.getStringArray(R.array.config_perDeviceStateRotationLockDefaults))
+ .thenReturn(arrayOf())
+ }
+
+ @After
+ fun tearDown() {
+ DeviceStateAutoRotateSettingManagerProvider.resetInstance()
+ }
+
+ @Test
+ @EnableFlags(Flags.FLAG_ENABLE_DEVICE_STATE_AUTO_ROTATE_SETTING_REFACTOR)
+ fun getSingletonInstance_refactorFlagEnabled_returnsRefactoredManager() {
+ val manager = DeviceStateAutoRotateSettingManagerProvider.getSingletonInstance(mockContext)
+
+ assertThat(manager).isInstanceOf(DeviceStateAutoRotateSettingManagerImpl::class.java)
+ }
+
+ @Test
+ @DisableFlags(Flags.FLAG_ENABLE_DEVICE_STATE_AUTO_ROTATE_SETTING_REFACTOR)
+ fun getSingletonInstance_refactorFlagDisabled_returnsLegacyManager() {
+ val manager = DeviceStateAutoRotateSettingManagerProvider.getSingletonInstance(mockContext)
+
+ assertThat(manager).isInstanceOf(DeviceStateRotationLockSettingsManager::class.java)
+ }
+
+ @Test
+ @EnableFlags(Flags.FLAG_ENABLE_DEVICE_STATE_AUTO_ROTATE_SETTING_REFACTOR)
+ fun getSingletonInstance_resetInstance_returnsNewInstance() {
+ val manager1 = DeviceStateAutoRotateSettingManagerProvider.getSingletonInstance(mockContext)
+ DeviceStateAutoRotateSettingManagerProvider.resetInstance()
+ val manager2 = DeviceStateAutoRotateSettingManagerProvider.getSingletonInstance(mockContext)
+
+ assertNotSame(manager1, manager2)
+ }
+
+ @Test
+ @EnableFlags(Flags.FLAG_ENABLE_DEVICE_STATE_AUTO_ROTATE_SETTING_REFACTOR)
+ fun getSingletonInstance_getInstanceTwice_returnsSameInstance() {
+ val manager1 = DeviceStateAutoRotateSettingManagerProvider.getSingletonInstance(mockContext)
+ val manager2 = DeviceStateAutoRotateSettingManagerProvider.getSingletonInstance(mockContext)
+
+ assertSame(manager1, manager2)
+ }
+}
diff --git a/tests/robotests/src/com/android/settings/display/SmartAutoRotateControllerTest.java b/tests/robotests/src/com/android/settings/display/SmartAutoRotateControllerTest.java
index e2542b0..a1eb89c 100644
--- a/tests/robotests/src/com/android/settings/display/SmartAutoRotateControllerTest.java
+++ b/tests/robotests/src/com/android/settings/display/SmartAutoRotateControllerTest.java
@@ -19,6 +19,7 @@
import static com.android.settings.core.BasePreferenceController.AVAILABLE;
import static com.android.settings.core.BasePreferenceController.DISABLED_DEPENDENT_SETTING;
import static com.android.settings.core.BasePreferenceController.UNSUPPORTED_ON_DEVICE;
+import static com.android.settings.testutils.DeviceStateAutoRotateSettingTestUtils.setDeviceStateRotationLockEnabled;
import static com.google.common.truth.Truth.assertThat;
@@ -33,6 +34,7 @@
import android.content.pm.PackageManager;
import android.content.pm.ResolveInfo;
import android.content.pm.ServiceInfo;
+import android.content.res.Resources;
import android.hardware.devicestate.DeviceState;
import android.hardware.devicestate.DeviceStateManager;
import android.os.UserHandle;
@@ -41,11 +43,11 @@
import androidx.preference.Preference;
import com.android.settings.testutils.ResolveInfoBuilder;
-import com.android.settings.testutils.shadow.ShadowDeviceStateRotationLockSettingsManager;
+import com.android.settings.testutils.shadow.ShadowDeviceStateAutoRotateSettingManager;
import com.android.settings.testutils.shadow.ShadowRotationPolicy;
import com.android.settings.testutils.shadow.ShadowSensorPrivacyManager;
import com.android.settings.testutils.shadow.ShadowSystemSettings;
-import com.android.settingslib.devicestate.DeviceStateRotationLockSettingsManager;
+import com.android.settingslib.devicestate.DeviceStateAutoRotateSettingManager;
import org.junit.Before;
import org.junit.Test;
@@ -73,17 +75,21 @@
private Preference mPreference;
@Mock
private DeviceStateManager mDeviceStateManager;
+ @Mock
+ private Resources mResources;
private ContentResolver mContentResolver;
- private DeviceStateRotationLockSettingsManager mDeviceStateAutoRotateSettingsManager;
+ private DeviceStateAutoRotateSettingManager mDeviceStateAutoRotateSettingManager;
@Before
public void setUp() {
MockitoAnnotations.initMocks(this);
final Context context = Mockito.spy(RuntimeEnvironment.application);
mContentResolver = RuntimeEnvironment.application.getContentResolver();
+ mResources = Mockito.spy(RuntimeEnvironment.application.getResources());
when(context.getPackageManager()).thenReturn(mPackageManager);
when(context.getContentResolver()).thenReturn(mContentResolver);
+ when(context.getResources()).thenReturn(mResources);
doReturn(PACKAGE_NAME).when(mPackageManager).getRotationResolverPackageName();
doReturn(PackageManager.PERMISSION_GRANTED).when(mPackageManager).checkPermission(
Manifest.permission.CAMERA, PACKAGE_NAME);
@@ -91,8 +97,9 @@
doReturn(context).when(context).getApplicationContext();
doReturn(mDeviceStateManager).when(context).getSystemService(DeviceStateManager.class);
doReturn(getDeviceStateList()).when(mDeviceStateManager).getSupportedDeviceStates();
- mDeviceStateAutoRotateSettingsManager = DeviceStateRotationLockSettingsManager.getInstance(
- context);
+ setDeviceStateRotationLockEnabled(false, mResources);
+ mDeviceStateAutoRotateSettingManager =
+ DeviceStateAutoRotateSettingManagerProvider.getSingletonInstance(context);
mController = Mockito.spy(new SmartAutoRotateController(context, "test_key"));
when(mController.isCameraLocked()).thenReturn(false);
@@ -144,7 +151,7 @@
@Test
@Config(shadows = {
- ShadowDeviceStateRotationLockSettingsManager.class,
+ ShadowDeviceStateAutoRotateSettingManager.class,
ShadowRotationPolicy.class
})
public void getAvailabilityStatus_deviceStateRotationLocked_returnDisableDependentSetting() {
@@ -158,7 +165,7 @@
@Test
@Config(shadows = {
- ShadowDeviceStateRotationLockSettingsManager.class,
+ ShadowDeviceStateAutoRotateSettingManager.class,
ShadowRotationPolicy.class
})
public void getAvailabilityStatus_deviceStateRotationUnlocked_returnAvailable() {
@@ -182,18 +189,18 @@
private void enableDeviceStateRotation() {
ShadowRotationPolicy.setRotationSupported(true);
- ShadowDeviceStateRotationLockSettingsManager.setDeviceStateRotationLockEnabled(true);
+ setDeviceStateRotationLockEnabled(true, mResources);
}
private void lockDeviceStateRotation() {
- ShadowDeviceStateRotationLockSettingsManager shadowManager =
- Shadow.extract(mDeviceStateAutoRotateSettingsManager);
+ ShadowDeviceStateAutoRotateSettingManager shadowManager =
+ Shadow.extract(mDeviceStateAutoRotateSettingManager);
shadowManager.setRotationLockedForAllStates(true);
}
private void unlockDeviceStateRotation() {
- ShadowDeviceStateRotationLockSettingsManager shadowManager =
- Shadow.extract(mDeviceStateAutoRotateSettingsManager);
+ ShadowDeviceStateAutoRotateSettingManager shadowManager =
+ Shadow.extract(mDeviceStateAutoRotateSettingManager);
shadowManager.setRotationLockedForAllStates(false);
}
diff --git a/tests/robotests/src/com/android/settings/display/SmartAutoRotatePreferenceControllerTest.java b/tests/robotests/src/com/android/settings/display/SmartAutoRotatePreferenceControllerTest.java
index 9f1b5d4..1fb4703 100644
--- a/tests/robotests/src/com/android/settings/display/SmartAutoRotatePreferenceControllerTest.java
+++ b/tests/robotests/src/com/android/settings/display/SmartAutoRotatePreferenceControllerTest.java
@@ -18,6 +18,8 @@
import static android.provider.Settings.Secure.CAMERA_AUTOROTATE;
+import static com.android.settings.testutils.DeviceStateAutoRotateSettingTestUtils.setDeviceStateRotationLockEnabled;
+
import static com.google.common.truth.Truth.assertThat;
import static org.mockito.ArgumentMatchers.any;
@@ -40,7 +42,6 @@
import com.android.settings.core.BasePreferenceController;
import com.android.settings.testutils.FakeFeatureFactory;
import com.android.settings.testutils.ResolveInfoBuilder;
-import com.android.settings.testutils.shadow.ShadowDeviceStateRotationLockSettingsManager;
import com.android.settings.testutils.shadow.ShadowSensorPrivacyManager;
import com.android.settings.testutils.shadow.ShadowSystemSettings;
@@ -57,8 +58,7 @@
@RunWith(RobolectricTestRunner.class)
@Config(shadows = {
ShadowSystemSettings.class,
- ShadowSensorPrivacyManager.class,
- ShadowDeviceStateRotationLockSettingsManager.class
+ ShadowSensorPrivacyManager.class
})
public class SmartAutoRotatePreferenceControllerTest {
@@ -104,7 +104,7 @@
new SmartAutoRotatePreferenceController(mContext, "smart_auto_rotate"));
when(mController.isCameraLocked()).thenReturn(false);
when(mController.isPowerSaveMode()).thenReturn(false);
- ShadowDeviceStateRotationLockSettingsManager.setDeviceStateRotationLockEnabled(false);
+ setDeviceStateRotationLockEnabled(false, mResources);
}
@Test
@@ -213,7 +213,7 @@
@Test
public void getAvailabilityStatus_deviceStateRotationEnabled_returnsUnsupported() {
enableAutoRotationPreference();
- ShadowDeviceStateRotationLockSettingsManager.setDeviceStateRotationLockEnabled(true);
+ setDeviceStateRotationLockEnabled(true, mResources);
assertThat(mController.getAvailabilityStatus()).isEqualTo(
BasePreferenceController.UNSUPPORTED_ON_DEVICE);
diff --git a/tests/robotests/src/com/android/settings/display/SmartAutoRotatePreferenceFragmentTest.java b/tests/robotests/src/com/android/settings/display/SmartAutoRotatePreferenceFragmentTest.java
index 1615538..731cffb 100644
--- a/tests/robotests/src/com/android/settings/display/SmartAutoRotatePreferenceFragmentTest.java
+++ b/tests/robotests/src/com/android/settings/display/SmartAutoRotatePreferenceFragmentTest.java
@@ -27,6 +27,7 @@
import static com.android.settings.display.SmartAutoRotatePreferenceFragment.AUTO_ROTATE_MAIN_SWITCH_PREFERENCE_KEY;
import static com.android.settings.display.SmartAutoRotatePreferenceFragment.AUTO_ROTATE_SWITCH_PREFERENCE_KEY;
+import static com.android.settings.testutils.DeviceStateAutoRotateSettingTestUtils.setDeviceStateRotationLockEnabled;
import static com.google.common.truth.Truth.assertThat;
@@ -55,10 +56,8 @@
import com.android.settings.R;
import com.android.settings.SettingsActivity;
import com.android.settings.testutils.ResolveInfoBuilder;
-import com.android.settings.testutils.shadow.ShadowDeviceStateRotationLockSettingsManager;
import com.android.settings.testutils.shadow.ShadowRotationPolicy;
import com.android.settingslib.core.AbstractPreferenceController;
-import com.android.settingslib.devicestate.DeviceStateRotationLockSettingsManager;
import org.junit.Before;
import org.junit.Test;
@@ -75,7 +74,6 @@
@RunWith(RobolectricTestRunner.class)
@Config(shadows = {
com.android.settings.testutils.shadow.ShadowFragment.class,
- ShadowDeviceStateRotationLockSettingsManager.class,
ShadowRotationPolicy.class
})
public class SmartAutoRotatePreferenceFragmentTest {
@@ -174,7 +172,7 @@
@Test
public void createHeader_faceDetectionSupported_switchBarIsEnabled() {
- ShadowDeviceStateRotationLockSettingsManager.setDeviceStateRotationLockEnabled(false);
+ setDeviceStateRotationLockEnabled(false, mResources);
mFragment.createHeader(mActivity);
verify(mRotateMainSwitchPreference, never()).setVisible(false);
@@ -184,7 +182,7 @@
@Test
public void createHeader_deviceStateRotationSupported_switchBarIsDisabled() {
ShadowRotationPolicy.setRotationSupported(true);
- ShadowDeviceStateRotationLockSettingsManager.setDeviceStateRotationLockEnabled(true);
+ setDeviceStateRotationLockEnabled(true, mResources);
mFragment.createHeader(mActivity);
@@ -258,15 +256,14 @@
private void enableDeviceStateSettableRotationStates(
String[] settableStates, String[] settableStatesDescriptions) {
when(mResources.getStringArray(
- com.android.internal.R.array.config_perDeviceStateRotationLockDefaults))
+ com.android.internal.R.array.config_perDeviceStateRotationLockDefaults))
.thenReturn(settableStates);
when(mResources.getStringArray(R.array.config_settableAutoRotationDeviceStatesDescriptions))
.thenReturn(settableStatesDescriptions);
when(mResources.getBoolean(R.bool.config_auto_rotate_face_detection_available))
.thenReturn(true);
- DeviceStateRotationLockSettingsManager.resetInstance();
- DeviceStateRotationLockSettingsManager.getInstance(mContext)
- .resetStateForTesting(mResources);
+ DeviceStateAutoRotateSettingManagerProvider.resetInstance();
+ when(mContext.getResources()).thenReturn(mResources);
}
// Sets up posture mappings for PosturesHelper
diff --git a/tests/robotests/src/com/android/settings/localepicker/LocaleListEditorTest.java b/tests/robotests/src/com/android/settings/localepicker/LocaleListEditorTest.java
index 22d39e3..5f5b8f6 100644
--- a/tests/robotests/src/com/android/settings/localepicker/LocaleListEditorTest.java
+++ b/tests/robotests/src/com/android/settings/localepicker/LocaleListEditorTest.java
@@ -275,6 +275,7 @@
public void showConfirmDialog_systemLocaleSelected_shouldShowLocaleChangeDialog()
throws Exception {
//pre-condition
+ Locale.setDefault(Locale.forLanguageTag("zh-TW"));
setUpLocaleConditions(true);
final Configuration config = new Configuration();
config.setLocales((LocaleList.forLanguageTags("zh-TW,en-US")));
@@ -379,6 +380,7 @@
@Test
public void onTouch_dragDifferentLocaleToTop_showConfirmDialog() throws Exception {
MotionEvent event = MotionEvent.obtain(0L, 0L, MotionEvent.ACTION_UP, 0.0f, 0.0f, 0);
+ Locale.setDefault(Locale.forLanguageTag("zh-TW"));
setUpLocaleConditions(true);
final Configuration config = new Configuration();
config.setLocales((LocaleList.forLanguageTags("zh-TW,en-US")));
diff --git a/tests/robotests/src/com/android/settings/testutils/DeviceStateAutoRotateSettingTestUtils.java b/tests/robotests/src/com/android/settings/testutils/DeviceStateAutoRotateSettingTestUtils.java
new file mode 100644
index 0000000..3359b2f
--- /dev/null
+++ b/tests/robotests/src/com/android/settings/testutils/DeviceStateAutoRotateSettingTestUtils.java
@@ -0,0 +1,41 @@
+/*
+ * 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.testutils;
+
+import static org.mockito.Mockito.when;
+
+import android.content.res.Resources;
+
+/**
+ * Helper for testing device state auto rotate setting
+ */
+public class DeviceStateAutoRotateSettingTestUtils {
+
+ /**
+ * Mock {@link mockResources} to return device state auto rotate enabled or disabled based on
+ * value passed for {@link enable}.
+ */
+ public static void setDeviceStateRotationLockEnabled(boolean enable, Resources mockResources) {
+ String[] perDeviceStateRotationLockDefaults = new String[0];
+ if (enable) {
+ perDeviceStateRotationLockDefaults = new String[]{"test_value"};
+ }
+ when(mockResources.getStringArray(
+ com.android.internal.R.array.config_perDeviceStateRotationLockDefaults))
+ .thenReturn(perDeviceStateRotationLockDefaults);
+ }
+}
diff --git a/tests/robotests/src/com/android/settings/testutils/shadow/ShadowDeviceStateRotationLockSettingsManager.java b/tests/robotests/src/com/android/settings/testutils/shadow/ShadowDeviceStateAutoRotateSettingManager.java
similarity index 73%
rename from tests/robotests/src/com/android/settings/testutils/shadow/ShadowDeviceStateRotationLockSettingsManager.java
rename to tests/robotests/src/com/android/settings/testutils/shadow/ShadowDeviceStateAutoRotateSettingManager.java
index ed266e3..b44d79e 100644
--- a/tests/robotests/src/com/android/settings/testutils/shadow/ShadowDeviceStateRotationLockSettingsManager.java
+++ b/tests/robotests/src/com/android/settings/testutils/shadow/ShadowDeviceStateAutoRotateSettingManager.java
@@ -16,29 +16,17 @@
package com.android.settings.testutils.shadow;
-import android.content.Context;
-
import com.android.settingslib.devicestate.DeviceStateRotationLockSettingsManager;
import org.robolectric.annotation.Implementation;
import org.robolectric.annotation.Implements;
@Implements(DeviceStateRotationLockSettingsManager.class)
-public class ShadowDeviceStateRotationLockSettingsManager {
+public class ShadowDeviceStateAutoRotateSettingManager {
- private static boolean sDeviceStateRotationLockEnabled;
private boolean mIsRotationLockedForAllStates;
@Implementation
- public static boolean isDeviceStateRotationLockEnabled(Context context) {
- return sDeviceStateRotationLockEnabled;
- }
-
- public static void setDeviceStateRotationLockEnabled(boolean enabled) {
- sDeviceStateRotationLockEnabled = enabled;
- }
-
- @Implementation
public boolean isRotationLockedForAllStates() {
return mIsRotationLockedForAllStates;
}
diff --git a/tests/robotests/testutils/com/android/settings/testutils/shadow/ShadowBluetoothUtils.java b/tests/robotests/testutils/com/android/settings/testutils/shadow/ShadowBluetoothUtils.java
index 4dca749..72de746 100644
--- a/tests/robotests/testutils/com/android/settings/testutils/shadow/ShadowBluetoothUtils.java
+++ b/tests/robotests/testutils/com/android/settings/testutils/shadow/ShadowBluetoothUtils.java
@@ -18,24 +18,48 @@
import android.content.Context;
+import androidx.annotation.NonNull;
+
import com.android.settings.bluetooth.Utils;
+import com.android.settingslib.bluetooth.CachedBluetoothDevice;
import com.android.settingslib.bluetooth.LocalBluetoothManager;
import org.robolectric.annotation.Implementation;
import org.robolectric.annotation.Implements;
import org.robolectric.annotation.Resetter;
+import java.util.HashMap;
+import java.util.Map;
+
/** Robolectric shadow for the bluetooth utils. */
@Implements(Utils.class)
public class ShadowBluetoothUtils {
public static LocalBluetoothManager sLocalBluetoothManager;
+ private static final Map<CachedBluetoothDevice, Boolean> sLeAudioState = new HashMap<>();
@Implementation
protected static LocalBluetoothManager getLocalBtManager(Context context) {
return sLocalBluetoothManager;
}
+ /** Sets le audio state for the device. */
+ @Implementation
+ public static void setLeAudioEnabled(
+ @NonNull LocalBluetoothManager manager,
+ @NonNull CachedBluetoothDevice cachedDevice,
+ boolean enable) {
+ sLeAudioState.put(cachedDevice, enable);
+ }
+
+ /** Checks whether le audio is enabled for the device. */
+ public static boolean isLeAudioEnabled(@NonNull CachedBluetoothDevice cachedDevice) {
+ if (sLeAudioState.containsKey(cachedDevice)) {
+ return sLeAudioState.get(cachedDevice);
+ }
+ return false;
+ }
+
/** Resets the local bluetooth manager to null. */
@Resetter
public static void reset() {
diff --git a/tests/unit/src/com/android/settings/safetycenter/FaceSafetySourceTest.java b/tests/unit/src/com/android/settings/safetycenter/FaceSafetySourceTest.java
index 5d94532..1d6f48f 100644
--- a/tests/unit/src/com/android/settings/safetycenter/FaceSafetySourceTest.java
+++ b/tests/unit/src/com/android/settings/safetycenter/FaceSafetySourceTest.java
@@ -37,7 +37,6 @@
import android.content.Intent;
import android.content.pm.PackageManager;
import android.hardware.face.FaceManager;
-import android.hardware.fingerprint.FingerprintManager;
import android.os.UserHandle;
import android.platform.test.annotations.DisableFlags;
import android.platform.test.annotations.EnableFlags;
@@ -53,7 +52,6 @@
import com.android.internal.widget.LockPatternUtils;
import com.android.settings.Settings;
-import com.android.settings.biometrics.BiometricEnrollActivity;
import com.android.settings.biometrics.face.FaceEnrollIntroductionInternal;
import com.android.settings.flags.Flags;
import com.android.settings.testutils.FakeFeatureFactory;
@@ -85,7 +83,6 @@
@Mock private PackageManager mPackageManager;
@Mock private DevicePolicyManager mDevicePolicyManager;
@Mock private FaceManager mFaceManager;
- @Mock private FingerprintManager mFingerprintManager;
@Mock private LockPatternUtils mLockPatternUtils;
@Mock private SafetyCenterManagerWrapper mSafetyCenterManagerWrapper;
@Mock private SupervisionManager mSupervisionManager;
@@ -100,8 +97,6 @@
when(mApplicationContext.getSystemService(Context.DEVICE_POLICY_SERVICE))
.thenReturn(mDevicePolicyManager);
when(mApplicationContext.getSystemService(Context.FACE_SERVICE)).thenReturn(mFaceManager);
- when(mApplicationContext.getSystemService(Context.FINGERPRINT_SERVICE))
- .thenReturn(mFingerprintManager);
when(mApplicationContext.getSystemService(Context.SUPERVISION_SERVICE))
.thenReturn(mSupervisionManager);
FakeFeatureFactory featureFactory = FakeFeatureFactory.setupForTest();
@@ -216,12 +211,10 @@
@Test
@RequiresFlagsEnabled(Flags.FLAG_BIOMETRICS_ONBOARDING_EDUCATION)
- public void setSafetySourceData_onlyFaceNotEnrolled_whenNotDisabledByAdmin_setsData() {
+ public void setSafetySourceData_withFaceNotEnrolled_whenNotDisabledByAdmin_setsData() {
when(mSafetyCenterManagerWrapper.isEnabled(mApplicationContext)).thenReturn(true);
when(mFaceManager.isHardwareDetected()).thenReturn(true);
when(mFaceManager.hasEnrolledTemplates(anyInt())).thenReturn(false);
- when(mFingerprintManager.isHardwareDetected()).thenReturn(true);
- when(mFingerprintManager.hasEnrolledFingerprints(anyInt())).thenReturn(true);
when(mDevicePolicyManager.getKeyguardDisabledFeatures(COMPONENT_NAME)).thenReturn(0);
FaceSafetySource.setSafetySourceData(mApplicationContext, EVENT_SOURCE_STATE_CHANGED);
@@ -234,24 +227,6 @@
@Test
@RequiresFlagsEnabled(Flags.FLAG_BIOMETRICS_ONBOARDING_EDUCATION)
- public void setSafetySourceData_noBiometricEnrolled_whenNotDisabledByAdmin_setsData() {
- when(mSafetyCenterManagerWrapper.isEnabled(mApplicationContext)).thenReturn(true);
- when(mFaceManager.isHardwareDetected()).thenReturn(true);
- when(mFaceManager.hasEnrolledTemplates(anyInt())).thenReturn(false);
- when(mFingerprintManager.isHardwareDetected()).thenReturn(true);
- when(mFingerprintManager.hasEnrolledFingerprints(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_new",
- BiometricEnrollActivity.class.getName());
- }
-
- @Test
- @RequiresFlagsEnabled(Flags.FLAG_BIOMETRICS_ONBOARDING_EDUCATION)
@DisableFlags(android.app.supervision.flags.Flags.FLAG_DEPRECATE_DPM_SUPERVISION_APIS)
public void setSafetySourceData_withFaceEnrolled_whenDisabledByAdmin_setsData() {
when(mDevicePolicyManager.getProfileOwnerOrDeviceOwnerSupervisionComponent(USER_HANDLE))
diff --git a/tests/unit/src/com/android/settings/safetycenter/FingerprintSafetySourceTest.java b/tests/unit/src/com/android/settings/safetycenter/FingerprintSafetySourceTest.java
index 18eae9a..dac2699 100644
--- a/tests/unit/src/com/android/settings/safetycenter/FingerprintSafetySourceTest.java
+++ b/tests/unit/src/com/android/settings/safetycenter/FingerprintSafetySourceTest.java
@@ -36,7 +36,6 @@
import android.content.Context;
import android.content.Intent;
import android.content.pm.PackageManager;
-import android.hardware.face.FaceManager;
import android.hardware.fingerprint.Fingerprint;
import android.hardware.fingerprint.FingerprintManager;
import android.os.UserHandle;
@@ -53,7 +52,6 @@
import androidx.test.ext.junit.runners.AndroidJUnit4;
import com.android.internal.widget.LockPatternUtils;
-import com.android.settings.biometrics.BiometricEnrollActivity;
import com.android.settings.biometrics.fingerprint.FingerprintSettings;
import com.android.settings.flags.Flags;
import com.android.settings.testutils.FakeFeatureFactory;
@@ -89,7 +87,6 @@
@Mock private PackageManager mPackageManager;
@Mock private DevicePolicyManager mDevicePolicyManager;
@Mock private FingerprintManager mFingerprintManager;
- @Mock private FaceManager mFaceManager;
@Mock private LockPatternUtils mLockPatternUtils;
@Mock private SafetyCenterManagerWrapper mSafetyCenterManagerWrapper;
@Mock private SupervisionManager mSupervisionManager;
@@ -103,7 +100,6 @@
when(mPackageManager.hasSystemFeature(PackageManager.FEATURE_FACE)).thenReturn(true);
when(mApplicationContext.getSystemService(Context.FINGERPRINT_SERVICE))
.thenReturn(mFingerprintManager);
- when(mApplicationContext.getSystemService(Context.FACE_SERVICE)).thenReturn(mFaceManager);
when(mApplicationContext.getSystemService(Context.DEVICE_POLICY_SERVICE))
.thenReturn(mDevicePolicyManager);
when(mApplicationContext.getSystemService(Context.SUPERVISION_SERVICE))
@@ -232,12 +228,10 @@
@Test
@RequiresFlagsEnabled(Flags.FLAG_BIOMETRICS_ONBOARDING_EDUCATION)
- public void setSafetySourceData_onlyFingerprintNotEnrolled_whenNotDisabledByAdmin_setsData() {
+ public void setSafetySourceData_withFingerprintNotEnrolled_whenNotDisabledByAdmin_setsData() {
when(mSafetyCenterManagerWrapper.isEnabled(mApplicationContext)).thenReturn(true);
when(mFingerprintManager.isHardwareDetected()).thenReturn(true);
when(mFingerprintManager.hasEnrolledFingerprints(anyInt())).thenReturn(false);
- when(mFaceManager.isHardwareDetected()).thenReturn(true);
- when(mFaceManager.hasEnrolledTemplates(anyInt())).thenReturn(true);
when(mDevicePolicyManager.getKeyguardDisabledFeatures(COMPONENT_NAME)).thenReturn(0);
FingerprintSafetySource.setSafetySourceData(
@@ -251,25 +245,6 @@
@Test
@RequiresFlagsEnabled(Flags.FLAG_BIOMETRICS_ONBOARDING_EDUCATION)
- public void setSafetySourceData_noBiometricEnrolled_whenNotDisabledByAdmin_setsData() {
- when(mSafetyCenterManagerWrapper.isEnabled(mApplicationContext)).thenReturn(true);
- when(mFingerprintManager.isHardwareDetected()).thenReturn(true);
- when(mFingerprintManager.hasEnrolledFingerprints(anyInt())).thenReturn(false);
- when(mFaceManager.isHardwareDetected()).thenReturn(true);
- when(mFaceManager.hasEnrolledTemplates(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_new",
- BiometricEnrollActivity.class.getName());
- }
-
- @Test
- @RequiresFlagsEnabled(Flags.FLAG_BIOMETRICS_ONBOARDING_EDUCATION)
@DisableFlags(android.app.supervision.flags.Flags.FLAG_DEPRECATE_DPM_SUPERVISION_APIS)
public void setSafetySourceData_withFingerprintsEnrolled_whenDisabledByAdmin_setsData() {
int enrolledFingerprintsCount = 2;