Merge changes from topic "hearingAidsInT" into tm-dev am: c3bbb709b9
Original change: https://googleplex-android-review.googlesource.com/c/platform/packages/apps/Settings/+/17321711 Change-Id: Ieb1b469f29429cb1f542b03fcdced951f72aad9c Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
This commit is contained in:
@@ -18,9 +18,7 @@ package com.android.settings.accessibility;
|
||||
|
||||
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.never;
|
||||
import static org.mockito.Mockito.spy;
|
||||
import static org.mockito.Mockito.verify;
|
||||
import static org.mockito.Mockito.when;
|
||||
@@ -48,7 +46,6 @@ import com.android.settingslib.bluetooth.LocalBluetoothProfileManager;
|
||||
|
||||
import org.junit.After;
|
||||
import org.junit.Before;
|
||||
import org.junit.Ignore;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.mockito.Mock;
|
||||
@@ -63,7 +60,6 @@ import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
@RunWith(RobolectricTestRunner.class)
|
||||
@Ignore
|
||||
@Config(shadows = {ShadowBluetoothAdapter.class, ShadowBluetoothUtils.class})
|
||||
public class AccessibilityHearingAidPreferenceControllerTest {
|
||||
private static final String TEST_DEVICE_ADDRESS = "00:A1:A1:A1:A1:A1";
|
||||
@@ -82,6 +78,8 @@ public class AccessibilityHearingAidPreferenceControllerTest {
|
||||
@Mock
|
||||
private CachedBluetoothDevice mCachedBluetoothDevice;
|
||||
@Mock
|
||||
private CachedBluetoothDevice mCachedSubBluetoothDevice;
|
||||
@Mock
|
||||
private CachedBluetoothDeviceManager mCachedDeviceManager;
|
||||
@Mock
|
||||
private LocalBluetoothManager mLocalBluetoothManager;
|
||||
@@ -111,18 +109,54 @@ public class AccessibilityHearingAidPreferenceControllerTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void onHearingAidStateChanged_connected_updateHearingAidSummary() {
|
||||
public void getSummary_connectedHearingAidRightSide_connectedRightSideSummary() {
|
||||
when(mCachedBluetoothDevice.getDeviceSide()).thenReturn(
|
||||
HearingAidProfile.DeviceSide.SIDE_RIGHT);
|
||||
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()).isEqualTo(TEST_DEVICE_NAME);
|
||||
assertThat(mHearingAidPreference.getSummary().toString().contentEquals(
|
||||
"TEST_HEARING_AID_BT_DEVICE_NAME, right only")).isTrue();
|
||||
}
|
||||
|
||||
@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();
|
||||
Intent intent = new Intent(BluetoothHearingAid.ACTION_CONNECTION_STATE_CHANGED);
|
||||
intent.putExtra(BluetoothHearingAid.EXTRA_STATE, BluetoothHearingAid.STATE_DISCONNECTED);
|
||||
@@ -133,7 +167,7 @@ public class AccessibilityHearingAidPreferenceControllerTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void onBluetoothStateChanged_bluetoothOff_updateHearingAidSummary() {
|
||||
public void getSummary_bluetoothOff_disconnectedSummary() {
|
||||
mPreferenceController.onStart();
|
||||
Intent intent = new Intent(BluetoothAdapter.ACTION_STATE_CHANGED);
|
||||
intent.putExtra(BluetoothAdapter.EXTRA_STATE, BluetoothAdapter.STATE_OFF);
|
||||
@@ -168,19 +202,14 @@ public class AccessibilityHearingAidPreferenceControllerTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void onNotSupportHearingAidProfile_doNotDoReceiverOperation() {
|
||||
public void onNotSupportHearingAidProfile_isNotAvailable() {
|
||||
//clear bluetooth supported profile
|
||||
mShadowBluetoothAdapter.clearSupportedProfiles();
|
||||
mPreferenceController = new AccessibilityHearingAidPreferenceController(mContext,
|
||||
HEARING_AID_PREFERENCE);
|
||||
mPreferenceController.setPreference(mHearingAidPreference);
|
||||
//not call registerReceiver()
|
||||
mPreferenceController.onStart();
|
||||
verify(mContext, never()).registerReceiver(any(), any());
|
||||
|
||||
//not call unregisterReceiver()
|
||||
mPreferenceController.onStop();
|
||||
verify(mContext, never()).unregisterReceiver(any());
|
||||
assertThat(mPreferenceController.isAvailable()).isFalse();
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -224,4 +253,11 @@ public class AccessibilityHearingAidPreferenceControllerTest {
|
||||
deviceList.add(mBluetoothDevice);
|
||||
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