diff options
| author | 2017-04-21 01:16:31 +0000 | |
|---|---|---|
| committer | 2017-04-21 01:16:33 +0000 | |
| commit | c5680c9b05a645bfe474f2885f72fa669854f11c (patch) | |
| tree | 031392afe3e46fb64dacf79f6b5b6c846f8652a5 | |
| parent | b44f4d2f51f21fa2c91888328612380c86cfedf6 (diff) | |
| parent | ad4d1d8e28618546953e75d4983335631feb6f2a (diff) | |
Merge "Allow the Bluetooth MAC address to be updated asynchronously (2/3)"
| -rw-r--r-- | core/java/android/bluetooth/BluetoothAdapter.java | 24 | ||||
| -rw-r--r-- | core/res/AndroidManifest.xml | 1 | ||||
| -rw-r--r-- | services/core/java/com/android/server/BluetoothManagerService.java | 11 |
3 files changed, 36 insertions, 0 deletions
diff --git a/core/java/android/bluetooth/BluetoothAdapter.java b/core/java/android/bluetooth/BluetoothAdapter.java index 845a47d99842..85636033d819 100644 --- a/core/java/android/bluetooth/BluetoothAdapter.java +++ b/core/java/android/bluetooth/BluetoothAdapter.java @@ -466,6 +466,30 @@ public final class BluetoothAdapter { "android.bluetooth.adapter.action.BLE_STATE_CHANGED"; /** + * Intent used to broadcast the change in the Bluetooth address + * of the local Bluetooth adapter. + * <p>Always contains the extra field {@link + * #EXTRA_BLUETOOTH_ADDRESS} containing the Bluetooth address. + * + * Note: only system level processes are allowed to send this + * defined broadcast. + * + * @hide + */ + public static final String ACTION_BLUETOOTH_ADDRESS_CHANGED = + "android.bluetooth.adapter.action.BLUETOOTH_ADDRESS_CHANGED"; + + /** + * Used as a String extra field in {@link + * #ACTION_BLUETOOTH_ADDRESS_CHANGED} intent to store the local + * Bluetooth address. + * + * @hide + */ + public static final String EXTRA_BLUETOOTH_ADDRESS = + "android.bluetooth.adapter.extra.BLUETOOTH_ADDRESS"; + + /** * Broadcast Action: The notifys Bluetooth ACL connected event. This will be * by BLE Always on enabled application to know the ACL_CONNECTED event * when Bluetooth state in STATE_BLE_ON. This denotes GATT connection diff --git a/core/res/AndroidManifest.xml b/core/res/AndroidManifest.xml index 9991a20a9b82..9e7bf2777a5a 100644 --- a/core/res/AndroidManifest.xml +++ b/core/res/AndroidManifest.xml @@ -122,6 +122,7 @@ <protected-broadcast android:name="android.bluetooth.adapter.action.DISCOVERY_STARTED" /> <protected-broadcast android:name="android.bluetooth.adapter.action.DISCOVERY_FINISHED" /> <protected-broadcast android:name="android.bluetooth.adapter.action.LOCAL_NAME_CHANGED" /> + <protected-broadcast android:name="android.bluetooth.adapter.action.BLUETOOTH_ADDRESS_CHANGED" /> <protected-broadcast android:name="android.bluetooth.adapter.action.CONNECTION_STATE_CHANGED" /> <protected-broadcast android:name="android.bluetooth.device.action.UUID" /> <protected-broadcast android:name="android.bluetooth.device.action.MAS_INSTANCE" /> diff --git a/services/core/java/com/android/server/BluetoothManagerService.java b/services/core/java/com/android/server/BluetoothManagerService.java index de4734f02d0e..5eb4db408a67 100644 --- a/services/core/java/com/android/server/BluetoothManagerService.java +++ b/services/core/java/com/android/server/BluetoothManagerService.java @@ -307,6 +307,14 @@ class BluetoothManagerService extends IBluetoothManager.Stub { if (newName != null) { storeNameAndAddress(newName, null); } + } else if (BluetoothAdapter.ACTION_BLUETOOTH_ADDRESS_CHANGED.equals(action)) { + String newAddress = intent.getStringExtra(BluetoothAdapter.EXTRA_BLUETOOTH_ADDRESS); + if (newAddress != null) { + if (DBG) Slog.d(TAG, "Bluetooth Adapter address changed to " + newAddress); + storeNameAndAddress(null, newAddress); + } else { + if (DBG) Slog.e(TAG, "No Bluetooth Adapter address parameter found"); + } } } }; @@ -343,6 +351,9 @@ class BluetoothManagerService extends IBluetoothManager.Stub { IntentFilter filter = new IntentFilter(BluetoothAdapter.ACTION_LOCAL_NAME_CHANGED); filter.setPriority(IntentFilter.SYSTEM_HIGH_PRIORITY); mContext.registerReceiver(mReceiver, filter); + filter = new IntentFilter(BluetoothAdapter.ACTION_BLUETOOTH_ADDRESS_CHANGED); + filter.setPriority(IntentFilter.SYSTEM_HIGH_PRIORITY); + mContext.registerReceiver(mReceiver, filter); loadStoredNameAndAddress(); if (isBluetoothPersistedStateOn()) { if (DBG) Slog.d(TAG, "Startup: Bluetooth persisted state is ON."); |