private void assertThatAllClientsAreDisconnected() { if( m_nativeConnectionStates.size() == 0 ) return; for( String macAddress : m_nativeConnectionStates.keySet() ) { final Integer state = m_nativeConnectionStates.get(macAddress); if( state != null && state != BluetoothGattServer.STATE_DISCONNECTED ) { m_mngr.ASSERT(false, "Found a server connection state that is not disconnected when it should be."); return; } } }
PeerDevice(BluetoothGattServer server) { mConnectionState = STATE_DISCONNECTED; mPeerRole = ROLE_CLIENT; mGattServer = server; mSending = false; mSendList = null; }
public final int getNativeState(final String macAddress) { if( m_nativeConnectionStates.containsKey(macAddress) ) { return m_nativeConnectionStates.get(macAddress); } else { return BluetoothGattServer.STATE_DISCONNECTED; } }
@Override protected boolean isExecutable() { boolean shouldBeExecutable = super.isExecutable() && getServer().m_nativeWrapper.getNativeState(m_macAddress) == BluetoothGattServer.STATE_CONNECTED; if( shouldBeExecutable ) { return true; } return false; }
private void updateConnectedDevicesStatus() { final String message = getString(R.string.status_devicesConnected) + " " + mBluetoothManager.getConnectedDevices(BluetoothGattServer.GATT).size(); runOnUiThread(new Runnable() { @Override public void run() { mConnectionStatus.setText(message); } }); }
private void disconnectFromDevices() { Log.d(TAG, "Disconnecting devices..."); for (BluetoothDevice device : mBluetoothManager.getConnectedDevices( BluetoothGattServer.GATT)) { Log.d(TAG, "Devices: " + device.getAddress() + " " + device.getName()); mGattServer.cancelConnection(device); } }
public boolean addProfileToGATTServer(BluetoothGattServer server) { boolean fail = false; try { Thread.sleep(2000); } catch (InterruptedException e2) { e2.printStackTrace(); } if (!server.addService(batteryService)) { fail = true; Log.d(TAG, "fail adding BatteryService"); } else { Log.d(TAG, "added BatteryService"); } try { Thread.sleep(2000); } catch (InterruptedException e1) { e1.printStackTrace(); } if (!server.addService(HIDService)) { fail = true; Log.d(TAG, "fail adding HIDService"); } else { Log.d(TAG, "added HIDService"); } try { Thread.sleep(2000); } catch (InterruptedException e) { e.printStackTrace(); } if (!server.addService(deviceInfoService)) { fail = true; Log.d(TAG, "fail adding DeviceInfoService"); } else { Log.d(TAG, "added DeviceInfoService"); } return !fail; }
public BluetoothGattServer getGattServer() { return mGattServer; }
void setGattServer(BluetoothGattServer gattServer) { mGattServer = gattServer; }
@Override public BluetoothGattServer getNativeServer() { return null; }
public final boolean isDisconnecting(final String macAddress) { return getNativeState(macAddress) == BluetoothGattServer.STATE_DISCONNECTING; }
public final boolean isDisconnected(final String macAddress) { return getNativeState(macAddress) == BluetoothGattServer.STATE_DISCONNECTED; }
public final boolean isConnected(final String macAddress) { return getNativeState(macAddress) == BluetoothGattServer.STATE_CONNECTED; }
public final boolean isConnecting(final String macAddress) { return getNativeState(macAddress) == BluetoothGattServer.STATE_CONNECTING; }
public final boolean isConnectingOrConnected(final String macAddress) { final int nativeState = getNativeState(macAddress); return nativeState == BluetoothGattServer.STATE_CONNECTING || nativeState == BluetoothGattServer.STATE_CONNECTED; }
public final boolean isDisconnectingOrDisconnected(final String macAddress) { final int nativeState = getNativeState(macAddress); return nativeState == BluetoothGattServer.STATE_DISCONNECTING || nativeState == BluetoothGattServer.STATE_DISCONNECTED; }
/** * Provides just-in-case lower-level access to the native server instance. * See similar warning for {@link BleDevice#getNative()}. */ @Advanced public final @Nullable(Nullable.Prevalence.RARE) BluetoothGattServer getNative() { return m_nativeWrapper.getNative().getNativeServer(); }
P_AndroidBleServer(BluetoothGattServer server) { m_server = server; }
@Override public final BluetoothGattServer getNativeServer() { return m_server; }
public BluetoothGattServer getGattServer() { return gattServer; }
public void readCharacteristic(BluetoothGattServer gattServer, BluetoothDevice device, int requestId, int offset, BluetoothGattCharacteristic characteristic) { // UUID uuid = characteristic.getUuid(); int status = BluetoothGatt.GATT_SUCCESS; if (isLocked()) { if (characteristic == mUnlockCharacteristic) { log("Generating secure unlock challenge"); characteristic.setValue(new byte[16]); new SecureRandom().nextBytes(characteristic.getValue()); } else { if (characteristic != mLockStateCharacteristic) { status = BluetoothGatt.GATT_READ_NOT_PERMITTED; } } } else if (characteristic == mUnlockCharacteristic) { status = BluetoothGatt.GATT_READ_NOT_PERMITTED; } else if (characteristic == mPublicEcdhKeyCharacteristic) { log("ECDH Public Key was requested"); if (0 == offset) { characteristic.setValue(null == mEidKeyPair ? new byte[0] : mEidKeyPair.getPublicKey()); } } else if (characteristic == mAdvSlotDataCharacteristic) { log("Advertisement slot data requested"); characteristic.setValue(mConfigCallback.getAdvertisedData()); } else if (characteristic == mEidIdentityKeyCharacteristic) { log("Identity Key was requested"); byte[] identityKey = mConfigCallback.getEidIdentityKey(); if (null == identityKey) { status = BluetoothGatt.GATT_FAILURE; } else { characteristic.setValue(aes_transform(true, identityKey, 0, 16)); } } gattServer.sendResponse(device, requestId, status, offset, status == BluetoothGatt.GATT_SUCCESS ? Arrays.copyOfRange(characteristic.getValue(), offset, characteristic.getValue().length) : null); }
public ExecAddService(BluetoothGattServer bleServer, BluetoothGattService service) { this.bleServer = bleServer; this.service = service; }
protected BluetoothGattServer getBleServer() { return bleServer; }
public AospGattServer(BluetoothGattServer srv) { mGattSrv = srv; }
@TargetApi(Build.VERSION_CODES.JELLY_BEAN_MR2) private BluetoothGattServer getGattServer(Context context, BluetoothManager manager) { return manager.openGattServer(context, mBLEServerAdaptor); }
BluetoothGattServer getNativeServer();