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 17 package com.android.car.settings.bluetooth; 18 19 import static android.os.UserManager.DISALLOW_CONFIG_BLUETOOTH; 20 21 import android.car.drivingstate.CarUxRestrictions; 22 import android.content.Context; 23 24 import com.android.car.settings.R; 25 import com.android.car.settings.common.FragmentController; 26 import com.android.settingslib.bluetooth.BluetoothDeviceFilter; 27 import com.android.settingslib.bluetooth.CachedBluetoothDevice; 28 29 /** 30 * Displays a list of bonded (paired) Bluetooth devices. Clicking on a device will attempt a 31 * connection with that device. If a device is already connected, a click will prompt the user to 32 * disconnect. Devices are shown with an addition affordance which launches the device details page. 33 */ 34 public class BluetoothBondedDevicesPreferenceController extends 35 BluetoothDevicesGroupPreferenceController { 36 BluetoothBondedDevicesPreferenceController(Context context, String preferenceKey, FragmentController fragmentController, CarUxRestrictions uxRestrictions)37 public BluetoothBondedDevicesPreferenceController(Context context, String preferenceKey, 38 FragmentController fragmentController, CarUxRestrictions uxRestrictions) { 39 super(context, preferenceKey, fragmentController, uxRestrictions); 40 } 41 42 @Override getDeviceFilter()43 protected BluetoothDeviceFilter.Filter getDeviceFilter() { 44 return BluetoothDeviceFilter.BONDED_DEVICE_FILTER; 45 } 46 47 @Override createDevicePreference(CachedBluetoothDevice cachedDevice)48 protected BluetoothDevicePreference createDevicePreference(CachedBluetoothDevice cachedDevice) { 49 BluetoothDevicePreference pref = super.createDevicePreference(cachedDevice); 50 if (!getCarUserManagerHelper().isCurrentProcessUserHasRestriction( 51 DISALLOW_CONFIG_BLUETOOTH)) { 52 pref.setWidgetLayoutResource(R.layout.details_preference_widget); 53 pref.setOnButtonClickListener(preference -> getFragmentController().launchFragment( 54 BluetoothDeviceDetailsFragment.newInstance(cachedDevice))); 55 pref.showAction(true); 56 } 57 return pref; 58 } 59 60 @Override onDeviceClicked(CachedBluetoothDevice cachedDevice)61 protected void onDeviceClicked(CachedBluetoothDevice cachedDevice) { 62 if (cachedDevice.isConnected()) { 63 getFragmentController().showDialog( 64 BluetoothDisconnectConfirmDialogFragment.newInstance(cachedDevice), 65 /* tag= */ null); 66 } else { 67 cachedDevice.connect(/* connectAllProfiles= */ true); 68 } 69 } 70 71 @Override onDeviceBondStateChanged(CachedBluetoothDevice cachedDevice, int bondState)72 public void onDeviceBondStateChanged(CachedBluetoothDevice cachedDevice, int bondState) { 73 refreshUi(); 74 } 75 } 76