Home | History | Annotate | Download | only in bluetooth
      1 /*
      2  * Copyright (C) 2010-2016 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 
     18 package android.bluetooth;
     19 
     20 import android.Manifest;
     21 import android.annotation.IntDef;
     22 import android.annotation.RequiresPermission;
     23 import android.annotation.SystemApi;
     24 import android.annotation.UnsupportedAppUsage;
     25 import android.os.Build;
     26 
     27 import java.lang.annotation.Retention;
     28 import java.lang.annotation.RetentionPolicy;
     29 import java.util.List;
     30 
     31 /**
     32  * Public APIs for the Bluetooth Profiles.
     33  *
     34  * <p> Clients should call {@link BluetoothAdapter#getProfileProxy},
     35  * to get the Profile Proxy. Each public profile implements this
     36  * interface.
     37  */
     38 public interface BluetoothProfile {
     39 
     40     /**
     41      * Extra for the connection state intents of the individual profiles.
     42      *
     43      * This extra represents the current connection state of the profile of the
     44      * Bluetooth device.
     45      */
     46     String EXTRA_STATE = "android.bluetooth.profile.extra.STATE";
     47 
     48     /**
     49      * Extra for the connection state intents of the individual profiles.
     50      *
     51      * This extra represents the previous connection state of the profile of the
     52      * Bluetooth device.
     53      */
     54     String EXTRA_PREVIOUS_STATE =
     55             "android.bluetooth.profile.extra.PREVIOUS_STATE";
     56 
     57     /** The profile is in disconnected state */
     58     int STATE_DISCONNECTED = 0;
     59     /** The profile is in connecting state */
     60     int STATE_CONNECTING = 1;
     61     /** The profile is in connected state */
     62     int STATE_CONNECTED = 2;
     63     /** The profile is in disconnecting state */
     64     int STATE_DISCONNECTING = 3;
     65 
     66     /** @hide */
     67     @IntDef({
     68             STATE_DISCONNECTED,
     69             STATE_CONNECTING,
     70             STATE_CONNECTED,
     71             STATE_DISCONNECTING,
     72     })
     73     @Retention(RetentionPolicy.SOURCE)
     74     public @interface BtProfileState {}
     75 
     76     /**
     77      * Headset and Handsfree profile
     78      */
     79     int HEADSET = 1;
     80 
     81     /**
     82      * A2DP profile.
     83      */
     84     int A2DP = 2;
     85 
     86     /**
     87      * Health Profile
     88      *
     89      * @deprecated Health Device Profile (HDP) and MCAP protocol are no longer used. New
     90      * apps should use Bluetooth Low Energy based solutions such as {@link BluetoothGatt},
     91      * {@link BluetoothAdapter#listenUsingL2capChannel()}, or
     92      * {@link BluetoothDevice#createL2capChannel(int)}
     93      */
     94     @Deprecated
     95     int HEALTH = 3;
     96 
     97     /**
     98      * HID Host
     99      *
    100      * @hide
    101      */
    102     int HID_HOST = 4;
    103 
    104     /**
    105      * PAN Profile
    106      *
    107      * @hide
    108      */
    109     @UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.P, trackingBug = 115609023)
    110     int PAN = 5;
    111 
    112     /**
    113      * PBAP
    114      *
    115      * @hide
    116      */
    117     int PBAP = 6;
    118 
    119     /**
    120      * GATT
    121      */
    122     int GATT = 7;
    123 
    124     /**
    125      * GATT_SERVER
    126      */
    127     int GATT_SERVER = 8;
    128 
    129     /**
    130      * MAP Profile
    131      *
    132      * @hide
    133      */
    134     int MAP = 9;
    135 
    136     /*
    137      * SAP Profile
    138      * @hide
    139      */
    140     int SAP = 10;
    141 
    142     /**
    143      * A2DP Sink Profile
    144      *
    145      * @hide
    146      */
    147     @UnsupportedAppUsage
    148     int A2DP_SINK = 11;
    149 
    150     /**
    151      * AVRCP Controller Profile
    152      *
    153      * @hide
    154      */
    155     @UnsupportedAppUsage
    156     int AVRCP_CONTROLLER = 12;
    157 
    158     /**
    159      * AVRCP Target Profile
    160      *
    161      * @hide
    162      */
    163     int AVRCP = 13;
    164 
    165     /**
    166      * Headset Client - HFP HF Role
    167      *
    168      * @hide
    169      */
    170     int HEADSET_CLIENT = 16;
    171 
    172     /**
    173      * PBAP Client
    174      *
    175      * @hide
    176      */
    177     int PBAP_CLIENT = 17;
    178 
    179     /**
    180      * MAP Messaging Client Equipment (MCE)
    181      *
    182      * @hide
    183      */
    184     int MAP_CLIENT = 18;
    185 
    186     /**
    187      * HID Device
    188      */
    189     int HID_DEVICE = 19;
    190 
    191     /**
    192      * Object Push Profile (OPP)
    193      *
    194      * @hide
    195      */
    196     int OPP = 20;
    197 
    198     /**
    199      * Hearing Aid Device
    200      *
    201      */
    202     int HEARING_AID = 21;
    203 
    204     /**
    205      * Max profile ID. This value should be updated whenever a new profile is added to match
    206      * the largest value assigned to a profile.
    207      *
    208      * @hide
    209      */
    210     int MAX_PROFILE_ID = 21;
    211 
    212     /**
    213      * Default priority for devices that we try to auto-connect to and
    214      * and allow incoming connections for the profile
    215      *
    216      * @hide
    217      **/
    218     @UnsupportedAppUsage
    219     int PRIORITY_AUTO_CONNECT = 1000;
    220 
    221     /**
    222      * Default priority for devices that allow incoming
    223      * and outgoing connections for the profile
    224      *
    225      * @hide
    226      **/
    227     @SystemApi
    228     int PRIORITY_ON = 100;
    229 
    230     /**
    231      * Default priority for devices that does not allow incoming
    232      * connections and outgoing connections for the profile.
    233      *
    234      * @hide
    235      **/
    236     @SystemApi
    237     int PRIORITY_OFF = 0;
    238 
    239     /**
    240      * Default priority when not set or when the device is unpaired
    241      *
    242      * @hide
    243      */
    244     @UnsupportedAppUsage
    245     int PRIORITY_UNDEFINED = -1;
    246 
    247     /**
    248      * Get connected devices for this specific profile.
    249      *
    250      * <p> Return the set of devices which are in state {@link #STATE_CONNECTED}
    251      *
    252      * @return List of devices. The list will be empty on error.
    253      */
    254     @RequiresPermission(Manifest.permission.BLUETOOTH)
    255     public List<BluetoothDevice> getConnectedDevices();
    256 
    257     /**
    258      * Get a list of devices that match any of the given connection
    259      * states.
    260      *
    261      * <p> If none of the devices match any of the given states,
    262      * an empty list will be returned.
    263      *
    264      * @param states Array of states. States can be one of {@link #STATE_CONNECTED}, {@link
    265      * #STATE_CONNECTING}, {@link #STATE_DISCONNECTED}, {@link #STATE_DISCONNECTING},
    266      * @return List of devices. The list will be empty on error.
    267      */
    268     @RequiresPermission(Manifest.permission.BLUETOOTH)
    269     public List<BluetoothDevice> getDevicesMatchingConnectionStates(int[] states);
    270 
    271     /**
    272      * Get the current connection state of the profile
    273      *
    274      * @param device Remote bluetooth device.
    275      * @return State of the profile connection. One of {@link #STATE_CONNECTED}, {@link
    276      * #STATE_CONNECTING}, {@link #STATE_DISCONNECTED}, {@link #STATE_DISCONNECTING}
    277      */
    278     @RequiresPermission(Manifest.permission.BLUETOOTH)
    279     @BtProfileState int getConnectionState(BluetoothDevice device);
    280 
    281     /**
    282      * An interface for notifying BluetoothProfile IPC clients when they have
    283      * been connected or disconnected to the service.
    284      */
    285     public interface ServiceListener {
    286         /**
    287          * Called to notify the client when the proxy object has been
    288          * connected to the service.
    289          *
    290          * @param profile - One of {@link #HEADSET} or {@link #A2DP}
    291          * @param proxy - One of {@link BluetoothHeadset} or {@link BluetoothA2dp}
    292          */
    293         public void onServiceConnected(int profile, BluetoothProfile proxy);
    294 
    295         /**
    296          * Called to notify the client that this proxy object has been
    297          * disconnected from the service.
    298          *
    299          * @param profile - One of {@link #HEADSET} or {@link #A2DP}
    300          */
    301         public void onServiceDisconnected(int profile);
    302     }
    303 
    304     /**
    305      * Convert an integer value of connection state into human readable string
    306      *
    307      * @param connectionState - One of {@link #STATE_DISCONNECTED}, {@link #STATE_CONNECTING},
    308      * {@link #STATE_CONNECTED}, or {@link #STATE_DISCONNECTED}
    309      * @return a string representation of the connection state, STATE_UNKNOWN if the state
    310      * is not defined
    311      * @hide
    312      */
    313     static String getConnectionStateName(int connectionState) {
    314         switch (connectionState) {
    315             case STATE_DISCONNECTED:
    316                 return "STATE_DISCONNECTED";
    317             case STATE_CONNECTING:
    318                 return "STATE_CONNECTING";
    319             case STATE_CONNECTED:
    320                 return "STATE_CONNECTED";
    321             case STATE_DISCONNECTING:
    322                 return "STATE_DISCONNECTING";
    323             default:
    324                 return "STATE_UNKNOWN";
    325         }
    326     }
    327 }
    328