diff options
| author | 2025-03-04 08:20:00 -0800 | |
|---|---|---|
| committer | 2025-03-04 08:20:00 -0800 | |
| commit | d662bde9f3d3ccb91c9cc1db05c885da665a1bd5 (patch) | |
| tree | f87f48d1af79f3c247a96dc6ab085963ccec1172 /framework/java | |
| parent | 94e84208f2214402f8d0fa224a14914f80d513ff (diff) | |
| parent | 93dfb9659f91fb038a4f3fe71da652854e1ed746 (diff) | |
Merge "Refactor: Consolidate `isValidDevice` implementations in Bluetooth classes" into main am: 1f804765f4 am: 93dfb9659f
Original change: https://android-review.googlesource.com/c/platform/packages/modules/Bluetooth/+/3522473
Change-Id: I29bb8745cb56ad2ba3f462f7176cf2c1c6623244
Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
Diffstat (limited to 'framework/java')
16 files changed, 19 insertions, 76 deletions
diff --git a/framework/java/android/bluetooth/BluetoothA2dp.java b/framework/java/android/bluetooth/BluetoothA2dp.java index 2e3bf9ea92..207167a053 100644 --- a/framework/java/android/bluetooth/BluetoothA2dp.java +++ b/framework/java/android/bluetooth/BluetoothA2dp.java @@ -21,6 +21,7 @@ import static android.Manifest.permission.BLUETOOTH_PRIVILEGED; import static android.bluetooth.BluetoothProfile.CONNECTION_POLICY_ALLOWED; import static android.bluetooth.BluetoothProfile.CONNECTION_POLICY_FORBIDDEN; import static android.bluetooth.BluetoothProfile.STATE_DISCONNECTED; +import static android.bluetooth.BluetoothUtils.isValidDevice; import android.annotation.IntDef; import android.annotation.NonNull; @@ -1108,13 +1109,6 @@ public final class BluetoothA2dp implements BluetoothProfile { } } - private static boolean isValidDevice(BluetoothDevice device) { - if (device == null) return false; - - if (BluetoothAdapter.checkBluetoothAddress(device.getAddress())) return true; - return false; - } - private static void log(String msg) { Log.d(TAG, msg); } diff --git a/framework/java/android/bluetooth/BluetoothA2dpSink.java b/framework/java/android/bluetooth/BluetoothA2dpSink.java index c49bc1ea7a..ac45bcf46e 100644 --- a/framework/java/android/bluetooth/BluetoothA2dpSink.java +++ b/framework/java/android/bluetooth/BluetoothA2dpSink.java @@ -21,6 +21,7 @@ import static android.Manifest.permission.BLUETOOTH_PRIVILEGED; import static android.bluetooth.BluetoothProfile.CONNECTION_POLICY_ALLOWED; import static android.bluetooth.BluetoothProfile.CONNECTION_POLICY_FORBIDDEN; import static android.bluetooth.BluetoothProfile.STATE_DISCONNECTED; +import static android.bluetooth.BluetoothUtils.isValidDevice; import android.annotation.NonNull; import android.annotation.RequiresNoPermission; @@ -428,10 +429,6 @@ public final class BluetoothA2dpSink implements BluetoothProfile { return mAdapter.getState() == BluetoothAdapter.STATE_ON; } - private static boolean isValidDevice(BluetoothDevice device) { - return device != null && BluetoothAdapter.checkBluetoothAddress(device.getAddress()); - } - private static void log(String msg) { Log.d(TAG, msg); } diff --git a/framework/java/android/bluetooth/BluetoothAvrcpController.java b/framework/java/android/bluetooth/BluetoothAvrcpController.java index bb8390f559..2d39b89925 100644 --- a/framework/java/android/bluetooth/BluetoothAvrcpController.java +++ b/framework/java/android/bluetooth/BluetoothAvrcpController.java @@ -18,6 +18,7 @@ package android.bluetooth; import static android.Manifest.permission.BLUETOOTH_CONNECT; import static android.bluetooth.BluetoothProfile.STATE_DISCONNECTED; +import static android.bluetooth.BluetoothUtils.isValidDevice; import android.annotation.RequiresNoPermission; import android.annotation.RequiresPermission; @@ -275,10 +276,6 @@ public final class BluetoothAvrcpController implements BluetoothProfile { return mAdapter.getState() == BluetoothAdapter.STATE_ON; } - private static boolean isValidDevice(BluetoothDevice device) { - return device != null && BluetoothAdapter.checkBluetoothAddress(device.getAddress()); - } - private static void log(String msg) { Log.d(TAG, msg); } diff --git a/framework/java/android/bluetooth/BluetoothHapClient.java b/framework/java/android/bluetooth/BluetoothHapClient.java index 1699c5bf02..e551cca8f5 100644 --- a/framework/java/android/bluetooth/BluetoothHapClient.java +++ b/framework/java/android/bluetooth/BluetoothHapClient.java @@ -23,6 +23,7 @@ import static android.bluetooth.BluetoothProfile.CONNECTION_POLICY_ALLOWED; import static android.bluetooth.BluetoothProfile.CONNECTION_POLICY_FORBIDDEN; import static android.bluetooth.BluetoothProfile.STATE_DISCONNECTED; import static android.bluetooth.BluetoothUtils.callServiceIfEnabled; +import static android.bluetooth.BluetoothUtils.isValidDevice; import static java.util.Objects.requireNonNull; @@ -1087,11 +1088,4 @@ public final class BluetoothHapClient implements BluetoothProfile, AutoCloseable this::getService, s -> s.setPresetNameForGroup(groupId, presetIndex, name, mAttributionSource)); } - - private static boolean isValidDevice(BluetoothDevice device) { - if (device == null) return false; - - if (BluetoothAdapter.checkBluetoothAddress(device.getAddress())) return true; - return false; - } } diff --git a/framework/java/android/bluetooth/BluetoothHeadset.java b/framework/java/android/bluetooth/BluetoothHeadset.java index 448bb05ea0..3e33b42980 100644 --- a/framework/java/android/bluetooth/BluetoothHeadset.java +++ b/framework/java/android/bluetooth/BluetoothHeadset.java @@ -22,6 +22,7 @@ import static android.Manifest.permission.MODIFY_PHONE_STATE; import static android.bluetooth.BluetoothProfile.CONNECTION_POLICY_ALLOWED; import static android.bluetooth.BluetoothProfile.CONNECTION_POLICY_FORBIDDEN; import static android.bluetooth.BluetoothProfile.STATE_DISCONNECTED; +import static android.bluetooth.BluetoothUtils.isValidDevice; import static java.util.Objects.requireNonNull; @@ -1281,10 +1282,6 @@ public final class BluetoothHeadset implements BluetoothProfile { return mAdapter.getState() == BluetoothAdapter.STATE_OFF; } - private static boolean isValidDevice(BluetoothDevice device) { - return device != null && BluetoothAdapter.checkBluetoothAddress(device.getAddress()); - } - private static void log(String msg) { Log.d(TAG, msg); } diff --git a/framework/java/android/bluetooth/BluetoothHeadsetClient.java b/framework/java/android/bluetooth/BluetoothHeadsetClient.java index 14cb62c960..fea8f81c5f 100644 --- a/framework/java/android/bluetooth/BluetoothHeadsetClient.java +++ b/framework/java/android/bluetooth/BluetoothHeadsetClient.java @@ -20,6 +20,7 @@ import static android.Manifest.permission.BLUETOOTH_PRIVILEGED; import static android.bluetooth.BluetoothProfile.CONNECTION_POLICY_ALLOWED; import static android.bluetooth.BluetoothProfile.CONNECTION_POLICY_FORBIDDEN; import static android.bluetooth.BluetoothProfile.STATE_DISCONNECTED; +import static android.bluetooth.BluetoothUtils.isValidDevice; import static java.util.Objects.requireNonNull; @@ -1645,10 +1646,6 @@ public final class BluetoothHeadsetClient implements BluetoothProfile, AutoClose return mAdapter.getState() == BluetoothAdapter.STATE_ON; } - private static boolean isValidDevice(BluetoothDevice device) { - return device != null && BluetoothAdapter.checkBluetoothAddress(device.getAddress()); - } - private static void log(String msg) { Log.d(TAG, msg); } diff --git a/framework/java/android/bluetooth/BluetoothHearingAid.java b/framework/java/android/bluetooth/BluetoothHearingAid.java index d5ed621a37..7e14057546 100644 --- a/framework/java/android/bluetooth/BluetoothHearingAid.java +++ b/framework/java/android/bluetooth/BluetoothHearingAid.java @@ -22,6 +22,7 @@ import static android.Manifest.permission.BLUETOOTH_SCAN; import static android.bluetooth.BluetoothProfile.CONNECTION_POLICY_ALLOWED; import static android.bluetooth.BluetoothProfile.CONNECTION_POLICY_FORBIDDEN; import static android.bluetooth.BluetoothProfile.STATE_DISCONNECTED; +import static android.bluetooth.BluetoothUtils.isValidDevice; import android.annotation.IntDef; import android.annotation.NonNull; @@ -762,11 +763,4 @@ public final class BluetoothHearingAid implements BluetoothProfile { throw new IllegalArgumentException("Device cannot be null"); } } - - private static boolean isValidDevice(BluetoothDevice device) { - if (device == null) return false; - - if (BluetoothAdapter.checkBluetoothAddress(device.getAddress())) return true; - return false; - } } diff --git a/framework/java/android/bluetooth/BluetoothHidDevice.java b/framework/java/android/bluetooth/BluetoothHidDevice.java index 3098c80fdd..92ee4f5fb3 100644 --- a/framework/java/android/bluetooth/BluetoothHidDevice.java +++ b/framework/java/android/bluetooth/BluetoothHidDevice.java @@ -21,6 +21,7 @@ import static android.Manifest.permission.BLUETOOTH_PRIVILEGED; import static android.bluetooth.BluetoothProfile.CONNECTION_POLICY_ALLOWED; import static android.bluetooth.BluetoothProfile.CONNECTION_POLICY_FORBIDDEN; import static android.bluetooth.BluetoothUtils.executeFromBinder; +import static android.bluetooth.BluetoothUtils.isValidDevice; import android.annotation.NonNull; import android.annotation.RequiresNoPermission; @@ -788,13 +789,6 @@ public final class BluetoothHidDevice implements BluetoothProfile { return false; } - private static boolean isValidDevice(BluetoothDevice device) { - if (device == null) return false; - - if (BluetoothAdapter.checkBluetoothAddress(device.getAddress())) return true; - return false; - } - private static void log(String msg) { if (DBG) { Log.d(TAG, msg); diff --git a/framework/java/android/bluetooth/BluetoothHidHost.java b/framework/java/android/bluetooth/BluetoothHidHost.java index 7b67a90862..5eb6895746 100644 --- a/framework/java/android/bluetooth/BluetoothHidHost.java +++ b/framework/java/android/bluetooth/BluetoothHidHost.java @@ -21,6 +21,7 @@ import static android.Manifest.permission.BLUETOOTH_PRIVILEGED; import static android.bluetooth.BluetoothProfile.CONNECTION_POLICY_ALLOWED; import static android.bluetooth.BluetoothProfile.CONNECTION_POLICY_FORBIDDEN; import static android.bluetooth.BluetoothProfile.STATE_DISCONNECTED; +import static android.bluetooth.BluetoothUtils.isValidDevice; import static java.util.Objects.requireNonNull; @@ -604,10 +605,6 @@ public final class BluetoothHidHost implements BluetoothProfile { return mAdapter.getState() == BluetoothAdapter.STATE_ON; } - private static boolean isValidDevice(BluetoothDevice device) { - return device != null && BluetoothAdapter.checkBluetoothAddress(device.getAddress()); - } - /** * Initiate virtual unplug for a HID input device. * diff --git a/framework/java/android/bluetooth/BluetoothMap.java b/framework/java/android/bluetooth/BluetoothMap.java index f88ec35dbb..4c44995921 100644 --- a/framework/java/android/bluetooth/BluetoothMap.java +++ b/framework/java/android/bluetooth/BluetoothMap.java @@ -21,6 +21,7 @@ import static android.Manifest.permission.BLUETOOTH_PRIVILEGED; import static android.bluetooth.BluetoothProfile.CONNECTION_POLICY_ALLOWED; import static android.bluetooth.BluetoothProfile.CONNECTION_POLICY_FORBIDDEN; import static android.bluetooth.BluetoothProfile.STATE_DISCONNECTED; +import static android.bluetooth.BluetoothUtils.isValidDevice; import android.annotation.NonNull; import android.annotation.RequiresNoPermission; @@ -553,8 +554,4 @@ public final class BluetoothMap implements BluetoothProfile, AutoCloseable { private boolean isEnabled() { return mAdapter.isEnabled(); } - - private static boolean isValidDevice(BluetoothDevice device) { - return device != null && BluetoothAdapter.checkBluetoothAddress(device.getAddress()); - } } diff --git a/framework/java/android/bluetooth/BluetoothMapClient.java b/framework/java/android/bluetooth/BluetoothMapClient.java index 2b28da9f0c..a018669858 100644 --- a/framework/java/android/bluetooth/BluetoothMapClient.java +++ b/framework/java/android/bluetooth/BluetoothMapClient.java @@ -23,6 +23,7 @@ import static android.Manifest.permission.SEND_SMS; import static android.bluetooth.BluetoothProfile.CONNECTION_POLICY_ALLOWED; import static android.bluetooth.BluetoothProfile.CONNECTION_POLICY_FORBIDDEN; import static android.bluetooth.BluetoothProfile.STATE_DISCONNECTED; +import static android.bluetooth.BluetoothUtils.isValidDevice; import android.annotation.NonNull; import android.annotation.Nullable; @@ -574,8 +575,4 @@ public final class BluetoothMapClient implements BluetoothProfile, AutoCloseable private boolean isEnabled() { return mAdapter.isEnabled(); } - - private static boolean isValidDevice(BluetoothDevice device) { - return device != null && BluetoothAdapter.checkBluetoothAddress(device.getAddress()); - } } diff --git a/framework/java/android/bluetooth/BluetoothPan.java b/framework/java/android/bluetooth/BluetoothPan.java index 43b1469407..ded188821e 100644 --- a/framework/java/android/bluetooth/BluetoothPan.java +++ b/framework/java/android/bluetooth/BluetoothPan.java @@ -24,6 +24,7 @@ import static android.bluetooth.BluetoothProfile.CONNECTION_POLICY_ALLOWED; import static android.bluetooth.BluetoothProfile.CONNECTION_POLICY_FORBIDDEN; import static android.bluetooth.BluetoothProfile.STATE_DISCONNECTED; import static android.bluetooth.BluetoothUtils.executeFromBinder; +import static android.bluetooth.BluetoothUtils.isValidDevice; import static java.util.Objects.requireNonNull; @@ -610,11 +611,6 @@ public final class BluetoothPan implements BluetoothProfile { } @UnsupportedAppUsage - private static boolean isValidDevice(BluetoothDevice device) { - return device != null && BluetoothAdapter.checkBluetoothAddress(device.getAddress()); - } - - @UnsupportedAppUsage private static void log(String msg) { Log.d(TAG, msg); } diff --git a/framework/java/android/bluetooth/BluetoothPbap.java b/framework/java/android/bluetooth/BluetoothPbap.java index ecbbe0ab23..8da64ddb96 100644 --- a/framework/java/android/bluetooth/BluetoothPbap.java +++ b/framework/java/android/bluetooth/BluetoothPbap.java @@ -21,6 +21,7 @@ import static android.Manifest.permission.BLUETOOTH_PRIVILEGED; import static android.bluetooth.BluetoothProfile.CONNECTION_POLICY_ALLOWED; import static android.bluetooth.BluetoothProfile.CONNECTION_POLICY_FORBIDDEN; import static android.bluetooth.BluetoothProfile.STATE_DISCONNECTED; +import static android.bluetooth.BluetoothUtils.isValidDevice; import android.annotation.NonNull; import android.annotation.RequiresNoPermission; @@ -300,13 +301,6 @@ public class BluetoothPbap implements BluetoothProfile { return false; } - private static boolean isValidDevice(BluetoothDevice device) { - if (device == null) return false; - - if (BluetoothAdapter.checkBluetoothAddress(device.getAddress())) return true; - return false; - } - private static void log(String msg) { if (DBG) { Log.d(TAG, msg); diff --git a/framework/java/android/bluetooth/BluetoothPbapClient.java b/framework/java/android/bluetooth/BluetoothPbapClient.java index 4c0eff490b..391c46da63 100644 --- a/framework/java/android/bluetooth/BluetoothPbapClient.java +++ b/framework/java/android/bluetooth/BluetoothPbapClient.java @@ -21,6 +21,7 @@ import static android.Manifest.permission.BLUETOOTH_PRIVILEGED; import static android.bluetooth.BluetoothProfile.CONNECTION_POLICY_ALLOWED; import static android.bluetooth.BluetoothProfile.CONNECTION_POLICY_FORBIDDEN; import static android.bluetooth.BluetoothProfile.STATE_DISCONNECTED; +import static android.bluetooth.BluetoothUtils.isValidDevice; import android.annotation.NonNull; import android.annotation.RequiresNoPermission; @@ -312,10 +313,6 @@ public final class BluetoothPbapClient implements BluetoothProfile, AutoCloseabl return mAdapter.isEnabled(); } - private static boolean isValidDevice(BluetoothDevice device) { - return device != null && BluetoothAdapter.checkBluetoothAddress(device.getAddress()); - } - /** * Set priority of the profile * diff --git a/framework/java/android/bluetooth/BluetoothSap.java b/framework/java/android/bluetooth/BluetoothSap.java index aa4686d30a..5ec412cb39 100644 --- a/framework/java/android/bluetooth/BluetoothSap.java +++ b/framework/java/android/bluetooth/BluetoothSap.java @@ -21,6 +21,7 @@ import static android.Manifest.permission.BLUETOOTH_PRIVILEGED; import static android.bluetooth.BluetoothProfile.CONNECTION_POLICY_ALLOWED; import static android.bluetooth.BluetoothProfile.CONNECTION_POLICY_FORBIDDEN; import static android.bluetooth.BluetoothProfile.STATE_DISCONNECTED; +import static android.bluetooth.BluetoothUtils.isValidDevice; import static java.util.Objects.requireNonNull; @@ -539,8 +540,4 @@ public final class BluetoothSap implements BluetoothProfile, AutoCloseable { private boolean isEnabled() { return mAdapter.isEnabled(); } - - private static boolean isValidDevice(BluetoothDevice device) { - return device != null && BluetoothAdapter.checkBluetoothAddress(device.getAddress()); - } } diff --git a/framework/java/android/bluetooth/BluetoothUtils.java b/framework/java/android/bluetooth/BluetoothUtils.java index 52fb2160a5..2665af1bac 100644 --- a/framework/java/android/bluetooth/BluetoothUtils.java +++ b/framework/java/android/bluetooth/BluetoothUtils.java @@ -429,4 +429,8 @@ public final class BluetoothUtils { public static void logRemoteException(String tag, RemoteException ex) { Log.w(tag, ex.toString() + ": " + inlineStackTrace()); } + + static boolean isValidDevice(BluetoothDevice device) { + return device != null && BluetoothAdapter.checkBluetoothAddress(device.getAddress()); + } } |