hughchen | b89929a | 2018-11-12 15:44:39 +0800 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2018 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 | package com.android.settingslib.media; |
| 17 | |
| 18 | import android.content.Context; |
| 19 | import android.util.Log; |
| 20 | |
| 21 | import com.android.settingslib.R; |
| 22 | import com.android.settingslib.bluetooth.A2dpProfile; |
| 23 | import com.android.settingslib.bluetooth.HearingAidProfile; |
| 24 | import com.android.settingslib.bluetooth.LocalBluetoothManager; |
| 25 | import com.android.settingslib.bluetooth.LocalBluetoothProfileManager; |
| 26 | |
| 27 | /** |
| 28 | * PhoneMediaDevice extends MediaDevice to represents Phone device. |
| 29 | */ |
| 30 | public class PhoneMediaDevice extends MediaDevice { |
| 31 | |
| 32 | private static final String TAG = "PhoneMediaDevice"; |
| 33 | |
| 34 | public static final String ID = "phone_media_device_id_1"; |
| 35 | |
| 36 | private LocalBluetoothProfileManager mProfileManager; |
| 37 | private LocalBluetoothManager mLocalBluetoothManager; |
| 38 | |
| 39 | PhoneMediaDevice(Context context, LocalBluetoothManager localBluetoothManager) { |
| 40 | super(context, MediaDeviceType.TYPE_PHONE_DEVICE); |
| 41 | |
| 42 | mLocalBluetoothManager = localBluetoothManager; |
| 43 | mProfileManager = mLocalBluetoothManager.getProfileManager(); |
timhypeng | a8b826c | 2018-11-14 15:33:53 +0800 | [diff] [blame] | 44 | initDeviceRecord(); |
hughchen | b89929a | 2018-11-12 15:44:39 +0800 | [diff] [blame] | 45 | } |
| 46 | |
| 47 | @Override |
| 48 | public String getName() { |
| 49 | return mContext |
| 50 | .getString(com.android.settingslib.R.string.media_transfer_phone_device_name); |
| 51 | } |
| 52 | |
| 53 | @Override |
| 54 | public int getIcon() { |
| 55 | //TODO(b/117129183): This is not final icon for phone device, just for demo. |
| 56 | return R.drawable.ic_bt_cellphone; |
| 57 | } |
| 58 | |
| 59 | @Override |
| 60 | public String getId() { |
| 61 | return ID; |
| 62 | } |
| 63 | |
| 64 | @Override |
| 65 | public void connect() { |
| 66 | final HearingAidProfile hapProfile = mProfileManager.getHearingAidProfile(); |
| 67 | final A2dpProfile a2dpProfile = mProfileManager.getA2dpProfile(); |
| 68 | |
| 69 | if (hapProfile != null && a2dpProfile != null) { |
timhypeng | a8b826c | 2018-11-14 15:33:53 +0800 | [diff] [blame] | 70 | mIsConnected = hapProfile.setActiveDevice(null) && a2dpProfile.setActiveDevice(null); |
| 71 | super.connect(); |
hughchen | b89929a | 2018-11-12 15:44:39 +0800 | [diff] [blame] | 72 | } |
| 73 | Log.d(TAG, "connect() device : " + getName() + ", is selected : " + mIsConnected); |
| 74 | } |
| 75 | |
| 76 | @Override |
| 77 | public void disconnect() { |
| 78 | //TODO(b/117129183): disconnected last select device |
| 79 | mIsConnected = false; |
| 80 | } |
| 81 | } |