Loading packages/SettingsLib/src/com/android/settingslib/bluetooth/BluetoothEventManager.java +5 −19 Original line number Diff line number Diff line Loading @@ -53,22 +53,23 @@ public class BluetoothEventManager { private final BroadcastReceiver mBroadcastReceiver = new BluetoothBroadcastReceiver(); private final BroadcastReceiver mProfileBroadcastReceiver = new BluetoothBroadcastReceiver(); private final Collection<BluetoothCallback> mCallbacks = new ArrayList<>(); private android.os.Handler mReceiverHandler; private Context mContext; private final android.os.Handler mReceiverHandler; private final Context mContext; interface Handler { void onReceive(Context context, Intent intent, BluetoothDevice device); } BluetoothEventManager(LocalBluetoothAdapter adapter, CachedBluetoothDeviceManager deviceManager, Context context) { CachedBluetoothDeviceManager deviceManager, Context context, android.os.Handler handler) { mLocalAdapter = adapter; mDeviceManager = deviceManager; mAdapterIntentFilter = new IntentFilter(); mProfileIntentFilter = new IntentFilter(); mHandlerMap = new HashMap<>(); mContext = context; mReceiverHandler = handler; // Bluetooth on/off broadcasts addHandler(BluetoothAdapter.ACTION_STATE_CHANGED, new AdapterStateChangedHandler()); Loading Loading @@ -104,15 +105,6 @@ public class BluetoothEventManager { new AudioModeChangedHandler()); mContext.registerReceiver(mBroadcastReceiver, mAdapterIntentFilter, null, mReceiverHandler); mContext.registerReceiver(mProfileBroadcastReceiver, mProfileIntentFilter, null, mReceiverHandler); } public void setReceiverHandler(android.os.Handler handler) { mContext.unregisterReceiver(mBroadcastReceiver); mContext.unregisterReceiver(mProfileBroadcastReceiver); mReceiverHandler = handler; mContext.registerReceiver(mBroadcastReceiver, mAdapterIntentFilter, null, mReceiverHandler); registerProfileIntentReceiver(); } /** Register to start receiving callbacks for Bluetooth events. */ Loading Loading @@ -233,12 +225,6 @@ public class BluetoothEventManager { BluetoothDevice device) { int state = intent.getIntExtra(BluetoothAdapter.EXTRA_STATE, BluetoothAdapter.ERROR); // Reregister Profile Broadcast Receiver as part of TURN OFF if (state == BluetoothAdapter.STATE_OFF) { context.unregisterReceiver(mProfileBroadcastReceiver); registerProfileIntentReceiver(); } // update local profiles and get paired devices mLocalAdapter.setBluetoothStateInt(state); // send callback to update UI and possibly start scanning Loading packages/SettingsLib/src/com/android/settingslib/bluetooth/LocalBluetoothManager.java +17 −4 Original line number Diff line number Diff line Loading @@ -17,6 +17,7 @@ package com.android.settingslib.bluetooth; import android.content.Context; import android.os.Handler; import android.util.Log; import java.lang.ref.WeakReference; Loading Loading @@ -57,7 +58,7 @@ public class LocalBluetoothManager { } // This will be around as long as this process is Context appContext = context.getApplicationContext(); sInstance = new LocalBluetoothManager(adapter, appContext); sInstance = new LocalBluetoothManager(adapter, appContext, null); if (onInitCallback != null) { onInitCallback.onBluetoothManagerInitialized(appContext, sInstance); } Loading @@ -66,13 +67,25 @@ public class LocalBluetoothManager { return sInstance; } private LocalBluetoothManager(LocalBluetoothAdapter adapter, Context context) { /** * Returns a new instance of {@link LocalBluetoothManager} or null if Bluetooth is not * supported for this hardware. This instance should be globally cached by the caller. */ public static LocalBluetoothManager create(Context context, Handler handler) { LocalBluetoothAdapter adapter = LocalBluetoothAdapter.getInstance(); if (adapter == null) { return null; } return new LocalBluetoothManager(adapter, context.getApplicationContext(), handler); } private LocalBluetoothManager( LocalBluetoothAdapter adapter, Context context, Handler handler) { mContext = context; mLocalAdapter = adapter; mCachedDeviceManager = new CachedBluetoothDeviceManager(context, this); mEventManager = new BluetoothEventManager(mLocalAdapter, mCachedDeviceManager, context); mCachedDeviceManager, context, handler); mProfileManager = new LocalBluetoothProfileManager(context, mLocalAdapter, mCachedDeviceManager, mEventManager); Loading packages/SettingsLib/tests/robotests/src/com/android/settingslib/bluetooth/BluetoothEventManagerTest.java +1 −1 Original line number Diff line number Diff line Loading @@ -54,7 +54,7 @@ public class BluetoothEventManagerTest { mContext = RuntimeEnvironment.application; mBluetoothEventManager = new BluetoothEventManager(mLocalAdapter, mCachedDeviceManager, mContext); mCachedDeviceManager, mContext, null); } /** Loading packages/SettingsLib/tests/robotests/src/com/android/settingslib/bluetooth/LocalBluetoothProfileManagerTest.java +7 −19 Original line number Diff line number Diff line Loading @@ -76,7 +76,7 @@ public class LocalBluetoothProfileManagerTest { mContext = spy(RuntimeEnvironment.application); mLocalBluetoothAdapter = LocalBluetoothAdapter.getInstance(); mEventManager = spy(new BluetoothEventManager(mLocalBluetoothAdapter, mDeviceManager, mContext)); mContext, null)); mShadowBluetoothAdapter = Shadow.extract(BluetoothAdapter.getDefaultAdapter()); when(mDeviceManager.findDevice(mDevice)).thenReturn(mCachedBluetoothDevice); mProfileManager = new LocalBluetoothProfileManager(mContext, mLocalBluetoothAdapter, Loading Loading @@ -151,9 +151,7 @@ public class LocalBluetoothProfileManagerTest { mShadowBluetoothAdapter.setSupportedProfiles(generateList( new int[] {BluetoothProfile.A2DP})); mProfileManager.updateLocalProfiles(); // Refer to BluetoothControllerImpl, it will call setReceiverHandler after // LocalBluetoothProfileManager created. mEventManager.setReceiverHandler(null); mIntent = new Intent(BluetoothA2dp.ACTION_CONNECTION_STATE_CHANGED); mIntent.putExtra(BluetoothDevice.EXTRA_DEVICE, mDevice); mIntent.putExtra(BluetoothProfile.EXTRA_PREVIOUS_STATE, BluetoothProfile.STATE_CONNECTING); Loading @@ -174,9 +172,7 @@ public class LocalBluetoothProfileManagerTest { mShadowBluetoothAdapter.setSupportedProfiles(generateList( new int[] {BluetoothProfile.HEADSET})); mProfileManager.updateLocalProfiles(); // Refer to BluetoothControllerImpl, it will call setReceiverHandler after // LocalBluetoothProfileManager created. mEventManager.setReceiverHandler(null); mIntent = new Intent(BluetoothHeadset.ACTION_CONNECTION_STATE_CHANGED); mIntent.putExtra(BluetoothDevice.EXTRA_DEVICE, mDevice); mIntent.putExtra(BluetoothProfile.EXTRA_PREVIOUS_STATE, BluetoothProfile.STATE_CONNECTING); Loading @@ -197,9 +193,7 @@ public class LocalBluetoothProfileManagerTest { mShadowBluetoothAdapter.setSupportedProfiles(generateList( new int[] {BluetoothProfile.HEARING_AID})); mProfileManager.updateLocalProfiles(); // Refer to BluetoothControllerImpl, it will call setReceiverHandler after // LocalBluetoothProfileManager created. mEventManager.setReceiverHandler(null); mIntent = new Intent(BluetoothHearingAid.ACTION_CONNECTION_STATE_CHANGED); mIntent.putExtra(BluetoothDevice.EXTRA_DEVICE, mDevice); mIntent.putExtra(BluetoothProfile.EXTRA_PREVIOUS_STATE, BluetoothProfile.STATE_CONNECTING); Loading @@ -220,9 +214,7 @@ public class LocalBluetoothProfileManagerTest { mShadowBluetoothAdapter.setSupportedProfiles(generateList( new int[] {BluetoothProfile.PAN})); mProfileManager.updateLocalProfiles(); // Refer to BluetoothControllerImpl, it will call setReceiverHandler after // LocalBluetoothProfileManager created. mEventManager.setReceiverHandler(null); mIntent = new Intent(BluetoothPan.ACTION_CONNECTION_STATE_CHANGED); mIntent.putExtra(BluetoothDevice.EXTRA_DEVICE, mDevice); mIntent.putExtra(BluetoothProfile.EXTRA_PREVIOUS_STATE, BluetoothProfile.STATE_CONNECTING); Loading @@ -243,9 +235,7 @@ public class LocalBluetoothProfileManagerTest { () { mShadowBluetoothAdapter.setSupportedProfiles(null); mProfileManager.updateLocalProfiles(); // Refer to BluetoothControllerImpl, it will call setReceiverHandler after // LocalBluetoothProfileManager created. mEventManager.setReceiverHandler(null); mIntent = new Intent(BluetoothPan.ACTION_CONNECTION_STATE_CHANGED); mIntent.putExtra(BluetoothDevice.EXTRA_DEVICE, mDevice); mIntent.putExtra(BluetoothProfile.EXTRA_PREVIOUS_STATE, BluetoothProfile.STATE_CONNECTING); Loading @@ -265,9 +255,7 @@ public class LocalBluetoothProfileManagerTest { mShadowBluetoothAdapter.setSupportedProfiles(generateList( new int[] {BluetoothProfile.PAN})); mProfileManager.updateLocalProfiles(); // Refer to BluetoothControllerImpl, it will call setReceiverHandler after // LocalBluetoothProfileManager created. mEventManager.setReceiverHandler(null); mIntent = new Intent(BluetoothPan.ACTION_CONNECTION_STATE_CHANGED); mIntent.putExtra(BluetoothDevice.EXTRA_DEVICE, mDevice); mIntent.putExtra(BluetoothProfile.EXTRA_PREVIOUS_STATE, BluetoothProfile.STATE_CONNECTING); Loading packages/SystemUI/src/com/android/systemui/Dependency.java +6 −1 Original line number Diff line number Diff line Loading @@ -132,6 +132,10 @@ public class Dependency extends SystemUI { * Key for getting a background Looper for background work. */ public static final DependencyKey<Looper> BG_LOOPER = new DependencyKey<>("background_looper"); /** * Key for getting a background Handler for background work. */ public static final DependencyKey<Handler> BG_HANDLER = new DependencyKey<>("background_handler"); /** * Key for getting a Handler for receiving time tick broadcasts on. */ Loading Loading @@ -166,6 +170,7 @@ public class Dependency extends SystemUI { thread.start(); return thread.getLooper(); }); mProviders.put(BG_HANDLER, () -> new Handler(getDependency(BG_LOOPER))); mProviders.put(MAIN_HANDLER, () -> new Handler(Looper.getMainLooper())); mProviders.put(ActivityStarter.class, () -> new ActivityStarterDelegate()); mProviders.put(ActivityStarterDelegate.class, () -> Loading Loading @@ -288,7 +293,7 @@ public class Dependency extends SystemUI { new PluginDependencyProvider(get(PluginManager.class))); mProviders.put(LocalBluetoothManager.class, () -> LocalBluetoothManager.getInstance(mContext, null)); LocalBluetoothManager.create(mContext, getDependency(BG_HANDLER))); mProviders.put(VolumeDialogController.class, () -> new VolumeDialogControllerImpl(mContext)); Loading Loading
packages/SettingsLib/src/com/android/settingslib/bluetooth/BluetoothEventManager.java +5 −19 Original line number Diff line number Diff line Loading @@ -53,22 +53,23 @@ public class BluetoothEventManager { private final BroadcastReceiver mBroadcastReceiver = new BluetoothBroadcastReceiver(); private final BroadcastReceiver mProfileBroadcastReceiver = new BluetoothBroadcastReceiver(); private final Collection<BluetoothCallback> mCallbacks = new ArrayList<>(); private android.os.Handler mReceiverHandler; private Context mContext; private final android.os.Handler mReceiverHandler; private final Context mContext; interface Handler { void onReceive(Context context, Intent intent, BluetoothDevice device); } BluetoothEventManager(LocalBluetoothAdapter adapter, CachedBluetoothDeviceManager deviceManager, Context context) { CachedBluetoothDeviceManager deviceManager, Context context, android.os.Handler handler) { mLocalAdapter = adapter; mDeviceManager = deviceManager; mAdapterIntentFilter = new IntentFilter(); mProfileIntentFilter = new IntentFilter(); mHandlerMap = new HashMap<>(); mContext = context; mReceiverHandler = handler; // Bluetooth on/off broadcasts addHandler(BluetoothAdapter.ACTION_STATE_CHANGED, new AdapterStateChangedHandler()); Loading Loading @@ -104,15 +105,6 @@ public class BluetoothEventManager { new AudioModeChangedHandler()); mContext.registerReceiver(mBroadcastReceiver, mAdapterIntentFilter, null, mReceiverHandler); mContext.registerReceiver(mProfileBroadcastReceiver, mProfileIntentFilter, null, mReceiverHandler); } public void setReceiverHandler(android.os.Handler handler) { mContext.unregisterReceiver(mBroadcastReceiver); mContext.unregisterReceiver(mProfileBroadcastReceiver); mReceiverHandler = handler; mContext.registerReceiver(mBroadcastReceiver, mAdapterIntentFilter, null, mReceiverHandler); registerProfileIntentReceiver(); } /** Register to start receiving callbacks for Bluetooth events. */ Loading Loading @@ -233,12 +225,6 @@ public class BluetoothEventManager { BluetoothDevice device) { int state = intent.getIntExtra(BluetoothAdapter.EXTRA_STATE, BluetoothAdapter.ERROR); // Reregister Profile Broadcast Receiver as part of TURN OFF if (state == BluetoothAdapter.STATE_OFF) { context.unregisterReceiver(mProfileBroadcastReceiver); registerProfileIntentReceiver(); } // update local profiles and get paired devices mLocalAdapter.setBluetoothStateInt(state); // send callback to update UI and possibly start scanning Loading
packages/SettingsLib/src/com/android/settingslib/bluetooth/LocalBluetoothManager.java +17 −4 Original line number Diff line number Diff line Loading @@ -17,6 +17,7 @@ package com.android.settingslib.bluetooth; import android.content.Context; import android.os.Handler; import android.util.Log; import java.lang.ref.WeakReference; Loading Loading @@ -57,7 +58,7 @@ public class LocalBluetoothManager { } // This will be around as long as this process is Context appContext = context.getApplicationContext(); sInstance = new LocalBluetoothManager(adapter, appContext); sInstance = new LocalBluetoothManager(adapter, appContext, null); if (onInitCallback != null) { onInitCallback.onBluetoothManagerInitialized(appContext, sInstance); } Loading @@ -66,13 +67,25 @@ public class LocalBluetoothManager { return sInstance; } private LocalBluetoothManager(LocalBluetoothAdapter adapter, Context context) { /** * Returns a new instance of {@link LocalBluetoothManager} or null if Bluetooth is not * supported for this hardware. This instance should be globally cached by the caller. */ public static LocalBluetoothManager create(Context context, Handler handler) { LocalBluetoothAdapter adapter = LocalBluetoothAdapter.getInstance(); if (adapter == null) { return null; } return new LocalBluetoothManager(adapter, context.getApplicationContext(), handler); } private LocalBluetoothManager( LocalBluetoothAdapter adapter, Context context, Handler handler) { mContext = context; mLocalAdapter = adapter; mCachedDeviceManager = new CachedBluetoothDeviceManager(context, this); mEventManager = new BluetoothEventManager(mLocalAdapter, mCachedDeviceManager, context); mCachedDeviceManager, context, handler); mProfileManager = new LocalBluetoothProfileManager(context, mLocalAdapter, mCachedDeviceManager, mEventManager); Loading
packages/SettingsLib/tests/robotests/src/com/android/settingslib/bluetooth/BluetoothEventManagerTest.java +1 −1 Original line number Diff line number Diff line Loading @@ -54,7 +54,7 @@ public class BluetoothEventManagerTest { mContext = RuntimeEnvironment.application; mBluetoothEventManager = new BluetoothEventManager(mLocalAdapter, mCachedDeviceManager, mContext); mCachedDeviceManager, mContext, null); } /** Loading
packages/SettingsLib/tests/robotests/src/com/android/settingslib/bluetooth/LocalBluetoothProfileManagerTest.java +7 −19 Original line number Diff line number Diff line Loading @@ -76,7 +76,7 @@ public class LocalBluetoothProfileManagerTest { mContext = spy(RuntimeEnvironment.application); mLocalBluetoothAdapter = LocalBluetoothAdapter.getInstance(); mEventManager = spy(new BluetoothEventManager(mLocalBluetoothAdapter, mDeviceManager, mContext)); mContext, null)); mShadowBluetoothAdapter = Shadow.extract(BluetoothAdapter.getDefaultAdapter()); when(mDeviceManager.findDevice(mDevice)).thenReturn(mCachedBluetoothDevice); mProfileManager = new LocalBluetoothProfileManager(mContext, mLocalBluetoothAdapter, Loading Loading @@ -151,9 +151,7 @@ public class LocalBluetoothProfileManagerTest { mShadowBluetoothAdapter.setSupportedProfiles(generateList( new int[] {BluetoothProfile.A2DP})); mProfileManager.updateLocalProfiles(); // Refer to BluetoothControllerImpl, it will call setReceiverHandler after // LocalBluetoothProfileManager created. mEventManager.setReceiverHandler(null); mIntent = new Intent(BluetoothA2dp.ACTION_CONNECTION_STATE_CHANGED); mIntent.putExtra(BluetoothDevice.EXTRA_DEVICE, mDevice); mIntent.putExtra(BluetoothProfile.EXTRA_PREVIOUS_STATE, BluetoothProfile.STATE_CONNECTING); Loading @@ -174,9 +172,7 @@ public class LocalBluetoothProfileManagerTest { mShadowBluetoothAdapter.setSupportedProfiles(generateList( new int[] {BluetoothProfile.HEADSET})); mProfileManager.updateLocalProfiles(); // Refer to BluetoothControllerImpl, it will call setReceiverHandler after // LocalBluetoothProfileManager created. mEventManager.setReceiverHandler(null); mIntent = new Intent(BluetoothHeadset.ACTION_CONNECTION_STATE_CHANGED); mIntent.putExtra(BluetoothDevice.EXTRA_DEVICE, mDevice); mIntent.putExtra(BluetoothProfile.EXTRA_PREVIOUS_STATE, BluetoothProfile.STATE_CONNECTING); Loading @@ -197,9 +193,7 @@ public class LocalBluetoothProfileManagerTest { mShadowBluetoothAdapter.setSupportedProfiles(generateList( new int[] {BluetoothProfile.HEARING_AID})); mProfileManager.updateLocalProfiles(); // Refer to BluetoothControllerImpl, it will call setReceiverHandler after // LocalBluetoothProfileManager created. mEventManager.setReceiverHandler(null); mIntent = new Intent(BluetoothHearingAid.ACTION_CONNECTION_STATE_CHANGED); mIntent.putExtra(BluetoothDevice.EXTRA_DEVICE, mDevice); mIntent.putExtra(BluetoothProfile.EXTRA_PREVIOUS_STATE, BluetoothProfile.STATE_CONNECTING); Loading @@ -220,9 +214,7 @@ public class LocalBluetoothProfileManagerTest { mShadowBluetoothAdapter.setSupportedProfiles(generateList( new int[] {BluetoothProfile.PAN})); mProfileManager.updateLocalProfiles(); // Refer to BluetoothControllerImpl, it will call setReceiverHandler after // LocalBluetoothProfileManager created. mEventManager.setReceiverHandler(null); mIntent = new Intent(BluetoothPan.ACTION_CONNECTION_STATE_CHANGED); mIntent.putExtra(BluetoothDevice.EXTRA_DEVICE, mDevice); mIntent.putExtra(BluetoothProfile.EXTRA_PREVIOUS_STATE, BluetoothProfile.STATE_CONNECTING); Loading @@ -243,9 +235,7 @@ public class LocalBluetoothProfileManagerTest { () { mShadowBluetoothAdapter.setSupportedProfiles(null); mProfileManager.updateLocalProfiles(); // Refer to BluetoothControllerImpl, it will call setReceiverHandler after // LocalBluetoothProfileManager created. mEventManager.setReceiverHandler(null); mIntent = new Intent(BluetoothPan.ACTION_CONNECTION_STATE_CHANGED); mIntent.putExtra(BluetoothDevice.EXTRA_DEVICE, mDevice); mIntent.putExtra(BluetoothProfile.EXTRA_PREVIOUS_STATE, BluetoothProfile.STATE_CONNECTING); Loading @@ -265,9 +255,7 @@ public class LocalBluetoothProfileManagerTest { mShadowBluetoothAdapter.setSupportedProfiles(generateList( new int[] {BluetoothProfile.PAN})); mProfileManager.updateLocalProfiles(); // Refer to BluetoothControllerImpl, it will call setReceiverHandler after // LocalBluetoothProfileManager created. mEventManager.setReceiverHandler(null); mIntent = new Intent(BluetoothPan.ACTION_CONNECTION_STATE_CHANGED); mIntent.putExtra(BluetoothDevice.EXTRA_DEVICE, mDevice); mIntent.putExtra(BluetoothProfile.EXTRA_PREVIOUS_STATE, BluetoothProfile.STATE_CONNECTING); Loading
packages/SystemUI/src/com/android/systemui/Dependency.java +6 −1 Original line number Diff line number Diff line Loading @@ -132,6 +132,10 @@ public class Dependency extends SystemUI { * Key for getting a background Looper for background work. */ public static final DependencyKey<Looper> BG_LOOPER = new DependencyKey<>("background_looper"); /** * Key for getting a background Handler for background work. */ public static final DependencyKey<Handler> BG_HANDLER = new DependencyKey<>("background_handler"); /** * Key for getting a Handler for receiving time tick broadcasts on. */ Loading Loading @@ -166,6 +170,7 @@ public class Dependency extends SystemUI { thread.start(); return thread.getLooper(); }); mProviders.put(BG_HANDLER, () -> new Handler(getDependency(BG_LOOPER))); mProviders.put(MAIN_HANDLER, () -> new Handler(Looper.getMainLooper())); mProviders.put(ActivityStarter.class, () -> new ActivityStarterDelegate()); mProviders.put(ActivityStarterDelegate.class, () -> Loading Loading @@ -288,7 +293,7 @@ public class Dependency extends SystemUI { new PluginDependencyProvider(get(PluginManager.class))); mProviders.put(LocalBluetoothManager.class, () -> LocalBluetoothManager.getInstance(mContext, null)); LocalBluetoothManager.create(mContext, getDependency(BG_HANDLER))); mProviders.put(VolumeDialogController.class, () -> new VolumeDialogControllerImpl(mContext)); Loading