Loading android/app/src/com/android/bluetooth/Utils.java +36 −0 Original line number Original line Diff line number Diff line Loading @@ -44,8 +44,10 @@ import android.bluetooth.BluetoothDevice; import android.companion.AssociationInfo; import android.companion.AssociationInfo; import android.companion.CompanionDeviceManager; import android.companion.CompanionDeviceManager; import android.content.AttributionSource; import android.content.AttributionSource; import android.content.BroadcastReceiver; import android.content.ContentValues; import android.content.ContentValues; import android.content.Context; import android.content.Context; import android.content.Intent; import android.content.pm.PackageInfo; import android.content.pm.PackageInfo; import android.content.pm.PackageManager; import android.content.pm.PackageManager; import android.location.LocationManager; import android.location.LocationManager; Loading @@ -53,6 +55,7 @@ import android.net.Uri; import android.os.Binder; import android.os.Binder; import android.os.Build; import android.os.Build; import android.os.Bundle; import android.os.Bundle; import android.os.Handler; import android.os.ParcelUuid; import android.os.ParcelUuid; import android.os.PowerExemptionManager; import android.os.PowerExemptionManager; import android.os.Process; import android.os.Process; Loading Loading @@ -1056,6 +1059,8 @@ public final class Utils { /** /** * Returns bundled broadcast options. * Returns bundled broadcast options. */ */ // TODO(b/193460475): Remove when tooling supports SystemApi to public API. @SuppressLint("NewApi") public static @NonNull Bundle getTempAllowlistBroadcastOptions() { public static @NonNull Bundle getTempAllowlistBroadcastOptions() { return getTempBroadcastOptions().toBundle(); return getTempBroadcastOptions().toBundle(); } } Loading @@ -1063,6 +1068,8 @@ public final class Utils { /** /** * Returns broadcast options. * Returns broadcast options. */ */ // TODO(b/193460475): Remove when tooling supports SystemApi to public API. @SuppressLint("NewApi") public static @NonNull BroadcastOptions getTempBroadcastOptions() { public static @NonNull BroadcastOptions getTempBroadcastOptions() { final BroadcastOptions bOptions = BroadcastOptions.makeBasic(); final BroadcastOptions bOptions = BroadcastOptions.makeBasic(); // Use the Bluetooth process identity to pass permission check when reading DeviceConfig // Use the Bluetooth process identity to pass permission check when reading DeviceConfig Loading @@ -1078,6 +1085,35 @@ public final class Utils { } } return bOptions; return bOptions; } } /** * Sends the {@code intent} as a broadcast in the provided {@code context} to receivers that * have been granted the specified {@code receiverPermission} with the {@link BroadcastOptions} * {@code options}. * * @see Context#sendBroadcast(Intent, String, Bundle) */ // TODO(b/193460475): Remove when tooling supports SystemApi to public API. @SuppressLint("NewApi") public static void sendBroadcast(@NonNull Context context, @NonNull Intent intent, @Nullable String receiverPermission, @Nullable Bundle options) { context.sendBroadcast(intent, receiverPermission, options); } /** * @see Context#sendOrderedBroadcast(Intent, String, Bundle, BroadcastReceiver, Handler, * int, String, Bundle) */ // TODO(b/193460475): Remove when tooling supports SystemApi to public API. @SuppressLint("NewApi") public static void sendOrderedBroadcast(@NonNull Context context, @NonNull Intent intent, @Nullable String receiverPermission, @Nullable Bundle options, @Nullable BroadcastReceiver resultReceiver, @Nullable Handler scheduler, int initialCode, @Nullable String initialData, @Nullable Bundle initialExtras) { context.sendOrderedBroadcast(intent, receiverPermission, options, resultReceiver, scheduler, initialCode, initialData, initialExtras); } /** /** * Checks that value is present as at least one of the elements of the array. * Checks that value is present as at least one of the elements of the array. * @param array the array to check in * @param array the array to check in Loading android/app/src/com/android/bluetooth/a2dp/A2dpService.java +4 −2 Original line number Original line Diff line number Diff line Loading @@ -1085,7 +1085,8 @@ public class A2dpService extends ProfileService { intent.putExtra(BluetoothDevice.EXTRA_DEVICE, device); intent.putExtra(BluetoothDevice.EXTRA_DEVICE, device); intent.addFlags(Intent.FLAG_RECEIVER_REGISTERED_ONLY_BEFORE_BOOT intent.addFlags(Intent.FLAG_RECEIVER_REGISTERED_ONLY_BEFORE_BOOT | Intent.FLAG_RECEIVER_INCLUDE_BACKGROUND); | Intent.FLAG_RECEIVER_INCLUDE_BACKGROUND); sendBroadcast(intent, BLUETOOTH_CONNECT, Utils.getTempAllowlistBroadcastOptions()); Utils.sendBroadcast(this, intent, BLUETOOTH_CONNECT, Utils.getTempAllowlistBroadcastOptions()); } } private void broadcastCodecConfig(BluetoothDevice device, BluetoothCodecStatus codecStatus) { private void broadcastCodecConfig(BluetoothDevice device, BluetoothCodecStatus codecStatus) { Loading @@ -1097,7 +1098,8 @@ public class A2dpService extends ProfileService { intent.putExtra(BluetoothDevice.EXTRA_DEVICE, device); intent.putExtra(BluetoothDevice.EXTRA_DEVICE, device); intent.addFlags(Intent.FLAG_RECEIVER_REGISTERED_ONLY_BEFORE_BOOT intent.addFlags(Intent.FLAG_RECEIVER_REGISTERED_ONLY_BEFORE_BOOT | Intent.FLAG_RECEIVER_INCLUDE_BACKGROUND); | Intent.FLAG_RECEIVER_INCLUDE_BACKGROUND); sendBroadcast(intent, BLUETOOTH_CONNECT, Utils.getTempAllowlistBroadcastOptions()); Utils.sendBroadcast(this, intent, BLUETOOTH_CONNECT, Utils.getTempAllowlistBroadcastOptions()); } } private class BondStateChangedReceiver extends BroadcastReceiver { private class BondStateChangedReceiver extends BroadcastReceiver { Loading android/app/src/com/android/bluetooth/a2dp/A2dpStateMachine.java +2 −2 Original line number Original line Diff line number Diff line Loading @@ -701,7 +701,7 @@ final class A2dpStateMachine extends StateMachine { intent.putExtra(BluetoothDevice.EXTRA_DEVICE, mDevice); intent.putExtra(BluetoothDevice.EXTRA_DEVICE, mDevice); intent.addFlags(Intent.FLAG_RECEIVER_REGISTERED_ONLY_BEFORE_BOOT intent.addFlags(Intent.FLAG_RECEIVER_REGISTERED_ONLY_BEFORE_BOOT | Intent.FLAG_RECEIVER_INCLUDE_BACKGROUND); | Intent.FLAG_RECEIVER_INCLUDE_BACKGROUND); mA2dpService.sendBroadcast(intent, BLUETOOTH_CONNECT, Utils.sendBroadcast(mA2dpService, intent, BLUETOOTH_CONNECT, Utils.getTempAllowlistBroadcastOptions()); Utils.getTempAllowlistBroadcastOptions()); } } Loading @@ -713,7 +713,7 @@ final class A2dpStateMachine extends StateMachine { intent.putExtra(BluetoothProfile.EXTRA_PREVIOUS_STATE, prevState); intent.putExtra(BluetoothProfile.EXTRA_PREVIOUS_STATE, prevState); intent.putExtra(BluetoothProfile.EXTRA_STATE, newState); intent.putExtra(BluetoothProfile.EXTRA_STATE, newState); intent.addFlags(Intent.FLAG_RECEIVER_REGISTERED_ONLY_BEFORE_BOOT); intent.addFlags(Intent.FLAG_RECEIVER_REGISTERED_ONLY_BEFORE_BOOT); mA2dpService.sendBroadcast(intent, BLUETOOTH_CONNECT, Utils.sendBroadcast(mA2dpService, intent, BLUETOOTH_CONNECT, Utils.getTempAllowlistBroadcastOptions()); Utils.getTempAllowlistBroadcastOptions()); } } Loading android/app/src/com/android/bluetooth/a2dpsink/A2dpSinkStateMachine.java +2 −1 Original line number Original line Diff line number Diff line Loading @@ -310,6 +310,7 @@ public class A2dpSinkStateMachine extends StateMachine { intent.putExtra(BluetoothDevice.EXTRA_DEVICE, mDevice); intent.putExtra(BluetoothDevice.EXTRA_DEVICE, mDevice); intent.addFlags(Intent.FLAG_RECEIVER_REGISTERED_ONLY_BEFORE_BOOT); intent.addFlags(Intent.FLAG_RECEIVER_REGISTERED_ONLY_BEFORE_BOOT); mMostRecentState = currentState; mMostRecentState = currentState; mService.sendBroadcast(intent, BLUETOOTH_CONNECT, Utils.getTempAllowlistBroadcastOptions()); Utils.sendBroadcast(mService, intent, BLUETOOTH_CONNECT, Utils.getTempAllowlistBroadcastOptions()); } } } } android/app/src/com/android/bluetooth/avrcpcontroller/AvrcpControllerStateMachine.java +2 −1 Original line number Original line Diff line number Diff line Loading @@ -1320,7 +1320,8 @@ class AvrcpControllerStateMachine extends StateMachine { intent.putExtra(BluetoothDevice.EXTRA_DEVICE, mDevice); intent.putExtra(BluetoothDevice.EXTRA_DEVICE, mDevice); intent.addFlags(Intent.FLAG_RECEIVER_REGISTERED_ONLY_BEFORE_BOOT); intent.addFlags(Intent.FLAG_RECEIVER_REGISTERED_ONLY_BEFORE_BOOT); mMostRecentState = currentState; mMostRecentState = currentState; mService.sendBroadcast(intent, BLUETOOTH_CONNECT, Utils.getTempAllowlistBroadcastOptions()); Utils.sendBroadcast(mService, intent, BLUETOOTH_CONNECT, Utils.getTempAllowlistBroadcastOptions()); } } private boolean shouldRequestFocus() { private boolean shouldRequestFocus() { Loading Loading
android/app/src/com/android/bluetooth/Utils.java +36 −0 Original line number Original line Diff line number Diff line Loading @@ -44,8 +44,10 @@ import android.bluetooth.BluetoothDevice; import android.companion.AssociationInfo; import android.companion.AssociationInfo; import android.companion.CompanionDeviceManager; import android.companion.CompanionDeviceManager; import android.content.AttributionSource; import android.content.AttributionSource; import android.content.BroadcastReceiver; import android.content.ContentValues; import android.content.ContentValues; import android.content.Context; import android.content.Context; import android.content.Intent; import android.content.pm.PackageInfo; import android.content.pm.PackageInfo; import android.content.pm.PackageManager; import android.content.pm.PackageManager; import android.location.LocationManager; import android.location.LocationManager; Loading @@ -53,6 +55,7 @@ import android.net.Uri; import android.os.Binder; import android.os.Binder; import android.os.Build; import android.os.Build; import android.os.Bundle; import android.os.Bundle; import android.os.Handler; import android.os.ParcelUuid; import android.os.ParcelUuid; import android.os.PowerExemptionManager; import android.os.PowerExemptionManager; import android.os.Process; import android.os.Process; Loading Loading @@ -1056,6 +1059,8 @@ public final class Utils { /** /** * Returns bundled broadcast options. * Returns bundled broadcast options. */ */ // TODO(b/193460475): Remove when tooling supports SystemApi to public API. @SuppressLint("NewApi") public static @NonNull Bundle getTempAllowlistBroadcastOptions() { public static @NonNull Bundle getTempAllowlistBroadcastOptions() { return getTempBroadcastOptions().toBundle(); return getTempBroadcastOptions().toBundle(); } } Loading @@ -1063,6 +1068,8 @@ public final class Utils { /** /** * Returns broadcast options. * Returns broadcast options. */ */ // TODO(b/193460475): Remove when tooling supports SystemApi to public API. @SuppressLint("NewApi") public static @NonNull BroadcastOptions getTempBroadcastOptions() { public static @NonNull BroadcastOptions getTempBroadcastOptions() { final BroadcastOptions bOptions = BroadcastOptions.makeBasic(); final BroadcastOptions bOptions = BroadcastOptions.makeBasic(); // Use the Bluetooth process identity to pass permission check when reading DeviceConfig // Use the Bluetooth process identity to pass permission check when reading DeviceConfig Loading @@ -1078,6 +1085,35 @@ public final class Utils { } } return bOptions; return bOptions; } } /** * Sends the {@code intent} as a broadcast in the provided {@code context} to receivers that * have been granted the specified {@code receiverPermission} with the {@link BroadcastOptions} * {@code options}. * * @see Context#sendBroadcast(Intent, String, Bundle) */ // TODO(b/193460475): Remove when tooling supports SystemApi to public API. @SuppressLint("NewApi") public static void sendBroadcast(@NonNull Context context, @NonNull Intent intent, @Nullable String receiverPermission, @Nullable Bundle options) { context.sendBroadcast(intent, receiverPermission, options); } /** * @see Context#sendOrderedBroadcast(Intent, String, Bundle, BroadcastReceiver, Handler, * int, String, Bundle) */ // TODO(b/193460475): Remove when tooling supports SystemApi to public API. @SuppressLint("NewApi") public static void sendOrderedBroadcast(@NonNull Context context, @NonNull Intent intent, @Nullable String receiverPermission, @Nullable Bundle options, @Nullable BroadcastReceiver resultReceiver, @Nullable Handler scheduler, int initialCode, @Nullable String initialData, @Nullable Bundle initialExtras) { context.sendOrderedBroadcast(intent, receiverPermission, options, resultReceiver, scheduler, initialCode, initialData, initialExtras); } /** /** * Checks that value is present as at least one of the elements of the array. * Checks that value is present as at least one of the elements of the array. * @param array the array to check in * @param array the array to check in Loading
android/app/src/com/android/bluetooth/a2dp/A2dpService.java +4 −2 Original line number Original line Diff line number Diff line Loading @@ -1085,7 +1085,8 @@ public class A2dpService extends ProfileService { intent.putExtra(BluetoothDevice.EXTRA_DEVICE, device); intent.putExtra(BluetoothDevice.EXTRA_DEVICE, device); intent.addFlags(Intent.FLAG_RECEIVER_REGISTERED_ONLY_BEFORE_BOOT intent.addFlags(Intent.FLAG_RECEIVER_REGISTERED_ONLY_BEFORE_BOOT | Intent.FLAG_RECEIVER_INCLUDE_BACKGROUND); | Intent.FLAG_RECEIVER_INCLUDE_BACKGROUND); sendBroadcast(intent, BLUETOOTH_CONNECT, Utils.getTempAllowlistBroadcastOptions()); Utils.sendBroadcast(this, intent, BLUETOOTH_CONNECT, Utils.getTempAllowlistBroadcastOptions()); } } private void broadcastCodecConfig(BluetoothDevice device, BluetoothCodecStatus codecStatus) { private void broadcastCodecConfig(BluetoothDevice device, BluetoothCodecStatus codecStatus) { Loading @@ -1097,7 +1098,8 @@ public class A2dpService extends ProfileService { intent.putExtra(BluetoothDevice.EXTRA_DEVICE, device); intent.putExtra(BluetoothDevice.EXTRA_DEVICE, device); intent.addFlags(Intent.FLAG_RECEIVER_REGISTERED_ONLY_BEFORE_BOOT intent.addFlags(Intent.FLAG_RECEIVER_REGISTERED_ONLY_BEFORE_BOOT | Intent.FLAG_RECEIVER_INCLUDE_BACKGROUND); | Intent.FLAG_RECEIVER_INCLUDE_BACKGROUND); sendBroadcast(intent, BLUETOOTH_CONNECT, Utils.getTempAllowlistBroadcastOptions()); Utils.sendBroadcast(this, intent, BLUETOOTH_CONNECT, Utils.getTempAllowlistBroadcastOptions()); } } private class BondStateChangedReceiver extends BroadcastReceiver { private class BondStateChangedReceiver extends BroadcastReceiver { Loading
android/app/src/com/android/bluetooth/a2dp/A2dpStateMachine.java +2 −2 Original line number Original line Diff line number Diff line Loading @@ -701,7 +701,7 @@ final class A2dpStateMachine extends StateMachine { intent.putExtra(BluetoothDevice.EXTRA_DEVICE, mDevice); intent.putExtra(BluetoothDevice.EXTRA_DEVICE, mDevice); intent.addFlags(Intent.FLAG_RECEIVER_REGISTERED_ONLY_BEFORE_BOOT intent.addFlags(Intent.FLAG_RECEIVER_REGISTERED_ONLY_BEFORE_BOOT | Intent.FLAG_RECEIVER_INCLUDE_BACKGROUND); | Intent.FLAG_RECEIVER_INCLUDE_BACKGROUND); mA2dpService.sendBroadcast(intent, BLUETOOTH_CONNECT, Utils.sendBroadcast(mA2dpService, intent, BLUETOOTH_CONNECT, Utils.getTempAllowlistBroadcastOptions()); Utils.getTempAllowlistBroadcastOptions()); } } Loading @@ -713,7 +713,7 @@ final class A2dpStateMachine extends StateMachine { intent.putExtra(BluetoothProfile.EXTRA_PREVIOUS_STATE, prevState); intent.putExtra(BluetoothProfile.EXTRA_PREVIOUS_STATE, prevState); intent.putExtra(BluetoothProfile.EXTRA_STATE, newState); intent.putExtra(BluetoothProfile.EXTRA_STATE, newState); intent.addFlags(Intent.FLAG_RECEIVER_REGISTERED_ONLY_BEFORE_BOOT); intent.addFlags(Intent.FLAG_RECEIVER_REGISTERED_ONLY_BEFORE_BOOT); mA2dpService.sendBroadcast(intent, BLUETOOTH_CONNECT, Utils.sendBroadcast(mA2dpService, intent, BLUETOOTH_CONNECT, Utils.getTempAllowlistBroadcastOptions()); Utils.getTempAllowlistBroadcastOptions()); } } Loading
android/app/src/com/android/bluetooth/a2dpsink/A2dpSinkStateMachine.java +2 −1 Original line number Original line Diff line number Diff line Loading @@ -310,6 +310,7 @@ public class A2dpSinkStateMachine extends StateMachine { intent.putExtra(BluetoothDevice.EXTRA_DEVICE, mDevice); intent.putExtra(BluetoothDevice.EXTRA_DEVICE, mDevice); intent.addFlags(Intent.FLAG_RECEIVER_REGISTERED_ONLY_BEFORE_BOOT); intent.addFlags(Intent.FLAG_RECEIVER_REGISTERED_ONLY_BEFORE_BOOT); mMostRecentState = currentState; mMostRecentState = currentState; mService.sendBroadcast(intent, BLUETOOTH_CONNECT, Utils.getTempAllowlistBroadcastOptions()); Utils.sendBroadcast(mService, intent, BLUETOOTH_CONNECT, Utils.getTempAllowlistBroadcastOptions()); } } } }
android/app/src/com/android/bluetooth/avrcpcontroller/AvrcpControllerStateMachine.java +2 −1 Original line number Original line Diff line number Diff line Loading @@ -1320,7 +1320,8 @@ class AvrcpControllerStateMachine extends StateMachine { intent.putExtra(BluetoothDevice.EXTRA_DEVICE, mDevice); intent.putExtra(BluetoothDevice.EXTRA_DEVICE, mDevice); intent.addFlags(Intent.FLAG_RECEIVER_REGISTERED_ONLY_BEFORE_BOOT); intent.addFlags(Intent.FLAG_RECEIVER_REGISTERED_ONLY_BEFORE_BOOT); mMostRecentState = currentState; mMostRecentState = currentState; mService.sendBroadcast(intent, BLUETOOTH_CONNECT, Utils.getTempAllowlistBroadcastOptions()); Utils.sendBroadcast(mService, intent, BLUETOOTH_CONNECT, Utils.getTempAllowlistBroadcastOptions()); } } private boolean shouldRequestFocus() { private boolean shouldRequestFocus() { Loading