Java Code Examples for android.bluetooth.BluetoothGattService#SERVICE_TYPE_SECONDARY

The following examples show how to use android.bluetooth.BluetoothGattService#SERVICE_TYPE_SECONDARY . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: GattConnectDisconnectTests.java    From bitgatt with Mozilla Public License 2.0 6 votes vote down vote up
@Test
public void gattDiscoverServicesTest() throws Exception {
    FitbitGatt.getInstance().startGattClient(mockContext);
    UUID serviceUuidOne = UUID.randomUUID();
    UUID serviceUuidTwo = UUID.randomUUID();
    final TransactionResult[] resultTx = new TransactionResult[1];
    BluetoothGattService service1 = new BluetoothGattService(serviceUuidOne, BluetoothGattService.SERVICE_TYPE_PRIMARY);
    BluetoothGattService service2 = new BluetoothGattService(serviceUuidTwo, BluetoothGattService.SERVICE_TYPE_SECONDARY);
    ArrayList<BluetoothGattService> services = new ArrayList<>();
    services.add(service1);
    services.add(service2);
    FitbitBluetoothDevice device = new FitbitBluetoothDevice(MOCK_ADDRESS, "fooDevice");
    GattConnection conn = new GattConnection(device, mockContext.getMainLooper());
    FitbitGatt.getInstance().putConnectionIntoDevices(device, conn);
    conn.setMockMode(true);
    conn.setState(GattState.IDLE);
    CountDownLatch latch = new CountDownLatch(1);
    GattClientDiscoverMockServicesTransaction discoverMockTx = new GattClientDiscoverMockServicesTransaction(conn, GattState.DISCOVERY_SUCCESS, services, false);
    conn.runTx(discoverMockTx, result -> {
        resultTx[0] = result;
        latch.countDown();
    });
    latch.await(1, TimeUnit.SECONDS);
    assertEquals(TransactionResult.TransactionResultStatus.SUCCESS, resultTx[0].resultStatus);
    assertEquals(services.size(), resultTx[0].getServices().size());
}
 
Example 2
Source File: GattConnectDisconnectTests.java    From bitgatt with Mozilla Public License 2.0 5 votes vote down vote up
@Test
public void filterConnectedDevicesAll() {
    // started
    FitbitGatt.getInstance().startGattClient(mockContext);
    Assert.assertTrue(FitbitGatt.getInstance().isInitialized());
    UUID serviceUuidOne = UUID.fromString("5F1CBF47-4A8E-467F-9E55-BAFE00839CC1");
    UUID serviceUuidTwo = UUID.fromString("528B080E-6608-403F-8F39-2246650751D0");
    BluetoothGattService service1 = new BluetoothGattService(serviceUuidOne, BluetoothGattService.SERVICE_TYPE_PRIMARY);
    BluetoothGattService service2 = new BluetoothGattService(serviceUuidTwo, BluetoothGattService.SERVICE_TYPE_SECONDARY);
    // populate fake connected devices
    for (int i = 0; i < 4; i++) {
        String address = String.format(Locale.ENGLISH, "02:00:00:00:00:1%s", Integer.toString(i));
        String name = String.format(Locale.ENGLISH, "fooDevice%s", i);
        FitbitBluetoothDevice device = new FitbitBluetoothDevice(address, name);
        GattConnection conn = new GattConnection(device, mockContext.getMainLooper());
        conn.setMockMode(true);
        // for the purpose of this test we will just set connected to true
        conn.setState(GattState.CONNECTED);
        if (i % 2 == 0) {
            conn.addService(service1);
        } else {
            conn.addService(service2);
        }
        FitbitGatt.getInstance().putConnectionIntoDevices(device, conn);
    }
    // request matching conns
    ArrayList<UUID> services = new ArrayList<>(2);
    services.add(serviceUuidOne);
    List<GattConnection> conns = FitbitGatt.getInstance().getMatchingConnectionsForServices(services);
    Assert.assertEquals(2, conns.size());
}
 
Example 3
Source File: GattDatabase.java    From AsteroidOSSync with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Builds the current {@link BluetoothGattService}, and returns the parent {@link GattDatabase}.
 */
public final GattDatabase build()
{
    m_service = new BluetoothGattService(m_serviceUuid, m_isPrimary ? BluetoothGattService.SERVICE_TYPE_PRIMARY : BluetoothGattService.SERVICE_TYPE_SECONDARY);
    for (BluetoothGattCharacteristic ch : m_characteristics)
    {
        m_service.addCharacteristic(ch);
    }
    m_database.addService(m_service);
    return m_database;
}
 
Example 4
Source File: GattDatabase.java    From SweetBlue with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Builds the current {@link BluetoothGattService}, and returns the parent {@link GattDatabase}.
 */
public final GattDatabase build()
{
    m_service = new BluetoothGattService(m_serviceUuid, m_isPrimary ? BluetoothGattService.SERVICE_TYPE_PRIMARY : BluetoothGattService.SERVICE_TYPE_SECONDARY);
    for (BluetoothGattCharacteristic ch : m_characteristics)
    {
        m_service.addCharacteristic(ch);
    }
    m_database.addService(m_service);
    return m_database;
}
 
Example 5
Source File: GattDatabase.java    From SweetBlue with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Builds the current {@link BluetoothGattService}, and returns the parent {@link GattDatabase}.
 */
public final GattDatabase build()
{
    m_service = new BluetoothGattService(m_serviceUuid, m_isPrimary ? BluetoothGattService.SERVICE_TYPE_PRIMARY : BluetoothGattService.SERVICE_TYPE_SECONDARY);
    for (BluetoothGattCharacteristic ch : m_characteristics)
    {
        m_service.addCharacteristic(ch);
    }
    m_database.addService(m_service);
    return m_database;
}
 
Example 6
Source File: GattPlugin.java    From bitgatt with Mozilla Public License 2.0 4 votes vote down vote up
private void showGattServerServices(DumperContext dumpContext) {
    int n = 106;
    StringBuilder builder = new StringBuilder();
    String status = PASS_STATUS;
    String error = "";
    if (!isJsonFormat) {
        for (int i = 0; i < n; i++) {
            builder.append("=");
        }
        log(dumpContext, builder.toString());
        format(dumpContext, "| %1$32s | %2$32s |\n",
            "Service UUID",
            "Type");
    }
    String serviceUuid;
    String type;
    BluetoothGattServer server = fitbitGatt.getServer().getServer();
    List<BluetoothGattService> services = server.getServices();
    JSONArray jsonArray = new JSONArray();
    try {
        for (BluetoothGattService service : services) {
            serviceUuid = service.getUuid().toString();
            switch (service.getType()) {
                case BluetoothGattService.SERVICE_TYPE_PRIMARY:
                    type = "primary";
                    break;
                case BluetoothGattService.SERVICE_TYPE_SECONDARY:
                    type = "secondary";
                    break;
                default:
                    type = "unknown";
            }
            if (!isJsonFormat) {
                format(dumpContext, "| %1$32s | %2$32s |\n", serviceUuid, type);
            } else {
                Map<String, Object> map = new LinkedHashMap<String, Object>();
                map.put(RESULT_SERVICE_UUID_KEY, serviceUuid);
                map.put(RESULT_SERVICE_TYPE_KEY, type);
                JSONObject jsonObject = makeJsonObject(map);
                jsonArray.put(jsonObject);
            }
        }
    } catch (Exception e) {
        status = FAIL_STATUS;
        error = Arrays.toString(e.getStackTrace());
    }

    builder = new StringBuilder();
    if (!isJsonFormat) {
        for (int i = 0; i < n; i++) {
            builder.append("=");
        }
        log(dumpContext, builder.toString());
    } else {
        logJsonResult(dumpContext, status, error, jsonArray);
    }
}