Merge changes from topic "hearingAidsInT" into tm-dev
* changes: Add 'Live Caption' preference for hearing aids device in Device details page Update summary in Accessibility -> Hearing aids Header for hearing aids now listed in one summary
This commit is contained in:
@@ -66,6 +66,18 @@
|
|||||||
<PreferenceCategory
|
<PreferenceCategory
|
||||||
android:key="bluetooth_profiles"/>
|
android:key="bluetooth_profiles"/>
|
||||||
|
|
||||||
|
<PreferenceCategory
|
||||||
|
android:key="bluetooth_related_tools"
|
||||||
|
android:title="@string/bluetooth_screen_related">
|
||||||
|
<Preference
|
||||||
|
android:key="live_caption"
|
||||||
|
android:icon="@drawable/ic_live_caption"
|
||||||
|
android:persistent="false"
|
||||||
|
android:summary="@string/live_caption_summary"
|
||||||
|
android:title="@string/live_caption_title"
|
||||||
|
settings:controller="com.android.settings.accessibility.LiveCaptionPreferenceController"/>
|
||||||
|
</PreferenceCategory>
|
||||||
|
|
||||||
<com.android.settingslib.widget.FooterPreference
|
<com.android.settingslib.widget.FooterPreference
|
||||||
android:key="device_details_footer"
|
android:key="device_details_footer"
|
||||||
android:selectable="false"
|
android:selectable="false"
|
||||||
|
@@ -39,12 +39,13 @@ import com.android.settings.bluetooth.BluetoothDeviceDetailsFragment;
|
|||||||
import com.android.settings.core.BasePreferenceController;
|
import com.android.settings.core.BasePreferenceController;
|
||||||
import com.android.settings.core.SubSettingLauncher;
|
import com.android.settings.core.SubSettingLauncher;
|
||||||
import com.android.settingslib.bluetooth.CachedBluetoothDevice;
|
import com.android.settingslib.bluetooth.CachedBluetoothDevice;
|
||||||
|
import com.android.settingslib.bluetooth.CachedBluetoothDeviceManager;
|
||||||
|
import com.android.settingslib.bluetooth.HearingAidProfile;
|
||||||
import com.android.settingslib.bluetooth.LocalBluetoothManager;
|
import com.android.settingslib.bluetooth.LocalBluetoothManager;
|
||||||
import com.android.settingslib.core.lifecycle.LifecycleObserver;
|
import com.android.settingslib.core.lifecycle.LifecycleObserver;
|
||||||
import com.android.settingslib.core.lifecycle.events.OnStart;
|
import com.android.settingslib.core.lifecycle.events.OnStart;
|
||||||
import com.android.settingslib.core.lifecycle.events.OnStop;
|
import com.android.settingslib.core.lifecycle.events.OnStop;
|
||||||
|
|
||||||
import java.util.Iterator;
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.concurrent.ExecutionException;
|
import java.util.concurrent.ExecutionException;
|
||||||
import java.util.concurrent.FutureTask;
|
import java.util.concurrent.FutureTask;
|
||||||
@@ -82,15 +83,13 @@ public class AccessibilityHearingAidPreferenceController extends BasePreferenceC
|
|||||||
|
|
||||||
private final LocalBluetoothManager mLocalBluetoothManager;
|
private final LocalBluetoothManager mLocalBluetoothManager;
|
||||||
private final BluetoothAdapter mBluetoothAdapter;
|
private final BluetoothAdapter mBluetoothAdapter;
|
||||||
//cache value of supporting hearing aid or not
|
|
||||||
private boolean mHearingAidProfileSupported;
|
|
||||||
private FragmentManager mFragmentManager;
|
private FragmentManager mFragmentManager;
|
||||||
|
|
||||||
public AccessibilityHearingAidPreferenceController(Context context, String preferenceKey) {
|
public AccessibilityHearingAidPreferenceController(Context context, String preferenceKey) {
|
||||||
super(context, preferenceKey);
|
super(context, preferenceKey);
|
||||||
mLocalBluetoothManager = getLocalBluetoothManager();
|
mLocalBluetoothManager = getLocalBluetoothManager();
|
||||||
mBluetoothAdapter = BluetoothAdapter.getDefaultAdapter();
|
mBluetoothAdapter = BluetoothAdapter.getDefaultAdapter();
|
||||||
mHearingAidProfileSupported = isHearingAidProfileSupported();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -101,29 +100,25 @@ public class AccessibilityHearingAidPreferenceController extends BasePreferenceC
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int getAvailabilityStatus() {
|
public int getAvailabilityStatus() {
|
||||||
return mHearingAidProfileSupported ? AVAILABLE : UNSUPPORTED_ON_DEVICE;
|
return isHearingAidProfileSupported() ? AVAILABLE : UNSUPPORTED_ON_DEVICE;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onStart() {
|
public void onStart() {
|
||||||
if (mHearingAidProfileSupported) {
|
IntentFilter filter = new IntentFilter();
|
||||||
IntentFilter filter = new IntentFilter();
|
filter.addAction(BluetoothHearingAid.ACTION_CONNECTION_STATE_CHANGED);
|
||||||
filter.addAction(BluetoothHearingAid.ACTION_CONNECTION_STATE_CHANGED);
|
filter.addAction(BluetoothAdapter.ACTION_STATE_CHANGED);
|
||||||
filter.addAction(BluetoothAdapter.ACTION_STATE_CHANGED);
|
mContext.registerReceiver(mHearingAidChangedReceiver, filter);
|
||||||
mContext.registerReceiver(mHearingAidChangedReceiver, filter);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onStop() {
|
public void onStop() {
|
||||||
if (mHearingAidProfileSupported) {
|
mContext.unregisterReceiver(mHearingAidChangedReceiver);
|
||||||
mContext.unregisterReceiver(mHearingAidChangedReceiver);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean handlePreferenceTreeClick(Preference preference) {
|
public boolean handlePreferenceTreeClick(Preference preference) {
|
||||||
if (TextUtils.equals(preference.getKey(), getPreferenceKey())){
|
if (TextUtils.equals(preference.getKey(), getPreferenceKey())) {
|
||||||
final CachedBluetoothDevice device = getConnectedHearingAidDevice();
|
final CachedBluetoothDevice device = getConnectedHearingAidDevice();
|
||||||
if (device == null) {
|
if (device == null) {
|
||||||
launchHearingAidInstructionDialog();
|
launchHearingAidInstructionDialog();
|
||||||
@@ -141,7 +136,27 @@ public class AccessibilityHearingAidPreferenceController extends BasePreferenceC
|
|||||||
if (device == null) {
|
if (device == null) {
|
||||||
return mContext.getText(R.string.accessibility_hearingaid_not_connected_summary);
|
return mContext.getText(R.string.accessibility_hearingaid_not_connected_summary);
|
||||||
}
|
}
|
||||||
return device.getName();
|
|
||||||
|
final int connectedNum = getConnectedHearingAidDeviceNum();
|
||||||
|
final CharSequence name = device.getName();
|
||||||
|
final int side = device.getDeviceSide();
|
||||||
|
final CachedBluetoothDevice subDevice = device.getSubDevice();
|
||||||
|
if (connectedNum > 1) {
|
||||||
|
return mContext.getString(R.string.accessibility_hearingaid_more_device_summary, name);
|
||||||
|
}
|
||||||
|
if (subDevice != null && subDevice.isConnected()) {
|
||||||
|
return mContext.getString(
|
||||||
|
R.string.accessibility_hearingaid_left_and_right_side_device_summary, name);
|
||||||
|
}
|
||||||
|
if (side == HearingAidProfile.DeviceSide.SIDE_INVALID) {
|
||||||
|
return mContext.getString(
|
||||||
|
R.string.accessibility_hearingaid_active_device_summary, name);
|
||||||
|
}
|
||||||
|
return (side == HearingAidProfile.DeviceSide.SIDE_LEFT)
|
||||||
|
? mContext.getString(
|
||||||
|
R.string.accessibility_hearingaid_left_side_device_summary, name)
|
||||||
|
: mContext.getString(
|
||||||
|
R.string.accessibility_hearingaid_right_side_device_summary, name);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setFragmentManager(FragmentManager fragmentManager) {
|
public void setFragmentManager(FragmentManager fragmentManager) {
|
||||||
@@ -150,33 +165,44 @@ public class AccessibilityHearingAidPreferenceController extends BasePreferenceC
|
|||||||
|
|
||||||
@VisibleForTesting
|
@VisibleForTesting
|
||||||
CachedBluetoothDevice getConnectedHearingAidDevice() {
|
CachedBluetoothDevice getConnectedHearingAidDevice() {
|
||||||
if (!mHearingAidProfileSupported) {
|
if (!isHearingAidProfileSupported()) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
if (mBluetoothAdapter == null || !mBluetoothAdapter.isEnabled()) {
|
|
||||||
return null;
|
final CachedBluetoothDeviceManager deviceManager =
|
||||||
}
|
mLocalBluetoothManager.getCachedDeviceManager();
|
||||||
final List<BluetoothDevice> deviceList = mLocalBluetoothManager.getProfileManager()
|
final HearingAidProfile hearingAidProfile =
|
||||||
.getHearingAidProfile().getConnectedDevices();
|
mLocalBluetoothManager.getProfileManager().getHearingAidProfile();
|
||||||
final Iterator it = deviceList.iterator();
|
final List<BluetoothDevice> deviceList = hearingAidProfile.getConnectedDevices();
|
||||||
while (it.hasNext()) {
|
for (BluetoothDevice obj : deviceList) {
|
||||||
BluetoothDevice obj = (BluetoothDevice)it.next();
|
if (!deviceManager.isSubDevice(obj)) {
|
||||||
if (!mLocalBluetoothManager.getCachedDeviceManager().isSubDevice(obj)) {
|
return deviceManager.findDevice(obj);
|
||||||
return mLocalBluetoothManager.getCachedDeviceManager().findDevice(obj);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private int getConnectedHearingAidDeviceNum() {
|
||||||
|
if (!isHearingAidProfileSupported()) {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
final CachedBluetoothDeviceManager deviceManager =
|
||||||
|
mLocalBluetoothManager.getCachedDeviceManager();
|
||||||
|
final HearingAidProfile hearingAidProfile =
|
||||||
|
mLocalBluetoothManager.getProfileManager().getHearingAidProfile();
|
||||||
|
final List<BluetoothDevice> deviceList = hearingAidProfile.getConnectedDevices();
|
||||||
|
return (int) deviceList.stream()
|
||||||
|
.filter(device -> !deviceManager.isSubDevice(device))
|
||||||
|
.count();
|
||||||
|
}
|
||||||
|
|
||||||
private boolean isHearingAidProfileSupported() {
|
private boolean isHearingAidProfileSupported() {
|
||||||
if (mBluetoothAdapter == null || !mBluetoothAdapter.isEnabled()) {
|
if (mBluetoothAdapter == null || !mBluetoothAdapter.isEnabled()) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
final List<Integer> supportedList = mBluetoothAdapter.getSupportedProfiles();
|
final List<Integer> supportedList = mBluetoothAdapter.getSupportedProfiles();
|
||||||
if (supportedList.contains(BluetoothProfile.HEARING_AID)) {
|
return supportedList.contains(BluetoothProfile.HEARING_AID);
|
||||||
return true;
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private LocalBluetoothManager getLocalBluetoothManager() {
|
private LocalBluetoothManager getLocalBluetoothManager() {
|
||||||
|
@@ -75,10 +75,8 @@ public class BluetoothDetailsHeaderController extends BluetoothDetailsController
|
|||||||
if (TextUtils.isEmpty(summaryText)) {
|
if (TextUtils.isEmpty(summaryText)) {
|
||||||
// If first summary is unavailable, not to show second summary.
|
// If first summary is unavailable, not to show second summary.
|
||||||
mHeaderController.setSecondSummary((CharSequence)null);
|
mHeaderController.setSecondSummary((CharSequence)null);
|
||||||
} else {
|
|
||||||
// If both the hearing aids are connected, two device status should be shown.
|
|
||||||
mHeaderController.setSecondSummary(mDeviceManager.getSubDeviceSummary(mCachedDevice));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
mHeaderController.setLabel(mCachedDevice.getName());
|
mHeaderController.setLabel(mCachedDevice.getName());
|
||||||
mHeaderController.setIcon(pair.first);
|
mHeaderController.setIcon(pair.first);
|
||||||
mHeaderController.setIconContentDescription(pair.second);
|
mHeaderController.setIconContentDescription(pair.second);
|
||||||
|
@@ -0,0 +1,72 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (C) 2022 The Android Open Source Project
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package com.android.settings.bluetooth;
|
||||||
|
|
||||||
|
|
||||||
|
import android.content.Context;
|
||||||
|
|
||||||
|
import androidx.preference.Preference;
|
||||||
|
import androidx.preference.PreferenceCategory;
|
||||||
|
import androidx.preference.PreferenceFragmentCompat;
|
||||||
|
import androidx.preference.PreferenceScreen;
|
||||||
|
|
||||||
|
import com.android.settingslib.bluetooth.CachedBluetoothDevice;
|
||||||
|
import com.android.settingslib.core.lifecycle.Lifecycle;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This class adds related tools preference.
|
||||||
|
*/
|
||||||
|
public class BluetoothDetailsRelatedToolsController extends BluetoothDetailsController{
|
||||||
|
private static final String KEY_RELATED_TOOLS_GROUP = "bluetooth_related_tools";
|
||||||
|
private static final String KEY_LIVE_CAPTION = "live_caption";
|
||||||
|
|
||||||
|
public BluetoothDetailsRelatedToolsController(Context context,
|
||||||
|
PreferenceFragmentCompat fragment, CachedBluetoothDevice device, Lifecycle lifecycle) {
|
||||||
|
super(context, fragment, device, lifecycle);
|
||||||
|
lifecycle.addObserver(this);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean isAvailable() {
|
||||||
|
return mCachedDevice.isHearingAidDevice();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void init(PreferenceScreen screen) {
|
||||||
|
if (!mCachedDevice.isHearingAidDevice()) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
final PreferenceCategory preferenceCategory = screen.findPreference(getPreferenceKey());
|
||||||
|
final Preference liveCaptionPreference = screen.findPreference(KEY_LIVE_CAPTION);
|
||||||
|
if (!liveCaptionPreference.isVisible()) {
|
||||||
|
preferenceCategory.removePreference(liveCaptionPreference);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (preferenceCategory.getPreferenceCount() == 0) {
|
||||||
|
screen.removePreference(preferenceCategory);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void refresh() {}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getPreferenceKey() {
|
||||||
|
return KEY_RELATED_TOOLS_GROUP;
|
||||||
|
}
|
||||||
|
}
|
@@ -246,6 +246,8 @@ public class BluetoothDeviceDetailsFragment extends RestrictedDashboardFragment
|
|||||||
mCachedDevice, lifecycle));
|
mCachedDevice, lifecycle));
|
||||||
controllers.add(new BluetoothDetailsMacAddressController(context, this, mCachedDevice,
|
controllers.add(new BluetoothDetailsMacAddressController(context, this, mCachedDevice,
|
||||||
lifecycle));
|
lifecycle));
|
||||||
|
controllers.add(new BluetoothDetailsRelatedToolsController(context, this, mCachedDevice,
|
||||||
|
lifecycle));
|
||||||
}
|
}
|
||||||
return controllers;
|
return controllers;
|
||||||
}
|
}
|
||||||
|
@@ -18,9 +18,7 @@ package com.android.settings.accessibility;
|
|||||||
|
|
||||||
import static com.google.common.truth.Truth.assertThat;
|
import static com.google.common.truth.Truth.assertThat;
|
||||||
|
|
||||||
import static org.mockito.ArgumentMatchers.any;
|
|
||||||
import static org.mockito.Mockito.doNothing;
|
import static org.mockito.Mockito.doNothing;
|
||||||
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;
|
||||||
@@ -48,7 +46,6 @@ import com.android.settingslib.bluetooth.LocalBluetoothProfileManager;
|
|||||||
|
|
||||||
import org.junit.After;
|
import org.junit.After;
|
||||||
import org.junit.Before;
|
import org.junit.Before;
|
||||||
import org.junit.Ignore;
|
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
import org.junit.runner.RunWith;
|
import org.junit.runner.RunWith;
|
||||||
import org.mockito.Mock;
|
import org.mockito.Mock;
|
||||||
@@ -63,7 +60,6 @@ import java.util.ArrayList;
|
|||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
@RunWith(RobolectricTestRunner.class)
|
@RunWith(RobolectricTestRunner.class)
|
||||||
@Ignore
|
|
||||||
@Config(shadows = {ShadowBluetoothAdapter.class, ShadowBluetoothUtils.class})
|
@Config(shadows = {ShadowBluetoothAdapter.class, ShadowBluetoothUtils.class})
|
||||||
public class AccessibilityHearingAidPreferenceControllerTest {
|
public class AccessibilityHearingAidPreferenceControllerTest {
|
||||||
private static final String TEST_DEVICE_ADDRESS = "00:A1:A1:A1:A1:A1";
|
private static final String TEST_DEVICE_ADDRESS = "00:A1:A1:A1:A1:A1";
|
||||||
@@ -82,6 +78,8 @@ public class AccessibilityHearingAidPreferenceControllerTest {
|
|||||||
@Mock
|
@Mock
|
||||||
private CachedBluetoothDevice mCachedBluetoothDevice;
|
private CachedBluetoothDevice mCachedBluetoothDevice;
|
||||||
@Mock
|
@Mock
|
||||||
|
private CachedBluetoothDevice mCachedSubBluetoothDevice;
|
||||||
|
@Mock
|
||||||
private CachedBluetoothDeviceManager mCachedDeviceManager;
|
private CachedBluetoothDeviceManager mCachedDeviceManager;
|
||||||
@Mock
|
@Mock
|
||||||
private LocalBluetoothManager mLocalBluetoothManager;
|
private LocalBluetoothManager mLocalBluetoothManager;
|
||||||
@@ -111,18 +109,54 @@ public class AccessibilityHearingAidPreferenceControllerTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void onHearingAidStateChanged_connected_updateHearingAidSummary() {
|
public void getSummary_connectedHearingAidRightSide_connectedRightSideSummary() {
|
||||||
|
when(mCachedBluetoothDevice.getDeviceSide()).thenReturn(
|
||||||
|
HearingAidProfile.DeviceSide.SIDE_RIGHT);
|
||||||
when(mHearingAidProfile.getConnectedDevices()).thenReturn(generateHearingAidDeviceList());
|
when(mHearingAidProfile.getConnectedDevices()).thenReturn(generateHearingAidDeviceList());
|
||||||
mPreferenceController.onStart();
|
mPreferenceController.onStart();
|
||||||
Intent intent = new Intent(BluetoothHearingAid.ACTION_CONNECTION_STATE_CHANGED);
|
Intent intent = new Intent(BluetoothHearingAid.ACTION_CONNECTION_STATE_CHANGED);
|
||||||
intent.putExtra(BluetoothHearingAid.EXTRA_STATE, BluetoothHearingAid.STATE_CONNECTED);
|
intent.putExtra(BluetoothHearingAid.EXTRA_STATE, BluetoothHearingAid.STATE_CONNECTED);
|
||||||
sendIntent(intent);
|
sendIntent(intent);
|
||||||
|
|
||||||
assertThat(mHearingAidPreference.getSummary()).isEqualTo(TEST_DEVICE_NAME);
|
assertThat(mHearingAidPreference.getSummary().toString().contentEquals(
|
||||||
|
"TEST_HEARING_AID_BT_DEVICE_NAME, right only")).isTrue();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void onHearingAidStateChanged_disconnected_updateHearingAidSummary() {
|
public void getSummary_connectedHearingAidBothSide_connectedBothSideSummary() {
|
||||||
|
when(mCachedBluetoothDevice.getDeviceSide()).thenReturn(
|
||||||
|
HearingAidProfile.DeviceSide.SIDE_LEFT);
|
||||||
|
when(mCachedSubBluetoothDevice.isConnected()).thenReturn(true);
|
||||||
|
when(mCachedBluetoothDevice.getSubDevice()).thenReturn(mCachedSubBluetoothDevice);
|
||||||
|
when(mHearingAidProfile.getConnectedDevices()).thenReturn(generateHearingAidDeviceList());
|
||||||
|
mPreferenceController.onStart();
|
||||||
|
Intent intent = new Intent(BluetoothHearingAid.ACTION_CONNECTION_STATE_CHANGED);
|
||||||
|
intent.putExtra(BluetoothHearingAid.EXTRA_STATE, BluetoothHearingAid.STATE_CONNECTED);
|
||||||
|
sendIntent(intent);
|
||||||
|
|
||||||
|
assertThat(mHearingAidPreference.getSummary().toString().contentEquals(
|
||||||
|
"TEST_HEARING_AID_BT_DEVICE_NAME, left and right")).isTrue();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void getSummary_connectedMultipleHearingAids_connectedBothSideSummary() {
|
||||||
|
when(mCachedBluetoothDevice.getDeviceSide()).thenReturn(
|
||||||
|
HearingAidProfile.DeviceSide.SIDE_LEFT);
|
||||||
|
when(mCachedSubBluetoothDevice.isConnected()).thenReturn(true);
|
||||||
|
when(mCachedBluetoothDevice.getSubDevice()).thenReturn(mCachedSubBluetoothDevice);
|
||||||
|
when(mHearingAidProfile.getConnectedDevices()).thenReturn(
|
||||||
|
generateMultipleHearingAidDeviceList());
|
||||||
|
mPreferenceController.onStart();
|
||||||
|
Intent intent = new Intent(BluetoothHearingAid.ACTION_CONNECTION_STATE_CHANGED);
|
||||||
|
intent.putExtra(BluetoothHearingAid.EXTRA_STATE, BluetoothHearingAid.STATE_CONNECTED);
|
||||||
|
sendIntent(intent);
|
||||||
|
|
||||||
|
assertThat(mHearingAidPreference.getSummary().toString().contentEquals(
|
||||||
|
"TEST_HEARING_AID_BT_DEVICE_NAME +1 more")).isTrue();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void getSummary_disconnectedHearingAid_disconnectedSummary() {
|
||||||
mPreferenceController.onStart();
|
mPreferenceController.onStart();
|
||||||
Intent intent = new Intent(BluetoothHearingAid.ACTION_CONNECTION_STATE_CHANGED);
|
Intent intent = new Intent(BluetoothHearingAid.ACTION_CONNECTION_STATE_CHANGED);
|
||||||
intent.putExtra(BluetoothHearingAid.EXTRA_STATE, BluetoothHearingAid.STATE_DISCONNECTED);
|
intent.putExtra(BluetoothHearingAid.EXTRA_STATE, BluetoothHearingAid.STATE_DISCONNECTED);
|
||||||
@@ -133,7 +167,7 @@ public class AccessibilityHearingAidPreferenceControllerTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void onBluetoothStateChanged_bluetoothOff_updateHearingAidSummary() {
|
public void getSummary_bluetoothOff_disconnectedSummary() {
|
||||||
mPreferenceController.onStart();
|
mPreferenceController.onStart();
|
||||||
Intent intent = new Intent(BluetoothAdapter.ACTION_STATE_CHANGED);
|
Intent intent = new Intent(BluetoothAdapter.ACTION_STATE_CHANGED);
|
||||||
intent.putExtra(BluetoothAdapter.EXTRA_STATE, BluetoothAdapter.STATE_OFF);
|
intent.putExtra(BluetoothAdapter.EXTRA_STATE, BluetoothAdapter.STATE_OFF);
|
||||||
@@ -168,19 +202,14 @@ public class AccessibilityHearingAidPreferenceControllerTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void onNotSupportHearingAidProfile_doNotDoReceiverOperation() {
|
public void onNotSupportHearingAidProfile_isNotAvailable() {
|
||||||
//clear bluetooth supported profile
|
//clear bluetooth supported profile
|
||||||
mShadowBluetoothAdapter.clearSupportedProfiles();
|
mShadowBluetoothAdapter.clearSupportedProfiles();
|
||||||
mPreferenceController = new AccessibilityHearingAidPreferenceController(mContext,
|
mPreferenceController = new AccessibilityHearingAidPreferenceController(mContext,
|
||||||
HEARING_AID_PREFERENCE);
|
HEARING_AID_PREFERENCE);
|
||||||
mPreferenceController.setPreference(mHearingAidPreference);
|
mPreferenceController.setPreference(mHearingAidPreference);
|
||||||
//not call registerReceiver()
|
|
||||||
mPreferenceController.onStart();
|
|
||||||
verify(mContext, never()).registerReceiver(any(), any());
|
|
||||||
|
|
||||||
//not call unregisterReceiver()
|
assertThat(mPreferenceController.isAvailable()).isFalse();
|
||||||
mPreferenceController.onStop();
|
|
||||||
verify(mContext, never()).unregisterReceiver(any());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@@ -224,4 +253,11 @@ public class AccessibilityHearingAidPreferenceControllerTest {
|
|||||||
deviceList.add(mBluetoothDevice);
|
deviceList.add(mBluetoothDevice);
|
||||||
return deviceList;
|
return deviceList;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private List<BluetoothDevice> generateMultipleHearingAidDeviceList() {
|
||||||
|
final List<BluetoothDevice> deviceList = new ArrayList<>(2);
|
||||||
|
deviceList.add(mBluetoothDevice);
|
||||||
|
deviceList.add(mBluetoothDevice);
|
||||||
|
return deviceList;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@@ -0,0 +1,52 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (C) 2022 The Android Open Source Project
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package com.android.settings.bluetooth;
|
||||||
|
|
||||||
|
import static com.google.common.truth.Truth.assertThat;
|
||||||
|
|
||||||
|
import static org.mockito.Mockito.when;
|
||||||
|
|
||||||
|
import org.junit.Test;
|
||||||
|
import org.junit.runner.RunWith;
|
||||||
|
import org.robolectric.RobolectricTestRunner;
|
||||||
|
|
||||||
|
/** Tests for {@link BluetoothDetailsRelatedToolsController}. */
|
||||||
|
@RunWith(RobolectricTestRunner.class)
|
||||||
|
public class BluetoothDetailsRelatedToolsControllerTest extends BluetoothDetailsControllerTestBase {
|
||||||
|
private BluetoothDetailsRelatedToolsController mController;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void setUp() {
|
||||||
|
super.setUp();
|
||||||
|
mController = new BluetoothDetailsRelatedToolsController(mContext, mFragment, mCachedDevice,
|
||||||
|
mLifecycle);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void isAvailable_isHearingAidDevice_available() {
|
||||||
|
when(mCachedDevice.isHearingAidDevice()).thenReturn(true);
|
||||||
|
|
||||||
|
assertThat(mController.isAvailable()).isTrue();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void isAvailable_notHearingAidDevice_notAvailable() {
|
||||||
|
when(mCachedDevice.isHearingAidDevice()).thenReturn(false);
|
||||||
|
|
||||||
|
assertThat(mController.isAvailable()).isFalse();
|
||||||
|
}
|
||||||
|
}
|
Reference in New Issue
Block a user