Merge changes If6c3b2f3,I8dafefbb
* changes: Fix 'Hearing aids' of Accessibility page didn't display connected info promptly when mobile restart Fix after dis/reconnect HA, DUT will request to re-pair one side of HA
This commit is contained in:
@@ -28,7 +28,6 @@ import android.app.Activity;
|
||||
import android.bluetooth.BluetoothAdapter;
|
||||
import android.bluetooth.BluetoothDevice;
|
||||
import android.bluetooth.BluetoothHearingAid;
|
||||
import android.bluetooth.BluetoothManager;
|
||||
import android.bluetooth.BluetoothProfile;
|
||||
import android.content.BroadcastReceiver;
|
||||
import android.content.Intent;
|
||||
@@ -74,7 +73,6 @@ public class AccessibilityHearingAidPreferenceControllerTest {
|
||||
|
||||
private BluetoothAdapter mBluetoothAdapter;
|
||||
private ShadowBluetoothAdapter mShadowBluetoothAdapter;
|
||||
private BluetoothManager mBluetoothManager;
|
||||
private BluetoothDevice mBluetoothDevice;
|
||||
private Activity mContext;
|
||||
private Preference mHearingAidPreference;
|
||||
@@ -101,8 +99,8 @@ public class AccessibilityHearingAidPreferenceControllerTest {
|
||||
MockitoAnnotations.initMocks(this);
|
||||
mShadowApplication = ShadowApplication.getInstance();
|
||||
mContext = spy(Robolectric.setupActivity(Activity.class));
|
||||
setupBluetoothEnvironment();
|
||||
setupHearingAidEnvironment();
|
||||
setupEnvironment();
|
||||
|
||||
mHearingAidPreference = new Preference(mContext);
|
||||
mHearingAidPreference.setKey(HEARING_AID_PREFERENCE);
|
||||
mPreferenceController = new AccessibilityHearingAidPreferenceController(mContext,
|
||||
@@ -247,25 +245,39 @@ public class AccessibilityHearingAidPreferenceControllerTest {
|
||||
assertThat(dialog.isShowing()).isTrue();
|
||||
}
|
||||
|
||||
private void setupBluetoothEnvironment() {
|
||||
@Test
|
||||
public void onServiceConnected_updateSummary() {
|
||||
mPreferenceController.onStart();
|
||||
when(mCachedBluetoothDevice.isConnectedHearingAidDevice()).thenReturn(true);
|
||||
when(mCachedBluetoothDevice.getDeviceMode()).thenReturn(
|
||||
HearingAidProfile.DeviceMode.MODE_BINAURAL);
|
||||
when(mCachedBluetoothDevice.getDeviceSide()).thenReturn(
|
||||
HearingAidProfile.DeviceSide.SIDE_LEFT);
|
||||
when(mHearingAidProfile.getConnectedDevices()).thenReturn(generateHearingAidDeviceList());
|
||||
|
||||
mPreferenceController.onServiceConnected();
|
||||
|
||||
assertThat(mHearingAidPreference.getSummary().toString()).isEqualTo(
|
||||
"TEST_HEARING_AID_BT_DEVICE_NAME, left only");
|
||||
}
|
||||
|
||||
private void setupEnvironment() {
|
||||
ShadowBluetoothUtils.sLocalBluetoothManager = mLocalBluetoothManager;
|
||||
mLocalBluetoothManager = Utils.getLocalBtManager(mContext);
|
||||
mBluetoothManager = mContext.getSystemService(BluetoothManager.class);
|
||||
mBluetoothAdapter = mBluetoothManager.getAdapter();
|
||||
mBluetoothAdapter = BluetoothAdapter.getDefaultAdapter();
|
||||
mShadowBluetoothAdapter = Shadow.extract(mBluetoothAdapter);
|
||||
mShadowBluetoothAdapter.addSupportedProfiles(BluetoothProfile.HEARING_AID);
|
||||
mBluetoothDevice = mBluetoothAdapter.getRemoteDevice(TEST_DEVICE_ADDRESS);
|
||||
mBluetoothAdapter.enable();
|
||||
|
||||
doReturn(mEventManager).when(mLocalBluetoothManager).getEventManager();
|
||||
when(mLocalBluetoothManager.getCachedDeviceManager()).thenReturn(mCachedDeviceManager);
|
||||
when(mLocalBluetoothManager.getProfileManager()).thenReturn(mLocalBluetoothProfileManager);
|
||||
when(mLocalBluetoothProfileManager.getHearingAidProfile()).thenReturn(mHearingAidProfile);
|
||||
doReturn(mEventManager).when(mLocalBluetoothManager).getEventManager();
|
||||
}
|
||||
|
||||
private void setupHearingAidEnvironment() {
|
||||
mBluetoothAdapter = BluetoothAdapter.getDefaultAdapter();
|
||||
mShadowBluetoothAdapter = Shadow.extract(mBluetoothAdapter);
|
||||
mBluetoothDevice = mBluetoothAdapter.getRemoteDevice(TEST_DEVICE_ADDRESS);
|
||||
mBluetoothAdapter.enable();
|
||||
mShadowBluetoothAdapter.addSupportedProfiles(BluetoothProfile.HEARING_AID);
|
||||
when(mCachedDeviceManager.findDevice(mBluetoothDevice)).thenReturn(mCachedBluetoothDevice);
|
||||
when(mCachedBluetoothDevice.getAddress()).thenReturn(TEST_DEVICE_ADDRESS);
|
||||
when(mCachedBluetoothDevice.getName()).thenReturn(TEST_DEVICE_NAME);
|
||||
when(mHearingAidProfile.isProfileReady()).thenReturn(true);
|
||||
}
|
||||
|
||||
private void sendIntent(Intent intent) {
|
||||
|
@@ -18,24 +18,38 @@ package com.android.settings.accessibility;
|
||||
|
||||
import static com.google.common.truth.Truth.assertThat;
|
||||
|
||||
import static org.mockito.Mockito.doReturn;
|
||||
import static org.mockito.Mockito.spy;
|
||||
import static org.mockito.Mockito.verify;
|
||||
import static org.mockito.Mockito.when;
|
||||
import static org.robolectric.Shadows.shadowOf;
|
||||
|
||||
import android.app.settings.SettingsEnums;
|
||||
import android.bluetooth.BluetoothAdapter;
|
||||
import android.bluetooth.BluetoothDevice;
|
||||
import android.bluetooth.BluetoothProfile;
|
||||
import android.content.Context;
|
||||
import android.content.DialogInterface;
|
||||
import android.content.Intent;
|
||||
import android.os.Bundle;
|
||||
|
||||
import androidx.appcompat.app.AlertDialog;
|
||||
import androidx.fragment.app.FragmentActivity;
|
||||
import androidx.fragment.app.FragmentManager;
|
||||
import androidx.test.core.app.ApplicationProvider;
|
||||
|
||||
import com.android.settings.R;
|
||||
import com.android.settings.SettingsActivity;
|
||||
import com.android.settings.bluetooth.BluetoothPairingDetail;
|
||||
import com.android.settings.bluetooth.HearingAidPairingDialogFragment;
|
||||
import com.android.settings.bluetooth.Utils;
|
||||
import com.android.settings.testutils.shadow.ShadowAlertDialogCompat;
|
||||
import com.android.settings.testutils.shadow.ShadowBluetoothAdapter;
|
||||
import com.android.settings.testutils.shadow.ShadowBluetoothUtils;
|
||||
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 org.junit.Before;
|
||||
import org.junit.Rule;
|
||||
@@ -47,39 +61,57 @@ import org.mockito.junit.MockitoRule;
|
||||
import org.robolectric.Robolectric;
|
||||
import org.robolectric.RobolectricTestRunner;
|
||||
import org.robolectric.annotation.Config;
|
||||
import org.robolectric.shadow.api.Shadow;
|
||||
|
||||
/** Tests for {@link HearingAidPairingDialogFragment}. */
|
||||
@RunWith(RobolectricTestRunner.class)
|
||||
@Config(shadows = ShadowAlertDialogCompat.class)
|
||||
@Config(shadows = {ShadowAlertDialogCompat.class, ShadowBluetoothAdapter.class,
|
||||
ShadowBluetoothUtils.class})
|
||||
public class HearingAidPairingDialogFragmentTest {
|
||||
|
||||
@Rule
|
||||
public final MockitoRule mockito = MockitoJUnit.rule();
|
||||
|
||||
private static final String KEY_CACHED_DEVICE_SIDE = "cached_device_side";
|
||||
private static final String TEST_DEVICE_ADDRESS = "00:A1:A1:A1:A1:A1";
|
||||
|
||||
private final Context mContext = ApplicationProvider.getApplicationContext();
|
||||
@Mock
|
||||
private CachedBluetoothDevice mCachedBluetoothDevice;
|
||||
@Mock
|
||||
private CachedBluetoothDevice mCachedSubBluetoothDevice;
|
||||
@Mock
|
||||
private LocalBluetoothManager mLocalBluetoothManager;
|
||||
@Mock
|
||||
private CachedBluetoothDeviceManager mCachedDeviceManager;
|
||||
private BluetoothAdapter mBluetoothAdapter;
|
||||
private FragmentActivity mActivity;
|
||||
private HearingAidPairingDialogFragment mFragment;
|
||||
private ShadowBluetoothAdapter mShadowBluetoothAdapter;
|
||||
private BluetoothDevice mBluetoothDevice;
|
||||
private FragmentManager mFragmentManager;
|
||||
|
||||
@Before
|
||||
public void setUp() {
|
||||
mFragment = spy(HearingAidPairingDialogFragment.newInstance(mCachedBluetoothDevice));
|
||||
setupEnvironment();
|
||||
mFragment = spy(HearingAidPairingDialogFragment.newInstance(TEST_DEVICE_ADDRESS));
|
||||
mActivity = Robolectric.setupActivity(FragmentActivity.class);
|
||||
mFragmentManager = mActivity.getSupportFragmentManager();
|
||||
when(mFragment.getActivity()).thenReturn(mActivity);
|
||||
doReturn(mFragmentManager).when(mFragment).getParentFragmentManager();
|
||||
mFragment.onAttach(mContext);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void newInstance_deviceSideRight_argumentSideRight() {
|
||||
when(mCachedBluetoothDevice.getDeviceSide()).thenReturn(
|
||||
HearingAidProfile.DeviceSide.SIDE_RIGHT);
|
||||
final AlertDialog dialog = (AlertDialog) mFragment.onCreateDialog(Bundle.EMPTY);
|
||||
dialog.show();
|
||||
|
||||
mFragment = HearingAidPairingDialogFragment.newInstance(mCachedBluetoothDevice);
|
||||
|
||||
final Bundle bundle = mFragment.getArguments();
|
||||
assertThat(bundle.getInt(KEY_CACHED_DEVICE_SIDE)).isEqualTo(
|
||||
HearingAidProfile.DeviceSide.SIDE_RIGHT);
|
||||
final String pairLeftString = mContext.getText(
|
||||
R.string.bluetooth_pair_other_ear_dialog_left_ear_positive_button).toString();
|
||||
assertThat(dialog.getButton(
|
||||
DialogInterface.BUTTON_POSITIVE).getText().toString()).isEqualTo(pairLeftString);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -109,4 +141,26 @@ public class HearingAidPairingDialogFragmentTest {
|
||||
assertThat(mFragment.getMetricsCategory()).isEqualTo(
|
||||
SettingsEnums.DIALOG_ACCESSIBILITY_HEARING_AID_PAIR_ANOTHER);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void onDeviceAttributesChanged_subHearingAidDeviceConnected_dialogDismiss() {
|
||||
when(mCachedSubBluetoothDevice.isConnectedHearingAidDevice()).thenReturn(true);
|
||||
when(mCachedBluetoothDevice.getSubDevice()).thenReturn(mCachedSubBluetoothDevice);
|
||||
|
||||
mFragment.onDeviceAttributesChanged();
|
||||
|
||||
verify(mFragment).dismiss();
|
||||
}
|
||||
|
||||
private void setupEnvironment() {
|
||||
ShadowBluetoothUtils.sLocalBluetoothManager = mLocalBluetoothManager;
|
||||
mBluetoothAdapter = BluetoothAdapter.getDefaultAdapter();
|
||||
mLocalBluetoothManager = Utils.getLocalBtManager(mContext);
|
||||
mShadowBluetoothAdapter = Shadow.extract(mBluetoothAdapter);
|
||||
mBluetoothDevice = mBluetoothAdapter.getRemoteDevice(TEST_DEVICE_ADDRESS);
|
||||
mShadowBluetoothAdapter.addSupportedProfiles(BluetoothProfile.HEARING_AID);
|
||||
when(mLocalBluetoothManager.getCachedDeviceManager()).thenReturn(mCachedDeviceManager);
|
||||
when(mCachedDeviceManager.findDevice(mBluetoothDevice)).thenReturn(mCachedBluetoothDevice);
|
||||
when(mCachedBluetoothDevice.getAddress()).thenReturn(TEST_DEVICE_ADDRESS);
|
||||
}
|
||||
}
|
||||
|
@@ -20,13 +20,24 @@ import static com.google.common.truth.Truth.assertThat;
|
||||
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
import android.bluetooth.BluetoothAdapter;
|
||||
import android.bluetooth.BluetoothDevice;
|
||||
import android.bluetooth.BluetoothProfile;
|
||||
import android.content.Context;
|
||||
|
||||
import androidx.appcompat.app.AlertDialog;
|
||||
import androidx.fragment.app.FragmentActivity;
|
||||
import androidx.fragment.app.FragmentManager;
|
||||
import androidx.test.core.app.ApplicationProvider;
|
||||
|
||||
import com.android.settings.bluetooth.Utils;
|
||||
import com.android.settings.testutils.shadow.ShadowAlertDialogCompat;
|
||||
import com.android.settings.testutils.shadow.ShadowBluetoothAdapter;
|
||||
import com.android.settings.testutils.shadow.ShadowBluetoothUtils;
|
||||
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 org.junit.Before;
|
||||
import org.junit.Rule;
|
||||
@@ -38,27 +49,40 @@ import org.mockito.junit.MockitoRule;
|
||||
import org.robolectric.Robolectric;
|
||||
import org.robolectric.RobolectricTestRunner;
|
||||
import org.robolectric.annotation.Config;
|
||||
import org.robolectric.shadow.api.Shadow;
|
||||
|
||||
/** Tests for {@link HearingAidUtils}. */
|
||||
@RunWith(RobolectricTestRunner.class)
|
||||
@Config(shadows = ShadowAlertDialogCompat.class)
|
||||
@Config(shadows = {ShadowAlertDialogCompat.class, ShadowBluetoothAdapter.class,
|
||||
ShadowBluetoothUtils.class})
|
||||
public class HearingAidUtilsTest {
|
||||
|
||||
@Rule
|
||||
public final MockitoRule mockito = MockitoJUnit.rule();
|
||||
private final Context mContext = ApplicationProvider.getApplicationContext();
|
||||
|
||||
private static final String TEST_DEVICE_ADDRESS = "00:A1:A1:A1:A1:A1";
|
||||
|
||||
@Mock
|
||||
private CachedBluetoothDevice mCachedBluetoothDevice;
|
||||
@Mock
|
||||
private CachedBluetoothDevice mSubCachedBluetoothDevice;
|
||||
|
||||
@Mock
|
||||
private LocalBluetoothManager mLocalBluetoothManager;
|
||||
@Mock
|
||||
private CachedBluetoothDeviceManager mCachedDeviceManager;
|
||||
private BluetoothDevice mBluetoothDevice;
|
||||
private BluetoothAdapter mBluetoothAdapter;
|
||||
private ShadowBluetoothAdapter mShadowBluetoothAdapter;
|
||||
private FragmentManager mFragmentManager;
|
||||
|
||||
@Before
|
||||
public void setUp() {
|
||||
setupEnvironment();
|
||||
final FragmentActivity mActivity = Robolectric.setupActivity(FragmentActivity.class);
|
||||
mFragmentManager = mActivity.getSupportFragmentManager();
|
||||
ShadowAlertDialogCompat.reset();
|
||||
when(mCachedBluetoothDevice.getAddress()).thenReturn(TEST_DEVICE_ADDRESS);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -123,4 +147,16 @@ public class HearingAidUtilsTest {
|
||||
final AlertDialog dialog = ShadowAlertDialogCompat.getLatestAlertDialog();
|
||||
assertThat(dialog.isShowing()).isTrue();
|
||||
}
|
||||
|
||||
private void setupEnvironment() {
|
||||
ShadowBluetoothUtils.sLocalBluetoothManager = mLocalBluetoothManager;
|
||||
mBluetoothAdapter = BluetoothAdapter.getDefaultAdapter();
|
||||
mLocalBluetoothManager = Utils.getLocalBtManager(mContext);
|
||||
mShadowBluetoothAdapter = Shadow.extract(mBluetoothAdapter);
|
||||
mBluetoothDevice = mBluetoothAdapter.getRemoteDevice(TEST_DEVICE_ADDRESS);
|
||||
mShadowBluetoothAdapter.addSupportedProfiles(BluetoothProfile.HEARING_AID);
|
||||
when(mLocalBluetoothManager.getCachedDeviceManager()).thenReturn(mCachedDeviceManager);
|
||||
when(mCachedDeviceManager.findDevice(mBluetoothDevice)).thenReturn(mCachedBluetoothDevice);
|
||||
when(mCachedBluetoothDevice.getAddress()).thenReturn(TEST_DEVICE_ADDRESS);
|
||||
}
|
||||
}
|
||||
|
@@ -27,6 +27,7 @@ import static org.mockito.Mockito.spy;
|
||||
import static org.mockito.Mockito.verify;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
import android.bluetooth.BluetoothDevice;
|
||||
import android.bluetooth.BluetoothProfile;
|
||||
import android.content.Context;
|
||||
import android.content.pm.PackageManager;
|
||||
@@ -50,6 +51,7 @@ import com.android.settings.testutils.shadow.ShadowBluetoothUtils;
|
||||
import com.android.settingslib.bluetooth.BluetoothCallback;
|
||||
import com.android.settingslib.bluetooth.BluetoothEventManager;
|
||||
import com.android.settingslib.bluetooth.CachedBluetoothDevice;
|
||||
import com.android.settingslib.bluetooth.CachedBluetoothDeviceManager;
|
||||
import com.android.settingslib.bluetooth.HearingAidProfile;
|
||||
import com.android.settingslib.bluetooth.LocalBluetoothManager;
|
||||
|
||||
@@ -70,6 +72,7 @@ import org.robolectric.annotation.Config;
|
||||
ShadowBluetoothUtils.class})
|
||||
public class AvailableMediaDeviceGroupControllerTest {
|
||||
|
||||
private static final String TEST_DEVICE_ADDRESS = "00:A1:A1:A1:A1:A1";
|
||||
private static final String PREFERENCE_KEY_1 = "pref_key_1";
|
||||
|
||||
@Mock
|
||||
@@ -85,7 +88,9 @@ public class AvailableMediaDeviceGroupControllerTest {
|
||||
@Mock
|
||||
private BluetoothEventManager mEventManager;
|
||||
@Mock
|
||||
private LocalBluetoothManager mLocalManager;
|
||||
private LocalBluetoothManager mLocalBluetoothManager;
|
||||
@Mock
|
||||
private CachedBluetoothDeviceManager mCachedDeviceManager;
|
||||
@Mock
|
||||
private CachedBluetoothDevice mCachedBluetoothDevice;
|
||||
|
||||
@@ -93,7 +98,6 @@ public class AvailableMediaDeviceGroupControllerTest {
|
||||
private Context mContext;
|
||||
private Preference mPreference;
|
||||
private AvailableMediaDeviceGroupController mAvailableMediaDeviceGroupController;
|
||||
private LocalBluetoothManager mLocalBluetoothManager;
|
||||
private AudioManager mAudioManager;
|
||||
|
||||
@Before
|
||||
@@ -112,10 +116,14 @@ public class AvailableMediaDeviceGroupControllerTest {
|
||||
when(mDashboardFragment.getParentFragmentManager()).thenReturn(
|
||||
mActivity.getSupportFragmentManager());
|
||||
|
||||
ShadowBluetoothUtils.sLocalBluetoothManager = mLocalManager;
|
||||
ShadowBluetoothUtils.sLocalBluetoothManager = mLocalBluetoothManager;
|
||||
mLocalBluetoothManager = Utils.getLocalBtManager(mContext);
|
||||
mAudioManager = mContext.getSystemService(AudioManager.class);
|
||||
doReturn(mEventManager).when(mLocalBluetoothManager).getEventManager();
|
||||
when(mLocalBluetoothManager.getCachedDeviceManager()).thenReturn(mCachedDeviceManager);
|
||||
when(mCachedDeviceManager.findDevice(any(BluetoothDevice.class))).thenReturn(
|
||||
mCachedBluetoothDevice);
|
||||
when(mCachedBluetoothDevice.getAddress()).thenReturn(TEST_DEVICE_ADDRESS);
|
||||
|
||||
mAvailableMediaDeviceGroupController = spy(
|
||||
new AvailableMediaDeviceGroupController(mContext));
|
||||
|
Reference in New Issue
Block a user