Fix context leak in AudioSwitchPreferenceController.

In this controller the context is stored into a global singleton but was
not cleared, thus leaking context and associated views.

Change-Id: I4247f8ff753bc0a331c6c81a0e4b5b4bc41588de
Fixes: 80507279
Test: robotests
Test: inspected hprof before/after change
diff --git a/src/com/android/settings/sound/AudioSwitchPreferenceController.java b/src/com/android/settings/sound/AudioSwitchPreferenceController.java
index 44e175c..6723660 100644
--- a/src/com/android/settings/sound/AudioSwitchPreferenceController.java
+++ b/src/com/android/settings/sound/AudioSwitchPreferenceController.java
@@ -118,7 +118,6 @@
             Log.e(TAG, "Bluetooth is not supported on this device");
             return;
         }
-        mLocalBluetoothManager.setForegroundActivity(mContext);
         mProfileManager = mLocalBluetoothManager.getProfileManager();
     }
 
@@ -171,11 +170,13 @@
 
     @Override
     public void onStart() {
+        mLocalBluetoothManager.setForegroundActivity(mContext);
         register();
     }
 
     @Override
     public void onStop() {
+        mLocalBluetoothManager.setForegroundActivity(null);
         unregister();
     }
 
diff --git a/tests/robotests/src/com/android/settings/sound/AudioOutputSwitchPreferenceControllerTest.java b/tests/robotests/src/com/android/settings/sound/AudioOutputSwitchPreferenceControllerTest.java
index 2455f16..1140aee 100644
--- a/tests/robotests/src/com/android/settings/sound/AudioOutputSwitchPreferenceControllerTest.java
+++ b/tests/robotests/src/com/android/settings/sound/AudioOutputSwitchPreferenceControllerTest.java
@@ -230,6 +230,7 @@
         verify(mLocalBluetoothManager.getEventManager()).registerCallback(
                 any(BluetoothCallback.class));
         verify(mContext).registerReceiver(any(BroadcastReceiver.class), any(IntentFilter.class));
+        verify(mLocalBluetoothManager).setForegroundActivity(mContext);
     }
 
     @Test
@@ -240,6 +241,7 @@
         verify(mLocalBluetoothManager.getEventManager()).unregisterCallback(
                 any(BluetoothCallback.class));
         verify(mContext).unregisterReceiver(any(BroadcastReceiver.class));
+        verify(mLocalBluetoothManager).setForegroundActivity(null);
     }
 
     @Test