Loading core/java/android/bluetooth/BluetoothA2dp.java +114 −0 Original line number Diff line number Diff line Loading @@ -136,6 +136,38 @@ public final class BluetoothA2dp implements BluetoothProfile { */ public static final int STATE_NOT_PLAYING = 11; /** * We don't have a stored preference for whether or not the given A2DP sink device supports * optional codecs. * @hide */ public static final int OPTIONAL_CODECS_SUPPORT_UNKNOWN = -1; /** * The given A2DP sink device does not support optional codecs. * @hide */ public static final int OPTIONAL_CODECS_NOT_SUPPORTED = 0; /** * The given A2DP sink device does support optional codecs. * @hide */ public static final int OPTIONAL_CODECS_SUPPORTED = 1; /** * We don't have a stored preference for whether optional codecs should be enabled or disabled * for the given A2DP device. * @hide */ public static final int OPTIONAL_CODECS_PREF_UNKNOWN = -1; /** * Optional codecs should be disabled for the given A2DP device. * @hide */ public static final int OPTIONAL_CODECS_PREF_DISABLED = 0; /** * Optional codecs should be enabled for the given A2DP device. * @hide */ public static final int OPTIONAL_CODECS_PREF_ENABLED = 1; private Context mContext; private ServiceListener mServiceListener; private final ReentrantReadWriteLock mServiceLock = new ReentrantReadWriteLock(); Loading Loading @@ -654,6 +686,88 @@ public final class BluetoothA2dp implements BluetoothProfile { } } /** * Returns whether this device supports optional codecs. * * @param device The device to check * @return one of OPTIONAL_CODECS_SUPPORT_UNKNOWN, OPTIONAL_CODECS_NOT_SUPPORTED, or * OPTIONAL_CODECS_SUPPORTED. * * @hide */ public int supportsOptionalCodecs(BluetoothDevice device) { try { mServiceLock.readLock().lock(); if (mService != null && isEnabled() && isValidDevice(device)) { return mService.supportsOptionalCodecs(device); } if (mService == null) Log.w(TAG, "Proxy not attached to service"); return OPTIONAL_CODECS_SUPPORT_UNKNOWN; } catch (RemoteException e) { Log.e(TAG, "Error talking to BT service in getSupportsOptionalCodecs()", e); return OPTIONAL_CODECS_SUPPORT_UNKNOWN; } finally { mServiceLock.readLock().unlock(); } } /** * Returns whether this device should have optional codecs enabled. * * @param device The device in question. * @return one of OPTIONAL_CODECS_PREF_UNKNOWN, OPTIONAL_CODECS_PREF_ENABLED, or * OPTIONAL_CODECS_PREF_DISABLED. * * @hide */ public int getOptionalCodecsEnabled(BluetoothDevice device) { try { mServiceLock.readLock().lock(); if (mService != null && isEnabled() && isValidDevice(device)) { return mService.getOptionalCodecsEnabled(device); } if (mService == null) Log.w(TAG, "Proxy not attached to service"); return OPTIONAL_CODECS_PREF_UNKNOWN; } catch (RemoteException e) { Log.e(TAG, "Error talking to BT service in getSupportsOptionalCodecs()", e); return OPTIONAL_CODECS_PREF_UNKNOWN; } finally { mServiceLock.readLock().unlock(); } } /** * Sets a persistent preference for whether a given device should have optional codecs enabled. * * @param device The device to set this preference for. * @param value Whether the optional codecs should be enabled for this device. This should be * one of OPTIONAL_CODECS_PREF_UNKNOWN, OPTIONAL_CODECS_PREF_ENABLED, or * OPTIONAL_CODECS_PREF_DISABLED. * @hide */ public void setOptionalCodecsEnabled(BluetoothDevice device, int value) { try { if (value != BluetoothA2dp.OPTIONAL_CODECS_PREF_UNKNOWN && value != BluetoothA2dp.OPTIONAL_CODECS_PREF_DISABLED && value != BluetoothA2dp.OPTIONAL_CODECS_PREF_ENABLED) { Log.e(TAG, "Invalid value passed to setOptionalCodecsEnabled: " + value); return; } mServiceLock.readLock().lock(); if (mService != null && isEnabled() && isValidDevice(device)) { mService.setOptionalCodecsEnabled(device, value); } if (mService == null) Log.w(TAG, "Proxy not attached to service"); return; } catch (RemoteException e) { Log.e(TAG, "Stack:" + Log.getStackTraceString(new Throwable())); return; } finally { mServiceLock.readLock().unlock(); } } /** * Helper for converting a state to a string. * Loading core/java/android/bluetooth/IBluetoothA2dp.aidl +3 −0 Original line number Diff line number Diff line Loading @@ -42,4 +42,7 @@ interface IBluetoothA2dp { oneway void setCodecConfigPreference(in BluetoothCodecConfig codecConfig); oneway void enableOptionalCodecs(); oneway void disableOptionalCodecs(); int supportsOptionalCodecs(in BluetoothDevice device); int getOptionalCodecsEnabled(in BluetoothDevice device); oneway void setOptionalCodecsEnabled(in BluetoothDevice device, int value); } core/java/android/provider/Settings.java +25 −0 Original line number Diff line number Diff line Loading @@ -8981,6 +8981,12 @@ public final class Settings { public static final String BLUETOOTH_A2DP_SRC_PRIORITY_PREFIX = "bluetooth_a2dp_src_priority_"; /** {@hide} */ public static final String BLUETOOTH_A2DP_SUPPORTS_OPTIONAL_CODECS_PREFIX = "bluetooth_a2dp_supports_optional_codecs_"; /** {@hide} */ public static final String BLUETOOTH_A2DP_OPTIONAL_CODECS_ENABLED_PREFIX = "bluetooth_a2dp_optional_codecs_enabled_"; /** {@hide} */ public static final String BLUETOOTH_INPUT_DEVICE_PRIORITY_PREFIX = "bluetooth_input_device_priority_"; /** {@hide} */ Loading Loading @@ -9246,6 +9252,25 @@ public final class Settings { return BLUETOOTH_A2DP_SRC_PRIORITY_PREFIX + address.toUpperCase(Locale.ROOT); } /** * Get the key that retrieves a bluetooth a2dp device's ability to support optional codecs. * @hide */ public static final String getBluetoothA2dpSupportsOptionalCodecsKey(String address) { return BLUETOOTH_A2DP_SUPPORTS_OPTIONAL_CODECS_PREFIX + address.toUpperCase(Locale.ROOT); } /** * Get the key that retrieves whether a bluetooth a2dp device should have optional codecs * enabled. * @hide */ public static final String getBluetoothA2dpOptionalCodecsEnabledKey(String address) { return BLUETOOTH_A2DP_OPTIONAL_CODECS_ENABLED_PREFIX + address.toUpperCase(Locale.ROOT); } /** * Get the key that retrieves a bluetooth Input Device's priority. * @hide Loading core/proto/android/providers/settings.proto +2 −0 Original line number Diff line number Diff line Loading @@ -329,6 +329,8 @@ message GlobalSettingsProto { SettingProto max_notification_enqueue_rate = 284; SettingProto cell_on = 285; SettingProto network_recommendations_package = 286; SettingProto bluetooth_a2dp_supports_optional_codecs_prefix = 287; SettingProto bluetooth_a2dp_optional_codecs_enabled_prefix = 288; } message SecureSettingsProto { Loading core/tests/coretests/src/android/provider/SettingsBackupTest.java +2 −0 Original line number Diff line number Diff line Loading @@ -109,6 +109,8 @@ public class SettingsBackupTest { Settings.Global.BLE_SCAN_ALWAYS_AVAILABLE, Settings.Global.BLUETOOTH_A2DP_SINK_PRIORITY_PREFIX, Settings.Global.BLUETOOTH_A2DP_SRC_PRIORITY_PREFIX, Settings.Global.BLUETOOTH_A2DP_SUPPORTS_OPTIONAL_CODECS_PREFIX, Settings.Global.BLUETOOTH_A2DP_OPTIONAL_CODECS_ENABLED_PREFIX, Settings.Global.BLUETOOTH_DISABLED_PROFILES, Settings.Global.BLUETOOTH_HEADSET_PRIORITY_PREFIX, Settings.Global.BLUETOOTH_INPUT_DEVICE_PRIORITY_PREFIX, Loading Loading
core/java/android/bluetooth/BluetoothA2dp.java +114 −0 Original line number Diff line number Diff line Loading @@ -136,6 +136,38 @@ public final class BluetoothA2dp implements BluetoothProfile { */ public static final int STATE_NOT_PLAYING = 11; /** * We don't have a stored preference for whether or not the given A2DP sink device supports * optional codecs. * @hide */ public static final int OPTIONAL_CODECS_SUPPORT_UNKNOWN = -1; /** * The given A2DP sink device does not support optional codecs. * @hide */ public static final int OPTIONAL_CODECS_NOT_SUPPORTED = 0; /** * The given A2DP sink device does support optional codecs. * @hide */ public static final int OPTIONAL_CODECS_SUPPORTED = 1; /** * We don't have a stored preference for whether optional codecs should be enabled or disabled * for the given A2DP device. * @hide */ public static final int OPTIONAL_CODECS_PREF_UNKNOWN = -1; /** * Optional codecs should be disabled for the given A2DP device. * @hide */ public static final int OPTIONAL_CODECS_PREF_DISABLED = 0; /** * Optional codecs should be enabled for the given A2DP device. * @hide */ public static final int OPTIONAL_CODECS_PREF_ENABLED = 1; private Context mContext; private ServiceListener mServiceListener; private final ReentrantReadWriteLock mServiceLock = new ReentrantReadWriteLock(); Loading Loading @@ -654,6 +686,88 @@ public final class BluetoothA2dp implements BluetoothProfile { } } /** * Returns whether this device supports optional codecs. * * @param device The device to check * @return one of OPTIONAL_CODECS_SUPPORT_UNKNOWN, OPTIONAL_CODECS_NOT_SUPPORTED, or * OPTIONAL_CODECS_SUPPORTED. * * @hide */ public int supportsOptionalCodecs(BluetoothDevice device) { try { mServiceLock.readLock().lock(); if (mService != null && isEnabled() && isValidDevice(device)) { return mService.supportsOptionalCodecs(device); } if (mService == null) Log.w(TAG, "Proxy not attached to service"); return OPTIONAL_CODECS_SUPPORT_UNKNOWN; } catch (RemoteException e) { Log.e(TAG, "Error talking to BT service in getSupportsOptionalCodecs()", e); return OPTIONAL_CODECS_SUPPORT_UNKNOWN; } finally { mServiceLock.readLock().unlock(); } } /** * Returns whether this device should have optional codecs enabled. * * @param device The device in question. * @return one of OPTIONAL_CODECS_PREF_UNKNOWN, OPTIONAL_CODECS_PREF_ENABLED, or * OPTIONAL_CODECS_PREF_DISABLED. * * @hide */ public int getOptionalCodecsEnabled(BluetoothDevice device) { try { mServiceLock.readLock().lock(); if (mService != null && isEnabled() && isValidDevice(device)) { return mService.getOptionalCodecsEnabled(device); } if (mService == null) Log.w(TAG, "Proxy not attached to service"); return OPTIONAL_CODECS_PREF_UNKNOWN; } catch (RemoteException e) { Log.e(TAG, "Error talking to BT service in getSupportsOptionalCodecs()", e); return OPTIONAL_CODECS_PREF_UNKNOWN; } finally { mServiceLock.readLock().unlock(); } } /** * Sets a persistent preference for whether a given device should have optional codecs enabled. * * @param device The device to set this preference for. * @param value Whether the optional codecs should be enabled for this device. This should be * one of OPTIONAL_CODECS_PREF_UNKNOWN, OPTIONAL_CODECS_PREF_ENABLED, or * OPTIONAL_CODECS_PREF_DISABLED. * @hide */ public void setOptionalCodecsEnabled(BluetoothDevice device, int value) { try { if (value != BluetoothA2dp.OPTIONAL_CODECS_PREF_UNKNOWN && value != BluetoothA2dp.OPTIONAL_CODECS_PREF_DISABLED && value != BluetoothA2dp.OPTIONAL_CODECS_PREF_ENABLED) { Log.e(TAG, "Invalid value passed to setOptionalCodecsEnabled: " + value); return; } mServiceLock.readLock().lock(); if (mService != null && isEnabled() && isValidDevice(device)) { mService.setOptionalCodecsEnabled(device, value); } if (mService == null) Log.w(TAG, "Proxy not attached to service"); return; } catch (RemoteException e) { Log.e(TAG, "Stack:" + Log.getStackTraceString(new Throwable())); return; } finally { mServiceLock.readLock().unlock(); } } /** * Helper for converting a state to a string. * Loading
core/java/android/bluetooth/IBluetoothA2dp.aidl +3 −0 Original line number Diff line number Diff line Loading @@ -42,4 +42,7 @@ interface IBluetoothA2dp { oneway void setCodecConfigPreference(in BluetoothCodecConfig codecConfig); oneway void enableOptionalCodecs(); oneway void disableOptionalCodecs(); int supportsOptionalCodecs(in BluetoothDevice device); int getOptionalCodecsEnabled(in BluetoothDevice device); oneway void setOptionalCodecsEnabled(in BluetoothDevice device, int value); }
core/java/android/provider/Settings.java +25 −0 Original line number Diff line number Diff line Loading @@ -8981,6 +8981,12 @@ public final class Settings { public static final String BLUETOOTH_A2DP_SRC_PRIORITY_PREFIX = "bluetooth_a2dp_src_priority_"; /** {@hide} */ public static final String BLUETOOTH_A2DP_SUPPORTS_OPTIONAL_CODECS_PREFIX = "bluetooth_a2dp_supports_optional_codecs_"; /** {@hide} */ public static final String BLUETOOTH_A2DP_OPTIONAL_CODECS_ENABLED_PREFIX = "bluetooth_a2dp_optional_codecs_enabled_"; /** {@hide} */ public static final String BLUETOOTH_INPUT_DEVICE_PRIORITY_PREFIX = "bluetooth_input_device_priority_"; /** {@hide} */ Loading Loading @@ -9246,6 +9252,25 @@ public final class Settings { return BLUETOOTH_A2DP_SRC_PRIORITY_PREFIX + address.toUpperCase(Locale.ROOT); } /** * Get the key that retrieves a bluetooth a2dp device's ability to support optional codecs. * @hide */ public static final String getBluetoothA2dpSupportsOptionalCodecsKey(String address) { return BLUETOOTH_A2DP_SUPPORTS_OPTIONAL_CODECS_PREFIX + address.toUpperCase(Locale.ROOT); } /** * Get the key that retrieves whether a bluetooth a2dp device should have optional codecs * enabled. * @hide */ public static final String getBluetoothA2dpOptionalCodecsEnabledKey(String address) { return BLUETOOTH_A2DP_OPTIONAL_CODECS_ENABLED_PREFIX + address.toUpperCase(Locale.ROOT); } /** * Get the key that retrieves a bluetooth Input Device's priority. * @hide Loading
core/proto/android/providers/settings.proto +2 −0 Original line number Diff line number Diff line Loading @@ -329,6 +329,8 @@ message GlobalSettingsProto { SettingProto max_notification_enqueue_rate = 284; SettingProto cell_on = 285; SettingProto network_recommendations_package = 286; SettingProto bluetooth_a2dp_supports_optional_codecs_prefix = 287; SettingProto bluetooth_a2dp_optional_codecs_enabled_prefix = 288; } message SecureSettingsProto { Loading
core/tests/coretests/src/android/provider/SettingsBackupTest.java +2 −0 Original line number Diff line number Diff line Loading @@ -109,6 +109,8 @@ public class SettingsBackupTest { Settings.Global.BLE_SCAN_ALWAYS_AVAILABLE, Settings.Global.BLUETOOTH_A2DP_SINK_PRIORITY_PREFIX, Settings.Global.BLUETOOTH_A2DP_SRC_PRIORITY_PREFIX, Settings.Global.BLUETOOTH_A2DP_SUPPORTS_OPTIONAL_CODECS_PREFIX, Settings.Global.BLUETOOTH_A2DP_OPTIONAL_CODECS_ENABLED_PREFIX, Settings.Global.BLUETOOTH_DISABLED_PROFILES, Settings.Global.BLUETOOTH_HEADSET_PRIORITY_PREFIX, Settings.Global.BLUETOOTH_INPUT_DEVICE_PRIORITY_PREFIX, Loading