Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
P
platform_packages_modules_Bluetooth
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Iterations
Wiki
Requirements
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Package Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
LMODroid
platform_packages_modules_Bluetooth
Commits
459f8c84
Commit
459f8c84
authored
1 year ago
by
Kihong Seong
Committed by
Gerrit Code Review
1 year ago
Browse files
Options
Downloads
Plain Diff
Merge "Add bumble test for scanning with CALLBACK_TYPE_ALL_MATCHES" into main
parents
492306dc
7405bdb0
No related branches found
Branches containing commit
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
framework/tests/bumble/src/android/bluetooth/LeScanningTest.java
+204
-0
204 additions, 0 deletions
...rk/tests/bumble/src/android/bluetooth/LeScanningTest.java
with
204 additions
and
0 deletions
framework/tests/bumble/src/android/bluetooth/LeScanningTest.java
0 → 100644
+
204
−
0
View file @
459f8c84
/*
* Copyright (C) 2023 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package
android.bluetooth
;
import
static
com
.
google
.
common
.
truth
.
Truth
.
assertThat
;
import
android.bluetooth.le.BluetoothLeScanner
;
import
android.bluetooth.le.ScanCallback
;
import
android.bluetooth.le.ScanFilter
;
import
android.bluetooth.le.ScanResult
;
import
android.bluetooth.le.ScanSettings
;
import
android.os.ParcelUuid
;
import
android.util.Log
;
import
androidx.test.core.app.ApplicationProvider
;
import
androidx.test.platform.app.InstrumentationRegistry
;
import
androidx.test.runner.AndroidJUnit4
;
import
com.google.protobuf.Empty
;
import
org.junit.After
;
import
org.junit.AfterClass
;
import
org.junit.Before
;
import
org.junit.BeforeClass
;
import
org.junit.Test
;
import
org.junit.runner.RunWith
;
import
java.util.ArrayList
;
import
java.util.List
;
import
java.util.concurrent.CompletableFuture
;
import
java.util.concurrent.TimeUnit
;
import
io.grpc.ManagedChannel
;
import
io.grpc.okhttp.OkHttpChannelBuilder
;
import
io.grpc.stub.StreamObserver
;
import
pandora.HostGrpc
;
import
pandora.HostProto
;
import
pandora.HostProto.AdvertiseRequest
;
import
pandora.HostProto.AdvertiseResponse
;
@RunWith
(
AndroidJUnit4
.
class
)
public
class
LeScanningTest
{
private
static
final
String
TAG
=
"LeScanningTest"
;
private
static
final
int
TIMEOUT_SCANNING_MS
=
1000
;
private
static
ManagedChannel
mChannel
;
private
static
HostGrpc
.
HostBlockingStub
mHostBlockingStub
;
private
static
HostGrpc
.
HostStub
mHostStub
;
private
final
String
TEST_UUID_STRING
=
"00001805-0000-1000-8000-00805f9b34fb"
;
@BeforeClass
public
static
void
setUpClass
()
throws
Exception
{
InstrumentationRegistry
.
getInstrumentation
()
.
getUiAutomation
()
.
adoptShellPermissionIdentity
();
}
@Before
public
void
setUp
()
throws
Exception
{
// FactorReset is killing the server and restart
// all channel created before the server restarted
// cannot be reused
ManagedChannel
channel
=
OkHttpChannelBuilder
.
forAddress
(
"localhost"
,
7999
).
usePlaintext
().
build
();
HostGrpc
.
HostBlockingStub
stub
=
HostGrpc
.
newBlockingStub
(
channel
);
stub
.
factoryReset
(
Empty
.
getDefaultInstance
());
// terminate the channel
channel
.
shutdown
().
awaitTermination
(
1
,
TimeUnit
.
SECONDS
);
// Create a new channel for all successive grpc calls
mChannel
=
OkHttpChannelBuilder
.
forAddress
(
"localhost"
,
7999
).
usePlaintext
().
build
();
mHostBlockingStub
=
HostGrpc
.
newBlockingStub
(
mChannel
);
mHostStub
=
HostGrpc
.
newStub
(
mChannel
);
mHostBlockingStub
.
withWaitForReady
().
readLocalAddress
(
Empty
.
getDefaultInstance
());
}
@After
public
void
tearDown
()
throws
Exception
{
// terminate the channel
mChannel
.
shutdown
().
awaitTermination
(
1
,
TimeUnit
.
SECONDS
);
}
@AfterClass
public
static
void
tearDownClass
()
throws
Exception
{
InstrumentationRegistry
.
getInstrumentation
()
.
getUiAutomation
()
.
dropShellPermissionIdentity
();
}
@Test
public
void
startBleScan_withCallbackTypeAllMatches
()
{
advertiseWithBumble
(
TEST_UUID_STRING
);
List
<
ScanResult
>
results
=
startScanning
(
TEST_UUID_STRING
,
ScanSettings
.
CALLBACK_TYPE_ALL_MATCHES
).
join
();
assertThat
(
results
.
get
(
0
).
getScanRecord
().
getServiceUuids
().
get
(
0
)).
isEqualTo
(
ParcelUuid
.
fromString
(
TEST_UUID_STRING
));
assertThat
(
results
.
get
(
1
).
getScanRecord
().
getServiceUuids
().
get
(
0
)).
isEqualTo
(
ParcelUuid
.
fromString
(
TEST_UUID_STRING
));
}
private
CompletableFuture
<
List
<
ScanResult
>>
startScanning
(
String
serviceUuid
,
int
callbackType
)
{
CompletableFuture
<
List
<
ScanResult
>>
future
=
new
CompletableFuture
<>();
List
<
ScanResult
>
scanResults
=
new
ArrayList
<>();
android
.
content
.
Context
context
=
ApplicationProvider
.
getApplicationContext
();
BluetoothManager
bluetoothManager
=
context
.
getSystemService
(
BluetoothManager
.
class
);
BluetoothAdapter
bluetoothAdapter
=
bluetoothManager
.
getAdapter
();
// Start scanning
BluetoothLeScanner
leScanner
=
bluetoothAdapter
.
getBluetoothLeScanner
();
ScanSettings
scanSettings
=
new
ScanSettings
.
Builder
()
.
setScanMode
(
ScanSettings
.
SCAN_MODE_LOW_LATENCY
)
.
setCallbackType
(
callbackType
)
.
build
();
List
<
ScanFilter
>
scanFilters
=
new
ArrayList
<>();
ScanFilter
scanFilter
=
new
ScanFilter
.
Builder
()
.
setServiceUuid
(
ParcelUuid
.
fromString
(
serviceUuid
))
.
build
();
scanFilters
.
add
(
scanFilter
);
ScanCallback
scanCallback
=
new
ScanCallback
()
{
@Override
public
void
onScanResult
(
int
callbackType
,
ScanResult
result
)
{
Log
.
i
(
TAG
,
"onScanResult "
+
"callbackType: "
+
callbackType
+
", service uuids: "
+
result
.
getScanRecord
().
getServiceUuids
());
if
(
scanResults
.
size
()
<
2
)
{
scanResults
.
add
(
result
);
}
else
{
future
.
complete
(
scanResults
);
}
}
@Override
public
void
onScanFailed
(
int
errorCode
)
{
Log
.
i
(
TAG
,
"onScanFailed "
+
"errorCode: "
+
errorCode
);
future
.
complete
(
null
);
}
};
leScanner
.
startScan
(
scanFilters
,
scanSettings
,
scanCallback
);
// Make sure completableFuture object completes with null after some timeout
return
future
.
completeOnTimeout
(
null
,
TIMEOUT_SCANNING_MS
,
TimeUnit
.
MILLISECONDS
);
}
private
void
advertiseWithBumble
(
String
serviceUuid
)
{
HostProto
.
DataTypes
dataType
=
HostProto
.
DataTypes
.
newBuilder
()
.
addCompleteServiceClassUuids128
(
serviceUuid
)
.
build
();
AdvertiseRequest
request
=
AdvertiseRequest
.
newBuilder
()
.
setLegacy
(
true
)
.
setData
(
dataType
)
.
build
();
StreamObserver
<
AdvertiseResponse
>
responseObserver
=
new
StreamObserver
<>()
{
@Override
public
void
onNext
(
AdvertiseResponse
response
)
{
Log
.
i
(
TAG
,
"advertise observer: onNext"
);
}
@Override
public
void
onError
(
Throwable
e
)
{
Log
.
e
(
TAG
,
"advertise observer: on error "
+
e
);
}
@Override
public
void
onCompleted
()
{
Log
.
i
(
TAG
,
"advertise observer: on completed"
);
}
};
mHostStub
.
advertise
(
request
,
responseObserver
);
}
}
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment