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

Commit a32ebfb5 authored by Angela Wang's avatar Angela Wang Committed by Android (Google) Code Review
Browse files

Merge "Redirects to connected devices page in a11y pairing page" into main

parents 3410c48c 4a2b4a87
Loading
Loading
Loading
Loading
+6 −25
Original line number Diff line number Diff line
@@ -16,27 +16,19 @@

package com.android.settings.accessibility;

import static android.app.Activity.RESULT_OK;

import android.content.Context;
import android.content.Intent;
import android.preference.PreferenceManager;
import android.text.TextUtils;

import androidx.annotation.VisibleForTesting;
import androidx.preference.Preference;

import com.android.settings.bluetooth.BluetoothPairingDetail;
import com.android.settings.connecteddevice.ConnectedDeviceDashboardFragment;
import com.android.settings.core.BasePreferenceController;
import com.android.settings.core.SubSettingLauncher;
import com.android.settings.dashboard.DashboardFragment;

import androidx.annotation.VisibleForTesting;

/** Preference controller for all bluetooth device preference. */
public class ViewAllBluetoothDevicesPreferenceController extends BasePreferenceController implements
        PreferenceManager.OnActivityResultListener {

    private static final int REQUEST_CODE_BONDED_DEVICE = 270;
public class ViewAllBluetoothDevicesPreferenceController extends BasePreferenceController {
    private DashboardFragment mFragment;

    public ViewAllBluetoothDevicesPreferenceController(Context context, String preferenceKey) {
@@ -60,29 +52,18 @@ public class ViewAllBluetoothDevicesPreferenceController extends BasePreferenceC
    @Override
    public boolean handlePreferenceTreeClick(Preference preference) {
        if (TextUtils.equals(preference.getKey(), getPreferenceKey())) {
            launchBluetoothPairingDetail();
            launchConnectedDevicePage();
            return true;
        }

        return false;
    }

    @Override
    public boolean onActivityResult(int requestCode, int resultCode, Intent data) {
        // If back from BONDED device page, then no need to show scan result again.
        // Finish the fragment.
        if (requestCode == REQUEST_CODE_BONDED_DEVICE && resultCode == RESULT_OK) {
            mFragment.finish();
        }
        return false;
    }

    @VisibleForTesting
    void launchBluetoothPairingDetail() {
    void launchConnectedDevicePage() {
        new SubSettingLauncher(mContext)
                .setDestination(BluetoothPairingDetail.class.getName())
                .setDestination(ConnectedDeviceDashboardFragment.class.getName())
                .setSourceMetricsCategory(mFragment.getMetricsCategory())
                .setResultListener(mFragment, REQUEST_CODE_BONDED_DEVICE)
                .launch();
    }
}
+0 −3
Original line number Diff line number Diff line
@@ -16,7 +16,6 @@

package com.android.settings.bluetooth;

import static android.app.Activity.RESULT_OK;
import static android.os.UserManager.DISALLOW_CONFIG_BLUETOOTH;

import android.bluetooth.BluetoothAdapter;
@@ -94,7 +93,6 @@ public abstract class BluetoothDevicePairingDetailBase extends DeviceListPrefere
    public void onDeviceBondStateChanged(CachedBluetoothDevice cachedDevice, int bondState) {
        if (bondState == BluetoothDevice.BOND_BONDED) {
            // If one device is connected(bonded), then close this fragment.
            setResult(RESULT_OK);
            finish();
            return;
        } else if (bondState == BluetoothDevice.BOND_BONDING) {
@@ -126,7 +124,6 @@ public abstract class BluetoothDevicePairingDetailBase extends DeviceListPrefere
        if (cachedDevice != null && cachedDevice.isConnected()) {
            final BluetoothDevice device = cachedDevice.getDevice();
            if (device != null && mSelectedList.contains(device)) {
                setResult(RESULT_OK);
                finish();
            } else {
                onDeviceDeleted(cachedDevice);
+3 −3
Original line number Diff line number Diff line
@@ -74,13 +74,13 @@ public class ViewAllBluetoothDevicesPreferenceControllerTest {
    }

    @Test
    public void handlePreferenceTreeClick_expectedPreference_launchBluetoothPairingDetail() {
        doNothing().when(mController).launchBluetoothPairingDetail();
    public void handlePreferenceTreeClick_expectedPreference_launchConnectedDevicePage() {
        doNothing().when(mController).launchConnectedDevicePage();
        mPreference.setKey(TEST_KEY);

        boolean status = mController.handlePreferenceTreeClick(mPreference);

        verify(mController).launchBluetoothPairingDetail();
        verify(mController).launchConnectedDevicePage();
        assertThat(status).isTrue();
    }
}