John Spurlock | af8d6c4 | 2014-05-07 17:49:08 -0400 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2008 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.systemui.statusbar.policy; |
| 18 | |
Sudheer Shanka | b6fc931 | 2016-01-27 19:59:03 +0000 | [diff] [blame] | 19 | import android.app.ActivityManager; |
John Spurlock | af8d6c4 | 2014-05-07 17:49:08 -0400 | [diff] [blame] | 20 | import android.bluetooth.BluetoothAdapter; |
John Spurlock | af8d6c4 | 2014-05-07 17:49:08 -0400 | [diff] [blame] | 21 | import android.content.Context; |
Jason Monk | 744cf64 | 2015-05-19 12:04:41 -0400 | [diff] [blame] | 22 | import android.os.Handler; |
Jason Monk | 4ae97d3 | 2014-12-17 10:14:33 -0500 | [diff] [blame] | 23 | import android.os.Looper; |
Jason Monk | 744cf64 | 2015-05-19 12:04:41 -0400 | [diff] [blame] | 24 | import android.os.Message; |
Sudheer Shanka | b6fc931 | 2016-01-27 19:59:03 +0000 | [diff] [blame] | 25 | import android.os.UserHandle; |
| 26 | import android.os.UserManager; |
John Spurlock | 486b78e | 2014-07-07 08:37:56 -0400 | [diff] [blame] | 27 | import android.util.Log; |
John Spurlock | af8d6c4 | 2014-05-07 17:49:08 -0400 | [diff] [blame] | 28 | |
Jason Monk | be3c5db | 2015-02-04 13:00:55 -0500 | [diff] [blame] | 29 | import com.android.settingslib.bluetooth.BluetoothCallback; |
| 30 | import com.android.settingslib.bluetooth.CachedBluetoothDevice; |
| 31 | import com.android.settingslib.bluetooth.LocalBluetoothManager; |
Jason Monk | 6a73e63 | 2017-03-17 11:08:30 -0400 | [diff] [blame^] | 32 | import com.android.systemui.Dependency; |
John Spurlock | 486b78e | 2014-07-07 08:37:56 -0400 | [diff] [blame] | 33 | |
| 34 | import java.io.FileDescriptor; |
| 35 | import java.io.PrintWriter; |
John Spurlock | af8d6c4 | 2014-05-07 17:49:08 -0400 | [diff] [blame] | 36 | import java.util.ArrayList; |
Jason Monk | be3c5db | 2015-02-04 13:00:55 -0500 | [diff] [blame] | 37 | import java.util.Collection; |
John Spurlock | af8d6c4 | 2014-05-07 17:49:08 -0400 | [diff] [blame] | 38 | |
Jason Monk | be3c5db | 2015-02-04 13:00:55 -0500 | [diff] [blame] | 39 | public class BluetoothControllerImpl implements BluetoothController, BluetoothCallback, |
| 40 | CachedBluetoothDevice.Callback { |
John Spurlock | 486b78e | 2014-07-07 08:37:56 -0400 | [diff] [blame] | 41 | private static final String TAG = "BluetoothController"; |
| 42 | private static final boolean DEBUG = Log.isLoggable(TAG, Log.DEBUG); |
Jason Monk | 4ae97d3 | 2014-12-17 10:14:33 -0500 | [diff] [blame] | 43 | |
Jason Monk | be3c5db | 2015-02-04 13:00:55 -0500 | [diff] [blame] | 44 | private final LocalBluetoothManager mLocalBluetoothManager; |
Sudheer Shanka | b6fc931 | 2016-01-27 19:59:03 +0000 | [diff] [blame] | 45 | private final UserManager mUserManager; |
| 46 | private final int mCurrentUser; |
Jason Monk | 4ae97d3 | 2014-12-17 10:14:33 -0500 | [diff] [blame] | 47 | |
John Spurlock | d1c86e2 | 2014-06-01 00:04:53 -0400 | [diff] [blame] | 48 | private boolean mEnabled; |
Jason Monk | a7d92b6 | 2015-05-27 10:20:37 -0400 | [diff] [blame] | 49 | private int mConnectionState = BluetoothAdapter.STATE_DISCONNECTED; |
Jason Monk | be3c5db | 2015-02-04 13:00:55 -0500 | [diff] [blame] | 50 | private CachedBluetoothDevice mLastDevice; |
John Spurlock | af8d6c4 | 2014-05-07 17:49:08 -0400 | [diff] [blame] | 51 | |
Jason Monk | 744cf64 | 2015-05-19 12:04:41 -0400 | [diff] [blame] | 52 | private final H mHandler = new H(); |
Jason Monk | fac2538 | 2016-07-19 14:13:37 -0400 | [diff] [blame] | 53 | private int mState; |
Jason Monk | 744cf64 | 2015-05-19 12:04:41 -0400 | [diff] [blame] | 54 | |
Jason Monk | 4ae97d3 | 2014-12-17 10:14:33 -0500 | [diff] [blame] | 55 | public BluetoothControllerImpl(Context context, Looper bgLooper) { |
Jason Monk | 6a73e63 | 2017-03-17 11:08:30 -0400 | [diff] [blame^] | 56 | mLocalBluetoothManager = Dependency.get(LocalBluetoothManager.class); |
Jason Monk | be3c5db | 2015-02-04 13:00:55 -0500 | [diff] [blame] | 57 | if (mLocalBluetoothManager != null) { |
Jason Monk | 744cf64 | 2015-05-19 12:04:41 -0400 | [diff] [blame] | 58 | mLocalBluetoothManager.getEventManager().setReceiverHandler(new Handler(bgLooper)); |
Jason Monk | be3c5db | 2015-02-04 13:00:55 -0500 | [diff] [blame] | 59 | mLocalBluetoothManager.getEventManager().registerCallback(this); |
| 60 | onBluetoothStateChanged( |
| 61 | mLocalBluetoothManager.getBluetoothAdapter().getBluetoothState()); |
John Spurlock | af8d6c4 | 2014-05-07 17:49:08 -0400 | [diff] [blame] | 62 | } |
Sudheer Shanka | b6fc931 | 2016-01-27 19:59:03 +0000 | [diff] [blame] | 63 | mUserManager = (UserManager) context.getSystemService(Context.USER_SERVICE); |
| 64 | mCurrentUser = ActivityManager.getCurrentUser(); |
| 65 | } |
| 66 | |
| 67 | @Override |
| 68 | public boolean canConfigBluetooth() { |
| 69 | return !mUserManager.hasUserRestriction(UserManager.DISALLOW_CONFIG_BLUETOOTH, |
| 70 | UserHandle.of(mCurrentUser)); |
John Spurlock | af8d6c4 | 2014-05-07 17:49:08 -0400 | [diff] [blame] | 71 | } |
| 72 | |
John Spurlock | 486b78e | 2014-07-07 08:37:56 -0400 | [diff] [blame] | 73 | public void dump(FileDescriptor fd, PrintWriter pw, String[] args) { |
| 74 | pw.println("BluetoothController state:"); |
Jason Monk | be3c5db | 2015-02-04 13:00:55 -0500 | [diff] [blame] | 75 | pw.print(" mLocalBluetoothManager="); pw.println(mLocalBluetoothManager); |
Jason Monk | 09389a9 | 2015-05-19 16:06:52 -0400 | [diff] [blame] | 76 | if (mLocalBluetoothManager == null) { |
| 77 | return; |
| 78 | } |
John Spurlock | 486b78e | 2014-07-07 08:37:56 -0400 | [diff] [blame] | 79 | pw.print(" mEnabled="); pw.println(mEnabled); |
Jason Monk | a7d92b6 | 2015-05-27 10:20:37 -0400 | [diff] [blame] | 80 | pw.print(" mConnectionState="); pw.println(stateToString(mConnectionState)); |
John Spurlock | 486b78e | 2014-07-07 08:37:56 -0400 | [diff] [blame] | 81 | pw.print(" mLastDevice="); pw.println(mLastDevice); |
Adrian Roos | a4b5486 | 2016-06-17 14:28:27 -0700 | [diff] [blame] | 82 | pw.print(" mCallbacks.size="); pw.println(mHandler.mCallbacks.size()); |
Jason Monk | be3c5db | 2015-02-04 13:00:55 -0500 | [diff] [blame] | 83 | pw.println(" Bluetooth Devices:"); |
| 84 | for (CachedBluetoothDevice device : |
| 85 | mLocalBluetoothManager.getCachedDeviceManager().getCachedDevicesCopy()) { |
| 86 | pw.println(" " + getDeviceString(device)); |
John Spurlock | 486b78e | 2014-07-07 08:37:56 -0400 | [diff] [blame] | 87 | } |
| 88 | } |
| 89 | |
Jason Monk | a7d92b6 | 2015-05-27 10:20:37 -0400 | [diff] [blame] | 90 | private static String stateToString(int state) { |
| 91 | switch (state) { |
| 92 | case BluetoothAdapter.STATE_CONNECTED: |
| 93 | return "CONNECTED"; |
| 94 | case BluetoothAdapter.STATE_CONNECTING: |
| 95 | return "CONNECTING"; |
| 96 | case BluetoothAdapter.STATE_DISCONNECTED: |
| 97 | return "DISCONNECTED"; |
| 98 | case BluetoothAdapter.STATE_DISCONNECTING: |
| 99 | return "DISCONNECTING"; |
| 100 | } |
| 101 | return "UNKNOWN(" + state + ")"; |
| 102 | } |
| 103 | |
Jason Monk | be3c5db | 2015-02-04 13:00:55 -0500 | [diff] [blame] | 104 | private String getDeviceString(CachedBluetoothDevice device) { |
| 105 | return device.getName() + " " + device.getBondState() + " " + device.isConnected(); |
John Spurlock | 486b78e | 2014-07-07 08:37:56 -0400 | [diff] [blame] | 106 | } |
| 107 | |
Jason Monk | a7d92b6 | 2015-05-27 10:20:37 -0400 | [diff] [blame] | 108 | @Override |
Jason Monk | 8852905 | 2016-11-04 13:29:58 -0400 | [diff] [blame] | 109 | public void addCallback(Callback cb) { |
Adrian Roos | a4b5486 | 2016-06-17 14:28:27 -0700 | [diff] [blame] | 110 | mHandler.obtainMessage(H.MSG_ADD_CALLBACK, cb).sendToTarget(); |
Jason Monk | 744cf64 | 2015-05-19 12:04:41 -0400 | [diff] [blame] | 111 | mHandler.sendEmptyMessage(H.MSG_STATE_CHANGED); |
John Spurlock | af8d6c4 | 2014-05-07 17:49:08 -0400 | [diff] [blame] | 112 | } |
| 113 | |
| 114 | @Override |
Jason Monk | 8852905 | 2016-11-04 13:29:58 -0400 | [diff] [blame] | 115 | public void removeCallback(Callback cb) { |
Adrian Roos | a4b5486 | 2016-06-17 14:28:27 -0700 | [diff] [blame] | 116 | mHandler.obtainMessage(H.MSG_REMOVE_CALLBACK, cb).sendToTarget(); |
John Spurlock | af8d6c4 | 2014-05-07 17:49:08 -0400 | [diff] [blame] | 117 | } |
| 118 | |
| 119 | @Override |
| 120 | public boolean isBluetoothEnabled() { |
Jason Monk | be3c5db | 2015-02-04 13:00:55 -0500 | [diff] [blame] | 121 | return mEnabled; |
John Spurlock | af8d6c4 | 2014-05-07 17:49:08 -0400 | [diff] [blame] | 122 | } |
| 123 | |
| 124 | @Override |
Jason Monk | fac2538 | 2016-07-19 14:13:37 -0400 | [diff] [blame] | 125 | public int getBluetoothState() { |
| 126 | return mState; |
| 127 | } |
| 128 | |
| 129 | @Override |
John Spurlock | af8d6c4 | 2014-05-07 17:49:08 -0400 | [diff] [blame] | 130 | public boolean isBluetoothConnected() { |
Jason Monk | a7d92b6 | 2015-05-27 10:20:37 -0400 | [diff] [blame] | 131 | return mConnectionState == BluetoothAdapter.STATE_CONNECTED; |
John Spurlock | af8d6c4 | 2014-05-07 17:49:08 -0400 | [diff] [blame] | 132 | } |
| 133 | |
| 134 | @Override |
John Spurlock | d1c86e2 | 2014-06-01 00:04:53 -0400 | [diff] [blame] | 135 | public boolean isBluetoothConnecting() { |
Jason Monk | a7d92b6 | 2015-05-27 10:20:37 -0400 | [diff] [blame] | 136 | return mConnectionState == BluetoothAdapter.STATE_CONNECTING; |
John Spurlock | d1c86e2 | 2014-06-01 00:04:53 -0400 | [diff] [blame] | 137 | } |
| 138 | |
| 139 | @Override |
John Spurlock | af8d6c4 | 2014-05-07 17:49:08 -0400 | [diff] [blame] | 140 | public void setBluetoothEnabled(boolean enabled) { |
Jason Monk | be3c5db | 2015-02-04 13:00:55 -0500 | [diff] [blame] | 141 | if (mLocalBluetoothManager != null) { |
| 142 | mLocalBluetoothManager.getBluetoothAdapter().setBluetoothEnabled(enabled); |
John Spurlock | af8d6c4 | 2014-05-07 17:49:08 -0400 | [diff] [blame] | 143 | } |
| 144 | } |
| 145 | |
| 146 | @Override |
| 147 | public boolean isBluetoothSupported() { |
Jason Monk | be3c5db | 2015-02-04 13:00:55 -0500 | [diff] [blame] | 148 | return mLocalBluetoothManager != null; |
John Spurlock | af8d6c4 | 2014-05-07 17:49:08 -0400 | [diff] [blame] | 149 | } |
| 150 | |
John Spurlock | 486b78e | 2014-07-07 08:37:56 -0400 | [diff] [blame] | 151 | @Override |
Jason Monk | be3c5db | 2015-02-04 13:00:55 -0500 | [diff] [blame] | 152 | public void connect(final CachedBluetoothDevice device) { |
| 153 | if (mLocalBluetoothManager == null || device == null) return; |
| 154 | device.connect(true); |
John Spurlock | 486b78e | 2014-07-07 08:37:56 -0400 | [diff] [blame] | 155 | } |
| 156 | |
| 157 | @Override |
Jason Monk | be3c5db | 2015-02-04 13:00:55 -0500 | [diff] [blame] | 158 | public void disconnect(CachedBluetoothDevice device) { |
| 159 | if (mLocalBluetoothManager == null || device == null) return; |
| 160 | device.disconnect(); |
John Spurlock | af8d6c4 | 2014-05-07 17:49:08 -0400 | [diff] [blame] | 161 | } |
| 162 | |
| 163 | @Override |
John Spurlock | d1c86e2 | 2014-06-01 00:04:53 -0400 | [diff] [blame] | 164 | public String getLastDeviceName() { |
Jason Monk | be3c5db | 2015-02-04 13:00:55 -0500 | [diff] [blame] | 165 | return mLastDevice != null ? mLastDevice.getName() : null; |
John Spurlock | af8d6c4 | 2014-05-07 17:49:08 -0400 | [diff] [blame] | 166 | } |
| 167 | |
Jason Monk | be3c5db | 2015-02-04 13:00:55 -0500 | [diff] [blame] | 168 | @Override |
| 169 | public Collection<CachedBluetoothDevice> getDevices() { |
| 170 | return mLocalBluetoothManager != null |
| 171 | ? mLocalBluetoothManager.getCachedDeviceManager().getCachedDevicesCopy() |
| 172 | : null; |
Jason Monk | 4630c89 | 2014-12-08 16:36:16 -0500 | [diff] [blame] | 173 | } |
| 174 | |
Jason Monk | be3c5db | 2015-02-04 13:00:55 -0500 | [diff] [blame] | 175 | private void updateConnected() { |
Jason Monk | 9097056 | 2015-06-19 10:04:49 -0400 | [diff] [blame] | 176 | // Make sure our connection state is up to date. |
| 177 | int state = mLocalBluetoothManager.getBluetoothAdapter().getConnectionState(); |
Jason Monk | 6a73e63 | 2017-03-17 11:08:30 -0400 | [diff] [blame^] | 178 | if (mLastDevice != null && !mLastDevice.isConnected()) { |
| 179 | // Clear out last device if no longer connected. |
| 180 | mLastDevice = null; |
Jason Monk | 9097056 | 2015-06-19 10:04:49 -0400 | [diff] [blame] | 181 | } |
Jason Monk | 6a73e63 | 2017-03-17 11:08:30 -0400 | [diff] [blame^] | 182 | // If any of the devices are in a higher state than the adapter, move the adapter into |
| 183 | // that state. |
Jason Monk | be3c5db | 2015-02-04 13:00:55 -0500 | [diff] [blame] | 184 | for (CachedBluetoothDevice device : getDevices()) { |
Jason Monk | 6a73e63 | 2017-03-17 11:08:30 -0400 | [diff] [blame^] | 185 | int maxDeviceState = device.getMaxConnectionState(); |
| 186 | if (maxDeviceState > state) { |
| 187 | state = maxDeviceState; |
| 188 | } |
| 189 | if (mLastDevice == null && device.isConnected()) { |
| 190 | // Set as last connected device only if we don't have one. |
John Spurlock | 486b78e | 2014-07-07 08:37:56 -0400 | [diff] [blame] | 191 | mLastDevice = device; |
John Spurlock | 486b78e | 2014-07-07 08:37:56 -0400 | [diff] [blame] | 192 | } |
John Spurlock | 486b78e | 2014-07-07 08:37:56 -0400 | [diff] [blame] | 193 | } |
Jason Monk | 6a73e63 | 2017-03-17 11:08:30 -0400 | [diff] [blame^] | 194 | |
| 195 | if (mLastDevice == null && state == BluetoothAdapter.STATE_CONNECTED) { |
Jason Monk | bba7317 | 2015-08-12 16:17:34 -0400 | [diff] [blame] | 196 | // If somehow we think we are connected, but have no connected devices, we aren't |
| 197 | // connected. |
Jason Monk | 6a73e63 | 2017-03-17 11:08:30 -0400 | [diff] [blame^] | 198 | state = BluetoothAdapter.STATE_DISCONNECTED; |
| 199 | } |
| 200 | if (state != mConnectionState) { |
| 201 | mConnectionState = state; |
Jason Monk | bba7317 | 2015-08-12 16:17:34 -0400 | [diff] [blame] | 202 | mHandler.sendEmptyMessage(H.MSG_STATE_CHANGED); |
| 203 | } |
John Spurlock | 486b78e | 2014-07-07 08:37:56 -0400 | [diff] [blame] | 204 | } |
| 205 | |
Jason Monk | be3c5db | 2015-02-04 13:00:55 -0500 | [diff] [blame] | 206 | @Override |
| 207 | public void onBluetoothStateChanged(int bluetoothState) { |
Jason Monk | fac2538 | 2016-07-19 14:13:37 -0400 | [diff] [blame] | 208 | mEnabled = bluetoothState == BluetoothAdapter.STATE_ON |
| 209 | || bluetoothState == BluetoothAdapter.STATE_TURNING_ON; |
| 210 | mState = bluetoothState; |
Jason Monk | 744cf64 | 2015-05-19 12:04:41 -0400 | [diff] [blame] | 211 | mHandler.sendEmptyMessage(H.MSG_STATE_CHANGED); |
John Spurlock | 486b78e | 2014-07-07 08:37:56 -0400 | [diff] [blame] | 212 | } |
| 213 | |
Jason Monk | be3c5db | 2015-02-04 13:00:55 -0500 | [diff] [blame] | 214 | @Override |
| 215 | public void onScanningStateChanged(boolean started) { |
| 216 | // Don't care. |
| 217 | } |
Jason Monk | 4ae97d3 | 2014-12-17 10:14:33 -0500 | [diff] [blame] | 218 | |
Jason Monk | be3c5db | 2015-02-04 13:00:55 -0500 | [diff] [blame] | 219 | @Override |
| 220 | public void onDeviceAdded(CachedBluetoothDevice cachedDevice) { |
| 221 | cachedDevice.registerCallback(this); |
| 222 | updateConnected(); |
Jason Monk | 744cf64 | 2015-05-19 12:04:41 -0400 | [diff] [blame] | 223 | mHandler.sendEmptyMessage(H.MSG_PAIRED_DEVICES_CHANGED); |
Jason Monk | be3c5db | 2015-02-04 13:00:55 -0500 | [diff] [blame] | 224 | } |
Jason Monk | 4ae97d3 | 2014-12-17 10:14:33 -0500 | [diff] [blame] | 225 | |
Jason Monk | be3c5db | 2015-02-04 13:00:55 -0500 | [diff] [blame] | 226 | @Override |
| 227 | public void onDeviceDeleted(CachedBluetoothDevice cachedDevice) { |
| 228 | updateConnected(); |
Jason Monk | 744cf64 | 2015-05-19 12:04:41 -0400 | [diff] [blame] | 229 | mHandler.sendEmptyMessage(H.MSG_PAIRED_DEVICES_CHANGED); |
Jason Monk | be3c5db | 2015-02-04 13:00:55 -0500 | [diff] [blame] | 230 | } |
| 231 | |
| 232 | @Override |
| 233 | public void onDeviceBondStateChanged(CachedBluetoothDevice cachedDevice, int bondState) { |
| 234 | updateConnected(); |
Jason Monk | 744cf64 | 2015-05-19 12:04:41 -0400 | [diff] [blame] | 235 | mHandler.sendEmptyMessage(H.MSG_PAIRED_DEVICES_CHANGED); |
Jason Monk | be3c5db | 2015-02-04 13:00:55 -0500 | [diff] [blame] | 236 | } |
| 237 | |
| 238 | @Override |
| 239 | public void onDeviceAttributesChanged() { |
| 240 | updateConnected(); |
Jason Monk | 744cf64 | 2015-05-19 12:04:41 -0400 | [diff] [blame] | 241 | mHandler.sendEmptyMessage(H.MSG_PAIRED_DEVICES_CHANGED); |
Jason Monk | be3c5db | 2015-02-04 13:00:55 -0500 | [diff] [blame] | 242 | } |
| 243 | |
| 244 | @Override |
| 245 | public void onConnectionStateChanged(CachedBluetoothDevice cachedDevice, int state) { |
Jason Monk | be3c5db | 2015-02-04 13:00:55 -0500 | [diff] [blame] | 246 | mLastDevice = cachedDevice; |
| 247 | updateConnected(); |
Jason Monk | 744cf64 | 2015-05-19 12:04:41 -0400 | [diff] [blame] | 248 | mHandler.sendEmptyMessage(H.MSG_STATE_CHANGED); |
| 249 | } |
| 250 | |
| 251 | private final class H extends Handler { |
Adrian Roos | a4b5486 | 2016-06-17 14:28:27 -0700 | [diff] [blame] | 252 | private final ArrayList<BluetoothController.Callback> mCallbacks = new ArrayList<>(); |
| 253 | |
Jason Monk | 744cf64 | 2015-05-19 12:04:41 -0400 | [diff] [blame] | 254 | private static final int MSG_PAIRED_DEVICES_CHANGED = 1; |
| 255 | private static final int MSG_STATE_CHANGED = 2; |
Adrian Roos | a4b5486 | 2016-06-17 14:28:27 -0700 | [diff] [blame] | 256 | private static final int MSG_ADD_CALLBACK = 3; |
| 257 | private static final int MSG_REMOVE_CALLBACK = 4; |
Jason Monk | 744cf64 | 2015-05-19 12:04:41 -0400 | [diff] [blame] | 258 | |
| 259 | @Override |
| 260 | public void handleMessage(Message msg) { |
| 261 | switch (msg.what) { |
| 262 | case MSG_PAIRED_DEVICES_CHANGED: |
| 263 | firePairedDevicesChanged(); |
| 264 | break; |
| 265 | case MSG_STATE_CHANGED: |
| 266 | fireStateChange(); |
| 267 | break; |
Adrian Roos | a4b5486 | 2016-06-17 14:28:27 -0700 | [diff] [blame] | 268 | case MSG_ADD_CALLBACK: |
| 269 | mCallbacks.add((BluetoothController.Callback) msg.obj); |
| 270 | break; |
| 271 | case MSG_REMOVE_CALLBACK: |
| 272 | mCallbacks.remove((BluetoothController.Callback) msg.obj); |
| 273 | break; |
Jason Monk | 744cf64 | 2015-05-19 12:04:41 -0400 | [diff] [blame] | 274 | } |
| 275 | } |
| 276 | |
| 277 | private void firePairedDevicesChanged() { |
| 278 | for (BluetoothController.Callback cb : mCallbacks) { |
| 279 | cb.onBluetoothDevicesChanged(); |
| 280 | } |
| 281 | } |
| 282 | |
| 283 | private void fireStateChange() { |
| 284 | for (BluetoothController.Callback cb : mCallbacks) { |
| 285 | fireStateChange(cb); |
| 286 | } |
| 287 | } |
| 288 | |
| 289 | private void fireStateChange(BluetoothController.Callback cb) { |
Jason Monk | a7d92b6 | 2015-05-27 10:20:37 -0400 | [diff] [blame] | 290 | cb.onBluetoothStateChange(mEnabled); |
Jason Monk | 744cf64 | 2015-05-19 12:04:41 -0400 | [diff] [blame] | 291 | } |
John Spurlock | 486b78e | 2014-07-07 08:37:56 -0400 | [diff] [blame] | 292 | } |
John Spurlock | af8d6c4 | 2014-05-07 17:49:08 -0400 | [diff] [blame] | 293 | } |