static jmethodID method_onScanParamSetupCompleted;
static jmethodID method_getSampleGattDbElement;
static jmethodID method_onGetGattDb;
+static jmethodID method_onClientPhyUpdate;
+static jmethodID method_onClientPhyRead;
/**
* Server callback methods
static jmethodID method_onNotificationSent;
static jmethodID method_onServerCongestion;
static jmethodID method_onServerMtuChanged;
+static jmethodID method_onServerPhyUpdate;
+static jmethodID method_onServerPhyRead;
/**
* Advertiser callback methods
array.get());
}
+void btgattc_phy_updated_cb(int conn_id, uint8_t tx_phy, uint8_t rx_phy,
+ uint8_t status) {
+ CallbackEnv sCallbackEnv(__func__);
+ if (!sCallbackEnv.valid()) return;
+
+ info("ASDFASDFADSFDSAFDS");
+ sCallbackEnv->CallVoidMethod(mCallbacksObj, method_onClientPhyUpdate, conn_id,
+ tx_phy, rx_phy, status);
+}
+
static const btgatt_scanner_callbacks_t sGattScannerCallbacks = {
btgattc_scan_result_cb,
btgattc_batchscan_reports_cb,
btgattc_congestion_cb,
btgattc_get_gatt_db_cb,
NULL, /* services_removed_cb */
- NULL /* services_added_cb */
-};
+ NULL, /* services_added_cb */
+ btgattc_phy_updated_cb};
/**
* BTA server callbacks
conn_id, mtu);
}
+void btgatts_phy_updated_cb(int conn_id, uint8_t tx_phy, uint8_t rx_phy,
+ uint8_t status) {
+ CallbackEnv sCallbackEnv(__func__);
+ if (!sCallbackEnv.valid()) return;
+
+ sCallbackEnv->CallVoidMethod(mCallbacksObj, method_onServerPhyUpdate, conn_id,
+ tx_phy, rx_phy, status);
+}
+
static const btgatt_server_callbacks_t sGattServerCallbacks = {
btgatts_register_app_cb,
btgatts_connection_cb,
btgatts_response_confirmation_cb,
btgatts_indication_sent_cb,
btgatts_congestion_cb,
- btgatts_mtu_changed_cb};
+ btgatts_mtu_changed_cb,
+ btgatts_phy_updated_cb};
/**
* GATT callbacks
"()Lcom/android/bluetooth/gatt/GattDbElement;");
method_onGetGattDb =
env->GetMethodID(clazz, "onGetGattDb", "(ILjava/util/ArrayList;)V");
+ method_onClientPhyRead =
+ env->GetMethodID(clazz, "onClientPhyRead", "(IIII)V");
+ method_onClientPhyUpdate =
+ env->GetMethodID(clazz, "onClientPhyUpdate", "(IIII)V");
// Server callbacks
method_onServerCongestion =
env->GetMethodID(clazz, "onServerCongestion", "(IZ)V");
method_onServerMtuChanged = env->GetMethodID(clazz, "onMtuChanged", "(II)V");
+ method_onServerPhyRead =
+ env->GetMethodID(clazz, "onServerPhyRead", "(IIII)V");
+ method_onServerPhyUpdate =
+ env->GetMethodID(clazz, "onServerPhyUpdate", "(IIII)V");
info("classInitNative: Success!");
}
sGattIf->client->disconnect(clientIf, &bda, conn_id);
}
+static void gattClientSetPreferredPhyNative(JNIEnv* env, jobject object,
+ jint clientIf, jint conn_id,
+ jint tx_phy, jint rx_phy,
+ jint phy_options) {
+ if (!sGattIf) return;
+ sGattIf->client->set_preferred_phy(conn_id, tx_phy, rx_phy, phy_options);
+}
+
+static void readClientPhyCb(int conn_id, uint8_t tx_phy, uint8_t rx_phy,
+ uint8_t status) {
+ CallbackEnv sCallbackEnv(__func__);
+ if (!sCallbackEnv.valid()) return;
+
+ sCallbackEnv->CallVoidMethod(mCallbacksObj, method_onClientPhyRead, conn_id,
+ tx_phy, rx_phy, status);
+}
+
+static void gattClientReadPhyNative(JNIEnv* env, jobject object, jint clientIf,
+ jint conn_id) {
+ if (!sGattIf) return;
+ sGattIf->client->read_phy(conn_id, base::Bind(readClientPhyCb, conn_id));
+}
+
static void gattClientRefreshNative(JNIEnv* env, jobject object, jint clientIf,
jstring address) {
if (!sGattIf) return;
sGattIf->server->disconnect(serverIf, &bda, conn_id);
}
+static void gattServerSetPreferredPhyNative(JNIEnv* env, jobject object,
+ jint serverIf, jint conn_id,
+ jint tx_phy, jint rx_phy,
+ jint phy_options) {
+ if (!sGattIf) return;
+ sGattIf->server->set_preferred_phy(conn_id, tx_phy, rx_phy, phy_options);
+}
+
+static void readServerPhyCb(int conn_id, uint8_t tx_phy, uint8_t rx_phy,
+ uint8_t status) {
+ CallbackEnv sCallbackEnv(__func__);
+ if (!sCallbackEnv.valid()) return;
+
+ sCallbackEnv->CallVoidMethod(mCallbacksObj, method_onServerPhyRead, conn_id,
+ tx_phy, rx_phy, status);
+}
+
+static void gattServerReadPhyNative(JNIEnv* env, jobject object, jint serverIf,
+ jint conn_id) {
+ if (!sGattIf) return;
+ sGattIf->server->read_phy(conn_id, base::Bind(readServerPhyCb, conn_id));
+}
+
static void gattServerAddServiceNative(JNIEnv* env, jobject object,
jint server_if,
jobject gatt_db_elements) {
(void*)gattClientConnectNative},
{"gattClientDisconnectNative", "(ILjava/lang/String;I)V",
(void*)gattClientDisconnectNative},
+ {"gattClientSetPreferredPhyNative", "(IIIII)V",
+ (void*)gattClientSetPreferredPhyNative},
+ {"gattClientReadPhyNative", "(II)V", (void*)gattClientReadPhyNative},
{"gattClientRefreshNative", "(ILjava/lang/String;)V",
(void*)gattClientRefreshNative},
{"gattClientSearchServiceNative", "(IZJJ)V",
(void*)gattServerConnectNative},
{"gattServerDisconnectNative", "(ILjava/lang/String;I)V",
(void*)gattServerDisconnectNative},
+ {"gattServerSetPreferredPhyNative", "(IIIII)V",
+ (void*)gattServerSetPreferredPhyNative},
+ {"gattServerReadPhyNative", "(II)V", (void*)gattServerReadPhyNative},
{"gattServerAddServiceNative", "(ILjava/util/List;)V",
(void*)gattServerAddServiceNative},
{"gattServerStopServiceNative", "(II)V",
service.flushPendingBatchResults(scannerId);
}
+ @Override
public void clientConnect(
int clientIf, String address, boolean isDirect, int transport, int phy) {
GattService service = getService();
service.clientConnect(clientIf, address, isDirect, transport, phy);
}
+ @Override
public void clientDisconnect(int clientIf, String address) {
GattService service = getService();
if (service == null) return;
service.clientDisconnect(clientIf, address);
}
+ @Override
public void clientSetPreferredPhy(
int clientIf, String address, int txPhy, int rxPhy, int phyOptions) {
GattService service = getService();
if (service == null) return;
- // TODO(jpawlowski): implement
+ service.clientSetPreferredPhy(clientIf, address, txPhy, rxPhy, phyOptions);
}
+ @Override
public void clientReadPhy(int clientIf, String address) {
GattService service = getService();
if (service == null) return;
- // TODO(jpawlowski): implement
+ service.clientReadPhy(clientIf, address);
}
public void refreshDevice(int clientIf, String address) {
int serverIf, String address, int txPhy, int rxPhy, int phyOptions) {
GattService service = getService();
if (service == null) return;
- // TODO(jpawlowski): implement
+ service.serverSetPreferredPhy(serverIf, address, txPhy, rxPhy, phyOptions);
}
public void serverReadPhy(int clientIf, String address) {
GattService service = getService();
if (service == null) return;
- // TODO(jpawlowski): implement
+ service.serverReadPhy(clientIf, address);
}
public void addService(int serverIf, BluetoothGattService svc) {
}
}
+ void onClientPhyUpdate(int connId, int txPhy, int rxPhy, int status) throws RemoteException {
+ if (DBG) Log.d(TAG, "onClientPhyUpdate() - connId=" + connId + ", status=" + status);
+
+ String address = mClientMap.addressByConnId(connId);
+ if (address == null) return;
+
+ ClientMap.App app = mClientMap.getByConnId(connId);
+ if (app == null) return;
+
+ app.callback.onPhyUpdate(address, txPhy, rxPhy, status);
+ }
+
+ void onClientPhyRead(int connId, int txPhy, int rxPhy, int status) throws RemoteException {
+ if (DBG) Log.d(TAG, "onClientPhyRead() - connId=" + connId + ", status=" + status);
+
+ String address = mClientMap.addressByConnId(connId);
+ if (address == null) return;
+
+ ClientMap.App app = mClientMap.getByConnId(connId);
+ if (app == null) return;
+
+ app.callback.onPhyRead(address, txPhy, rxPhy, status);
+ }
+
+ void onServerPhyUpdate(int connId, int txPhy, int rxPhy, int status) throws RemoteException {
+ if (DBG) Log.d(TAG, "onServerPhyUpdate() - connId=" + connId + ", status=" + status);
+
+ String address = mServerMap.addressByConnId(connId);
+ if (address == null) return;
+
+ ServerMap.App app = mServerMap.getByConnId(connId);
+ if (app == null) return;
+
+ app.callback.onPhyUpdate(address, txPhy, rxPhy, status);
+ }
+
+ void onServerPhyRead(int connId, int txPhy, int rxPhy, int status) throws RemoteException {
+ if (DBG) Log.d(TAG, "onServerPhyRead() - connId=" + connId + ", status=" + status);
+
+ String address = mServerMap.addressByConnId(connId);
+ if (address == null) return;
+
+ ServerMap.App app = mServerMap.getByConnId(connId);
+ if (app == null) return;
+
+ app.callback.onPhyRead(address, txPhy, rxPhy, status);
+ }
+
void onSearchCompleted(int connId, int status) throws RemoteException {
if (DBG) Log.d(TAG, "onSearchCompleted() - connId=" + connId+ ", status=" + status);
// Gatt DB is ready!
gattClientDisconnectNative(clientIf, address, connId != null ? connId : 0);
}
+ void clientSetPreferredPhy(int clientIf, String address, int txPhy, int rxPhy, int phyOptions) {
+ enforceCallingOrSelfPermission(BLUETOOTH_PERM, "Need BLUETOOTH permission");
+
+ Integer connId = mClientMap.connIdByAddress(clientIf, address);
+ if (connId == null) {
+ Log.d(TAG, "clientSetPreferredPhy() - no connection to " + address);
+ return;
+ }
+
+ if (DBG) Log.d(TAG, "clientSetPreferredPhy() - address=" + address + ", connId=" + connId);
+ gattClientSetPreferredPhyNative(clientIf, connId, txPhy, rxPhy, phyOptions);
+ }
+
+ void clientReadPhy(int clientIf, String address) {
+ enforceCallingOrSelfPermission(BLUETOOTH_PERM, "Need BLUETOOTH permission");
+
+ Integer connId = mClientMap.connIdByAddress(clientIf, address);
+ if (connId == null) {
+ Log.d(TAG, "clientReadPhy() - no connection to " + address);
+ return;
+ }
+
+ if (DBG) Log.d(TAG, "clientReadPhy() - address=" + address + ", connId=" + connId);
+ gattClientReadPhyNative(clientIf, connId);
+ }
+
int numHwTrackFiltersAvailable() {
return (AdapterService.getAdapterService().getTotalNumOfTrackableAdvertisements()
- mScanManager.getCurrentUsedTrackingAdvertisement());
gattServerDisconnectNative(serverIf, address, connId != null ? connId : 0);
}
+ void serverSetPreferredPhy(int serverIf, String address, int txPhy, int rxPhy, int phyOptions) {
+ enforceCallingOrSelfPermission(BLUETOOTH_PERM, "Need BLUETOOTH permission");
+
+ Integer connId = mServerMap.connIdByAddress(serverIf, address);
+ if (connId == null) {
+ Log.d(TAG, "serverSetPreferredPhy() - no connection to " + address);
+ return;
+ }
+
+ if (DBG) Log.d(TAG, "serverSetPreferredPhy() - address=" + address + ", connId=" + connId);
+ gattServerSetPreferredPhyNative(serverIf, connId, txPhy, rxPhy, phyOptions);
+ }
+
+ void serverReadPhy(int serverIf, String address) {
+ enforceCallingOrSelfPermission(BLUETOOTH_PERM, "Need BLUETOOTH permission");
+
+ Integer connId = mServerMap.connIdByAddress(serverIf, address);
+ if (connId == null) {
+ Log.d(TAG, "serverReadPhy() - no connection to " + address);
+ return;
+ }
+
+ if (DBG) Log.d(TAG, "serverReadPhy() - address=" + address + ", connId=" + connId);
+ gattServerReadPhyNative(serverIf, connId);
+ }
+
void addService(int serverIf, BluetoothGattService service) {
enforceCallingOrSelfPermission(BLUETOOTH_PERM, "Need BLUETOOTH permission");
private native void gattClientDisconnectNative(int clientIf, String address,
int conn_id);
+ private native void gattClientSetPreferredPhyNative(
+ int clientIf, int conn_id, int tx_phy, int rx_phy, int phy_options);
+
+ private native void gattClientReadPhyNative(int clientIf, int conn_id);
+
private native void gattClientRefreshNative(int clientIf, String address);
private native void gattClientSearchServiceNative(int conn_id,
private native void gattServerDisconnectNative(int serverIf, String address,
int conn_id);
+ private native void gattServerSetPreferredPhyNative(
+ int clientIf, int conn_id, int tx_phy, int rx_phy, int phy_options);
+
+ private native void gattServerReadPhyNative(int clientIf, int conn_id);
+
private native void gattServerAddServiceNative(int server_if, List<GattDbElement> service);
private native void gattServerStopServiceNative (int server_if,