Snap for 11571437 from 958d17bb69 to 24Q3-release

Change-Id: Ie74810f4de61388c840bc23d7ba9b4764fc3329d
This commit is contained in:
Android Build Coastguard Worker
2024-03-13 23:20:56 +00:00
25 changed files with 352 additions and 97 deletions

View File

@@ -17,6 +17,7 @@
<LinearLayout <LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android" xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:androidprv="http://schemas.android.com/apk/prv/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto" xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
@@ -77,7 +78,7 @@
android:layout_gravity="start" android:layout_gravity="start"
android:textAlignment="viewStart" android:textAlignment="viewStart"
android:textAppearance="?android:attr/textAppearanceSmall" android:textAppearance="?android:attr/textAppearanceSmall"
android:textColor="?android:attr/textColorSecondary" android:textColor="?androidprv:attr/materialColorOnSurfaceVariant"
android:maxLines="4" android:maxLines="4"
android:hyphenationFrequency="normalFast" android:hyphenationFrequency="normalFast"
android:lineBreakWordStyle="phrase" android:lineBreakWordStyle="phrase"

View File

@@ -19,7 +19,7 @@
<color name="homepage_accessibility_background">#783BE5</color> <color name="homepage_accessibility_background">#783BE5</color>
<color name="homepage_support_background">#3F5FBD</color> <color name="homepage_support_background">#3F5FBD</color>
<color name="contextual_card_background">@*android:color/material_grey_900</color> <color name="contextual_card_background">@*android:color/material_grey_900</color>
<color name="search_bar_background">?androidprv:attr/materialColorSurfaceContainerHigh</color> <color name="search_bar_background">?androidprv:attr/materialColorSurfaceBright</color>
<color name="notification_importance_button_unselected">#5F6368</color> <color name="notification_importance_button_unselected">#5F6368</color>
<!-- Palette list preference colors. --> <!-- Palette list preference colors. -->

View File

@@ -249,7 +249,7 @@
<item name="android:layout_gravity">center</item> <item name="android:layout_gravity">center</item>
<item name="android:fontFamily">@*android:string/config_headlineFontFamily</item> <item name="android:fontFamily">@*android:string/config_headlineFontFamily</item>
<item name="android:textSize">@dimen/search_bar_text_size</item> <item name="android:textSize">@dimen/search_bar_text_size</item>
<item name="android:textColor">?android:attr/textColorSecondary</item> <item name="android:textColor">?androidprv:attr/materialColorOnSurfaceVariant</item>
<item name="android:singleLine">true</item> <item name="android:singleLine">true</item>
</style> </style>

View File

@@ -1289,7 +1289,8 @@ public final class Utils extends com.android.settingslib.Utils {
*/ */
@ColorInt @ColorInt
public static int getHomepageIconColor(Context context) { public static int getHomepageIconColor(Context context) {
return getColorAttrDefaultColor(context, android.R.attr.textColorPrimary); return getColorAttrDefaultColor(
context, com.android.internal.R.attr.materialColorOnSurface);
} }
/** /**

View File

@@ -175,6 +175,9 @@ public class AccessibilitySettings extends DashboardFragment implements
// Observe changes from accessibility selection menu // Observe changes from accessibility selection menu
shortcutFeatureKeys.add(Settings.Secure.ACCESSIBILITY_BUTTON_TARGETS); shortcutFeatureKeys.add(Settings.Secure.ACCESSIBILITY_BUTTON_TARGETS);
shortcutFeatureKeys.add(Settings.Secure.ACCESSIBILITY_SHORTCUT_TARGET_SERVICE); shortcutFeatureKeys.add(Settings.Secure.ACCESSIBILITY_SHORTCUT_TARGET_SERVICE);
if (android.view.accessibility.Flags.a11yQsShortcut()) {
shortcutFeatureKeys.add(Settings.Secure.ACCESSIBILITY_QS_TARGETS);
}
shortcutFeatureKeys.add(Settings.Secure.ACCESSIBILITY_STICKY_KEYS); shortcutFeatureKeys.add(Settings.Secure.ACCESSIBILITY_STICKY_KEYS);
shortcutFeatureKeys.add(Settings.Secure.ACCESSIBILITY_SLOW_KEYS); shortcutFeatureKeys.add(Settings.Secure.ACCESSIBILITY_SLOW_KEYS);
shortcutFeatureKeys.add(Settings.Secure.ACCESSIBILITY_BOUNCE_KEYS); shortcutFeatureKeys.add(Settings.Secure.ACCESSIBILITY_BOUNCE_KEYS);

View File

@@ -125,6 +125,9 @@ public abstract class AccessibilityShortcutPreferenceFragment extends Restricted
final List<String> shortcutFeatureKeys = new ArrayList<>(); final List<String> shortcutFeatureKeys = new ArrayList<>();
shortcutFeatureKeys.add(Settings.Secure.ACCESSIBILITY_BUTTON_TARGETS); shortcutFeatureKeys.add(Settings.Secure.ACCESSIBILITY_BUTTON_TARGETS);
shortcutFeatureKeys.add(Settings.Secure.ACCESSIBILITY_SHORTCUT_TARGET_SERVICE); shortcutFeatureKeys.add(Settings.Secure.ACCESSIBILITY_SHORTCUT_TARGET_SERVICE);
if (android.view.accessibility.Flags.a11yQsShortcut()) {
shortcutFeatureKeys.add(Settings.Secure.ACCESSIBILITY_QS_TARGETS);
}
mSettingsContentObserver = new AccessibilitySettingsContentObserver(new Handler()); mSettingsContentObserver = new AccessibilitySettingsContentObserver(new Handler());
mSettingsContentObserver.registerKeysToObserverCallback(shortcutFeatureKeys, key -> { mSettingsContentObserver.registerKeysToObserverCallback(shortcutFeatureKeys, key -> {
updateShortcutPreferenceData(); updateShortcutPreferenceData();

View File

@@ -74,6 +74,9 @@ public class ColorAndMotionFragment extends DashboardFragment {
mShortcutFeatureKeys.add(Settings.Secure.ACCESSIBILITY_DISPLAY_DALTONIZER_ENABLED); mShortcutFeatureKeys.add(Settings.Secure.ACCESSIBILITY_DISPLAY_DALTONIZER_ENABLED);
mShortcutFeatureKeys.add(Settings.Secure.ACCESSIBILITY_SHORTCUT_TARGET_SERVICE); mShortcutFeatureKeys.add(Settings.Secure.ACCESSIBILITY_SHORTCUT_TARGET_SERVICE);
mShortcutFeatureKeys.add(Settings.Secure.ACCESSIBILITY_BUTTON_TARGETS); mShortcutFeatureKeys.add(Settings.Secure.ACCESSIBILITY_BUTTON_TARGETS);
if (android.view.accessibility.Flags.a11yQsShortcut()) {
mShortcutFeatureKeys.add(Settings.Secure.ACCESSIBILITY_QS_TARGETS);
}
if (Flags.forceInvertColor()) { if (Flags.forceInvertColor()) {
mShortcutFeatureKeys.add(ToggleForceInvertPreferenceController.SETTINGS_KEY); mShortcutFeatureKeys.add(ToggleForceInvertPreferenceController.SETTINGS_KEY);
} }

View File

@@ -192,7 +192,7 @@ public class HearingDevicePairingFragment extends RestrictedDashboardFragment im
public void onDeviceBondStateChanged(@NonNull CachedBluetoothDevice cachedDevice, public void onDeviceBondStateChanged(@NonNull CachedBluetoothDevice cachedDevice,
int bondState) { int bondState) {
if (DEBUG) { if (DEBUG) {
Log.d(TAG, "onDeviceBondStateChanged: " + cachedDevice.getDevice() + ", state = " Log.d(TAG, "onDeviceBondStateChanged: " + cachedDevice + ", state = "
+ bondState); + bondState);
} }
if (bondState == BluetoothDevice.BOND_BONDED) { if (bondState == BluetoothDevice.BOND_BONDED) {
@@ -276,13 +276,13 @@ public class HearingDevicePairingFragment extends RestrictedDashboardFragment im
} }
mDevicePreferenceMap.put(cachedDevice, preference); mDevicePreferenceMap.put(cachedDevice, preference);
if (DEBUG) { if (DEBUG) {
Log.d(TAG, "Add device. device: " + cachedDevice.getDevice()); Log.d(TAG, "Add device. device: " + cachedDevice);
} }
} }
void removeDevice(CachedBluetoothDevice cachedDevice) { void removeDevice(CachedBluetoothDevice cachedDevice) {
if (DEBUG) { if (DEBUG) {
Log.d(TAG, "removeDevice: " + cachedDevice.getDevice()); Log.d(TAG, "removeDevice: " + cachedDevice);
} }
BluetoothDevicePreference preference = mDevicePreferenceMap.remove(cachedDevice); BluetoothDevicePreference preference = mDevicePreferenceMap.remove(cachedDevice);
if (mAvailableHearingDeviceGroup != null && preference != null) { if (mAvailableHearingDeviceGroup != null && preference != null) {
@@ -331,13 +331,13 @@ public class HearingDevicePairingFragment extends RestrictedDashboardFragment im
cachedDevice = mCachedDeviceManager.addDevice(device); cachedDevice = mCachedDeviceManager.addDevice(device);
} else if (cachedDevice.getBondState() == BluetoothDevice.BOND_BONDED) { } else if (cachedDevice.getBondState() == BluetoothDevice.BOND_BONDED) {
if (DEBUG) { if (DEBUG) {
Log.d(TAG, "Skip this device, already bonded: " + cachedDevice.getDevice()); Log.d(TAG, "Skip this device, already bonded: " + cachedDevice);
} }
return; return;
} }
if (cachedDevice.getHearingAidInfo() == null) { if (cachedDevice.getHearingAidInfo() == null) {
if (DEBUG) { if (DEBUG) {
Log.d(TAG, "Set hearing aid info on device: " + cachedDevice.getDevice()); Log.d(TAG, "Set hearing aid info on device: " + cachedDevice);
} }
cachedDevice.setHearingAidInfo(new HearingAidInfo.Builder().build()); cachedDevice.setHearingAidInfo(new HearingAidInfo.Builder().build());
} }
@@ -455,7 +455,7 @@ public class HearingDevicePairingFragment extends RestrictedDashboardFragment im
void discoverServices(CachedBluetoothDevice cachedDevice) { void discoverServices(CachedBluetoothDevice cachedDevice) {
if (DEBUG) { if (DEBUG) {
Log.d(TAG, "connectGattToCheckCompatibility, device: " + cachedDevice.getDevice()); Log.d(TAG, "connectGattToCheckCompatibility, device: " + cachedDevice);
} }
BluetoothGatt gatt = cachedDevice.getDevice().connectGatt(getContext(), false, BluetoothGatt gatt = cachedDevice.getDevice().connectGatt(getContext(), false,
new BluetoothGattCallback() { new BluetoothGattCallback() {
@@ -465,7 +465,7 @@ public class HearingDevicePairingFragment extends RestrictedDashboardFragment im
super.onConnectionStateChange(gatt, status, newState); super.onConnectionStateChange(gatt, status, newState);
if (DEBUG) { if (DEBUG) {
Log.d(TAG, "onConnectionStateChange, status: " + status + ", newState: " Log.d(TAG, "onConnectionStateChange, status: " + status + ", newState: "
+ newState + ", device: " + cachedDevice.getDevice()); + newState + ", device: " + cachedDevice);
} }
if (status == GATT_SUCCESS if (status == GATT_SUCCESS
&& newState == BluetoothProfile.STATE_CONNECTED) { && newState == BluetoothProfile.STATE_CONNECTED) {
@@ -481,14 +481,14 @@ public class HearingDevicePairingFragment extends RestrictedDashboardFragment im
super.onServicesDiscovered(gatt, status); super.onServicesDiscovered(gatt, status);
if (DEBUG) { if (DEBUG) {
Log.d(TAG, "onServicesDiscovered, status: " + status + ", device: " Log.d(TAG, "onServicesDiscovered, status: " + status + ", device: "
+ cachedDevice.getDevice()); + cachedDevice);
} }
if (status == GATT_SUCCESS) { if (status == GATT_SUCCESS) {
if (gatt.getService(BluetoothUuid.HEARING_AID.getUuid()) != null if (gatt.getService(BluetoothUuid.HEARING_AID.getUuid()) != null
|| gatt.getService(BluetoothUuid.HAS.getUuid()) != null) { || gatt.getService(BluetoothUuid.HAS.getUuid()) != null) {
if (DEBUG) { if (DEBUG) {
Log.d(TAG, "compatible with Android, device: " Log.d(TAG, "compatible with Android, device: "
+ cachedDevice.getDevice()); + cachedDevice);
} }
addDevice(cachedDevice); addDevice(cachedDevice);
} }

View File

@@ -22,6 +22,7 @@ import static com.android.settings.accessibility.AccessibilityUtil.State.OFF;
import static com.android.settings.accessibility.AccessibilityUtil.State.ON; import static com.android.settings.accessibility.AccessibilityUtil.State.ON;
import android.app.settings.SettingsEnums; import android.app.settings.SettingsEnums;
import android.content.ContentResolver;
import android.content.Context; import android.content.Context;
import android.database.ContentObserver; import android.database.ContentObserver;
import android.net.Uri; import android.net.Uri;
@@ -159,8 +160,11 @@ public class KeyboardVibrationTogglePreferenceController extends TogglePreferenc
} }
private boolean updateKeyboardVibrationSetting(boolean enable) { private boolean updateKeyboardVibrationSetting(boolean enable) {
final boolean success = Settings.System.putInt(mContext.getContentResolver(), final ContentResolver contentResolver = mContext.getContentResolver();
KEYBOARD_VIBRATION_ENABLED, enable ? ON : OFF); final boolean success = Settings.System.putInt(contentResolver,
KEYBOARD_VIBRATION_ENABLED, enable ? ON : OFF);
contentResolver.notifyChange(Settings.System.getUriFor(KEYBOARD_VIBRATION_ENABLED),
null /* observer */, ContentResolver.NOTIFY_NO_DELAY);
if (!success) { if (!success) {
Log.w(TAG, "Update settings database error!"); Log.w(TAG, "Update settings database error!");
} }

View File

@@ -179,6 +179,9 @@ public abstract class ToggleFeaturePreferenceFragment extends DashboardFragment
final List<String> shortcutFeatureKeys = new ArrayList<>(); final List<String> shortcutFeatureKeys = new ArrayList<>();
shortcutFeatureKeys.add(Settings.Secure.ACCESSIBILITY_BUTTON_TARGETS); shortcutFeatureKeys.add(Settings.Secure.ACCESSIBILITY_BUTTON_TARGETS);
shortcutFeatureKeys.add(Settings.Secure.ACCESSIBILITY_SHORTCUT_TARGET_SERVICE); shortcutFeatureKeys.add(Settings.Secure.ACCESSIBILITY_SHORTCUT_TARGET_SERVICE);
if (android.view.accessibility.Flags.a11yQsShortcut()) {
shortcutFeatureKeys.add(Settings.Secure.ACCESSIBILITY_QS_TARGETS);
}
return shortcutFeatureKeys; return shortcutFeatureKeys;
} }

View File

@@ -50,6 +50,8 @@ public class OneHandedSettingsUtils {
Settings.Secure.getUriFor(Settings.Secure.ACCESSIBILITY_BUTTON_TARGETS); Settings.Secure.getUriFor(Settings.Secure.ACCESSIBILITY_BUTTON_TARGETS);
static final Uri HARDWARE_SHORTCUT_ENABLED_URI = static final Uri HARDWARE_SHORTCUT_ENABLED_URI =
Settings.Secure.getUriFor(Settings.Secure.ACCESSIBILITY_SHORTCUT_TARGET_SERVICE); Settings.Secure.getUriFor(Settings.Secure.ACCESSIBILITY_SHORTCUT_TARGET_SERVICE);
static final Uri QS_SHORTCUT_ENABLED_URI =
Settings.Secure.getUriFor(Settings.Secure.ACCESSIBILITY_QS_TARGETS);
public enum OneHandedTimeout { public enum OneHandedTimeout {
NEVER(0), SHORT(4), MEDIUM(8), LONG(12); NEVER(0), SHORT(4), MEDIUM(8), LONG(12);
@@ -254,6 +256,16 @@ public class OneHandedSettingsUtils {
if (!TextUtils.isEmpty(targetsHW) && targetsHW.contains(ONE_HANDED_MODE_TARGET_NAME)) { if (!TextUtils.isEmpty(targetsHW) && targetsHW.contains(ONE_HANDED_MODE_TARGET_NAME)) {
return true; return true;
} }
if (android.view.accessibility.Flags.a11yQsShortcut()) {
// Checks QS_SHORTCUT_KEY
final String targetsQs = Settings.Secure.getStringForUser(context.getContentResolver(),
Settings.Secure.ACCESSIBILITY_QS_TARGETS, sCurrentUserId);
if (!TextUtils.isEmpty(targetsQs) && targetsQs.contains(ONE_HANDED_MODE_TARGET_NAME)) {
return true;
}
}
return false; return false;
} }
@@ -301,6 +313,9 @@ public class OneHandedSettingsUtils {
resolver.registerContentObserver(SHOW_NOTIFICATION_ENABLED_URI, true, this); resolver.registerContentObserver(SHOW_NOTIFICATION_ENABLED_URI, true, this);
resolver.registerContentObserver(SOFTWARE_SHORTCUT_ENABLED_URI, true, this); resolver.registerContentObserver(SOFTWARE_SHORTCUT_ENABLED_URI, true, this);
resolver.registerContentObserver(HARDWARE_SHORTCUT_ENABLED_URI, true, this); resolver.registerContentObserver(HARDWARE_SHORTCUT_ENABLED_URI, true, this);
if (android.view.accessibility.Flags.a11yQsShortcut()) {
resolver.registerContentObserver(QS_SHORTCUT_ENABLED_URI, true, this);
}
} }
@Override @Override

View File

@@ -84,6 +84,13 @@ open class MobileNetworkEidPreferenceController(context: Context, key: String) :
} }
override fun onViewCreated(viewLifecycleOwner: LifecycleOwner) { override fun onViewCreated(viewLifecycleOwner: LifecycleOwner) {
if (!this::lazyViewModel.isInitialized) {
Log.e(
this.javaClass.simpleName,
"lateinit property lazyViewModel has not been initialized"
)
return
}
preference.isVisible = false preference.isVisible = false
val viewModel by lazyViewModel val viewModel by lazyViewModel

View File

@@ -78,6 +78,13 @@ class MobileNetworkImeiPreferenceController(context: Context, key: String) :
} }
override fun onViewCreated(viewLifecycleOwner: LifecycleOwner) { override fun onViewCreated(viewLifecycleOwner: LifecycleOwner) {
if (!this::lazyViewModel.isInitialized) {
Log.e(
this.javaClass.simpleName,
"lateinit property lazyViewModel has not been initialized"
)
return
}
val viewModel by lazyViewModel val viewModel by lazyViewModel
val coroutineScope = viewLifecycleOwner.lifecycleScope val coroutineScope = viewLifecycleOwner.lifecycleScope

View File

@@ -19,6 +19,7 @@ package com.android.settings.network.telephony
import android.content.Context import android.content.Context
import android.telephony.SubscriptionInfo import android.telephony.SubscriptionInfo
import android.telephony.SubscriptionManager import android.telephony.SubscriptionManager
import android.util.Log
import androidx.annotation.VisibleForTesting import androidx.annotation.VisibleForTesting
import androidx.fragment.app.Fragment import androidx.fragment.app.Fragment
import androidx.fragment.app.viewModels import androidx.fragment.app.viewModels
@@ -66,6 +67,13 @@ class MobileNetworkPhoneNumberPreferenceController(context: Context, key: String
} }
override fun onViewCreated(viewLifecycleOwner: LifecycleOwner) { override fun onViewCreated(viewLifecycleOwner: LifecycleOwner) {
if (!this::lazyViewModel.isInitialized) {
Log.e(
this.javaClass.simpleName,
"lateinit property lazyViewModel has not been initialized"
)
return
}
val viewModel by lazyViewModel val viewModel by lazyViewModel
val coroutineScope = viewLifecycleOwner.lifecycleScope val coroutineScope = viewLifecycleOwner.lifecycleScope

View File

@@ -19,6 +19,7 @@ package com.android.settings.network.telephony
import android.content.Context import android.content.Context
import android.telephony.SubscriptionInfo import android.telephony.SubscriptionInfo
import android.telephony.SubscriptionManager import android.telephony.SubscriptionManager
import android.util.Log
import androidx.annotation.VisibleForTesting import androidx.annotation.VisibleForTesting
import androidx.fragment.app.Fragment import androidx.fragment.app.Fragment
import androidx.fragment.app.viewModels import androidx.fragment.app.viewModels
@@ -26,6 +27,7 @@ import androidx.lifecycle.LifecycleOwner
import androidx.preference.Preference import androidx.preference.Preference
import androidx.preference.PreferenceScreen import androidx.preference.PreferenceScreen
import com.android.settings.flags.Flags import com.android.settings.flags.Flags
import com.android.settings.network.SimOnboardingActivity
import com.android.settings.network.SubscriptionInfoListViewModel import com.android.settings.network.SubscriptionInfoListViewModel
import com.android.settingslib.spa.framework.util.collectLatestWithLifecycle import com.android.settingslib.spa.framework.util.collectLatestWithLifecycle
@@ -57,6 +59,14 @@ class MobileNetworkSpnPreferenceController(context: Context, key: String) :
} }
override fun onViewCreated(viewLifecycleOwner: LifecycleOwner) { override fun onViewCreated(viewLifecycleOwner: LifecycleOwner) {
if (!this::lazyViewModel.isInitialized) {
Log.e(
this.javaClass.simpleName,
"lateinit property lazyViewModel has not been initialized"
)
return
}
val viewModel by lazyViewModel val viewModel by lazyViewModel
viewModel.subscriptionInfoListFlow viewModel.subscriptionInfoListFlow

View File

@@ -22,6 +22,7 @@ import android.telecom.TelecomManager
import android.telephony.SubscriptionManager import android.telephony.SubscriptionManager
import android.telephony.TelephonyManager import android.telephony.TelephonyManager
import android.telephony.ims.ImsMmTelManager import android.telephony.ims.ImsMmTelManager
import android.util.Log
import androidx.lifecycle.LifecycleOwner import androidx.lifecycle.LifecycleOwner
import androidx.preference.Preference import androidx.preference.Preference
import androidx.preference.PreferenceScreen import androidx.preference.PreferenceScreen
@@ -76,6 +77,13 @@ open class WifiCallingPreferenceController @JvmOverloads constructor(
} }
override fun onViewCreated(viewLifecycleOwner: LifecycleOwner) { override fun onViewCreated(viewLifecycleOwner: LifecycleOwner) {
if(mSubId == SubscriptionManager.INVALID_SUBSCRIPTION_ID){
Log.e(
this.javaClass.simpleName,
"mSubId is INVALID_SUBSCRIPTION_ID"
)
return
}
wifiCallingRepositoryFactory(mSubId).wifiCallingReadyFlow() wifiCallingRepositoryFactory(mSubId).wifiCallingReadyFlow()
.collectLatestWithLifecycle(viewLifecycleOwner) { isReady -> .collectLatestWithLifecycle(viewLifecycleOwner) { isReady ->
preference.isVisible = isReady preference.isVisible = isReady

View File

@@ -23,6 +23,7 @@ import android.os.PersistableBundle
import android.provider.Settings import android.provider.Settings
import android.telephony.CarrierConfigManager import android.telephony.CarrierConfigManager
import android.telephony.ServiceState import android.telephony.ServiceState
import android.telephony.SubscriptionManager
import android.telephony.TelephonyManager import android.telephony.TelephonyManager
import androidx.annotation.VisibleForTesting import androidx.annotation.VisibleForTesting
import androidx.compose.runtime.Composable import androidx.compose.runtime.Composable
@@ -80,7 +81,7 @@ class AutoSelectPreferenceController @JvmOverloads constructor(
@VisibleForTesting @VisibleForTesting
var progressDialog: ProgressDialog? = null var progressDialog: ProgressDialog? = null
private var subId by notNull<Int>() private var subId = SubscriptionManager.INVALID_SUBSCRIPTION_ID
/** /**
* Initialization based on given subscription id. * Initialization based on given subscription id.

View File

@@ -16,6 +16,7 @@
package com.android.settings.spa.network package com.android.settings.spa.network
import android.telephony.SubscriptionInfo
import androidx.compose.foundation.layout.Column import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.padding import androidx.compose.foundation.layout.padding
import androidx.compose.material.icons.Icons import androidx.compose.material.icons.Icons
@@ -63,52 +64,55 @@ fun SimOnboardingLabelSimImpl(
cancelAction cancelAction
), ),
) { ) {
labelSimBody(onboardingService) LabelSimBody(onboardingService)
} }
} }
@Composable @Composable
private fun labelSimBody(onboardingService: SimOnboardingService) { private fun LabelSimBody(onboardingService: SimOnboardingService) {
Column(Modifier.padding(SettingsDimension.itemPadding)) { Column(Modifier.padding(SettingsDimension.itemPadding)) {
SettingsBody(stringResource(R.string.sim_onboarding_label_sim_msg)) SettingsBody(stringResource(R.string.sim_onboarding_label_sim_msg))
} }
for (subInfo in onboardingService.getSelectableSubscriptionInfoList()) { for (subInfo in onboardingService.getSelectableSubscriptionInfoList()) {
var titleSimName by remember { LabelSimPreference(onboardingService, subInfo)
mutableStateOf(
onboardingService.getSubscriptionInfoDisplayName(subInfo)
)
}
var summaryNumber = subInfo.number
// TODO using the SubscriptionUtil.getFormattedPhoneNumber
val alertDialogPresenter = rememberAlertDialogPresenter(
confirmButton = AlertDialogButton(
stringResource(R.string.mobile_network_sim_name_rename)
) {
onboardingService.addItemForRenaming(subInfo, titleSimName)
},
dismissButton = AlertDialogButton(stringResource(R.string.cancel)) {
titleSimName = onboardingService.getSubscriptionInfoDisplayName(subInfo)
},
title = stringResource(R.string.sim_onboarding_label_sim_dialog_title),
text = {
Text(summaryNumber,
modifier = Modifier.padding(bottom = SettingsDimension.itemPaddingVertical))
SettingsOutlinedTextField(
value = titleSimName,
label = stringResource(R.string.sim_onboarding_label_sim_dialog_label),
enabled = true,
shape = MaterialTheme.shapes.extraLarge
) {
titleSimName = it
}
},
)
Preference(object : PreferenceModel {
override val title = titleSimName
override val summary: () -> String
get() = { summaryNumber }
override val onClick = alertDialogPresenter::open
})
} }
} }
@Composable
private fun LabelSimPreference(
onboardingService: SimOnboardingService,
subInfo: SubscriptionInfo,
) {
var titleSimName by remember {
mutableStateOf(onboardingService.getSubscriptionInfoDisplayName(subInfo))
}
val phoneNumber = phoneNumber(subInfo)
val alertDialogPresenter = rememberAlertDialogPresenter(
confirmButton = AlertDialogButton(stringResource(R.string.mobile_network_sim_name_rename)) {
onboardingService.addItemForRenaming(subInfo, titleSimName)
},
dismissButton = AlertDialogButton(stringResource(R.string.cancel)) {
titleSimName = onboardingService.getSubscriptionInfoDisplayName(subInfo)
},
title = stringResource(R.string.sim_onboarding_label_sim_dialog_title),
text = {
Text(
phoneNumber.value ?: "",
modifier = Modifier.padding(bottom = SettingsDimension.itemPaddingVertical)
)
SettingsOutlinedTextField(
value = titleSimName,
label = stringResource(R.string.sim_onboarding_label_sim_dialog_label),
shape = MaterialTheme.shapes.extraLarge
) {
titleSimName = it
}
},
)
Preference(object : PreferenceModel {
override val title = titleSimName
override val summary = { phoneNumber.value ?: "" }
override val onClick = alertDialogPresenter::open
})
}

View File

@@ -25,6 +25,7 @@ import androidx.compose.foundation.layout.Column
import androidx.compose.material.icons.Icons import androidx.compose.material.icons.Icons
import androidx.compose.material.icons.outlined.Add import androidx.compose.material.icons.outlined.Add
import androidx.compose.runtime.Composable import androidx.compose.runtime.Composable
import androidx.compose.runtime.State
import androidx.compose.runtime.remember import androidx.compose.runtime.remember
import androidx.compose.ui.platform.LocalContext import androidx.compose.ui.platform.LocalContext
import androidx.compose.ui.res.stringResource import androidx.compose.ui.res.stringResource
@@ -58,9 +59,7 @@ private fun SimPreference(subInfo: SubscriptionInfo) {
val checked = remember(subInfo.subscriptionId) { val checked = remember(subInfo.subscriptionId) {
context.isSubscriptionEnabledFlow(subInfo.subscriptionId) context.isSubscriptionEnabledFlow(subInfo.subscriptionId)
}.collectAsStateWithLifecycle(initialValue = false) }.collectAsStateWithLifecycle(initialValue = false)
val phoneNumber = remember(subInfo) { val phoneNumber = phoneNumber(subInfo)
context.phoneNumberFlow(subInfo)
}.collectAsStateWithLifecycle(initialValue = null)
RestrictedTwoTargetSwitchPreference( RestrictedTwoTargetSwitchPreference(
model = object : SwitchPreferenceModel { model = object : SwitchPreferenceModel {
override val title = subInfo.displayName.toString() override val title = subInfo.displayName.toString()
@@ -80,6 +79,14 @@ private fun SimPreference(subInfo: SubscriptionInfo) {
} }
} }
@Composable
fun phoneNumber(subInfo: SubscriptionInfo): State<String?> {
val context = LocalContext.current
return remember(subInfo) {
context.phoneNumberFlow(subInfo)
}.collectAsStateWithLifecycle(initialValue = null)
}
@Composable @Composable
private fun AddSim() { private fun AddSim() {
val context = LocalContext.current val context = LocalContext.current

View File

@@ -38,8 +38,12 @@ import android.content.pm.ResolveInfo;
import android.content.pm.ServiceInfo; import android.content.pm.ServiceInfo;
import android.database.ContentObserver; import android.database.ContentObserver;
import android.os.Build; import android.os.Build;
import android.platform.test.annotations.DisableFlags;
import android.platform.test.annotations.EnableFlags;
import android.platform.test.flag.junit.SetFlagsRule;
import android.provider.Settings; import android.provider.Settings;
import android.view.accessibility.AccessibilityManager; import android.view.accessibility.AccessibilityManager;
import android.view.accessibility.Flags;
import androidx.fragment.app.Fragment; import androidx.fragment.app.Fragment;
import androidx.test.core.app.ApplicationProvider; import androidx.test.core.app.ApplicationProvider;
@@ -59,6 +63,8 @@ import com.android.settingslib.bluetooth.LocalBluetoothManager;
import com.android.settingslib.search.SearchIndexableRaw; import com.android.settingslib.search.SearchIndexableRaw;
import com.android.settingslib.testutils.shadow.ShadowColorDisplayManager; import com.android.settingslib.testutils.shadow.ShadowColorDisplayManager;
import com.google.common.truth.BooleanSubject;
import org.junit.Before; import org.junit.Before;
import org.junit.Rule; import org.junit.Rule;
import org.junit.Test; import org.junit.Test;
@@ -103,6 +109,7 @@ public class AccessibilitySettingsTest {
@Rule @Rule
public final MockitoRule mocks = MockitoJUnit.rule(); public final MockitoRule mocks = MockitoJUnit.rule();
@Rule public final SetFlagsRule mSetFlagsRule = new SetFlagsRule();
private final Context mContext = ApplicationProvider.getApplicationContext(); private final Context mContext = ApplicationProvider.getApplicationContext();
@Spy @Spy
private final AccessibilityServiceInfo mServiceInfo = getMockAccessibilityServiceInfo( private final AccessibilityServiceInfo mServiceInfo = getMockAccessibilityServiceInfo(
@@ -316,30 +323,39 @@ public class AccessibilitySettingsTest {
} }
@Test @Test
public void onCreate_haveRegisterToSpecificUrisAndActions() { @DisableFlags(Flags.FLAG_A11Y_QS_SHORTCUT)
public void onCreate_flagDisabled_haveRegisterToSpecificUrisAndActions() {
setupFragment(); setupFragment();
ShadowContentResolver shadowContentResolver = shadowOf(mContext.getContentResolver()); assertUriObserversContainsClazz(Settings.Secure.ACCESSIBILITY_BUTTON_TARGETS,
Collection<ContentObserver> a11yButtonTargetsObservers = AccessibilitySettingsContentObserver.class).isTrue();
shadowContentResolver.getContentObservers( assertUriObserversContainsClazz(Settings.Secure.ACCESSIBILITY_SHORTCUT_TARGET_SERVICE,
Settings.Secure.getUriFor(Settings.Secure.ACCESSIBILITY_BUTTON_TARGETS)); AccessibilitySettingsContentObserver.class).isTrue();
Collection<ContentObserver> a11yShortcutTargetServiceObservers = assertUriObserversContainsClazz(Settings.Secure.ACCESSIBILITY_QS_TARGETS,
shadowContentResolver.getContentObservers(Settings.Secure.getUriFor( AccessibilitySettingsContentObserver.class).isFalse();
Settings.Secure.ACCESSIBILITY_SHORTCUT_TARGET_SERVICE)); List<BroadcastReceiver> broadcastReceivers =
shadowOf((Application) ApplicationProvider.getApplicationContext())
.getRegisteredReceivers()
.stream().map(wrapper -> wrapper.broadcastReceiver).toList();
assertThat(broadcastReceivers.stream().anyMatch(
broadcastReceiver -> broadcastReceiver instanceof PackageMonitor)).isTrue();
}
@Test
@EnableFlags(Flags.FLAG_A11Y_QS_SHORTCUT)
public void onCreate_flagEnabled_haveRegisterToSpecificUrisAndActions() {
setupFragment();
assertUriObserversContainsClazz(Settings.Secure.ACCESSIBILITY_BUTTON_TARGETS,
AccessibilitySettingsContentObserver.class).isTrue();
assertUriObserversContainsClazz(Settings.Secure.ACCESSIBILITY_SHORTCUT_TARGET_SERVICE,
AccessibilitySettingsContentObserver.class).isTrue();
assertUriObserversContainsClazz(Settings.Secure.ACCESSIBILITY_QS_TARGETS,
AccessibilitySettingsContentObserver.class).isTrue();
List<BroadcastReceiver> broadcastReceivers = List<BroadcastReceiver> broadcastReceivers =
shadowOf((Application) ApplicationProvider.getApplicationContext()) shadowOf((Application) ApplicationProvider.getApplicationContext())
.getRegisteredReceivers() .getRegisteredReceivers()
.stream().map(wrapper -> wrapper.broadcastReceiver).toList(); .stream().map(wrapper -> wrapper.broadcastReceiver).toList();
assertThat(
a11yButtonTargetsObservers.stream()
.anyMatch(contentObserver ->
contentObserver instanceof AccessibilitySettingsContentObserver))
.isTrue();
assertThat(
a11yShortcutTargetServiceObservers.stream()
.anyMatch(contentObserver ->
contentObserver instanceof AccessibilitySettingsContentObserver))
.isTrue();
assertThat(broadcastReceivers.stream().anyMatch( assertThat(broadcastReceivers.stream().anyMatch(
broadcastReceiver -> broadcastReceiver instanceof PackageMonitor)).isTrue(); broadcastReceiver -> broadcastReceiver instanceof PackageMonitor)).isTrue();
} }
@@ -350,27 +366,16 @@ public class AccessibilitySettingsTest {
mActivityController.pause().stop().destroy(); mActivityController.pause().stop().destroy();
ShadowContentResolver shadowContentResolver = shadowOf(mContext.getContentResolver()); assertUriObserversContainsClazz(Settings.Secure.ACCESSIBILITY_BUTTON_TARGETS,
Collection<ContentObserver> a11yButtonTargetsObservers = AccessibilitySettingsContentObserver.class).isFalse();
shadowContentResolver.getContentObservers( assertUriObserversContainsClazz(Settings.Secure.ACCESSIBILITY_SHORTCUT_TARGET_SERVICE,
Settings.Secure.getUriFor(Settings.Secure.ACCESSIBILITY_BUTTON_TARGETS)); AccessibilitySettingsContentObserver.class).isFalse();
Collection<ContentObserver> a11yShortcutTargetServiceObservers = assertUriObserversContainsClazz(Settings.Secure.ACCESSIBILITY_QS_TARGETS,
shadowContentResolver.getContentObservers(Settings.Secure.getUriFor( AccessibilitySettingsContentObserver.class).isFalse();
Settings.Secure.ACCESSIBILITY_SHORTCUT_TARGET_SERVICE));
List<BroadcastReceiver> broadcastReceivers = List<BroadcastReceiver> broadcastReceivers =
shadowOf((Application) ApplicationProvider.getApplicationContext()) shadowOf((Application) ApplicationProvider.getApplicationContext())
.getRegisteredReceivers() .getRegisteredReceivers()
.stream().map(wrapper -> wrapper.broadcastReceiver).toList(); .stream().map(wrapper -> wrapper.broadcastReceiver).toList();
assertThat(
a11yButtonTargetsObservers.stream()
.anyMatch(contentObserver ->
contentObserver instanceof AccessibilitySettingsContentObserver))
.isFalse();
assertThat(
a11yShortcutTargetServiceObservers.stream()
.anyMatch(contentObserver ->
contentObserver instanceof AccessibilitySettingsContentObserver))
.isFalse();
assertThat(broadcastReceivers.stream().anyMatch( assertThat(broadcastReceivers.stream().anyMatch(
broadcastReceiver -> broadcastReceiver instanceof PackageMonitor)).isFalse(); broadcastReceiver -> broadcastReceiver instanceof PackageMonitor)).isFalse();
} }
@@ -491,4 +496,14 @@ public class AccessibilitySettingsTest {
Settings.Secure.ACCESSIBILITY_BUTTON_TARGETS, Settings.Secure.ACCESSIBILITY_BUTTON_TARGETS,
enabled ? componentName.flattenToString() : ""); enabled ? componentName.flattenToString() : "");
} }
private BooleanSubject assertUriObserversContainsClazz(
String settingUri, Class<?> clazz) {
ShadowContentResolver shadowContentResolver = shadowOf(mContext.getContentResolver());
Collection<ContentObserver> observers =
shadowContentResolver.getContentObservers(
Settings.Secure.getUriFor(settingUri));
return assertThat(observers.stream().anyMatch(clazz::isInstance));
}
} }

View File

@@ -178,7 +178,7 @@ public class HearingDevicePairingFragmentTest {
} }
@Test @Test
public void handleLeScanResult_isNotAndroidCompatible_() { public void handleLeScanResult_isNotAndroidCompatible_discoverServices() {
ScanResult scanResult = mock(ScanResult.class); ScanResult scanResult = mock(ScanResult.class);
doReturn(mDevice).when(scanResult).getDevice(); doReturn(mDevice).when(scanResult).getDevice();
doReturn(mCachedDevice).when(mCachedDeviceManager).findDevice(mDevice); doReturn(mCachedDevice).when(mCachedDeviceManager).findDevice(mDevice);
@@ -189,6 +189,19 @@ public class HearingDevicePairingFragmentTest {
verify(mFragment).discoverServices(mCachedDevice); verify(mFragment).discoverServices(mCachedDevice);
} }
@Test
public void handleLeScanResult_alreadyBonded_doNothing() {
ScanResult scanResult = mock(ScanResult.class);
doReturn(mDevice).when(scanResult).getDevice();
doReturn(mCachedDevice).when(mCachedDeviceManager).findDevice(mDevice);
doReturn(BluetoothDevice.BOND_BONDED).when(mCachedDevice).getBondState();
mFragment.handleLeScanResult(scanResult);
verify(mFragment, never()).addDevice(mCachedDevice);
verify(mFragment, never()).discoverServices(mCachedDevice);
}
@Test @Test
public void onProfileConnectionStateChanged_deviceConnected_inSelectedList_finish() { public void onProfileConnectionStateChanged_deviceConnected_inSelectedList_finish() {
doReturn(true).when(mCachedDevice).isConnected(); doReturn(true).when(mCachedDevice).isConnected();

View File

@@ -30,6 +30,7 @@ import static org.mockito.Mockito.when;
import static org.mockito.Mockito.verify; import static org.mockito.Mockito.verify;
import android.app.settings.SettingsEnums; import android.app.settings.SettingsEnums;
import android.content.ContentResolver;
import android.content.Context; import android.content.Context;
import android.content.res.Resources; import android.content.res.Resources;
import android.os.vibrator.Flags; import android.os.vibrator.Flags;
@@ -60,6 +61,9 @@ public class KeyboardVibrationTogglePreferenceControllerTest {
@Mock @Mock
private PreferenceScreen mPreferenceScreen; private PreferenceScreen mPreferenceScreen;
@Mock
private ContentResolver mContentResolver;
private Context mContext; private Context mContext;
private Resources mResources; private Resources mResources;
private KeyboardVibrationTogglePreferenceController mController; private KeyboardVibrationTogglePreferenceController mController;
@@ -72,6 +76,7 @@ public class KeyboardVibrationTogglePreferenceControllerTest {
mContext = spy(ApplicationProvider.getApplicationContext()); mContext = spy(ApplicationProvider.getApplicationContext());
mResources = spy(mContext.getResources()); mResources = spy(mContext.getResources());
when(mContext.getResources()).thenReturn(mResources); when(mContext.getResources()).thenReturn(mResources);
when(mContext.getContentResolver()).thenReturn(mContentResolver);
mFeatureFactory = FakeFeatureFactory.setupForTest(); mFeatureFactory = FakeFeatureFactory.setupForTest();
mController = new KeyboardVibrationTogglePreferenceController(mContext, "preferenceKey"); mController = new KeyboardVibrationTogglePreferenceController(mContext, "preferenceKey");
mPreference = new SwitchPreference(mContext); mPreference = new SwitchPreference(mContext);

View File

@@ -24,6 +24,7 @@ import static org.mockito.ArgumentMatchers.any;
import static org.mockito.ArgumentMatchers.eq; import static org.mockito.ArgumentMatchers.eq;
import static org.mockito.Mockito.doReturn; import static org.mockito.Mockito.doReturn;
import static org.mockito.Mockito.mock; import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.never;
import static org.mockito.Mockito.spy; import static org.mockito.Mockito.spy;
import static org.mockito.Mockito.verify; import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when; import static org.mockito.Mockito.when;
@@ -146,8 +147,9 @@ public class ToggleFeaturePreferenceFragmentTest {
} }
@Test @Test
@EnableFlags(android.view.accessibility.Flags.FLAG_A11Y_QS_SHORTCUT)
@Config(shadows = {ShadowFragment.class}) @Config(shadows = {ShadowFragment.class})
public void onResume_haveRegisterToSpecificUris() { public void onResume_flagEnabled_haveRegisterToSpecificUris() {
mFragment.onAttach(mContext); mFragment.onAttach(mContext);
mFragment.onCreate(Bundle.EMPTY); mFragment.onCreate(Bundle.EMPTY);
@@ -162,6 +164,36 @@ public class ToggleFeaturePreferenceFragmentTest {
Settings.Secure.ACCESSIBILITY_SHORTCUT_TARGET_SERVICE)), Settings.Secure.ACCESSIBILITY_SHORTCUT_TARGET_SERVICE)),
eq(false), eq(false),
any(AccessibilitySettingsContentObserver.class)); any(AccessibilitySettingsContentObserver.class));
verify(mContentResolver).registerContentObserver(
eq(Settings.Secure.getUriFor(
Settings.Secure.ACCESSIBILITY_QS_TARGETS)),
eq(false),
any(AccessibilitySettingsContentObserver.class));
}
@Test
@DisableFlags(android.view.accessibility.Flags.FLAG_A11Y_QS_SHORTCUT)
@Config(shadows = {ShadowFragment.class})
public void onResume_flagDisabled_haveRegisterToSpecificUris() {
mFragment.onAttach(mContext);
mFragment.onCreate(Bundle.EMPTY);
mFragment.onResume();
verify(mContentResolver).registerContentObserver(
eq(Settings.Secure.getUriFor(Settings.Secure.ACCESSIBILITY_BUTTON_TARGETS)),
eq(false),
any(AccessibilitySettingsContentObserver.class));
verify(mContentResolver).registerContentObserver(
eq(Settings.Secure.getUriFor(
Settings.Secure.ACCESSIBILITY_SHORTCUT_TARGET_SERVICE)),
eq(false),
any(AccessibilitySettingsContentObserver.class));
verify(mContentResolver, never()).registerContentObserver(
eq(Settings.Secure.getUriFor(
Settings.Secure.ACCESSIBILITY_QS_TARGETS)),
eq(false),
any(AccessibilitySettingsContentObserver.class));
} }
@Test @Test

View File

@@ -292,7 +292,39 @@ public class ToggleScreenMagnificationPreferenceFragmentTest {
} }
@Test @Test
public void onResume_haveRegisterToSpecificUris() { @EnableFlags(android.view.accessibility.Flags.FLAG_A11Y_QS_SHORTCUT)
public void onResume_flagEnabled_haveRegisterToSpecificUris() {
ShadowContentResolver shadowContentResolver = Shadows.shadowOf(
mContext.getContentResolver());
Uri[] observedUri = new Uri[]{
Settings.Secure.getUriFor(Settings.Secure.ACCESSIBILITY_BUTTON_TARGETS),
Settings.Secure.getUriFor(
Settings.Secure.ACCESSIBILITY_SHORTCUT_TARGET_SERVICE),
Settings.Secure.getUriFor(
Settings.Secure.ACCESSIBILITY_QS_TARGETS),
Settings.Secure.getUriFor(
Settings.Secure.ACCESSIBILITY_MAGNIFICATION_FOLLOW_TYPING_ENABLED),
Settings.Secure.getUriFor(
Settings.Secure.ACCESSIBILITY_MAGNIFICATION_ALWAYS_ON_ENABLED)
};
for (Uri uri : observedUri) {
// verify no observer registered before launching the fragment
assertThat(shadowContentResolver.getContentObservers(uri)).isEmpty();
}
mFragController.create(R.id.main_content, /* bundle= */ null).start().resume();
for (Uri uri : observedUri) {
Collection<ContentObserver> observers = shadowContentResolver.getContentObservers(uri);
assertThat(observers.size()).isEqualTo(1);
assertThat(observers.stream().findFirst().get()).isInstanceOf(
AccessibilitySettingsContentObserver.class);
}
}
@Test
@DisableFlags(android.view.accessibility.Flags.FLAG_A11Y_QS_SHORTCUT)
public void onResume_flagDisabled_haveRegisterToSpecificUris() {
ShadowContentResolver shadowContentResolver = Shadows.shadowOf( ShadowContentResolver shadowContentResolver = Shadows.shadowOf(
mContext.getContentResolver()); mContext.getContentResolver());
Uri[] observedUri = new Uri[]{ Uri[] observedUri = new Uri[]{
@@ -317,6 +349,9 @@ public class ToggleScreenMagnificationPreferenceFragmentTest {
assertThat(observers.stream().findFirst().get()).isInstanceOf( assertThat(observers.stream().findFirst().get()).isInstanceOf(
AccessibilitySettingsContentObserver.class); AccessibilitySettingsContentObserver.class);
} }
assertThat(shadowContentResolver.getContentObservers(
Settings.Secure.getUriFor(
Settings.Secure.ACCESSIBILITY_QS_TARGETS))).hasSize(0);
} }
@Test @Test

View File

@@ -16,13 +16,20 @@
package com.android.settings.gestures; package com.android.settings.gestures;
import static com.android.settings.gestures.OneHandedSettingsUtils.ONE_HANDED_MODE_TARGET_NAME;
import static com.google.common.truth.Truth.assertThat; import static com.google.common.truth.Truth.assertThat;
import android.content.Context; import android.content.Context;
import android.os.UserHandle; import android.os.UserHandle;
import android.platform.test.annotations.DisableFlags;
import android.platform.test.annotations.EnableFlags;
import android.platform.test.flag.junit.SetFlagsRule;
import android.provider.Settings; import android.provider.Settings;
import android.view.accessibility.Flags;
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.robolectric.RobolectricTestRunner; import org.robolectric.RobolectricTestRunner;
@@ -30,7 +37,8 @@ import org.robolectric.RuntimeEnvironment;
@RunWith(RobolectricTestRunner.class) @RunWith(RobolectricTestRunner.class)
public class OneHandedSettingsUtilsTest { public class OneHandedSettingsUtilsTest {
@Rule
public final SetFlagsRule mSetFlagsRule = new SetFlagsRule();
private static final int OFF = 0; private static final int OFF = 0;
private static final int ON = 1; private static final int ON = 1;
@@ -120,4 +128,66 @@ public class OneHandedSettingsUtilsTest {
OneHandedSettingsUtils.OneHandedTimeout.LONG.getValue(), mCurrentUserId)) OneHandedSettingsUtils.OneHandedTimeout.LONG.getValue(), mCurrentUserId))
.isEqualTo(12); .isEqualTo(12);
} }
@Test
public void getShortcutEnabled_a11yButtonVolumeKeysShortcutEnabled_returnTrue() {
setupShortcuts(
/* enableFab= */ true, /* enableVolumeKeys= */ true, /* enableQs=*/ false);
assertThat(OneHandedSettingsUtils.getShortcutEnabled(mContext)).isTrue();
}
@Test
public void getShortcutEnabled_a11yButtonShortcutEnabled_returnTrue() {
setupShortcuts(
/* enableFab= */ true, /* enableVolumeKeys= */ false, /* enableQs=*/ false);
assertThat(OneHandedSettingsUtils.getShortcutEnabled(mContext)).isTrue();
}
@Test
public void getShortcutEnabled_volumeKeysShortcutEnabled_returnTrue() {
setupShortcuts(
/* enableFab= */ false, /* enableVolumeKeys= */ true, /* enableQs=*/ false);
assertThat(OneHandedSettingsUtils.getShortcutEnabled(mContext)).isTrue();
}
@Test
public void getShortcutEnabled_noShortcutsEnabled_returnFalse() {
setupShortcuts(
/* enableFab= */ false, /* enableVolumeKeys= */ false, /* enableQs=*/ false);
assertThat(OneHandedSettingsUtils.getShortcutEnabled(mContext)).isFalse();
}
@Test
@EnableFlags(Flags.FLAG_A11Y_QS_SHORTCUT)
public void getShortcutEnabled_qsShortcutEnabled_returnTrue() {
setupShortcuts(
/* enableFab= */ false, /* enableVolumeKeys= */ false, /* enableQs=*/ true);
assertThat(OneHandedSettingsUtils.getShortcutEnabled(mContext)).isTrue();
}
@Test
@DisableFlags(Flags.FLAG_A11Y_QS_SHORTCUT)
public void getShortcutEnabled_flagDisabled_qsShortcutEnabled_returnFalse() {
setupShortcuts(
/* enableFab= */ false, /* enableVolumeKeys= */ false, /* enableQs=*/ true);
assertThat(OneHandedSettingsUtils.getShortcutEnabled(mContext)).isFalse();
}
private void setupShortcuts(boolean enableFab, boolean enableVolumeKeys, boolean enableQs) {
setupShortcut(Settings.Secure.ACCESSIBILITY_BUTTON_TARGETS, enableFab);
setupShortcut(Settings.Secure.ACCESSIBILITY_SHORTCUT_TARGET_SERVICE, enableVolumeKeys);
setupShortcut(Settings.Secure.ACCESSIBILITY_QS_TARGETS, enableQs);
}
private void setupShortcut(String shortcutSettingKey, boolean enabled) {
final String targetName = enabled ? ONE_HANDED_MODE_TARGET_NAME : "";
Settings.Secure.putStringForUser(
mContext.getContentResolver(), shortcutSettingKey, targetName, mCurrentUserId);
}
} }