blob: e0f3c2ff76923c2a6201c1fae71a746e3c57a37a [file] [log] [blame]
hughchenb89929a2018-11-12 15:44:39 +08001/*
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 */
16package com.android.settingslib.media;
17
18import android.content.Context;
19import android.util.Log;
20
21import com.android.settingslib.R;
22import com.android.settingslib.bluetooth.A2dpProfile;
23import com.android.settingslib.bluetooth.HearingAidProfile;
24import com.android.settingslib.bluetooth.LocalBluetoothManager;
25import com.android.settingslib.bluetooth.LocalBluetoothProfileManager;
26
27/**
28 * PhoneMediaDevice extends MediaDevice to represents Phone device.
29 */
30public 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();
timhypenga8b826c2018-11-14 15:33:53 +080044 initDeviceRecord();
hughchenb89929a2018-11-12 15:44:39 +080045 }
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) {
timhypenga8b826c2018-11-14 15:33:53 +080070 mIsConnected = hapProfile.setActiveDevice(null) && a2dpProfile.setActiveDevice(null);
71 super.connect();
hughchenb89929a2018-11-12 15:44:39 +080072 }
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}