Loading framework/java/android/bluetooth/le/AdvertiseData.java +4 −4 Original line number Diff line number Diff line Loading @@ -119,8 +119,8 @@ public final class AdvertiseData implements Parcelable { } AdvertiseData other = (AdvertiseData) obj; return Objects.equals(mServiceUuids, other.mServiceUuids) && Utils.equals(mManufacturerSpecificData, other.mManufacturerSpecificData) && Utils.equals(mServiceData, other.mServiceData) && BluetoothLeUtils.equals(mManufacturerSpecificData, other.mManufacturerSpecificData) && BluetoothLeUtils.equals(mServiceData, other.mServiceData) && mIncludeDeviceName == other.mIncludeDeviceName && mIncludeTxPowerLevel == other.mIncludeTxPowerLevel; } Loading @@ -128,8 +128,8 @@ public final class AdvertiseData implements Parcelable { @Override public String toString() { return "AdvertiseData [mServiceUuids=" + mServiceUuids + ", mManufacturerSpecificData=" + Utils.toString(mManufacturerSpecificData) + ", mServiceData=" + Utils.toString(mServiceData) + BluetoothLeUtils.toString(mManufacturerSpecificData) + ", mServiceData=" + BluetoothLeUtils.toString(mServiceData) + ", mIncludeTxPowerLevel=" + mIncludeTxPowerLevel + ", mIncludeDeviceName=" + mIncludeDeviceName + "]"; } Loading framework/java/android/bluetooth/le/BluetoothLeAdvertiser.java +12 −10 Original line number Diff line number Diff line Loading @@ -107,7 +107,7 @@ public final class BluetoothLeAdvertiser { AdvertiseData advertiseData, AdvertiseData scanResponse, final AdvertiseCallback callback) { synchronized (mLeAdvertisers) { checkAdapterState(); BluetoothLeUtils.checkAdapterStateOn(mBluetoothAdapter); if (callback == null) { throw new IllegalArgumentException("callback cannot be null"); } Loading Loading @@ -150,7 +150,7 @@ public final class BluetoothLeAdvertiser { */ public void stopAdvertising(final AdvertiseCallback callback) { synchronized (mLeAdvertisers) { checkAdapterState(); BluetoothLeUtils.checkAdapterStateOn(mBluetoothAdapter); if (callback == null) { throw new IllegalArgumentException("callback cannot be null"); } Loading Loading @@ -265,9 +265,18 @@ public final class BluetoothLeAdvertiser { } if (mClientIf > 0 && mIsAdvertising) { mLeAdvertisers.put(mAdvertiseCallback, this); } else { } else if (mClientIf <= 0) { // Post internal error if registration failed. postStartFailure(mAdvertiseCallback, AdvertiseCallback.ADVERTISE_FAILED_INTERNAL_ERROR); } else { // Unregister application if it's already registered but advertise failed. try { mBluetoothGatt.unregisterClient(mClientIf); mClientIf = -1; } catch (RemoteException e) { Log.e(TAG, "remote exception when unregistering", e); } } } } Loading Loading @@ -342,13 +351,6 @@ public final class BluetoothLeAdvertiser { } } // TODO: move this api to a common util class. private void checkAdapterState() { if (mBluetoothAdapter.getState() != mBluetoothAdapter.STATE_ON) { throw new IllegalStateException("BT Adapter is not turned ON"); } } private void postStartFailure(final AdvertiseCallback callback, final int error) { mHandler.post(new Runnable() { @Override Loading framework/java/android/bluetooth/le/BluetoothLeScanner.java +4 −12 Original line number Diff line number Diff line Loading @@ -80,11 +80,10 @@ public final class BluetoothLeScanner { * @throws IllegalArgumentException If {@code callback} is null. */ public void startScan(final ScanCallback callback) { checkAdapterState(); if (callback == null) { throw new IllegalArgumentException("callback is null"); } this.startScan(null, new ScanSettings.Builder().build(), callback); startScan(null, new ScanSettings.Builder().build(), callback); } /** Loading @@ -104,7 +103,7 @@ public final class BluetoothLeScanner { private void startScan(List<ScanFilter> filters, ScanSettings settings, final ScanCallback callback, List<List<ResultStorageDescriptor>> resultStorages) { checkAdapterState(); BluetoothLeUtils.checkAdapterStateOn(mBluetoothAdapter); if (settings == null || callback == null) { throw new IllegalArgumentException("settings or callback is null"); } Loading Loading @@ -142,7 +141,7 @@ public final class BluetoothLeScanner { * @param callback */ public void stopScan(ScanCallback callback) { checkAdapterState(); BluetoothLeUtils.checkAdapterStateOn(mBluetoothAdapter); synchronized (mLeScanClients) { BleScanCallbackWrapper wrapper = mLeScanClients.remove(callback); if (wrapper == null) { Loading @@ -162,7 +161,7 @@ public final class BluetoothLeScanner { * used to start scan. */ public void flushPendingScanResults(ScanCallback callback) { checkAdapterState(); BluetoothLeUtils.checkAdapterStateOn(mBluetoothAdapter); if (callback == null) { throw new IllegalArgumentException("callback cannot be null!"); } Loading Loading @@ -373,13 +372,6 @@ public final class BluetoothLeScanner { } } // TODO: move this api to a common util class. private void checkAdapterState() { if (mBluetoothAdapter.getState() != mBluetoothAdapter.STATE_ON) { throw new IllegalStateException("BT Adapter is not turned ON"); } } private void postCallbackError(final ScanCallback callback, final int errorCode) { mHandler.post(new Runnable() { @Override Loading framework/java/android/bluetooth/le/Utils.java→framework/java/android/bluetooth/le/BluetoothLeUtils.java +15 −1 Original line number Diff line number Diff line Loading @@ -16,6 +16,7 @@ package android.bluetooth.le; import android.bluetooth.BluetoothAdapter; import android.util.SparseArray; import java.util.Arrays; Loading @@ -29,7 +30,7 @@ import java.util.Set; * * @hide */ public class Utils { public class BluetoothLeUtils { /** * Returns a string composed from a {@link SparseArray}. Loading Loading @@ -123,4 +124,17 @@ public class Utils { } return true; } /** * Ensure Bluetooth is turned on. * * @throws IllegalStateException If {@code adapter} is null or Bluetooth state is not * {@link BluetoothAdapter#STATE_ON}. */ static void checkAdapterStateOn(BluetoothAdapter adapter) { if (adapter == null || adapter.getState() != BluetoothAdapter.STATE_ON) { throw new IllegalStateException("BT Adapter is not turned ON"); } } } framework/java/android/bluetooth/le/ScanRecord.java +2 −2 Original line number Diff line number Diff line Loading @@ -268,8 +268,8 @@ public final class ScanRecord { @Override public String toString() { return "ScanRecord [mAdvertiseFlags=" + mAdvertiseFlags + ", mServiceUuids=" + mServiceUuids + ", mManufacturerSpecificData=" + Utils.toString(mManufacturerSpecificData) + ", mServiceData=" + Utils.toString(mServiceData) + ", mManufacturerSpecificData=" + BluetoothLeUtils.toString(mManufacturerSpecificData) + ", mServiceData=" + BluetoothLeUtils.toString(mServiceData) + ", mTxPowerLevel=" + mTxPowerLevel + ", mDeviceName=" + mDeviceName + "]"; } Loading Loading
framework/java/android/bluetooth/le/AdvertiseData.java +4 −4 Original line number Diff line number Diff line Loading @@ -119,8 +119,8 @@ public final class AdvertiseData implements Parcelable { } AdvertiseData other = (AdvertiseData) obj; return Objects.equals(mServiceUuids, other.mServiceUuids) && Utils.equals(mManufacturerSpecificData, other.mManufacturerSpecificData) && Utils.equals(mServiceData, other.mServiceData) && BluetoothLeUtils.equals(mManufacturerSpecificData, other.mManufacturerSpecificData) && BluetoothLeUtils.equals(mServiceData, other.mServiceData) && mIncludeDeviceName == other.mIncludeDeviceName && mIncludeTxPowerLevel == other.mIncludeTxPowerLevel; } Loading @@ -128,8 +128,8 @@ public final class AdvertiseData implements Parcelable { @Override public String toString() { return "AdvertiseData [mServiceUuids=" + mServiceUuids + ", mManufacturerSpecificData=" + Utils.toString(mManufacturerSpecificData) + ", mServiceData=" + Utils.toString(mServiceData) + BluetoothLeUtils.toString(mManufacturerSpecificData) + ", mServiceData=" + BluetoothLeUtils.toString(mServiceData) + ", mIncludeTxPowerLevel=" + mIncludeTxPowerLevel + ", mIncludeDeviceName=" + mIncludeDeviceName + "]"; } Loading
framework/java/android/bluetooth/le/BluetoothLeAdvertiser.java +12 −10 Original line number Diff line number Diff line Loading @@ -107,7 +107,7 @@ public final class BluetoothLeAdvertiser { AdvertiseData advertiseData, AdvertiseData scanResponse, final AdvertiseCallback callback) { synchronized (mLeAdvertisers) { checkAdapterState(); BluetoothLeUtils.checkAdapterStateOn(mBluetoothAdapter); if (callback == null) { throw new IllegalArgumentException("callback cannot be null"); } Loading Loading @@ -150,7 +150,7 @@ public final class BluetoothLeAdvertiser { */ public void stopAdvertising(final AdvertiseCallback callback) { synchronized (mLeAdvertisers) { checkAdapterState(); BluetoothLeUtils.checkAdapterStateOn(mBluetoothAdapter); if (callback == null) { throw new IllegalArgumentException("callback cannot be null"); } Loading Loading @@ -265,9 +265,18 @@ public final class BluetoothLeAdvertiser { } if (mClientIf > 0 && mIsAdvertising) { mLeAdvertisers.put(mAdvertiseCallback, this); } else { } else if (mClientIf <= 0) { // Post internal error if registration failed. postStartFailure(mAdvertiseCallback, AdvertiseCallback.ADVERTISE_FAILED_INTERNAL_ERROR); } else { // Unregister application if it's already registered but advertise failed. try { mBluetoothGatt.unregisterClient(mClientIf); mClientIf = -1; } catch (RemoteException e) { Log.e(TAG, "remote exception when unregistering", e); } } } } Loading Loading @@ -342,13 +351,6 @@ public final class BluetoothLeAdvertiser { } } // TODO: move this api to a common util class. private void checkAdapterState() { if (mBluetoothAdapter.getState() != mBluetoothAdapter.STATE_ON) { throw new IllegalStateException("BT Adapter is not turned ON"); } } private void postStartFailure(final AdvertiseCallback callback, final int error) { mHandler.post(new Runnable() { @Override Loading
framework/java/android/bluetooth/le/BluetoothLeScanner.java +4 −12 Original line number Diff line number Diff line Loading @@ -80,11 +80,10 @@ public final class BluetoothLeScanner { * @throws IllegalArgumentException If {@code callback} is null. */ public void startScan(final ScanCallback callback) { checkAdapterState(); if (callback == null) { throw new IllegalArgumentException("callback is null"); } this.startScan(null, new ScanSettings.Builder().build(), callback); startScan(null, new ScanSettings.Builder().build(), callback); } /** Loading @@ -104,7 +103,7 @@ public final class BluetoothLeScanner { private void startScan(List<ScanFilter> filters, ScanSettings settings, final ScanCallback callback, List<List<ResultStorageDescriptor>> resultStorages) { checkAdapterState(); BluetoothLeUtils.checkAdapterStateOn(mBluetoothAdapter); if (settings == null || callback == null) { throw new IllegalArgumentException("settings or callback is null"); } Loading Loading @@ -142,7 +141,7 @@ public final class BluetoothLeScanner { * @param callback */ public void stopScan(ScanCallback callback) { checkAdapterState(); BluetoothLeUtils.checkAdapterStateOn(mBluetoothAdapter); synchronized (mLeScanClients) { BleScanCallbackWrapper wrapper = mLeScanClients.remove(callback); if (wrapper == null) { Loading @@ -162,7 +161,7 @@ public final class BluetoothLeScanner { * used to start scan. */ public void flushPendingScanResults(ScanCallback callback) { checkAdapterState(); BluetoothLeUtils.checkAdapterStateOn(mBluetoothAdapter); if (callback == null) { throw new IllegalArgumentException("callback cannot be null!"); } Loading Loading @@ -373,13 +372,6 @@ public final class BluetoothLeScanner { } } // TODO: move this api to a common util class. private void checkAdapterState() { if (mBluetoothAdapter.getState() != mBluetoothAdapter.STATE_ON) { throw new IllegalStateException("BT Adapter is not turned ON"); } } private void postCallbackError(final ScanCallback callback, final int errorCode) { mHandler.post(new Runnable() { @Override Loading
framework/java/android/bluetooth/le/Utils.java→framework/java/android/bluetooth/le/BluetoothLeUtils.java +15 −1 Original line number Diff line number Diff line Loading @@ -16,6 +16,7 @@ package android.bluetooth.le; import android.bluetooth.BluetoothAdapter; import android.util.SparseArray; import java.util.Arrays; Loading @@ -29,7 +30,7 @@ import java.util.Set; * * @hide */ public class Utils { public class BluetoothLeUtils { /** * Returns a string composed from a {@link SparseArray}. Loading Loading @@ -123,4 +124,17 @@ public class Utils { } return true; } /** * Ensure Bluetooth is turned on. * * @throws IllegalStateException If {@code adapter} is null or Bluetooth state is not * {@link BluetoothAdapter#STATE_ON}. */ static void checkAdapterStateOn(BluetoothAdapter adapter) { if (adapter == null || adapter.getState() != BluetoothAdapter.STATE_ON) { throw new IllegalStateException("BT Adapter is not turned ON"); } } }
framework/java/android/bluetooth/le/ScanRecord.java +2 −2 Original line number Diff line number Diff line Loading @@ -268,8 +268,8 @@ public final class ScanRecord { @Override public String toString() { return "ScanRecord [mAdvertiseFlags=" + mAdvertiseFlags + ", mServiceUuids=" + mServiceUuids + ", mManufacturerSpecificData=" + Utils.toString(mManufacturerSpecificData) + ", mServiceData=" + Utils.toString(mServiceData) + ", mManufacturerSpecificData=" + BluetoothLeUtils.toString(mManufacturerSpecificData) + ", mServiceData=" + BluetoothLeUtils.toString(mServiceData) + ", mTxPowerLevel=" + mTxPowerLevel + ", mDeviceName=" + mDeviceName + "]"; } Loading