diff options
author | Jason Monk <jmonk@google.com> | 2015-05-19 12:04:41 -0400 |
---|---|---|
committer | Jason Monk <jmonk@google.com> | 2015-05-19 13:13:15 -0400 |
commit | 744cf647f71b1e5a012a90ef195bf2c3c486f418 (patch) | |
tree | 790226ba7df64cf2e107008989895b76699c9c8b /packages | |
parent | 7597dc7c4dfe49ba7c5d0e7568873521b90c6682 (diff) | |
download | frameworks_base-744cf647f71b1e5a012a90ef195bf2c3c486f418.zip frameworks_base-744cf647f71b1e5a012a90ef195bf2c3c486f418.tar.gz frameworks_base-744cf647f71b1e5a012a90ef195bf2c3c486f418.tar.bz2 |
SysUI: Move BT receivers to bg
Bug: 19520495
Change-Id: I58e7d023b9eaf67fccd1634e00803c8c8d871fff
Diffstat (limited to 'packages')
-rwxr-xr-x | packages/SettingsLib/src/com/android/settingslib/bluetooth/BluetoothEventManager.java | 15 | ||||
-rw-r--r-- | packages/SystemUI/src/com/android/systemui/statusbar/policy/BluetoothControllerImpl.java | 68 |
2 files changed, 57 insertions, 26 deletions
diff --git a/packages/SettingsLib/src/com/android/settingslib/bluetooth/BluetoothEventManager.java b/packages/SettingsLib/src/com/android/settingslib/bluetooth/BluetoothEventManager.java index 5d6b2f1..d3e7104 100755 --- a/packages/SettingsLib/src/com/android/settingslib/bluetooth/BluetoothEventManager.java +++ b/packages/SettingsLib/src/com/android/settingslib/bluetooth/BluetoothEventManager.java @@ -51,11 +51,13 @@ public final class BluetoothEventManager { private final Collection<BluetoothCallback> mCallbacks = new ArrayList<BluetoothCallback>(); + private android.os.Handler mReceiverHandler; + interface Handler { void onReceive(Context context, Intent intent, BluetoothDevice device); } - void addHandler(String action, Handler handler) { + private void addHandler(String action, Handler handler) { mHandlerMap.put(action, handler); mAdapterIntentFilter.addAction(action); } @@ -103,11 +105,18 @@ public final class BluetoothEventManager { // Dock event broadcasts addHandler(Intent.ACTION_DOCK_EVENT, new DockEventHandler()); - mContext.registerReceiver(mBroadcastReceiver, mAdapterIntentFilter); + mContext.registerReceiver(mBroadcastReceiver, mAdapterIntentFilter, null, mReceiverHandler); } void registerProfileIntentReceiver() { - mContext.registerReceiver(mBroadcastReceiver, mProfileIntentFilter); + mContext.registerReceiver(mBroadcastReceiver, mProfileIntentFilter, null, mReceiverHandler); + } + + public void setReceiverHandler(android.os.Handler handler) { + mContext.unregisterReceiver(mBroadcastReceiver); + mReceiverHandler = handler; + mContext.registerReceiver(mBroadcastReceiver, mAdapterIntentFilter, null, mReceiverHandler); + registerProfileIntentReceiver(); } /** Register to start receiving callbacks for Bluetooth events. */ diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/policy/BluetoothControllerImpl.java b/packages/SystemUI/src/com/android/systemui/statusbar/policy/BluetoothControllerImpl.java index 8d4f302..114427c 100644 --- a/packages/SystemUI/src/com/android/systemui/statusbar/policy/BluetoothControllerImpl.java +++ b/packages/SystemUI/src/com/android/systemui/statusbar/policy/BluetoothControllerImpl.java @@ -18,7 +18,9 @@ package com.android.systemui.statusbar.policy; import android.bluetooth.BluetoothAdapter; import android.content.Context; +import android.os.Handler; import android.os.Looper; +import android.os.Message; import android.util.Log; import com.android.settingslib.bluetooth.BluetoothCallback; @@ -42,9 +44,12 @@ public class BluetoothControllerImpl implements BluetoothController, BluetoothCa private boolean mConnecting; private CachedBluetoothDevice mLastDevice; + private final H mHandler = new H(); + public BluetoothControllerImpl(Context context, Looper bgLooper) { mLocalBluetoothManager = LocalBluetoothManager.getInstance(context, null); if (mLocalBluetoothManager != null) { + mLocalBluetoothManager.getEventManager().setReceiverHandler(new Handler(bgLooper)); mLocalBluetoothManager.getEventManager().registerCallback(this); onBluetoothStateChanged( mLocalBluetoothManager.getBluetoothAdapter().getBluetoothState()); @@ -71,7 +76,7 @@ public class BluetoothControllerImpl implements BluetoothController, BluetoothCa public void addStateChangedCallback(Callback cb) { mCallbacks.add(cb); - fireStateChange(cb); + mHandler.sendEmptyMessage(H.MSG_STATE_CHANGED); } @Override @@ -132,22 +137,6 @@ public class BluetoothControllerImpl implements BluetoothController, BluetoothCa : null; } - private void firePairedDevicesChanged() { - for (Callback cb : mCallbacks) { - cb.onBluetoothDevicesChanged(); - } - } - - private void fireStateChange() { - for (Callback cb : mCallbacks) { - fireStateChange(cb); - } - } - - private void fireStateChange(Callback cb) { - cb.onBluetoothStateChange(mEnabled, mConnecting); - } - private void updateConnected() { if (mLastDevice != null && mLastDevice.isConnected()) { // Our current device is still valid. @@ -163,7 +152,7 @@ public class BluetoothControllerImpl implements BluetoothController, BluetoothCa @Override public void onBluetoothStateChanged(int bluetoothState) { mEnabled = bluetoothState == BluetoothAdapter.STATE_ON; - fireStateChange(); + mHandler.sendEmptyMessage(H.MSG_STATE_CHANGED); } @Override @@ -175,25 +164,25 @@ public class BluetoothControllerImpl implements BluetoothController, BluetoothCa public void onDeviceAdded(CachedBluetoothDevice cachedDevice) { cachedDevice.registerCallback(this); updateConnected(); - firePairedDevicesChanged(); + mHandler.sendEmptyMessage(H.MSG_PAIRED_DEVICES_CHANGED); } @Override public void onDeviceDeleted(CachedBluetoothDevice cachedDevice) { updateConnected(); - firePairedDevicesChanged(); + mHandler.sendEmptyMessage(H.MSG_PAIRED_DEVICES_CHANGED); } @Override public void onDeviceBondStateChanged(CachedBluetoothDevice cachedDevice, int bondState) { updateConnected(); - firePairedDevicesChanged(); + mHandler.sendEmptyMessage(H.MSG_PAIRED_DEVICES_CHANGED); } @Override public void onDeviceAttributesChanged() { updateConnected(); - firePairedDevicesChanged(); + mHandler.sendEmptyMessage(H.MSG_PAIRED_DEVICES_CHANGED); } @Override @@ -201,6 +190,39 @@ public class BluetoothControllerImpl implements BluetoothController, BluetoothCa mConnecting = state == BluetoothAdapter.STATE_CONNECTING; mLastDevice = cachedDevice; updateConnected(); - fireStateChange(); + mHandler.sendEmptyMessage(H.MSG_STATE_CHANGED); + } + + private final class H extends Handler { + private static final int MSG_PAIRED_DEVICES_CHANGED = 1; + private static final int MSG_STATE_CHANGED = 2; + + @Override + public void handleMessage(Message msg) { + switch (msg.what) { + case MSG_PAIRED_DEVICES_CHANGED: + firePairedDevicesChanged(); + break; + case MSG_STATE_CHANGED: + fireStateChange(); + break; + } + } + + private void firePairedDevicesChanged() { + for (BluetoothController.Callback cb : mCallbacks) { + cb.onBluetoothDevicesChanged(); + } + } + + private void fireStateChange() { + for (BluetoothController.Callback cb : mCallbacks) { + fireStateChange(cb); + } + } + + private void fireStateChange(BluetoothController.Callback cb) { + cb.onBluetoothStateChange(mEnabled, mConnecting); + } } } |