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

Commit 667cbc58 authored by TreeHugger Robot's avatar TreeHugger Robot Committed by Android (Google) Code Review
Browse files

Merge "Add “Rename device” on Bluetooth screen" into pi-dev

parents 273faa21 211d49f2
Loading
Loading
Loading
Loading
+3 −1
Original line number Diff line number Diff line
@@ -16,12 +16,14 @@

<PreferenceScreen
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:settings="http://schemas.android.com/apk/res-auto"
    android:title="@string/bluetooth_pairing_pref_title">

    <Preference
        android:key="bt_pair_rename_devices"
        android:title="@string/bluetooth_device_name"
        android:summary="@string/summary_placeholder" />
        android:summary="@string/summary_placeholder"
        settings:controller="com.android.settings.bluetooth.BluetoothDeviceRenamePreferenceController"/>

    <com.android.settings.bluetooth.BluetoothProgressCategory
        android:key="available_devices"
+6 −0
Original line number Diff line number Diff line
@@ -19,6 +19,12 @@
    android:key="bluetooth_switchbar_screen"
    android:title="@string/bluetooth_settings_title">

    <Preference
        android:key="bluetooth_screen_bt_pair_rename_devices"
        android:title="@string/bluetooth_device_name"
        android:summary="@string/summary_placeholder"
        settings:controller="com.android.settings.bluetooth.BluetoothDeviceRenamePreferenceController"/>

    <com.android.settingslib.RestrictedPreference
        android:key="bluetooth_screen_add_bt_devices"
        android:title="@string/bluetooth_pairing_pref_title"
+9 −25
Original line number Diff line number Diff line
@@ -32,7 +32,6 @@ import com.android.settings.R;
import com.android.settings.core.BasePreferenceController;
import com.android.settingslib.bluetooth.LocalBluetoothAdapter;
import com.android.settingslib.bluetooth.LocalBluetoothManager;
import com.android.settingslib.core.lifecycle.Lifecycle;
import com.android.settingslib.core.lifecycle.LifecycleObserver;
import com.android.settingslib.core.lifecycle.events.OnStart;
import com.android.settingslib.core.lifecycle.events.OnStop;
@@ -44,16 +43,16 @@ public class BluetoothDeviceNamePreferenceController extends BasePreferenceContr
        LifecycleObserver, OnStart, OnStop {
    private static final String TAG = "BluetoothNamePrefCtrl";

    public static final String KEY_DEVICE_NAME = "device_name";


    @VisibleForTesting
    Preference mPreference;
    private LocalBluetoothManager mLocalManager;
    private LocalBluetoothAdapter mLocalAdapter;

    public BluetoothDeviceNamePreferenceController(Context context, Lifecycle lifecycle) {
        this(context, (LocalBluetoothAdapter) null);
    /**
     * Constructor exclusively used for Slice.
     */
    public BluetoothDeviceNamePreferenceController(Context context, String preferenceKey) {
        super(context, preferenceKey);

        mLocalManager = Utils.getLocalBtManager(context);
        if (mLocalManager == null) {
@@ -61,22 +60,12 @@ public class BluetoothDeviceNamePreferenceController extends BasePreferenceContr
            return;
        }
        mLocalAdapter = mLocalManager.getBluetoothAdapter();

        if (lifecycle != null) {
            lifecycle.addObserver(this);
        }
    }

    /**
     * Constructor exclusively used for Slice.
     */
    public BluetoothDeviceNamePreferenceController(Context context) {
        this(context, (Lifecycle) null);
    }

    @VisibleForTesting
    BluetoothDeviceNamePreferenceController(Context context, LocalBluetoothAdapter localAdapter) {
        super(context, KEY_DEVICE_NAME);
    BluetoothDeviceNamePreferenceController(Context context, LocalBluetoothAdapter localAdapter,
            String preferenceKey) {
        super(context, preferenceKey);
        mLocalAdapter = localAdapter;
    }

@@ -102,11 +91,6 @@ public class BluetoothDeviceNamePreferenceController extends BasePreferenceContr
        return mLocalAdapter != null ? AVAILABLE : UNSUPPORTED_ON_DEVICE;
    }

    @Override
    public String getPreferenceKey() {
        return KEY_DEVICE_NAME;
    }

    @Override
    public void updateState(Preference preference) {
        updateDeviceName(preference);
@@ -134,7 +118,7 @@ public class BluetoothDeviceNamePreferenceController extends BasePreferenceContr
    public Preference createBluetoothDeviceNamePreference(PreferenceScreen screen, int order) {
        mPreference = new Preference(screen.getContext());
        mPreference.setOrder(order);
        mPreference.setKey(KEY_DEVICE_NAME);
        mPreference.setKey(getPreferenceKey());
        screen.addPreference(mPreference);

        return mPreference;
+15 −24
Original line number Diff line number Diff line
@@ -26,44 +26,35 @@ import com.android.internal.logging.nano.MetricsProto;
import com.android.settings.overlay.FeatureFactory;
import com.android.settingslib.bluetooth.LocalBluetoothAdapter;
import com.android.settingslib.core.instrumentation.MetricsFeatureProvider;
import com.android.settingslib.core.lifecycle.Lifecycle;

public class BluetoothDeviceRenamePreferenceController extends
        BluetoothDeviceNamePreferenceController {

    private final Fragment mFragment;
    private String mPrefKey;
    private Fragment mFragment;
    private MetricsFeatureProvider mMetricsFeatureProvider;

    public BluetoothDeviceRenamePreferenceController(Context context, String prefKey,
            Fragment fragment, Lifecycle lifecycle) {
        super(context, lifecycle);
        mPrefKey = prefKey;
        mFragment = fragment;
        mMetricsFeatureProvider = FeatureFactory.getFactory(context).getMetricsFeatureProvider();
    }

    /**
     * Constructor exclusively used for Slice.
     */
    public BluetoothDeviceRenamePreferenceController(Context context, String prefKey) {
        super(context, (Lifecycle) null);
        mPrefKey = prefKey;
        mFragment = null;
    public BluetoothDeviceRenamePreferenceController(Context context, String preferenceKey) {
        super(context, preferenceKey);
        mMetricsFeatureProvider = FeatureFactory.getFactory(context).getMetricsFeatureProvider();
    }

    @VisibleForTesting
    BluetoothDeviceRenamePreferenceController(Context context, String prefKey, Fragment fragment,
            LocalBluetoothAdapter localAdapter) {
        super(context, localAdapter);
        mPrefKey = prefKey;
        mFragment = fragment;
    BluetoothDeviceRenamePreferenceController(Context context, LocalBluetoothAdapter localAdapter,
            String preferenceKey) {
        super(context, localAdapter, preferenceKey);
        mMetricsFeatureProvider = FeatureFactory.getFactory(context).getMetricsFeatureProvider();
    }

    @Override
    public String getPreferenceKey() {
        return mPrefKey;
    /**
     * Set the {@link Fragment} that used to show {@link LocalDeviceNameDialogFragment}
     * in {@code handlePreferenceTreeClick}
     */
    @VisibleForTesting
    public void setFragment(Fragment fragment) {
        mFragment = fragment;
    }

    @Override
@@ -78,7 +69,7 @@ public class BluetoothDeviceRenamePreferenceController extends

    @Override
    public boolean handlePreferenceTreeClick(Preference preference) {
        if (TextUtils.equals(mPrefKey, preference.getKey()) && mFragment != null) {
        if (TextUtils.equals(getPreferenceKey(), preference.getKey()) && mFragment != null) {
            mMetricsFeatureProvider.action(mContext,
                    MetricsProto.MetricsEvent.ACTION_BLUETOOTH_RENAME);
            LocalDeviceNameDialogFragment.newInstance()
+6 −15
Original line number Diff line number Diff line
@@ -30,12 +30,8 @@ import com.android.settings.R;
import com.android.settings.search.Indexable;
import com.android.settingslib.bluetooth.BluetoothDeviceFilter;
import com.android.settingslib.bluetooth.CachedBluetoothDevice;
import com.android.settingslib.core.AbstractPreferenceController;
import com.android.settingslib.widget.FooterPreference;

import java.util.ArrayList;
import java.util.List;

/**
 * BluetoothPairingDetail is a page to scan bluetooth devices and pair them.
 */
@@ -47,7 +43,6 @@ public class BluetoothPairingDetail extends DeviceListPreferenceFragment impleme
    static final String KEY_AVAIL_DEVICES = "available_devices";
    @VisibleForTesting
    static final String KEY_FOOTER_PREF = "footer_preference";
    private static final String KEY_RENAME_DEVICES = "bt_pair_rename_devices";

    @VisibleForTesting
    BluetoothProgressCategory mAvailableDevicesCategory;
@@ -80,6 +75,12 @@ public class BluetoothPairingDetail extends DeviceListPreferenceFragment impleme
        mAvailableDevicesCategory.setProgress(mLocalAdapter.isDiscovering());
    }

    @Override
    public void onAttach(Context context) {
        super.onAttach(context);
        use(BluetoothDeviceRenamePreferenceController.class).setFragment(this);
    }

    @VisibleForTesting
    void updateBluetooth() {
        if (mLocalAdapter.isEnabled()) {
@@ -199,16 +200,6 @@ public class BluetoothPairingDetail extends DeviceListPreferenceFragment impleme
        return R.xml.bluetooth_pairing_detail;
    }

    @Override
    protected List<AbstractPreferenceController> createPreferenceControllers(Context context) {
        final List<AbstractPreferenceController> controllers = new ArrayList<>();
        controllers.add(
                new BluetoothDeviceRenamePreferenceController(context, KEY_RENAME_DEVICES, this,
                        getLifecycle()));

        return controllers;
    }

    @Override
    public String getDeviceListKey() {
        return KEY_AVAIL_DEVICES;
Loading