Merge "[AWARE] Update network API: make open/encrypted explicit"
diff --git a/Android.mk b/Android.mk
index 4e1479a..a07fd01 100644
--- a/Android.mk
+++ b/Android.mk
@@ -128,9 +128,11 @@
core/java/android/bluetooth/IBluetoothInputHost.aidl \
core/java/android/bluetooth/IBluetoothHidDeviceCallback.aidl \
core/java/android/bluetooth/IBluetoothGatt.aidl \
- core/java/android/bluetooth/IBluetoothGattCallback.aidl \
- core/java/android/bluetooth/IBluetoothGattServerCallback.aidl \
+ core/java/android/bluetooth/IBluetoothGattCallbackExt.aidl \
+ core/java/android/bluetooth/IBluetoothGattServerCallbackExt.aidl \
core/java/android/bluetooth/le/IAdvertiserCallback.aidl \
+ core/java/android/bluetooth/le/IAdvertisingSetCallback.aidl \
+ core/java/android/bluetooth/le/IPeriodicAdvertisingCallback.aidl \
core/java/android/bluetooth/le/IScannerCallback.aidl \
core/java/android/content/IClipboard.aidl \
core/java/android/content/IContentService.aidl \
diff --git a/api/current.txt b/api/current.txt
index 8bce532..b5a99ca 100644
--- a/api/current.txt
+++ b/api/current.txt
@@ -6695,6 +6695,7 @@
method public java.util.Set<android.bluetooth.BluetoothDevice> getBondedDevices();
method public static synchronized android.bluetooth.BluetoothAdapter getDefaultAdapter();
method public java.lang.String getName();
+ method public android.bluetooth.le.PeriodicAdvertisingManager getPeriodicAdvertisingManager();
method public int getProfileConnectionState(int);
method public boolean getProfileProxy(android.content.Context, android.bluetooth.BluetoothProfile.ServiceListener, int);
method public android.bluetooth.BluetoothDevice getRemoteDevice(java.lang.String);
@@ -6703,6 +6704,10 @@
method public int getState();
method public boolean isDiscovering();
method public boolean isEnabled();
+ method public boolean isLe2MPhySupported();
+ method public boolean isLeCodedPhySupported();
+ method public boolean isLeExtendedAdvertisingSupported();
+ method public boolean isLePeriodicAdvertisingSupported();
method public boolean isMultipleAdvertisementSupported();
method public boolean isOffloadedFilteringSupported();
method public boolean isOffloadedScanBatchingSupported();
@@ -7071,6 +7076,9 @@
public final class BluetoothDevice implements android.os.Parcelable {
method public android.bluetooth.BluetoothGatt connectGatt(android.content.Context, boolean, android.bluetooth.BluetoothGattCallback);
method public android.bluetooth.BluetoothGatt connectGatt(android.content.Context, boolean, android.bluetooth.BluetoothGattCallback, int);
+ method public android.bluetooth.BluetoothGatt connectGatt(android.content.Context, boolean, android.bluetooth.BluetoothGattCallbackExt);
+ method public android.bluetooth.BluetoothGatt connectGatt(android.content.Context, boolean, android.bluetooth.BluetoothGattCallbackExt, int);
+ method public android.bluetooth.BluetoothGatt connectGatt(android.content.Context, boolean, android.bluetooth.BluetoothGattCallbackExt, int, int);
method public boolean createBond();
method public android.bluetooth.BluetoothSocket createInsecureRfcommSocketToServiceRecord(java.util.UUID) throws java.io.IOException;
method public android.bluetooth.BluetoothSocket createRfcommSocketToServiceRecord(java.util.UUID) throws java.io.IOException;
@@ -7114,6 +7122,13 @@
field public static final java.lang.String EXTRA_UUID = "android.bluetooth.device.extra.UUID";
field public static final int PAIRING_VARIANT_PASSKEY_CONFIRMATION = 2; // 0x2
field public static final int PAIRING_VARIANT_PIN = 0; // 0x0
+ field public static final int PHY_LE_1M = 1; // 0x1
+ field public static final int PHY_LE_2M = 2; // 0x2
+ field public static final int PHY_LE_ANY = 7; // 0x7
+ field public static final int PHY_LE_CODED = 4; // 0x4
+ field public static final int PHY_OPTION_NO_PREFERRED = 0; // 0x0
+ field public static final int PHY_OPTION_S2 = 1; // 0x1
+ field public static final int PHY_OPTION_S8 = 2; // 0x2
field public static final int TRANSPORT_AUTO = 0; // 0x0
field public static final int TRANSPORT_BREDR = 1; // 0x1
field public static final int TRANSPORT_LE = 2; // 0x2
@@ -7136,10 +7151,12 @@
method public java.util.List<android.bluetooth.BluetoothGattService> getServices();
method public boolean readCharacteristic(android.bluetooth.BluetoothGattCharacteristic);
method public boolean readDescriptor(android.bluetooth.BluetoothGattDescriptor);
+ method public void readPhy();
method public boolean readRemoteRssi();
method public boolean requestConnectionPriority(int);
method public boolean requestMtu(int);
method public boolean setCharacteristicNotification(android.bluetooth.BluetoothGattCharacteristic, boolean);
+ method public void setPreferredPhy(int, int, int);
method public boolean writeCharacteristic(android.bluetooth.BluetoothGattCharacteristic);
method public boolean writeDescriptor(android.bluetooth.BluetoothGattDescriptor);
field public static final int CONNECTION_PRIORITY_BALANCED = 0; // 0x0
@@ -7157,8 +7174,12 @@
field public static final int GATT_WRITE_NOT_PERMITTED = 3; // 0x3
}
- public abstract class BluetoothGattCallback {
+ public abstract deprecated class BluetoothGattCallback extends android.bluetooth.BluetoothGattCallbackExt {
ctor public BluetoothGattCallback();
+ }
+
+ public abstract class BluetoothGattCallbackExt {
+ ctor public BluetoothGattCallbackExt();
method public void onCharacteristicChanged(android.bluetooth.BluetoothGatt, android.bluetooth.BluetoothGattCharacteristic);
method public void onCharacteristicRead(android.bluetooth.BluetoothGatt, android.bluetooth.BluetoothGattCharacteristic, int);
method public void onCharacteristicWrite(android.bluetooth.BluetoothGatt, android.bluetooth.BluetoothGattCharacteristic, int);
@@ -7166,6 +7187,8 @@
method public void onDescriptorRead(android.bluetooth.BluetoothGatt, android.bluetooth.BluetoothGattDescriptor, int);
method public void onDescriptorWrite(android.bluetooth.BluetoothGatt, android.bluetooth.BluetoothGattDescriptor, int);
method public void onMtuChanged(android.bluetooth.BluetoothGatt, int, int);
+ method public void onPhyRead(android.bluetooth.BluetoothGatt, int, int, int);
+ method public void onPhyUpdate(android.bluetooth.BluetoothGatt, int, int, int);
method public void onReadRemoteRssi(android.bluetooth.BluetoothGatt, int, int);
method public void onReliableWriteCompleted(android.bluetooth.BluetoothGatt, int);
method public void onServicesDiscovered(android.bluetooth.BluetoothGatt, int);
@@ -7259,12 +7282,18 @@
method public android.bluetooth.BluetoothGattService getService(java.util.UUID);
method public java.util.List<android.bluetooth.BluetoothGattService> getServices();
method public boolean notifyCharacteristicChanged(android.bluetooth.BluetoothDevice, android.bluetooth.BluetoothGattCharacteristic, boolean);
+ method public void readPhy(android.bluetooth.BluetoothDevice);
method public boolean removeService(android.bluetooth.BluetoothGattService);
method public boolean sendResponse(android.bluetooth.BluetoothDevice, int, int, int, byte[]);
+ method public void setPreferredPhy(android.bluetooth.BluetoothDevice, int, int, int);
}
- public abstract class BluetoothGattServerCallback {
+ public abstract deprecated class BluetoothGattServerCallback extends android.bluetooth.BluetoothGattServerCallbackExt {
ctor public BluetoothGattServerCallback();
+ }
+
+ public abstract class BluetoothGattServerCallbackExt {
+ ctor public BluetoothGattServerCallbackExt();
method public void onCharacteristicReadRequest(android.bluetooth.BluetoothDevice, int, int, android.bluetooth.BluetoothGattCharacteristic);
method public void onCharacteristicWriteRequest(android.bluetooth.BluetoothDevice, int, android.bluetooth.BluetoothGattCharacteristic, boolean, boolean, int, byte[]);
method public void onConnectionStateChange(android.bluetooth.BluetoothDevice, int, int);
@@ -7273,6 +7302,8 @@
method public void onExecuteWrite(android.bluetooth.BluetoothDevice, int, boolean);
method public void onMtuChanged(android.bluetooth.BluetoothDevice, int);
method public void onNotificationSent(android.bluetooth.BluetoothDevice, int);
+ method public void onPhyRead(android.bluetooth.BluetoothDevice, int, int, int);
+ method public void onPhyUpdate(android.bluetooth.BluetoothDevice, int, int, int);
method public void onServiceAdded(int, android.bluetooth.BluetoothGattService);
}
@@ -7473,10 +7504,85 @@
method public android.bluetooth.le.AdvertiseSettings.Builder setTxPowerLevel(int);
}
+ public final class AdvertisingSet {
+ method public void enableAdvertising(boolean);
+ method public void periodicAdvertisingEnable(boolean);
+ method public void setAdvertisingData(android.bluetooth.le.AdvertiseData);
+ method public void setAdvertisingParameters(android.bluetooth.le.AdvertisingSetParameters);
+ method public void setPeriodicAdvertisingData(android.bluetooth.le.AdvertiseData);
+ method public void setPeriodicAdvertisingParameters(android.bluetooth.le.PeriodicAdvertisingParameters);
+ method public void setScanResponseData(android.bluetooth.le.AdvertiseData);
+ }
+
+ public abstract class AdvertisingSetCallback {
+ ctor public AdvertisingSetCallback();
+ method public void onAdvertisingDataSet(android.bluetooth.le.AdvertisingSet, int);
+ method public void onAdvertisingEnabled(android.bluetooth.le.AdvertisingSet, boolean, int);
+ method public void onAdvertisingParametersUpdated(android.bluetooth.le.AdvertisingSet, int);
+ method public void onAdvertisingSetStarted(android.bluetooth.le.AdvertisingSet, int);
+ method public void onAdvertisingSetStopped(android.bluetooth.le.AdvertisingSet);
+ method public void onPeriodicAdvertisingDataSet(android.bluetooth.le.AdvertisingSet, int);
+ method public void onPeriodicAdvertisingEnable(android.bluetooth.le.AdvertisingSet, boolean, int);
+ method public void onPeriodicAdvertisingParametersUpdated(android.bluetooth.le.AdvertisingSet, int);
+ method public void onScanResponseDataSet(android.bluetooth.le.AdvertisingSet, int);
+ field public static final int ADVERTISE_FAILED_ALREADY_STARTED = 3; // 0x3
+ field public static final int ADVERTISE_FAILED_DATA_TOO_LARGE = 1; // 0x1
+ field public static final int ADVERTISE_FAILED_FEATURE_UNSUPPORTED = 5; // 0x5
+ field public static final int ADVERTISE_FAILED_INTERNAL_ERROR = 4; // 0x4
+ field public static final int ADVERTISE_FAILED_TOO_MANY_ADVERTISERS = 2; // 0x2
+ field public static final int ADVERTISE_SUCCESS = 0; // 0x0
+ }
+
+ public final class AdvertisingSetParameters implements android.os.Parcelable {
+ method public int describeContents();
+ method public int getInterval();
+ method public int getPrimaryPhy();
+ method public int getSecondaryPhy();
+ method public int getTimeout();
+ method public int getTxPowerLevel();
+ method public boolean includeTxPower();
+ method public boolean isAnonymous();
+ method public boolean isConnectable();
+ method public boolean isLegacy();
+ method public void writeToParcel(android.os.Parcel, int);
+ field public static final android.os.Parcelable.Creator<android.bluetooth.le.AdvertisingSetParameters> CREATOR;
+ field public static final int INTERVAL_HIGH = 160; // 0xa0
+ field public static final int INTERVAL_LOW = 1600; // 0x640
+ field public static final int INTERVAL_MAX = 16777215; // 0xffffff
+ field public static final int INTERVAL_MEDIUM = 400; // 0x190
+ field public static final int INTERVAL_MIN = 160; // 0xa0
+ field public static final int PHY_LE_1M = 1; // 0x1
+ field public static final int PHY_LE_2M = 2; // 0x2
+ field public static final int PHY_LE_CODED = 3; // 0x3
+ field public static final int TX_POWER_HIGH = 1; // 0x1
+ field public static final int TX_POWER_LOW = -15; // 0xfffffff1
+ field public static final int TX_POWER_MAX = 1; // 0x1
+ field public static final int TX_POWER_MEDIUM = -7; // 0xfffffff9
+ field public static final int TX_POWER_MIN = -127; // 0xffffff81
+ field public static final int TX_POWER_ULTRA_LOW = -21; // 0xffffffeb
+ }
+
+ public static final class AdvertisingSetParameters.Builder {
+ ctor public AdvertisingSetParameters.Builder();
+ method public android.bluetooth.le.AdvertisingSetParameters build();
+ method public android.bluetooth.le.AdvertisingSetParameters.Builder setAnonymouus(boolean);
+ method public android.bluetooth.le.AdvertisingSetParameters.Builder setConnectable(boolean);
+ method public android.bluetooth.le.AdvertisingSetParameters.Builder setIncludeTxPower(boolean);
+ method public android.bluetooth.le.AdvertisingSetParameters.Builder setInterval(int);
+ method public android.bluetooth.le.AdvertisingSetParameters.Builder setLegacyMode(boolean);
+ method public android.bluetooth.le.AdvertisingSetParameters.Builder setPrimaryPhy(int);
+ method public android.bluetooth.le.AdvertisingSetParameters.Builder setSecondaryPhy(int);
+ method public android.bluetooth.le.AdvertisingSetParameters.Builder setTimeout(int);
+ method public android.bluetooth.le.AdvertisingSetParameters.Builder setTxPowerLevel(int);
+ }
+
public final class BluetoothLeAdvertiser {
method public void startAdvertising(android.bluetooth.le.AdvertiseSettings, android.bluetooth.le.AdvertiseData, android.bluetooth.le.AdvertiseCallback);
method public void startAdvertising(android.bluetooth.le.AdvertiseSettings, android.bluetooth.le.AdvertiseData, android.bluetooth.le.AdvertiseData, android.bluetooth.le.AdvertiseCallback);
+ method public void startAdvertisingSet(android.bluetooth.le.AdvertisingSetParameters, android.bluetooth.le.AdvertiseData, android.bluetooth.le.AdvertiseData, android.bluetooth.le.PeriodicAdvertisingParameters, android.bluetooth.le.AdvertiseData, android.bluetooth.le.AdvertisingSetCallback);
+ method public void startAdvertisingSet(android.bluetooth.le.AdvertisingSetParameters, android.bluetooth.le.AdvertiseData, android.bluetooth.le.AdvertiseData, android.bluetooth.le.PeriodicAdvertisingParameters, android.bluetooth.le.AdvertiseData, android.bluetooth.le.AdvertisingSetCallback, android.os.Handler);
method public void stopAdvertising(android.bluetooth.le.AdvertiseCallback);
+ method public void stopAdvertisingSet(android.bluetooth.le.AdvertisingSetCallback);
}
public final class BluetoothLeScanner {
@@ -7486,6 +7592,53 @@
method public void stopScan(android.bluetooth.le.ScanCallback);
}
+ public abstract class PeriodicAdvertisingCallback {
+ ctor public PeriodicAdvertisingCallback();
+ method public void onPeriodicAdvertisingReport(android.bluetooth.le.PeriodicAdvertisingReport);
+ method public void onSyncEstablished(int, android.bluetooth.BluetoothDevice, int, int, int, int);
+ method public void onSyncLost(int);
+ field public static final int SYNC_NO_RESOURCES = 2; // 0x2
+ field public static final int SYNC_NO_RESPONSE = 1; // 0x1
+ }
+
+ public final class PeriodicAdvertisingManager {
+ method public void registerSync(android.bluetooth.le.ScanResult, int, int, android.bluetooth.le.PeriodicAdvertisingCallback);
+ method public void registerSync(android.bluetooth.le.ScanResult, int, int, android.bluetooth.le.PeriodicAdvertisingCallback, android.os.Handler);
+ method public void unregisterSync(android.bluetooth.le.PeriodicAdvertisingCallback);
+ }
+
+ public final class PeriodicAdvertisingParameters implements android.os.Parcelable {
+ method public int describeContents();
+ method public boolean getEnable();
+ method public boolean getIncludeTxPower();
+ method public int getInterval();
+ method public void writeToParcel(android.os.Parcel, int);
+ field public static final android.os.Parcelable.Creator<android.bluetooth.le.PeriodicAdvertisingParameters> CREATOR;
+ }
+
+ public static final class PeriodicAdvertisingParameters.Builder {
+ ctor public PeriodicAdvertisingParameters.Builder();
+ method public android.bluetooth.le.PeriodicAdvertisingParameters build();
+ method public android.bluetooth.le.PeriodicAdvertisingParameters.Builder setEnable(boolean);
+ method public android.bluetooth.le.PeriodicAdvertisingParameters.Builder setIncludeTxPower(boolean);
+ method public android.bluetooth.le.PeriodicAdvertisingParameters.Builder setInterval(int);
+ }
+
+ public final class PeriodicAdvertisingReport implements android.os.Parcelable {
+ ctor public PeriodicAdvertisingReport(int, int, int, int, android.bluetooth.le.ScanRecord);
+ method public int describeContents();
+ method public android.bluetooth.le.ScanRecord getData();
+ method public int getDataStatus();
+ method public int getRssi();
+ method public int getSyncHandle();
+ method public long getTimestampNanos();
+ method public int getTxPower();
+ method public void writeToParcel(android.os.Parcel, int);
+ field public static final android.os.Parcelable.Creator<android.bluetooth.le.PeriodicAdvertisingReport> CREATOR;
+ field public static final int DATA_COMPLETE = 0; // 0x0
+ field public static final int DATA_INCOMPLETE_TRUNCATED = 2; // 0x2
+ }
+
public abstract class ScanCallback {
ctor public ScanCallback();
method public void onBatchScanResults(java.util.List<android.bluetooth.le.ScanResult>);
@@ -7540,19 +7693,37 @@
}
public final class ScanResult implements android.os.Parcelable {
- ctor public ScanResult(android.bluetooth.BluetoothDevice, android.bluetooth.le.ScanRecord, int, long);
+ ctor public deprecated ScanResult(android.bluetooth.BluetoothDevice, android.bluetooth.le.ScanRecord, int, long);
+ ctor public ScanResult(android.bluetooth.BluetoothDevice, int, int, int, int, int, int, int, android.bluetooth.le.ScanRecord, long);
method public int describeContents();
+ method public int getAdvertisingSid();
+ method public int getDataStatus();
method public android.bluetooth.BluetoothDevice getDevice();
+ method public int getPeriodicAdvertisingInterval();
+ method public int getPrimaryPhy();
method public int getRssi();
method public android.bluetooth.le.ScanRecord getScanRecord();
+ method public int getSecondaryPhy();
method public long getTimestampNanos();
+ method public int getTxPower();
+ method public boolean isConnectable();
+ method public boolean isLegacy();
method public void writeToParcel(android.os.Parcel, int);
field public static final android.os.Parcelable.Creator<android.bluetooth.le.ScanResult> CREATOR;
+ field public static final int DATA_COMPLETE = 0; // 0x0
+ field public static final int DATA_TRUNCATED = 2; // 0x2
+ field public static final int PHY_LE_1M = 1; // 0x1
+ field public static final int PHY_LE_2M = 2; // 0x2
+ field public static final int PHY_LE_CODED = 3; // 0x3
+ field public static final int PHY_UNUSED = 0; // 0x0
+ field public static final int SID_NOT_PRESENT = 255; // 0xff
}
public final class ScanSettings implements android.os.Parcelable {
method public int describeContents();
method public int getCallbackType();
+ method public boolean getLegacy();
+ method public int getPhy();
method public long getReportDelayMillis();
method public int getScanMode();
method public int getScanResultType();
@@ -7566,6 +7737,9 @@
field public static final int MATCH_NUM_FEW_ADVERTISEMENT = 2; // 0x2
field public static final int MATCH_NUM_MAX_ADVERTISEMENT = 3; // 0x3
field public static final int MATCH_NUM_ONE_ADVERTISEMENT = 1; // 0x1
+ field public static final int PHY_LE_1M = 1; // 0x1
+ field public static final int PHY_LE_ALL_SUPPORTED = 255; // 0xff
+ field public static final int PHY_LE_CODED = 3; // 0x3
field public static final int SCAN_MODE_BALANCED = 1; // 0x1
field public static final int SCAN_MODE_LOW_LATENCY = 2; // 0x2
field public static final int SCAN_MODE_LOW_POWER = 0; // 0x0
@@ -7576,8 +7750,10 @@
ctor public ScanSettings.Builder();
method public android.bluetooth.le.ScanSettings build();
method public android.bluetooth.le.ScanSettings.Builder setCallbackType(int);
+ method public android.bluetooth.le.ScanSettings.Builder setLegacy(boolean);
method public android.bluetooth.le.ScanSettings.Builder setMatchMode(int);
method public android.bluetooth.le.ScanSettings.Builder setNumOfMatches(int);
+ method public android.bluetooth.le.ScanSettings.Builder setPhy(int);
method public android.bluetooth.le.ScanSettings.Builder setReportDelay(long);
method public android.bluetooth.le.ScanSettings.Builder setScanMode(int);
}
diff --git a/api/system-current.txt b/api/system-current.txt
index becf9a8..c2338d8 100644
--- a/api/system-current.txt
+++ b/api/system-current.txt
@@ -6993,6 +6993,7 @@
method public java.util.Set<android.bluetooth.BluetoothDevice> getBondedDevices();
method public static synchronized android.bluetooth.BluetoothAdapter getDefaultAdapter();
method public java.lang.String getName();
+ method public android.bluetooth.le.PeriodicAdvertisingManager getPeriodicAdvertisingManager();
method public int getProfileConnectionState(int);
method public boolean getProfileProxy(android.content.Context, android.bluetooth.BluetoothProfile.ServiceListener, int);
method public android.bluetooth.BluetoothDevice getRemoteDevice(java.lang.String);
@@ -7002,7 +7003,11 @@
method public boolean isBleScanAlwaysAvailable();
method public boolean isDiscovering();
method public boolean isEnabled();
+ method public boolean isLe2MPhySupported();
+ method public boolean isLeCodedPhySupported();
method public boolean isLeEnabled();
+ method public boolean isLeExtendedAdvertisingSupported();
+ method public boolean isLePeriodicAdvertisingSupported();
method public boolean isMultipleAdvertisementSupported();
method public boolean isOffloadedFilteringSupported();
method public boolean isOffloadedScanBatchingSupported();
@@ -7373,6 +7378,9 @@
public final class BluetoothDevice implements android.os.Parcelable {
method public android.bluetooth.BluetoothGatt connectGatt(android.content.Context, boolean, android.bluetooth.BluetoothGattCallback);
method public android.bluetooth.BluetoothGatt connectGatt(android.content.Context, boolean, android.bluetooth.BluetoothGattCallback, int);
+ method public android.bluetooth.BluetoothGatt connectGatt(android.content.Context, boolean, android.bluetooth.BluetoothGattCallbackExt);
+ method public android.bluetooth.BluetoothGatt connectGatt(android.content.Context, boolean, android.bluetooth.BluetoothGattCallbackExt, int);
+ method public android.bluetooth.BluetoothGatt connectGatt(android.content.Context, boolean, android.bluetooth.BluetoothGattCallbackExt, int, int);
method public boolean createBond();
method public android.bluetooth.BluetoothSocket createInsecureRfcommSocketToServiceRecord(java.util.UUID) throws java.io.IOException;
method public android.bluetooth.BluetoothSocket createRfcommSocketToServiceRecord(java.util.UUID) throws java.io.IOException;
@@ -7418,6 +7426,13 @@
field public static final java.lang.String EXTRA_UUID = "android.bluetooth.device.extra.UUID";
field public static final int PAIRING_VARIANT_PASSKEY_CONFIRMATION = 2; // 0x2
field public static final int PAIRING_VARIANT_PIN = 0; // 0x0
+ field public static final int PHY_LE_1M = 1; // 0x1
+ field public static final int PHY_LE_2M = 2; // 0x2
+ field public static final int PHY_LE_ANY = 7; // 0x7
+ field public static final int PHY_LE_CODED = 4; // 0x4
+ field public static final int PHY_OPTION_NO_PREFERRED = 0; // 0x0
+ field public static final int PHY_OPTION_S2 = 1; // 0x1
+ field public static final int PHY_OPTION_S8 = 2; // 0x2
field public static final int TRANSPORT_AUTO = 0; // 0x0
field public static final int TRANSPORT_BREDR = 1; // 0x1
field public static final int TRANSPORT_LE = 2; // 0x2
@@ -7440,10 +7455,12 @@
method public java.util.List<android.bluetooth.BluetoothGattService> getServices();
method public boolean readCharacteristic(android.bluetooth.BluetoothGattCharacteristic);
method public boolean readDescriptor(android.bluetooth.BluetoothGattDescriptor);
+ method public void readPhy();
method public boolean readRemoteRssi();
method public boolean requestConnectionPriority(int);
method public boolean requestMtu(int);
method public boolean setCharacteristicNotification(android.bluetooth.BluetoothGattCharacteristic, boolean);
+ method public void setPreferredPhy(int, int, int);
method public boolean writeCharacteristic(android.bluetooth.BluetoothGattCharacteristic);
method public boolean writeDescriptor(android.bluetooth.BluetoothGattDescriptor);
field public static final int CONNECTION_PRIORITY_BALANCED = 0; // 0x0
@@ -7461,8 +7478,12 @@
field public static final int GATT_WRITE_NOT_PERMITTED = 3; // 0x3
}
- public abstract class BluetoothGattCallback {
+ public abstract deprecated class BluetoothGattCallback extends android.bluetooth.BluetoothGattCallbackExt {
ctor public BluetoothGattCallback();
+ }
+
+ public abstract class BluetoothGattCallbackExt {
+ ctor public BluetoothGattCallbackExt();
method public void onCharacteristicChanged(android.bluetooth.BluetoothGatt, android.bluetooth.BluetoothGattCharacteristic);
method public void onCharacteristicRead(android.bluetooth.BluetoothGatt, android.bluetooth.BluetoothGattCharacteristic, int);
method public void onCharacteristicWrite(android.bluetooth.BluetoothGatt, android.bluetooth.BluetoothGattCharacteristic, int);
@@ -7470,6 +7491,8 @@
method public void onDescriptorRead(android.bluetooth.BluetoothGatt, android.bluetooth.BluetoothGattDescriptor, int);
method public void onDescriptorWrite(android.bluetooth.BluetoothGatt, android.bluetooth.BluetoothGattDescriptor, int);
method public void onMtuChanged(android.bluetooth.BluetoothGatt, int, int);
+ method public void onPhyRead(android.bluetooth.BluetoothGatt, int, int, int);
+ method public void onPhyUpdate(android.bluetooth.BluetoothGatt, int, int, int);
method public void onReadRemoteRssi(android.bluetooth.BluetoothGatt, int, int);
method public void onReliableWriteCompleted(android.bluetooth.BluetoothGatt, int);
method public void onServicesDiscovered(android.bluetooth.BluetoothGatt, int);
@@ -7563,12 +7586,18 @@
method public android.bluetooth.BluetoothGattService getService(java.util.UUID);
method public java.util.List<android.bluetooth.BluetoothGattService> getServices();
method public boolean notifyCharacteristicChanged(android.bluetooth.BluetoothDevice, android.bluetooth.BluetoothGattCharacteristic, boolean);
+ method public void readPhy(android.bluetooth.BluetoothDevice);
method public boolean removeService(android.bluetooth.BluetoothGattService);
method public boolean sendResponse(android.bluetooth.BluetoothDevice, int, int, int, byte[]);
+ method public void setPreferredPhy(android.bluetooth.BluetoothDevice, int, int, int);
}
- public abstract class BluetoothGattServerCallback {
+ public abstract deprecated class BluetoothGattServerCallback extends android.bluetooth.BluetoothGattServerCallbackExt {
ctor public BluetoothGattServerCallback();
+ }
+
+ public abstract class BluetoothGattServerCallbackExt {
+ ctor public BluetoothGattServerCallbackExt();
method public void onCharacteristicReadRequest(android.bluetooth.BluetoothDevice, int, int, android.bluetooth.BluetoothGattCharacteristic);
method public void onCharacteristicWriteRequest(android.bluetooth.BluetoothDevice, int, android.bluetooth.BluetoothGattCharacteristic, boolean, boolean, int, byte[]);
method public void onConnectionStateChange(android.bluetooth.BluetoothDevice, int, int);
@@ -7577,6 +7606,8 @@
method public void onExecuteWrite(android.bluetooth.BluetoothDevice, int, boolean);
method public void onMtuChanged(android.bluetooth.BluetoothDevice, int);
method public void onNotificationSent(android.bluetooth.BluetoothDevice, int);
+ method public void onPhyRead(android.bluetooth.BluetoothDevice, int, int, int);
+ method public void onPhyUpdate(android.bluetooth.BluetoothDevice, int, int, int);
method public void onServiceAdded(int, android.bluetooth.BluetoothGattService);
}
@@ -7777,10 +7808,85 @@
method public android.bluetooth.le.AdvertiseSettings.Builder setTxPowerLevel(int);
}
+ public final class AdvertisingSet {
+ method public void enableAdvertising(boolean);
+ method public void periodicAdvertisingEnable(boolean);
+ method public void setAdvertisingData(android.bluetooth.le.AdvertiseData);
+ method public void setAdvertisingParameters(android.bluetooth.le.AdvertisingSetParameters);
+ method public void setPeriodicAdvertisingData(android.bluetooth.le.AdvertiseData);
+ method public void setPeriodicAdvertisingParameters(android.bluetooth.le.PeriodicAdvertisingParameters);
+ method public void setScanResponseData(android.bluetooth.le.AdvertiseData);
+ }
+
+ public abstract class AdvertisingSetCallback {
+ ctor public AdvertisingSetCallback();
+ method public void onAdvertisingDataSet(android.bluetooth.le.AdvertisingSet, int);
+ method public void onAdvertisingEnabled(android.bluetooth.le.AdvertisingSet, boolean, int);
+ method public void onAdvertisingParametersUpdated(android.bluetooth.le.AdvertisingSet, int);
+ method public void onAdvertisingSetStarted(android.bluetooth.le.AdvertisingSet, int);
+ method public void onAdvertisingSetStopped(android.bluetooth.le.AdvertisingSet);
+ method public void onPeriodicAdvertisingDataSet(android.bluetooth.le.AdvertisingSet, int);
+ method public void onPeriodicAdvertisingEnable(android.bluetooth.le.AdvertisingSet, boolean, int);
+ method public void onPeriodicAdvertisingParametersUpdated(android.bluetooth.le.AdvertisingSet, int);
+ method public void onScanResponseDataSet(android.bluetooth.le.AdvertisingSet, int);
+ field public static final int ADVERTISE_FAILED_ALREADY_STARTED = 3; // 0x3
+ field public static final int ADVERTISE_FAILED_DATA_TOO_LARGE = 1; // 0x1
+ field public static final int ADVERTISE_FAILED_FEATURE_UNSUPPORTED = 5; // 0x5
+ field public static final int ADVERTISE_FAILED_INTERNAL_ERROR = 4; // 0x4
+ field public static final int ADVERTISE_FAILED_TOO_MANY_ADVERTISERS = 2; // 0x2
+ field public static final int ADVERTISE_SUCCESS = 0; // 0x0
+ }
+
+ public final class AdvertisingSetParameters implements android.os.Parcelable {
+ method public int describeContents();
+ method public int getInterval();
+ method public int getPrimaryPhy();
+ method public int getSecondaryPhy();
+ method public int getTimeout();
+ method public int getTxPowerLevel();
+ method public boolean includeTxPower();
+ method public boolean isAnonymous();
+ method public boolean isConnectable();
+ method public boolean isLegacy();
+ method public void writeToParcel(android.os.Parcel, int);
+ field public static final android.os.Parcelable.Creator<android.bluetooth.le.AdvertisingSetParameters> CREATOR;
+ field public static final int INTERVAL_HIGH = 160; // 0xa0
+ field public static final int INTERVAL_LOW = 1600; // 0x640
+ field public static final int INTERVAL_MAX = 16777215; // 0xffffff
+ field public static final int INTERVAL_MEDIUM = 400; // 0x190
+ field public static final int INTERVAL_MIN = 160; // 0xa0
+ field public static final int PHY_LE_1M = 1; // 0x1
+ field public static final int PHY_LE_2M = 2; // 0x2
+ field public static final int PHY_LE_CODED = 3; // 0x3
+ field public static final int TX_POWER_HIGH = 1; // 0x1
+ field public static final int TX_POWER_LOW = -15; // 0xfffffff1
+ field public static final int TX_POWER_MAX = 1; // 0x1
+ field public static final int TX_POWER_MEDIUM = -7; // 0xfffffff9
+ field public static final int TX_POWER_MIN = -127; // 0xffffff81
+ field public static final int TX_POWER_ULTRA_LOW = -21; // 0xffffffeb
+ }
+
+ public static final class AdvertisingSetParameters.Builder {
+ ctor public AdvertisingSetParameters.Builder();
+ method public android.bluetooth.le.AdvertisingSetParameters build();
+ method public android.bluetooth.le.AdvertisingSetParameters.Builder setAnonymouus(boolean);
+ method public android.bluetooth.le.AdvertisingSetParameters.Builder setConnectable(boolean);
+ method public android.bluetooth.le.AdvertisingSetParameters.Builder setIncludeTxPower(boolean);
+ method public android.bluetooth.le.AdvertisingSetParameters.Builder setInterval(int);
+ method public android.bluetooth.le.AdvertisingSetParameters.Builder setLegacyMode(boolean);
+ method public android.bluetooth.le.AdvertisingSetParameters.Builder setPrimaryPhy(int);
+ method public android.bluetooth.le.AdvertisingSetParameters.Builder setSecondaryPhy(int);
+ method public android.bluetooth.le.AdvertisingSetParameters.Builder setTimeout(int);
+ method public android.bluetooth.le.AdvertisingSetParameters.Builder setTxPowerLevel(int);
+ }
+
public final class BluetoothLeAdvertiser {
method public void startAdvertising(android.bluetooth.le.AdvertiseSettings, android.bluetooth.le.AdvertiseData, android.bluetooth.le.AdvertiseCallback);
method public void startAdvertising(android.bluetooth.le.AdvertiseSettings, android.bluetooth.le.AdvertiseData, android.bluetooth.le.AdvertiseData, android.bluetooth.le.AdvertiseCallback);
+ method public void startAdvertisingSet(android.bluetooth.le.AdvertisingSetParameters, android.bluetooth.le.AdvertiseData, android.bluetooth.le.AdvertiseData, android.bluetooth.le.PeriodicAdvertisingParameters, android.bluetooth.le.AdvertiseData, android.bluetooth.le.AdvertisingSetCallback);
+ method public void startAdvertisingSet(android.bluetooth.le.AdvertisingSetParameters, android.bluetooth.le.AdvertiseData, android.bluetooth.le.AdvertiseData, android.bluetooth.le.PeriodicAdvertisingParameters, android.bluetooth.le.AdvertiseData, android.bluetooth.le.AdvertisingSetCallback, android.os.Handler);
method public void stopAdvertising(android.bluetooth.le.AdvertiseCallback);
+ method public void stopAdvertisingSet(android.bluetooth.le.AdvertisingSetCallback);
}
public final class BluetoothLeScanner {
@@ -7793,6 +7899,53 @@
method public void stopScan(android.bluetooth.le.ScanCallback);
}
+ public abstract class PeriodicAdvertisingCallback {
+ ctor public PeriodicAdvertisingCallback();
+ method public void onPeriodicAdvertisingReport(android.bluetooth.le.PeriodicAdvertisingReport);
+ method public void onSyncEstablished(int, android.bluetooth.BluetoothDevice, int, int, int, int);
+ method public void onSyncLost(int);
+ field public static final int SYNC_NO_RESOURCES = 2; // 0x2
+ field public static final int SYNC_NO_RESPONSE = 1; // 0x1
+ }
+
+ public final class PeriodicAdvertisingManager {
+ method public void registerSync(android.bluetooth.le.ScanResult, int, int, android.bluetooth.le.PeriodicAdvertisingCallback);
+ method public void registerSync(android.bluetooth.le.ScanResult, int, int, android.bluetooth.le.PeriodicAdvertisingCallback, android.os.Handler);
+ method public void unregisterSync(android.bluetooth.le.PeriodicAdvertisingCallback);
+ }
+
+ public final class PeriodicAdvertisingParameters implements android.os.Parcelable {
+ method public int describeContents();
+ method public boolean getEnable();
+ method public boolean getIncludeTxPower();
+ method public int getInterval();
+ method public void writeToParcel(android.os.Parcel, int);
+ field public static final android.os.Parcelable.Creator<android.bluetooth.le.PeriodicAdvertisingParameters> CREATOR;
+ }
+
+ public static final class PeriodicAdvertisingParameters.Builder {
+ ctor public PeriodicAdvertisingParameters.Builder();
+ method public android.bluetooth.le.PeriodicAdvertisingParameters build();
+ method public android.bluetooth.le.PeriodicAdvertisingParameters.Builder setEnable(boolean);
+ method public android.bluetooth.le.PeriodicAdvertisingParameters.Builder setIncludeTxPower(boolean);
+ method public android.bluetooth.le.PeriodicAdvertisingParameters.Builder setInterval(int);
+ }
+
+ public final class PeriodicAdvertisingReport implements android.os.Parcelable {
+ ctor public PeriodicAdvertisingReport(int, int, int, int, android.bluetooth.le.ScanRecord);
+ method public int describeContents();
+ method public android.bluetooth.le.ScanRecord getData();
+ method public int getDataStatus();
+ method public int getRssi();
+ method public int getSyncHandle();
+ method public long getTimestampNanos();
+ method public int getTxPower();
+ method public void writeToParcel(android.os.Parcel, int);
+ field public static final android.os.Parcelable.Creator<android.bluetooth.le.PeriodicAdvertisingReport> CREATOR;
+ field public static final int DATA_COMPLETE = 0; // 0x0
+ field public static final int DATA_INCOMPLETE_TRUNCATED = 2; // 0x2
+ }
+
public final class ResultStorageDescriptor implements android.os.Parcelable {
ctor public ResultStorageDescriptor(int, int, int);
method public int describeContents();
@@ -7857,19 +8010,37 @@
}
public final class ScanResult implements android.os.Parcelable {
- ctor public ScanResult(android.bluetooth.BluetoothDevice, android.bluetooth.le.ScanRecord, int, long);
+ ctor public deprecated ScanResult(android.bluetooth.BluetoothDevice, android.bluetooth.le.ScanRecord, int, long);
+ ctor public ScanResult(android.bluetooth.BluetoothDevice, int, int, int, int, int, int, int, android.bluetooth.le.ScanRecord, long);
method public int describeContents();
+ method public int getAdvertisingSid();
+ method public int getDataStatus();
method public android.bluetooth.BluetoothDevice getDevice();
+ method public int getPeriodicAdvertisingInterval();
+ method public int getPrimaryPhy();
method public int getRssi();
method public android.bluetooth.le.ScanRecord getScanRecord();
+ method public int getSecondaryPhy();
method public long getTimestampNanos();
+ method public int getTxPower();
+ method public boolean isConnectable();
+ method public boolean isLegacy();
method public void writeToParcel(android.os.Parcel, int);
field public static final android.os.Parcelable.Creator<android.bluetooth.le.ScanResult> CREATOR;
+ field public static final int DATA_COMPLETE = 0; // 0x0
+ field public static final int DATA_TRUNCATED = 2; // 0x2
+ field public static final int PHY_LE_1M = 1; // 0x1
+ field public static final int PHY_LE_2M = 2; // 0x2
+ field public static final int PHY_LE_CODED = 3; // 0x3
+ field public static final int PHY_UNUSED = 0; // 0x0
+ field public static final int SID_NOT_PRESENT = 255; // 0xff
}
public final class ScanSettings implements android.os.Parcelable {
method public int describeContents();
method public int getCallbackType();
+ method public boolean getLegacy();
+ method public int getPhy();
method public long getReportDelayMillis();
method public int getScanMode();
method public int getScanResultType();
@@ -7883,6 +8054,9 @@
field public static final int MATCH_NUM_FEW_ADVERTISEMENT = 2; // 0x2
field public static final int MATCH_NUM_MAX_ADVERTISEMENT = 3; // 0x3
field public static final int MATCH_NUM_ONE_ADVERTISEMENT = 1; // 0x1
+ field public static final int PHY_LE_1M = 1; // 0x1
+ field public static final int PHY_LE_ALL_SUPPORTED = 255; // 0xff
+ field public static final int PHY_LE_CODED = 3; // 0x3
field public static final int SCAN_MODE_BALANCED = 1; // 0x1
field public static final int SCAN_MODE_LOW_LATENCY = 2; // 0x2
field public static final int SCAN_MODE_LOW_POWER = 0; // 0x0
@@ -7895,8 +8069,10 @@
ctor public ScanSettings.Builder();
method public android.bluetooth.le.ScanSettings build();
method public android.bluetooth.le.ScanSettings.Builder setCallbackType(int);
+ method public android.bluetooth.le.ScanSettings.Builder setLegacy(boolean);
method public android.bluetooth.le.ScanSettings.Builder setMatchMode(int);
method public android.bluetooth.le.ScanSettings.Builder setNumOfMatches(int);
+ method public android.bluetooth.le.ScanSettings.Builder setPhy(int);
method public android.bluetooth.le.ScanSettings.Builder setReportDelay(long);
method public android.bluetooth.le.ScanSettings.Builder setScanMode(int);
method public android.bluetooth.le.ScanSettings.Builder setScanResultType(int);
diff --git a/api/test-current.txt b/api/test-current.txt
index bd378a2..bc0b5b0 100644
--- a/api/test-current.txt
+++ b/api/test-current.txt
@@ -6704,6 +6704,7 @@
method public java.util.Set<android.bluetooth.BluetoothDevice> getBondedDevices();
method public static synchronized android.bluetooth.BluetoothAdapter getDefaultAdapter();
method public java.lang.String getName();
+ method public android.bluetooth.le.PeriodicAdvertisingManager getPeriodicAdvertisingManager();
method public int getProfileConnectionState(int);
method public boolean getProfileProxy(android.content.Context, android.bluetooth.BluetoothProfile.ServiceListener, int);
method public android.bluetooth.BluetoothDevice getRemoteDevice(java.lang.String);
@@ -6712,6 +6713,10 @@
method public int getState();
method public boolean isDiscovering();
method public boolean isEnabled();
+ method public boolean isLe2MPhySupported();
+ method public boolean isLeCodedPhySupported();
+ method public boolean isLeExtendedAdvertisingSupported();
+ method public boolean isLePeriodicAdvertisingSupported();
method public boolean isMultipleAdvertisementSupported();
method public boolean isOffloadedFilteringSupported();
method public boolean isOffloadedScanBatchingSupported();
@@ -7080,6 +7085,9 @@
public final class BluetoothDevice implements android.os.Parcelable {
method public android.bluetooth.BluetoothGatt connectGatt(android.content.Context, boolean, android.bluetooth.BluetoothGattCallback);
method public android.bluetooth.BluetoothGatt connectGatt(android.content.Context, boolean, android.bluetooth.BluetoothGattCallback, int);
+ method public android.bluetooth.BluetoothGatt connectGatt(android.content.Context, boolean, android.bluetooth.BluetoothGattCallbackExt);
+ method public android.bluetooth.BluetoothGatt connectGatt(android.content.Context, boolean, android.bluetooth.BluetoothGattCallbackExt, int);
+ method public android.bluetooth.BluetoothGatt connectGatt(android.content.Context, boolean, android.bluetooth.BluetoothGattCallbackExt, int, int);
method public boolean createBond();
method public android.bluetooth.BluetoothSocket createInsecureRfcommSocketToServiceRecord(java.util.UUID) throws java.io.IOException;
method public android.bluetooth.BluetoothSocket createRfcommSocketToServiceRecord(java.util.UUID) throws java.io.IOException;
@@ -7123,6 +7131,13 @@
field public static final java.lang.String EXTRA_UUID = "android.bluetooth.device.extra.UUID";
field public static final int PAIRING_VARIANT_PASSKEY_CONFIRMATION = 2; // 0x2
field public static final int PAIRING_VARIANT_PIN = 0; // 0x0
+ field public static final int PHY_LE_1M = 1; // 0x1
+ field public static final int PHY_LE_2M = 2; // 0x2
+ field public static final int PHY_LE_ANY = 7; // 0x7
+ field public static final int PHY_LE_CODED = 4; // 0x4
+ field public static final int PHY_OPTION_NO_PREFERRED = 0; // 0x0
+ field public static final int PHY_OPTION_S2 = 1; // 0x1
+ field public static final int PHY_OPTION_S8 = 2; // 0x2
field public static final int TRANSPORT_AUTO = 0; // 0x0
field public static final int TRANSPORT_BREDR = 1; // 0x1
field public static final int TRANSPORT_LE = 2; // 0x2
@@ -7145,10 +7160,12 @@
method public java.util.List<android.bluetooth.BluetoothGattService> getServices();
method public boolean readCharacteristic(android.bluetooth.BluetoothGattCharacteristic);
method public boolean readDescriptor(android.bluetooth.BluetoothGattDescriptor);
+ method public void readPhy();
method public boolean readRemoteRssi();
method public boolean requestConnectionPriority(int);
method public boolean requestMtu(int);
method public boolean setCharacteristicNotification(android.bluetooth.BluetoothGattCharacteristic, boolean);
+ method public void setPreferredPhy(int, int, int);
method public boolean writeCharacteristic(android.bluetooth.BluetoothGattCharacteristic);
method public boolean writeDescriptor(android.bluetooth.BluetoothGattDescriptor);
field public static final int CONNECTION_PRIORITY_BALANCED = 0; // 0x0
@@ -7166,8 +7183,12 @@
field public static final int GATT_WRITE_NOT_PERMITTED = 3; // 0x3
}
- public abstract class BluetoothGattCallback {
+ public abstract deprecated class BluetoothGattCallback extends android.bluetooth.BluetoothGattCallbackExt {
ctor public BluetoothGattCallback();
+ }
+
+ public abstract class BluetoothGattCallbackExt {
+ ctor public BluetoothGattCallbackExt();
method public void onCharacteristicChanged(android.bluetooth.BluetoothGatt, android.bluetooth.BluetoothGattCharacteristic);
method public void onCharacteristicRead(android.bluetooth.BluetoothGatt, android.bluetooth.BluetoothGattCharacteristic, int);
method public void onCharacteristicWrite(android.bluetooth.BluetoothGatt, android.bluetooth.BluetoothGattCharacteristic, int);
@@ -7175,6 +7196,8 @@
method public void onDescriptorRead(android.bluetooth.BluetoothGatt, android.bluetooth.BluetoothGattDescriptor, int);
method public void onDescriptorWrite(android.bluetooth.BluetoothGatt, android.bluetooth.BluetoothGattDescriptor, int);
method public void onMtuChanged(android.bluetooth.BluetoothGatt, int, int);
+ method public void onPhyRead(android.bluetooth.BluetoothGatt, int, int, int);
+ method public void onPhyUpdate(android.bluetooth.BluetoothGatt, int, int, int);
method public void onReadRemoteRssi(android.bluetooth.BluetoothGatt, int, int);
method public void onReliableWriteCompleted(android.bluetooth.BluetoothGatt, int);
method public void onServicesDiscovered(android.bluetooth.BluetoothGatt, int);
@@ -7268,12 +7291,18 @@
method public android.bluetooth.BluetoothGattService getService(java.util.UUID);
method public java.util.List<android.bluetooth.BluetoothGattService> getServices();
method public boolean notifyCharacteristicChanged(android.bluetooth.BluetoothDevice, android.bluetooth.BluetoothGattCharacteristic, boolean);
+ method public void readPhy(android.bluetooth.BluetoothDevice);
method public boolean removeService(android.bluetooth.BluetoothGattService);
method public boolean sendResponse(android.bluetooth.BluetoothDevice, int, int, int, byte[]);
+ method public void setPreferredPhy(android.bluetooth.BluetoothDevice, int, int, int);
}
- public abstract class BluetoothGattServerCallback {
+ public abstract deprecated class BluetoothGattServerCallback extends android.bluetooth.BluetoothGattServerCallbackExt {
ctor public BluetoothGattServerCallback();
+ }
+
+ public abstract class BluetoothGattServerCallbackExt {
+ ctor public BluetoothGattServerCallbackExt();
method public void onCharacteristicReadRequest(android.bluetooth.BluetoothDevice, int, int, android.bluetooth.BluetoothGattCharacteristic);
method public void onCharacteristicWriteRequest(android.bluetooth.BluetoothDevice, int, android.bluetooth.BluetoothGattCharacteristic, boolean, boolean, int, byte[]);
method public void onConnectionStateChange(android.bluetooth.BluetoothDevice, int, int);
@@ -7282,6 +7311,8 @@
method public void onExecuteWrite(android.bluetooth.BluetoothDevice, int, boolean);
method public void onMtuChanged(android.bluetooth.BluetoothDevice, int);
method public void onNotificationSent(android.bluetooth.BluetoothDevice, int);
+ method public void onPhyRead(android.bluetooth.BluetoothDevice, int, int, int);
+ method public void onPhyUpdate(android.bluetooth.BluetoothDevice, int, int, int);
method public void onServiceAdded(int, android.bluetooth.BluetoothGattService);
}
@@ -7482,10 +7513,85 @@
method public android.bluetooth.le.AdvertiseSettings.Builder setTxPowerLevel(int);
}
+ public final class AdvertisingSet {
+ method public void enableAdvertising(boolean);
+ method public void periodicAdvertisingEnable(boolean);
+ method public void setAdvertisingData(android.bluetooth.le.AdvertiseData);
+ method public void setAdvertisingParameters(android.bluetooth.le.AdvertisingSetParameters);
+ method public void setPeriodicAdvertisingData(android.bluetooth.le.AdvertiseData);
+ method public void setPeriodicAdvertisingParameters(android.bluetooth.le.PeriodicAdvertisingParameters);
+ method public void setScanResponseData(android.bluetooth.le.AdvertiseData);
+ }
+
+ public abstract class AdvertisingSetCallback {
+ ctor public AdvertisingSetCallback();
+ method public void onAdvertisingDataSet(android.bluetooth.le.AdvertisingSet, int);
+ method public void onAdvertisingEnabled(android.bluetooth.le.AdvertisingSet, boolean, int);
+ method public void onAdvertisingParametersUpdated(android.bluetooth.le.AdvertisingSet, int);
+ method public void onAdvertisingSetStarted(android.bluetooth.le.AdvertisingSet, int);
+ method public void onAdvertisingSetStopped(android.bluetooth.le.AdvertisingSet);
+ method public void onPeriodicAdvertisingDataSet(android.bluetooth.le.AdvertisingSet, int);
+ method public void onPeriodicAdvertisingEnable(android.bluetooth.le.AdvertisingSet, boolean, int);
+ method public void onPeriodicAdvertisingParametersUpdated(android.bluetooth.le.AdvertisingSet, int);
+ method public void onScanResponseDataSet(android.bluetooth.le.AdvertisingSet, int);
+ field public static final int ADVERTISE_FAILED_ALREADY_STARTED = 3; // 0x3
+ field public static final int ADVERTISE_FAILED_DATA_TOO_LARGE = 1; // 0x1
+ field public static final int ADVERTISE_FAILED_FEATURE_UNSUPPORTED = 5; // 0x5
+ field public static final int ADVERTISE_FAILED_INTERNAL_ERROR = 4; // 0x4
+ field public static final int ADVERTISE_FAILED_TOO_MANY_ADVERTISERS = 2; // 0x2
+ field public static final int ADVERTISE_SUCCESS = 0; // 0x0
+ }
+
+ public final class AdvertisingSetParameters implements android.os.Parcelable {
+ method public int describeContents();
+ method public int getInterval();
+ method public int getPrimaryPhy();
+ method public int getSecondaryPhy();
+ method public int getTimeout();
+ method public int getTxPowerLevel();
+ method public boolean includeTxPower();
+ method public boolean isAnonymous();
+ method public boolean isConnectable();
+ method public boolean isLegacy();
+ method public void writeToParcel(android.os.Parcel, int);
+ field public static final android.os.Parcelable.Creator<android.bluetooth.le.AdvertisingSetParameters> CREATOR;
+ field public static final int INTERVAL_HIGH = 160; // 0xa0
+ field public static final int INTERVAL_LOW = 1600; // 0x640
+ field public static final int INTERVAL_MAX = 16777215; // 0xffffff
+ field public static final int INTERVAL_MEDIUM = 400; // 0x190
+ field public static final int INTERVAL_MIN = 160; // 0xa0
+ field public static final int PHY_LE_1M = 1; // 0x1
+ field public static final int PHY_LE_2M = 2; // 0x2
+ field public static final int PHY_LE_CODED = 3; // 0x3
+ field public static final int TX_POWER_HIGH = 1; // 0x1
+ field public static final int TX_POWER_LOW = -15; // 0xfffffff1
+ field public static final int TX_POWER_MAX = 1; // 0x1
+ field public static final int TX_POWER_MEDIUM = -7; // 0xfffffff9
+ field public static final int TX_POWER_MIN = -127; // 0xffffff81
+ field public static final int TX_POWER_ULTRA_LOW = -21; // 0xffffffeb
+ }
+
+ public static final class AdvertisingSetParameters.Builder {
+ ctor public AdvertisingSetParameters.Builder();
+ method public android.bluetooth.le.AdvertisingSetParameters build();
+ method public android.bluetooth.le.AdvertisingSetParameters.Builder setAnonymouus(boolean);
+ method public android.bluetooth.le.AdvertisingSetParameters.Builder setConnectable(boolean);
+ method public android.bluetooth.le.AdvertisingSetParameters.Builder setIncludeTxPower(boolean);
+ method public android.bluetooth.le.AdvertisingSetParameters.Builder setInterval(int);
+ method public android.bluetooth.le.AdvertisingSetParameters.Builder setLegacyMode(boolean);
+ method public android.bluetooth.le.AdvertisingSetParameters.Builder setPrimaryPhy(int);
+ method public android.bluetooth.le.AdvertisingSetParameters.Builder setSecondaryPhy(int);
+ method public android.bluetooth.le.AdvertisingSetParameters.Builder setTimeout(int);
+ method public android.bluetooth.le.AdvertisingSetParameters.Builder setTxPowerLevel(int);
+ }
+
public final class BluetoothLeAdvertiser {
method public void startAdvertising(android.bluetooth.le.AdvertiseSettings, android.bluetooth.le.AdvertiseData, android.bluetooth.le.AdvertiseCallback);
method public void startAdvertising(android.bluetooth.le.AdvertiseSettings, android.bluetooth.le.AdvertiseData, android.bluetooth.le.AdvertiseData, android.bluetooth.le.AdvertiseCallback);
+ method public void startAdvertisingSet(android.bluetooth.le.AdvertisingSetParameters, android.bluetooth.le.AdvertiseData, android.bluetooth.le.AdvertiseData, android.bluetooth.le.PeriodicAdvertisingParameters, android.bluetooth.le.AdvertiseData, android.bluetooth.le.AdvertisingSetCallback);
+ method public void startAdvertisingSet(android.bluetooth.le.AdvertisingSetParameters, android.bluetooth.le.AdvertiseData, android.bluetooth.le.AdvertiseData, android.bluetooth.le.PeriodicAdvertisingParameters, android.bluetooth.le.AdvertiseData, android.bluetooth.le.AdvertisingSetCallback, android.os.Handler);
method public void stopAdvertising(android.bluetooth.le.AdvertiseCallback);
+ method public void stopAdvertisingSet(android.bluetooth.le.AdvertisingSetCallback);
}
public final class BluetoothLeScanner {
@@ -7495,6 +7601,53 @@
method public void stopScan(android.bluetooth.le.ScanCallback);
}
+ public abstract class PeriodicAdvertisingCallback {
+ ctor public PeriodicAdvertisingCallback();
+ method public void onPeriodicAdvertisingReport(android.bluetooth.le.PeriodicAdvertisingReport);
+ method public void onSyncEstablished(int, android.bluetooth.BluetoothDevice, int, int, int, int);
+ method public void onSyncLost(int);
+ field public static final int SYNC_NO_RESOURCES = 2; // 0x2
+ field public static final int SYNC_NO_RESPONSE = 1; // 0x1
+ }
+
+ public final class PeriodicAdvertisingManager {
+ method public void registerSync(android.bluetooth.le.ScanResult, int, int, android.bluetooth.le.PeriodicAdvertisingCallback);
+ method public void registerSync(android.bluetooth.le.ScanResult, int, int, android.bluetooth.le.PeriodicAdvertisingCallback, android.os.Handler);
+ method public void unregisterSync(android.bluetooth.le.PeriodicAdvertisingCallback);
+ }
+
+ public final class PeriodicAdvertisingParameters implements android.os.Parcelable {
+ method public int describeContents();
+ method public boolean getEnable();
+ method public boolean getIncludeTxPower();
+ method public int getInterval();
+ method public void writeToParcel(android.os.Parcel, int);
+ field public static final android.os.Parcelable.Creator<android.bluetooth.le.PeriodicAdvertisingParameters> CREATOR;
+ }
+
+ public static final class PeriodicAdvertisingParameters.Builder {
+ ctor public PeriodicAdvertisingParameters.Builder();
+ method public android.bluetooth.le.PeriodicAdvertisingParameters build();
+ method public android.bluetooth.le.PeriodicAdvertisingParameters.Builder setEnable(boolean);
+ method public android.bluetooth.le.PeriodicAdvertisingParameters.Builder setIncludeTxPower(boolean);
+ method public android.bluetooth.le.PeriodicAdvertisingParameters.Builder setInterval(int);
+ }
+
+ public final class PeriodicAdvertisingReport implements android.os.Parcelable {
+ ctor public PeriodicAdvertisingReport(int, int, int, int, android.bluetooth.le.ScanRecord);
+ method public int describeContents();
+ method public android.bluetooth.le.ScanRecord getData();
+ method public int getDataStatus();
+ method public int getRssi();
+ method public int getSyncHandle();
+ method public long getTimestampNanos();
+ method public int getTxPower();
+ method public void writeToParcel(android.os.Parcel, int);
+ field public static final android.os.Parcelable.Creator<android.bluetooth.le.PeriodicAdvertisingReport> CREATOR;
+ field public static final int DATA_COMPLETE = 0; // 0x0
+ field public static final int DATA_INCOMPLETE_TRUNCATED = 2; // 0x2
+ }
+
public abstract class ScanCallback {
ctor public ScanCallback();
method public void onBatchScanResults(java.util.List<android.bluetooth.le.ScanResult>);
@@ -7549,19 +7702,37 @@
}
public final class ScanResult implements android.os.Parcelable {
- ctor public ScanResult(android.bluetooth.BluetoothDevice, android.bluetooth.le.ScanRecord, int, long);
+ ctor public deprecated ScanResult(android.bluetooth.BluetoothDevice, android.bluetooth.le.ScanRecord, int, long);
+ ctor public ScanResult(android.bluetooth.BluetoothDevice, int, int, int, int, int, int, int, android.bluetooth.le.ScanRecord, long);
method public int describeContents();
+ method public int getAdvertisingSid();
+ method public int getDataStatus();
method public android.bluetooth.BluetoothDevice getDevice();
+ method public int getPeriodicAdvertisingInterval();
+ method public int getPrimaryPhy();
method public int getRssi();
method public android.bluetooth.le.ScanRecord getScanRecord();
+ method public int getSecondaryPhy();
method public long getTimestampNanos();
+ method public int getTxPower();
+ method public boolean isConnectable();
+ method public boolean isLegacy();
method public void writeToParcel(android.os.Parcel, int);
field public static final android.os.Parcelable.Creator<android.bluetooth.le.ScanResult> CREATOR;
+ field public static final int DATA_COMPLETE = 0; // 0x0
+ field public static final int DATA_TRUNCATED = 2; // 0x2
+ field public static final int PHY_LE_1M = 1; // 0x1
+ field public static final int PHY_LE_2M = 2; // 0x2
+ field public static final int PHY_LE_CODED = 3; // 0x3
+ field public static final int PHY_UNUSED = 0; // 0x0
+ field public static final int SID_NOT_PRESENT = 255; // 0xff
}
public final class ScanSettings implements android.os.Parcelable {
method public int describeContents();
method public int getCallbackType();
+ method public boolean getLegacy();
+ method public int getPhy();
method public long getReportDelayMillis();
method public int getScanMode();
method public int getScanResultType();
@@ -7575,6 +7746,9 @@
field public static final int MATCH_NUM_FEW_ADVERTISEMENT = 2; // 0x2
field public static final int MATCH_NUM_MAX_ADVERTISEMENT = 3; // 0x3
field public static final int MATCH_NUM_ONE_ADVERTISEMENT = 1; // 0x1
+ field public static final int PHY_LE_1M = 1; // 0x1
+ field public static final int PHY_LE_ALL_SUPPORTED = 255; // 0xff
+ field public static final int PHY_LE_CODED = 3; // 0x3
field public static final int SCAN_MODE_BALANCED = 1; // 0x1
field public static final int SCAN_MODE_LOW_LATENCY = 2; // 0x2
field public static final int SCAN_MODE_LOW_POWER = 0; // 0x0
@@ -7585,8 +7759,10 @@
ctor public ScanSettings.Builder();
method public android.bluetooth.le.ScanSettings build();
method public android.bluetooth.le.ScanSettings.Builder setCallbackType(int);
+ method public android.bluetooth.le.ScanSettings.Builder setLegacy(boolean);
method public android.bluetooth.le.ScanSettings.Builder setMatchMode(int);
method public android.bluetooth.le.ScanSettings.Builder setNumOfMatches(int);
+ method public android.bluetooth.le.ScanSettings.Builder setPhy(int);
method public android.bluetooth.le.ScanSettings.Builder setReportDelay(long);
method public android.bluetooth.le.ScanSettings.Builder setScanMode(int);
}
diff --git a/core/java/android/bluetooth/BluetoothAdapter.java b/core/java/android/bluetooth/BluetoothAdapter.java
index dbc25af..8186937 100644
--- a/core/java/android/bluetooth/BluetoothAdapter.java
+++ b/core/java/android/bluetooth/BluetoothAdapter.java
@@ -26,6 +26,7 @@
import android.app.ActivityThread;
import android.bluetooth.le.BluetoothLeAdvertiser;
import android.bluetooth.le.BluetoothLeScanner;
+import android.bluetooth.le.PeriodicAdvertisingManager;
import android.bluetooth.le.ScanCallback;
import android.bluetooth.le.ScanFilter;
import android.bluetooth.le.ScanRecord;
@@ -525,6 +526,7 @@
private static BluetoothLeScanner sBluetoothLeScanner;
private static BluetoothLeAdvertiser sBluetoothLeAdvertiser;
+ private static PeriodicAdvertisingManager sPeriodicAdvertisingManager;
private final IBluetoothManager mManagerService;
private IBluetooth mService;
@@ -630,6 +632,30 @@
}
/**
+ * Returns a {@link PeriodicAdvertisingManager} object for Bluetooth LE Periodic Advertising
+ * operations. Will return null if Bluetooth is turned off or if Bluetooth LE Periodic
+ * Advertising is not supported on this device.
+ * <p>
+ * Use {@link #isLePeriodicAdvertisingSupported()} to check whether LE Periodic Advertising is
+ * supported on this device before calling this method.
+ */
+ public PeriodicAdvertisingManager getPeriodicAdvertisingManager() {
+ if (!getLeAccess())
+ return null;
+
+ if (!isLePeriodicAdvertisingSupported())
+ return null;
+
+ synchronized (mLock) {
+ if (sPeriodicAdvertisingManager == null) {
+ sPeriodicAdvertisingManager =
+ new PeriodicAdvertisingManager(mManagerService);
+ }
+ }
+ return sPeriodicAdvertisingManager;
+ }
+
+ /**
* Returns a {@link BluetoothLeScanner} object for Bluetooth LE scan operations.
*/
public BluetoothLeScanner getBluetoothLeScanner() {
@@ -1385,6 +1411,78 @@
}
/**
+ * Return true if LE 2M PHY feature is supported.
+ *
+ * @return true if chipset supports LE 2M PHY feature
+ */
+ public boolean isLe2MPhySupported() {
+ if (!getLeAccess()) return false;
+ try {
+ mServiceLock.readLock().lock();
+ if (mService != null) return mService.isLe2MPhySupported();
+ } catch (RemoteException e) {
+ Log.e(TAG, "failed to get isExtendedAdvertisingSupported, error: ", e);
+ } finally {
+ mServiceLock.readLock().unlock();
+ }
+ return false;
+ }
+
+ /**
+ * Return true if LE Coded PHY feature is supported.
+ *
+ * @return true if chipset supports LE Coded PHY feature
+ */
+ public boolean isLeCodedPhySupported() {
+ if (!getLeAccess()) return false;
+ try {
+ mServiceLock.readLock().lock();
+ if (mService != null) return mService.isLeCodedPhySupported();
+ } catch (RemoteException e) {
+ Log.e(TAG, "failed to get isLeCodedPhySupported, error: ", e);
+ } finally {
+ mServiceLock.readLock().unlock();
+ }
+ return false;
+ }
+
+ /**
+ * Return true if LE Periodic Advertising feature is supported.
+ *
+ * @return true if chipset supports LE Periodic Advertising feature
+ */
+ public boolean isLeExtendedAdvertisingSupported() {
+ if (!getLeAccess()) return false;
+ try {
+ mServiceLock.readLock().lock();
+ if (mService != null) return mService.isLeExtendedAdvertisingSupported();
+ } catch (RemoteException e) {
+ Log.e(TAG, "failed to get isLeExtendedAdvertisingSupported, error: ", e);
+ } finally {
+ mServiceLock.readLock().unlock();
+ }
+ return false;
+ }
+
+ /**
+ * Return true if LE Periodic Advertising feature is supported.
+ *
+ * @return true if chipset supports LE Periodic Advertising feature
+ */
+ public boolean isLePeriodicAdvertisingSupported() {
+ if (!getLeAccess()) return false;
+ try {
+ mServiceLock.readLock().lock();
+ if (mService != null) return mService.isLePeriodicAdvertisingSupported();
+ } catch (RemoteException e) {
+ Log.e(TAG, "failed to get isLePeriodicAdvertisingSupported, error: ", e);
+ } finally {
+ mServiceLock.readLock().unlock();
+ }
+ return false;
+ }
+
+ /**
* Return true if hardware has entries available for matching beacons
*
* @return true if there are hw entries available for matching beacons
diff --git a/core/java/android/bluetooth/BluetoothDevice.java b/core/java/android/bluetooth/BluetoothDevice.java
index 7b1e687..31fc294 100644
--- a/core/java/android/bluetooth/BluetoothDevice.java
+++ b/core/java/android/bluetooth/BluetoothDevice.java
@@ -592,6 +592,42 @@
*/
public static final int TRANSPORT_LE = 2;
+ /**
+ * 1M initiating PHY.
+ */
+ public static final int PHY_LE_1M = 1;
+
+ /**
+ * 2M initiating PHY.
+ */
+ public static final int PHY_LE_2M = 2;
+
+ /**
+ * LE Coded initiating PHY.
+ */
+ public static final int PHY_LE_CODED = 4;
+
+ /**
+ * Any LE PHY.
+ */
+ public static final int PHY_LE_ANY = PHY_LE_1M | PHY_LE_2M | PHY_LE_CODED;
+
+ /**
+ * No preferred coding when transmitting on the LE Coded PHY.
+ */
+ public static final int PHY_OPTION_NO_PREFERRED = 0;
+
+ /**
+ * Prefer the S=2 coding to be used when transmitting on the LE Coded PHY.
+ */
+ public static final int PHY_OPTION_S2 = 1;
+
+ /**
+ * Prefer the S=8 coding to be used when transmitting on the LE Coded PHY.
+ */
+ public static final int PHY_OPTION_S8 = 2;
+
+
/** @hide */
public static final String EXTRA_MAS_INSTANCE =
"android.bluetooth.device.extra.MAS_INSTANCE";
@@ -1615,6 +1651,67 @@
*/
public BluetoothGatt connectGatt(Context context, boolean autoConnect,
BluetoothGattCallback callback, int transport) {
+ return (connectGatt(context, autoConnect,callback, TRANSPORT_AUTO, PHY_LE_1M));
+ }
+
+ /**
+ * Connect to GATT Server hosted by this device. Caller acts as GATT client.
+ * The callback is used to deliver results to Caller, such as connection status as well
+ * as any further GATT client operations.
+ * The method returns a BluetoothGatt instance. You can use BluetoothGatt to conduct
+ * GATT client operations.
+ * @param callback GATT callback handler that will receive asynchronous callbacks.
+ * @param autoConnect Whether to directly connect to the remote device (false)
+ * or to automatically connect as soon as the remote
+ * device becomes available (true).
+ * @throws IllegalArgumentException if callback is null
+ */
+ public BluetoothGatt connectGatt(Context context, boolean autoConnect,
+ BluetoothGattCallbackExt callback) {
+ return (connectGatt(context, autoConnect,callback, TRANSPORT_AUTO));
+ }
+
+ /**
+ * Connect to GATT Server hosted by this device. Caller acts as GATT client.
+ * The callback is used to deliver results to Caller, such as connection status as well
+ * as any further GATT client operations.
+ * The method returns a BluetoothGatt instance. You can use BluetoothGatt to conduct
+ * GATT client operations.
+ * @param callback GATT callback handler that will receive asynchronous callbacks.
+ * @param autoConnect Whether to directly connect to the remote device (false)
+ * or to automatically connect as soon as the remote
+ * device becomes available (true).
+ * @param transport preferred transport for GATT connections to remote dual-mode devices
+ * {@link BluetoothDevice#TRANSPORT_AUTO} or
+ * {@link BluetoothDevice#TRANSPORT_BREDR} or {@link BluetoothDevice#TRANSPORT_LE}
+ * @throws IllegalArgumentException if callback is null
+ */
+ public BluetoothGatt connectGatt(Context context, boolean autoConnect,
+ BluetoothGattCallbackExt callback, int transport) {
+ return (connectGatt(context, autoConnect,callback, TRANSPORT_AUTO, PHY_LE_1M));
+ }
+
+ /**
+ * Connect to GATT Server hosted by this device. Caller acts as GATT client.
+ * The callback is used to deliver results to Caller, such as connection status as well
+ * as any further GATT client operations.
+ * The method returns a BluetoothGatt instance. You can use BluetoothGatt to conduct
+ * GATT client operations.
+ * @param callback GATT callback handler that will receive asynchronous callbacks.
+ * @param autoConnect Whether to directly connect to the remote device (false)
+ * or to automatically connect as soon as the remote
+ * device becomes available (true).
+ * @param transport preferred transport for GATT connections to remote dual-mode devices
+ * {@link BluetoothDevice#TRANSPORT_AUTO} or
+ * {@link BluetoothDevice#TRANSPORT_BREDR} or {@link BluetoothDevice#TRANSPORT_LE}
+ * @param phy preferred PHY for connections to remote LE device. Bitwise OR of any of
+ * {@link BluetoothDevice#PHY_LE_1M}, {@link BluetoothDevice#PHY_LE_2M},
+ * and {@link BluetoothDevice#PHY_LE_CODED}. This option does not take effect if
+ * {@code autoConnect} is set to true.
+ * @throws IllegalArgumentException if callback is null
+ */
+ public BluetoothGatt connectGatt(Context context, boolean autoConnect,
+ BluetoothGattCallbackExt callback, int transport, int phy) {
// TODO(Bluetooth) check whether platform support BLE
// Do the check here or in GattServer?
BluetoothAdapter adapter = BluetoothAdapter.getDefaultAdapter();
@@ -1625,7 +1722,7 @@
// BLE is not supported
return null;
}
- BluetoothGatt gatt = new BluetoothGatt(iGatt, this, transport);
+ BluetoothGatt gatt = new BluetoothGatt(iGatt, this, transport, phy);
gatt.connect(autoConnect, callback);
return gatt;
} catch (RemoteException e) {Log.e(TAG, "", e);}
diff --git a/core/java/android/bluetooth/BluetoothGatt.java b/core/java/android/bluetooth/BluetoothGatt.java
index 97a3297..0cb69ae 100644
--- a/core/java/android/bluetooth/BluetoothGatt.java
+++ b/core/java/android/bluetooth/BluetoothGatt.java
@@ -31,7 +31,7 @@
* <p>This class provides Bluetooth GATT functionality to enable communication
* with Bluetooth Smart or Smart Ready devices.
*
- * <p>To connect to a remote peripheral device, create a {@link BluetoothGattCallback}
+ * <p>To connect to a remote peripheral device, create a {@link BluetoothGattCallbackExt}
* and call {@link BluetoothDevice#connectGatt} to get a instance of this class.
* GATT capable devices can be discovered using the Bluetooth device discovery or BLE
* scan process.
@@ -42,7 +42,7 @@
private static final boolean VDBG = false;
private IBluetoothGatt mService;
- private BluetoothGattCallback mCallback;
+ private BluetoothGattCallbackExt mCallback;
private int mClientIf;
private BluetoothDevice mDevice;
private boolean mAutoConnect;
@@ -51,6 +51,7 @@
private final Object mStateLock = new Object();
private Boolean mDeviceBusy = false;
private int mTransport;
+ private int mPhy;
private static final int AUTH_RETRY_STATE_IDLE = 0;
private static final int AUTH_RETRY_STATE_NO_MITM = 1;
@@ -132,10 +133,10 @@
/*package*/ static final int AUTHENTICATION_MITM = 2;
/**
- * Bluetooth GATT callbacks. Overrides the default BluetoothGattCallback implementation.
+ * Bluetooth GATT callbacks. Overrides the default BluetoothGattCallbackExt implementation.
*/
- private final IBluetoothGattCallback mBluetoothGattCallback =
- new IBluetoothGattCallback.Stub() {
+ private final IBluetoothGattCallbackExt mBluetoothGattCallbackExt =
+ new IBluetoothGattCallbackExt.Stub() {
/**
* Application interface registered - app is ready to go
* @hide
@@ -161,13 +162,51 @@
}
try {
mService.clientConnect(mClientIf, mDevice.getAddress(),
- !mAutoConnect, mTransport); // autoConnect is inverse of "isDirect"
+ !mAutoConnect, mTransport, mPhy); // autoConnect is inverse of "isDirect"
} catch (RemoteException e) {
Log.e(TAG,"",e);
}
}
/**
+ * Phy update callback
+ * @hide
+ */
+ @Override
+ public void onPhyUpdate(String address, int txPhy, int rxPhy, int status) {
+ if (DBG) Log.d(TAG, "onPhyUpdate() - status=" + status
+ + " address=" + address + " txPhy=" + txPhy + " rxPhy=" + rxPhy);
+ if (!address.equals(mDevice.getAddress())) {
+ return;
+ }
+
+ try {
+ mCallback.onPhyUpdate(BluetoothGatt.this, txPhy, rxPhy, status);
+ } catch (Exception ex) {
+ Log.w(TAG, "Unhandled exception in callback", ex);
+ }
+ }
+
+ /**
+ * Phy read callback
+ * @hide
+ */
+ @Override
+ public void onPhyRead(String address, int txPhy, int rxPhy, int status) {
+ if (DBG) Log.d(TAG, "onPhyRead() - status=" + status
+ + " address=" + address + " txPhy=" + txPhy + " rxPhy=" + rxPhy);
+ if (!address.equals(mDevice.getAddress())) {
+ return;
+ }
+
+ try {
+ mCallback.onPhyRead(BluetoothGatt.this, txPhy, rxPhy, status);
+ } catch (Exception ex) {
+ Log.w(TAG, "Unhandled exception in callback", ex);
+ }
+ }
+
+ /**
* Client connection state changed
* @hide
*/
@@ -503,10 +542,11 @@
};
/*package*/ BluetoothGatt(IBluetoothGatt iGatt, BluetoothDevice device,
- int transport) {
+ int transport, int phy) {
mService = iGatt;
mDevice = device;
mTransport = transport;
+ mPhy = phy;
mServices = new ArrayList<BluetoothGattService>();
mConnState = CONN_STATE_IDLE;
@@ -578,7 +618,7 @@
/**
* Register an application callback to start using GATT.
*
- * <p>This is an asynchronous call. The callback {@link BluetoothGattCallback#onAppRegistered}
+ * <p>This is an asynchronous call. The callback {@link BluetoothGattCallbackExt#onAppRegistered}
* is used to notify success or failure if the function returns true.
*
* <p>Requires {@link android.Manifest.permission#BLUETOOTH} permission.
@@ -587,7 +627,7 @@
* @return If true, the callback will be called to notify success or failure,
* false on immediate error
*/
- private boolean registerApp(BluetoothGattCallback callback) {
+ private boolean registerApp(BluetoothGattCallbackExt callback) {
if (DBG) Log.d(TAG, "registerApp()");
if (mService == null) return false;
@@ -596,7 +636,7 @@
if (DBG) Log.d(TAG, "registerApp() - UUID=" + uuid);
try {
- mService.registerClient(new ParcelUuid(uuid), mBluetoothGattCallback);
+ mService.registerClient(new ParcelUuid(uuid), mBluetoothGattCallbackExt);
} catch (RemoteException e) {
Log.e(TAG,"",e);
return false;
@@ -626,7 +666,7 @@
*
* <p>The connection may not be established right away, but will be
* completed when the remote device is available. A
- * {@link BluetoothGattCallback#onConnectionStateChange} callback will be
+ * {@link BluetoothGattCallbackExt#onConnectionStateChange} callback will be
* invoked when the connection state changes as a result of this function.
*
* <p>The autoConnect parameter determines whether to actively connect to
@@ -644,7 +684,7 @@
* device becomes available (true).
* @return true, if the connection attempt was initiated successfully
*/
- /*package*/ boolean connect(Boolean autoConnect, BluetoothGattCallback callback) {
+ /*package*/ boolean connect(Boolean autoConnect, BluetoothGattCallbackExt callback) {
if (DBG) Log.d(TAG, "connect() - device: " + mDevice.getAddress() + ", auto: " + autoConnect);
synchronized(mStateLock) {
if (mConnState != CONN_STATE_IDLE) {
@@ -696,7 +736,7 @@
public boolean connect() {
try {
mService.clientConnect(mClientIf, mDevice.getAddress(),
- false, mTransport); // autoConnect is inverse of "isDirect"
+ false, mTransport, mPhy); // autoConnect is inverse of "isDirect"
return true;
} catch (RemoteException e) {
Log.e(TAG,"",e);
@@ -705,6 +745,45 @@
}
/**
+ * Set the preferred connection PHY for this app. Please note that this is just a
+ * recommendation, wether the PHY change will happen depends on other applications peferences,
+ * local and remote controller capabilities. Controller can override these settings.
+ * <p>
+ * {@link BluetoothGattCallbackExt#onPhyUpdate} will be triggered as a result of this call, even
+ * if no PHY change happens. It is also triggered when remote device updates the PHY.
+ *
+ * @param txPhy preferred transmitter PHY. Bitwise OR of any of
+ * {@link BluetoothDevice#PHY_LE_1M}, {@link BluetoothDevice#PHY_LE_2M}, and
+ * {@link BluetoothDevice#PHY_LE_CODED}.
+ * @param rxPhy preferred receiver PHY. Bitwise OR of any of
+ * {@link BluetoothDevice#PHY_LE_1M}, {@link BluetoothDevice#PHY_LE_2M}, and
+ * {@link BluetoothDevice#PHY_LE_CODED}.
+ * @param phyOptions preferred coding to use when transmitting on the LE Coded PHY. Can be one
+ * of {@link BluetoothDevice#PHY_OPTION_NO_PREFERRED},
+ * {@link BluetoothDevice#PHY_OPTION_S2} or {@link BluetoothDevice#PHY_OPTION_S8}
+ */
+ public void setPreferredPhy(int txPhy, int rxPhy, int phyOptions) {
+ try {
+ mService.clientSetPreferredPhy(mClientIf, mDevice.getAddress(), txPhy, rxPhy,
+ phyOptions);
+ } catch (RemoteException e) {
+ Log.e(TAG,"",e);
+ }
+ }
+
+ /**
+ * Read the current transmitter PHY and receiver PHY of the connection. The values are returned
+ * in {@link BluetoothGattCallbackExt#onPhyRead}
+ */
+ public void readPhy() {
+ try {
+ mService.clientReadPhy(mClientIf, mDevice.getAddress());
+ } catch (RemoteException e) {
+ Log.e(TAG,"",e);
+ }
+ }
+
+ /**
* Return the remote bluetooth device this GATT client targets to
*
* @return remote bluetooth device
@@ -718,7 +797,7 @@
* characteristics and descriptors.
*
* <p>This is an asynchronous operation. Once service discovery is completed,
- * the {@link BluetoothGattCallback#onServicesDiscovered} callback is
+ * the {@link BluetoothGattCallbackExt#onServicesDiscovered} callback is
* triggered. If the discovery was successful, the remote services can be
* retrieved using the {@link #getServices} function.
*
@@ -797,7 +876,7 @@
* Reads the requested characteristic from the associated remote device.
*
* <p>This is an asynchronous operation. The result of the read operation
- * is reported by the {@link BluetoothGattCallback#onCharacteristicRead}
+ * is reported by the {@link BluetoothGattCallbackExt#onCharacteristicRead}
* callback.
*
* <p>Requires {@link android.Manifest.permission#BLUETOOTH} permission.
@@ -839,7 +918,7 @@
* Writes a given characteristic and its values to the associated remote device.
*
* <p>Once the write operation has been completed, the
- * {@link BluetoothGattCallback#onCharacteristicWrite} callback is invoked,
+ * {@link BluetoothGattCallbackExt#onCharacteristicWrite} callback is invoked,
* reporting the result of the operation.
*
* <p>Requires {@link android.Manifest.permission#BLUETOOTH} permission.
@@ -883,7 +962,7 @@
* Reads the value for a given descriptor from the associated remote device.
*
* <p>Once the read operation has been completed, the
- * {@link BluetoothGattCallback#onDescriptorRead} callback is
+ * {@link BluetoothGattCallbackExt#onDescriptorRead} callback is
* triggered, signaling the result of the operation.
*
* <p>Requires {@link android.Manifest.permission#BLUETOOTH} permission.
@@ -924,7 +1003,7 @@
/**
* Write the value of a given descriptor to the associated remote device.
*
- * <p>A {@link BluetoothGattCallback#onDescriptorWrite} callback is
+ * <p>A {@link BluetoothGattCallbackExt#onDescriptorWrite} callback is
* triggered to report the result of the write operation.
*
* <p>Requires {@link android.Manifest.permission#BLUETOOTH} permission.
@@ -968,7 +1047,7 @@
* <p>Once a reliable write transaction has been initiated, all calls
* to {@link #writeCharacteristic} are sent to the remote device for
* verification and queued up for atomic execution. The application will
- * receive an {@link BluetoothGattCallback#onCharacteristicWrite} callback
+ * receive an {@link BluetoothGattCallbackExt#onCharacteristicWrite} callback
* in response to every {@link #writeCharacteristic} call and is responsible
* for verifying if the value has been transmitted accurately.
*
@@ -1002,7 +1081,7 @@
* <p>This function will commit all queued up characteristic write
* operations for a given remote device.
*
- * <p>A {@link BluetoothGattCallback#onReliableWriteCompleted} callback is
+ * <p>A {@link BluetoothGattCallbackExt#onReliableWriteCompleted} callback is
* invoked to indicate whether the transaction has been executed correctly.
*
* <p>Requires {@link android.Manifest.permission#BLUETOOTH} permission.
@@ -1059,7 +1138,7 @@
* Enable or disable notifications/indications for a given characteristic.
*
* <p>Once notifications are enabled for a characteristic, a
- * {@link BluetoothGattCallback#onCharacteristicChanged} callback will be
+ * {@link BluetoothGattCallbackExt#onCharacteristicChanged} callback will be
* triggered if the remote device indicates that the given characteristic
* has changed.
*
@@ -1114,7 +1193,7 @@
/**
* Read the RSSI for a connected remote device.
*
- * <p>The {@link BluetoothGattCallback#onReadRemoteRssi} callback will be
+ * <p>The {@link BluetoothGattCallbackExt#onReadRemoteRssi} callback will be
* invoked when the RSSI value has been read.
*
* <p>Requires {@link android.Manifest.permission#BLUETOOTH} permission.
@@ -1142,7 +1221,7 @@
* the data sent is truncated to the MTU size. This function may be used
* to request a larger MTU size to be able to send more data at once.
*
- * <p>A {@link BluetoothGattCallback#onMtuChanged} callback will indicate
+ * <p>A {@link BluetoothGattCallbackExt#onMtuChanged} callback will indicate
* whether this operation was successful.
*
* <p>Requires {@link android.Manifest.permission#BLUETOOTH} permission.
diff --git a/core/java/android/bluetooth/BluetoothGattCallback.java b/core/java/android/bluetooth/BluetoothGattCallback.java
index a915620..4da106d 100644
--- a/core/java/android/bluetooth/BluetoothGattCallback.java
+++ b/core/java/android/bluetooth/BluetoothGattCallback.java
@@ -18,138 +18,22 @@
/**
* This abstract class is used to implement {@link BluetoothGatt} callbacks.
+ * @deprecated use {@link BluetoothGattCallbackExt}
*/
-public abstract class BluetoothGattCallback {
+public abstract class BluetoothGattCallback extends BluetoothGattCallbackExt {
/**
- * Callback indicating when GATT client has connected/disconnected to/from a remote
- * GATT server.
- *
- * @param gatt GATT client
- * @param status Status of the connect or disconnect operation.
- * {@link BluetoothGatt#GATT_SUCCESS} if the operation succeeds.
- * @param newState Returns the new connection state. Can be one of
- * {@link BluetoothProfile#STATE_DISCONNECTED} or
- * {@link BluetoothProfile#STATE_CONNECTED}
+ * @hide
*/
- public void onConnectionStateChange(BluetoothGatt gatt, int status,
- int newState) {
+ @Override
+ public void onPhyUpdate(BluetoothGatt gatt, int txPhy, int rxPhy, int status) {
}
/**
- * Callback invoked when the list of remote services, characteristics and descriptors
- * for the remote device have been updated, ie new services have been discovered.
- *
- * @param gatt GATT client invoked {@link BluetoothGatt#discoverServices}
- * @param status {@link BluetoothGatt#GATT_SUCCESS} if the remote device
- * has been explored successfully.
+ * @hide
*/
- public void onServicesDiscovered(BluetoothGatt gatt, int status) {
+ @Override
+ public void onPhyRead(BluetoothGatt gatt, int txPhy, int rxPhy, int status) {
}
- /**
- * Callback reporting the result of a characteristic read operation.
- *
- * @param gatt GATT client invoked {@link BluetoothGatt#readCharacteristic}
- * @param characteristic Characteristic that was read from the associated
- * remote device.
- * @param status {@link BluetoothGatt#GATT_SUCCESS} if the read operation
- * was completed successfully.
- */
- public void onCharacteristicRead(BluetoothGatt gatt, BluetoothGattCharacteristic characteristic,
- int status) {
- }
-
- /**
- * Callback indicating the result of a characteristic write operation.
- *
- * <p>If this callback is invoked while a reliable write transaction is
- * in progress, the value of the characteristic represents the value
- * reported by the remote device. An application should compare this
- * value to the desired value to be written. If the values don't match,
- * the application must abort the reliable write transaction.
- *
- * @param gatt GATT client invoked {@link BluetoothGatt#writeCharacteristic}
- * @param characteristic Characteristic that was written to the associated
- * remote device.
- * @param status The result of the write operation
- * {@link BluetoothGatt#GATT_SUCCESS} if the operation succeeds.
- */
- public void onCharacteristicWrite(BluetoothGatt gatt,
- BluetoothGattCharacteristic characteristic, int status) {
- }
-
- /**
- * Callback triggered as a result of a remote characteristic notification.
- *
- * @param gatt GATT client the characteristic is associated with
- * @param characteristic Characteristic that has been updated as a result
- * of a remote notification event.
- */
- public void onCharacteristicChanged(BluetoothGatt gatt,
- BluetoothGattCharacteristic characteristic) {
- }
-
- /**
- * Callback reporting the result of a descriptor read operation.
- *
- * @param gatt GATT client invoked {@link BluetoothGatt#readDescriptor}
- * @param descriptor Descriptor that was read from the associated
- * remote device.
- * @param status {@link BluetoothGatt#GATT_SUCCESS} if the read operation
- * was completed successfully
- */
- public void onDescriptorRead(BluetoothGatt gatt, BluetoothGattDescriptor descriptor,
- int status) {
- }
-
- /**
- * Callback indicating the result of a descriptor write operation.
- *
- * @param gatt GATT client invoked {@link BluetoothGatt#writeDescriptor}
- * @param descriptor Descriptor that was writte to the associated
- * remote device.
- * @param status The result of the write operation
- * {@link BluetoothGatt#GATT_SUCCESS} if the operation succeeds.
- */
- public void onDescriptorWrite(BluetoothGatt gatt, BluetoothGattDescriptor descriptor,
- int status) {
- }
-
- /**
- * Callback invoked when a reliable write transaction has been completed.
- *
- * @param gatt GATT client invoked {@link BluetoothGatt#executeReliableWrite}
- * @param status {@link BluetoothGatt#GATT_SUCCESS} if the reliable write
- * transaction was executed successfully
- */
- public void onReliableWriteCompleted(BluetoothGatt gatt, int status) {
- }
-
- /**
- * Callback reporting the RSSI for a remote device connection.
- *
- * This callback is triggered in response to the
- * {@link BluetoothGatt#readRemoteRssi} function.
- *
- * @param gatt GATT client invoked {@link BluetoothGatt#readRemoteRssi}
- * @param rssi The RSSI value for the remote device
- * @param status {@link BluetoothGatt#GATT_SUCCESS} if the RSSI was read successfully
- */
- public void onReadRemoteRssi(BluetoothGatt gatt, int rssi, int status) {
- }
-
- /**
- * Callback indicating the MTU for a given device connection has changed.
- *
- * This callback is triggered in response to the
- * {@link BluetoothGatt#requestMtu} function, or in response to a connection
- * event.
- *
- * @param gatt GATT client invoked {@link BluetoothGatt#requestMtu}
- * @param mtu The new MTU size
- * @param status {@link BluetoothGatt#GATT_SUCCESS} if the MTU has been changed successfully
- */
- public void onMtuChanged(BluetoothGatt gatt, int mtu, int status) {
- }
}
diff --git a/core/java/android/bluetooth/BluetoothGattCallbackExt.java b/core/java/android/bluetooth/BluetoothGattCallbackExt.java
new file mode 100644
index 0000000..63774c8
--- /dev/null
+++ b/core/java/android/bluetooth/BluetoothGattCallbackExt.java
@@ -0,0 +1,182 @@
+/*
+ * Copyright (C) 2017 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package android.bluetooth;
+
+/**
+ * This abstract class is used to implement {@link BluetoothGatt} callbacks.
+ */
+public abstract class BluetoothGattCallbackExt {
+
+ /**
+ * Callback triggered as result of {@link BluetoothGatt#setPreferredPhy}, or as a result of
+ * remote device changing the PHY.
+ *
+ * @param gatt GATT client
+ * @param txPhy the transmitter PHY in use. One of {@link BluetoothDevice#PHY_LE_1M},
+ * {@link BluetoothDevice#PHY_LE_2M}, and {@link BluetoothDevice#PHY_LE_CODED}.
+ * @param rxPhy the receiver PHY in use. One of {@link BluetoothDevice#PHY_LE_1M},
+ * {@link BluetoothDevice#PHY_LE_2M}, and {@link BluetoothDevice#PHY_LE_CODED}.
+ * @param status status of the operation
+ */
+ public void onPhyUpdate(BluetoothGatt gatt, int txPhy, int rxPhy, int status) {
+ }
+
+ /**
+ * Callback triggered as result of {@link BluetoothGatt#readPhy}
+ *
+ * @param gatt GATT client
+ * @param txPhy the transmitter PHY in use. One of {@link BluetoothDevice#PHY_LE_1M},
+ * {@link BluetoothDevice#PHY_LE_2M}, and {@link BluetoothDevice#PHY_LE_CODED}.
+ * @param rxPhy the receiver PHY in use. One of {@link BluetoothDevice#PHY_LE_1M},
+ * {@link BluetoothDevice#PHY_LE_2M}, and {@link BluetoothDevice#PHY_LE_CODED}.
+ * @param status status of the operation
+ */
+ public void onPhyRead(BluetoothGatt gatt, int txPhy, int rxPhy, int status) {
+ }
+
+ /**
+ * Callback indicating when GATT client has connected/disconnected to/from a remote
+ * GATT server.
+ *
+ * @param gatt GATT client
+ * @param status Status of the connect or disconnect operation.
+ * {@link BluetoothGatt#GATT_SUCCESS} if the operation succeeds.
+ * @param newState Returns the new connection state. Can be one of
+ * {@link BluetoothProfile#STATE_DISCONNECTED} or
+ * {@link BluetoothProfile#STATE_CONNECTED}
+ */
+ public void onConnectionStateChange(BluetoothGatt gatt, int status,
+ int newState) {
+ }
+
+ /**
+ * Callback invoked when the list of remote services, characteristics and descriptors
+ * for the remote device have been updated, ie new services have been discovered.
+ *
+ * @param gatt GATT client invoked {@link BluetoothGatt#discoverServices}
+ * @param status {@link BluetoothGatt#GATT_SUCCESS} if the remote device
+ * has been explored successfully.
+ */
+ public void onServicesDiscovered(BluetoothGatt gatt, int status) {
+ }
+
+ /**
+ * Callback reporting the result of a characteristic read operation.
+ *
+ * @param gatt GATT client invoked {@link BluetoothGatt#readCharacteristic}
+ * @param characteristic Characteristic that was read from the associated
+ * remote device.
+ * @param status {@link BluetoothGatt#GATT_SUCCESS} if the read operation
+ * was completed successfully.
+ */
+ public void onCharacteristicRead(BluetoothGatt gatt, BluetoothGattCharacteristic characteristic,
+ int status) {
+ }
+
+ /**
+ * Callback indicating the result of a characteristic write operation.
+ *
+ * <p>If this callback is invoked while a reliable write transaction is
+ * in progress, the value of the characteristic represents the value
+ * reported by the remote device. An application should compare this
+ * value to the desired value to be written. If the values don't match,
+ * the application must abort the reliable write transaction.
+ *
+ * @param gatt GATT client invoked {@link BluetoothGatt#writeCharacteristic}
+ * @param characteristic Characteristic that was written to the associated
+ * remote device.
+ * @param status The result of the write operation
+ * {@link BluetoothGatt#GATT_SUCCESS} if the operation succeeds.
+ */
+ public void onCharacteristicWrite(BluetoothGatt gatt,
+ BluetoothGattCharacteristic characteristic, int status) {
+ }
+
+ /**
+ * Callback triggered as a result of a remote characteristic notification.
+ *
+ * @param gatt GATT client the characteristic is associated with
+ * @param characteristic Characteristic that has been updated as a result
+ * of a remote notification event.
+ */
+ public void onCharacteristicChanged(BluetoothGatt gatt,
+ BluetoothGattCharacteristic characteristic) {
+ }
+
+ /**
+ * Callback reporting the result of a descriptor read operation.
+ *
+ * @param gatt GATT client invoked {@link BluetoothGatt#readDescriptor}
+ * @param descriptor Descriptor that was read from the associated
+ * remote device.
+ * @param status {@link BluetoothGatt#GATT_SUCCESS} if the read operation
+ * was completed successfully
+ */
+ public void onDescriptorRead(BluetoothGatt gatt, BluetoothGattDescriptor descriptor,
+ int status) {
+ }
+
+ /**
+ * Callback indicating the result of a descriptor write operation.
+ *
+ * @param gatt GATT client invoked {@link BluetoothGatt#writeDescriptor}
+ * @param descriptor Descriptor that was writte to the associated
+ * remote device.
+ * @param status The result of the write operation
+ * {@link BluetoothGatt#GATT_SUCCESS} if the operation succeeds.
+ */
+ public void onDescriptorWrite(BluetoothGatt gatt, BluetoothGattDescriptor descriptor,
+ int status) {
+ }
+
+ /**
+ * Callback invoked when a reliable write transaction has been completed.
+ *
+ * @param gatt GATT client invoked {@link BluetoothGatt#executeReliableWrite}
+ * @param status {@link BluetoothGatt#GATT_SUCCESS} if the reliable write
+ * transaction was executed successfully
+ */
+ public void onReliableWriteCompleted(BluetoothGatt gatt, int status) {
+ }
+
+ /**
+ * Callback reporting the RSSI for a remote device connection.
+ *
+ * This callback is triggered in response to the
+ * {@link BluetoothGatt#readRemoteRssi} function.
+ *
+ * @param gatt GATT client invoked {@link BluetoothGatt#readRemoteRssi}
+ * @param rssi The RSSI value for the remote device
+ * @param status {@link BluetoothGatt#GATT_SUCCESS} if the RSSI was read successfully
+ */
+ public void onReadRemoteRssi(BluetoothGatt gatt, int rssi, int status) {
+ }
+
+ /**
+ * Callback indicating the MTU for a given device connection has changed.
+ *
+ * This callback is triggered in response to the
+ * {@link BluetoothGatt#requestMtu} function, or in response to a connection
+ * event.
+ *
+ * @param gatt GATT client invoked {@link BluetoothGatt#requestMtu}
+ * @param mtu The new MTU size
+ * @param status {@link BluetoothGatt#GATT_SUCCESS} if the MTU has been changed successfully
+ */
+ public void onMtuChanged(BluetoothGatt gatt, int mtu, int status) {
+ }
+}
diff --git a/core/java/android/bluetooth/BluetoothGattServer.java b/core/java/android/bluetooth/BluetoothGattServer.java
index 5ffceba..9ee739f 100644
--- a/core/java/android/bluetooth/BluetoothGattServer.java
+++ b/core/java/android/bluetooth/BluetoothGattServer.java
@@ -46,7 +46,7 @@
private BluetoothAdapter mAdapter;
private IBluetoothGatt mService;
- private BluetoothGattServerCallback mCallback;
+ private BluetoothGattServerCallbackExt mCallback;
private Object mServerIfLock = new Object();
private int mServerIf;
@@ -59,8 +59,8 @@
/**
* Bluetooth GATT interface callbacks
*/
- private final IBluetoothGattServerCallback mBluetoothGattServerCallback =
- new IBluetoothGattServerCallback.Stub() {
+ private final IBluetoothGattServerCallbackExt mBluetoothGattServerCallback =
+ new IBluetoothGattServerCallbackExt.Stub() {
/**
* Application interface registered - app is ready to go
* @hide
@@ -292,6 +292,42 @@
Log.w(TAG, "Unhandled exception: " + ex);
}
}
+
+ /**
+ * The PHY for a connection was updated
+ * @hide
+ */
+ public void onPhyUpdate(String address, int txPhy, int rxPhy, int status) {
+ if (DBG) Log.d(TAG, "onPhyUpdate() - " + "device=" + address + ", txPHy=" + txPhy
+ + ", rxPHy=" + rxPhy);
+
+ BluetoothDevice device = mAdapter.getRemoteDevice(address);
+ if (device == null) return;
+
+ try {
+ mCallback.onPhyUpdate(device, txPhy, rxPhy, status);
+ } catch (Exception ex) {
+ Log.w(TAG, "Unhandled exception: " + ex);
+ }
+ }
+
+ /**
+ * The PHY for a connection was read
+ * @hide
+ */
+ public void onPhyRead(String address, int txPhy, int rxPhy, int status) {
+ if (DBG) Log.d(TAG, "onPhyUpdate() - " + "device=" + address + ", txPHy=" + txPhy
+ + ", rxPHy=" + rxPhy);
+
+ BluetoothDevice device = mAdapter.getRemoteDevice(address);
+ if (device == null) return;
+
+ try {
+ mCallback.onPhyRead(device, txPhy, rxPhy, status);
+ } catch (Exception ex) {
+ Log.w(TAG, "Unhandled exception: " + ex);
+ }
+ }
};
/**
@@ -360,7 +396,7 @@
* @return true, the callback will be called to notify success or failure,
* false on immediate error
*/
- /*package*/ boolean registerCallback(BluetoothGattServerCallback callback) {
+ /*package*/ boolean registerCallback(BluetoothGattServerCallbackExt callback) {
if (DBG) Log.d(TAG, "registerCallback()");
if (mService == null) {
Log.e(TAG, "GATT service not available");
@@ -436,7 +472,7 @@
*
* <p>The connection may not be established right away, but will be
* completed when the remote device is available. A
- * {@link BluetoothGattServerCallback#onConnectionStateChange} callback will be
+ * {@link BluetoothGattServerCallbackExt#onConnectionStateChange} callback will be
* invoked when the connection state changes as a result of this function.
*
* <p>The autoConnect paramter determines whether to actively connect to
@@ -488,16 +524,58 @@
}
/**
+ * Set the preferred connection PHY for this app. Please note that this is just a
+ * recommendation, wether the PHY change will happen depends on other applications peferences,
+ * local and remote controller capabilities. Controller can override these settings.
+ * <p>
+ * {@link BluetoothGattServerCallbackExt#onPhyUpdate} will be triggered as a result of this call, even
+ * if no PHY change happens. It is also triggered when remote device updates the PHY.
+ *
+ * @param device The remote device to send this response to
+ * @param txPhy preferred transmitter PHY. Bitwise OR of any of
+ * {@link BluetoothDevice#PHY_LE_1M}, {@link BluetoothDevice#PHY_LE_2M}, and
+ * {@link BluetoothDevice#PHY_LE_CODED}.
+ * @param rxPhy preferred receiver PHY. Bitwise OR of any of
+ * {@link BluetoothDevice#PHY_LE_1M}, {@link BluetoothDevice#PHY_LE_2M}, and
+ * {@link BluetoothDevice#PHY_LE_CODED}.
+ * @param phyOptions preferred coding to use when transmitting on the LE Coded PHY. Can be one
+ * of {@link BluetoothDevice#PHY_OPTION_NO_PREFERRED},
+ * {@link BluetoothDevice#PHY_OPTION_S2} or {@link BluetoothDevice#PHY_OPTION_S8}
+ */
+ public void setPreferredPhy(BluetoothDevice device, int txPhy, int rxPhy, int phyOptions) {
+ try {
+ mService.serverSetPreferredPhy(mServerIf, device.getAddress(), txPhy, rxPhy,
+ phyOptions);
+ } catch (RemoteException e) {
+ Log.e(TAG,"",e);
+ }
+ }
+
+ /**
+ * Read the current transmitter PHY and receiver PHY of the connection. The values are returned
+ * in {@link BluetoothGattServerCallbackExt#onPhyRead}
+ *
+ * @param device The remote device to send this response to
+ */
+ public void readPhy(BluetoothDevice device) {
+ try {
+ mService.serverReadPhy(mServerIf, device.getAddress());
+ } catch (RemoteException e) {
+ Log.e(TAG,"",e);
+ }
+ }
+
+ /**
* Send a response to a read or write request to a remote device.
*
* <p>This function must be invoked in when a remote read/write request
* is received by one of these callback methods:
*
* <ul>
- * <li>{@link BluetoothGattServerCallback#onCharacteristicReadRequest}
- * <li>{@link BluetoothGattServerCallback#onCharacteristicWriteRequest}
- * <li>{@link BluetoothGattServerCallback#onDescriptorReadRequest}
- * <li>{@link BluetoothGattServerCallback#onDescriptorWriteRequest}
+ * <li>{@link BluetoothGattServerCallbackExt#onCharacteristicReadRequest}
+ * <li>{@link BluetoothGattServerCallbackExt#onCharacteristicWriteRequest}
+ * <li>{@link BluetoothGattServerCallbackExt#onDescriptorReadRequest}
+ * <li>{@link BluetoothGattServerCallbackExt#onDescriptorWriteRequest}
* </ul>
*
* <p>Requires {@link android.Manifest.permission#BLUETOOTH} permission.
diff --git a/core/java/android/bluetooth/BluetoothGattServerCallback.java b/core/java/android/bluetooth/BluetoothGattServerCallback.java
index 2afcf9a..75ceb52 100644
--- a/core/java/android/bluetooth/BluetoothGattServerCallback.java
+++ b/core/java/android/bluetooth/BluetoothGattServerCallback.java
@@ -1,5 +1,5 @@
/*
- * Copyright (C) 2013 The Android Open Source Project
+ * Copyright (C) 2017 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -20,141 +20,21 @@
/**
* This abstract class is used to implement {@link BluetoothGattServer} callbacks.
+ * @deprecated please use {@link BluetoothGattServerCallbackExt}
*/
-public abstract class BluetoothGattServerCallback {
+public abstract class BluetoothGattServerCallback extends BluetoothGattServerCallbackExt {
/**
- * Callback indicating when a remote device has been connected or disconnected.
- *
- * @param device Remote device that has been connected or disconnected.
- * @param status Status of the connect or disconnect operation.
- * @param newState Returns the new connection state. Can be one of
- * {@link BluetoothProfile#STATE_DISCONNECTED} or
- * {@link BluetoothProfile#STATE_CONNECTED}
+ * @hide
*/
- public void onConnectionStateChange(BluetoothDevice device, int status,
- int newState) {
+ @Override
+ public void onPhyUpdate(BluetoothDevice device, int txPhy, int rxPhy, int status) {
}
/**
- * Indicates whether a local service has been added successfully.
- *
- * @param status Returns {@link BluetoothGatt#GATT_SUCCESS} if the service
- * was added successfully.
- * @param service The service that has been added
+ * @hide
*/
- public void onServiceAdded(int status, BluetoothGattService service) {
- }
-
- /**
- * A remote client has requested to read a local characteristic.
- *
- * <p>An application must call {@link BluetoothGattServer#sendResponse}
- * to complete the request.
- *
- * @param device The remote device that has requested the read operation
- * @param requestId The Id of the request
- * @param offset Offset into the value of the characteristic
- * @param characteristic Characteristic to be read
- */
- public void onCharacteristicReadRequest(BluetoothDevice device, int requestId,
- int offset, BluetoothGattCharacteristic characteristic) {
- }
-
- /**
- * A remote client has requested to write to a local characteristic.
- *
- * <p>An application must call {@link BluetoothGattServer#sendResponse}
- * to complete the request.
- *
- * @param device The remote device that has requested the write operation
- * @param requestId The Id of the request
- * @param characteristic Characteristic to be written to.
- * @param preparedWrite true, if this write operation should be queued for
- * later execution.
- * @param responseNeeded true, if the remote device requires a response
- * @param offset The offset given for the value
- * @param value The value the client wants to assign to the characteristic
- */
- public void onCharacteristicWriteRequest(BluetoothDevice device, int requestId,
- BluetoothGattCharacteristic characteristic,
- boolean preparedWrite, boolean responseNeeded,
- int offset, byte[] value) {
- }
-
- /**
- * A remote client has requested to read a local descriptor.
- *
- * <p>An application must call {@link BluetoothGattServer#sendResponse}
- * to complete the request.
- *
- * @param device The remote device that has requested the read operation
- * @param requestId The Id of the request
- * @param offset Offset into the value of the characteristic
- * @param descriptor Descriptor to be read
- */
- public void onDescriptorReadRequest(BluetoothDevice device, int requestId,
- int offset, BluetoothGattDescriptor descriptor) {
- }
-
- /**
- * A remote client has requested to write to a local descriptor.
- *
- * <p>An application must call {@link BluetoothGattServer#sendResponse}
- * to complete the request.
- *
- * @param device The remote device that has requested the write operation
- * @param requestId The Id of the request
- * @param descriptor Descriptor to be written to.
- * @param preparedWrite true, if this write operation should be queued for
- * later execution.
- * @param responseNeeded true, if the remote device requires a response
- * @param offset The offset given for the value
- * @param value The value the client wants to assign to the descriptor
- */
- public void onDescriptorWriteRequest(BluetoothDevice device, int requestId,
- BluetoothGattDescriptor descriptor,
- boolean preparedWrite, boolean responseNeeded,
- int offset, byte[] value) {
- }
-
- /**
- * Execute all pending write operations for this device.
- *
- * <p>An application must call {@link BluetoothGattServer#sendResponse}
- * to complete the request.
- *
- * @param device The remote device that has requested the write operations
- * @param requestId The Id of the request
- * @param execute Whether the pending writes should be executed (true) or
- * cancelled (false)
- */
- public void onExecuteWrite(BluetoothDevice device, int requestId, boolean execute) {
- }
-
- /**
- * Callback invoked when a notification or indication has been sent to
- * a remote device.
- *
- * <p>When multiple notifications are to be sent, an application must
- * wait for this callback to be received before sending additional
- * notifications.
- *
- * @param device The remote device the notification has been sent to
- * @param status {@link BluetoothGatt#GATT_SUCCESS} if the operation was successful
- */
- public void onNotificationSent(BluetoothDevice device, int status) {
- }
-
- /**
- * Callback indicating the MTU for a given device connection has changed.
- *
- * <p>This callback will be invoked if a remote client has requested to change
- * the MTU for a given connection.
- *
- * @param device The remote device that requested the MTU change
- * @param mtu The new MTU size
- */
- public void onMtuChanged(BluetoothDevice device, int mtu) {
+ @Override
+ public void onPhyRead(BluetoothDevice device, int txPhy, int rxPhy, int status) {
}
}
diff --git a/core/java/android/bluetooth/BluetoothGattServerCallbackExt.java b/core/java/android/bluetooth/BluetoothGattServerCallbackExt.java
new file mode 100644
index 0000000..455cce0
--- /dev/null
+++ b/core/java/android/bluetooth/BluetoothGattServerCallbackExt.java
@@ -0,0 +1,187 @@
+/*
+ * Copyright (C) 2013 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package android.bluetooth;
+
+import android.bluetooth.BluetoothDevice;
+
+/**
+ * This abstract class is used to implement {@link BluetoothGattServer} callbacks.
+ */
+public abstract class BluetoothGattServerCallbackExt {
+
+ /**
+ * Callback indicating when a remote device has been connected or disconnected.
+ *
+ * @param device Remote device that has been connected or disconnected.
+ * @param status Status of the connect or disconnect operation.
+ * @param newState Returns the new connection state. Can be one of
+ * {@link BluetoothProfile#STATE_DISCONNECTED} or
+ * {@link BluetoothProfile#STATE_CONNECTED}
+ */
+ public void onConnectionStateChange(BluetoothDevice device, int status,
+ int newState) {
+ }
+
+ /**
+ * Indicates whether a local service has been added successfully.
+ *
+ * @param status Returns {@link BluetoothGatt#GATT_SUCCESS} if the service
+ * was added successfully.
+ * @param service The service that has been added
+ */
+ public void onServiceAdded(int status, BluetoothGattService service) {
+ }
+
+ /**
+ * A remote client has requested to read a local characteristic.
+ *
+ * <p>An application must call {@link BluetoothGattServer#sendResponse}
+ * to complete the request.
+ *
+ * @param device The remote device that has requested the read operation
+ * @param requestId The Id of the request
+ * @param offset Offset into the value of the characteristic
+ * @param characteristic Characteristic to be read
+ */
+ public void onCharacteristicReadRequest(BluetoothDevice device, int requestId,
+ int offset, BluetoothGattCharacteristic characteristic) {
+ }
+
+ /**
+ * A remote client has requested to write to a local characteristic.
+ *
+ * <p>An application must call {@link BluetoothGattServer#sendResponse}
+ * to complete the request.
+ *
+ * @param device The remote device that has requested the write operation
+ * @param requestId The Id of the request
+ * @param characteristic Characteristic to be written to.
+ * @param preparedWrite true, if this write operation should be queued for
+ * later execution.
+ * @param responseNeeded true, if the remote device requires a response
+ * @param offset The offset given for the value
+ * @param value The value the client wants to assign to the characteristic
+ */
+ public void onCharacteristicWriteRequest(BluetoothDevice device, int requestId,
+ BluetoothGattCharacteristic characteristic,
+ boolean preparedWrite, boolean responseNeeded,
+ int offset, byte[] value) {
+ }
+
+ /**
+ * A remote client has requested to read a local descriptor.
+ *
+ * <p>An application must call {@link BluetoothGattServer#sendResponse}
+ * to complete the request.
+ *
+ * @param device The remote device that has requested the read operation
+ * @param requestId The Id of the request
+ * @param offset Offset into the value of the characteristic
+ * @param descriptor Descriptor to be read
+ */
+ public void onDescriptorReadRequest(BluetoothDevice device, int requestId,
+ int offset, BluetoothGattDescriptor descriptor) {
+ }
+
+ /**
+ * A remote client has requested to write to a local descriptor.
+ *
+ * <p>An application must call {@link BluetoothGattServer#sendResponse}
+ * to complete the request.
+ *
+ * @param device The remote device that has requested the write operation
+ * @param requestId The Id of the request
+ * @param descriptor Descriptor to be written to.
+ * @param preparedWrite true, if this write operation should be queued for
+ * later execution.
+ * @param responseNeeded true, if the remote device requires a response
+ * @param offset The offset given for the value
+ * @param value The value the client wants to assign to the descriptor
+ */
+ public void onDescriptorWriteRequest(BluetoothDevice device, int requestId,
+ BluetoothGattDescriptor descriptor,
+ boolean preparedWrite, boolean responseNeeded,
+ int offset, byte[] value) {
+ }
+
+ /**
+ * Execute all pending write operations for this device.
+ *
+ * <p>An application must call {@link BluetoothGattServer#sendResponse}
+ * to complete the request.
+ *
+ * @param device The remote device that has requested the write operations
+ * @param requestId The Id of the request
+ * @param execute Whether the pending writes should be executed (true) or
+ * cancelled (false)
+ */
+ public void onExecuteWrite(BluetoothDevice device, int requestId, boolean execute) {
+ }
+
+ /**
+ * Callback invoked when a notification or indication has been sent to
+ * a remote device.
+ *
+ * <p>When multiple notifications are to be sent, an application must
+ * wait for this callback to be received before sending additional
+ * notifications.
+ *
+ * @param device The remote device the notification has been sent to
+ * @param status {@link BluetoothGatt#GATT_SUCCESS} if the operation was successful
+ */
+ public void onNotificationSent(BluetoothDevice device, int status) {
+ }
+
+ /**
+ * Callback indicating the MTU for a given device connection has changed.
+ *
+ * <p>This callback will be invoked if a remote client has requested to change
+ * the MTU for a given connection.
+ *
+ * @param device The remote device that requested the MTU change
+ * @param mtu The new MTU size
+ */
+ public void onMtuChanged(BluetoothDevice device, int mtu) {
+ }
+
+ /**
+ * Callback triggered as result of {@link BluetoothGattServer#setPreferredPhy}, or as a result
+ * of remote device changing the PHY.
+ *
+ * @param device The remote device
+ * @param txPhy the transmitter PHY in use. One of {@link BluetoothDevice#PHY_LE_1M},
+ * {@link BluetoothDevice#PHY_LE_2M}, and {@link BluetoothDevice#PHY_LE_CODED}
+ * @param rxPhy the receiver PHY in use. One of {@link BluetoothDevice#PHY_LE_1M},
+ * {@link BluetoothDevice#PHY_LE_2M}, and {@link BluetoothDevice#PHY_LE_CODED}
+ * @param status status of the operation
+ */
+ public void onPhyUpdate(BluetoothDevice device, int txPhy, int rxPhy, int status) {
+ }
+
+ /**
+ * Callback triggered as result of {@link BluetoothGattServer#readPhy}
+ *
+ * @param device The remote device that requested the PHY read
+ * @param txPhy the transmitter PHY in use. One of {@link BluetoothDevice#PHY_LE_1M},
+ * {@link BluetoothDevice#PHY_LE_2M}, and {@link BluetoothDevice#PHY_LE_CODED}
+ * @param rxPhy the receiver PHY in use. One of {@link BluetoothDevice#PHY_LE_1M},
+ * {@link BluetoothDevice#PHY_LE_2M}, and {@link BluetoothDevice#PHY_LE_CODED}
+ * @param status status of the operation
+ */
+ public void onPhyRead(BluetoothDevice device, int txPhy, int rxPhy, int status) {
+ }
+}
diff --git a/core/java/android/bluetooth/IBluetooth.aidl b/core/java/android/bluetooth/IBluetooth.aidl
index 53fef2a..76ca554 100644
--- a/core/java/android/bluetooth/IBluetooth.aidl
+++ b/core/java/android/bluetooth/IBluetooth.aidl
@@ -104,6 +104,10 @@
boolean isOffloadedFilteringSupported();
boolean isOffloadedScanBatchingSupported();
boolean isActivityAndEnergyReportingSupported();
+ boolean isLe2MPhySupported();
+ boolean isLeCodedPhySupported();
+ boolean isLeExtendedAdvertisingSupported();
+ boolean isLePeriodicAdvertisingSupported();
BluetoothActivityEnergyInfo reportActivityInfo();
/**
diff --git a/core/java/android/bluetooth/IBluetoothGatt.aidl b/core/java/android/bluetooth/IBluetoothGatt.aidl
index aa2291e..33fedc7 100644
--- a/core/java/android/bluetooth/IBluetoothGatt.aidl
+++ b/core/java/android/bluetooth/IBluetoothGatt.aidl
@@ -20,15 +20,20 @@
import android.bluetooth.BluetoothGattService;
import android.bluetooth.le.AdvertiseSettings;
import android.bluetooth.le.AdvertiseData;
+import android.bluetooth.le.AdvertisingSetParameters;
+import android.bluetooth.le.PeriodicAdvertisingParameters;
import android.bluetooth.le.ScanFilter;
+import android.bluetooth.le.ScanResult;
import android.bluetooth.le.ScanSettings;
import android.bluetooth.le.ResultStorageDescriptor;
import android.os.ParcelUuid;
import android.os.WorkSource;
-import android.bluetooth.IBluetoothGattCallback;
-import android.bluetooth.IBluetoothGattServerCallback;
+import android.bluetooth.IBluetoothGattCallbackExt;
+import android.bluetooth.IBluetoothGattServerCallbackExt;
import android.bluetooth.le.IAdvertiserCallback;
+import android.bluetooth.le.IAdvertisingSetCallback;
+import android.bluetooth.le.IPeriodicAdvertisingCallback;
import android.bluetooth.le.IScannerCallback;
/**
@@ -53,10 +58,29 @@
in AdvertiseSettings settings);
void stopMultiAdvertising(in int advertiserId);
- void registerClient(in ParcelUuid appId, in IBluetoothGattCallback callback);
+ void startAdvertisingSet(in AdvertisingSetParameters parameters, in AdvertiseData advertiseData,
+ in AdvertiseData scanResponse, in PeriodicAdvertisingParameters periodicParameters,
+ in AdvertiseData periodicData, in IAdvertisingSetCallback callback);
+ void stopAdvertisingSet(in IAdvertisingSetCallback callback);
+
+ void enableAdverisingSet(in int advertiserId, in boolean enable);
+ void setAdvertisingData(in int advertiserId, in AdvertiseData data);
+ void setScanResponseData(in int advertiserId, in AdvertiseData data);
+ void setAdvertisingParameters(in int advertiserId, in AdvertisingSetParameters parameters);
+ void setPeriodicAdvertisingParameters(in int advertiserId, in PeriodicAdvertisingParameters parameters);
+ void setPeriodicAdvertisingData(in int advertiserId, in AdvertiseData data);
+ void periodicAdvertisingEnable(in int advertiserId, in boolean enable);
+
+ void registerSync(in ScanResult scanResult, in int skip, in int timeout, in IPeriodicAdvertisingCallback callback);
+ void unregisterSync(in IPeriodicAdvertisingCallback callback);
+
+ void registerClient(in ParcelUuid appId, in IBluetoothGattCallbackExt callback);
+
void unregisterClient(in int clientIf);
- void clientConnect(in int clientIf, in String address, in boolean isDirect, in int transport);
+ void clientConnect(in int clientIf, in String address, in boolean isDirect, in int transport, in int phy);
void clientDisconnect(in int clientIf, in String address);
+ void clientSetPreferredPhy(in int clientIf, in String address, in int txPhy, in int rxPhy, in int phyOptions);
+ void clientReadPhy(in int clientIf, in String address);
void refreshDevice(in int clientIf, in String address);
void discoverServices(in int clientIf, in String address);
void readCharacteristic(in int clientIf, in String address, in int handle, in int authReq);
@@ -72,10 +96,12 @@
void configureMTU(in int clientIf, in String address, in int mtu);
void connectionParameterUpdate(in int clientIf, in String address, in int connectionPriority);
- void registerServer(in ParcelUuid appId, in IBluetoothGattServerCallback callback);
+ void registerServer(in ParcelUuid appId, in IBluetoothGattServerCallbackExt callback);
void unregisterServer(in int serverIf);
void serverConnect(in int serverIf, in String address, in boolean isDirect, in int transport);
void serverDisconnect(in int serverIf, in String address);
+ void serverSetPreferredPhy(in int clientIf, in String address, in int txPhy, in int rxPhy, in int phyOptions);
+ void serverReadPhy(in int clientIf, in String address);
void addService(in int serverIf, in BluetoothGattService service);
void removeService(in int serverIf, in int handle);
void clearServices(in int serverIf);
diff --git a/core/java/android/bluetooth/IBluetoothGattCallback.aidl b/core/java/android/bluetooth/IBluetoothGattCallbackExt.aidl
similarity index 88%
rename from core/java/android/bluetooth/IBluetoothGattCallback.aidl
rename to core/java/android/bluetooth/IBluetoothGattCallbackExt.aidl
index 72cb618..736f4b2 100644
--- a/core/java/android/bluetooth/IBluetoothGattCallback.aidl
+++ b/core/java/android/bluetooth/IBluetoothGattCallbackExt.aidl
@@ -22,10 +22,12 @@
* Callback definitions for interacting with BLE / GATT
* @hide
*/
-oneway interface IBluetoothGattCallback {
+oneway interface IBluetoothGattCallbackExt {
void onClientRegistered(in int status, in int clientIf);
void onClientConnectionState(in int status, in int clientIf,
in boolean connected, in String address);
+ void onPhyUpdate(in String address, in int txPhy, in int rxPhy, in int status);
+ void onPhyRead(in String address, in int txPhy, in int rxPhy, in int status);
void onSearchComplete(in String address, in List<BluetoothGattService> services, in int status);
void onCharacteristicRead(in String address, in int status, in int handle, in byte[] value);
void onCharacteristicWrite(in String address, in int status, in int handle);
diff --git a/core/java/android/bluetooth/IBluetoothGattServerCallback.aidl b/core/java/android/bluetooth/IBluetoothGattServerCallbackExt.aidl
similarity index 87%
rename from core/java/android/bluetooth/IBluetoothGattServerCallback.aidl
rename to core/java/android/bluetooth/IBluetoothGattServerCallbackExt.aidl
index 1a924fb..091ffb3 100644
--- a/core/java/android/bluetooth/IBluetoothGattServerCallback.aidl
+++ b/core/java/android/bluetooth/IBluetoothGattServerCallbackExt.aidl
@@ -1,5 +1,5 @@
/*
- * Copyright (C) 2013 The Android Open Source Project
+ * Copyright (C) 2017 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -21,7 +21,7 @@
* Callback definitions for interacting with BLE / GATT
* @hide
*/
-oneway interface IBluetoothGattServerCallback {
+oneway interface IBluetoothGattServerCallbackExt {
void onServerRegistered(in int status, in int serverIf);
void onServerConnectionState(in int status, in int serverIf,
in boolean connected, in String address);
@@ -40,4 +40,6 @@
void onExecuteWrite(in String address, in int transId, in boolean execWrite);
void onNotificationSent(in String address, in int status);
void onMtuChanged(in String address, in int mtu);
+ void onPhyUpdate(in String address, in int txPhy, in int rxPhy, in int status);
+ void onPhyRead(in String address, in int txPhy, in int rxPhy, in int status);
}
diff --git a/core/java/android/bluetooth/le/AdvertisingSet.java b/core/java/android/bluetooth/le/AdvertisingSet.java
new file mode 100644
index 0000000..1524022
--- /dev/null
+++ b/core/java/android/bluetooth/le/AdvertisingSet.java
@@ -0,0 +1,162 @@
+/*
+ * Copyright (C) 2017 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package android.bluetooth.le;
+
+import android.bluetooth.IBluetoothGatt;
+import android.bluetooth.IBluetoothManager;
+import android.bluetooth.le.IAdvertisingSetCallback;
+import android.os.RemoteException;
+import android.util.Log;
+
+/**
+ * This class provides a way to control single Bluetooth LE advertising instance.
+ * <p>
+ * To get an instance of {@link AdvertisingSet}, call the
+ * {@link BluetoothLeAdvertiser#startAdvertisingSet} method.
+ * <p>
+ * <b>Note:</b> Most of the methods here require {@link android.Manifest.permission#BLUETOOTH_ADMIN}
+ * permission.
+ *
+ * @see AdvertiseData
+ */
+public final class AdvertisingSet {
+ private static final String TAG = "AdvertisingSet";
+
+ private final IBluetoothGatt gatt;
+ private int advertiserId;
+
+ /* package */ AdvertisingSet(int advertiserId,
+ IBluetoothManager bluetoothManager) {
+ this.advertiserId = advertiserId;
+
+ try {
+ this.gatt = bluetoothManager.getBluetoothGatt();
+ } catch (RemoteException e) {
+ Log.e(TAG, "Failed to get Bluetooth gatt - ", e);
+ throw new IllegalStateException("Failed to get Bluetooth");
+ }
+ }
+
+ /* package */ void setAdvertiserId(int advertiserId) {
+ this.advertiserId = advertiserId;
+ }
+
+ /**
+ * Enables Advertising. This method returns immediately, the operation status is
+ * delivered
+ * through {@code callback.onAdvertisingEnabled()}.
+ * <p>
+ * Requires {@link android.Manifest.permission#BLUETOOTH_ADMIN}
+ *
+ */
+ public void enableAdvertising(boolean enable) {
+ try {
+ gatt.enableAdverisingSet(this.advertiserId, enable);
+ } catch (RemoteException e) {
+ Log.e(TAG, "remote exception - ", e);
+ }
+ }
+
+ /**
+ * Set/update data being Advertised. Make sure that data doesn't exceed the size limit for
+ * specified AdvertisingSetParameters. This method returns immediately, the operation status is
+ * delivered through {@code callback.onAdvertisingDataSet()}.
+ * <p>
+ * Advertising data must be empty if non-legacy scannable advertising is used.
+ */
+ public void setAdvertisingData(AdvertiseData data) {
+ try {
+ gatt.setAdvertisingData(this.advertiserId, data);
+ } catch (RemoteException e) {
+ Log.e(TAG, "remote exception - ", e);
+ }
+ }
+
+ /**
+ * Set/update scan response data. Make sure that data doesn't exceed the size limit for
+ * specified AdvertisingSetParameters. This method returns immediately, the operation status
+ * is delivered through {@code callback.onScanResponseDataSet()}.
+ */
+ public void setScanResponseData(AdvertiseData data) {
+ try {
+ gatt.setScanResponseData(this.advertiserId, data);
+ } catch (RemoteException e) {
+ Log.e(TAG, "remote exception - ", e);
+ }
+ }
+
+ /**
+ * Update advertising parameters associated with this AdvertisingSet. Must be called when
+ * advertising is not active. This method returns immediately, the operation status is delivered
+ * through {@code callback.onAdvertisingParametersUpdated}.
+ */
+ public void setAdvertisingParameters(AdvertisingSetParameters parameters) {
+ try {
+ gatt.setAdvertisingParameters(this.advertiserId, parameters);
+ } catch (RemoteException e) {
+ Log.e(TAG, "remote exception - ", e);
+ }
+ }
+
+ /**
+ * Update periodic advertising parameters associated with this set. Must be called when
+ * periodic advertising is not enabled. This method returns immediately, the operation
+ * status is delivered through {@code callback.onPeriodicAdvertisingParametersUpdated()}.
+ */
+ public void setPeriodicAdvertisingParameters(PeriodicAdvertisingParameters parameters) {
+ try {
+ gatt.setPeriodicAdvertisingParameters(this.advertiserId, parameters);
+ } catch (RemoteException e) {
+ Log.e(TAG, "remote exception - ", e);
+ }
+ }
+
+ /**
+ * Used to set periodic advertising data, must be called after setPeriodicAdvertisingParameters,
+ * or after advertising was started with periodic advertising data set. This method returns
+ * immediately, the operation status is delivered through
+ * {@code callback.onPeriodicAdvertisingDataSet()}.
+ */
+ public void setPeriodicAdvertisingData(AdvertiseData data) {
+ try {
+ gatt.setPeriodicAdvertisingData(this.advertiserId, data);
+ } catch (RemoteException e) {
+ Log.e(TAG, "remote exception - ", e);
+ }
+ }
+
+ /**
+ * Used to enable/disable periodic advertising. This method returns immediately, the operation
+ * status is delivered through {@code callback.onPeriodicAdvertisingEnable()}.
+ */
+ public void periodicAdvertisingEnable(boolean enable) {
+ try {
+ gatt.periodicAdvertisingEnable(this.advertiserId, enable);
+ } catch (RemoteException e) {
+ Log.e(TAG, "remote exception - ", e);
+ }
+ }
+
+ /**
+ * Returns advertiserId associated with thsi advertising set.
+ *
+ * @hide
+ */
+ public int getAdvertiserId(){
+ return advertiserId;
+ }
+}
\ No newline at end of file
diff --git a/core/java/android/bluetooth/le/AdvertisingSetCallback.java b/core/java/android/bluetooth/le/AdvertisingSetCallback.java
new file mode 100644
index 0000000..ceed8d9
--- /dev/null
+++ b/core/java/android/bluetooth/le/AdvertisingSetCallback.java
@@ -0,0 +1,144 @@
+/*
+ * Copyright (C) 2017 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package android.bluetooth.le;
+
+import android.bluetooth.BluetoothDevice;
+
+/**
+ * Bluetooth LE advertising set callbacks, used to deliver advertising operation
+ * status.
+ */
+public abstract class AdvertisingSetCallback {
+
+ /**
+ * The requested operation was successful.
+ */
+ public static final int ADVERTISE_SUCCESS = 0;
+
+ /**
+ * Failed to start advertising as the advertise data to be broadcasted is too
+ * large.
+ */
+ public static final int ADVERTISE_FAILED_DATA_TOO_LARGE = 1;
+
+ /**
+ * Failed to start advertising because no advertising instance is available.
+ */
+ public static final int ADVERTISE_FAILED_TOO_MANY_ADVERTISERS = 2;
+
+ /**
+ * Failed to start advertising as the advertising is already started.
+ */
+ public static final int ADVERTISE_FAILED_ALREADY_STARTED = 3;
+
+ /**
+ * Operation failed due to an internal error.
+ */
+ public static final int ADVERTISE_FAILED_INTERNAL_ERROR = 4;
+
+ /**
+ * This feature is not supported on this platform.
+ */
+ public static final int ADVERTISE_FAILED_FEATURE_UNSUPPORTED = 5;
+
+ /**
+ * Callback triggered in response to {@link BluetoothLeAdvertiser#startAdvertisingSet}
+ * indicating result of the operation. If status is ADVERTISE_SUCCESS, then advertisingSet
+ * contains the started set and it is advertising. If error occured, advertisingSet is
+ * null, and status will be set to proper error code.
+ *
+ * @param advertisingSet The advertising set that was started or null if error.
+ * @param status Status of the operation.
+ */
+ public void onAdvertisingSetStarted(AdvertisingSet advertisingSet, int status) {}
+
+ /**
+ * Callback triggered in response to {@link BluetoothLeAdvertiser#stopAdvertisingSet}
+ * indicating advertising set is stopped.
+ *
+ * @param advertisingSet The advertising set.
+ */
+ public void onAdvertisingSetStopped(AdvertisingSet advertisingSet) {}
+
+ /**
+ * Callback triggered in response to {@link BluetoothLeAdvertiser#startAdvertisingSet} indicating
+ * result of the operation. If status is ADVERTISE_SUCCESS, then advertising set is advertising.
+ *
+ * @param advertisingSet The advertising set.
+ * @param status Status of the operation.
+ */
+ public void onAdvertisingEnabled(AdvertisingSet advertisingSet, boolean enable, int status) {}
+
+ /**
+ * Callback triggered in response to {@link AdvertisingSet#setAdvertisingData} indicating
+ * result of the operation. If status is ADVERTISE_SUCCESS, then data was changed.
+ *
+ * @param advertisingSet The advertising set.
+ * @param status Status of the operation.
+ */
+ public void onAdvertisingDataSet(AdvertisingSet advertisingSet, int status) {}
+
+ /**
+ * Callback triggered in response to {@link AdvertisingSet#setAdvertisingData} indicating
+ * result of the operation.
+ *
+ * @param advertisingSet The advertising set.
+ * @param status Status of the operation.
+ */
+ public void onScanResponseDataSet(AdvertisingSet advertisingSet, int status) {}
+
+ /**
+ * Callback triggered in response to {@link AdvertisingSet#setAdvertisingParameters}
+ * indicating result of the operation.
+ *
+ * @param advertisingSet The advertising set.
+ * @param status Status of the operation.
+ */
+ public void onAdvertisingParametersUpdated(AdvertisingSet advertisingSet,
+ int status) {}
+
+ /**
+ * Callback triggered in response to {@link AdvertisingSet#setPeriodicAdvertisingParameters}
+ * indicating result of the operation.
+ *
+ * @param advertisingSet The advertising set.
+ * @param status Status of the operation.
+ */
+ public void
+ onPeriodicAdvertisingParametersUpdated(AdvertisingSet advertisingSet,
+ int status) {}
+
+ /**
+ * Callback triggered in response to {@link AdvertisingSet#setPeriodicAdvertisingData}
+ * indicating result of the operation.
+ *
+ * @param advertisingSet The advertising set.
+ * @param status Status of the operation.
+ */
+ public void onPeriodicAdvertisingDataSet(AdvertisingSet advertisingSet,
+ int status) {}
+
+ /**
+ * Callback triggered in response to {@link AdvertisingSet#periodicAdvertisingEnable}
+ * indicating result of the operation.
+ *
+ * @param advertisingSet The advertising set.
+ * @param status Status of the operation.
+ */
+ public void onPeriodicAdvertisingEnable(AdvertisingSet advertisingSet, boolean enable,
+ int status) {}
+}
\ No newline at end of file
diff --git a/core/java/android/bluetooth/le/AdvertisingSetParameters.aidl b/core/java/android/bluetooth/le/AdvertisingSetParameters.aidl
new file mode 100644
index 0000000..39034a0
--- /dev/null
+++ b/core/java/android/bluetooth/le/AdvertisingSetParameters.aidl
@@ -0,0 +1,19 @@
+/*
+ * Copyright (C) 2017 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package android.bluetooth.le;
+
+parcelable AdvertisingSetParameters;
diff --git a/core/java/android/bluetooth/le/AdvertisingSetParameters.java b/core/java/android/bluetooth/le/AdvertisingSetParameters.java
new file mode 100644
index 0000000..03a01e1
--- /dev/null
+++ b/core/java/android/bluetooth/le/AdvertisingSetParameters.java
@@ -0,0 +1,409 @@
+/*
+ * Copyright (C) 2017 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package android.bluetooth.le;
+
+import android.os.Parcel;
+import android.os.Parcelable;
+
+/**
+ * The {@link AdvertisingSetParameters} provide a way to adjust advertising
+ * preferences for each
+ * Bluetooth LE advertising set. Use {@link AdvertisingSetParameters.Builder} to
+ * create an
+ * instance of this class.
+ */
+public final class AdvertisingSetParameters implements Parcelable {
+
+ /**
+ * 1M advertiser PHY.
+ */
+ public static final int PHY_LE_1M = 1;
+
+ /**
+ * 2M advertiser PHY.
+ */
+ public static final int PHY_LE_2M = 2;
+
+ /**
+ * LE Coded advertiser PHY.
+ */
+ public static final int PHY_LE_CODED = 3;
+
+ /**
+ * Advertise on low frequency, around every 1000ms. This is the default and
+ * preferred advertising mode as it consumes the least power.
+ */
+ public static final int INTERVAL_LOW = 1600;
+
+ /**
+ * Advertise on medium frequency, around every 250ms. This is balanced
+ * between advertising frequency and power consumption.
+ */
+ public static final int INTERVAL_MEDIUM = 400;
+
+ /**
+ * Perform high frequency, low latency advertising, around every 100ms. This
+ * has the highest power consumption and should not be used for continuous
+ * background advertising.
+ */
+ public static final int INTERVAL_HIGH = 160;
+
+ /**
+ * Minimum value for advertising interval.
+ */
+ public static final int INTERVAL_MIN = 160;
+
+ /**
+ * Maximum value for advertising interval.
+ */
+ public static final int INTERVAL_MAX = 16777215;
+
+ /**
+ * Advertise using the lowest transmission (TX) power level. Low transmission
+ * power can be used to restrict the visibility range of advertising packets.
+ */
+ public static final int TX_POWER_ULTRA_LOW = -21;
+
+ /**
+ * Advertise using low TX power level.
+ */
+ public static final int TX_POWER_LOW = -15;
+
+ /**
+ * Advertise using medium TX power level.
+ */
+ public static final int TX_POWER_MEDIUM = -7;
+
+ /**
+ * Advertise using high TX power level. This corresponds to largest visibility
+ * range of the advertising packet.
+ */
+ public static final int TX_POWER_HIGH = 1;
+
+ /**
+ * Minimum value for TX power.
+ */
+ public static final int TX_POWER_MIN = -127;
+
+ /**
+ * Maximum value for TX power.
+ */
+ public static final int TX_POWER_MAX = 1;
+
+ /**
+ * The maximum limited advertisement duration as specified by the Bluetooth
+ * SIG
+ */
+ private static final int LIMITED_ADVERTISING_MAX_MILLIS = 180 * 1000;
+
+ private final boolean isLegacy;
+ private final boolean isAnonymous;
+ private final boolean includeTxPower;
+ private final int primaryPhy;
+ private final int secondaryPhy;
+ private final boolean connectable;
+ private final int interval;
+ private final int txPowerLevel;
+ private final int timeoutMillis;
+
+ private AdvertisingSetParameters(boolean connectable, boolean isLegacy,
+ boolean isAnonymous, boolean includeTxPower,
+ int primaryPhy, int secondaryPhy,
+ int interval, int txPowerLevel,
+ int timeoutMillis) {
+ this.connectable = connectable;
+ this.isLegacy = isLegacy;
+ this.isAnonymous = isAnonymous;
+ this.includeTxPower = includeTxPower;
+ this.primaryPhy = primaryPhy;
+ this.secondaryPhy = secondaryPhy;
+ this.interval = interval;
+ this.txPowerLevel = txPowerLevel;
+ this.timeoutMillis = timeoutMillis;
+ }
+
+ private AdvertisingSetParameters(Parcel in) {
+ connectable = in.readInt() != 0 ? true : false;
+ isLegacy = in.readInt() != 0 ? true : false;
+ isAnonymous = in.readInt() != 0 ? true : false;
+ includeTxPower = in.readInt() != 0 ? true : false;
+ primaryPhy = in.readInt();
+ secondaryPhy = in.readInt();
+ interval = in.readInt();
+ txPowerLevel = in.readInt();
+ timeoutMillis = in.readInt();
+ }
+
+ /**
+ * Returns whether the advertisement will be connectable.
+ */
+ public boolean isConnectable() { return connectable; }
+
+ /**
+ * Returns whether the legacy advertisement will be used.
+ */
+ public boolean isLegacy() { return isLegacy; }
+
+ /**
+ * Returns whether the advertisement will be anonymous.
+ */
+ public boolean isAnonymous() { return isAnonymous; }
+
+ /**
+ * Returns whether the TX Power will be included.
+ */
+ public boolean includeTxPower() { return includeTxPower; }
+
+ /**
+ * Returns the primary advertising phy.
+ */
+ public int getPrimaryPhy() { return primaryPhy; }
+
+ /**
+ * Returns the secondary advertising phy.
+ */
+ public int getSecondaryPhy() { return secondaryPhy; }
+
+ /**
+ * Returns the advertising interval.
+ */
+ public int getInterval() { return interval; }
+
+ /**
+ * Returns the TX power level for advertising.
+ */
+ public int getTxPowerLevel() { return txPowerLevel; }
+
+ /**
+ * Returns the advertising time limit in milliseconds.
+ */
+ public int getTimeout() { return timeoutMillis; }
+
+ @Override
+ public String toString() {
+ return "AdvertisingSetParameters [connectable=" + connectable
+ + ", isLegacy=" + isLegacy
+ + ", isAnonymous=" + isAnonymous
+ + ", includeTxPower=" + includeTxPower
+ + ", primaryPhy=" + primaryPhy
+ + ", secondaryPhy=" + secondaryPhy
+ + ", interval=" + interval
+ + ", txPowerLevel=" + txPowerLevel
+ + ", timeoutMillis=" + timeoutMillis + "]";
+ }
+
+ @Override
+ public int describeContents() {
+ return 0;
+ }
+
+ @Override
+ public void writeToParcel(Parcel dest, int flags) {
+ dest.writeInt(connectable ? 1 : 0);
+ dest.writeInt(isLegacy ? 1 : 0);
+ dest.writeInt(isAnonymous ? 1 : 0);
+ dest.writeInt(includeTxPower ? 1 : 0);
+ dest.writeInt(primaryPhy);
+ dest.writeInt(secondaryPhy);
+ dest.writeInt(interval);
+ dest.writeInt(txPowerLevel);
+ dest.writeInt(timeoutMillis);
+ }
+
+ public static final Parcelable.Creator<AdvertisingSetParameters> CREATOR =
+ new Creator<AdvertisingSetParameters>() {
+ @Override
+ public AdvertisingSetParameters[] newArray(int size) {
+ return new AdvertisingSetParameters[size];
+ }
+
+ @Override
+ public AdvertisingSetParameters createFromParcel(Parcel in) {
+ return new AdvertisingSetParameters(in);
+ }
+ };
+
+ /**
+ * Builder class for {@link AdvertisingSetParameters}.
+ */
+ public static final class Builder {
+
+ private boolean connectable = true;
+ private boolean isLegacy = false;
+ private boolean isAnonymous = false;
+ private boolean includeTxPower = false;
+ private int primaryPhy = PHY_LE_1M;
+ private int secondaryPhy = PHY_LE_1M;
+ private int interval = INTERVAL_LOW;
+ private int txPowerLevel = TX_POWER_MEDIUM;
+ private int timeoutMillis = 0;
+
+ /**
+ * Set whether the advertisement type should be connectable or
+ * non-connectable.
+ * Legacy advertisements can be both connectable and scannable. Other
+ * advertisements can be connectable only if not scannable.
+ * @param connectable Controls whether the advertisment type will be
+ * connectable (true) or non-connectable (false).
+ */
+ public Builder setConnectable(boolean connectable) {
+ this.connectable = connectable;
+ return this;
+ }
+
+ /**
+ * When set to true, advertising set will advertise 4.x Spec compliant
+ * advertisements.
+ *
+ * @param isLegacy wether legacy advertising mode should be used.
+ */
+ public Builder setLegacyMode(boolean isLegacy) {
+ this.isLegacy = isLegacy;
+ return this;
+ }
+
+ /**
+ * Set wether advertiser address should be ommited from all packets. If this
+ * mode is used, periodic advertising can't be enabled for this set.
+ *
+ * This is used only if legacy mode is not used.
+ *
+ * @param isAnonymous wether anonymous advertising should be used.
+ */
+ public Builder setAnonymouus(boolean isAnonymous) {
+ this.isAnonymous = isAnonymous;
+ return this;
+ }
+
+ /**
+ * Set wether TX power should be included in the extended header.
+ *
+ * This is used only if legacy mode is not used.
+ *
+ * @param includeTxPower wether TX power should be included in extended
+ * header
+ */
+ public Builder setIncludeTxPower(boolean includeTxPower) {
+ this.includeTxPower = includeTxPower;
+ return this;
+ }
+
+ /**
+ * Set the primary physical channel used for this advertising set.
+ *
+ * This is used only if legacy mode is not used.
+ *
+ * @param primaryPhy Primary advertising physical channel, can only be
+ * {@link AdvertisingSetParameters#PHY_LE_1M} or
+ * {@link AdvertisingSetParameters#PHY_LE_CODED}.
+ * @throws IllegalArgumentException If the primaryPhy is invalid.
+ */
+ public Builder setPrimaryPhy(int primaryPhy) {
+ if (primaryPhy != PHY_LE_1M && primaryPhy != PHY_LE_CODED) {
+ throw new IllegalArgumentException("bad primaryPhy " + primaryPhy);
+ }
+ this.primaryPhy = primaryPhy;
+ return this;
+ }
+
+ /**
+ * Set the secondary physical channel used for this advertising set.
+ *
+ * This is used only if legacy mode is not used.
+ *
+ * @param secondaryPhy Secondary advertising physical channel, can only be
+ * one of {@link AdvertisingSetParameters#PHY_LE_1M},
+ * {@link AdvertisingSetParameters#PHY_LE_2M} or
+ * {@link AdvertisingSetParameters#PHY_LE_CODED}.
+ * @throws IllegalArgumentException If the secondaryPhy is invalid.
+ */
+ public Builder setSecondaryPhy(int secondaryPhy) {
+ if (secondaryPhy != PHY_LE_1M && secondaryPhy !=PHY_LE_2M &&
+ secondaryPhy != PHY_LE_CODED) {
+ throw new IllegalArgumentException("bad secondaryPhy " + secondaryPhy);
+ }
+ this.secondaryPhy = secondaryPhy;
+ return this;
+ }
+
+ /**
+ * Set advertising interval.
+ *
+ * @param interval Bluetooth LE Advertising interval, in 0.625ms unit. Valid
+ * range is from 160 (100ms) to 16777215 (10,485.759375 s).
+ * Recommended values are:
+ * {@link AdvertisingSetParameters#INTERVAL_LOW},
+ * {@link AdvertisingSetParameters#INTERVAL_MEDIUM}, or
+ * {@link AdvertisingSetParameters#INTERVAL_HIGH}.
+ * @throws IllegalArgumentException If the interval is invalid.
+ */
+ public Builder setInterval(int interval) {
+ if (interval < INTERVAL_MIN || interval > INTERVAL_MAX) {
+ throw new IllegalArgumentException("unknown interval " + interval);
+ }
+ this.interval = interval;
+ return this;
+ }
+
+ /**
+ * Set the transmission power level for the advertising.
+ * @param txPowerLevel Transmission power of Bluetooth LE Advertising, in
+ * dBm. The valid range is [-127, 1] Recommended values are:
+ * {@link AdvertisingSetParameters#TX_POWER_ULTRA_LOW},
+ * {@link AdvertisingSetParameters#TX_POWER_LOW},
+ * {@link AdvertisingSetParameters#TX_POWER_MEDIUM}, or
+ * {@link AdvertisingSetParameters#TX_POWER_HIGH}.
+ *
+ * @throws IllegalArgumentException If the {@code txPowerLevel} is invalid.
+ */
+ public Builder setTxPowerLevel(int txPowerLevel) {
+ if (txPowerLevel < TX_POWER_MIN || txPowerLevel > TX_POWER_MAX) {
+ throw new IllegalArgumentException("unknown txPowerLevel " +
+ txPowerLevel);
+ }
+ this.txPowerLevel = txPowerLevel;
+ return this;
+ }
+
+ /**
+ * Limit advertising to a given amount of time.
+ * @param timeoutMillis Advertising time limit. May not exceed 180000
+ * milliseconds. A value of 0 will disable the time limit.
+ * @throws IllegalArgumentException If the provided timeout is over 180000
+ * ms.
+ */
+ public Builder setTimeout(int timeoutMillis) {
+ if (timeoutMillis < 0 || timeoutMillis > LIMITED_ADVERTISING_MAX_MILLIS) {
+ throw new IllegalArgumentException("timeoutMillis invalid (must be 0-" +
+ LIMITED_ADVERTISING_MAX_MILLIS +
+ " milliseconds)");
+ }
+ this.timeoutMillis = timeoutMillis;
+ return this;
+ }
+
+ /**
+ * Build the {@link AdvertisingSetParameters} object.
+ */
+ public AdvertisingSetParameters build() {
+ return new AdvertisingSetParameters(connectable, isLegacy, isAnonymous,
+ includeTxPower, primaryPhy,
+ secondaryPhy, interval, txPowerLevel,
+ timeoutMillis);
+ }
+ }
+}
\ No newline at end of file
diff --git a/core/java/android/bluetooth/le/BluetoothLeAdvertiser.java b/core/java/android/bluetooth/le/BluetoothLeAdvertiser.java
index 94d03e5..e03c947 100644
--- a/core/java/android/bluetooth/le/BluetoothLeAdvertiser.java
+++ b/core/java/android/bluetooth/le/BluetoothLeAdvertiser.java
@@ -62,6 +62,9 @@
private BluetoothAdapter mBluetoothAdapter;
private final Map<AdvertiseCallback, AdvertiseCallbackWrapper>
mLeAdvertisers = new HashMap<AdvertiseCallback, AdvertiseCallbackWrapper>();
+ private final Map<AdvertisingSetCallback, IAdvertisingSetCallback>
+ advertisingSetCallbackWrappers = new HashMap<>();
+ private final Map<Integer, AdvertisingSet> advertisingSets = new HashMap<>();
/**
* Use BluetoothAdapter.getLeAdvertiser() instead.
@@ -156,6 +159,93 @@
}
/**
+ * Creates a new advertising set. If operation succeed, device will start advertising. This
+ * method returns immediately, the operation status is delivered through
+ * {@code callback.onNewAdvertisingSet()}.
+ * <p>
+ * @param parameters advertising set parameters.
+ * @param advertiseData Advertisement data to be broadcasted.
+ * @param scanResponse Scan response associated with the advertisement data.
+ * @param periodicData Periodic advertising data.
+ * @param callback Callback for advertising set.
+ */
+ public void startAdvertisingSet(AdvertisingSetParameters parameters,
+ AdvertiseData advertiseData, AdvertiseData scanResponse,
+ PeriodicAdvertisingParameters periodicParameters,
+ AdvertiseData periodicData, AdvertisingSetCallback callback) {
+ startAdvertisingSet(parameters, advertiseData, scanResponse, periodicParameters,
+ periodicData, callback, new Handler(Looper.getMainLooper()));
+ }
+
+ /**
+ * Creates a new advertising set. If operation succeed, device will start advertising. This
+ * method returns immediately, the operation status is delivered through
+ * {@code callback.onNewAdvertisingSet()}.
+ * <p>
+ * @param parameters advertising set parameters.
+ * @param advertiseData Advertisement data to be broadcasted.
+ * @param scanResponse Scan response associated with the advertisement data.
+ * @param periodicData Periodic advertising data.
+ * @param callback Callback for advertising set.
+ * @param handler thread upon which the callbacks will be invoked.
+ */
+ public void startAdvertisingSet(AdvertisingSetParameters parameters,
+ AdvertiseData advertiseData, AdvertiseData scanResponse,
+ PeriodicAdvertisingParameters periodicParameters,
+ AdvertiseData periodicData, AdvertisingSetCallback callback,
+ Handler handler) {
+ BluetoothLeUtils.checkAdapterStateOn(mBluetoothAdapter);
+
+ if (callback == null) {
+ throw new IllegalArgumentException("callback cannot be null");
+ }
+
+ IBluetoothGatt gatt;
+ try {
+ gatt = mBluetoothManager.getBluetoothGatt();
+ } catch (RemoteException e) {
+ Log.e(TAG, "Failed to get Bluetooth gatt - ", e);
+ throw new IllegalStateException("Failed to get Bluetooth");
+ }
+
+ IAdvertisingSetCallback wrapped = wrap(callback, handler);
+ advertisingSetCallbackWrappers.put(callback, wrapped);
+
+ try {
+ gatt.startAdvertisingSet(parameters, advertiseData, scanResponse, periodicParameters,
+ periodicData, wrapped);
+ } catch (RemoteException e) {
+ Log.e(TAG, "Failed to start advertising set - ", e);
+ throw new IllegalStateException("Failed to start advertising set");
+ }
+ }
+
+ /**
+ * Used to dispose of a {@link AdvertisingSet} object, obtained with {@link
+ * BluetoothLeAdvertiser#startAdvertisingSet}.
+ */
+ public void stopAdvertisingSet(AdvertisingSetCallback callback) {
+ if (callback == null) {
+ throw new IllegalArgumentException("callback cannot be null");
+ }
+
+ IAdvertisingSetCallback wrapped = advertisingSetCallbackWrappers.remove(callback);
+ if (wrapped == null) {
+ throw new IllegalArgumentException(
+ "callback does not represent valid registered callback.");
+ }
+
+ IBluetoothGatt gatt;
+ try {
+ gatt = mBluetoothManager.getBluetoothGatt();
+ gatt.stopAdvertisingSet(wrapped);
+ } catch (RemoteException e) {
+ Log.e(TAG, "Failed to stop advertising - ", e);
+ throw new IllegalStateException("Failed to stop advertising");
+ }
+ }
+
+ /**
* Cleans up advertisers. Should be called when bluetooth is down.
*
* @hide
@@ -219,6 +309,110 @@
return array == null ? 0 : array.length;
}
+ IAdvertisingSetCallback wrap(AdvertisingSetCallback callback, Handler handler) {
+ return new IAdvertisingSetCallback.Stub() {
+ public void onAdvertisingSetStarted(int advertiserId, int status) {
+ handler.post(new Runnable() {
+ @Override
+ public void run() {
+ if (status != AdvertisingSetCallback.ADVERTISE_SUCCESS) {
+ callback.onAdvertisingSetStarted(null, status);
+ advertisingSetCallbackWrappers.remove(callback);
+ return;
+ }
+
+ AdvertisingSet advertisingSet =
+ new AdvertisingSet(advertiserId, mBluetoothManager);
+ advertisingSets.put(advertiserId, advertisingSet);
+ callback.onAdvertisingSetStarted(advertisingSet, status);
+ }
+ });
+ }
+
+ public void onAdvertisingSetStopped(int advertiserId) {
+ handler.post(new Runnable() {
+ @Override
+ public void run() {
+ AdvertisingSet advertisingSet = advertisingSets.get(advertiserId);
+ callback.onAdvertisingSetStopped(advertisingSet);
+ advertisingSets.remove(advertiserId);
+ advertisingSetCallbackWrappers.remove(callback);
+ }
+ });
+ }
+
+ public void onAdvertisingEnabled(int advertiserId, boolean enabled, int status) {
+ handler.post(new Runnable() {
+ @Override
+ public void run() {
+ AdvertisingSet advertisingSet = advertisingSets.get(advertiserId);
+ callback.onAdvertisingEnabled(advertisingSet, enabled, status);
+ }
+ });
+ }
+
+ public void onAdvertisingDataSet(int advertiserId, int status) {
+ handler.post(new Runnable() {
+ @Override
+ public void run() {
+ AdvertisingSet advertisingSet = advertisingSets.get(advertiserId);
+ callback.onAdvertisingDataSet(advertisingSet, status);
+ }
+ });
+ }
+
+ public void onScanResponseDataSet(int advertiserId, int status) {
+ handler.post(new Runnable() {
+ @Override
+ public void run() {
+ AdvertisingSet advertisingSet = advertisingSets.get(advertiserId);
+ callback.onScanResponseDataSet(advertisingSet, status);
+ }
+ });
+ }
+
+ public void onAdvertisingParametersUpdated(int advertiserId, int status) {
+ handler.post(new Runnable() {
+ @Override
+ public void run() {
+ AdvertisingSet advertisingSet = advertisingSets.get(advertiserId);
+ callback.onAdvertisingParametersUpdated(advertisingSet, status);
+ }
+ });
+ }
+
+ public void onPeriodicAdvertisingParametersUpdated(int advertiserId, int status) {
+ handler.post(new Runnable() {
+ @Override
+ public void run() {
+ AdvertisingSet advertisingSet = advertisingSets.get(advertiserId);
+ callback.onPeriodicAdvertisingParametersUpdated(advertisingSet, status);
+ }
+ });
+ }
+
+ public void onPeriodicAdvertisingDataSet(int advertiserId, int status) {
+ handler.post(new Runnable() {
+ @Override
+ public void run() {
+ AdvertisingSet advertisingSet = advertisingSets.get(advertiserId);
+ callback.onPeriodicAdvertisingDataSet(advertisingSet, status);
+ }
+ });
+ }
+
+ public void onPeriodicAdvertisingEnable(int advertiserId, boolean enable, int status) {
+ handler.post(new Runnable() {
+ @Override
+ public void run() {
+ AdvertisingSet advertisingSet = advertisingSets.get(advertiserId);
+ callback.onPeriodicAdvertisingEnable(advertisingSet, enable, status);
+ }
+ });
+ }
+ };
+ }
+
/**
* Bluetooth GATT interface callbacks for advertising.
*/
diff --git a/core/java/android/bluetooth/le/IAdvertisingSetCallback.aidl b/core/java/android/bluetooth/le/IAdvertisingSetCallback.aidl
new file mode 100644
index 0000000..4b0a111
--- /dev/null
+++ b/core/java/android/bluetooth/le/IAdvertisingSetCallback.aidl
@@ -0,0 +1,32 @@
+/*
+ * Copyright (C) 2017 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package android.bluetooth.le;
+
+/**
+ * Callback definitions for interacting with Advertiser
+ * @hide
+ */
+oneway interface IAdvertisingSetCallback {
+ void onAdvertisingSetStarted(in int advertiserId, in int status);
+ void onAdvertisingSetStopped(in int advertiserId);
+ void onAdvertisingEnabled(in int advertiserId, in boolean enable, in int status);
+ void onAdvertisingDataSet(in int advertiserId, in int status);
+ void onScanResponseDataSet(in int advertiserId, in int status);
+ void onAdvertisingParametersUpdated(in int advertiserId, in int status);
+ void onPeriodicAdvertisingParametersUpdated(in int advertiserId, in int status);
+ void onPeriodicAdvertisingDataSet(in int advertiserId, in int status);
+ void onPeriodicAdvertisingEnable(in int advertiserId, in boolean enable, in int status);
+}
diff --git a/core/java/android/bluetooth/le/IPeriodicAdvertisingCallback.aidl b/core/java/android/bluetooth/le/IPeriodicAdvertisingCallback.aidl
new file mode 100644
index 0000000..a76c54d
--- /dev/null
+++ b/core/java/android/bluetooth/le/IPeriodicAdvertisingCallback.aidl
@@ -0,0 +1,31 @@
+/*
+ * Copyright (C) 2017 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package android.bluetooth.le;
+
+import android.bluetooth.BluetoothDevice;
+import android.bluetooth.le.PeriodicAdvertisingReport;
+
+/**
+ * Callback definitions for interacting with Periodic Advertising
+ * @hide
+ */
+oneway interface IPeriodicAdvertisingCallback {
+
+ void onSyncEstablished(in int syncHandle, in BluetoothDevice device, in int advertisingSid,
+ in int skip, in int timeout, in int status);
+ void onPeriodicAdvertisingReport(in PeriodicAdvertisingReport report);
+ void onSyncLost(in int syncHandle);
+}
diff --git a/core/java/android/bluetooth/le/PeriodicAdvertisingCallback.java b/core/java/android/bluetooth/le/PeriodicAdvertisingCallback.java
new file mode 100644
index 0000000..6616231
--- /dev/null
+++ b/core/java/android/bluetooth/le/PeriodicAdvertisingCallback.java
@@ -0,0 +1,77 @@
+/*
+ * Copyright (C) 2017 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package android.bluetooth.le;
+
+import android.bluetooth.BluetoothDevice;
+
+/**
+ * Bluetooth LE periodic advertising callbacks, used to deliver periodic
+ * advertising operation status.
+ *
+ * @see PeriodicAdvertisingManager#createSync
+ */
+public abstract class PeriodicAdvertisingCallback {
+
+ /**
+ * The requested operation was successful.
+ *
+ * @hide
+ */
+ public static final int SYNC_SUCCESS = 0;
+
+ /**
+ * Sync failed to be established because remote device did not respond.
+ */
+ public static final int SYNC_NO_RESPONSE = 1;
+
+ /**
+ * Sync failed to be established because controller can't support more syncs.
+ */
+ public static final int SYNC_NO_RESOURCES = 2;
+
+
+ /**
+ * Callback when synchronization was established.
+ *
+ * @param syncHandle handle used to identify this synchronization.
+ * @param device remote device.
+ * @param advertisingSid synchronized advertising set id.
+ * @param skip The number of periodic advertising packets that can be skipped
+ * after a successful receive in force. @see PeriodicAdvertisingManager#createSync
+ * @param timeout Synchronization timeout for the periodic advertising in force. One
+ * unit is 10ms. @see PeriodicAdvertisingManager#createSync
+ * @param timeout
+ * @param status operation status.
+ */
+ public void onSyncEstablished(int syncHandle, BluetoothDevice device,
+ int advertisingSid, int skip, int timeout,
+ int status) {}
+
+ /**
+ * Callback when periodic advertising report is received.
+ *
+ * @param report periodic advertising report.
+ */
+ public void onPeriodicAdvertisingReport(PeriodicAdvertisingReport report) {}
+
+ /**
+ * Callback when periodic advertising synchronization was lost.
+ *
+ * @param syncHandle handle used to identify this synchronization.
+ */
+ public void onSyncLost(int syncHandle) {}
+}
diff --git a/core/java/android/bluetooth/le/PeriodicAdvertisingManager.java b/core/java/android/bluetooth/le/PeriodicAdvertisingManager.java
new file mode 100644
index 0000000..12c8a8c
--- /dev/null
+++ b/core/java/android/bluetooth/le/PeriodicAdvertisingManager.java
@@ -0,0 +1,237 @@
+/*
+ * Copyright (C) 2017 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License"); you may not
+ * use this file except in compliance with the License. You may obtain a copy of
+ * the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+ * License for the specific language governing permissions and limitations under
+ * the License.
+ */
+
+package android.bluetooth.le;
+
+import android.bluetooth.BluetoothAdapter;
+import android.bluetooth.BluetoothDevice;
+import android.bluetooth.IBluetoothGatt;
+import android.bluetooth.IBluetoothManager;
+import android.os.Handler;
+import android.os.Looper;
+import android.os.RemoteException;
+import android.util.Log;
+import java.util.IdentityHashMap;
+import java.util.Map;
+
+/**
+ * This class provides methods to perform periodic advertising related
+ * operations. An application can register for periodic advertisements using
+ * {@link PeriodicAdvertisingManager#registerSync}.
+ * <p>
+ * Use {@link BluetoothAdapter#getPeriodicAdvertisingManager()} to get an
+ * instance of {@link PeriodicAdvertisingManager}.
+ * <p>
+ * <b>Note:</b> Most of the methods here require
+ * {@link android.Manifest.permission#BLUETOOTH_ADMIN} permission.
+ */
+public final class PeriodicAdvertisingManager {
+
+ private static final String TAG = "PeriodicAdvertisingManager";
+
+ private static final int SKIP_MIN = 0;
+ private static final int SKIP_MAX = 499;
+ private static final int TIMEOUT_MIN = 10;
+ private static final int TIMEOUT_MAX = 16384;
+
+ private static final int SYNC_STARTING = -1;
+
+ private final IBluetoothManager mBluetoothManager;
+ private BluetoothAdapter mBluetoothAdapter;
+
+ /* maps callback, to callback wrapper and sync handle */
+ Map<PeriodicAdvertisingCallback,
+ IPeriodicAdvertisingCallback /* callbackWrapper */> callbackWrappers;
+
+ /**
+ * Use {@link BluetoothAdapter#getBluetoothLeScanner()} instead.
+ *
+ * @param bluetoothManager BluetoothManager that conducts overall Bluetooth Management.
+ * @hide
+ */
+ public PeriodicAdvertisingManager(IBluetoothManager bluetoothManager) {
+ mBluetoothManager = bluetoothManager;
+ mBluetoothAdapter = BluetoothAdapter.getDefaultAdapter();
+ callbackWrappers = new IdentityHashMap<>();
+ }
+
+ /**
+ * Synchronize with periodic advertising pointed to by the {@code scanResult}.
+ * The {@code scanResult} used must contain a valid advertisingSid. First
+ * call to registerSync will use the {@code skip} and {@code timeout} provided.
+ * Subsequent calls from other apps, trying to sync with same set will reuse
+ * existing sync, thus {@code skip} and {@code timeout} values will not take
+ * effect. The values in effect will be returned in
+ * {@link PeriodicAdvertisingCallback#onSyncEstablished}.
+ *
+ * @param scanResult Scan result containing advertisingSid.
+ * @param skip The number of periodic advertising packets that can be skipped
+ * after a successful receive. Must be between 0 and 499.
+ * @param timeout Synchronization timeout for the periodic advertising. One
+ * unit is 10ms. Must be between 10 (100ms) and 16384 (163.84s).
+ * @param callback Callback used to deliver all operations status.
+ * @throws IllegalArgumentException if {@code scanResult} is null or {@code
+ * skip} is invalid or {@code timeout} is invalid or {@code callback} is null.
+ */
+ public void registerSync(ScanResult scanResult, int skip, int timeout,
+ PeriodicAdvertisingCallback callback) {
+ registerSync(scanResult, skip, timeout, callback, null);
+ }
+
+ /**
+ * Synchronize with periodic advertising pointed to by the {@code scanResult}.
+ * The {@code scanResult} used must contain a valid advertisingSid. First
+ * call to registerSync will use the {@code skip} and {@code timeout} provided.
+ * Subsequent calls from other apps, trying to sync with same set will reuse
+ * existing sync, thus {@code skip} and {@code timeout} values will not take
+ * effect. The values in effect will be returned in
+ * {@link PeriodicAdvertisingCallback#onSyncEstablished}.
+ *
+ * @param scanResult Scan result containing advertisingSid.
+ * @param skip The number of periodic advertising packets that can be skipped
+ * after a successful receive. Must be between 0 and 499.
+ * @param timeout Synchronization timeout for the periodic advertising. One
+ * unit is 10ms. Must be between 10 (100ms) and 16384 (163.84s).
+ * @param callback Callback used to deliver all operations status.
+ * @param handler thread upon which the callbacks will be invoked.
+ * @throws IllegalArgumentException if {@code scanResult} is null or {@code
+ * skip} is invalid or {@code timeout} is invalid or {@code callback} is null.
+ */
+ public void registerSync(ScanResult scanResult, int skip, int timeout,
+ PeriodicAdvertisingCallback callback, Handler handler) {
+ if (callback == null) {
+ throw new IllegalArgumentException("callback can't be null");
+ }
+
+ if (scanResult == null) {
+ throw new IllegalArgumentException("scanResult can't be null");
+ }
+
+ if (scanResult.getAdvertisingSid() == ScanResult.SID_NOT_PRESENT) {
+ throw new IllegalArgumentException("scanResult must contain a valid sid");
+ }
+
+ if (skip < SKIP_MIN || skip > SKIP_MAX) {
+ throw new IllegalArgumentException(
+ "timeout must be between " + TIMEOUT_MIN + " and " + TIMEOUT_MAX);
+ }
+
+ if (timeout < TIMEOUT_MIN || timeout > TIMEOUT_MAX) {
+ throw new IllegalArgumentException(
+ "timeout must be between " + TIMEOUT_MIN + " and " + TIMEOUT_MAX);
+ }
+
+ IBluetoothGatt gatt;
+ try {
+ gatt = mBluetoothManager.getBluetoothGatt();
+ } catch (RemoteException e) {
+ Log.e(TAG, "Failed to get Bluetooth gatt - ", e);
+ callback.onSyncEstablished(0, scanResult.getDevice(), scanResult.getAdvertisingSid(),
+ skip, timeout,
+ PeriodicAdvertisingCallback.SYNC_NO_RESOURCES);
+ return;
+ }
+
+ if (handler == null)
+ handler = new Handler(Looper.getMainLooper());
+
+ IPeriodicAdvertisingCallback wrapped = wrap(callback, handler);
+ callbackWrappers.put(callback, wrapped);
+
+ try {
+ gatt.registerSync(scanResult, skip, timeout, wrapped);
+ } catch (RemoteException e) {
+ Log.e(TAG, "Failed to register sync - ", e);
+ return;
+ }
+ }
+
+ /**
+ * Cancel pending attempt to create sync, or terminate existing sync.
+ *
+ * @param callback Callback used to deliver all operations status.
+ * @throws IllegalArgumentException if {@code callback} is null, or not a properly
+ * registered callback.
+ */
+ public void unregisterSync(PeriodicAdvertisingCallback callback) {
+ if (callback == null) {
+ throw new IllegalArgumentException("callback can't be null");
+ }
+
+ IBluetoothGatt gatt;
+ try {
+ gatt = mBluetoothManager.getBluetoothGatt();
+ } catch (RemoteException e) {
+ Log.e(TAG, "Failed to get Bluetooth gatt - ", e);
+ return;
+ }
+
+ IPeriodicAdvertisingCallback wrapper = callbackWrappers.remove(callback);
+ if (wrapper == null) {
+ throw new IllegalArgumentException("callback was not properly registered");
+ }
+
+ try {
+ gatt.unregisterSync(wrapper);
+ } catch (RemoteException e) {
+ Log.e(TAG, "Failed to cancel sync creation - ", e);
+ return;
+ }
+ }
+
+ private IPeriodicAdvertisingCallback wrap(PeriodicAdvertisingCallback callback, Handler handler) {
+ return new IPeriodicAdvertisingCallback.Stub() {
+ public void onSyncEstablished(int syncHandle, BluetoothDevice device,
+ int advertisingSid, int skip, int timeout, int status) {
+
+ handler.post(new Runnable() {
+ @Override
+ public void run() {
+ callback.onSyncEstablished(syncHandle, device, advertisingSid, skip, timeout,
+ status);
+
+ if (status != PeriodicAdvertisingCallback.SYNC_SUCCESS) {
+ // App can still unregister the sync until notified it failed. Remove callback
+ // after app was notifed.
+ callbackWrappers.remove(callback);
+ }
+ }
+ });
+ }
+
+ public void onPeriodicAdvertisingReport(PeriodicAdvertisingReport report) {
+ handler.post(new Runnable() {
+ @Override
+ public void run() {
+ callback.onPeriodicAdvertisingReport(report);
+ }
+ });
+ }
+
+ public void onSyncLost(int syncHandle) {
+ handler.post(new Runnable() {
+ @Override
+ public void run() {
+ callback.onSyncLost(syncHandle);
+ // App can still unregister the sync until notified it's lost. Remove callback after
+ // app was notifed.
+ callbackWrappers.remove(callback);
+ }
+ });
+ }
+ };
+ }
+}
diff --git a/core/java/android/bluetooth/le/PeriodicAdvertisingParameters.aidl b/core/java/android/bluetooth/le/PeriodicAdvertisingParameters.aidl
new file mode 100644
index 0000000..f4bea22
--- /dev/null
+++ b/core/java/android/bluetooth/le/PeriodicAdvertisingParameters.aidl
@@ -0,0 +1,19 @@
+/*
+ * Copyright (C) 2017 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package android.bluetooth.le;
+
+parcelable PeriodicAdvertisingParameters;
diff --git a/core/java/android/bluetooth/le/PeriodicAdvertisingParameters.java b/core/java/android/bluetooth/le/PeriodicAdvertisingParameters.java
new file mode 100644
index 0000000..ebc92bd
--- /dev/null
+++ b/core/java/android/bluetooth/le/PeriodicAdvertisingParameters.java
@@ -0,0 +1,134 @@
+/*
+ * Copyright (C) 2017 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package android.bluetooth.le;
+
+import android.os.Parcel;
+import android.os.Parcelable;
+
+/**
+ * The {@link PeriodicAdvertisingParameters} provide a way to adjust periodic
+ * advertising preferences for each Bluetooth LE advertising set. Use {@link
+ * AdvertisingSetParameters.Builder} to create an instance of this class.
+ */
+public final class PeriodicAdvertisingParameters implements Parcelable {
+
+ private static final int INTERVAL_MAX = 80;
+ private static final int INTERVAL_MIN = 65519;
+
+ private final boolean enable;
+ private final boolean includeTxPower;
+ private final int interval;
+
+ private PeriodicAdvertisingParameters(boolean enable, boolean includeTxPower, int interval) {
+ this.enable = enable;
+ this.includeTxPower = includeTxPower;
+ this.interval = interval;
+ }
+
+ private PeriodicAdvertisingParameters(Parcel in) {
+ enable = in.readInt() != 0 ? true : false;
+ includeTxPower = in.readInt() != 0 ? true : false;
+ interval = in.readInt();
+ }
+
+ /**
+ * Returns whether the periodic advertising shall be enabled.
+ */
+ public boolean getEnable() { return enable; }
+
+ /**
+ * Returns whether the TX Power will be included.
+ */
+ public boolean getIncludeTxPower() { return includeTxPower; }
+
+ /**
+ * Returns the periodic advertising interval, in 1.25ms unit.
+ * Valid values are from 80 (100ms) to 65519 (81.89875s).
+ */
+ public int getInterval() { return interval; }
+
+ @Override
+ public int describeContents() {
+ return 0;
+ }
+
+ @Override
+ public void writeToParcel(Parcel dest, int flags) {
+ dest.writeInt(enable ? 1 : 0);
+ dest.writeInt(includeTxPower ? 1 : 0);
+ dest.writeInt(interval);
+ }
+
+ public static final Parcelable
+ .Creator<PeriodicAdvertisingParameters> CREATOR =
+ new Creator<PeriodicAdvertisingParameters>() {
+ @Override
+ public PeriodicAdvertisingParameters[] newArray(int size) {
+ return new PeriodicAdvertisingParameters[size];
+ }
+
+ @Override
+ public PeriodicAdvertisingParameters createFromParcel(Parcel in) {
+ return new PeriodicAdvertisingParameters(in);
+ }
+ };
+
+ public static final class Builder {
+ private boolean includeTxPower = false;
+ private boolean enable = false;
+ private int interval = INTERVAL_MAX;
+
+ /**
+ * Set wether the Periodic Advertising should be enabled for this set.
+ */
+ public Builder setEnable(boolean enable) {
+ this.enable = enable;
+ return this;
+ }
+
+ /**
+ * Whether the transmission power level should be included in the periodic
+ * packet.
+ */
+ public Builder setIncludeTxPower(boolean includeTxPower) {
+ this.includeTxPower = includeTxPower;
+ return this;
+ }
+
+ /**
+ * Set advertising interval for periodic advertising, in 1.25ms unit.
+ * Valid values are from 80 (100ms) to 65519 (81.89875s).
+ * Value from range [interval, interval+20ms] will be picked as the actual value.
+ * @throws IllegalArgumentException If the interval is invalid.
+ */
+ public Builder setInterval(int interval) {
+ if (interval < INTERVAL_MIN || interval > INTERVAL_MAX) {
+ throw new IllegalArgumentException("Invalid interval (must be " + INTERVAL_MIN +
+ "-" + INTERVAL_MAX + ")");
+ }
+ this.interval = interval;
+ return this;
+ }
+
+ /**
+ * Build the {@link AdvertisingSetParameters} object.
+ */
+ public PeriodicAdvertisingParameters build() {
+ return new PeriodicAdvertisingParameters(enable, includeTxPower, interval);
+ }
+ }
+}
diff --git a/core/java/android/bluetooth/le/PeriodicAdvertisingReport.aidl b/core/java/android/bluetooth/le/PeriodicAdvertisingReport.aidl
new file mode 100644
index 0000000..547d096
--- /dev/null
+++ b/core/java/android/bluetooth/le/PeriodicAdvertisingReport.aidl
@@ -0,0 +1,19 @@
+/*
+ * Copyright (C) 2017 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package android.bluetooth.le;
+
+parcelable PeriodicAdvertisingReport;
diff --git a/core/java/android/bluetooth/le/PeriodicAdvertisingReport.java b/core/java/android/bluetooth/le/PeriodicAdvertisingReport.java
new file mode 100644
index 0000000..3ff4ca5
--- /dev/null
+++ b/core/java/android/bluetooth/le/PeriodicAdvertisingReport.java
@@ -0,0 +1,184 @@
+/*
+ * Copyright (C) 2017 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package android.bluetooth.le;
+
+import android.annotation.Nullable;
+import android.os.Parcel;
+import android.os.Parcelable;
+
+import java.util.Objects;
+
+/**
+ * PeriodicAdvertisingReport for Bluetooth LE synchronized advertising.
+ */
+public final class PeriodicAdvertisingReport implements Parcelable {
+
+ /**
+ * The data returned is complete
+ */
+ public static final int DATA_COMPLETE = 0;
+
+ /**
+ * The data returned is incomplete. The controller was unsuccessfull to
+ * receive all chained packets, returning only partial data.
+ */
+ public static final int DATA_INCOMPLETE_TRUNCATED = 2;
+
+ private int syncHandle;
+ private int txPower;
+ private int rssi;
+ private int dataStatus;
+
+ // periodic advertising data.
+ @Nullable
+ private ScanRecord data;
+
+ // Device timestamp when the result was last seen.
+ private long timestampNanos;
+
+ /**
+ * Constructor of periodic advertising result.
+ *
+ */
+ public PeriodicAdvertisingReport(int syncHandle, int txPower, int rssi,
+ int dataStatus, ScanRecord data) {
+ this.syncHandle = syncHandle;
+ this.txPower = txPower;
+ this.rssi = rssi;
+ this.dataStatus = dataStatus;
+ this.data = data;
+ }
+
+ private PeriodicAdvertisingReport(Parcel in) {
+ readFromParcel(in);
+ }
+
+ @Override
+ public void writeToParcel(Parcel dest, int flags) {
+ dest.writeInt(syncHandle);
+ dest.writeLong(txPower);
+ dest.writeInt(rssi);
+ dest.writeInt(dataStatus);
+ if (data != null) {
+ dest.writeInt(1);
+ dest.writeByteArray(data.getBytes());
+ } else {
+ dest.writeInt(0);
+ }
+ }
+
+ private void readFromParcel(Parcel in) {
+ syncHandle = in.readInt();
+ txPower = in.readInt();
+ rssi = in.readInt();
+ dataStatus = in.readInt();
+ if (in.readInt() == 1) {
+ data = ScanRecord.parseFromBytes(in.createByteArray());
+ }
+ }
+
+ @Override
+ public int describeContents() {
+ return 0;
+ }
+
+ /**
+ * Returns the synchronization handle.
+ */
+ public int getSyncHandle() {
+ return syncHandle;
+ }
+
+ /**
+ * Returns the transmit power in dBm. The valid range is [-127, 126]. Value
+ * of 127 means information was not available.
+ */
+ public int getTxPower() {
+ return txPower;
+ }
+
+ /**
+ * Returns the received signal strength in dBm. The valid range is [-127, 20].
+ */
+ public int getRssi() {
+ return rssi;
+ }
+
+ /**
+ * Returns the data status. Can be one of {@link PeriodicAdvertisingReport#DATA_COMPLETE}
+ * or {@link PeriodicAdvertisingReport#DATA_INCOMPLETE_TRUNCATED}.
+ */
+ public int getDataStatus() {
+ return dataStatus;
+ }
+
+ /**
+ * Returns the data contained in this periodic advertising report.
+ */
+ @Nullable
+ public ScanRecord getData() {
+ return data;
+ }
+
+ /**
+ * Returns timestamp since boot when the scan record was observed.
+ */
+ public long getTimestampNanos() {
+ return timestampNanos;
+ }
+
+ @Override
+ public int hashCode() {
+ return Objects.hash(syncHandle, txPower, rssi, dataStatus, data, timestampNanos);
+ }
+
+ @Override
+ public boolean equals(Object obj) {
+ if (this == obj) {
+ return true;
+ }
+ if (obj == null || getClass() != obj.getClass()) {
+ return false;
+ }
+ PeriodicAdvertisingReport other = (PeriodicAdvertisingReport) obj;
+ return (syncHandle == other.syncHandle) &&
+ (txPower == other.txPower) &&
+ (rssi == other.rssi) &&
+ (dataStatus == other.dataStatus) &&
+ Objects.equals(data, other.data) &&
+ (timestampNanos == other.timestampNanos);
+ }
+
+ @Override
+ public String toString() {
+ return "PeriodicAdvertisingReport{syncHandle=" + syncHandle +
+ ", txPower=" + txPower + ", rssi=" + rssi + ", dataStatus=" + dataStatus +
+ ", data=" + Objects.toString(data) + ", timestampNanos=" + timestampNanos + '}';
+ }
+
+ public static final Parcelable.Creator<PeriodicAdvertisingReport> CREATOR = new Creator<PeriodicAdvertisingReport>() {
+ @Override
+ public PeriodicAdvertisingReport createFromParcel(Parcel source) {
+ return new PeriodicAdvertisingReport(source);
+ }
+
+ @Override
+ public PeriodicAdvertisingReport[] newArray(int size) {
+ return new PeriodicAdvertisingReport[size];
+ }
+ };
+}
diff --git a/core/java/android/bluetooth/le/ScanResult.java b/core/java/android/bluetooth/le/ScanResult.java
index 2fdfe7f..583ddd2 100644
--- a/core/java/android/bluetooth/le/ScanResult.java
+++ b/core/java/android/bluetooth/le/ScanResult.java
@@ -27,7 +27,56 @@
* ScanResult for Bluetooth LE scan.
*/
public final class ScanResult implements Parcelable {
- // Remote bluetooth device.
+
+ /**
+ * For chained advertisements, inidcates tha the data contained in this
+ * scan result is complete.
+ */
+ public static final int DATA_COMPLETE = 0x00;
+
+ /**
+ * For chained advertisements, indicates that the controller was
+ * unable to receive all chained packets and the scan result contains
+ * incomplete truncated data.
+ */
+ public static final int DATA_TRUNCATED = 0x02;
+
+ /**
+ * Indicates that the secondary physical layer was not used.
+ */
+ public static final int PHY_UNUSED = 0x00;
+
+ /**
+ * Bluetooth LE 1Mbit advertiser PHY.
+ */
+ public static final int PHY_LE_1M = 0x01;
+
+ /**
+ * Bluetooth LE 2Mbit advertiser PHY.
+ */
+ public static final int PHY_LE_2M = 0x02;
+
+ /**
+ * Bluetooth LE Coded advertiser PHY.
+ */
+ public static final int PHY_LE_CODED = 0x03;
+
+ /**
+ * Advertising Set ID is not present in the packet.
+ */
+ public static final int SID_NOT_PRESENT = 0xFF;
+
+ /**
+ * Mask for checking wether event type represents legacy advertisement.
+ */
+ private static final int ET_LEGACY_MASK = 0x10;
+
+ /**
+ * Mask for checking wether event type represents connectable advertisement.
+ */
+ private static final int ET_CONNECTABLE_MASK = 0x01;
+
+ // Remote Bluetooth device.
private BluetoothDevice mDevice;
// Scan record, including advertising data and scan response data.
@@ -40,13 +89,21 @@
// Device timestamp when the result was last seen.
private long mTimestampNanos;
+ private int mEventType;
+ private int mPrimaryPhy;
+ private int mSecondaryPhy;
+ private int mAdvertisingSid;
+ private int mTxPower;
+ private int mPeriodicAdvertisingInterval;
+
/**
- * Constructor of scan result.
+ * Constructs a new ScanResult.
*
- * @param device Remote bluetooth device that is found.
+ * @param device Remote Bluetooth device found.
* @param scanRecord Scan record including both advertising data and scan response data.
* @param rssi Received signal strength.
- * @param timestampNanos Device timestamp when the scan result was observed.
+ * @param timestampNanos Timestamp at which the scan result was observed.
+ * @deprecated use {@link #ScanResult(BluetoothDevice, int, int, int, int, int, int, int, ScanRecord, long)}
*/
public ScanResult(BluetoothDevice device, ScanRecord scanRecord, int rssi,
long timestampNanos) {
@@ -54,6 +111,41 @@
mScanRecord = scanRecord;
mRssi = rssi;
mTimestampNanos = timestampNanos;
+ mEventType = (DATA_COMPLETE << 5) | ET_LEGACY_MASK | ET_CONNECTABLE_MASK;
+ mPrimaryPhy = PHY_LE_1M;
+ mSecondaryPhy = PHY_UNUSED;
+ mAdvertisingSid = SID_NOT_PRESENT;
+ mTxPower = 127;
+ mPeriodicAdvertisingInterval = 0;
+ }
+
+ /**
+ * Constructs a new ScanResult.
+ *
+ * @param device Remote Bluetooth device found.
+ * @param eventType Event type.
+ * @param primaryPhy Primary advertising phy.
+ * @param secondaryPhy Secondary advertising phy.
+ * @param advertisingSid Advertising set ID.
+ * @param txPower Transmit power.
+ * @param rssi Received signal strength.
+ * @param periodicAdvertisingInterval Periodic advertising interval.
+ * @param scanRecord Scan record including both advertising data and scan response data.
+ * @param timestampNanos Timestamp at which the scan result was observed.
+ */
+ public ScanResult(BluetoothDevice device, int eventType, int primaryPhy, int secondaryPhy,
+ int advertisingSid, int txPower, int rssi, int periodicAdvertisingInterval,
+ ScanRecord scanRecord, long timestampNanos) {
+ mDevice = device;
+ mEventType = eventType;
+ mPrimaryPhy = primaryPhy;
+ mSecondaryPhy = secondaryPhy;
+ mAdvertisingSid = advertisingSid;
+ mTxPower = txPower;
+ mRssi = rssi;
+ mPeriodicAdvertisingInterval = periodicAdvertisingInterval;
+ mScanRecord = scanRecord;
+ mTimestampNanos = timestampNanos;
}
private ScanResult(Parcel in) {
@@ -76,6 +168,12 @@
}
dest.writeInt(mRssi);
dest.writeLong(mTimestampNanos);
+ dest.writeInt(mEventType);
+ dest.writeInt(mPrimaryPhy);
+ dest.writeInt(mSecondaryPhy);
+ dest.writeInt(mAdvertisingSid);
+ dest.writeInt(mTxPower);
+ dest.writeInt(mPeriodicAdvertisingInterval);
}
private void readFromParcel(Parcel in) {
@@ -87,6 +185,12 @@
}
mRssi = in.readInt();
mTimestampNanos = in.readLong();
+ mEventType = in.readInt();
+ mPrimaryPhy = in.readInt();
+ mSecondaryPhy = in.readInt();
+ mAdvertisingSid = in.readInt();
+ mTxPower = in.readInt();
+ mPeriodicAdvertisingInterval = in.readInt();
}
@Override
@@ -95,7 +199,7 @@
}
/**
- * Returns the remote bluetooth device identified by the bluetooth device address.
+ * Returns the remote Bluetooth device identified by the Bluetooth device address.
*/
public BluetoothDevice getDevice() {
return mDevice;
@@ -110,7 +214,7 @@
}
/**
- * Returns the received signal strength in dBm. The valid range is [-127, 127].
+ * Returns the received signal strength in dBm. The valid range is [-127, 126].
*/
public int getRssi() {
return mRssi;
@@ -123,9 +227,79 @@
return mTimestampNanos;
}
+ /**
+ * Returns true if this object represents legacy scan result.
+ * Legacy scan results do not contain advanced advertising information
+ * as specified in the Bluetooth Core Specification v5.
+ */
+ public boolean isLegacy() {
+ return (mEventType & ET_LEGACY_MASK) != 0;
+ }
+
+ /**
+ * Returns true if this object represents connectable scan result.
+ */
+ public boolean isConnectable() {
+ return (mEventType & ET_CONNECTABLE_MASK) != 0;
+ }
+
+ /**
+ * Returns the data status.
+ * Can be one of {@link ScanResult#DATA_COMPLETE} or
+ * {@link ScanResult#DATA_TRUNCATED}.
+ */
+ public int getDataStatus() {
+ // return bit 5 and 6
+ return (mEventType >> 5) & 0x03;
+ }
+
+ /**
+ * Returns the primary Physical Layer
+ * on which this advertisment was received.
+ * Can be one of {@link ScanResult#PHY_LE_1M} or
+ * {@link ScanResult#PHY_LE_CODED}.
+ */
+ public int getPrimaryPhy() { return mPrimaryPhy; }
+
+ /**
+ * Returns the secondary Physical Layer
+ * on which this advertisment was received.
+ * Can be one of {@link ScanResult#PHY_LE_1M},
+ * {@link ScanResult#PHY_LE_2M}, {@link ScanResult#PHY_LE_CODED}
+ * or {@link ScanResult#PHY_UNUSED} - if the advertisement
+ * was not received on a secondary physical channel.
+ */
+ public int getSecondaryPhy() { return mSecondaryPhy; }
+
+ /**
+ * Returns the advertising set id.
+ * May return {@link ScanResult#SID_NOT_PRESENT} if
+ * no set id was is present.
+ */
+ public int getAdvertisingSid() { return mAdvertisingSid; }
+
+ /**
+ * Returns the transmit power in dBm.
+ * Valid range is [-127, 126]. A value of 127 indicates that the
+ * advertisement did not indicate TX power.
+ */
+ public int getTxPower() { return mTxPower; }
+
+ /**
+ * Returns the periodic advertising interval in units of 1.25ms.
+ * Valid range is 6 (7.5ms) to 65536 (81918.75ms). A value of 0 means
+ * periodic advertising is not used for this scan result.
+ */
+ public int getPeriodicAdvertisingInterval() {
+ return mPeriodicAdvertisingInterval;
+ }
+
@Override
public int hashCode() {
- return Objects.hash(mDevice, mRssi, mScanRecord, mTimestampNanos);
+ return Objects.hash(mDevice, mRssi, mScanRecord, mTimestampNanos,
+ mEventType, mPrimaryPhy, mSecondaryPhy,
+ mAdvertisingSid, mTxPower,
+ mPeriodicAdvertisingInterval);
}
@Override
@@ -138,15 +312,24 @@
}
ScanResult other = (ScanResult) obj;
return Objects.equals(mDevice, other.mDevice) && (mRssi == other.mRssi) &&
- Objects.equals(mScanRecord, other.mScanRecord)
- && (mTimestampNanos == other.mTimestampNanos);
+ Objects.equals(mScanRecord, other.mScanRecord) &&
+ (mTimestampNanos == other.mTimestampNanos) &&
+ mEventType == other.mEventType &&
+ mPrimaryPhy == other.mPrimaryPhy &&
+ mSecondaryPhy == other.mSecondaryPhy &&
+ mAdvertisingSid == other.mAdvertisingSid &&
+ mTxPower == other.mTxPower &&
+ mPeriodicAdvertisingInterval == other.mPeriodicAdvertisingInterval;
}
@Override
public String toString() {
- return "ScanResult{" + "mDevice=" + mDevice + ", mScanRecord="
- + Objects.toString(mScanRecord) + ", mRssi=" + mRssi + ", mTimestampNanos="
- + mTimestampNanos + '}';
+ return "ScanResult{" + "device=" + mDevice + ", scanRecord=" +
+ Objects.toString(mScanRecord) + ", rssi=" + mRssi +
+ ", timestampNanos=" + mTimestampNanos + ", eventType=" + mEventType +
+ ", primaryPhy=" + mPrimaryPhy + ", secondaryPhy=" + mSecondaryPhy +
+ ", advertisingSid=" + mAdvertisingSid + ", txPower=" + mTxPower +
+ ", periodicAdvertisingInterval=" + mPeriodicAdvertisingInterval + '}';
}
public static final Parcelable.Creator<ScanResult> CREATOR = new Creator<ScanResult>() {
diff --git a/core/java/android/bluetooth/le/ScanSettings.java b/core/java/android/bluetooth/le/ScanSettings.java
index d616624..69c9a8c 100644
--- a/core/java/android/bluetooth/le/ScanSettings.java
+++ b/core/java/android/bluetooth/le/ScanSettings.java
@@ -122,6 +122,24 @@
@SystemApi
public static final int SCAN_RESULT_TYPE_ABBREVIATED = 1;
+ /**
+ * Use the Bluetooth LE 1Mbit PHY for scanning.
+ */
+ public static final int PHY_LE_1M = 1;
+
+ /**
+ * Use Bluetooth LE Coded PHY for scanning.
+ */
+ public static final int PHY_LE_CODED = 3;
+
+ /**
+ * Use all supported PHYs for scanning.
+ * This will check the controller capabilities, and start
+ * the scan on 1Mbit and LE Coded PHYs if supported, or on
+ * the 1Mbit PHY only.
+ */
+ public static final int PHY_LE_ALL_SUPPORTED = 255;
+
// Bluetooth LE scan mode.
private int mScanMode;
@@ -138,6 +156,11 @@
private int mNumOfMatchesPerFilter;
+ // Include only legacy advertising results
+ private boolean mLegacy;
+
+ private int mPhy;
+
public int getScanMode() {
return mScanMode;
}
@@ -165,6 +188,22 @@
}
/**
+ * Returns whether only legacy advertisements will be returned.
+ * Legacy advertisements include advertisements as specified
+ * by the Bluetooth core specification 4.2 and below.
+ */
+ public boolean getLegacy() {
+ return mLegacy;
+ }
+
+ /**
+ * Returns the physical layer used during a scan.
+ */
+ public int getPhy() {
+ return mPhy;
+ }
+
+ /**
* Returns report delay timestamp based on the device clock.
*/
public long getReportDelayMillis() {
@@ -172,13 +211,16 @@
}
private ScanSettings(int scanMode, int callbackType, int scanResultType,
- long reportDelayMillis, int matchMode, int numOfMatchesPerFilter) {
+ long reportDelayMillis, int matchMode,
+ int numOfMatchesPerFilter, boolean legacy, int phy) {
mScanMode = scanMode;
mCallbackType = callbackType;
mScanResultType = scanResultType;
mReportDelayMillis = reportDelayMillis;
mNumOfMatchesPerFilter = numOfMatchesPerFilter;
mMatchMode = matchMode;
+ mLegacy = legacy;
+ mPhy = phy;
}
private ScanSettings(Parcel in) {
@@ -188,6 +230,8 @@
mReportDelayMillis = in.readLong();
mMatchMode = in.readInt();
mNumOfMatchesPerFilter = in.readInt();
+ mLegacy = in.readInt() != 0 ? true : false;
+ mPhy = in.readInt();
}
@Override
@@ -198,6 +242,8 @@
dest.writeLong(mReportDelayMillis);
dest.writeInt(mMatchMode);
dest.writeInt(mNumOfMatchesPerFilter);
+ dest.writeInt(mLegacy ? 1 : 0);
+ dest.writeInt(mPhy);
}
@Override
@@ -228,6 +274,9 @@
private long mReportDelayMillis = 0;
private int mMatchMode = MATCH_MODE_AGGRESSIVE;
private int mNumOfMatchesPerFilter = MATCH_NUM_MAX_ADVERTISEMENT;
+ private boolean mLegacy = true;
+ private int mPhy = PHY_LE_ALL_SUPPORTED;
+
/**
* Set scan mode for Bluetooth LE scan.
*
@@ -341,11 +390,44 @@
}
/**
+ * Set whether only legacy advertisments should be returned in scan results.
+ * Legacy advertisements include advertisements as specified by the
+ * Bluetooth core specification 4.2 and below. This is true by default
+ * for compatibility with older apps.
+ *
+ * @param legacy true if only legacy advertisements will be returned
+ */
+ public Builder setLegacy(boolean legacy) {
+ mLegacy = legacy;
+ return this;
+ }
+
+ /**
+ * Set the Physical Layer to use during this scan.
+ * This is used only if {@link ScanSettings.Builder#setLegacy}
+ * is set to false.
+ * {@link android.bluetooth.BluetoothAdapter#isLeCodedPhySupported}
+ * may be used to check whether LE Coded phy is supported by calling
+ * {@link android.bluetooth.BluetoothAdapter#isLeCodedPhySupported}.
+ * Selecting an unsupported phy will result in failure to start scan.
+ *
+ * @param phy Can be one of
+ * {@link ScanSettings#PHY_LE_1M},
+ * {@link ScanSettings#PHY_LE_CODED} or
+ * {@link ScanSettings#PHY_LE_ALL_SUPPORTED}
+ */
+ public Builder setPhy(int phy) {
+ mPhy = phy;
+ return this;
+ }
+
+ /**
* Build {@link ScanSettings}.
*/
public ScanSettings build() {
return new ScanSettings(mScanMode, mCallbackType, mScanResultType,
- mReportDelayMillis, mMatchMode, mNumOfMatchesPerFilter);
+ mReportDelayMillis, mMatchMode,
+ mNumOfMatchesPerFilter, mLegacy, mPhy);
}
}
}
diff --git a/core/java/android/os/HwBinder.java b/core/java/android/os/HwBinder.java
index e025494..b09c51c 100644
--- a/core/java/android/os/HwBinder.java
+++ b/core/java/android/os/HwBinder.java
@@ -43,9 +43,7 @@
int code, HwParcel request, HwParcel reply, int flags)
throws RemoteException;
- public native final void registerService(
- ArrayList<String> interfaceChain,
- String serviceName)
+ public native final void registerService(String serviceName)
throws RemoteException;
public static native final IHwBinder getService(
diff --git a/core/jni/android_os_HwBinder.cpp b/core/jni/android_os_HwBinder.cpp
index 8791e27..c3978e7 100644
--- a/core/jni/android_os_HwBinder.cpp
+++ b/core/jni/android_os_HwBinder.cpp
@@ -49,12 +49,6 @@
namespace android {
-static jclass gArrayListClass;
-static struct {
- jmethodID size;
- jmethodID get;
-} gArrayListMethods;
-
static jclass gErrorClass;
static struct fields_t {
@@ -237,7 +231,6 @@
static void JHwBinder_native_registerService(
JNIEnv *env,
jobject thiz,
- jobject interfaceChainArrayList,
jstring serviceNameObj) {
if (serviceNameObj == NULL) {
jniThrowException(env, "java/lang/NullPointerException", NULL);
@@ -249,24 +242,6 @@
return; // XXX exception already pending?
}
- jint numInterfaces = env->CallIntMethod(interfaceChainArrayList,
- gArrayListMethods.size);
- hidl_string *strings = new hidl_string[numInterfaces];
-
- for (jint i = 0; i < numInterfaces; i++) {
- jstring strObj = static_cast<jstring>(
- env->CallObjectMethod(interfaceChainArrayList,
- gArrayListMethods.get,
- i)
- );
- const char * str = env->GetStringUTFChars(strObj, nullptr);
- strings[i] = hidl_string(str);
- env->ReleaseStringUTFChars(strObj, str);
- }
-
- hidl_vec<hidl_string> interfaceChain;
- interfaceChain.setToExternal(strings, numInterfaces, true /* shouldOwn */);
-
sp<hardware::IBinder> binder = JHwBinder::GetNativeContext(env, thiz);
/* TODO(b/33440494) this is not right */
@@ -280,7 +255,7 @@
return;
}
- Return<bool> ret = manager->add(interfaceChain, serviceName, base);
+ Return<bool> ret = manager->add(serviceName, base);
env->ReleaseStringUTFChars(serviceNameObj, serviceName);
serviceName = NULL;
@@ -383,7 +358,7 @@
"(IL" PACKAGE_PATH "/HwParcel;L" PACKAGE_PATH "/HwParcel;I)V",
(void *)JHwBinder_native_transact },
- { "registerService", "(Ljava/util/ArrayList;Ljava/lang/String;)V",
+ { "registerService", "(Ljava/lang/String;)V",
(void *)JHwBinder_native_registerService },
{ "getService", "(Ljava/lang/String;Ljava/lang/String;)L" PACKAGE_PATH "/IHwBinder;",
@@ -393,11 +368,6 @@
namespace android {
int register_android_os_HwBinder(JNIEnv *env) {
- jclass arrayListClass = FindClassOrDie(env, "java/util/ArrayList");
- gArrayListClass = MakeGlobalRefOrDie(env, arrayListClass);
- gArrayListMethods.size = GetMethodIDOrDie(env, arrayListClass, "size", "()I");
- gArrayListMethods.get = GetMethodIDOrDie(env, arrayListClass, "get", "(I)Ljava/lang/Object;");
-
jclass errorClass = FindClassOrDie(env, "java/lang/Error");
gErrorClass = MakeGlobalRefOrDie(env, errorClass);
diff --git a/core/tests/coretests/src/android/view/PopupWindowVisibility.java b/core/tests/coretests/src/android/view/PopupWindowVisibility.java
index 7eb0468..6e11ede 100644
--- a/core/tests/coretests/src/android/view/PopupWindowVisibility.java
+++ b/core/tests/coretests/src/android/view/PopupWindowVisibility.java
@@ -82,7 +82,7 @@
"Cote d'Ivoire", "Cambodia", "Cameroon", "Canada", "Cape Verde",
"Cayman Islands", "Central African Republic", "Chad", "Chile", "China",
"Christmas Island", "Cocos (Keeling) Islands", "Colombia", "Comoros", "Congo",
- "Cook Islands", "Costa Rica", "Croatia", "Cuba", "Cyprus", "Czech Republic",
+ "Cook Islands", "Costa Rica", "Croatia", "Cuba", "Cyprus", "Czechia",
"Democratic Republic of the Congo", "Denmark", "Djibouti", "Dominica", "Dominican Republic",
"East Timor", "Ecuador", "Egypt", "El Salvador", "Equatorial Guinea", "Eritrea",
"Estonia", "Ethiopia", "Faeroe Islands", "Falkland Islands", "Fiji", "Finland",
diff --git a/packages/CaptivePortalLogin/src/com/android/captiveportallogin/CaptivePortalLoginActivity.java b/packages/CaptivePortalLogin/src/com/android/captiveportallogin/CaptivePortalLoginActivity.java
index 23a8655..6394c64 100644
--- a/packages/CaptivePortalLogin/src/com/android/captiveportallogin/CaptivePortalLoginActivity.java
+++ b/packages/CaptivePortalLogin/src/com/android/captiveportallogin/CaptivePortalLoginActivity.java
@@ -77,8 +77,8 @@
mCm = ConnectivityManager.from(this);
mNetwork = getIntent().getParcelableExtra(ConnectivityManager.EXTRA_NETWORK);
mCaptivePortal = getIntent().getParcelableExtra(ConnectivityManager.EXTRA_CAPTIVE_PORTAL);
- mUserAgent = getIntent().getParcelableExtra(
- ConnectivityManager.EXTRA_CAPTIVE_PORTAL_USER_AGENT);
+ mUserAgent =
+ getIntent().getStringExtra(ConnectivityManager.EXTRA_CAPTIVE_PORTAL_USER_AGENT);
mUrl = getUrl();
if (mUrl == null) {
// getUrl() failed to parse the url provided in the intent: bail out in a way that
@@ -274,8 +274,17 @@
if (mUserAgent != null) {
urlConnection.setRequestProperty("User-Agent", mUserAgent);
}
+ // cannot read request header after connection
+ String requestHeader = urlConnection.getRequestProperties().toString();
+
urlConnection.getInputStream();
httpResponseCode = urlConnection.getResponseCode();
+ if (DBG) {
+ Log.d(TAG, "probe at " + mUrl +
+ " ret=" + httpResponseCode +
+ " request=" + requestHeader +
+ " headers=" + urlConnection.getHeaderFields());
+ }
} catch (IOException e) {
} finally {
if (urlConnection != null) urlConnection.disconnect();
diff --git a/packages/CarrierDefaultApp/AndroidManifest.xml b/packages/CarrierDefaultApp/AndroidManifest.xml
index d910920..2e642ec 100644
--- a/packages/CarrierDefaultApp/AndroidManifest.xml
+++ b/packages/CarrierDefaultApp/AndroidManifest.xml
@@ -17,16 +17,16 @@
*/
-->
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
- package="com.android.carrierdefaultapp"
- android:sharedUserId="android.uid.phone" >
+ package="com.android.carrierdefaultapp">
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.CONNECTIVITY_INTERNAL" />
<uses-permission android:name="android.permission.MODIFY_PHONE_STATE" />
- <uses-permission android:name="android.permission.READ_PHONE_STATE" />
+ <uses-permission android:name="android.permission.READ_PRIVILEGED_PHONE_STATE" />
<uses-permission android:name="android.permission.CONNECTIVITY_USE_RESTRICTED_NETWORKS" />
<uses-permission android:name="android.permission.SYSTEM_ALERT_WINDOW" />
+ <uses-permission android:name="android.permission.SUBSTITUTE_NOTIFICATION_APP_NAME" />
<application android:label="@string/app_name" >
<receiver android:name="com.android.carrierdefaultapp.CarrierDefaultBroadcastReceiver">
diff --git a/packages/CarrierDefaultApp/res/drawable/ic_sim_card.xml b/packages/CarrierDefaultApp/res/drawable/ic_sim_card.xml
index 5896757..dc54fe2 100644
--- a/packages/CarrierDefaultApp/res/drawable/ic_sim_card.xml
+++ b/packages/CarrierDefaultApp/res/drawable/ic_sim_card.xml
@@ -14,13 +14,12 @@
See the License for the specific language governing permissions and
limitations under the License.
-->
-
<vector xmlns:android="http://schemas.android.com/apk/res/android"
- android:width="@dimen/glif_icon_size"
- android:height="@dimen/glif_icon_size"
- android:viewportWidth="48"
- android:viewportHeight="48">
- <path
- android:fillColor="?android:attr/colorPrimary"
- android:pathData="M39.98,8c0,-2.21 -1.77,-4 -3.98,-4L20,4L8,16v24c0,2.21 1.79,4 4,4h24.02c2.21,0 3.98,-1.79 3.98,-4l-0.02,-32zM18,38h-4v-4h4v4zM34,38h-4v-4h4v4zM18,30h-4v-8h4v8zM26,38h-4v-8h4v8zM26,26h-4v-4h4v4zM34,30h-4v-8h4v8z" />
+ android:width="24dp"
+ android:height="24dp"
+ android:viewportWidth="24.0"
+ android:viewportHeight="24.0">
+<path
+ android:fillColor="#757575"
+ android:pathData="M18,2h-8L4.02,8 4,20c0,1.1 0.9,2 2,2h12c1.1,0 2,-0.9 2,-2L20,4c0,-1.1 -0.9,-2 -2,-2zM13,17h-2v-2h2v2zM13,13h-2L11,8h2v5z"/>
</vector>
\ No newline at end of file
diff --git a/packages/CarrierDefaultApp/res/values/strings.xml b/packages/CarrierDefaultApp/res/values/strings.xml
index 838ff39..fe5669d 100644
--- a/packages/CarrierDefaultApp/res/values/strings.xml
+++ b/packages/CarrierDefaultApp/res/values/strings.xml
@@ -1,10 +1,11 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>
<string name="app_name">CarrierDefaultApp</string>
- <string name="portal_notification_id">Activate your service</string>
- <string name="no_data_notification_id">No data service</string>
- <string name="portal_notification_detail">Tap to activate your service</string>
- <string name="no_data_notification_detail">No Service, please contact your service provider</string>
+ <string name="android_system_label">Android System</string>
+ <string name="portal_notification_id">Mobile data has run out</string>
+ <string name="no_data_notification_id">No Mobile data service</string>
+ <string name="portal_notification_detail">Tap to add funds to your %s SIM</string>
+ <string name="no_data_notification_detail">Please contact your service provider %s</string>
<string name="progress_dialogue_network_connection">Connecting to captive portal...</string>
<string name="alert_dialogue_network_timeout">Network timeout, would you like to retry?</string>
<string name="alert_dialogue_network_timeout_title">Network unavailable</string>
diff --git a/packages/CarrierDefaultApp/src/com/android/carrierdefaultapp/CarrierActionUtils.java b/packages/CarrierDefaultApp/src/com/android/carrierdefaultapp/CarrierActionUtils.java
index db4890f..d9bd2fc 100644
--- a/packages/CarrierDefaultApp/src/com/android/carrierdefaultapp/CarrierActionUtils.java
+++ b/packages/CarrierDefaultApp/src/com/android/carrierdefaultapp/CarrierActionUtils.java
@@ -21,6 +21,7 @@
import android.content.Context;
import android.content.Intent;
import android.content.res.Resources;
+import android.os.Bundle;
import android.telephony.SubscriptionManager;
import android.telephony.TelephonyManager;
import android.util.Log;
@@ -146,18 +147,25 @@
private static Notification getNotification(Context context, int titleId, int textId,
PendingIntent pendingIntent) {
- Resources resources = context.getResources();
+ final TelephonyManager telephonyMgr = context.getSystemService(TelephonyManager.class);
+ final Resources resources = context.getResources();
+ final Bundle extras = Bundle.forPair(Notification.EXTRA_SUBSTITUTE_APP_NAME,
+ resources.getString(R.string.android_system_label));
Notification.Builder builder = new Notification.Builder(context)
.setContentTitle(resources.getString(titleId))
- .setContentText(resources.getString(textId))
+ .setContentText(String.format(resources.getString(textId),
+ telephonyMgr.getNetworkOperatorName()))
.setSmallIcon(R.drawable.ic_sim_card)
+ .setColor(context.getColor(
+ com.android.internal.R.color.system_notification_accent_color))
.setOngoing(true)
.setPriority(Notification.PRIORITY_HIGH)
.setDefaults(Notification.DEFAULT_ALL)
.setVisibility(Notification.VISIBILITY_PUBLIC)
.setLocalOnly(true)
.setWhen(System.currentTimeMillis())
- .setShowWhen(false);
+ .setShowWhen(false)
+ .setExtras(extras);
if (pendingIntent != null) {
builder.setContentIntent(pendingIntent);
diff --git a/rs/jni/Android.mk b/rs/jni/Android.mk
index 447a47d..4040db3 100644
--- a/rs/jni/Android.mk
+++ b/rs/jni/Android.mk
@@ -5,6 +5,7 @@
android_renderscript_RenderScript.cpp
LOCAL_SHARED_LIBRARIES := \
+ libandroid \
libandroid_runtime \
libandroidfw \
libnativehelper \
diff --git a/rs/jni/android_renderscript_RenderScript.cpp b/rs/jni/android_renderscript_RenderScript.cpp
index 2300da3..b4630ef 100644
--- a/rs/jni/android_renderscript_RenderScript.cpp
+++ b/rs/jni/android_renderscript_RenderScript.cpp
@@ -34,6 +34,8 @@
#include "android_runtime/android_view_Surface.h"
#include "android_runtime/android_util_AssetManager.h"
#include "android/graphics/GraphicsJNI.h"
+#include "android/native_window.h"
+#include "android/native_window_jni.h"
#include <rsEnv.h>
#include <rsApiStubs.h>
@@ -1264,10 +1266,10 @@
ALOGD("nAllocationGetSurface, con(%p), a(%p)", (RsContext)con, (RsAllocation)a);
}
- IGraphicBufferProducer *v = (IGraphicBufferProducer *)rsAllocationGetSurface((RsContext)con,
- (RsAllocation)a);
- sp<IGraphicBufferProducer> bp = v;
- v->decStrong(nullptr);
+ ANativeWindow *anw = (ANativeWindow *)rsAllocationGetSurface((RsContext)con, (RsAllocation)a);
+
+ sp<Surface> surface(static_cast<Surface*>(anw));
+ sp<IGraphicBufferProducer> bp = surface->getIGraphicBufferProducer();
jobject o = android_view_Surface_createFromIGraphicBufferProducer(_env, bp);
return o;
@@ -1281,13 +1283,12 @@
(RsAllocation)alloc, (Surface *)sur);
}
- sp<Surface> s;
+ ANativeWindow *anw = nullptr;
if (sur != 0) {
- s = android_view_Surface_getSurface(_env, sur);
+ anw = ANativeWindow_fromSurface(_env, sur);
}
- rsAllocationSetSurface((RsContext)con, (RsAllocation)alloc,
- static_cast<ANativeWindow *>(s.get()));
+ rsAllocationSetSurface((RsContext)con, (RsAllocation)alloc, anw);
}
static void
diff --git a/services/core/java/com/android/server/connectivity/NetworkMonitor.java b/services/core/java/com/android/server/connectivity/NetworkMonitor.java
index c40780e..97669d2 100644
--- a/services/core/java/com/android/server/connectivity/NetworkMonitor.java
+++ b/services/core/java/com/android/server/connectivity/NetworkMonitor.java
@@ -789,6 +789,8 @@
if (userAgent != null) {
urlConnection.setRequestProperty("User-Agent", userAgent);
}
+ // cannot read request header after connection
+ String requestHeader = urlConnection.getRequestProperties().toString();
// Time how long it takes to get a response to our request
long requestTimestamp = SystemClock.elapsedRealtime();
@@ -802,6 +804,7 @@
validationLog(ValidationProbeEvent.getProbeName(probeType) + " " + url +
" time=" + (responseTimestamp - requestTimestamp) + "ms" +
" ret=" + httpResponseCode +
+ " request=" + requestHeader +
" headers=" + urlConnection.getHeaderFields());
// NOTE: We may want to consider an "HTTP/1.0 204" response to be a captive
// portal. The only example of this seen so far was a captive portal. For
diff --git a/telecomm/java/android/telecom/Log.java b/telecomm/java/android/telecom/Log.java
index ced6627..6107895 100644
--- a/telecomm/java/android/telecom/Log.java
+++ b/telecomm/java/android/telecom/Log.java
@@ -19,6 +19,7 @@
import android.content.Context;
import android.net.Uri;
import android.os.AsyncTask;
+import android.os.Build;
import android.telecom.Logging.EventManager;
import android.telecom.Logging.Session;
import android.telecom.Logging.SessionManager;
@@ -55,6 +56,7 @@
public static boolean ERROR = isLoggable(android.util.Log.ERROR);
private static final boolean FORCE_LOGGING = false; /* STOP SHIP if true */
+ private static final boolean USER_BUILD = Build.TYPE.equals("user");
// Used to synchronize singleton logging lazy initialization
private static final Object sSingletonSync = new Object();
@@ -404,7 +406,8 @@
/**
* Redact personally identifiable information for production users.
- * If we are running in verbose mode, return the original string, otherwise
+ * If we are running in verbose mode, return the original string,
+ * and return "****" if we are running on the user build, otherwise
* return a SHA-1 hash of the input string.
*/
public static String pii(Object pii) {
@@ -415,6 +418,11 @@
}
private static String secureHash(byte[] input) {
+ // Refrain from logging user personal information in user build.
+ if (USER_BUILD) {
+ return "****";
+ }
+
if (sMessageDigest != null) {
sMessageDigest.reset();
sMessageDigest.update(input);
diff --git a/telephony/java/android/telephony/Rlog.java b/telephony/java/android/telephony/Rlog.java
index cd0a012..2a31e3a 100644
--- a/telephony/java/android/telephony/Rlog.java
+++ b/telephony/java/android/telephony/Rlog.java
@@ -16,6 +16,7 @@
package android.telephony;
+import android.os.Build;
import android.text.TextUtils;
import android.util.Log;
@@ -32,6 +33,8 @@
*/
public final class Rlog {
+ private static final boolean USER_BUILD = Build.TYPE.equals("user");
+
private Rlog() {
}
@@ -125,10 +128,15 @@
/**
* Returns a secure hash (using the SHA1 algorithm) of the provided input.
*
- * @return the hash
+ * @return "****" if the build type is user, otherwise the hash
* @param input the bytes for which the secure hash should be computed.
*/
private static String secureHash(byte[] input) {
+ // Refrain from logging user personal information in user build.
+ if (USER_BUILD) {
+ return "****";
+ }
+
MessageDigest messageDigest;
try {
diff --git a/telephony/java/android/telephony/ims/ImsServiceBase.java b/telephony/java/android/telephony/ims/ImsServiceBase.java
index 0878db8..bb36862 100644
--- a/telephony/java/android/telephony/ims/ImsServiceBase.java
+++ b/telephony/java/android/telephony/ims/ImsServiceBase.java
@@ -19,6 +19,7 @@
import android.annotation.SystemApi;
import android.app.Service;
import android.content.Intent;
+import android.os.Binder;
import android.os.IBinder;
/**
@@ -30,8 +31,15 @@
@SystemApi
public class ImsServiceBase extends Service {
+ /**
+ * Binder connection that does nothing but keep the connection between this Service and the
+ * framework active. If this service crashes, the framework will be notified.
+ */
+ private IBinder mConnection = new Binder();
+
@Override
public IBinder onBind(Intent intent) {
- return null;
+ return mConnection;
}
+
}
diff --git a/telephony/java/com/android/internal/telephony/CallerInfo.java b/telephony/java/com/android/internal/telephony/CallerInfo.java
index 5f3f773..c9c48dc 100644
--- a/telephony/java/com/android/internal/telephony/CallerInfo.java
+++ b/telephony/java/com/android/internal/telephony/CallerInfo.java
@@ -30,9 +30,9 @@
import android.provider.ContactsContract.PhoneLookup;
import android.provider.ContactsContract.RawContacts;
import android.telephony.PhoneNumberUtils;
+import android.telephony.Rlog;
import android.telephony.TelephonyManager;
import android.text.TextUtils;
-import android.telephony.Rlog;
import android.util.Log;
import com.android.i18n.phonenumbers.geocoding.PhoneNumberOfflineGeocoder;
@@ -595,7 +595,8 @@
pn = util.parse(number, countryIso);
if (VDBG) Rlog.v(TAG, "- parsed number: " + pn);
} catch (NumberParseException e) {
- Rlog.w(TAG, "getGeoDescription: NumberParseException for incoming number '" + number + "'");
+ Rlog.w(TAG, "getGeoDescription: NumberParseException for incoming number '"
+ + Rlog.pii(TAG, number) + "'");
}
if (pn != null) {
diff --git a/tests/HwAccelerationTest/src/com/android/test/hwui/ListActivity.java b/tests/HwAccelerationTest/src/com/android/test/hwui/ListActivity.java
index db6421e..0defe92 100644
--- a/tests/HwAccelerationTest/src/com/android/test/hwui/ListActivity.java
+++ b/tests/HwAccelerationTest/src/com/android/test/hwui/ListActivity.java
@@ -42,7 +42,7 @@
"Burkina Faso", "Burundi", "Cote d'Ivoire", "Cambodia", "Cameroon", "Canada", "Cape Verde",
"Cayman Islands", "Central African Republic", "Chad", "Chile", "China",
"Christmas Island", "Cocos (Keeling) Islands", "Colombia", "Comoros", "Congo",
- "Cook Islands", "Costa Rica", "Croatia", "Cuba", "Cyprus", "Czech Republic",
+ "Cook Islands", "Costa Rica", "Croatia", "Cuba", "Cyprus", "Czechia",
"Democratic Republic of the Congo", "Denmark", "Djibouti", "Dominica", "Dominican Republic",
"East Timor", "Ecuador", "Egypt", "El Salvador", "Equatorial Guinea", "Eritrea",
"Estonia", "Ethiopia", "Faeroe Islands", "Falkland Islands", "Fiji", "Finland",
diff --git a/tests/HwAccelerationTest/src/com/android/test/hwui/TransparentListActivity.java b/tests/HwAccelerationTest/src/com/android/test/hwui/TransparentListActivity.java
index 535f865..ffb8689 100644
--- a/tests/HwAccelerationTest/src/com/android/test/hwui/TransparentListActivity.java
+++ b/tests/HwAccelerationTest/src/com/android/test/hwui/TransparentListActivity.java
@@ -42,7 +42,7 @@
"Burkina Faso", "Burundi", "Cote d'Ivoire", "Cambodia", "Cameroon", "Canada", "Cape Verde",
"Cayman Islands", "Central African Republic", "Chad", "Chile", "China",
"Christmas Island", "Cocos (Keeling) Islands", "Colombia", "Comoros", "Congo",
- "Cook Islands", "Costa Rica", "Croatia", "Cuba", "Cyprus", "Czech Republic",
+ "Cook Islands", "Costa Rica", "Croatia", "Cuba", "Cyprus", "Czechia",
"Democratic Republic of the Congo", "Denmark", "Djibouti", "Dominica", "Dominican Republic",
"East Timor", "Ecuador", "Egypt", "El Salvador", "Equatorial Guinea", "Eritrea",
"Estonia", "Ethiopia", "Faeroe Islands", "Falkland Islands", "Fiji", "Finland",
diff --git a/tests/HwAccelerationTest/src/com/android/test/hwui/ViewLayersActivity.java b/tests/HwAccelerationTest/src/com/android/test/hwui/ViewLayersActivity.java
index 0ddd7fd..7168478 100644
--- a/tests/HwAccelerationTest/src/com/android/test/hwui/ViewLayersActivity.java
+++ b/tests/HwAccelerationTest/src/com/android/test/hwui/ViewLayersActivity.java
@@ -126,7 +126,7 @@
"Burkina Faso", "Burundi", "Cote d'Ivoire", "Cambodia", "Cameroon", "Canada", "Cape Verde",
"Cayman Islands", "Central African Republic", "Chad", "Chile", "China",
"Christmas Island", "Cocos (Keeling) Islands", "Colombia", "Comoros", "Congo",
- "Cook Islands", "Costa Rica", "Croatia", "Cuba", "Cyprus", "Czech Republic",
+ "Cook Islands", "Costa Rica", "Croatia", "Cuba", "Cyprus", "Czechia",
"Democratic Republic of the Congo", "Denmark", "Djibouti", "Dominica", "Dominican Republic",
"East Timor", "Ecuador", "Egypt", "El Salvador", "Equatorial Guinea", "Eritrea",
"Estonia", "Ethiopia", "Faeroe Islands", "Falkland Islands", "Fiji", "Finland",
diff --git a/tests/HwAccelerationTest/src/com/android/test/hwui/ViewLayersActivity2.java b/tests/HwAccelerationTest/src/com/android/test/hwui/ViewLayersActivity2.java
index e795f02..a037d70 100644
--- a/tests/HwAccelerationTest/src/com/android/test/hwui/ViewLayersActivity2.java
+++ b/tests/HwAccelerationTest/src/com/android/test/hwui/ViewLayersActivity2.java
@@ -76,7 +76,7 @@
"Burkina Faso", "Burundi", "Cote d'Ivoire", "Cambodia", "Cameroon", "Canada", "Cape Verde",
"Cayman Islands", "Central African Republic", "Chad", "Chile", "China",
"Christmas Island", "Cocos (Keeling) Islands", "Colombia", "Comoros", "Congo",
- "Cook Islands", "Costa Rica", "Croatia", "Cuba", "Cyprus", "Czech Republic",
+ "Cook Islands", "Costa Rica", "Croatia", "Cuba", "Cyprus", "Czechia",
"Democratic Republic of the Congo", "Denmark", "Djibouti", "Dominica", "Dominican Republic",
"East Timor", "Ecuador", "Egypt", "El Salvador", "Equatorial Guinea", "Eritrea",
"Estonia", "Ethiopia", "Faeroe Islands", "Falkland Islands", "Fiji", "Finland",
diff --git a/tests/HwAccelerationTest/src/com/android/test/hwui/ViewLayersActivity3.java b/tests/HwAccelerationTest/src/com/android/test/hwui/ViewLayersActivity3.java
index c8ae75b..e65dd63 100644
--- a/tests/HwAccelerationTest/src/com/android/test/hwui/ViewLayersActivity3.java
+++ b/tests/HwAccelerationTest/src/com/android/test/hwui/ViewLayersActivity3.java
@@ -73,7 +73,7 @@
"Burkina Faso", "Burundi", "Cote d'Ivoire", "Cambodia", "Cameroon", "Canada", "Cape Verde",
"Cayman Islands", "Central African Republic", "Chad", "Chile", "China",
"Christmas Island", "Cocos (Keeling) Islands", "Colombia", "Comoros", "Congo",
- "Cook Islands", "Costa Rica", "Croatia", "Cuba", "Cyprus", "Czech Republic",
+ "Cook Islands", "Costa Rica", "Croatia", "Cuba", "Cyprus", "Czechia",
"Democratic Republic of the Congo", "Denmark", "Djibouti", "Dominica", "Dominican Republic",
"East Timor", "Ecuador", "Egypt", "El Salvador", "Equatorial Guinea", "Eritrea",
"Estonia", "Ethiopia", "Faeroe Islands", "Falkland Islands", "Fiji", "Finland",
diff --git a/tests/HwAccelerationTest/src/com/android/test/hwui/ViewLayersActivity4.java b/tests/HwAccelerationTest/src/com/android/test/hwui/ViewLayersActivity4.java
index 6072c6e..17f78af 100644
--- a/tests/HwAccelerationTest/src/com/android/test/hwui/ViewLayersActivity4.java
+++ b/tests/HwAccelerationTest/src/com/android/test/hwui/ViewLayersActivity4.java
@@ -80,7 +80,7 @@
"Burkina Faso", "Burundi", "Cote d'Ivoire", "Cambodia", "Cameroon", "Canada", "Cape Verde",
"Cayman Islands", "Central African Republic", "Chad", "Chile", "China",
"Christmas Island", "Cocos (Keeling) Islands", "Colombia", "Comoros", "Congo",
- "Cook Islands", "Costa Rica", "Croatia", "Cuba", "Cyprus", "Czech Republic",
+ "Cook Islands", "Costa Rica", "Croatia", "Cuba", "Cyprus", "Czechia",
"Democratic Republic of the Congo", "Denmark", "Djibouti", "Dominica", "Dominican Republic",
"East Timor", "Ecuador", "Egypt", "El Salvador", "Equatorial Guinea", "Eritrea",
"Estonia", "Ethiopia", "Faeroe Islands", "Falkland Islands", "Fiji", "Finland",
diff --git a/tests/HwAccelerationTest/src/com/android/test/hwui/ViewLayersActivity5.java b/tests/HwAccelerationTest/src/com/android/test/hwui/ViewLayersActivity5.java
index cbbb7ef..2dd7b6a 100644
--- a/tests/HwAccelerationTest/src/com/android/test/hwui/ViewLayersActivity5.java
+++ b/tests/HwAccelerationTest/src/com/android/test/hwui/ViewLayersActivity5.java
@@ -145,7 +145,7 @@
"Burkina Faso", "Burundi", "Cote d'Ivoire", "Cambodia", "Cameroon", "Canada", "Cape Verde",
"Cayman Islands", "Central African Republic", "Chad", "Chile", "China",
"Christmas Island", "Cocos (Keeling) Islands", "Colombia", "Comoros", "Congo",
- "Cook Islands", "Costa Rica", "Croatia", "Cuba", "Cyprus", "Czech Republic",
+ "Cook Islands", "Costa Rica", "Croatia", "Cuba", "Cyprus", "Czechia",
"Democratic Republic of the Congo", "Denmark", "Djibouti", "Dominica", "Dominican Republic",
"East Timor", "Ecuador", "Egypt", "El Salvador", "Equatorial Guinea", "Eritrea",
"Estonia", "Ethiopia", "Faeroe Islands", "Falkland Islands", "Fiji", "Finland",
diff --git a/tests/ImfTest/src/com/android/imftest/samples/AutoCompleteTextViewActivityLandscape.java b/tests/ImfTest/src/com/android/imftest/samples/AutoCompleteTextViewActivityLandscape.java
index b659135..5ab874f 100644
--- a/tests/ImfTest/src/com/android/imftest/samples/AutoCompleteTextViewActivityLandscape.java
+++ b/tests/ImfTest/src/com/android/imftest/samples/AutoCompleteTextViewActivityLandscape.java
@@ -66,7 +66,7 @@
"Cote d'Ivoire", "Cambodia", "Cameroon", "Canada", "Cape Verde",
"Cayman Islands", "Central African Republic", "Chad", "Chile", "China",
"Christmas Island", "Cocos (Keeling) Islands", "Colombia", "Comoros", "Congo",
- "Cook Islands", "Costa Rica", "Croatia", "Cuba", "Cyprus", "Czech Republic",
+ "Cook Islands", "Costa Rica", "Croatia", "Cuba", "Cyprus", "Czechia",
"Democratic Republic of the Congo", "Denmark", "Djibouti", "Dominica", "Dominican Republic",
"East Timor", "Ecuador", "Egypt", "El Salvador", "Equatorial Guinea", "Eritrea",
"Estonia", "Ethiopia", "Faeroe Islands", "Falkland Islands", "Fiji", "Finland",
diff --git a/tests/ImfTest/src/com/android/imftest/samples/AutoCompleteTextViewActivityPortrait.java b/tests/ImfTest/src/com/android/imftest/samples/AutoCompleteTextViewActivityPortrait.java
index 5bfe456..570cb6b 100644
--- a/tests/ImfTest/src/com/android/imftest/samples/AutoCompleteTextViewActivityPortrait.java
+++ b/tests/ImfTest/src/com/android/imftest/samples/AutoCompleteTextViewActivityPortrait.java
@@ -60,7 +60,7 @@
"Cote d'Ivoire", "Cambodia", "Cameroon", "Canada", "Cape Verde",
"Cayman Islands", "Central African Republic", "Chad", "Chile", "China",
"Christmas Island", "Cocos (Keeling) Islands", "Colombia", "Comoros", "Congo",
- "Cook Islands", "Costa Rica", "Croatia", "Cuba", "Cyprus", "Czech Republic",
+ "Cook Islands", "Costa Rica", "Croatia", "Cuba", "Cyprus", "Czechia",
"Democratic Republic of the Congo", "Denmark", "Djibouti", "Dominica", "Dominican Republic",
"East Timor", "Ecuador", "Egypt", "El Salvador", "Equatorial Guinea", "Eritrea",
"Estonia", "Ethiopia", "Faeroe Islands", "Falkland Islands", "Fiji", "Finland",