• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2017 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.bluetooth;
17 
18 import android.bluetooth.BluetoothDevice;
19 import android.content.Context;
20 import android.util.Log;
21 
22 import androidx.preference.Preference;
23 
24 import com.android.settings.connecteddevice.DevicePreferenceCallback;
25 import com.android.settings.dashboard.DashboardFragment;
26 import com.android.settingslib.bluetooth.CachedBluetoothDevice;
27 
28 /**
29  * Maintain and update saved bluetooth devices(bonded but not connected)
30  */
31 public class SavedBluetoothDeviceUpdater extends BluetoothDeviceUpdater
32         implements Preference.OnPreferenceClickListener {
33     private static final String TAG = "SavedBluetoothDeviceUpdater";
34     private static final boolean DBG = false;
35 
SavedBluetoothDeviceUpdater(Context context, DashboardFragment fragment, DevicePreferenceCallback devicePreferenceCallback)36     public SavedBluetoothDeviceUpdater(Context context, DashboardFragment fragment,
37             DevicePreferenceCallback devicePreferenceCallback) {
38         super(context, fragment, devicePreferenceCallback);
39     }
40 
41     @Override
isFilterMatched(CachedBluetoothDevice cachedDevice)42     public boolean isFilterMatched(CachedBluetoothDevice cachedDevice) {
43         final BluetoothDevice device = cachedDevice.getDevice();
44         if (DBG) {
45             Log.d(TAG, "isFilterMatched() device name : " + cachedDevice.getName() +
46                     ", is connected : " + device.isConnected() + ", is profile connected : "
47                     + cachedDevice.isConnected());
48         }
49         return device.getBondState() == BluetoothDevice.BOND_BONDED && !device.isConnected();
50     }
51 
52     @Override
onPreferenceClick(Preference preference)53     public boolean onPreferenceClick(Preference preference) {
54         final CachedBluetoothDevice device = ((BluetoothDevicePreference) preference)
55                 .getBluetoothDevice();
56         device.connect(true);
57         return true;
58     }
59 }
60