blob: 5b202dc58579f046eaf578979545b98ec1a26d2c [file] [log] [blame]
Jason Monk7ce96b92015-02-02 11:27:58 -05001/*
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
17package com.android.settingslib.bluetooth;
18
19import android.bluetooth.BluetoothA2dp;
Sanket Agarwal1bec6a52015-10-21 18:23:27 -070020import android.bluetooth.BluetoothA2dpSink;
Jason Monk7ce96b92015-02-02 11:27:58 -050021import android.bluetooth.BluetoothDevice;
22import android.bluetooth.BluetoothHeadset;
Sanket Agarwalf8a1c912016-01-26 20:12:52 -080023import android.bluetooth.BluetoothHeadsetClient;
Jakub Pawlowskiea580fa2017-11-22 11:02:34 -080024import android.bluetooth.BluetoothHearingAid;
Hansong Zhangdcae2932017-11-13 10:56:23 -080025import android.bluetooth.BluetoothHidDevice;
Hansong Zhang0edf7542017-10-20 15:55:59 -070026import android.bluetooth.BluetoothHidHost;
Jason Monk7ce96b92015-02-02 11:27:58 -050027import android.bluetooth.BluetoothMap;
Joseph Pirozzo631768d2016-09-01 14:19:28 -070028import android.bluetooth.BluetoothMapClient;
Jason Monk7ce96b92015-02-02 11:27:58 -050029import android.bluetooth.BluetoothPan;
Hemant Guptadbc3d8d2017-05-12 21:14:44 +053030import android.bluetooth.BluetoothPbap;
Joseph Pirozzo563c7002016-03-21 15:49:48 -070031import android.bluetooth.BluetoothPbapClient;
Jason Monk7ce96b92015-02-02 11:27:58 -050032import android.bluetooth.BluetoothProfile;
33import android.bluetooth.BluetoothUuid;
34import android.content.Context;
35import android.content.Intent;
36import android.os.ParcelUuid;
37import android.util.Log;
Andrew Sapperstein7aeb3f52017-04-19 20:03:42 -070038import com.android.internal.R;
Jason Monk7ce96b92015-02-02 11:27:58 -050039import java.util.ArrayList;
40import java.util.Collection;
41import java.util.HashMap;
42import java.util.Map;
Jason Monk7ce96b92015-02-02 11:27:58 -050043
44/**
45 * LocalBluetoothProfileManager provides access to the LocalBluetoothProfile
46 * objects for the available Bluetooth profiles.
47 */
Antony Sargent374d2592017-04-20 11:23:34 -070048public class LocalBluetoothProfileManager {
Jason Monk7ce96b92015-02-02 11:27:58 -050049 private static final String TAG = "LocalBluetoothProfileManager";
50 private static final boolean DEBUG = Utils.D;
51 /** Singleton instance. */
52 private static LocalBluetoothProfileManager sInstance;
53
54 /**
55 * An interface for notifying BluetoothHeadset IPC clients when they have
56 * been connected to the BluetoothHeadset service.
57 * Only used by com.android.settings.bluetooth.DockService.
58 */
59 public interface ServiceListener {
60 /**
61 * Called to notify the client when this proxy object has been
62 * connected to the BluetoothHeadset service. Clients must wait for
63 * this callback before making IPC calls on the BluetoothHeadset
64 * service.
65 */
66 void onServiceConnected();
67
68 /**
69 * Called to notify the client that this proxy object has been
70 * disconnected from the BluetoothHeadset service. Clients must not
71 * make IPC calls on the BluetoothHeadset service after this callback.
72 * This callback will currently only occur if the application hosting
73 * the BluetoothHeadset service, but may be called more often in future.
74 */
75 void onServiceDisconnected();
76 }
77
78 private final Context mContext;
79 private final LocalBluetoothAdapter mLocalAdapter;
80 private final CachedBluetoothDeviceManager mDeviceManager;
81 private final BluetoothEventManager mEventManager;
82
83 private A2dpProfile mA2dpProfile;
Sanket Agarwal1bec6a52015-10-21 18:23:27 -070084 private A2dpSinkProfile mA2dpSinkProfile;
Jason Monk7ce96b92015-02-02 11:27:58 -050085 private HeadsetProfile mHeadsetProfile;
Sanket Agarwalf8a1c912016-01-26 20:12:52 -080086 private HfpClientProfile mHfpClientProfile;
Jason Monk7ce96b92015-02-02 11:27:58 -050087 private MapProfile mMapProfile;
Joseph Pirozzo631768d2016-09-01 14:19:28 -070088 private MapClientProfile mMapClientProfile;
Jason Monk7ce96b92015-02-02 11:27:58 -050089 private final HidProfile mHidProfile;
Hansong Zhangdcae2932017-11-13 10:56:23 -080090 private HidDeviceProfile mHidDeviceProfile;
Jason Monk7ce96b92015-02-02 11:27:58 -050091 private OppProfile mOppProfile;
92 private final PanProfile mPanProfile;
Joseph Pirozzo563c7002016-03-21 15:49:48 -070093 private PbapClientProfile mPbapClientProfile;
Jason Monk7ce96b92015-02-02 11:27:58 -050094 private final PbapServerProfile mPbapProfile;
Joseph Pirozzo563c7002016-03-21 15:49:48 -070095 private final boolean mUsePbapPce;
Joseph Pirozzo631768d2016-09-01 14:19:28 -070096 private final boolean mUseMapClient;
Jakub Pawlowskiea580fa2017-11-22 11:02:34 -080097 private HearingAidProfile mHearingAidProfile;
Jason Monk7ce96b92015-02-02 11:27:58 -050098
99 /**
100 * Mapping from profile name, e.g. "HEADSET" to profile object.
101 */
102 private final Map<String, LocalBluetoothProfile>
103 mProfileNameMap = new HashMap<String, LocalBluetoothProfile>();
104
105 LocalBluetoothProfileManager(Context context,
106 LocalBluetoothAdapter adapter,
107 CachedBluetoothDeviceManager deviceManager,
108 BluetoothEventManager eventManager) {
109 mContext = context;
110
111 mLocalAdapter = adapter;
112 mDeviceManager = deviceManager;
113 mEventManager = eventManager;
Joseph Pirozzo563c7002016-03-21 15:49:48 -0700114 mUsePbapPce = mContext.getResources().getBoolean(R.bool.enable_pbap_pce_profile);
Joseph Pirozzo631768d2016-09-01 14:19:28 -0700115 // MAP Client is typically used in the same situations as PBAP Client
116 mUseMapClient = mContext.getResources().getBoolean(R.bool.enable_pbap_pce_profile);
Jason Monk7ce96b92015-02-02 11:27:58 -0500117 // pass this reference to adapter and event manager (circular dependency)
118 mLocalAdapter.setProfileManager(this);
119 mEventManager.setProfileManager(this);
120
121 ParcelUuid[] uuids = adapter.getUuids();
122
123 // uuids may be null if Bluetooth is turned off
124 if (uuids != null) {
125 updateLocalProfiles(uuids);
126 }
127
Hansong Zhangdcae2932017-11-13 10:56:23 -0800128 // Always add HID host, HID device, and PAN profiles
Jason Monk7ce96b92015-02-02 11:27:58 -0500129 mHidProfile = new HidProfile(context, mLocalAdapter, mDeviceManager, this);
130 addProfile(mHidProfile, HidProfile.NAME,
Hansong Zhang0edf7542017-10-20 15:55:59 -0700131 BluetoothHidHost.ACTION_CONNECTION_STATE_CHANGED);
Jason Monk7ce96b92015-02-02 11:27:58 -0500132
133 mPanProfile = new PanProfile(context);
134 addPanProfile(mPanProfile, PanProfile.NAME,
135 BluetoothPan.ACTION_CONNECTION_STATE_CHANGED);
136
Hansong Zhangdcae2932017-11-13 10:56:23 -0800137 mHidDeviceProfile = new HidDeviceProfile(context, mLocalAdapter, mDeviceManager, this);
138 addProfile(mHidDeviceProfile, HidDeviceProfile.NAME,
139 BluetoothHidDevice.ACTION_CONNECTION_STATE_CHANGED);
140
Jason Monk7ce96b92015-02-02 11:27:58 -0500141 if(DEBUG) Log.d(TAG, "Adding local MAP profile");
Joseph Pirozzo631768d2016-09-01 14:19:28 -0700142 if (mUseMapClient) {
143 mMapClientProfile = new MapClientProfile(mContext, mLocalAdapter, mDeviceManager, this);
144 addProfile(mMapClientProfile, MapClientProfile.NAME,
145 BluetoothMapClient.ACTION_CONNECTION_STATE_CHANGED);
146 } else {
147 mMapProfile = new MapProfile(mContext, mLocalAdapter, mDeviceManager, this);
148 addProfile(mMapProfile, MapProfile.NAME,
149 BluetoothMap.ACTION_CONNECTION_STATE_CHANGED);
150 }
Jason Monk7ce96b92015-02-02 11:27:58 -0500151
Hemant Guptadbc3d8d2017-05-12 21:14:44 +0530152 //Create PBAP server profile
153 if(DEBUG) Log.d(TAG, "Adding local PBAP profile");
Jakub Pawlowskiea580fa2017-11-22 11:02:34 -0800154
Jason Monk7ce96b92015-02-02 11:27:58 -0500155 mPbapProfile = new PbapServerProfile(context);
Hemant Guptadbc3d8d2017-05-12 21:14:44 +0530156 addProfile(mPbapProfile, PbapServerProfile.NAME,
157 BluetoothPbap.ACTION_CONNECTION_STATE_CHANGED);
Jason Monk7ce96b92015-02-02 11:27:58 -0500158
Jakub Pawlowskiea580fa2017-11-22 11:02:34 -0800159 mHearingAidProfile = new HearingAidProfile(mContext, mLocalAdapter, mDeviceManager, this);
160 addProfile(mHearingAidProfile, HearingAidProfile.NAME,
161 BluetoothHearingAid.ACTION_CONNECTION_STATE_CHANGED);
Jason Monk7ce96b92015-02-02 11:27:58 -0500162 if (DEBUG) Log.d(TAG, "LocalBluetoothProfileManager construction complete");
163 }
164
165 /**
166 * Initialize or update the local profile objects. If a UUID was previously
167 * present but has been removed, we print a warning but don't remove the
168 * profile object as it might be referenced elsewhere, or the UUID might
169 * come back and we don't want multiple copies of the profile objects.
170 * @param uuids
171 */
172 void updateLocalProfiles(ParcelUuid[] uuids) {
Sanket Agarwal1bec6a52015-10-21 18:23:27 -0700173 // A2DP SRC
Jason Monk7ce96b92015-02-02 11:27:58 -0500174 if (BluetoothUuid.isUuidPresent(uuids, BluetoothUuid.AudioSource)) {
175 if (mA2dpProfile == null) {
Sanket Agarwal1bec6a52015-10-21 18:23:27 -0700176 if(DEBUG) Log.d(TAG, "Adding local A2DP SRC profile");
Jason Monk7ce96b92015-02-02 11:27:58 -0500177 mA2dpProfile = new A2dpProfile(mContext, mLocalAdapter, mDeviceManager, this);
178 addProfile(mA2dpProfile, A2dpProfile.NAME,
179 BluetoothA2dp.ACTION_CONNECTION_STATE_CHANGED);
180 }
181 } else if (mA2dpProfile != null) {
182 Log.w(TAG, "Warning: A2DP profile was previously added but the UUID is now missing.");
183 }
184
Sanket Agarwalf8a1c912016-01-26 20:12:52 -0800185 // A2DP SINK
Sanket Agarwal1bec6a52015-10-21 18:23:27 -0700186 if (BluetoothUuid.isUuidPresent(uuids, BluetoothUuid.AudioSink)) {
187 if (mA2dpSinkProfile == null) {
188 if(DEBUG) Log.d(TAG, "Adding local A2DP Sink profile");
189 mA2dpSinkProfile = new A2dpSinkProfile(mContext, mLocalAdapter, mDeviceManager, this);
190 addProfile(mA2dpSinkProfile, A2dpSinkProfile.NAME,
191 BluetoothA2dpSink.ACTION_CONNECTION_STATE_CHANGED);
192 }
193 } else if (mA2dpSinkProfile != null) {
194 Log.w(TAG, "Warning: A2DP Sink profile was previously added but the UUID is now missing.");
195 }
196
Jason Monk7ce96b92015-02-02 11:27:58 -0500197 // Headset / Handsfree
198 if (BluetoothUuid.isUuidPresent(uuids, BluetoothUuid.Handsfree_AG) ||
199 BluetoothUuid.isUuidPresent(uuids, BluetoothUuid.HSP_AG)) {
200 if (mHeadsetProfile == null) {
201 if (DEBUG) Log.d(TAG, "Adding local HEADSET profile");
202 mHeadsetProfile = new HeadsetProfile(mContext, mLocalAdapter,
203 mDeviceManager, this);
204 addProfile(mHeadsetProfile, HeadsetProfile.NAME,
205 BluetoothHeadset.ACTION_CONNECTION_STATE_CHANGED);
206 }
207 } else if (mHeadsetProfile != null) {
208 Log.w(TAG, "Warning: HEADSET profile was previously added but the UUID is now missing.");
209 }
210
Sanket Agarwalf8a1c912016-01-26 20:12:52 -0800211 // Headset HF
212 if (BluetoothUuid.isUuidPresent(uuids, BluetoothUuid.Handsfree)) {
213 if (mHfpClientProfile == null) {
214 if(DEBUG) Log.d(TAG, "Adding local HfpClient profile");
215 mHfpClientProfile =
216 new HfpClientProfile(mContext, mLocalAdapter, mDeviceManager, this);
217 addProfile(mHfpClientProfile, HfpClientProfile.NAME,
218 BluetoothHeadsetClient.ACTION_CONNECTION_STATE_CHANGED);
219 }
220 } else if (mHfpClientProfile != null) {
221 Log.w(TAG,
222 "Warning: Hfp Client profile was previously added but the UUID is now missing.");
223 } else {
224 Log.d(TAG, "Handsfree Uuid not found.");
225 }
226
Joseph Pirozzo631768d2016-09-01 14:19:28 -0700227 // Message Access Profile Client
228 if (BluetoothUuid.isUuidPresent(uuids, BluetoothUuid.MNS)) {
229 if (mMapClientProfile == null) {
230 if(DEBUG) Log.d(TAG, "Adding local Map Client profile");
231 mMapClientProfile =
232 new MapClientProfile(mContext, mLocalAdapter, mDeviceManager, this);
233 addProfile(mMapClientProfile, MapClientProfile.NAME,
234 BluetoothMapClient.ACTION_CONNECTION_STATE_CHANGED);
235 }
236 } else if (mMapClientProfile != null) {
237 Log.w(TAG,
238 "Warning: MAP Client profile was previously added but the UUID is now missing.");
239 } else {
240 Log.d(TAG, "MAP Client Uuid not found.");
241 }
242
Jason Monk7ce96b92015-02-02 11:27:58 -0500243 // OPP
244 if (BluetoothUuid.isUuidPresent(uuids, BluetoothUuid.ObexObjectPush)) {
245 if (mOppProfile == null) {
246 if(DEBUG) Log.d(TAG, "Adding local OPP profile");
247 mOppProfile = new OppProfile();
248 // Note: no event handler for OPP, only name map.
249 mProfileNameMap.put(OppProfile.NAME, mOppProfile);
250 }
251 } else if (mOppProfile != null) {
252 Log.w(TAG, "Warning: OPP profile was previously added but the UUID is now missing.");
253 }
Joseph Pirozzo563c7002016-03-21 15:49:48 -0700254
255 //PBAP Client
256 if (mUsePbapPce) {
257 if (mPbapClientProfile == null) {
258 if(DEBUG) Log.d(TAG, "Adding local PBAP Client profile");
259 mPbapClientProfile = new PbapClientProfile(mContext, mLocalAdapter, mDeviceManager,
260 this);
261 addProfile(mPbapClientProfile, PbapClientProfile.NAME,
262 BluetoothPbapClient.ACTION_CONNECTION_STATE_CHANGED);
263 }
264 } else if (mPbapClientProfile != null) {
265 Log.w(TAG,
266 "Warning: PBAP Client profile was previously added but the UUID is now missing.");
267 }
268
Jakub Pawlowskiea580fa2017-11-22 11:02:34 -0800269 //Hearing Aid Client
270 if (BluetoothUuid.isUuidPresent(uuids, BluetoothUuid.HearingAid)) {
271 if (mHearingAidProfile == null) {
272 if(DEBUG) Log.d(TAG, "Adding local Hearing Aid profile");
273 mHearingAidProfile = new HearingAidProfile(mContext, mLocalAdapter, mDeviceManager, this);
274 addProfile(mHearingAidProfile, HearingAidProfile.NAME,
275 BluetoothHearingAid.ACTION_CONNECTION_STATE_CHANGED);
276 }
277 } else if (mHearingAidProfile != null) {
278 Log.w(TAG, "Warning: Hearing Aid profile was previously added but the UUID is now missing.");
279 }
280
Jason Monk7ce96b92015-02-02 11:27:58 -0500281 mEventManager.registerProfileIntentReceiver();
282
Joseph Pirozzo563c7002016-03-21 15:49:48 -0700283 // There is no local SDP record for HID and Settings app doesn't control PBAP Server.
Jason Monk7ce96b92015-02-02 11:27:58 -0500284 }
285
286 private final Collection<ServiceListener> mServiceListeners =
287 new ArrayList<ServiceListener>();
288
289 private void addProfile(LocalBluetoothProfile profile,
290 String profileName, String stateChangedAction) {
291 mEventManager.addProfileHandler(stateChangedAction, new StateChangedHandler(profile));
292 mProfileNameMap.put(profileName, profile);
293 }
294
295 private void addPanProfile(LocalBluetoothProfile profile,
296 String profileName, String stateChangedAction) {
297 mEventManager.addProfileHandler(stateChangedAction,
298 new PanStateChangedHandler(profile));
299 mProfileNameMap.put(profileName, profile);
300 }
301
302 public LocalBluetoothProfile getProfileByName(String name) {
303 return mProfileNameMap.get(name);
304 }
305
306 // Called from LocalBluetoothAdapter when state changes to ON
307 void setBluetoothStateOn() {
308 ParcelUuid[] uuids = mLocalAdapter.getUuids();
309 if (uuids != null) {
310 updateLocalProfiles(uuids);
311 }
312 mEventManager.readPairedDevices();
313 }
314
315 /**
316 * Generic handler for connection state change events for the specified profile.
317 */
318 private class StateChangedHandler implements BluetoothEventManager.Handler {
319 final LocalBluetoothProfile mProfile;
320
321 StateChangedHandler(LocalBluetoothProfile profile) {
322 mProfile = profile;
323 }
324
325 public void onReceive(Context context, Intent intent, BluetoothDevice device) {
326 CachedBluetoothDevice cachedDevice = mDeviceManager.findDevice(device);
327 if (cachedDevice == null) {
328 Log.w(TAG, "StateChangedHandler found new device: " + device);
329 cachedDevice = mDeviceManager.addDevice(mLocalAdapter,
330 LocalBluetoothProfileManager.this, device);
331 }
332 int newState = intent.getIntExtra(BluetoothProfile.EXTRA_STATE, 0);
333 int oldState = intent.getIntExtra(BluetoothProfile.EXTRA_PREVIOUS_STATE, 0);
334 if (newState == BluetoothProfile.STATE_DISCONNECTED &&
335 oldState == BluetoothProfile.STATE_CONNECTING) {
336 Log.i(TAG, "Failed to connect " + mProfile + " device");
337 }
338
339 cachedDevice.onProfileStateChanged(mProfile, newState);
340 cachedDevice.refresh();
341 }
342 }
343
344 /** State change handler for NAP and PANU profiles. */
345 private class PanStateChangedHandler extends StateChangedHandler {
346
347 PanStateChangedHandler(LocalBluetoothProfile profile) {
348 super(profile);
349 }
350
351 @Override
352 public void onReceive(Context context, Intent intent, BluetoothDevice device) {
353 PanProfile panProfile = (PanProfile) mProfile;
354 int role = intent.getIntExtra(BluetoothPan.EXTRA_LOCAL_ROLE, 0);
355 panProfile.setLocalRole(device, role);
356 super.onReceive(context, intent, device);
357 }
358 }
359
360 // called from DockService
361 public void addServiceListener(ServiceListener l) {
362 mServiceListeners.add(l);
363 }
364
365 // called from DockService
366 public void removeServiceListener(ServiceListener l) {
367 mServiceListeners.remove(l);
368 }
369
370 // not synchronized: use only from UI thread! (TODO: verify)
371 void callServiceConnectedListeners() {
372 for (ServiceListener l : mServiceListeners) {
373 l.onServiceConnected();
374 }
375 }
376
377 // not synchronized: use only from UI thread! (TODO: verify)
378 void callServiceDisconnectedListeners() {
379 for (ServiceListener listener : mServiceListeners) {
380 listener.onServiceDisconnected();
381 }
382 }
383
384 // This is called by DockService, so check Headset and A2DP.
385 public synchronized boolean isManagerReady() {
386 // Getting just the headset profile is fine for now. Will need to deal with A2DP
387 // and others if they aren't always in a ready state.
388 LocalBluetoothProfile profile = mHeadsetProfile;
389 if (profile != null) {
390 return profile.isProfileReady();
391 }
392 profile = mA2dpProfile;
393 if (profile != null) {
394 return profile.isProfileReady();
395 }
Sanket Agarwal1bec6a52015-10-21 18:23:27 -0700396 profile = mA2dpSinkProfile;
397 if (profile != null) {
398 return profile.isProfileReady();
399 }
Jason Monk7ce96b92015-02-02 11:27:58 -0500400 return false;
401 }
402
403 public A2dpProfile getA2dpProfile() {
404 return mA2dpProfile;
405 }
406
Sanket Agarwalf8a1c912016-01-26 20:12:52 -0800407 public A2dpSinkProfile getA2dpSinkProfile() {
408 if ((mA2dpSinkProfile != null) && (mA2dpSinkProfile.isProfileReady())) {
409 return mA2dpSinkProfile;
410 } else {
Sanket Agarwal1bec6a52015-10-21 18:23:27 -0700411 return null;
Sanket Agarwalf8a1c912016-01-26 20:12:52 -0800412 }
Sanket Agarwal1bec6a52015-10-21 18:23:27 -0700413 }
414
Jason Monk7ce96b92015-02-02 11:27:58 -0500415 public HeadsetProfile getHeadsetProfile() {
416 return mHeadsetProfile;
417 }
418
Sanket Agarwalf8a1c912016-01-26 20:12:52 -0800419 public HfpClientProfile getHfpClientProfile() {
420 if ((mHfpClientProfile != null) && (mHfpClientProfile.isProfileReady())) {
421 return mHfpClientProfile;
422 } else {
423 return null;
424 }
425 }
426
Joseph Pirozzo563c7002016-03-21 15:49:48 -0700427 public PbapClientProfile getPbapClientProfile() {
428 return mPbapClientProfile;
429 }
430
Jason Monk7ce96b92015-02-02 11:27:58 -0500431 public PbapServerProfile getPbapProfile(){
432 return mPbapProfile;
433 }
434
435 public MapProfile getMapProfile(){
436 return mMapProfile;
437 }
438
Joseph Pirozzo631768d2016-09-01 14:19:28 -0700439 public MapClientProfile getMapClientProfile() {
440 return mMapClientProfile;
441 }
442
Jakub Pawlowskiea580fa2017-11-22 11:02:34 -0800443 public HearingAidProfile getHearingAidProfile() {
444 return mHearingAidProfile;
445 }
446
Jason Monk7ce96b92015-02-02 11:27:58 -0500447 /**
448 * Fill in a list of LocalBluetoothProfile objects that are supported by
449 * the local device and the remote device.
450 *
451 * @param uuids of the remote device
452 * @param localUuids UUIDs of the local device
453 * @param profiles The list of profiles to fill
454 * @param removedProfiles list of profiles that were removed
455 */
456 synchronized void updateProfiles(ParcelUuid[] uuids, ParcelUuid[] localUuids,
457 Collection<LocalBluetoothProfile> profiles,
458 Collection<LocalBluetoothProfile> removedProfiles,
459 boolean isPanNapConnected, BluetoothDevice device) {
460 // Copy previous profile list into removedProfiles
461 removedProfiles.clear();
462 removedProfiles.addAll(profiles);
Joseph Pirozzo99fecc02016-04-07 13:43:49 -0700463 if (DEBUG) {
464 Log.d(TAG,"Current Profiles" + profiles.toString());
465 }
Jason Monk7ce96b92015-02-02 11:27:58 -0500466 profiles.clear();
467
468 if (uuids == null) {
469 return;
470 }
471
472 if (mHeadsetProfile != null) {
473 if ((BluetoothUuid.isUuidPresent(localUuids, BluetoothUuid.HSP_AG) &&
474 BluetoothUuid.isUuidPresent(uuids, BluetoothUuid.HSP)) ||
475 (BluetoothUuid.isUuidPresent(localUuids, BluetoothUuid.Handsfree_AG) &&
476 BluetoothUuid.isUuidPresent(uuids, BluetoothUuid.Handsfree))) {
477 profiles.add(mHeadsetProfile);
478 removedProfiles.remove(mHeadsetProfile);
479 }
480 }
481
Joseph Pirozzo99fecc02016-04-07 13:43:49 -0700482 if ((mHfpClientProfile != null) &&
483 BluetoothUuid.isUuidPresent(uuids, BluetoothUuid.Handsfree_AG) &&
484 BluetoothUuid.isUuidPresent(localUuids, BluetoothUuid.Handsfree)) {
485 profiles.add(mHfpClientProfile);
486 removedProfiles.remove(mHfpClientProfile);
487 }
488
Jason Monk7ce96b92015-02-02 11:27:58 -0500489 if (BluetoothUuid.containsAnyUuid(uuids, A2dpProfile.SINK_UUIDS) &&
490 mA2dpProfile != null) {
491 profiles.add(mA2dpProfile);
492 removedProfiles.remove(mA2dpProfile);
493 }
494
Sanket Agarwal1bec6a52015-10-21 18:23:27 -0700495 if (BluetoothUuid.containsAnyUuid(uuids, A2dpSinkProfile.SRC_UUIDS) &&
496 mA2dpSinkProfile != null) {
497 profiles.add(mA2dpSinkProfile);
498 removedProfiles.remove(mA2dpSinkProfile);
Joseph Pirozzo99fecc02016-04-07 13:43:49 -0700499 }
Sanket Agarwal1bec6a52015-10-21 18:23:27 -0700500
Jason Monk7ce96b92015-02-02 11:27:58 -0500501 if (BluetoothUuid.isUuidPresent(uuids, BluetoothUuid.ObexObjectPush) &&
502 mOppProfile != null) {
503 profiles.add(mOppProfile);
504 removedProfiles.remove(mOppProfile);
505 }
506
507 if ((BluetoothUuid.isUuidPresent(uuids, BluetoothUuid.Hid) ||
508 BluetoothUuid.isUuidPresent(uuids, BluetoothUuid.Hogp)) &&
509 mHidProfile != null) {
510 profiles.add(mHidProfile);
511 removedProfiles.remove(mHidProfile);
512 }
513
Hansong Zhangdcae2932017-11-13 10:56:23 -0800514 if (mHidProfile != null && mHidDeviceProfile.getConnectionStatus(device)
515 != BluetoothProfile.STATE_DISCONNECTED) {
516 profiles.add(mHidDeviceProfile);
517 removedProfiles.remove(mHidDeviceProfile);
518 }
519
Jason Monk7ce96b92015-02-02 11:27:58 -0500520 if(isPanNapConnected)
521 if(DEBUG) Log.d(TAG, "Valid PAN-NAP connection exists.");
522 if ((BluetoothUuid.isUuidPresent(uuids, BluetoothUuid.NAP) &&
523 mPanProfile != null) || isPanNapConnected) {
524 profiles.add(mPanProfile);
525 removedProfiles.remove(mPanProfile);
526 }
527
528 if ((mMapProfile != null) &&
529 (mMapProfile.getConnectionStatus(device) == BluetoothProfile.STATE_CONNECTED)) {
530 profiles.add(mMapProfile);
531 removedProfiles.remove(mMapProfile);
532 mMapProfile.setPreferred(device, true);
533 }
Jason Monk7ce96b92015-02-02 11:27:58 -0500534
Hemant Guptadbc3d8d2017-05-12 21:14:44 +0530535 if ((mPbapProfile != null) &&
536 (mPbapProfile.getConnectionStatus(device) == BluetoothProfile.STATE_CONNECTED)) {
537 profiles.add(mPbapProfile);
538 removedProfiles.remove(mPbapProfile);
539 mPbapProfile.setPreferred(device, true);
540 }
541
Joseph Pirozzo631768d2016-09-01 14:19:28 -0700542 if (mMapClientProfile != null) {
543 profiles.add(mMapClientProfile);
544 removedProfiles.remove(mMapClientProfile);
545 }
546
Joseph Pirozzo563c7002016-03-21 15:49:48 -0700547 if (mUsePbapPce) {
548 profiles.add(mPbapClientProfile);
549 removedProfiles.remove(mPbapClientProfile);
Joseph Pirozzo563c7002016-03-21 15:49:48 -0700550 }
Joseph Pirozzo99fecc02016-04-07 13:43:49 -0700551
Jakub Pawlowskiea580fa2017-11-22 11:02:34 -0800552 if (BluetoothUuid.isUuidPresent(uuids, BluetoothUuid.HearingAid) &&
553 mHearingAidProfile != null) {
554 profiles.add(mHearingAidProfile);
555 removedProfiles.remove(mHearingAidProfile);
556 }
557
Joseph Pirozzo99fecc02016-04-07 13:43:49 -0700558 if (DEBUG) {
559 Log.d(TAG,"New Profiles" + profiles.toString());
560 }
Joseph Pirozzo563c7002016-03-21 15:49:48 -0700561 }
Jason Monk7ce96b92015-02-02 11:27:58 -0500562}