1 /*
2  * Copyright (C) 2022 The Android Open Source Project
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 package com.android.server.uwb.discovery;
17 
18 import android.bluetooth.le.ScanResult;
19 
20 import androidx.annotation.WorkerThread;
21 
22 import com.android.server.uwb.discovery.ble.DiscoveryAdvertisement;
23 
24 /** Abstract class for Discovery Scan Provider */
25 @WorkerThread
26 public abstract class DiscoveryScanProvider extends DiscoveryProvider {
27 
28     /** Holds information about the discovery request. */
29     public static class DiscoveryResult {
30 
31         // BLE discovery result
32         public ScanResult scanResult;
33         public DiscoveryAdvertisement discoveryAdvertisement;
34 
DiscoveryResult( ScanResult scanResult, DiscoveryAdvertisement discoveryAdvertisement)35         public DiscoveryResult(
36                 ScanResult scanResult, DiscoveryAdvertisement discoveryAdvertisement) {
37             this.scanResult = scanResult;
38             this.discoveryAdvertisement = discoveryAdvertisement;
39         }
40     }
41 
42     /** Callback for listening to discovery events. */
43     @WorkerThread
44     public interface DiscoveryScanCallback {
45         /**
46          * Called when device is discovered.
47          *
48          * @param result provide the info on discovered device.
49          */
onDiscovered(DiscoveryResult result)50         void onDiscovered(DiscoveryResult result);
51         /**
52          * Called when discovery failed.
53          *
54          * @param errorCode discovery failure error code.
55          */
onDiscoveryFailed(int errorCode)56         void onDiscoveryFailed(int errorCode);
57     }
58 }
59