Settings app: Run Bluetooth Event receiver when not in fg.
Also fix connection indication issues. Fixes bugs 3510336 and 3513352 Change-Id: Iaa47c9d7fd04fa5dd2700f55993ba2fd1a78fd70
This commit is contained in:
@@ -44,8 +44,9 @@ final class BluetoothEventManager {
|
||||
private final LocalBluetoothAdapter mLocalAdapter;
|
||||
private final CachedBluetoothDeviceManager mDeviceManager;
|
||||
private LocalBluetoothProfileManager mProfileManager;
|
||||
private final IntentFilter mIntentFilter;
|
||||
private final IntentFilter mAdapterIntentFilter, mProfileIntentFilter;
|
||||
private final Map<String, Handler> mHandlerMap;
|
||||
private Context mContext;
|
||||
|
||||
private final Collection<BluetoothCallback> mCallbacks =
|
||||
new ArrayList<BluetoothCallback>();
|
||||
@@ -56,7 +57,12 @@ final class BluetoothEventManager {
|
||||
|
||||
void addHandler(String action, Handler handler) {
|
||||
mHandlerMap.put(action, handler);
|
||||
mIntentFilter.addAction(action);
|
||||
mAdapterIntentFilter.addAction(action);
|
||||
}
|
||||
|
||||
void addProfileHandler(String action, Handler handler) {
|
||||
mHandlerMap.put(action, handler);
|
||||
mProfileIntentFilter.addAction(action);
|
||||
}
|
||||
|
||||
// Set profile manager after construction due to circular dependency
|
||||
@@ -65,11 +71,13 @@ final class BluetoothEventManager {
|
||||
}
|
||||
|
||||
BluetoothEventManager(LocalBluetoothAdapter adapter,
|
||||
CachedBluetoothDeviceManager deviceManager) {
|
||||
CachedBluetoothDeviceManager deviceManager, Context context) {
|
||||
mLocalAdapter = adapter;
|
||||
mDeviceManager = deviceManager;
|
||||
mIntentFilter = new IntentFilter();
|
||||
mAdapterIntentFilter = new IntentFilter();
|
||||
mProfileIntentFilter = new IntentFilter();
|
||||
mHandlerMap = new HashMap<String, Handler>();
|
||||
mContext = context;
|
||||
|
||||
// Bluetooth on/off broadcasts
|
||||
addHandler(BluetoothAdapter.ACTION_STATE_CHANGED, new AdapterStateChangedHandler());
|
||||
@@ -91,28 +99,11 @@ final class BluetoothEventManager {
|
||||
|
||||
// Dock event broadcasts
|
||||
addHandler(Intent.ACTION_DOCK_EVENT, new DockEventHandler());
|
||||
mContext.registerReceiver(mBroadcastReceiver, mAdapterIntentFilter);
|
||||
}
|
||||
|
||||
/**
|
||||
* A Bluetooth-related activity is now in the foreground. Register to
|
||||
* start receiving Bluetooth events.
|
||||
* @param context a Context object for the current Activity
|
||||
*/
|
||||
void resume(Context context) {
|
||||
if (mLocalAdapter.syncBluetoothState()) {
|
||||
// adapter state changed while we were paused: send callbacks
|
||||
int newState = mLocalAdapter.getState();
|
||||
synchronized (mCallbacks) {
|
||||
for (BluetoothCallback callback : mCallbacks) {
|
||||
callback.onBluetoothStateChanged(newState);
|
||||
}
|
||||
}
|
||||
}
|
||||
context.registerReceiver(mBroadcastReceiver, mIntentFilter);
|
||||
}
|
||||
|
||||
void pause(Context context) {
|
||||
context.unregisterReceiver(mBroadcastReceiver);
|
||||
void registerProfileIntentReceiver() {
|
||||
mContext.registerReceiver(mBroadcastReceiver, mProfileIntentFilter);
|
||||
}
|
||||
|
||||
/** Register to start receiving callbacks for Bluetooth events. */
|
||||
|
@@ -66,7 +66,7 @@ public final class LocalBluetoothManager {
|
||||
|
||||
mCachedDeviceManager = new CachedBluetoothDeviceManager();
|
||||
mEventManager = new BluetoothEventManager(mLocalAdapter,
|
||||
mCachedDeviceManager);
|
||||
mCachedDeviceManager, context);
|
||||
mProfileManager = new LocalBluetoothProfileManager(context,
|
||||
mLocalAdapter, mCachedDeviceManager, mEventManager);
|
||||
}
|
||||
@@ -87,11 +87,9 @@ public final class LocalBluetoothManager {
|
||||
if (context != null) {
|
||||
Log.d(TAG, "setting foreground activity to non-null context");
|
||||
mForegroundActivity = context;
|
||||
mEventManager.resume(context);
|
||||
} else {
|
||||
if (mForegroundActivity != null) {
|
||||
Log.d(TAG, "setting foreground activity to null");
|
||||
mEventManager.pause(mForegroundActivity);
|
||||
mForegroundActivity = null;
|
||||
}
|
||||
}
|
||||
|
@@ -159,6 +159,7 @@ final class LocalBluetoothProfileManager {
|
||||
} else if (mOppProfile != null) {
|
||||
Log.w(TAG, "Warning: OPP profile was previously added but the UUID is now missing.");
|
||||
}
|
||||
mEventManager.registerProfileIntentReceiver();
|
||||
|
||||
// There is no local SDP record for HID and Settings app doesn't control PBAP
|
||||
}
|
||||
@@ -168,7 +169,7 @@ final class LocalBluetoothProfileManager {
|
||||
|
||||
private void addProfile(LocalBluetoothProfile profile,
|
||||
String profileName, String stateChangedAction) {
|
||||
mEventManager.addHandler(stateChangedAction, new StateChangedHandler(profile));
|
||||
mEventManager.addProfileHandler(stateChangedAction, new StateChangedHandler(profile));
|
||||
mProfileNameMap.put(profileName, profile);
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user