Java Code Examples for android.bluetooth.BluetoothGattServer

The following are top voted examples for showing how to use android.bluetooth.BluetoothGattServer. These examples are extracted from open source projects. You can vote up the examples you like and your votes will be used in our system to generate more good examples.
Example 1
Project: AsteroidOSSync   File: P_NativeServerWrapper.java   Source Code and License 7 votes vote down vote up
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;
		}
	}
}
 
Example 2
Project: SweetBlue   File: P_NativeServerWrapper.java   Source Code and License 6 votes vote down vote up
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;
		}
	}
}
 
Example 3
Project: mesh-core-on-android   File: JniCallbacks.java   Source Code and License 5 votes vote down vote up
PeerDevice(BluetoothGattServer server) {
	mConnectionState = STATE_DISCONNECTED;
	mPeerRole = ROLE_CLIENT;
	mGattServer = server;
	mSending = false;
	mSendList = null;
}
 
Example 4
Project: AsteroidOSSync   File: P_NativeServerWrapper.java   Source Code and License 5 votes vote down vote up
public final int getNativeState(final String macAddress)
{
	if( m_nativeConnectionStates.containsKey(macAddress) )
	{
		return m_nativeConnectionStates.get(macAddress);
	}
	else
	{
		return BluetoothGattServer.STATE_DISCONNECTED;
	}
}
 
Example 5
Project: AsteroidOSSync   File: PA_Task_RequiresServerConnection.java   Source Code and License 5 votes vote down vote up
@Override protected boolean isExecutable()
{
	boolean shouldBeExecutable = super.isExecutable() && getServer().m_nativeWrapper.getNativeState(m_macAddress) == BluetoothGattServer.STATE_CONNECTED;
	
	if( shouldBeExecutable )
	{
		return true;
	}
	
	return false;
}
 
Example 6
Project: ble-test-peripheral-android   File: Peripheral.java   Source Code and License 5 votes vote down vote up
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);
    }
  });
}
 
Example 7
Project: ble-test-peripheral-android   File: Peripheral.java   Source Code and License 5 votes vote down vote up
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);
  }
}
 
Example 8
Project: SweetBlue   File: P_NativeServerWrapper.java   Source Code and License 5 votes vote down vote up
public final int getNativeState(final String macAddress)
{
	if( m_nativeConnectionStates.containsKey(macAddress) )
	{
		return m_nativeConnectionStates.get(macAddress);
	}
	else
	{
		return BluetoothGattServer.STATE_DISCONNECTED;
	}
}
 
Example 9
Project: SweetBlue   File: PA_Task_RequiresServerConnection.java   Source Code and License 5 votes vote down vote up
@Override protected boolean isExecutable()
{
	boolean shouldBeExecutable = super.isExecutable() && getServer().m_nativeWrapper.getNativeState(m_macAddress) == BluetoothGattServer.STATE_CONNECTED;
	
	if( shouldBeExecutable )
	{
		return true;
	}
	
	return false;
}
 
Example 10
Project: BGSEP   File: HIDoverGattProfile.java   Source Code and License 5 votes vote down vote up
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;
}
 
Example 11
Project: mesh-core-on-android   File: JniCallbacks.java   Source Code and License 4 votes vote down vote up
public BluetoothGattServer getGattServer() {
		return mGattServer;
}
 
Example 12
Project: android-bluetooth-current-time-service   File: CurrentTimeService.java   Source Code and License 4 votes vote down vote up
void setGattServer(BluetoothGattServer gattServer) {
    mGattServer = gattServer;
}
 
Example 13
Project: AsteroidOSSync   File: UnitTestServerLayer.java   Source Code and License 4 votes vote down vote up
@Override
public BluetoothGattServer getNativeServer()
{
    return null;
}
 
Example 14
Project: AsteroidOSSync   File: P_NativeServerWrapper.java   Source Code and License 4 votes vote down vote up
public final boolean isDisconnecting(final String macAddress)
{
	return getNativeState(macAddress) == BluetoothGattServer.STATE_DISCONNECTING;
}
 
Example 15
Project: AsteroidOSSync   File: P_NativeServerWrapper.java   Source Code and License 4 votes vote down vote up
public final boolean isDisconnected(final String macAddress)
{
	return getNativeState(macAddress) == BluetoothGattServer.STATE_DISCONNECTED;
}
 
Example 16
Project: AsteroidOSSync   File: P_NativeServerWrapper.java   Source Code and License 4 votes vote down vote up
public final boolean isConnected(final String macAddress)
{
	return getNativeState(macAddress) == BluetoothGattServer.STATE_CONNECTED;
}
 
Example 17
Project: AsteroidOSSync   File: P_NativeServerWrapper.java   Source Code and License 4 votes vote down vote up
public final boolean isConnecting(final String macAddress)
{
	return getNativeState(macAddress) == BluetoothGattServer.STATE_CONNECTING;
}
 
Example 18
Project: AsteroidOSSync   File: P_NativeServerWrapper.java   Source Code and License 4 votes vote down vote up
public final boolean isConnectingOrConnected(final String macAddress)
{
	final int  nativeState = getNativeState(macAddress);

	return nativeState == BluetoothGattServer.STATE_CONNECTING || nativeState == BluetoothGattServer.STATE_CONNECTED;
}
 
Example 19
Project: AsteroidOSSync   File: P_NativeServerWrapper.java   Source Code and License 4 votes vote down vote up
public final boolean isDisconnectingOrDisconnected(final String macAddress)
{
	final int  nativeState = getNativeState(macAddress);

	return nativeState == BluetoothGattServer.STATE_DISCONNECTING || nativeState == BluetoothGattServer.STATE_DISCONNECTED;
}
 
Example 20
Project: AsteroidOSSync   File: BleServer.java   Source Code and License 4 votes vote down vote up
/**
 * 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();
}
 
Example 21
Project: AsteroidOSSync   File: P_AndroidBleServer.java   Source Code and License 4 votes vote down vote up
P_AndroidBleServer(BluetoothGattServer server)
{
    m_server = server;
}
 
Example 22
Project: AsteroidOSSync   File: P_AndroidBleServer.java   Source Code and License 4 votes vote down vote up
@Override
public final BluetoothGattServer getNativeServer()
{
    return m_server;
}
 
Example 23
Project: BLE-Mesh   File: BLEGattServer.java   Source Code and License 4 votes vote down vote up
public BluetoothGattServer getGattServer() {
    return gattServer;
}
 
Example 24
Project: beacons-android   File: EddystoneGattService.java   Source Code and License 4 votes vote down vote up
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);
    }
 
Example 25
Project: swan-sense-studio   File: BLEManager.java   Source Code and License 4 votes vote down vote up
public ExecAddService(BluetoothGattServer bleServer, BluetoothGattService service) {
    this.bleServer = bleServer;
    this.service = service;
}
 
Example 26
Project: swan-sense-studio   File: BLEManager.java   Source Code and License 4 votes vote down vote up
protected BluetoothGattServer getBleServer() {
    return bleServer;
}
 
Example 27
Project: swan-sense-studio   File: BLEClientWorker.java   Source Code and License 4 votes vote down vote up
public ExecAddService(BluetoothGattServer bleServer, BluetoothGattService service) {
    this.bleServer = bleServer;
    this.service = service;
}
 
Example 28
Project: SweetBlue   File: UnitTestServerLayer.java   Source Code and License 4 votes vote down vote up
@Override
public BluetoothGattServer getNativeServer()
{
    return null;
}
 
Example 29
Project: SweetBlue   File: P_NativeServerWrapper.java   Source Code and License 4 votes vote down vote up
public final boolean isDisconnecting(final String macAddress)
{
	return getNativeState(macAddress) == BluetoothGattServer.STATE_DISCONNECTING;
}
 
Example 30
Project: SweetBlue   File: P_NativeServerWrapper.java   Source Code and License 4 votes vote down vote up
public final boolean isDisconnected(final String macAddress)
{
	return getNativeState(macAddress) == BluetoothGattServer.STATE_DISCONNECTED;
}
 
Example 31
Project: SweetBlue   File: P_NativeServerWrapper.java   Source Code and License 4 votes vote down vote up
public final boolean isConnected(final String macAddress)
{
	return getNativeState(macAddress) == BluetoothGattServer.STATE_CONNECTED;
}
 
Example 32
Project: SweetBlue   File: P_NativeServerWrapper.java   Source Code and License 4 votes vote down vote up
public final boolean isConnecting(final String macAddress)
{
	return getNativeState(macAddress) == BluetoothGattServer.STATE_CONNECTING;
}
 
Example 33
Project: SweetBlue   File: P_NativeServerWrapper.java   Source Code and License 4 votes vote down vote up
public final boolean isConnectingOrConnected(final String macAddress)
{
	final int  nativeState = getNativeState(macAddress);

	return nativeState == BluetoothGattServer.STATE_CONNECTING || nativeState == BluetoothGattServer.STATE_CONNECTED;
}
 
Example 34
Project: SweetBlue   File: P_NativeServerWrapper.java   Source Code and License 4 votes vote down vote up
public final boolean isDisconnectingOrDisconnected(final String macAddress)
{
	final int  nativeState = getNativeState(macAddress);

	return nativeState == BluetoothGattServer.STATE_DISCONNECTING || nativeState == BluetoothGattServer.STATE_DISCONNECTED;
}
 
Example 35
Project: SweetBlue   File: BleServer.java   Source Code and License 4 votes vote down vote up
/**
 * 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();
}
 
Example 36
Project: SweetBlue   File: P_AndroidBleServer.java   Source Code and License 4 votes vote down vote up
P_AndroidBleServer(BluetoothGattServer server)
{
    m_server = server;
}
 
Example 37
Project: SweetBlue   File: P_AndroidBleServer.java   Source Code and License 4 votes vote down vote up
@Override
public final BluetoothGattServer getNativeServer()
{
    return m_server;
}
 
Example 38
Project: Bluebit   File: AospGattServer.java   Source Code and License 4 votes vote down vote up
public AospGattServer(BluetoothGattServer srv) {
    mGattSrv = srv;
}
 
Example 39
Project: BLEServerSimple   File: AdvertiseAdaptor.java   Source Code and License 3 votes vote down vote up
@TargetApi(Build.VERSION_CODES.JELLY_BEAN_MR2)
private BluetoothGattServer getGattServer(Context context, BluetoothManager manager) {
    return manager.openGattServer(context, mBLEServerAdaptor);
}
 
Example 40
Project: AsteroidOSSync   File: P_NativeServerLayer.java   Source Code and License votes vote down vote up
BluetoothGattServer getNativeServer(); 
Example 41
Project: SweetBlue   File: P_NativeServerLayer.java   Source Code and License votes vote down vote up
BluetoothGattServer getNativeServer();