summaryrefslogtreecommitdiff
path: root/framework/java/android/bluetooth/le/AdvertisingSet.java
diff options
context:
space:
mode:
authorJakub Pawlowski <jpawlowski@google.com>2017-01-10 06:15:54 -0800
committerJakub Pawlowski <jpawlowski@google.com>2017-03-08 19:04:49 +0000
commit258e43c15602c8246bc565150158b1c56e3c0814 (patch)
tree9878d62e90d16982e0ac42a0a73de0853d5a6538 /framework/java/android/bluetooth/le/AdvertisingSet.java
parent95e9c5c0f2d620f8d6bd065133b9349e1dc4b47d (diff)
Bluetooth 5 Advertising API
Test: manual Bug: 30622771 Change-Id: Id6856e6110872ec50ff1af54ddc75c0104a6459c (cherry picked from commit 5324a14cf490656269ef862d7f8f6b139a21c0e6)
Diffstat (limited to 'framework/java/android/bluetooth/le/AdvertisingSet.java')
-rw-r--r--framework/java/android/bluetooth/le/AdvertisingSet.java162
1 files changed, 162 insertions, 0 deletions
diff --git a/framework/java/android/bluetooth/le/AdvertisingSet.java b/framework/java/android/bluetooth/le/AdvertisingSet.java
new file mode 100644
index 0000000000..1524022b1f
--- /dev/null
+++ b/framework/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