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 android.bluetooth.BluetoothAdapter; 20 import android.bluetooth.BluetoothDevice; 21 import android.content.Context; 22 import android.os.Bundle; 23 24 import androidx.annotation.XmlRes; 25 26 import com.android.car.settings.R; 27 import com.android.car.settings.common.SettingsFragment; 28 import com.android.settingslib.bluetooth.CachedBluetoothDevice; 29 import com.android.settingslib.bluetooth.LocalBluetoothManager; 30 31 /** 32 * Page which displays information for a remote Bluetooth device including the name, icon, 33 * connection status, supported profiles, and MAC. 34 */ 35 public class BluetoothDeviceDetailsFragment extends SettingsFragment { 36 37 private static final String KEY_DEVICE_ADDRESS = "device_address"; 38 39 private CachedBluetoothDevice mCachedDevice; 40 41 /** 42 * Returns a new {@link BluetoothDeviceDetailsFragment} for the given {@code device}. 43 */ newInstance(CachedBluetoothDevice device)44 public static BluetoothDeviceDetailsFragment newInstance(CachedBluetoothDevice device) { 45 Bundle args = new Bundle(); 46 args.putString(BluetoothDeviceDetailsFragment.KEY_DEVICE_ADDRESS, device.getAddress()); 47 BluetoothDeviceDetailsFragment fragment = new BluetoothDeviceDetailsFragment(); 48 fragment.setArguments(args); 49 return fragment; 50 } 51 52 @Override 53 @XmlRes getPreferenceScreenResId()54 protected int getPreferenceScreenResId() { 55 return R.xml.bluetooth_device_details_fragment; 56 } 57 58 @Override onAttach(Context context)59 public void onAttach(Context context) { 60 super.onAttach(context); 61 LocalBluetoothManager manager = BluetoothUtils.getLocalBtManager(context); 62 if (manager == null) { 63 goBack(); 64 return; 65 } 66 String deviceAddress = getArguments().getString(KEY_DEVICE_ADDRESS); 67 BluetoothDevice remoteDevice = BluetoothAdapter.getDefaultAdapter().getRemoteDevice( 68 deviceAddress); 69 mCachedDevice = manager.getCachedDeviceManager().findDevice(remoteDevice); 70 if (mCachedDevice == null) { 71 goBack(); 72 return; 73 } 74 75 use(BluetoothDeviceNamePreferenceController.class, 76 R.string.pk_bluetooth_device_name).setCachedDevice(mCachedDevice); 77 use(BluetoothDeviceActionButtonsPreferenceController.class, 78 R.string.pk_bluetooth_device_action_buttons).setCachedDevice(mCachedDevice); 79 use(BluetoothDeviceProfilesPreferenceController.class, 80 R.string.pk_bluetooth_device_profiles).setCachedDevice(mCachedDevice); 81 use(BluetoothDeviceAddressPreferenceController.class, 82 R.string.pk_bluetooth_device_address).setCachedDevice(mCachedDevice); 83 } 84 } 85