Merge "Use BluetoothUtils.isAdvancedDetailsHeader in Header controllers."

This commit is contained in:
Vania Januar
2023-02-08 09:36:56 +00:00
committed by Android (Google) Code Review
4 changed files with 3 additions and 39 deletions

View File

@@ -126,7 +126,7 @@ public class AdvancedBluetoothDetailsHeaderController extends BasePreferenceCont
if (mCachedDevice == null) { if (mCachedDevice == null) {
return CONDITIONALLY_UNAVAILABLE; return CONDITIONALLY_UNAVAILABLE;
} }
return Utils.isAdvancedDetailsHeader(mCachedDevice.getDevice()) return BluetoothUtils.isAdvancedDetailsHeader(mCachedDevice.getDevice())
? AVAILABLE : CONDITIONALLY_UNAVAILABLE; ? AVAILABLE : CONDITIONALLY_UNAVAILABLE;
} }

View File

@@ -57,7 +57,7 @@ public class BluetoothDetailsHeaderController extends BluetoothDetailsController
boolean hasLeAudio = mCachedDevice.getConnectableProfiles() boolean hasLeAudio = mCachedDevice.getConnectableProfiles()
.stream() .stream()
.anyMatch(profile -> profile.getProfileId() == BluetoothProfile.LE_AUDIO); .anyMatch(profile -> profile.getProfileId() == BluetoothProfile.LE_AUDIO);
return !Utils.isAdvancedDetailsHeader(mCachedDevice.getDevice()) && !hasLeAudio; return !BluetoothUtils.isAdvancedDetailsHeader(mCachedDevice.getDevice()) && !hasLeAudio;
} }
@Override @Override

View File

@@ -111,7 +111,7 @@ public class LeAudioBluetoothDetailsHeaderController extends BasePreferenceContr
.stream() .stream()
.anyMatch(profile -> profile.getProfileId() == BluetoothProfile.LE_AUDIO); .anyMatch(profile -> profile.getProfileId() == BluetoothProfile.LE_AUDIO);
return !Utils.isAdvancedDetailsHeader(mCachedDevice.getDevice()) && hasLeAudio return !BluetoothUtils.isAdvancedDetailsHeader(mCachedDevice.getDevice()) && hasLeAudio
? AVAILABLE : CONDITIONALLY_UNAVAILABLE; ? AVAILABLE : CONDITIONALLY_UNAVAILABLE;
} }

View File

@@ -28,18 +28,14 @@ import android.content.pm.PackageInfo;
import android.content.pm.PackageManager; import android.content.pm.PackageManager;
import android.content.pm.PackageManager.NameNotFoundException; import android.content.pm.PackageManager.NameNotFoundException;
import android.os.UserHandle; import android.os.UserHandle;
import android.provider.DeviceConfig;
import android.provider.Settings; import android.provider.Settings;
import android.text.TextUtils;
import android.util.Log; import android.util.Log;
import android.widget.Toast; import android.widget.Toast;
import androidx.annotation.NonNull;
import androidx.annotation.VisibleForTesting; import androidx.annotation.VisibleForTesting;
import androidx.appcompat.app.AlertDialog; import androidx.appcompat.app.AlertDialog;
import com.android.settings.R; import com.android.settings.R;
import com.android.settings.core.SettingsUIDeviceConfig;
import com.android.settings.overlay.FeatureFactory; import com.android.settings.overlay.FeatureFactory;
import com.android.settingslib.bluetooth.BluetoothUtils; import com.android.settingslib.bluetooth.BluetoothUtils;
import com.android.settingslib.bluetooth.BluetoothUtils.ErrorListener; import com.android.settingslib.bluetooth.BluetoothUtils.ErrorListener;
@@ -165,38 +161,6 @@ public final class Utils {
Settings.Global.BLE_SCAN_ALWAYS_AVAILABLE, 0) == 1; Settings.Global.BLE_SCAN_ALWAYS_AVAILABLE, 0) == 1;
} }
/**
* Check if the Bluetooth device supports advanced details header
*
* @param bluetoothDevice the BluetoothDevice to get metadata
* @return true if it supports advanced details header, false otherwise.
*/
public static boolean isAdvancedDetailsHeader(@NonNull BluetoothDevice bluetoothDevice) {
final boolean advancedEnabled = DeviceConfig.getBoolean(DeviceConfig.NAMESPACE_SETTINGS_UI,
SettingsUIDeviceConfig.BT_ADVANCED_HEADER_ENABLED, true);
if (!advancedEnabled) {
Log.d(TAG, "isAdvancedDetailsHeader: advancedEnabled is false");
return false;
}
// The metadata is for Android R
final boolean untetheredHeadset = BluetoothUtils.getBooleanMetaData(bluetoothDevice,
BluetoothDevice.METADATA_IS_UNTETHERED_HEADSET);
if (untetheredHeadset) {
Log.d(TAG, "isAdvancedDetailsHeader: untetheredHeadset is true");
return true;
}
// The metadata is for Android S
final String deviceType = BluetoothUtils.getStringMetaData(bluetoothDevice,
BluetoothDevice.METADATA_DEVICE_TYPE);
if (TextUtils.equals(deviceType, BluetoothDevice.DEVICE_TYPE_UNTETHERED_HEADSET)
|| TextUtils.equals(deviceType, BluetoothDevice.DEVICE_TYPE_WATCH)
|| TextUtils.equals(deviceType, BluetoothDevice.DEVICE_TYPE_DEFAULT)) {
Log.d(TAG, "isAdvancedDetailsHeader: deviceType is " + deviceType);
return true;
}
return false;
}
/** /**
* Returns the Bluetooth Package name * Returns the Bluetooth Package name
*/ */