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      *
50      * @hide
51      */
52     public static final int SCAN_FAILED_OUT_OF_HARDWARE_RESOURCES = 5;
53 
54     /**
55      * Fails to start scan as application tries to scan too frequently.
56      * @hide
57      */
58     public static final int SCAN_FAILED_SCANNING_TOO_FREQUENTLY = 6;
59 
60     static final int NO_ERROR = 0;
61 
62     /**
63      * Callback when a BLE advertisement has been found.
64      *
65      * @param callbackType Determines how this callback was triggered. Could be one of {@link
66      * ScanSettings#CALLBACK_TYPE_ALL_MATCHES}, {@link ScanSettings#CALLBACK_TYPE_FIRST_MATCH} or
67      * {@link ScanSettings#CALLBACK_TYPE_MATCH_LOST}
68      * @param result A Bluetooth LE scan result.
69      */
onScanResult(int callbackType, ScanResult result)70     public void onScanResult(int callbackType, ScanResult result) {
71     }
72 
73     /**
74      * Callback when batch results are delivered.
75      *
76      * @param results List of scan results that are previously scanned.
77      */
onBatchScanResults(List<ScanResult> results)78     public void onBatchScanResults(List<ScanResult> results) {
79     }
80 
81     /**
82      * Callback when scan could not be started.
83      *
84      * @param errorCode Error code (one of SCAN_FAILED_*) for scan failure.
85      */
onScanFailed(int errorCode)86     public void onScanFailed(int errorCode) {
87     }
88 }
89