Loading AndroidManifest.xml +1 −0 Original line number Diff line number Diff line Loading @@ -75,6 +75,7 @@ <uses-permission android:name="android.permission.PACKAGE_USAGE_STATS"/> <uses-permission android:name="android.permission.QUERY_ALL_PACKAGES"/> <uses-permission android:name="android.permission.MANAGE_COMPANION_DEVICES"/> <uses-permission android:name="android.permission.START_FOREGROUND_SERVICES_FROM_BACKGROUND"/> <uses-sdk android:minSdkVersion="14"/> Loading src/com/android/bluetooth/Utils.java +18 −0 Original line number Diff line number Diff line Loading @@ -26,12 +26,14 @@ import static android.content.PermissionChecker.PERMISSION_HARD_DENIED; import static android.content.PermissionChecker.PID_UNKNOWN; import static android.content.pm.PackageManager.GET_PERMISSIONS; import static android.content.pm.PackageManager.PERMISSION_GRANTED; import static android.os.PowerExemptionManager.TEMPORARY_ALLOW_LIST_TYPE_FOREGROUND_SERVICE_ALLOWED; import android.Manifest; import android.annotation.NonNull; import android.annotation.RequiresPermission; import android.annotation.SuppressLint; import android.app.AppOpsManager; import android.app.BroadcastOptions; import android.bluetooth.BluetoothAdapter; import android.bluetooth.BluetoothDevice; import android.companion.Association; Loading @@ -47,7 +49,9 @@ import android.location.LocationManager; import android.net.Uri; import android.os.Binder; import android.os.Build; import android.os.Bundle; import android.os.ParcelUuid; import android.os.PowerExemptionManager; import android.os.Process; import android.os.SystemProperties; import android.os.UserHandle; Loading Loading @@ -83,6 +87,16 @@ public final class Utils { static final int BD_ADDR_LEN = 6; // bytes static final int BD_UUID_LEN = 16; // bytes public static final Bundle sTempAllowlistBroadcastOptions; static { final long durationMs = 10_000; final BroadcastOptions bOptions = BroadcastOptions.makeBasic(); bOptions.setTemporaryAppAllowlist(durationMs, TEMPORARY_ALLOW_LIST_TYPE_FOREGROUND_SERVICE_ALLOWED, PowerExemptionManager.REASON_BLUETOOTH_BROADCAST, ""); sTempAllowlistBroadcastOptions = bOptions.toBundle(); } /* * Special characters * Loading Loading @@ -866,4 +880,8 @@ public final class Utils { return 1 == context.getContentResolver().update(uri, values, null, null); } public static @NonNull Bundle getTempAllowlistBroadcastOptions() { return sTempAllowlistBroadcastOptions; } } src/com/android/bluetooth/a2dp/A2dpService.java +2 −2 Original line number Diff line number Diff line Loading @@ -1094,7 +1094,7 @@ public class A2dpService extends ProfileService { intent.putExtra(BluetoothDevice.EXTRA_DEVICE, device); intent.addFlags(Intent.FLAG_RECEIVER_REGISTERED_ONLY_BEFORE_BOOT | Intent.FLAG_RECEIVER_INCLUDE_BACKGROUND); sendBroadcast(intent, BLUETOOTH_CONNECT); sendBroadcast(intent, BLUETOOTH_CONNECT, Utils.getTempAllowlistBroadcastOptions()); } private void broadcastCodecConfig(BluetoothDevice device, BluetoothCodecStatus codecStatus) { Loading @@ -1106,7 +1106,7 @@ public class A2dpService extends ProfileService { intent.putExtra(BluetoothDevice.EXTRA_DEVICE, device); intent.addFlags(Intent.FLAG_RECEIVER_REGISTERED_ONLY_BEFORE_BOOT | Intent.FLAG_RECEIVER_INCLUDE_BACKGROUND); sendBroadcast(intent, BLUETOOTH_CONNECT); sendBroadcast(intent, BLUETOOTH_CONNECT, Utils.getTempAllowlistBroadcastOptions()); } private class BondStateChangedReceiver extends BroadcastReceiver { Loading src/com/android/bluetooth/a2dp/A2dpStateMachine.java +5 −2 Original line number Diff line number Diff line Loading @@ -58,6 +58,7 @@ import android.os.Looper; import android.os.Message; import android.util.Log; import com.android.bluetooth.Utils; import com.android.bluetooth.btservice.ProfileService; import com.android.bluetooth.statemachine.State; import com.android.bluetooth.statemachine.StateMachine; Loading Loading @@ -685,7 +686,8 @@ final class A2dpStateMachine extends StateMachine { intent.putExtra(BluetoothDevice.EXTRA_DEVICE, mDevice); intent.addFlags(Intent.FLAG_RECEIVER_REGISTERED_ONLY_BEFORE_BOOT | Intent.FLAG_RECEIVER_INCLUDE_BACKGROUND); mA2dpService.sendBroadcast(intent, BLUETOOTH_CONNECT); mA2dpService.sendBroadcast(intent, BLUETOOTH_CONNECT, Utils.getTempAllowlistBroadcastOptions()); } private void broadcastAudioState(int newState, int prevState) { Loading @@ -696,7 +698,8 @@ final class A2dpStateMachine extends StateMachine { intent.putExtra(BluetoothProfile.EXTRA_PREVIOUS_STATE, prevState); intent.putExtra(BluetoothProfile.EXTRA_STATE, newState); intent.addFlags(Intent.FLAG_RECEIVER_REGISTERED_ONLY_BEFORE_BOOT); mA2dpService.sendBroadcast(intent, BLUETOOTH_CONNECT); mA2dpService.sendBroadcast(intent, BLUETOOTH_CONNECT, Utils.getTempAllowlistBroadcastOptions()); } @Override Loading src/com/android/bluetooth/a2dpsink/A2dpSinkStateMachine.java +1 −1 Original line number Diff line number Diff line Loading @@ -311,6 +311,6 @@ public class A2dpSinkStateMachine extends StateMachine { intent.putExtra(BluetoothDevice.EXTRA_DEVICE, mDevice); intent.addFlags(Intent.FLAG_RECEIVER_REGISTERED_ONLY_BEFORE_BOOT); mMostRecentState = currentState; mService.sendBroadcast(intent, BLUETOOTH_CONNECT); mService.sendBroadcast(intent, BLUETOOTH_CONNECT, Utils.getTempAllowlistBroadcastOptions()); } } Loading
AndroidManifest.xml +1 −0 Original line number Diff line number Diff line Loading @@ -75,6 +75,7 @@ <uses-permission android:name="android.permission.PACKAGE_USAGE_STATS"/> <uses-permission android:name="android.permission.QUERY_ALL_PACKAGES"/> <uses-permission android:name="android.permission.MANAGE_COMPANION_DEVICES"/> <uses-permission android:name="android.permission.START_FOREGROUND_SERVICES_FROM_BACKGROUND"/> <uses-sdk android:minSdkVersion="14"/> Loading
src/com/android/bluetooth/Utils.java +18 −0 Original line number Diff line number Diff line Loading @@ -26,12 +26,14 @@ import static android.content.PermissionChecker.PERMISSION_HARD_DENIED; import static android.content.PermissionChecker.PID_UNKNOWN; import static android.content.pm.PackageManager.GET_PERMISSIONS; import static android.content.pm.PackageManager.PERMISSION_GRANTED; import static android.os.PowerExemptionManager.TEMPORARY_ALLOW_LIST_TYPE_FOREGROUND_SERVICE_ALLOWED; import android.Manifest; import android.annotation.NonNull; import android.annotation.RequiresPermission; import android.annotation.SuppressLint; import android.app.AppOpsManager; import android.app.BroadcastOptions; import android.bluetooth.BluetoothAdapter; import android.bluetooth.BluetoothDevice; import android.companion.Association; Loading @@ -47,7 +49,9 @@ import android.location.LocationManager; import android.net.Uri; import android.os.Binder; import android.os.Build; import android.os.Bundle; import android.os.ParcelUuid; import android.os.PowerExemptionManager; import android.os.Process; import android.os.SystemProperties; import android.os.UserHandle; Loading Loading @@ -83,6 +87,16 @@ public final class Utils { static final int BD_ADDR_LEN = 6; // bytes static final int BD_UUID_LEN = 16; // bytes public static final Bundle sTempAllowlistBroadcastOptions; static { final long durationMs = 10_000; final BroadcastOptions bOptions = BroadcastOptions.makeBasic(); bOptions.setTemporaryAppAllowlist(durationMs, TEMPORARY_ALLOW_LIST_TYPE_FOREGROUND_SERVICE_ALLOWED, PowerExemptionManager.REASON_BLUETOOTH_BROADCAST, ""); sTempAllowlistBroadcastOptions = bOptions.toBundle(); } /* * Special characters * Loading Loading @@ -866,4 +880,8 @@ public final class Utils { return 1 == context.getContentResolver().update(uri, values, null, null); } public static @NonNull Bundle getTempAllowlistBroadcastOptions() { return sTempAllowlistBroadcastOptions; } }
src/com/android/bluetooth/a2dp/A2dpService.java +2 −2 Original line number Diff line number Diff line Loading @@ -1094,7 +1094,7 @@ public class A2dpService extends ProfileService { intent.putExtra(BluetoothDevice.EXTRA_DEVICE, device); intent.addFlags(Intent.FLAG_RECEIVER_REGISTERED_ONLY_BEFORE_BOOT | Intent.FLAG_RECEIVER_INCLUDE_BACKGROUND); sendBroadcast(intent, BLUETOOTH_CONNECT); sendBroadcast(intent, BLUETOOTH_CONNECT, Utils.getTempAllowlistBroadcastOptions()); } private void broadcastCodecConfig(BluetoothDevice device, BluetoothCodecStatus codecStatus) { Loading @@ -1106,7 +1106,7 @@ public class A2dpService extends ProfileService { intent.putExtra(BluetoothDevice.EXTRA_DEVICE, device); intent.addFlags(Intent.FLAG_RECEIVER_REGISTERED_ONLY_BEFORE_BOOT | Intent.FLAG_RECEIVER_INCLUDE_BACKGROUND); sendBroadcast(intent, BLUETOOTH_CONNECT); sendBroadcast(intent, BLUETOOTH_CONNECT, Utils.getTempAllowlistBroadcastOptions()); } private class BondStateChangedReceiver extends BroadcastReceiver { Loading
src/com/android/bluetooth/a2dp/A2dpStateMachine.java +5 −2 Original line number Diff line number Diff line Loading @@ -58,6 +58,7 @@ import android.os.Looper; import android.os.Message; import android.util.Log; import com.android.bluetooth.Utils; import com.android.bluetooth.btservice.ProfileService; import com.android.bluetooth.statemachine.State; import com.android.bluetooth.statemachine.StateMachine; Loading Loading @@ -685,7 +686,8 @@ final class A2dpStateMachine extends StateMachine { intent.putExtra(BluetoothDevice.EXTRA_DEVICE, mDevice); intent.addFlags(Intent.FLAG_RECEIVER_REGISTERED_ONLY_BEFORE_BOOT | Intent.FLAG_RECEIVER_INCLUDE_BACKGROUND); mA2dpService.sendBroadcast(intent, BLUETOOTH_CONNECT); mA2dpService.sendBroadcast(intent, BLUETOOTH_CONNECT, Utils.getTempAllowlistBroadcastOptions()); } private void broadcastAudioState(int newState, int prevState) { Loading @@ -696,7 +698,8 @@ final class A2dpStateMachine extends StateMachine { intent.putExtra(BluetoothProfile.EXTRA_PREVIOUS_STATE, prevState); intent.putExtra(BluetoothProfile.EXTRA_STATE, newState); intent.addFlags(Intent.FLAG_RECEIVER_REGISTERED_ONLY_BEFORE_BOOT); mA2dpService.sendBroadcast(intent, BLUETOOTH_CONNECT); mA2dpService.sendBroadcast(intent, BLUETOOTH_CONNECT, Utils.getTempAllowlistBroadcastOptions()); } @Override Loading
src/com/android/bluetooth/a2dpsink/A2dpSinkStateMachine.java +1 −1 Original line number Diff line number Diff line Loading @@ -311,6 +311,6 @@ public class A2dpSinkStateMachine extends StateMachine { intent.putExtra(BluetoothDevice.EXTRA_DEVICE, mDevice); intent.addFlags(Intent.FLAG_RECEIVER_REGISTERED_ONLY_BEFORE_BOOT); mMostRecentState = currentState; mService.sendBroadcast(intent, BLUETOOTH_CONNECT); mService.sendBroadcast(intent, BLUETOOTH_CONNECT, Utils.getTempAllowlistBroadcastOptions()); } }