summaryrefslogtreecommitdiff
path: root/service
diff options
context:
space:
mode:
author William Escande <wescande@google.com> 2025-03-06 13:10:25 -0800
committer William Escande <wescande@google.com> 2025-03-09 23:18:35 -0700
commit58c6f2f01a862d28fd16ab8500947f1a01616871 (patch)
tree8536779c20b260b801b01ba5090d69a31cb45af0 /service
parent42bff3c80946fe5320f8308dabe7150e5198e280 (diff)
25Q1 flag removal: get_name_and_address_as_callback
Bug: 368114370 Fix: 368114370 Flag: com.android.bluetooth.flags.get_name_and_address_as_callback Test: m com.android.bt Change-Id: Ic5def8cdf322302678f981e1164334be7a812ca9
Diffstat (limited to 'service')
-rw-r--r--service/src/com/android/server/bluetooth/BluetoothManagerService.java126
-rw-r--r--service/tests/src/com/android/server/bluetooth/BluetoothManagerServiceTest.java4
2 files changed, 11 insertions, 119 deletions
diff --git a/service/src/com/android/server/bluetooth/BluetoothManagerService.java b/service/src/com/android/server/bluetooth/BluetoothManagerService.java
index d352c22693..216b621794 100644
--- a/service/src/com/android/server/bluetooth/BluetoothManagerService.java
+++ b/service/src/com/android/server/bluetooth/BluetoothManagerService.java
@@ -510,24 +510,7 @@ class BluetoothManagerService {
@Override
public void onReceive(Context context, Intent intent) {
String action = intent.getAction();
- if (!Flags.getNameAndAddressAsCallback()
- && BluetoothAdapter.ACTION_LOCAL_NAME_CHANGED.equals(action)) {
- String newName = intent.getStringExtra(BluetoothAdapter.EXTRA_LOCAL_NAME);
- if (newName != null) {
- Log.d(TAG, "Local name changed to: " + newName);
- storeNameAndAddress(newName, null);
- }
- } else if (!Flags.getNameAndAddressAsCallback()
- && BluetoothAdapter.ACTION_BLUETOOTH_ADDRESS_CHANGED.equals(action)) {
- String newAddress =
- intent.getStringExtra(BluetoothAdapter.EXTRA_BLUETOOTH_ADDRESS);
- if (newAddress != null) {
- Log.d(TAG, "Local address changed to: " + logAddress(newAddress));
- storeNameAndAddress(null, newAddress);
- } else {
- Log.e(TAG, "No Bluetooth Adapter address parameter found");
- }
- } else if (Intent.ACTION_SETTING_RESTORED.equals(action)) {
+ if (Intent.ACTION_SETTING_RESTORED.equals(action)) {
final String name = intent.getStringExtra(Intent.EXTRA_SETTING_NAME);
if (Settings.Global.BLUETOOTH_ON.equals(name)) {
// The Bluetooth On state may be changed during system restore.
@@ -602,10 +585,6 @@ class BluetoothManagerService {
}
IntentFilter filter = new IntentFilter();
- if (!Flags.getNameAndAddressAsCallback()) {
- filter.addAction(BluetoothAdapter.ACTION_LOCAL_NAME_CHANGED);
- filter.addAction(BluetoothAdapter.ACTION_BLUETOOTH_ADDRESS_CHANGED);
- }
filter.addAction(Intent.ACTION_SETTING_RESTORED);
filter.addAction(Intent.ACTION_SHUTDOWN);
filter.setPriority(IntentFilter.SYSTEM_HIGH_PRIORITY);
@@ -640,20 +619,15 @@ class BluetoothManagerService {
null,
mHandler);
- if (Flags.getNameAndAddressAsCallback()) {
- mName =
- BluetoothServerProxy.getInstance()
- .settingsSecureGetString(
- mContentResolver, Settings.Secure.BLUETOOTH_NAME);
- mAddress =
- BluetoothServerProxy.getInstance()
- .settingsSecureGetString(
- mContentResolver, Settings.Secure.BLUETOOTH_ADDRESS);
-
- Log.d(TAG, "Local adapter: Name=" + mName + ", Address=" + logAddress(mAddress));
- } else {
- loadStoredNameAndAddress();
- }
+ mName =
+ BluetoothServerProxy.getInstance()
+ .settingsSecureGetString(mContentResolver, Settings.Secure.BLUETOOTH_NAME);
+ mAddress =
+ BluetoothServerProxy.getInstance()
+ .settingsSecureGetString(
+ mContentResolver, Settings.Secure.BLUETOOTH_ADDRESS);
+
+ Log.d(TAG, "Local adapter: Name=" + mName + ", Address=" + logAddress(mAddress));
if (isBluetoothPersistedStateOn()) {
Log.i(TAG, "Startup: Bluetooth persisted state is ON.");
@@ -723,25 +697,6 @@ class BluetoothManagerService {
BluetoothServerProxy.getInstance().setBluetoothPersistedState(mContentResolver, state);
}
- private void loadStoredNameAndAddress() {
- if (BluetoothProperties.isAdapterAddressValidationEnabled().orElse(false)
- && Settings.Secure.getInt(mContentResolver, Settings.Secure.BLUETOOTH_ADDR_VALID, 0)
- == 0) {
- // if the valid flag is not set, don't load the address and name
- Log.w(TAG, "There is no valid bluetooth name and address stored");
- return;
- }
- mName =
- BluetoothServerProxy.getInstance()
- .settingsSecureGetString(mContentResolver, Settings.Secure.BLUETOOTH_NAME);
- mAddress =
- BluetoothServerProxy.getInstance()
- .settingsSecureGetString(
- mContentResolver, Settings.Secure.BLUETOOTH_ADDRESS);
-
- Log.d(TAG, "loadStoredNameAndAddress: Name=" + mName + ", Address=" + logAddress(mAddress));
- }
-
private static String logAddress(String address) {
if (address == null) {
return "[address is null]";
@@ -752,35 +707,6 @@ class BluetoothManagerService {
return "XX:XX:XX:XX:" + address.substring(address.length() - 5);
}
- /**
- * Save the Bluetooth name and address in the persistent store. Only non-null values will be
- * saved.
- */
- private void storeNameAndAddress(String name, String address) {
- final String logHeader = "storeNameAndAddress(" + name + ", " + logAddress(address) + "): ";
- if (name != null) {
- if (Settings.Secure.putString(mContentResolver, Settings.Secure.BLUETOOTH_NAME, name)) {
- mName = name;
- } else {
- Log.e(TAG, logHeader + "Failed. Name is still " + mName);
- }
- }
-
- if (address != null) {
- if (Settings.Secure.putString(
- mContentResolver, Settings.Secure.BLUETOOTH_ADDRESS, address)) {
- mAddress = address;
- } else {
- Log.e(TAG, logHeader + "Failed. Address is still " + logAddress(mAddress));
- }
- }
-
- if ((mName != null) && (mAddress != null)) {
- Settings.Secure.putInt(mContentResolver, Settings.Secure.BLUETOOTH_ADDR_VALID, 1);
- }
- Log.d(TAG, logHeader + "Completed successfully");
- }
-
// Called from unsafe binder thread
IBluetooth registerAdapter(IBluetoothManagerCallback callback) {
mCallbacks.register(callback);
@@ -1273,43 +1199,11 @@ class BluetoothManagerService {
// Called from unsafe binder thread
String getAddress() {
- if (Flags.getNameAndAddressAsCallback()) {
- return mAddress;
- }
- // Copy to local variable to avoid race condition when checking for null
- AdapterBinder adapter = mAdapter;
- if (adapter != null) {
- try {
- return adapter.getAddress(mContext.getAttributionSource());
- } catch (RemoteException e) {
- Log.e(TAG, "getAddress(): Returning cached address", e);
- }
- }
-
- // mAddress is accessed from outside.
- // It is alright without a lock. Here, bluetooth is off, no other thread is
- // changing mAddress
return mAddress;
}
// Called from unsafe binder thread
String getName() {
- if (Flags.getNameAndAddressAsCallback()) {
- return mName;
- }
- // Copy to local variable to avoid race condition when checking for null
- AdapterBinder adapter = mAdapter;
- if (adapter != null) {
- try {
- return adapter.getName(mContext.getAttributionSource());
- } catch (RemoteException e) {
- Log.e(TAG, "getName(): Returning cached name", e);
- }
- }
-
- // mName is accessed from outside.
- // It alright without a lock. Here, bluetooth is off, no other thread is
- // changing mName
return mName;
}
diff --git a/service/tests/src/com/android/server/bluetooth/BluetoothManagerServiceTest.java b/service/tests/src/com/android/server/bluetooth/BluetoothManagerServiceTest.java
index ab80f152e6..480af98329 100644
--- a/service/tests/src/com/android/server/bluetooth/BluetoothManagerServiceTest.java
+++ b/service/tests/src/com/android/server/bluetooth/BluetoothManagerServiceTest.java
@@ -69,8 +69,6 @@ import android.provider.Settings;
import androidx.test.platform.app.InstrumentationRegistry;
-import com.android.bluetooth.flags.Flags;
-
import org.junit.After;
import org.junit.Before;
import org.junit.Rule;
@@ -95,7 +93,7 @@ public class BluetoothManagerServiceTest {
@Parameters(name = "{0}")
public static List<FlagsParameterization> getParams() {
- return FlagsParameterization.allCombinationsOf(Flags.FLAG_GET_NAME_AND_ADDRESS_AS_CALLBACK);
+ return FlagsParameterization.allCombinationsOf();
}
public BluetoothManagerServiceTest(FlagsParameterization flags) {