forked from chromium/chromium
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
bluetooth: android: BluetoothRemoteGattServiceAndroid::GetUUID
Create a Java class ChromeBluetoothRemoteGattService to implement BluetoothRemoteGattServiceAndroid, and implement GetUUID. Correct mistaken implementation of instanceID. Android's getInstanceId is only unique for services with the same UUID, so a device unique instance ID must join the UUID and Android's getInstanceId. Add the ability for tests to create services by providing a vector of UUID strings. BUG=541400 Review URL: https://codereview.chromium.org/1395783005 Cr-Commit-Position: refs/heads/master@{#354420}
- Loading branch information
Showing
17 changed files
with
189 additions
and
28 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
46 changes: 46 additions & 0 deletions
46
...ooth/android/java/src/org/chromium/device/bluetooth/ChromeBluetoothRemoteGattService.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
// Copyright 2015 The Chromium Authors. All rights reserved. | ||
// Use of this source code is governed by a BSD-style license that can be | ||
// found in the LICENSE file. | ||
|
||
package org.chromium.device.bluetooth; | ||
|
||
import org.chromium.base.Log; | ||
import org.chromium.base.annotations.CalledByNative; | ||
import org.chromium.base.annotations.JNINamespace; | ||
|
||
/** | ||
* Exposes android.bluetooth.BluetoothGattService as necessary | ||
* for C++ device::BluetoothRemoteGattServiceAndroid. | ||
* | ||
* Lifetime is controlled by | ||
* device::BluetoothRemoteGattServiceAndroid. | ||
*/ | ||
@JNINamespace("device") | ||
final class ChromeBluetoothRemoteGattService { | ||
private static final String TAG = "Bluetooth"; | ||
|
||
final Wrappers.BluetoothGattServiceWrapper mService; | ||
|
||
private ChromeBluetoothRemoteGattService(Wrappers.BluetoothGattServiceWrapper serviceWrapper) { | ||
mService = serviceWrapper; | ||
Log.v(TAG, "ChromeBluetoothRemoteGattService created."); | ||
} | ||
|
||
// --------------------------------------------------------------------------------------------- | ||
// BluetoothRemoteGattServiceAndroid methods implemented in java: | ||
|
||
// Implements BluetoothRemoteGattServiceAndroid::Create. | ||
// 'Object' type must be used because inner class Wrappers.BluetoothGattServiceWrapper reference | ||
// is not handled by jni_generator.py JavaToJni. http://crbug.com/505554 | ||
@CalledByNative | ||
private static ChromeBluetoothRemoteGattService create(Object serviceWrapper) { | ||
return new ChromeBluetoothRemoteGattService( | ||
(Wrappers.BluetoothGattServiceWrapper) serviceWrapper); | ||
} | ||
|
||
// Implements BluetoothRemoteGattServiceAndroid::GetUUID. | ||
@CalledByNative | ||
private String getUUID() { | ||
return mService.getUuid().toString(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
// Copyright 2014 The Chromium Authors. All rights reserved. | ||
// Use of this source code is governed by a BSD-style license that can be | ||
// found in the LICENSE file. | ||
|
||
#include "device/bluetooth/bluetooth_gatt_service.h" | ||
|
||
#include "testing/gtest/include/gtest/gtest.h" | ||
|
||
#if defined(OS_ANDROID) | ||
#include "device/bluetooth/test/bluetooth_test_android.h" | ||
#elif defined(OS_MACOSX) | ||
#include "device/bluetooth/test/bluetooth_test_mac.h" | ||
#endif | ||
|
||
namespace device { | ||
|
||
#if defined(OS_ANDROID) | ||
TEST_F(BluetoothTest, GetUUIDAndGetIdentifier) { | ||
InitWithFakeAdapter(); | ||
StartDiscoverySession(); | ||
BluetoothDevice* device = DiscoverLowEnergyDevice(3); | ||
device->CreateGattConnection(GetGattConnectionCallback(), | ||
GetConnectErrorCallback()); | ||
ResetEventCounts(); | ||
SimulateGattConnection(device); | ||
EXPECT_EQ(1, gatt_discovery_attempts_); | ||
|
||
// Create multiple instances with the same UUID. | ||
BluetoothUUID uuid("00000000-0000-1000-8000-00805f9b34fb"); | ||
std::vector<std::string> services; | ||
services.push_back(uuid.canonical_value()); | ||
services.push_back(uuid.canonical_value()); | ||
SimulateGattServicesDiscovered(device, services); | ||
|
||
// Each has the same UUID. | ||
EXPECT_EQ(uuid, device->GetGattServices()[0]->GetUUID()); | ||
EXPECT_EQ(uuid, device->GetGattServices()[1]->GetUUID()); | ||
|
||
// Instance IDs are unique. | ||
EXPECT_NE(device->GetGattServices()[0]->GetIdentifier(), | ||
device->GetGattServices()[1]->GetIdentifier()); | ||
} | ||
#endif // defined(OS_ANDROID) | ||
|
||
} // namespace device |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.