Snap for 12609205 from e784d052b9 to 25Q1-release
Change-Id: I1feee8a431bbc9e4bf3724917782cef1cf3d1767
This commit is contained in:
@@ -136,6 +136,8 @@
|
||||
<string name="keywords_add_bt_device">bluetooth</string>
|
||||
<!-- Title for bluetooth auto on toggle [CHAR LIMIT=60] -->
|
||||
<string name="bluetooth_screen_auto_on_title">Automatically turn on tomorrow</string>
|
||||
<!-- Summary for bluetooth auto on toggle [CHAR LIMIT=60] -->
|
||||
<string name="bluetooth_screen_auto_on_summary">If you turn off Bluetooth, it turns on again the next day</string>
|
||||
|
||||
|
||||
<!-- Button to help user to pair right ear of the hearing aid device. It will show when only one of the hearing aid device set is connected. [CHAR LIMIT=20] -->
|
||||
|
||||
@@ -22,35 +22,46 @@
|
||||
|
||||
<com.android.settingslib.widget.TopIntroPreference
|
||||
android:key="accessibility_control_timeout_intro"
|
||||
android:title="@string/accessibility_control_timeout_preference_intro_text"/>
|
||||
android:title="@string/accessibility_control_timeout_preference_intro_text"
|
||||
settings:searchable="false"/>
|
||||
|
||||
<com.android.settingslib.widget.IllustrationPreference
|
||||
android:key="accessibility_control_timeout_banner"
|
||||
settings:lottie_rawRes="@raw/a11y_timeout_banner"/>
|
||||
|
||||
<!-- Items in a list should not be searchable. -->
|
||||
<com.android.settingslib.widget.SelectorWithWidgetPreference
|
||||
android:key="accessibility_control_timeout_default"
|
||||
android:title="@string/accessibility_timeout_default"
|
||||
settings:controller="com.android.settings.accessibility.AccessibilityTimeoutController"/>
|
||||
settings:searchable="false"
|
||||
settings:controller="com.android.settings.accessibility.AccessibilityTimeoutController" />
|
||||
|
||||
<!-- Items in a list should not be searchable. -->
|
||||
<com.android.settingslib.widget.SelectorWithWidgetPreference
|
||||
android:key="accessibility_control_timeout_10secs"
|
||||
android:title="@string/accessibility_timeout_10secs"
|
||||
settings:searchable="false"
|
||||
settings:controller="com.android.settings.accessibility.AccessibilityTimeoutController"/>
|
||||
|
||||
<!-- Items in a list should not be searchable. -->
|
||||
<com.android.settingslib.widget.SelectorWithWidgetPreference
|
||||
android:key="accessibility_control_timeout_30secs"
|
||||
android:title="@string/accessibility_timeout_30secs"
|
||||
settings:searchable="false"
|
||||
settings:controller="com.android.settings.accessibility.AccessibilityTimeoutController"/>
|
||||
|
||||
<!-- Items in a list should not be searchable. -->
|
||||
<com.android.settingslib.widget.SelectorWithWidgetPreference
|
||||
android:key="accessibility_control_timeout_1min"
|
||||
android:title="@string/accessibility_timeout_1min"
|
||||
settings:searchable="false"
|
||||
settings:controller="com.android.settings.accessibility.AccessibilityTimeoutController"/>
|
||||
|
||||
<!-- Items in a list should not be searchable. -->
|
||||
<com.android.settingslib.widget.SelectorWithWidgetPreference
|
||||
android:key="accessibility_control_timeout_2mins"
|
||||
android:title="@string/accessibility_timeout_2mins"
|
||||
settings:searchable="false"
|
||||
settings:controller="com.android.settings.accessibility.AccessibilityTimeoutController"/>
|
||||
|
||||
<com.android.settings.accessibility.AccessibilityFooterPreference
|
||||
|
||||
@@ -21,6 +21,7 @@
|
||||
<SwitchPreferenceCompat
|
||||
android:key="bluetooth_auto_on_settings_toggle"
|
||||
android:title="@string/bluetooth_screen_auto_on_title"
|
||||
android:summary="@string/bluetooth_screen_auto_on_summary"
|
||||
settings:controller="com.android.settings.bluetooth.BluetoothAutoOnPreferenceController"/>
|
||||
|
||||
<Preference
|
||||
|
||||
@@ -18,11 +18,14 @@ package com.android.settings.accessibility;
|
||||
|
||||
import android.bluetooth.BluetoothProfile;
|
||||
import android.content.Context;
|
||||
import android.util.Log;
|
||||
|
||||
import androidx.annotation.VisibleForTesting;
|
||||
import androidx.fragment.app.FragmentManager;
|
||||
import androidx.preference.Preference;
|
||||
import androidx.preference.PreferenceScreen;
|
||||
|
||||
import com.android.settings.R;
|
||||
import com.android.settings.bluetooth.BluetoothDeviceUpdater;
|
||||
import com.android.settings.connecteddevice.DevicePreferenceCallback;
|
||||
import com.android.settings.dashboard.DashboardFragment;
|
||||
@@ -32,6 +35,9 @@ import com.android.settingslib.bluetooth.LocalBluetoothManager;
|
||||
import com.android.settingslib.core.lifecycle.LifecycleObserver;
|
||||
import com.android.settingslib.core.lifecycle.events.OnStart;
|
||||
import com.android.settingslib.core.lifecycle.events.OnStop;
|
||||
import com.android.settingslib.search.SearchIndexableRaw;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* Controller to update the {@link androidx.preference.PreferenceCategory} for all
|
||||
@@ -44,6 +50,7 @@ public class AvailableHearingDevicePreferenceController extends
|
||||
BluetoothCallback {
|
||||
|
||||
private static final String TAG = "AvailableHearingDevicePreferenceController";
|
||||
private static final String SEARCH_DATA_KEY_PREFIX = "a11y_available_hearing_device";
|
||||
|
||||
private BluetoothDeviceUpdater mAvailableHearingDeviceUpdater;
|
||||
private final LocalBluetoothManager mLocalBluetoothManager;
|
||||
@@ -56,6 +63,14 @@ public class AvailableHearingDevicePreferenceController extends
|
||||
context);
|
||||
}
|
||||
|
||||
@VisibleForTesting
|
||||
void init(AvailableHearingDeviceUpdater availableHearingDeviceUpdater) {
|
||||
if (mAvailableHearingDeviceUpdater != null) {
|
||||
throw new IllegalStateException("Should not call init() more than 1 time.");
|
||||
}
|
||||
mAvailableHearingDeviceUpdater = availableHearingDeviceUpdater;
|
||||
}
|
||||
|
||||
/**
|
||||
* Initializes objects in this controller. Need to call this before onStart().
|
||||
*
|
||||
@@ -107,4 +122,34 @@ public class AvailableHearingDevicePreferenceController extends
|
||||
getMetricsCategory());
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void updateDynamicRawDataToIndex(List<SearchIndexableRaw> rawData) {
|
||||
if (Flags.fixA11ySettingsSearch()) {
|
||||
if (mLocalBluetoothManager == null) {
|
||||
Log.d(TAG, "Bluetooth is not supported");
|
||||
return;
|
||||
}
|
||||
|
||||
for (CachedBluetoothDevice cachedDevice :
|
||||
mLocalBluetoothManager.getCachedDeviceManager().getCachedDevicesCopy()) {
|
||||
|
||||
if (!AvailableHearingDeviceUpdater.isAvailableHearingDevice(cachedDevice)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
SearchIndexableRaw data = new SearchIndexableRaw(mContext);
|
||||
// Include the identity address and add prefix to ensure the key is unique and
|
||||
// distinguish from Bluetooth's connected devices.
|
||||
data.key = SEARCH_DATA_KEY_PREFIX
|
||||
+ cachedDevice.getName() + cachedDevice.getIdentityAddress();
|
||||
data.title = cachedDevice.getName();
|
||||
data.summaryOn = mContext.getString(R.string.accessibility_hearingaid_title);
|
||||
data.screenTitle = mContext.getString(R.string.accessibility_hearingaid_title);
|
||||
rawData.add(data);
|
||||
}
|
||||
} else {
|
||||
super.updateDynamicRawDataToIndex(rawData);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -16,6 +16,7 @@
|
||||
|
||||
package com.android.settings.accessibility;
|
||||
|
||||
import android.bluetooth.BluetoothDevice;
|
||||
import android.content.Context;
|
||||
|
||||
import com.android.settings.bluetooth.AvailableMediaBluetoothDeviceUpdater;
|
||||
@@ -34,10 +35,16 @@ public class AvailableHearingDeviceUpdater extends AvailableMediaBluetoothDevice
|
||||
super(context, devicePreferenceCallback, metricsCategory);
|
||||
}
|
||||
|
||||
static boolean isAvailableHearingDevice(CachedBluetoothDevice cachedDevice) {
|
||||
final BluetoothDevice device = cachedDevice.getDevice();
|
||||
return cachedDevice.isHearingAidDevice()
|
||||
&& device.getBondState() == BluetoothDevice.BOND_BONDED
|
||||
&& device.isConnected();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isFilterMatched(CachedBluetoothDevice cachedDevice) {
|
||||
return cachedDevice.isHearingAidDevice()
|
||||
&& isDeviceConnected(cachedDevice)
|
||||
return isAvailableHearingDevice(cachedDevice)
|
||||
&& isDeviceInCachedDevicesList(cachedDevice);
|
||||
}
|
||||
|
||||
|
||||
@@ -17,17 +17,26 @@
|
||||
package com.android.settings.accessibility;
|
||||
|
||||
import android.content.Context;
|
||||
import android.util.Log;
|
||||
|
||||
import androidx.annotation.VisibleForTesting;
|
||||
import androidx.preference.Preference;
|
||||
import androidx.preference.PreferenceScreen;
|
||||
|
||||
import com.android.settings.R;
|
||||
import com.android.settings.bluetooth.BluetoothDeviceUpdater;
|
||||
import com.android.settings.bluetooth.Utils;
|
||||
import com.android.settings.connecteddevice.DevicePreferenceCallback;
|
||||
import com.android.settings.dashboard.DashboardFragment;
|
||||
import com.android.settingslib.bluetooth.CachedBluetoothDevice;
|
||||
import com.android.settingslib.bluetooth.LocalBluetoothManager;
|
||||
import com.android.settingslib.core.lifecycle.LifecycleObserver;
|
||||
import com.android.settingslib.core.lifecycle.events.OnResume;
|
||||
import com.android.settingslib.core.lifecycle.events.OnStart;
|
||||
import com.android.settingslib.core.lifecycle.events.OnStop;
|
||||
import com.android.settingslib.search.SearchIndexableRaw;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* Controller to update the {@link androidx.preference.PreferenceCategory} for all
|
||||
@@ -39,11 +48,23 @@ public class SavedHearingDevicePreferenceController extends
|
||||
BaseBluetoothDevicePreferenceController implements LifecycleObserver, OnStart, OnResume,
|
||||
OnStop {
|
||||
|
||||
private static final String TAG = "SavedHearingDevicePreferenceController";
|
||||
private static final String SEARCH_DATA_KEY_PREFIX = "a11y_saved_hearing_device";
|
||||
private BluetoothDeviceUpdater mSavedHearingDeviceUpdater;
|
||||
private final LocalBluetoothManager mLocalBluetoothManager;
|
||||
|
||||
public SavedHearingDevicePreferenceController(Context context,
|
||||
String preferenceKey) {
|
||||
super(context, preferenceKey);
|
||||
mLocalBluetoothManager = Utils.getLocalBluetoothManager(context);
|
||||
}
|
||||
|
||||
@VisibleForTesting
|
||||
void init(SavedHearingDeviceUpdater savedHearingDeviceUpdater) {
|
||||
if (mSavedHearingDeviceUpdater != null) {
|
||||
throw new IllegalStateException("Should not call init() more than 1 time.");
|
||||
}
|
||||
mSavedHearingDeviceUpdater = savedHearingDeviceUpdater;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -86,4 +107,34 @@ public class SavedHearingDevicePreferenceController extends
|
||||
mSavedHearingDeviceUpdater.forceUpdate();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void updateDynamicRawDataToIndex(List<SearchIndexableRaw> rawData) {
|
||||
if (Flags.fixA11ySettingsSearch()) {
|
||||
if (mLocalBluetoothManager == null) {
|
||||
Log.d(TAG, "Bluetooth is not supported");
|
||||
return;
|
||||
}
|
||||
|
||||
for (CachedBluetoothDevice cachedDevice :
|
||||
mLocalBluetoothManager.getCachedDeviceManager().getCachedDevicesCopy()) {
|
||||
|
||||
if (!SavedHearingDeviceUpdater.isSavedHearingAidDevice(cachedDevice)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
SearchIndexableRaw data = new SearchIndexableRaw(mContext);
|
||||
// Include the identity address and add prefix to ensure the key is unique and
|
||||
// distinguish from Bluetooth's connected devices.
|
||||
data.key = SEARCH_DATA_KEY_PREFIX
|
||||
+ cachedDevice.getName() + cachedDevice.getIdentityAddress();
|
||||
data.title = cachedDevice.getName();
|
||||
data.summaryOn = mContext.getString(R.string.accessibility_hearingaid_title);
|
||||
data.screenTitle = mContext.getString(R.string.accessibility_hearingaid_title);
|
||||
rawData.add(data);
|
||||
}
|
||||
} else {
|
||||
super.updateDynamicRawDataToIndex(rawData);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -36,14 +36,16 @@ public class SavedHearingDeviceUpdater extends SavedBluetoothDeviceUpdater {
|
||||
super(context, devicePreferenceCallback, /* showConnectedDevice= */ false, metricsCategory);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isFilterMatched(CachedBluetoothDevice cachedDevice) {
|
||||
static boolean isSavedHearingAidDevice(CachedBluetoothDevice cachedDevice) {
|
||||
final BluetoothDevice device = cachedDevice.getDevice();
|
||||
final boolean isSavedHearingAidDevice = cachedDevice.isHearingAidDevice()
|
||||
return cachedDevice.isHearingAidDevice()
|
||||
&& device.getBondState() == BluetoothDevice.BOND_BONDED
|
||||
&& !device.isConnected();
|
||||
}
|
||||
|
||||
return isSavedHearingAidDevice && isDeviceInCachedDevicesList(cachedDevice);
|
||||
@Override
|
||||
public boolean isFilterMatched(CachedBluetoothDevice cachedDevice) {
|
||||
return isSavedHearingAidDevice(cachedDevice) && isDeviceInCachedDevicesList(cachedDevice);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -164,7 +164,9 @@ public abstract class BaseTimeZonePicker extends InstrumentedFragment
|
||||
@Override
|
||||
public boolean onMenuItemActionExpand(MenuItem item) {
|
||||
// To prevent a large space on tool bar.
|
||||
if (mAppBarLayout != null) {
|
||||
mAppBarLayout.setExpanded(false /*expanded*/, false /*animate*/);
|
||||
}
|
||||
// To prevent user can expand the collapsing tool bar view.
|
||||
ViewCompat.setNestedScrollingEnabled(mRecyclerView, false);
|
||||
return true;
|
||||
@@ -173,7 +175,9 @@ public abstract class BaseTimeZonePicker extends InstrumentedFragment
|
||||
@Override
|
||||
public boolean onMenuItemActionCollapse(MenuItem item) {
|
||||
// We keep the collapsed status after user cancel the search function.
|
||||
if (mAppBarLayout != null) {
|
||||
mAppBarLayout.setExpanded(false /*expanded*/, false /*animate*/);
|
||||
}
|
||||
ViewCompat.setNestedScrollingEnabled(mRecyclerView, true);
|
||||
return true;
|
||||
}
|
||||
@@ -196,6 +200,10 @@ public abstract class BaseTimeZonePicker extends InstrumentedFragment
|
||||
}
|
||||
|
||||
private void autoSetCollapsingToolbarLayoutScrolling() {
|
||||
if (mAppBarLayout == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
CoordinatorLayout.LayoutParams params =
|
||||
(CoordinatorLayout.LayoutParams) mAppBarLayout.getLayoutParams();
|
||||
AppBarLayout.Behavior behavior = new AppBarLayout.Behavior();
|
||||
|
||||
@@ -35,20 +35,21 @@ public interface KeyboardSettingsFeatureProvider {
|
||||
boolean supportsFirmwareUpdate();
|
||||
|
||||
/**
|
||||
* Add firmware update preference category .
|
||||
* Register firmware information preferences update on preference screen.
|
||||
*
|
||||
* @param context The context to initialize the application with.
|
||||
* @param screen The {@link PreferenceScreen} to add the firmware update preference category.
|
||||
*
|
||||
* @return true if the category is added successfully.
|
||||
* @param screen The {@link PreferenceScreen} to add the firmware information preferences.
|
||||
*/
|
||||
boolean addFirmwareUpdateCategory(Context context, PreferenceScreen screen);
|
||||
void registerKeyboardInformationCategory(@Nullable PreferenceScreen screen);
|
||||
|
||||
/**
|
||||
* Unregister firmware information preferences update on preference screen.
|
||||
*/
|
||||
void unregisterKeyboardInformationCategory();
|
||||
|
||||
/**
|
||||
* Get custom action key icon.
|
||||
*
|
||||
* @param context Context for accessing resources.
|
||||
*
|
||||
* @return Returns the image of the icon, or null if there is no any custom icon.
|
||||
*/
|
||||
@Nullable
|
||||
|
||||
@@ -19,6 +19,7 @@ package com.android.settings.inputmethod;
|
||||
import android.content.Context;
|
||||
import android.graphics.drawable.Drawable;
|
||||
|
||||
import androidx.annotation.Nullable;
|
||||
import androidx.preference.PreferenceScreen;
|
||||
|
||||
/**
|
||||
@@ -32,12 +33,13 @@ public class KeyboardSettingsFeatureProviderImpl implements KeyboardSettingsFeat
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean addFirmwareUpdateCategory(Context context, PreferenceScreen screen) {
|
||||
return false;
|
||||
}
|
||||
public void registerKeyboardInformationCategory(@Nullable PreferenceScreen screen) {}
|
||||
|
||||
@Override
|
||||
public void unregisterKeyboardInformationCategory() {}
|
||||
|
||||
@Override
|
||||
public Drawable getActionKeyIcon(Context context) {
|
||||
return null;
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
@@ -164,7 +164,7 @@ public final class PhysicalKeyboardFragment extends DashboardFragment
|
||||
mFeatureProvider = featureFactory.getKeyboardSettingsFeatureProvider();
|
||||
mSupportsFirmwareUpdate = mFeatureProvider.supportsFirmwareUpdate();
|
||||
if (mSupportsFirmwareUpdate) {
|
||||
mFeatureProvider.addFirmwareUpdateCategory(getContext(), getPreferenceScreen());
|
||||
mFeatureProvider.registerKeyboardInformationCategory(getPreferenceScreen());
|
||||
}
|
||||
boolean isModifierKeySettingsEnabled = FeatureFlagUtils
|
||||
.isEnabled(getContext(), FeatureFlagUtils.SETTINGS_NEW_KEYBOARD_MODIFIER_KEY);
|
||||
@@ -344,7 +344,7 @@ public final class PhysicalKeyboardFragment extends DashboardFragment
|
||||
mKeyboardAssistanceCategory.setOrder(1);
|
||||
preferenceScreen.addPreference(mKeyboardAssistanceCategory);
|
||||
if (mSupportsFirmwareUpdate) {
|
||||
mFeatureProvider.addFirmwareUpdateCategory(getPrefContext(), preferenceScreen);
|
||||
mFeatureProvider.registerKeyboardInformationCategory(preferenceScreen);
|
||||
}
|
||||
|
||||
if (InputSettings.isAccessibilityBounceKeysFeatureEnabled()
|
||||
@@ -423,6 +423,9 @@ public final class PhysicalKeyboardFragment extends DashboardFragment
|
||||
|
||||
private void unregisterSettingsObserver() {
|
||||
getActivity().getContentResolver().unregisterContentObserver(mContentObserver);
|
||||
if (mSupportsFirmwareUpdate) {
|
||||
mFeatureProvider.unregisterKeyboardInformationCategory();
|
||||
}
|
||||
}
|
||||
|
||||
private void updateAccessibilityBounceKeysSwitch(@NonNull Context context) {
|
||||
|
||||
@@ -0,0 +1,118 @@
|
||||
/*
|
||||
* Copyright (C) 2024 The Android Open Source Project
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package com.android.settings.accessibility;
|
||||
|
||||
import static com.google.common.truth.Truth.assertThat;
|
||||
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
import android.bluetooth.BluetoothDevice;
|
||||
import android.content.Context;
|
||||
import android.platform.test.annotations.EnableFlags;
|
||||
import android.platform.test.flag.junit.SetFlagsRule;
|
||||
|
||||
import androidx.test.core.app.ApplicationProvider;
|
||||
|
||||
import com.android.settings.bluetooth.Utils;
|
||||
import com.android.settings.testutils.shadow.ShadowBluetoothUtils;
|
||||
import com.android.settingslib.bluetooth.CachedBluetoothDevice;
|
||||
import com.android.settingslib.bluetooth.CachedBluetoothDeviceManager;
|
||||
import com.android.settingslib.bluetooth.LocalBluetoothManager;
|
||||
import com.android.settingslib.search.SearchIndexableRaw;
|
||||
|
||||
import com.google.common.collect.ImmutableList;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Rule;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.mockito.Mock;
|
||||
import org.mockito.MockitoAnnotations;
|
||||
import org.robolectric.RobolectricTestRunner;
|
||||
import org.robolectric.annotation.Config;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
/** Tests for {@link AvailableHearingDevicePreferenceController} */
|
||||
@RunWith(RobolectricTestRunner.class)
|
||||
@Config(shadows = {ShadowBluetoothUtils.class})
|
||||
public class AvailableHearingDevicePreferenceControllerTest {
|
||||
@Rule
|
||||
public final SetFlagsRule mSetFlagsRule = new SetFlagsRule();
|
||||
|
||||
private static final String PREFERENCE_KEY = "preference_key";
|
||||
private static final String DEVICE_NAME = "device";
|
||||
|
||||
private Context mContext;
|
||||
private AvailableHearingDevicePreferenceController mAvailableHearingDevicePreferenceController;
|
||||
@Mock
|
||||
private AvailableHearingDeviceUpdater mAvailableHearingDeviceUpdater;
|
||||
@Mock
|
||||
private CachedBluetoothDeviceManager mCachedDeviceManager;
|
||||
@Mock
|
||||
private LocalBluetoothManager mLocalBluetoothManager;
|
||||
@Mock
|
||||
private CachedBluetoothDevice mCachedDevice;
|
||||
@Mock
|
||||
private BluetoothDevice mDevice;
|
||||
|
||||
|
||||
@Before
|
||||
public void setUp() {
|
||||
MockitoAnnotations.initMocks(this);
|
||||
|
||||
mContext = ApplicationProvider.getApplicationContext();
|
||||
ShadowBluetoothUtils.sLocalBluetoothManager = mLocalBluetoothManager;
|
||||
mLocalBluetoothManager = Utils.getLocalBtManager(mContext);
|
||||
when(mLocalBluetoothManager.getCachedDeviceManager()).thenReturn(mCachedDeviceManager);
|
||||
when(mCachedDevice.getDevice()).thenReturn(mDevice);
|
||||
when(mCachedDevice.getName()).thenReturn(DEVICE_NAME);
|
||||
when(mCachedDeviceManager.getCachedDevicesCopy()).thenReturn(
|
||||
ImmutableList.of(mCachedDevice));
|
||||
|
||||
mAvailableHearingDevicePreferenceController =
|
||||
new AvailableHearingDevicePreferenceController(mContext, PREFERENCE_KEY);
|
||||
mAvailableHearingDevicePreferenceController.init(mAvailableHearingDeviceUpdater);
|
||||
}
|
||||
|
||||
@Test
|
||||
@EnableFlags(Flags.FLAG_FIX_A11Y_SETTINGS_SEARCH)
|
||||
public void updateDynamicRawDataToIndex_isNotHearingAidDevice_deviceIsNotSearchable() {
|
||||
when(mDevice.getBondState()).thenReturn(BluetoothDevice.BOND_BONDED);
|
||||
when(mDevice.isConnected()).thenReturn(true);
|
||||
when(mCachedDevice.isHearingAidDevice()).thenReturn(false);
|
||||
List<SearchIndexableRaw> searchData = new ArrayList<>();
|
||||
|
||||
mAvailableHearingDevicePreferenceController.updateDynamicRawDataToIndex(searchData);
|
||||
|
||||
assertThat(searchData).isEmpty();
|
||||
}
|
||||
|
||||
@Test
|
||||
@EnableFlags(Flags.FLAG_FIX_A11Y_SETTINGS_SEARCH)
|
||||
public void updateDynamicRawDataToIndex_isHearingAidDevice_deviceIsSearchable() {
|
||||
when(mDevice.getBondState()).thenReturn(BluetoothDevice.BOND_BONDED);
|
||||
when(mDevice.isConnected()).thenReturn(true);
|
||||
when(mCachedDevice.isHearingAidDevice()).thenReturn(true);
|
||||
List<SearchIndexableRaw> searchData = new ArrayList<>();
|
||||
|
||||
mAvailableHearingDevicePreferenceController.updateDynamicRawDataToIndex(searchData);
|
||||
|
||||
assertThat(searchData).isNotEmpty();
|
||||
assertThat(searchData.get(0).key).contains(DEVICE_NAME);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,118 @@
|
||||
/*
|
||||
* Copyright (C) 2024 The Android Open Source Project
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package com.android.settings.accessibility;
|
||||
|
||||
import static com.google.common.truth.Truth.assertThat;
|
||||
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
import android.bluetooth.BluetoothDevice;
|
||||
import android.content.Context;
|
||||
import android.platform.test.annotations.EnableFlags;
|
||||
import android.platform.test.flag.junit.SetFlagsRule;
|
||||
|
||||
import androidx.test.core.app.ApplicationProvider;
|
||||
|
||||
import com.android.settings.bluetooth.Utils;
|
||||
import com.android.settings.testutils.shadow.ShadowBluetoothUtils;
|
||||
import com.android.settingslib.bluetooth.CachedBluetoothDevice;
|
||||
import com.android.settingslib.bluetooth.CachedBluetoothDeviceManager;
|
||||
import com.android.settingslib.bluetooth.LocalBluetoothManager;
|
||||
import com.android.settingslib.search.SearchIndexableRaw;
|
||||
|
||||
import com.google.common.collect.ImmutableList;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Rule;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.mockito.Mock;
|
||||
import org.mockito.MockitoAnnotations;
|
||||
import org.robolectric.RobolectricTestRunner;
|
||||
import org.robolectric.annotation.Config;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
/** Tests for {@link SavedHearingDevicePreferenceController} */
|
||||
@RunWith(RobolectricTestRunner.class)
|
||||
@Config(shadows = {ShadowBluetoothUtils.class})
|
||||
public class SavedHearingDevicePreferenceControllerTest {
|
||||
@Rule
|
||||
public final SetFlagsRule mSetFlagsRule = new SetFlagsRule();
|
||||
|
||||
private static final String PREFERENCE_KEY = "preference_key";
|
||||
private static final String DEVICE_NAME = "device";
|
||||
|
||||
private Context mContext;
|
||||
private SavedHearingDevicePreferenceController mSavedHearingDevicePreferenceController;
|
||||
@Mock
|
||||
private SavedHearingDeviceUpdater mSavedHearingDeviceUpdater;
|
||||
@Mock
|
||||
private CachedBluetoothDeviceManager mCachedDeviceManager;
|
||||
@Mock
|
||||
private LocalBluetoothManager mLocalBluetoothManager;
|
||||
@Mock
|
||||
private CachedBluetoothDevice mCachedDevice;
|
||||
@Mock
|
||||
private BluetoothDevice mDevice;
|
||||
|
||||
|
||||
@Before
|
||||
public void setUp() {
|
||||
MockitoAnnotations.initMocks(this);
|
||||
|
||||
mContext = ApplicationProvider.getApplicationContext();
|
||||
ShadowBluetoothUtils.sLocalBluetoothManager = mLocalBluetoothManager;
|
||||
mLocalBluetoothManager = Utils.getLocalBtManager(mContext);
|
||||
when(mLocalBluetoothManager.getCachedDeviceManager()).thenReturn(mCachedDeviceManager);
|
||||
when(mCachedDevice.getDevice()).thenReturn(mDevice);
|
||||
when(mCachedDevice.getName()).thenReturn(DEVICE_NAME);
|
||||
when(mCachedDeviceManager.getCachedDevicesCopy()).thenReturn(
|
||||
ImmutableList.of(mCachedDevice));
|
||||
|
||||
mSavedHearingDevicePreferenceController =
|
||||
new SavedHearingDevicePreferenceController(mContext, PREFERENCE_KEY);
|
||||
mSavedHearingDevicePreferenceController.init(mSavedHearingDeviceUpdater);
|
||||
}
|
||||
|
||||
@Test
|
||||
@EnableFlags(Flags.FLAG_FIX_A11Y_SETTINGS_SEARCH)
|
||||
public void updateDynamicRawDataToIndex_isNotHearingAidDevice_deviceIsNotSearchable() {
|
||||
when(mDevice.getBondState()).thenReturn(BluetoothDevice.BOND_BONDED);
|
||||
when(mDevice.isConnected()).thenReturn(false);
|
||||
when(mCachedDevice.isHearingAidDevice()).thenReturn(false);
|
||||
List<SearchIndexableRaw> searchData = new ArrayList<>();
|
||||
|
||||
mSavedHearingDevicePreferenceController.updateDynamicRawDataToIndex(searchData);
|
||||
|
||||
assertThat(searchData).isEmpty();
|
||||
}
|
||||
|
||||
@Test
|
||||
@EnableFlags(Flags.FLAG_FIX_A11Y_SETTINGS_SEARCH)
|
||||
public void updateDynamicRawDataToIndex_isHearingAidDevice_deviceIsSearchable() {
|
||||
when(mDevice.getBondState()).thenReturn(BluetoothDevice.BOND_BONDED);
|
||||
when(mDevice.isConnected()).thenReturn(false);
|
||||
when(mCachedDevice.isHearingAidDevice()).thenReturn(true);
|
||||
List<SearchIndexableRaw> searchData = new ArrayList<>();
|
||||
|
||||
mSavedHearingDevicePreferenceController.updateDynamicRawDataToIndex(searchData);
|
||||
|
||||
assertThat(searchData).isNotEmpty();
|
||||
assertThat(searchData.get(0).key).contains(DEVICE_NAME);
|
||||
}
|
||||
}
|
||||
@@ -19,10 +19,7 @@ package com.android.settings.inputmethod;
|
||||
import static com.google.common.truth.Truth.assertThat;
|
||||
|
||||
import android.content.Context;
|
||||
import android.os.Looper;
|
||||
|
||||
import androidx.preference.PreferenceManager;
|
||||
import androidx.preference.PreferenceScreen;
|
||||
import androidx.test.core.app.ApplicationProvider;
|
||||
import androidx.test.ext.junit.runners.AndroidJUnit4;
|
||||
|
||||
@@ -47,17 +44,6 @@ public class KeyboardSettingsFeatureProviderImplTest {
|
||||
assertThat(mFeatureProvider.supportsFirmwareUpdate()).isFalse();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void addFirmwareUpdateCategory_defaultValue_returnsFalse() {
|
||||
if (Looper.myLooper() == null) {
|
||||
Looper.prepare();
|
||||
}
|
||||
PreferenceManager preferenceManager = new PreferenceManager(mContext);
|
||||
PreferenceScreen screen = preferenceManager.createPreferenceScreen(mContext);
|
||||
|
||||
assertThat(mFeatureProvider.addFirmwareUpdateCategory(mContext, screen)).isFalse();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getActionKeyIcon_defaultValue_returnsNull() {
|
||||
assertThat(mFeatureProvider.getActionKeyIcon(mContext)).isNull();
|
||||
|
||||
Reference in New Issue
Block a user