Loading android/app/src/com/android/bluetooth/btservice/PhonePolicy.java +24 −7 Original line number Original line Diff line number Diff line Loading @@ -175,10 +175,7 @@ public class PhonePolicy implements AdapterService.BluetoothStateCallback { PhonePolicy(AdapterService service, ServiceFactory factory) { PhonePolicy(AdapterService service, ServiceFactory factory) { mAdapterService = service; mAdapterService = service; mDatabaseManager = mDatabaseManager = Objects.requireNonNull(service.getDatabase()); Objects.requireNonNull( mAdapterService.getDatabase(), "DatabaseManager cannot be null when PhonePolicy starts"); mFactory = factory; mFactory = factory; mHandler = new PhonePolicyHandler(service.getMainLooper()); mHandler = new PhonePolicyHandler(service.getMainLooper()); mAutoConnectProfilesSupported = mAutoConnectProfilesSupported = Loading Loading @@ -285,6 +282,23 @@ public class PhonePolicy implements AdapterService.BluetoothStateCallback { return isLeAudioOnlyGroup(device); return isLeAudioOnlyGroup(device); } } // return true if device support Hearing Access Service and it has not been manually disabled private boolean shouldEnableHapByDefault(BluetoothDevice device, ParcelUuid[] uuids) { if (!Flags.enableHapByDefault()) { Log.i(TAG, "shouldDefaultToHap: Flag enableHapByDefault is disabled"); return false; } HapClientService hap = mFactory.getHapClientService(); if (hap == null) { Log.e(TAG, "shouldDefaultToHap: HapClient is null"); return false; } return Utils.arrayContains(uuids, BluetoothUuid.HAS) && hap.getConnectionPolicy(device) != BluetoothProfile.CONNECTION_POLICY_FORBIDDEN; } // Policy implementation, all functions MUST be private // Policy implementation, all functions MUST be private @RequiresPermission(android.Manifest.permission.BLUETOOTH_PRIVILEGED) @RequiresPermission(android.Manifest.permission.BLUETOOTH_PRIVILEGED) private void processInitProfilePriorities(BluetoothDevice device, ParcelUuid[] uuids) { private void processInitProfilePriorities(BluetoothDevice device, ParcelUuid[] uuids) { Loading @@ -306,6 +320,7 @@ public class PhonePolicy implements AdapterService.BluetoothStateCallback { SystemProperties.getBoolean(BYPASS_LE_AUDIO_ALLOWLIST_PROPERTY, false); SystemProperties.getBoolean(BYPASS_LE_AUDIO_ALLOWLIST_PROPERTY, false); boolean isLeAudioOnly = isLeAudioOnlyDevice(device, uuids); boolean isLeAudioOnly = isLeAudioOnlyDevice(device, uuids); boolean shouldEnableHapByDefault = shouldEnableHapByDefault(device, uuids); boolean isLeAudioProfileAllowed = boolean isLeAudioProfileAllowed = (leAudioService != null) (leAudioService != null) && Utils.arrayContains(uuids, BluetoothUuid.LE_AUDIO) && Utils.arrayContains(uuids, BluetoothUuid.LE_AUDIO) Loading @@ -313,9 +328,9 @@ public class PhonePolicy implements AdapterService.BluetoothStateCallback { != BluetoothProfile.CONNECTION_POLICY_FORBIDDEN) != BluetoothProfile.CONNECTION_POLICY_FORBIDDEN) && (mLeAudioEnabledByDefault || isDualModeAudioEnabled()) && (mLeAudioEnabledByDefault || isDualModeAudioEnabled()) && (isBypassLeAudioAllowlist && (isBypassLeAudioAllowlist || shouldEnableHapByDefault || mAdapterService.isLeAudioAllowed(device) || mAdapterService.isLeAudioAllowed(device) || isLeAudioOnly); || isLeAudioOnly); debugLog( debugLog( "mLeAudioEnabledByDefault: " "mLeAudioEnabledByDefault: " + mLeAudioEnabledByDefault + mLeAudioEnabledByDefault Loading @@ -328,7 +343,9 @@ public class PhonePolicy implements AdapterService.BluetoothStateCallback { + ", isLeAudioProfileAllowed: " + ", isLeAudioProfileAllowed: " + isLeAudioProfileAllowed + isLeAudioProfileAllowed + ", isLeAudioOnly: " + ", isLeAudioOnly: " + isLeAudioOnly); + isLeAudioOnly + ", shouldEnableHapByDefault: " + shouldEnableHapByDefault); // Set profile priorities only for the profiles discovered on the remote device. // Set profile priorities only for the profiles discovered on the remote device. // This avoids needless auto-connect attempts to profiles non-existent on the remote device // This avoids needless auto-connect attempts to profiles non-existent on the remote device Loading Loading @@ -516,7 +533,7 @@ public class PhonePolicy implements AdapterService.BluetoothStateCallback { && (hearingAidService.getConnectionPolicy(device) && (hearingAidService.getConnectionPolicy(device) == BluetoothProfile.CONNECTION_POLICY_UNKNOWN)) { == BluetoothProfile.CONNECTION_POLICY_UNKNOWN)) { if (isLeAudioProfileAllowed) { if (isLeAudioProfileAllowed) { debugLog("LE Audio preferred over ASHA for device " + device); Log.i(TAG, "LE Audio preferred over ASHA for device " + device); mAdapterService mAdapterService .getDatabase() .getDatabase() .setProfileConnectionPolicy( .setProfileConnectionPolicy( Loading flags/hap.aconfig +7 −1 Original line number Original line Diff line number Diff line package: "com.android.bluetooth.flags" package: "com.android.bluetooth.flags" container: "com.android.btservices" container: "com.android.btservices" flag { name: "enable_hap_by_default" namespace: "bluetooth" description: "On device that support HAP, enable it by default and disable ASHA" bug: "345826775" } flag { flag { name: "settings_can_control_hap_preset" name: "settings_can_control_hap_preset" is_exported: true is_exported: true Loading @@ -8,4 +15,3 @@ flag { description: "Allow user to control the preset of hearing aid devices" description: "Allow user to control the preset of hearing aid devices" bug: "306236481" bug: "306236481" } } Loading
android/app/src/com/android/bluetooth/btservice/PhonePolicy.java +24 −7 Original line number Original line Diff line number Diff line Loading @@ -175,10 +175,7 @@ public class PhonePolicy implements AdapterService.BluetoothStateCallback { PhonePolicy(AdapterService service, ServiceFactory factory) { PhonePolicy(AdapterService service, ServiceFactory factory) { mAdapterService = service; mAdapterService = service; mDatabaseManager = mDatabaseManager = Objects.requireNonNull(service.getDatabase()); Objects.requireNonNull( mAdapterService.getDatabase(), "DatabaseManager cannot be null when PhonePolicy starts"); mFactory = factory; mFactory = factory; mHandler = new PhonePolicyHandler(service.getMainLooper()); mHandler = new PhonePolicyHandler(service.getMainLooper()); mAutoConnectProfilesSupported = mAutoConnectProfilesSupported = Loading Loading @@ -285,6 +282,23 @@ public class PhonePolicy implements AdapterService.BluetoothStateCallback { return isLeAudioOnlyGroup(device); return isLeAudioOnlyGroup(device); } } // return true if device support Hearing Access Service and it has not been manually disabled private boolean shouldEnableHapByDefault(BluetoothDevice device, ParcelUuid[] uuids) { if (!Flags.enableHapByDefault()) { Log.i(TAG, "shouldDefaultToHap: Flag enableHapByDefault is disabled"); return false; } HapClientService hap = mFactory.getHapClientService(); if (hap == null) { Log.e(TAG, "shouldDefaultToHap: HapClient is null"); return false; } return Utils.arrayContains(uuids, BluetoothUuid.HAS) && hap.getConnectionPolicy(device) != BluetoothProfile.CONNECTION_POLICY_FORBIDDEN; } // Policy implementation, all functions MUST be private // Policy implementation, all functions MUST be private @RequiresPermission(android.Manifest.permission.BLUETOOTH_PRIVILEGED) @RequiresPermission(android.Manifest.permission.BLUETOOTH_PRIVILEGED) private void processInitProfilePriorities(BluetoothDevice device, ParcelUuid[] uuids) { private void processInitProfilePriorities(BluetoothDevice device, ParcelUuid[] uuids) { Loading @@ -306,6 +320,7 @@ public class PhonePolicy implements AdapterService.BluetoothStateCallback { SystemProperties.getBoolean(BYPASS_LE_AUDIO_ALLOWLIST_PROPERTY, false); SystemProperties.getBoolean(BYPASS_LE_AUDIO_ALLOWLIST_PROPERTY, false); boolean isLeAudioOnly = isLeAudioOnlyDevice(device, uuids); boolean isLeAudioOnly = isLeAudioOnlyDevice(device, uuids); boolean shouldEnableHapByDefault = shouldEnableHapByDefault(device, uuids); boolean isLeAudioProfileAllowed = boolean isLeAudioProfileAllowed = (leAudioService != null) (leAudioService != null) && Utils.arrayContains(uuids, BluetoothUuid.LE_AUDIO) && Utils.arrayContains(uuids, BluetoothUuid.LE_AUDIO) Loading @@ -313,9 +328,9 @@ public class PhonePolicy implements AdapterService.BluetoothStateCallback { != BluetoothProfile.CONNECTION_POLICY_FORBIDDEN) != BluetoothProfile.CONNECTION_POLICY_FORBIDDEN) && (mLeAudioEnabledByDefault || isDualModeAudioEnabled()) && (mLeAudioEnabledByDefault || isDualModeAudioEnabled()) && (isBypassLeAudioAllowlist && (isBypassLeAudioAllowlist || shouldEnableHapByDefault || mAdapterService.isLeAudioAllowed(device) || mAdapterService.isLeAudioAllowed(device) || isLeAudioOnly); || isLeAudioOnly); debugLog( debugLog( "mLeAudioEnabledByDefault: " "mLeAudioEnabledByDefault: " + mLeAudioEnabledByDefault + mLeAudioEnabledByDefault Loading @@ -328,7 +343,9 @@ public class PhonePolicy implements AdapterService.BluetoothStateCallback { + ", isLeAudioProfileAllowed: " + ", isLeAudioProfileAllowed: " + isLeAudioProfileAllowed + isLeAudioProfileAllowed + ", isLeAudioOnly: " + ", isLeAudioOnly: " + isLeAudioOnly); + isLeAudioOnly + ", shouldEnableHapByDefault: " + shouldEnableHapByDefault); // Set profile priorities only for the profiles discovered on the remote device. // Set profile priorities only for the profiles discovered on the remote device. // This avoids needless auto-connect attempts to profiles non-existent on the remote device // This avoids needless auto-connect attempts to profiles non-existent on the remote device Loading Loading @@ -516,7 +533,7 @@ public class PhonePolicy implements AdapterService.BluetoothStateCallback { && (hearingAidService.getConnectionPolicy(device) && (hearingAidService.getConnectionPolicy(device) == BluetoothProfile.CONNECTION_POLICY_UNKNOWN)) { == BluetoothProfile.CONNECTION_POLICY_UNKNOWN)) { if (isLeAudioProfileAllowed) { if (isLeAudioProfileAllowed) { debugLog("LE Audio preferred over ASHA for device " + device); Log.i(TAG, "LE Audio preferred over ASHA for device " + device); mAdapterService mAdapterService .getDatabase() .getDatabase() .setProfileConnectionPolicy( .setProfileConnectionPolicy( Loading
flags/hap.aconfig +7 −1 Original line number Original line Diff line number Diff line package: "com.android.bluetooth.flags" package: "com.android.bluetooth.flags" container: "com.android.btservices" container: "com.android.btservices" flag { name: "enable_hap_by_default" namespace: "bluetooth" description: "On device that support HAP, enable it by default and disable ASHA" bug: "345826775" } flag { flag { name: "settings_can_control_hap_preset" name: "settings_can_control_hap_preset" is_exported: true is_exported: true Loading @@ -8,4 +15,3 @@ flag { description: "Allow user to control the preset of hearing aid devices" description: "Allow user to control the preset of hearing aid devices" bug: "306236481" bug: "306236481" } }