Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 91768260 authored by jasonwshsu's avatar jasonwshsu
Browse files

Fix corss-link hearing device settings

Root Cause: There are two device details entries in Connected devices and Hearing devices page which can both go to the same page, it will have the endless loop problem.

Solution: Only show hearing device settings comes from Connected devices page.

Bug: 320709814
Test: make RunSettingsRoboTests ROBOTEST_FILTER=BluetoothDeviceDetailsFragmentTest
Change-Id: I26941d0d16ab3bb0df0cb2c481c25c6c41340261
parent a3e50363
Loading
Loading
Loading
Loading
+2 −1
Original line number Original line Diff line number Diff line
@@ -38,7 +38,8 @@ import com.google.common.annotations.VisibleForTesting;
public class BluetoothDetailsHearingDeviceControlsController extends BluetoothDetailsController
public class BluetoothDetailsHearingDeviceControlsController extends BluetoothDetailsController
        implements Preference.OnPreferenceClickListener {
        implements Preference.OnPreferenceClickListener {


    private static final String KEY_DEVICE_CONTROLS_GENERAL_GROUP = "device_controls_general";
    @VisibleForTesting
    static final String KEY_DEVICE_CONTROLS_GENERAL_GROUP = "device_controls_general";
    @VisibleForTesting
    @VisibleForTesting
    static final String KEY_HEARING_DEVICE_CONTROLS = "hearing_device_controls";
    static final String KEY_HEARING_DEVICE_CONTROLS = "hearing_device_controls";


+17 −2
Original line number Original line Diff line number Diff line
@@ -22,6 +22,7 @@ import static android.os.UserManager.DISALLOW_CONFIG_BLUETOOTH;
import android.app.settings.SettingsEnums;
import android.app.settings.SettingsEnums;
import android.bluetooth.BluetoothDevice;
import android.bluetooth.BluetoothDevice;
import android.content.Context;
import android.content.Context;
import android.content.Intent;
import android.content.res.TypedArray;
import android.content.res.TypedArray;
import android.hardware.input.InputManager;
import android.hardware.input.InputManager;
import android.net.Uri;
import android.net.Uri;
@@ -53,6 +54,7 @@ import com.android.settings.slices.SlicePreferenceController;
import com.android.settingslib.bluetooth.CachedBluetoothDevice;
import com.android.settingslib.bluetooth.CachedBluetoothDevice;
import com.android.settingslib.bluetooth.LocalBluetoothManager;
import com.android.settingslib.bluetooth.LocalBluetoothManager;
import com.android.settingslib.core.AbstractPreferenceController;
import com.android.settingslib.core.AbstractPreferenceController;
import com.android.settingslib.core.instrumentation.MetricsFeatureProvider;
import com.android.settingslib.core.lifecycle.Lifecycle;
import com.android.settingslib.core.lifecycle.Lifecycle;


import java.util.ArrayList;
import java.util.ArrayList;
@@ -324,8 +326,11 @@ public class BluetoothDeviceDetailsFragment extends RestrictedDashboardFragment
                    lifecycle));
                    lifecycle));
            controllers.add(new BluetoothDetailsPairOtherController(context, this, mCachedDevice,
            controllers.add(new BluetoothDetailsPairOtherController(context, this, mCachedDevice,
                    lifecycle));
                    lifecycle));
            // Don't need to show hearing device again when launched from the same page.
            if (!isLaunchFromHearingDevicePage()) {
                controllers.add(new BluetoothDetailsHearingDeviceControlsController(context, this,
                controllers.add(new BluetoothDetailsHearingDeviceControlsController(context, this,
                        mCachedDevice, lifecycle));
                        mCachedDevice, lifecycle));
            }
            controllers.add(new BluetoothDetailsDataSyncController(context, this,
            controllers.add(new BluetoothDetailsDataSyncController(context, this,
                    mCachedDevice, lifecycle));
                    mCachedDevice, lifecycle));
        }
        }
@@ -345,6 +350,16 @@ public class BluetoothDeviceDetailsFragment extends RestrictedDashboardFragment
        return width;
        return width;
    }
    }


    private boolean isLaunchFromHearingDevicePage() {
        final Intent intent = getIntent();
        if (intent == null) {
            return false;
        }

        return intent.getIntExtra(MetricsFeatureProvider.EXTRA_SOURCE_METRICS_CATEGORY,
                SettingsEnums.PAGE_UNKNOWN) == SettingsEnums.ACCESSIBILITY_HEARING_AID_SETTINGS;
    }

    @VisibleForTesting
    @VisibleForTesting
    void setTitleForInputDevice() {
    void setTitleForInputDevice() {
        if (StylusDevicesController.isDeviceStylus(mInputDevice, mCachedDevice)) {
        if (StylusDevicesController.isDeviceStylus(mInputDevice, mCachedDevice)) {
+40 −0
Original line number Original line Diff line number Diff line
@@ -18,6 +18,8 @@ package com.android.settings.bluetooth;


import static android.bluetooth.BluetoothDevice.BOND_NONE;
import static android.bluetooth.BluetoothDevice.BOND_NONE;


import static com.android.settings.bluetooth.BluetoothDetailsHearingDeviceControlsController.KEY_DEVICE_CONTROLS_GENERAL_GROUP;

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.ArgumentMatchers.any;
@@ -29,8 +31,10 @@ import static org.mockito.Mockito.times;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
import static org.mockito.Mockito.when;


import android.app.settings.SettingsEnums;
import android.companion.CompanionDeviceManager;
import android.companion.CompanionDeviceManager;
import android.content.Context;
import android.content.Context;
import android.content.Intent;
import android.hardware.input.InputManager;
import android.hardware.input.InputManager;
import android.os.Bundle;
import android.os.Bundle;
import android.os.UserManager;
import android.os.UserManager;
@@ -49,6 +53,8 @@ import com.android.settings.R;
import com.android.settings.testutils.FakeFeatureFactory;
import com.android.settings.testutils.FakeFeatureFactory;
import com.android.settingslib.bluetooth.CachedBluetoothDevice;
import com.android.settingslib.bluetooth.CachedBluetoothDevice;
import com.android.settingslib.bluetooth.LocalBluetoothManager;
import com.android.settingslib.bluetooth.LocalBluetoothManager;
import com.android.settingslib.core.AbstractPreferenceController;
import com.android.settingslib.core.instrumentation.MetricsFeatureProvider;


import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableList;


@@ -65,6 +71,8 @@ import org.robolectric.RuntimeEnvironment;
import org.robolectric.annotation.Config;
import org.robolectric.annotation.Config;
import org.robolectric.fakes.RoboMenu;
import org.robolectric.fakes.RoboMenu;


import java.util.List;

@RunWith(RobolectricTestRunner.class)
@RunWith(RobolectricTestRunner.class)
@Config(shadows = {
@Config(shadows = {
        com.android.settings.testutils.shadow.ShadowUserManager.class,
        com.android.settings.testutils.shadow.ShadowUserManager.class,
@@ -216,6 +224,38 @@ public class BluetoothDeviceDetailsFragmentTest {
        verify(mFragment).finish();
        verify(mFragment).finish();
    }
    }


    @Test
    public void createPreferenceControllers_launchFromHAPage_deviceControllerNotExist() {
        BluetoothDeviceDetailsFragment fragment = setupFragment();
        Intent intent = fragment.getActivity().getIntent();
        intent.putExtra(MetricsFeatureProvider.EXTRA_SOURCE_METRICS_CATEGORY,
                SettingsEnums.ACCESSIBILITY_HEARING_AID_SETTINGS);
        fragment.onAttach(mContext);

        List<AbstractPreferenceController> controllerList = fragment.createPreferenceControllers(
                mContext);

        assertThat(controllerList.stream()
                .anyMatch(controller -> controller.getPreferenceKey().equals(
                        KEY_DEVICE_CONTROLS_GENERAL_GROUP))).isFalse();
    }

    @Test
    public void createPreferenceControllers_notLaunchFromHAPage_deviceControllerExist() {
        BluetoothDeviceDetailsFragment fragment = setupFragment();
        Intent intent = fragment.getActivity().getIntent();
        intent.putExtra(MetricsFeatureProvider.EXTRA_SOURCE_METRICS_CATEGORY,
                SettingsEnums.PAGE_UNKNOWN);
        fragment.onAttach(mContext);

        List<AbstractPreferenceController> controllerList = fragment.createPreferenceControllers(
                mContext);

        assertThat(controllerList.stream()
                .anyMatch(controller -> controller.getPreferenceKey().equals(
                        KEY_DEVICE_CONTROLS_GENERAL_GROUP))).isTrue();
    }

    private InputDevice createInputDeviceWithMatchingBluetoothAddress() {
    private InputDevice createInputDeviceWithMatchingBluetoothAddress() {
        doReturn(new int[]{0}).when(mInputManager).getInputDeviceIds();
        doReturn(new int[]{0}).when(mInputManager).getInputDeviceIds();
        InputDevice device = mock(InputDevice.class);
        InputDevice device = mock(InputDevice.class);