Merge "Replaces HearingDevicePairingDetail with HearingDevicePairingFragment" into main
diff --git a/res/xml/accessibility_hearing_aids.xml b/res/xml/accessibility_hearing_aids.xml
index 57a0fe2..9c6e661 100644
--- a/res/xml/accessibility_hearing_aids.xml
+++ b/res/xml/accessibility_hearing_aids.xml
@@ -32,6 +32,7 @@
         android:title="@string/bluetooth_pairing_pref_title"
         android:icon="@drawable/ic_add_24dp"
         android:summary="@string/connected_device_add_device_summary"
+        android:fragment="com.android.settings.accessibility.HearingDevicePairingFragment"
         settings:userRestriction="no_config_bluetooth"
         settings:useAdminDisabledSummary="true"
         settings:controller="com.android.settings.connecteddevice.AddDevicePreferenceController"/>
diff --git a/src/com/android/settings/accessibility/AccessibilityHearingAidsFragment.java b/src/com/android/settings/accessibility/AccessibilityHearingAidsFragment.java
index 80a03c6..cad2186 100644
--- a/src/com/android/settings/accessibility/AccessibilityHearingAidsFragment.java
+++ b/src/com/android/settings/accessibility/AccessibilityHearingAidsFragment.java
@@ -38,7 +38,6 @@
 public class AccessibilityHearingAidsFragment extends AccessibilityShortcutPreferenceFragment {
     private static final String TAG = "AccessibilityHearingAidsFragment";
     private static final String KEY_HEARING_OPTIONS_CATEGORY = "hearing_options_category";
-    public static final String KEY_HEARING_DEVICE_ADD_BT_DEVICES = "hearing_device_add_bt_devices";
     private static final int SHORTCUT_PREFERENCE_IN_CATEGORY_INDEX = 20;
     private String mFeatureName;
 
diff --git a/src/com/android/settings/accessibility/HearingDevicePairingDetail.java b/src/com/android/settings/accessibility/HearingDevicePairingDetail.java
deleted file mode 100644
index 117a8ed..0000000
--- a/src/com/android/settings/accessibility/HearingDevicePairingDetail.java
+++ /dev/null
@@ -1,96 +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 android.app.settings.SettingsEnums;
-import android.bluetooth.BluetoothDevice;
-import android.bluetooth.BluetoothUuid;
-import android.bluetooth.le.ScanFilter;
-import android.content.Context;
-
-import androidx.annotation.VisibleForTesting;
-
-import com.android.settings.R;
-import com.android.settings.bluetooth.BluetoothDevicePairingDetailBase;
-import com.android.settingslib.bluetooth.CachedBluetoothDevice;
-
-import java.util.ArrayList;
-import java.util.List;
-
-/**
- * HearingDevicePairingDetail is a page to scan hearing devices. This page shows scanning icons and
- * pairing them.
- */
-public class HearingDevicePairingDetail extends BluetoothDevicePairingDetailBase {
-
-    private static final String TAG = "HearingDevicePairingDetail";
-    @VisibleForTesting
-    static final String KEY_AVAILABLE_HEARING_DEVICES = "available_hearing_devices";
-
-    public HearingDevicePairingDetail() {
-        super();
-        final List<ScanFilter> filterList = new ArrayList<>();
-        // Filters for ASHA hearing aids
-        filterList.add(new ScanFilter.Builder().setServiceUuid(BluetoothUuid.HEARING_AID).build());
-        filterList.add(new ScanFilter.Builder()
-                .setServiceData(BluetoothUuid.HEARING_AID, new byte[0]).build());
-        // Filters for LE audio hearing aids
-        filterList.add(new ScanFilter.Builder().setServiceUuid(BluetoothUuid.HAS).build());
-        filterList.add(new ScanFilter.Builder()
-                .setServiceData(BluetoothUuid.HAS, new byte[0]).build());
-        setFilter(filterList);
-    }
-
-    @Override
-    public void onAttach(Context context) {
-        super.onAttach(context);
-        use(ViewAllBluetoothDevicesPreferenceController.class).init(this);
-    }
-
-    @Override
-    public void onStart() {
-        super.onStart();
-        mAvailableDevicesCategory.setProgress(mBluetoothAdapter.isEnabled());
-    }
-
-    @Override
-    public void onDeviceBondStateChanged(CachedBluetoothDevice cachedDevice, int bondState) {
-        super.onDeviceBondStateChanged(cachedDevice, bondState);
-
-        mAvailableDevicesCategory.setProgress(bondState == BluetoothDevice.BOND_NONE);
-    }
-
-    @Override
-    public int getMetricsCategory() {
-        return SettingsEnums.HEARING_AID_PAIRING;
-    }
-
-    @Override
-    protected int getPreferenceScreenResId() {
-        return R.xml.hearing_device_pairing_detail;
-    }
-
-    @Override
-    protected String getLogTag() {
-        return TAG;
-    }
-
-    @Override
-    public String getDeviceListKey() {
-        return KEY_AVAILABLE_HEARING_DEVICES;
-    }
-}
diff --git a/src/com/android/settings/bluetooth/HearingAidPairingDialogFragment.java b/src/com/android/settings/bluetooth/HearingAidPairingDialogFragment.java
index 3a16e3e..73c7d73 100644
--- a/src/com/android/settings/bluetooth/HearingAidPairingDialogFragment.java
+++ b/src/com/android/settings/bluetooth/HearingAidPairingDialogFragment.java
@@ -28,11 +28,9 @@
 import androidx.appcompat.app.AlertDialog;
 
 import com.android.settings.R;
-import com.android.settings.accessibility.HearingDevicePairingDetail;
 import com.android.settings.accessibility.HearingDevicePairingFragment;
 import com.android.settings.core.SubSettingLauncher;
 import com.android.settings.core.instrumentation.InstrumentedDialogFragment;
-import com.android.settings.flags.Flags;
 import com.android.settingslib.bluetooth.CachedBluetoothDevice;
 import com.android.settingslib.bluetooth.HearingAidInfo;
 import com.android.settingslib.bluetooth.LocalBluetoothManager;
@@ -125,11 +123,8 @@
         final int launchPage = getArguments().getInt(KEY_LAUNCH_PAGE);
         final boolean launchFromA11y = (launchPage == SettingsEnums.ACCESSIBILITY)
                 || (launchPage == SettingsEnums.ACCESSIBILITY_HEARING_AID_SETTINGS);
-        final String a11yDestination = Flags.newHearingDevicePairingPage()
-                ? HearingDevicePairingFragment.class.getName()
-                : HearingDevicePairingDetail.class.getName();
         final String destination = launchFromA11y
-                ? a11yDestination
+                ? HearingDevicePairingFragment.class.getName()
                 : BluetoothPairingDetail.class.getName();
         new SubSettingLauncher(getActivity())
                 .setDestination(destination)
diff --git a/src/com/android/settings/connecteddevice/AddDevicePreferenceController.java b/src/com/android/settings/connecteddevice/AddDevicePreferenceController.java
index ef44843..d2bc319 100644
--- a/src/com/android/settings/connecteddevice/AddDevicePreferenceController.java
+++ b/src/com/android/settings/connecteddevice/AddDevicePreferenceController.java
@@ -15,25 +15,18 @@
  */
 package com.android.settings.connecteddevice;
 
-import static com.android.settings.accessibility.AccessibilityHearingAidsFragment.KEY_HEARING_DEVICE_ADD_BT_DEVICES;
-
 import android.bluetooth.BluetoothAdapter;
 import android.content.BroadcastReceiver;
 import android.content.Context;
 import android.content.Intent;
 import android.content.IntentFilter;
 import android.content.pm.PackageManager;
-import android.text.TextUtils;
 
 import androidx.preference.Preference;
 import androidx.preference.PreferenceScreen;
 
 import com.android.settings.R;
-import com.android.settings.accessibility.HearingDevicePairingDetail;
-import com.android.settings.accessibility.HearingDevicePairingFragment;
 import com.android.settings.core.BasePreferenceController;
-import com.android.settings.core.SubSettingLauncher;
-import com.android.settings.flags.Flags;
 import com.android.settingslib.core.lifecycle.LifecycleObserver;
 import com.android.settingslib.core.lifecycle.events.OnStart;
 import com.android.settingslib.core.lifecycle.events.OnStop;
@@ -83,21 +76,6 @@
     }
 
     @Override
-    public boolean handlePreferenceTreeClick(Preference preference) {
-        if (TextUtils.equals(preference.getKey(), KEY_HEARING_DEVICE_ADD_BT_DEVICES)) {
-            String destination = Flags.newHearingDevicePairingPage()
-                    ? HearingDevicePairingFragment.class.getName()
-                    : HearingDevicePairingDetail.class.getName();
-            new SubSettingLauncher(preference.getContext())
-                    .setDestination(destination)
-                    .setSourceMetricsCategory(getMetricsCategory())
-                    .launch();
-            return true;
-        }
-        return super.handlePreferenceTreeClick(preference);
-    }
-
-    @Override
     public int getAvailabilityStatus() {
         return mContext.getPackageManager().hasSystemFeature(PackageManager.FEATURE_BLUETOOTH)
                 ? AVAILABLE
diff --git a/tests/robotests/src/com/android/settings/accessibility/HearingAidPairingDialogFragmentTest.java b/tests/robotests/src/com/android/settings/accessibility/HearingAidPairingDialogFragmentTest.java
index bd57e9d..d082b1f 100644
--- a/tests/robotests/src/com/android/settings/accessibility/HearingAidPairingDialogFragmentTest.java
+++ b/tests/robotests/src/com/android/settings/accessibility/HearingAidPairingDialogFragmentTest.java
@@ -32,10 +32,6 @@
 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.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 @@
     @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 @@
     }
 
     @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();
@@ -151,20 +142,6 @@
     }
 
     @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);
         dialog.show();
diff --git a/tests/robotests/src/com/android/settings/accessibility/HearingDevicePairingDetailTest.java b/tests/robotests/src/com/android/settings/accessibility/HearingDevicePairingDetailTest.java
deleted file mode 100644
index e1651d9..0000000
--- a/tests/robotests/src/com/android/settings/accessibility/HearingDevicePairingDetailTest.java
+++ /dev/null
@@ -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();
-        }
-    }
-}
diff --git a/tests/robotests/src/com/android/settings/accessibility/ViewAllBluetoothDevicesPreferenceControllerTest.java b/tests/robotests/src/com/android/settings/accessibility/ViewAllBluetoothDevicesPreferenceControllerTest.java
index 1f9fbeb..b368a22 100644
--- a/tests/robotests/src/com/android/settings/accessibility/ViewAllBluetoothDevicesPreferenceControllerTest.java
+++ b/tests/robotests/src/com/android/settings/accessibility/ViewAllBluetoothDevicesPreferenceControllerTest.java
@@ -56,7 +56,7 @@
     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;
diff --git a/tests/robotests/src/com/android/settings/connecteddevice/AddDevicePreferenceControllerTest.java b/tests/robotests/src/com/android/settings/connecteddevice/AddDevicePreferenceControllerTest.java
index 63fa88d..70c73a6 100644
--- a/tests/robotests/src/com/android/settings/connecteddevice/AddDevicePreferenceControllerTest.java
+++ b/tests/robotests/src/com/android/settings/connecteddevice/AddDevicePreferenceControllerTest.java
@@ -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.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 @@
 @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 @@
         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 @@
         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());
-    }
 }