Home | History | Annotate | Download | only in bluetooth
      1 /*
      2  * Copyright (C) 2011 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 com.android.settingslib.bluetooth;
     18 
     19 
     20 /**
     21  * BluetoothCallback provides a callback interface for the settings
     22  * UI to receive events from {@link BluetoothEventManager}.
     23  */
     24 public interface BluetoothCallback {
     25     /**
     26      * It will be called when the state of the local Bluetooth adapter has been changed.
     27      * It is listening {@link android.bluetooth.BluetoothAdapter#ACTION_STATE_CHANGED}.
     28      * For example, Bluetooth has been turned on or off.
     29      *
     30      * @param bluetoothState the current Bluetooth state, the possible values are:
     31      * {@link android.bluetooth.BluetoothAdapter#STATE_OFF},
     32      * {@link android.bluetooth.BluetoothAdapter#STATE_TURNING_ON},
     33      * {@link android.bluetooth.BluetoothAdapter#STATE_ON},
     34      * {@link android.bluetooth.BluetoothAdapter#STATE_TURNING_OFF}.
     35      */
     36     default void onBluetoothStateChanged(int bluetoothState) {}
     37 
     38     /**
     39      * It will be called when the local Bluetooth adapter has started
     40      * or finished the remote device discovery process.
     41      * It is listening {@link android.bluetooth.BluetoothAdapter#ACTION_DISCOVERY_STARTED} and
     42      * {@link android.bluetooth.BluetoothAdapter#ACTION_DISCOVERY_FINISHED}.
     43      *
     44      * @param started indicate the current process is started or finished.
     45      */
     46     default void onScanningStateChanged(boolean started) {}
     47 
     48     /**
     49      * It will be called in following situations:
     50      * 1. In scanning mode, when a new device has been found.
     51      * 2. When a profile service is connected and existing connected devices has been found.
     52      * This API only invoked once for each device and all devices will be cached in
     53      * {@link CachedBluetoothDeviceManager}.
     54      *
     55      * @param cachedDevice the Bluetooth device.
     56      */
     57     default void onDeviceAdded(CachedBluetoothDevice cachedDevice) {}
     58 
     59     /**
     60      * It will be called when requiring to remove a remote device from CachedBluetoothDevice list
     61      *
     62      * @param cachedDevice the Bluetooth device.
     63      */
     64     default void onDeviceDeleted(CachedBluetoothDevice cachedDevice) {}
     65 
     66     /**
     67      * It will be called when bond state of a remote device is changed.
     68      * It is listening {@link android.bluetooth.BluetoothDevice#ACTION_BOND_STATE_CHANGED}
     69      *
     70      * @param cachedDevice the Bluetooth device.
     71      * @param bondState the Bluetooth device bond state, the possible values are:
     72      * {@link android.bluetooth.BluetoothDevice#BOND_NONE},
     73      * {@link android.bluetooth.BluetoothDevice#BOND_BONDING},
     74      * {@link android.bluetooth.BluetoothDevice#BOND_BONDED}.
     75      */
     76     default void onDeviceBondStateChanged(CachedBluetoothDevice cachedDevice, int bondState) {}
     77 
     78     /**
     79      * It will be called in following situations:
     80      * 1. When the adapter is not connected to any profiles of any remote devices
     81      * and it attempts a connection to a profile.
     82      * 2. When the adapter disconnects from the last profile of the last device.
     83      * It is listening {@link android.bluetooth.BluetoothAdapter#ACTION_CONNECTION_STATE_CHANGED}
     84      *
     85      * @param cachedDevice the Bluetooth device.
     86      * @param state the Bluetooth device connection state, the possible values are:
     87      * {@link android.bluetooth.BluetoothAdapter#STATE_DISCONNECTED},
     88      * {@link android.bluetooth.BluetoothAdapter#STATE_CONNECTING},
     89      * {@link android.bluetooth.BluetoothAdapter#STATE_CONNECTED},
     90      * {@link android.bluetooth.BluetoothAdapter#STATE_DISCONNECTING}.
     91      */
     92     default void onConnectionStateChanged(CachedBluetoothDevice cachedDevice, int state) {}
     93 
     94     /**
     95      * It will be called when device been set as active for {@code bluetoothProfile}
     96      * It is listening in following intent:
     97      * {@link android.bluetooth.BluetoothA2dp#ACTION_ACTIVE_DEVICE_CHANGED}
     98      * {@link android.bluetooth.BluetoothHeadset#ACTION_ACTIVE_DEVICE_CHANGED}
     99      * {@link android.bluetooth.BluetoothHearingAid#ACTION_ACTIVE_DEVICE_CHANGED}
    100      *
    101      * @param activeDevice the active Bluetooth device.
    102      * @param bluetoothProfile the profile of active Bluetooth device.
    103      */
    104     default void onActiveDeviceChanged(CachedBluetoothDevice activeDevice, int bluetoothProfile) {}
    105 
    106     /**
    107      * It will be called in following situations:
    108      * 1. When the call state on the device is changed.
    109      * 2. When the audio connection state of the A2DP profile is changed.
    110      * It is listening in following intent:
    111      * {@link android.bluetooth.BluetoothHeadset#ACTION_AUDIO_STATE_CHANGED}
    112      * {@link android.telephony.TelephonyManager#ACTION_PHONE_STATE_CHANGED}
    113      */
    114     default void onAudioModeChanged() {}
    115 
    116     /**
    117      * It will be called when one of the bluetooth device profile connection state is changed.
    118      *
    119      * @param cachedDevice the active Bluetooth device.
    120      * @param state the BluetoothProfile connection state, the possible values are:
    121      * {@link android.bluetooth.BluetoothProfile#STATE_CONNECTED},
    122      * {@link android.bluetooth.BluetoothProfile#STATE_CONNECTING},
    123      * {@link android.bluetooth.BluetoothProfile#STATE_DISCONNECTED},
    124      * {@link android.bluetooth.BluetoothProfile#STATE_DISCONNECTING}.
    125      * @param bluetoothProfile the BluetoothProfile id.
    126      */
    127     default void onProfileConnectionStateChanged(CachedBluetoothDevice cachedDevice,
    128             int state, int bluetoothProfile) {
    129     }
    130 
    131     /**
    132      * Called when ACL connection state is changed. It listens to
    133      * {@link android.bluetooth.BluetoothDevice#ACTION_ACL_CONNECTED} and {@link
    134      * android.bluetooth.BluetoothDevice#ACTION_ACL_DISCONNECTED}
    135      *
    136      * @param cachedDevice Bluetooth device that changed
    137      * @param state        the Bluetooth device connection state, the possible values are:
    138      *                     {@link android.bluetooth.BluetoothAdapter#STATE_DISCONNECTED},
    139      *                     {@link android.bluetooth.BluetoothAdapter#STATE_CONNECTED}
    140      */
    141     default void onAclConnectionStateChanged(CachedBluetoothDevice cachedDevice, int state) {
    142     }
    143 }
    144