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.settings.connecteddevice; 17 18 import android.app.settings.SettingsEnums; 19 import android.bluetooth.BluetoothAdapter; 20 import android.content.Context; 21 import android.os.Bundle; 22 23 import androidx.annotation.VisibleForTesting; 24 25 import com.android.settings.R; 26 import com.android.settings.dashboard.DashboardFragment; 27 import com.android.settings.search.BaseSearchIndexProvider; 28 import com.android.settingslib.search.SearchIndexable; 29 30 /** 31 * This fragment contains previously connected device 32 */ 33 @SearchIndexable(forTarget = SearchIndexable.MOBILE) 34 public class PreviouslyConnectedDeviceDashboardFragment extends DashboardFragment { 35 36 private static final String TAG = "PreConnectedDeviceFrag"; 37 static final String KEY_PREVIOUSLY_CONNECTED_DEVICES = "saved_device_list"; 38 39 @VisibleForTesting 40 BluetoothAdapter mBluetoothAdapter; 41 42 @Override getHelpResource()43 public int getHelpResource() { 44 return R.string.help_url_previously_connected_devices; 45 } 46 47 @Override getPreferenceScreenResId()48 protected int getPreferenceScreenResId() { 49 return R.xml.previously_connected_devices; 50 } 51 52 @Override getLogTag()53 protected String getLogTag() { 54 return TAG; 55 } 56 57 @Override getMetricsCategory()58 public int getMetricsCategory() { 59 return SettingsEnums.PREVIOUSLY_CONNECTED_DEVICES; 60 } 61 62 @Override onCreate(Bundle savedInstanceState)63 public void onCreate(Bundle savedInstanceState) { 64 super.onCreate(savedInstanceState); 65 66 mBluetoothAdapter = BluetoothAdapter.getDefaultAdapter(); 67 } 68 69 @Override onAttach(Context context)70 public void onAttach(Context context) { 71 super.onAttach(context); 72 use(SavedDeviceGroupController.class).init(this); 73 } 74 75 @Override onStart()76 public void onStart() { 77 super.onStart(); 78 enableBluetoothIfNecessary(); 79 } 80 81 @VisibleForTesting enableBluetoothIfNecessary()82 void enableBluetoothIfNecessary() { 83 if (mBluetoothAdapter != null && !mBluetoothAdapter.isEnabled()) { 84 mBluetoothAdapter.enable(); 85 } 86 } 87 88 /** 89 * For Search. 90 */ 91 public static final BaseSearchIndexProvider SEARCH_INDEX_DATA_PROVIDER = 92 new BaseSearchIndexProvider(R.xml.previously_connected_devices); 93 }