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

Commit 76d8145f authored by Haijie Hong's avatar Haijie Hong
Browse files

Add BT extra options in device details page

Bug: 319562236
Test: make RunSettingsRoboTests ROBOTEST_FILTER=BluetoothDetailsExtraOptionsControllerTest
Change-Id: Ifab39d2bd19044d60f090f4a0419d1e20b2ad925
parent dea44ebf
Loading
Loading
Loading
Loading
+3 −0
Original line number Diff line number Diff line
@@ -80,6 +80,9 @@
    <PreferenceCategory
        android:key="bluetooth_profiles"/>

    <PreferenceCategory
        android:key="bt_extra_options"/>

    <PreferenceCategory
        android:key="bluetooth_related_tools"
        android:title="@string/bluetooth_screen_related">
+88 −0
Original line number Diff line number Diff line
/*
 * Copyright (C) 2024 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.bluetooth;

import android.content.Context;

import androidx.annotation.Nullable;
import androidx.annotation.VisibleForTesting;
import androidx.preference.Preference;
import androidx.preference.PreferenceCategory;
import androidx.preference.PreferenceFragmentCompat;
import androidx.preference.PreferenceScreen;

import com.android.settings.overlay.FeatureFactory;
import com.android.settingslib.bluetooth.CachedBluetoothDevice;
import com.android.settingslib.core.lifecycle.Lifecycle;
import com.android.settingslib.utils.ThreadUtils;

import dagger.internal.Preconditions;

import java.util.List;

public class BluetoothDetailsExtraOptionsController extends BluetoothDetailsController {

    private static final String KEY_BLUETOOTH_EXTRA_OPTIONS = "bt_extra_options";

    @VisibleForTesting @Nullable
    PreferenceCategory mOptionsContainer;
    @Nullable PreferenceScreen mPreferenceScreen;

    public BluetoothDetailsExtraOptionsController(
            Context context,
            PreferenceFragmentCompat fragment,
            CachedBluetoothDevice device,
            Lifecycle lifecycle) {
        super(context, fragment, device, lifecycle);
    }

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

    @Override
    protected void init(PreferenceScreen screen) {
        mPreferenceScreen = screen;
        mOptionsContainer = screen.findPreference(getPreferenceKey());
        refresh();
    }

    @Override
    protected void refresh() {
        ThreadUtils.postOnBackgroundThread(
                () -> {
                    List<Preference> options =
                            FeatureFactory.getFeatureFactory()
                                    .getBluetoothFeatureProvider()
                                    .getBluetoothExtraOptions(mContext, mCachedDevice);
                    ThreadUtils.postOnMainThread(
                            () -> {
                                if (mOptionsContainer != null) {
                                    mOptionsContainer.removeAll();
                                    for (Preference option : options) {
                                        mOptionsContainer.addPreference(option);
                                    }
                                    setVisible(
                                            Preconditions.checkNotNull(mPreferenceScreen),
                                            getPreferenceKey(),
                                            !options.isEmpty());
                                }
                            });
                });
    }
}
+3 −0
Original line number Diff line number Diff line
@@ -328,6 +328,9 @@ public class BluetoothDeviceDetailsFragment extends RestrictedDashboardFragment
                    mCachedDevice, lifecycle));
            controllers.add(new BluetoothDetailsDataSyncController(context, this,
                    mCachedDevice, lifecycle));
            controllers.add(
                    new BluetoothDetailsExtraOptionsController(
                            context, this, mCachedDevice, lifecycle));
        }
        return controllers;
    }
+13 −0
Original line number Diff line number Diff line
@@ -22,6 +22,10 @@ import android.content.Context;
import android.media.Spatializer;
import android.net.Uri;

import androidx.preference.Preference;

import com.android.settingslib.bluetooth.CachedBluetoothDevice;

import java.util.List;

/**
@@ -60,4 +64,13 @@ public interface BluetoothFeatureProvider {
     * @return the Spatializer instance
     */
    Spatializer getSpatializer(Context context);

    /**
     * Gets bluetooth device extra options
     *
     * @param context Context
     * @param device the bluetooth device
     * @return the extra bluetooth preference list
     */
    List<Preference> getBluetoothExtraOptions(Context context, CachedBluetoothDevice device);
}
+11 −0
Original line number Diff line number Diff line
@@ -23,7 +23,12 @@ import android.media.AudioManager;
import android.media.Spatializer;
import android.net.Uri;

import androidx.preference.Preference;

import com.android.settingslib.bluetooth.BluetoothUtils;
import com.android.settingslib.bluetooth.CachedBluetoothDevice;

import com.google.common.collect.ImmutableList;

import java.util.List;

@@ -54,4 +59,10 @@ public class BluetoothFeatureProviderImpl implements BluetoothFeatureProvider {
        AudioManager audioManager = context.getSystemService(AudioManager.class);
        return audioManager.getSpatializer();
    }

    @Override
    public List<Preference> getBluetoothExtraOptions(Context context,
            CachedBluetoothDevice device) {
        return ImmutableList.of();
    }
}
Loading