Replaces HearingDevicePairingDetail with HearingDevicePairingFragment
The new pairing page includes new UI for "See more devices" buttton and can show MFi + ASHA devices in the pairing list while these devices only advertise MFi HAS uuid in pairing mode. As allowed by "Flag Cleanup Policy", this change finishes the rollout of trunkfood flag new_hearing_device_pairing_page by defaulting to the "true" state. Bug: 307473972 Test: atest HearingAidPairingDialogFragmentTest Test: atest AddDevicePreferenceControllerTest Change-Id: I6c3377d535139d62791548557c581317d1878e9d
This commit is contained in:
@@ -32,10 +32,6 @@ import android.content.Context;
|
||||
import android.content.DialogInterface;
|
||||
import android.content.Intent;
|
||||
import android.os.Bundle;
|
||||
import android.platform.test.annotations.RequiresFlagsDisabled;
|
||||
import android.platform.test.annotations.RequiresFlagsEnabled;
|
||||
import android.platform.test.flag.junit.CheckFlagsRule;
|
||||
import android.platform.test.flag.junit.DeviceFlagsValueProvider;
|
||||
|
||||
import androidx.appcompat.app.AlertDialog;
|
||||
import androidx.fragment.app.FragmentActivity;
|
||||
@@ -47,7 +43,6 @@ 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.flags.Flags;
|
||||
import com.android.settings.testutils.shadow.ShadowBluetoothAdapter;
|
||||
import com.android.settings.testutils.shadow.ShadowBluetoothUtils;
|
||||
import com.android.settingslib.bluetooth.CachedBluetoothDevice;
|
||||
@@ -82,9 +77,6 @@ public class HearingAidPairingDialogFragmentTest {
|
||||
@Rule
|
||||
public final MockitoRule mockito = MockitoJUnit.rule();
|
||||
|
||||
@Rule
|
||||
public final CheckFlagsRule mCheckFlagsRule = DeviceFlagsValueProvider.createCheckFlagsRule();
|
||||
|
||||
private static final String TEST_DEVICE_ADDRESS = "00:A1:A1:A1:A1:A1";
|
||||
private static final int TEST_LAUNCH_PAGE = SettingsEnums.SETTINGS_CONNECTED_DEVICE_CATEGORY;
|
||||
|
||||
@@ -137,8 +129,7 @@ public class HearingAidPairingDialogFragmentTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
@RequiresFlagsEnabled(Flags.FLAG_NEW_HEARING_DEVICE_PAIRING_PAGE)
|
||||
public void dialogPositiveButtonClick_intentToNewA11yPairingPage() {
|
||||
public void dialogPositiveButtonClick_intentToA11yPairingPage() {
|
||||
setupDialog(SettingsEnums.ACCESSIBILITY);
|
||||
final AlertDialog dialog = (AlertDialog) mFragment.onCreateDialog(Bundle.EMPTY);
|
||||
dialog.show();
|
||||
@@ -150,20 +141,6 @@ public class HearingAidPairingDialogFragmentTest {
|
||||
.isEqualTo(HearingDevicePairingFragment.class.getName());
|
||||
}
|
||||
|
||||
@Test
|
||||
@RequiresFlagsDisabled(Flags.FLAG_NEW_HEARING_DEVICE_PAIRING_PAGE)
|
||||
public void dialogPositiveButtonClick_intentToOldA11yPairingPage() {
|
||||
setupDialog(SettingsEnums.ACCESSIBILITY);
|
||||
final AlertDialog dialog = (AlertDialog) mFragment.onCreateDialog(Bundle.EMPTY);
|
||||
dialog.show();
|
||||
|
||||
dialog.getButton(DialogInterface.BUTTON_POSITIVE).performClick();
|
||||
|
||||
final Intent intent = shadowOf(mActivity).getNextStartedActivity();
|
||||
assertThat(intent.getStringExtra(SettingsActivity.EXTRA_SHOW_FRAGMENT))
|
||||
.isEqualTo(HearingDevicePairingDetail.class.getName());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void dialogNegativeButtonClick_dismissDialog() {
|
||||
final AlertDialog dialog = (AlertDialog) mFragment.onCreateDialog(Bundle.EMPTY);
|
||||
|
@@ -1,115 +0,0 @@
|
||||
/*
|
||||
* Copyright (C) 2023 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.spy;
|
||||
import static org.mockito.Mockito.verify;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
import android.bluetooth.BluetoothAdapter;
|
||||
import android.bluetooth.BluetoothDevice;
|
||||
import android.content.Context;
|
||||
|
||||
import androidx.test.core.app.ApplicationProvider;
|
||||
|
||||
import com.android.settings.bluetooth.BluetoothProgressCategory;
|
||||
import com.android.settings.testutils.shadow.ShadowBluetoothAdapter;
|
||||
import com.android.settingslib.bluetooth.CachedBluetoothDevice;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Rule;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.mockito.Mock;
|
||||
import org.mockito.junit.MockitoJUnit;
|
||||
import org.mockito.junit.MockitoRule;
|
||||
import org.robolectric.RobolectricTestRunner;
|
||||
import org.robolectric.annotation.Config;
|
||||
import org.robolectric.shadow.api.Shadow;
|
||||
|
||||
/** Tests for {@link HearingDevicePairingDetail}. */
|
||||
@RunWith(RobolectricTestRunner.class)
|
||||
@Config(shadows = {ShadowBluetoothAdapter.class})
|
||||
public class HearingDevicePairingDetailTest {
|
||||
|
||||
@Rule
|
||||
public final MockitoRule mockito = MockitoJUnit.rule();
|
||||
|
||||
private final Context mContext = ApplicationProvider.getApplicationContext();
|
||||
|
||||
@Mock
|
||||
private CachedBluetoothDevice mCachedBluetoothDevice;
|
||||
private BluetoothProgressCategory mProgressCategory;
|
||||
private TestHearingDevicePairingDetail mFragment;
|
||||
|
||||
@Before
|
||||
public void setUp() {
|
||||
final BluetoothAdapter bluetoothAdapter = spy(BluetoothAdapter.getDefaultAdapter());
|
||||
final ShadowBluetoothAdapter shadowBluetoothAdapter = Shadow.extract(
|
||||
BluetoothAdapter.getDefaultAdapter());
|
||||
shadowBluetoothAdapter.setEnabled(true);
|
||||
|
||||
mProgressCategory = spy(new BluetoothProgressCategory(mContext));
|
||||
mFragment = spy(new TestHearingDevicePairingDetail());
|
||||
when(mFragment.getContext()).thenReturn(mContext);
|
||||
when(mFragment.findPreference(
|
||||
HearingDevicePairingDetail.KEY_AVAILABLE_HEARING_DEVICES)).thenReturn(
|
||||
mProgressCategory);
|
||||
mFragment.setBluetoothAdapter(bluetoothAdapter);
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getDeviceListKey_expectedKey() {
|
||||
assertThat(mFragment.getDeviceListKey()).isEqualTo(
|
||||
HearingDevicePairingDetail.KEY_AVAILABLE_HEARING_DEVICES);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void onDeviceBondStateChanged_bondNone_setProgressFalse() {
|
||||
mFragment.initPreferencesFromPreferenceScreen();
|
||||
|
||||
mFragment.onDeviceBondStateChanged(mCachedBluetoothDevice, BluetoothDevice.BOND_NONE);
|
||||
|
||||
verify(mProgressCategory).setProgress(true);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void onDeviceBondStateChanged_bonding_setProgressTrue() {
|
||||
mFragment.initPreferencesFromPreferenceScreen();
|
||||
|
||||
mFragment.onDeviceBondStateChanged(mCachedBluetoothDevice, BluetoothDevice.BOND_BONDING);
|
||||
|
||||
verify(mProgressCategory).setProgress(false);
|
||||
}
|
||||
|
||||
private static class TestHearingDevicePairingDetail extends HearingDevicePairingDetail {
|
||||
TestHearingDevicePairingDetail() {
|
||||
super();
|
||||
}
|
||||
|
||||
public void setBluetoothAdapter(BluetoothAdapter bluetoothAdapter) {
|
||||
this.mBluetoothAdapter = bluetoothAdapter;
|
||||
}
|
||||
|
||||
public void enableScanning() {
|
||||
super.enableScanning();
|
||||
}
|
||||
}
|
||||
}
|
@@ -56,7 +56,7 @@ public class ViewAllBluetoothDevicesPreferenceControllerTest {
|
||||
private final String TEST_KEY = "test_key";
|
||||
|
||||
@Spy
|
||||
private HearingDevicePairingDetail mFragment = new HearingDevicePairingDetail();
|
||||
private HearingDevicePairingFragment mFragment = new HearingDevicePairingFragment();
|
||||
private FragmentActivity mActivity;
|
||||
@Mock
|
||||
private PreferenceScreen mScreen;
|
||||
|
@@ -15,16 +15,12 @@
|
||||
*/
|
||||
package com.android.settings.connecteddevice;
|
||||
|
||||
import static com.android.settings.accessibility.AccessibilityHearingAidsFragment.KEY_HEARING_DEVICE_ADD_BT_DEVICES;
|
||||
import static com.android.settings.core.BasePreferenceController.AVAILABLE;
|
||||
import static com.android.settings.core.BasePreferenceController.UNSUPPORTED_ON_DEVICE;
|
||||
|
||||
import static com.google.common.truth.Truth.assertThat;
|
||||
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import static org.mockito.ArgumentMatchers.any;
|
||||
import static org.mockito.Mockito.doNothing;
|
||||
import static org.mockito.Mockito.verify;
|
||||
import static org.mockito.Mockito.when;
|
||||
import static org.robolectric.Shadows.shadowOf;
|
||||
|
||||
@@ -33,27 +29,17 @@ import android.content.BroadcastReceiver;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.content.pm.PackageManager;
|
||||
import android.platform.test.annotations.RequiresFlagsDisabled;
|
||||
import android.platform.test.annotations.RequiresFlagsEnabled;
|
||||
import android.platform.test.flag.junit.CheckFlagsRule;
|
||||
import android.platform.test.flag.junit.DeviceFlagsValueProvider;
|
||||
import android.text.TextUtils;
|
||||
|
||||
import androidx.preference.PreferenceScreen;
|
||||
import androidx.test.core.app.ApplicationProvider;
|
||||
|
||||
import com.android.settings.R;
|
||||
import com.android.settings.SettingsActivity;
|
||||
import com.android.settings.accessibility.HearingDevicePairingDetail;
|
||||
import com.android.settings.accessibility.HearingDevicePairingFragment;
|
||||
import com.android.settings.flags.Flags;
|
||||
import com.android.settingslib.RestrictedPreference;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Rule;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.mockito.ArgumentCaptor;
|
||||
import org.mockito.Mock;
|
||||
import org.mockito.MockitoAnnotations;
|
||||
import org.mockito.Spy;
|
||||
@@ -65,10 +51,6 @@ import org.robolectric.util.ReflectionHelpers;
|
||||
@RunWith(RobolectricTestRunner.class)
|
||||
@Config(shadows = ShadowApplicationPackageManager.class)
|
||||
public class AddDevicePreferenceControllerTest {
|
||||
|
||||
@Rule
|
||||
public final CheckFlagsRule mCheckFlagsRule = DeviceFlagsValueProvider.createCheckFlagsRule();
|
||||
|
||||
@Mock
|
||||
private PreferenceScreen mScreen;
|
||||
@Mock
|
||||
@@ -100,8 +82,6 @@ public class AddDevicePreferenceControllerTest {
|
||||
when(mBluetoothAdapter.isEnabled()).thenReturn(true);
|
||||
when(mScreen.findPreference(key)).thenReturn(mAddDevicePreference);
|
||||
mAddDevicePreferenceController.displayPreference(mScreen);
|
||||
|
||||
doNothing().when(mContext).startActivity(any(Intent.class));
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -157,30 +137,4 @@ public class AddDevicePreferenceControllerTest {
|
||||
assertThat(mAddDevicePreferenceController.getAvailabilityStatus())
|
||||
.isEqualTo(UNSUPPORTED_ON_DEVICE);
|
||||
}
|
||||
|
||||
@Test
|
||||
@RequiresFlagsEnabled(Flags.FLAG_NEW_HEARING_DEVICE_PAIRING_PAGE)
|
||||
public void handlePreferenceClick_A11yPreference_redirectToNewPairingPage() {
|
||||
mAddDevicePreference.setKey(KEY_HEARING_DEVICE_ADD_BT_DEVICES);
|
||||
final ArgumentCaptor<Intent> intentCaptor = ArgumentCaptor.forClass(Intent.class);
|
||||
|
||||
mAddDevicePreferenceController.handlePreferenceTreeClick(mAddDevicePreference);
|
||||
|
||||
verify(mContext).startActivity(intentCaptor.capture());
|
||||
assertThat(intentCaptor.getValue().getStringExtra(SettingsActivity.EXTRA_SHOW_FRAGMENT))
|
||||
.isEqualTo(HearingDevicePairingFragment.class.getName());
|
||||
}
|
||||
|
||||
@Test
|
||||
@RequiresFlagsDisabled(Flags.FLAG_NEW_HEARING_DEVICE_PAIRING_PAGE)
|
||||
public void handlePreferenceClick_A11yPreference_redirectToOldPairingPage() {
|
||||
mAddDevicePreference.setKey(KEY_HEARING_DEVICE_ADD_BT_DEVICES);
|
||||
final ArgumentCaptor<Intent> intentCaptor = ArgumentCaptor.forClass(Intent.class);
|
||||
|
||||
mAddDevicePreferenceController.handlePreferenceTreeClick(mAddDevicePreference);
|
||||
|
||||
verify(mContext).startActivity(intentCaptor.capture());
|
||||
assertThat(intentCaptor.getValue().getStringExtra(SettingsActivity.EXTRA_SHOW_FRAGMENT))
|
||||
.isEqualTo(HearingDevicePairingDetail.class.getName());
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user