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