1 /*
2  * Copyright (C) 2014 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 
17 package android.bluetooth.le;
18 
19 import java.util.List;
20 
21 /**
22  * Bluetooth LE scan callbacks. Scan results are reported using these callbacks.
23  *
24  * @see BluetoothLeScanner#startScan
25  */
26 public abstract class ScanCallback {
27     /**
28      * Fails to start scan as BLE scan with the same settings is already started by the app.
29      */
30     public static final int SCAN_FAILED_ALREADY_STARTED = 1;
31 
32     /**
33      * Fails to start scan as app cannot be registered.
34      */
35     public static final int SCAN_FAILED_APPLICATION_REGISTRATION_FAILED = 2;
36 
37     /**
38      * Fails to start scan due an internal error
39      */
40     public static final int SCAN_FAILED_INTERNAL_ERROR = 3;
41 
42     /**
43      * Fails to start power optimized scan as this feature is not supported.
44      */
45     public static final int SCAN_FAILED_FEATURE_UNSUPPORTED = 4;
46 
47     /**
48      * Fails to start scan as it is out of hardware resources.
49      * @hide
50      */
51     public static final int SCAN_FAILED_OUT_OF_HARDWARE_RESOURCES = 5;
52 
53     /**
54      * Callback when a BLE advertisement has been found.
55      *
56      * @param callbackType Determines how this callback was triggered. Could be one of
57      *            {@link ScanSettings#CALLBACK_TYPE_ALL_MATCHES},
58      *            {@link ScanSettings#CALLBACK_TYPE_FIRST_MATCH} or
59      *            {@link ScanSettings#CALLBACK_TYPE_MATCH_LOST}
60      * @param result A Bluetooth LE scan result.
61      */
onScanResult(int callbackType, ScanResult result)62     public void onScanResult(int callbackType, ScanResult result) {
63     }
64 
65     /**
66      * Callback when batch results are delivered.
67      *
68      * @param results List of scan results that are previously scanned.
69      */
onBatchScanResults(List<ScanResult> results)70     public void onBatchScanResults(List<ScanResult> results) {
71     }
72 
73     /**
74      * Callback when scan could not be started.
75      *
76      * @param errorCode Error code (one of SCAN_FAILED_*) for scan failure.
77      */
onScanFailed(int errorCode)78     public void onScanFailed(int errorCode) {
79     }
80 }
81