Use context from SystemUiDialog to fix button style.

Test: atest -c com.android.systemui.qs.tiles.dialog.bluetooth
Bug: b/329308541
Flag: NA
(cherry picked from commit f8c88c671b33c14c27c04c430e897d8bb0e5cda7)
Change-Id: I4e0bd33975fc4d44bb0680a69fca4232328a45b2
Merged-In: I4e0bd33975fc4d44bb0680a69fca4232328a45b2
diff --git a/packages/SystemUI/src/com/android/systemui/qs/tiles/BluetoothTile.java b/packages/SystemUI/src/com/android/systemui/qs/tiles/BluetoothTile.java
index 18d2f30..b0707db 100644
--- a/packages/SystemUI/src/com/android/systemui/qs/tiles/BluetoothTile.java
+++ b/packages/SystemUI/src/com/android/systemui/qs/tiles/BluetoothTile.java
@@ -111,7 +111,7 @@
     @Override
     protected void handleClick(@Nullable View view) {
         if (mFeatureFlags.isEnabled(Flags.BLUETOOTH_QS_TILE_DIALOG)) {
-            mDialogViewModel.showDialog(mContext, view);
+            mDialogViewModel.showDialog(view);
         } else {
             // Secondary clicks are header clicks, just toggle.
             final boolean isEnabled = mState.value;
diff --git a/packages/SystemUI/src/com/android/systemui/qs/tiles/dialog/bluetooth/BluetoothTileDialogDelegate.kt b/packages/SystemUI/src/com/android/systemui/qs/tiles/dialog/bluetooth/BluetoothTileDialogDelegate.kt
index 7ece6e0..9866459 100644
--- a/packages/SystemUI/src/com/android/systemui/qs/tiles/dialog/bluetooth/BluetoothTileDialogDelegate.kt
+++ b/packages/SystemUI/src/com/android/systemui/qs/tiles/dialog/bluetooth/BluetoothTileDialogDelegate.kt
@@ -16,7 +16,6 @@
 
 package com.android.systemui.qs.tiles.dialog.bluetooth
 
-import android.content.Context
 import android.os.Bundle
 import android.view.LayoutInflater
 import android.view.View
@@ -57,7 +56,6 @@
 class BluetoothTileDialogDelegate
 @AssistedInject
 internal constructor(
-    @Assisted private val context: Context,
     @Assisted private val initialUiProperties: BluetoothTileDialogViewModel.UiProperties,
     @Assisted private val cachedContentHeight: Int,
     @Assisted private val bluetoothToggleInitialValue: Boolean,
@@ -68,11 +66,8 @@
     private val uiEventLogger: UiEventLogger,
     private val logger: BluetoothTileDialogLogger,
     private val systemuiDialogFactory: SystemUIDialog.Factory,
-    mainLayoutInflater: LayoutInflater,
 ) : SystemUIDialog.Delegate {
 
-    private val layoutInflater = mainLayoutInflater.cloneInContext(context)
-
     private val mutableBluetoothStateToggle: MutableStateFlow<Boolean> =
         MutableStateFlow(bluetoothToggleInitialValue)
     internal val bluetoothStateToggle
@@ -101,7 +96,6 @@
     @AssistedFactory
     internal interface Factory {
         fun create(
-            context: Context,
             initialUiProperties: BluetoothTileDialogViewModel.UiProperties,
             cachedContentHeight: Int,
             bluetoothEnabled: Boolean,
@@ -111,16 +105,15 @@
     }
 
     override fun createDialog(): SystemUIDialog {
-        val dialog = systemuiDialogFactory.create(this, context)
-
-        return dialog
+        return systemuiDialogFactory.create(this)
     }
 
     override fun onCreate(dialog: SystemUIDialog, savedInstanceState: Bundle?) {
         SystemUIDialog.registerDismissListener(dialog, dismissListener)
         uiEventLogger.log(BluetoothTileDialogUiEvent.BLUETOOTH_TILE_DIALOG_SHOWN)
+        val context = dialog.context
 
-        layoutInflater.inflate(R.layout.bluetooth_tile_dialog, null).apply {
+        LayoutInflater.from(context).inflate(R.layout.bluetooth_tile_dialog, null).apply {
             accessibilityPaneTitle = context.getText(R.string.accessibility_desc_quick_settings)
             dialog.setContentView(this)
         }
@@ -200,7 +193,7 @@
             setEnabled(true)
             alpha = ENABLED_ALPHA
         }
-        getSubtitleTextView(dialog).text = context.getString(uiProperties.subTitleResId)
+        getSubtitleTextView(dialog).text = dialog.context.getString(uiProperties.subTitleResId)
         getAutoOnToggleView(dialog).visibility = uiProperties.autoOnToggleVisibility
     }
 
@@ -278,7 +271,7 @@
 
     private fun setupRecyclerView(dialog: SystemUIDialog) {
         getDeviceListView(dialog).apply {
-            layoutManager = LinearLayoutManager(context)
+            layoutManager = LinearLayoutManager(dialog.context)
             adapter = deviceItemAdapter
         }
     }
@@ -333,7 +326,9 @@
         private val asyncListDiffer = AsyncListDiffer(this, diffUtilCallback)
 
         override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): DeviceItemViewHolder {
-            val view = layoutInflater.inflate(R.layout.bluetooth_device_item, parent, false)
+            val view =
+                LayoutInflater.from(parent.context)
+                    .inflate(R.layout.bluetooth_device_item, parent, false)
             return DeviceItemViewHolder(view)
         }
 
diff --git a/packages/SystemUI/src/com/android/systemui/qs/tiles/dialog/bluetooth/BluetoothTileDialogViewModel.kt b/packages/SystemUI/src/com/android/systemui/qs/tiles/dialog/bluetooth/BluetoothTileDialogViewModel.kt
index 0486207..e3dbeb4 100644
--- a/packages/SystemUI/src/com/android/systemui/qs/tiles/dialog/bluetooth/BluetoothTileDialogViewModel.kt
+++ b/packages/SystemUI/src/com/android/systemui/qs/tiles/dialog/bluetooth/BluetoothTileDialogViewModel.kt
@@ -16,7 +16,6 @@
 
 package com.android.systemui.qs.tiles.dialog.bluetooth
 
-import android.content.Context
 import android.content.Intent
 import android.content.SharedPreferences
 import android.os.Bundle
@@ -78,19 +77,19 @@
     /**
      * Shows the dialog.
      *
-     * @param context The context in which the dialog is displayed.
      * @param view The view from which the dialog is shown.
      */
     @kotlinx.coroutines.ExperimentalCoroutinesApi
-    fun showDialog(context: Context, view: View?) {
+    fun showDialog(view: View?) {
         cancelJob()
 
         job =
             coroutineScope.launch(mainDispatcher) {
                 var updateDeviceItemJob: Job?
                 var updateDialogUiJob: Job? = null
-                val dialogDelegate = createBluetoothTileDialog(context)
+                val dialogDelegate = createBluetoothTileDialog()
                 val dialog = dialogDelegate.createDialog()
+                val context = dialog.context
 
                 view?.let {
                     dialogTransitionAnimator.showFromView(
@@ -206,7 +205,7 @@
             }
     }
 
-    private suspend fun createBluetoothTileDialog(context: Context): BluetoothTileDialogDelegate {
+    private suspend fun createBluetoothTileDialog(): BluetoothTileDialogDelegate {
         val cachedContentHeight =
             withContext(backgroundDispatcher) {
                 sharedPreferences.getInt(
@@ -216,7 +215,6 @@
             }
 
         return bluetoothDialogDelegateFactory.create(
-            context,
             UiProperties.build(
                 bluetoothStateInteractor.isBluetoothEnabled,
                 isAutoOnToggleFeatureAvailable()
diff --git a/packages/SystemUI/tests/src/com/android/systemui/qs/tiles/dialog/bluetooth/BluetoothTileDialogDelegateTest.kt b/packages/SystemUI/tests/src/com/android/systemui/qs/tiles/dialog/bluetooth/BluetoothTileDialogDelegateTest.kt
index 8ecb953..17b6127 100644
--- a/packages/SystemUI/tests/src/com/android/systemui/qs/tiles/dialog/bluetooth/BluetoothTileDialogDelegateTest.kt
+++ b/packages/SystemUI/tests/src/com/android/systemui/qs/tiles/dialog/bluetooth/BluetoothTileDialogDelegateTest.kt
@@ -109,7 +109,6 @@
 
         mBluetoothTileDialogDelegate =
             BluetoothTileDialogDelegate(
-                mContext,
                 uiProperties,
                 CONTENT_HEIGHT,
                 ENABLED,
@@ -119,14 +118,12 @@
                 fakeSystemClock,
                 uiEventLogger,
                 logger,
-                sysuiDialogFactory,
-                LayoutInflater.from(mContext)
+                sysuiDialogFactory
             )
 
         whenever(
                 sysuiDialogFactory.create(
-                    any(SystemUIDialog.Delegate::class.java),
-                    any(Context::class.java)
+                    any(SystemUIDialog.Delegate::class.java)
                 )
             )
             .thenAnswer {
@@ -216,7 +213,6 @@
             LayoutInflater.from(mContext).inflate(R.layout.bluetooth_device_item, null, false)
         val viewHolder =
             BluetoothTileDialogDelegate(
-                    mContext,
                     uiProperties,
                     CONTENT_HEIGHT,
                     ENABLED,
@@ -227,7 +223,6 @@
                     uiEventLogger,
                     logger,
                     sysuiDialogFactory,
-                    LayoutInflater.from(mContext)
                 )
                 .Adapter(bluetoothTileDialogCallback)
                 .DeviceItemViewHolder(view)
@@ -273,7 +268,6 @@
             val cachedHeight = Int.MAX_VALUE
             val dialog =
                 BluetoothTileDialogDelegate(
-                        mContext,
                         BluetoothTileDialogViewModel.UiProperties.build(ENABLED, ENABLED),
                         cachedHeight,
                         ENABLED,
@@ -284,7 +278,6 @@
                         uiEventLogger,
                         logger,
                         sysuiDialogFactory,
-                        LayoutInflater.from(mContext)
                     )
                     .createDialog()
             dialog.show()
@@ -298,7 +291,6 @@
         testScope.runTest {
             val dialog =
                 BluetoothTileDialogDelegate(
-                        mContext,
                         BluetoothTileDialogViewModel.UiProperties.build(ENABLED, ENABLED),
                         MATCH_PARENT,
                         ENABLED,
@@ -309,7 +301,6 @@
                         uiEventLogger,
                         logger,
                         sysuiDialogFactory,
-                        LayoutInflater.from(mContext)
                     )
                     .createDialog()
             dialog.show()
@@ -323,7 +314,6 @@
         testScope.runTest {
             val dialog =
                 BluetoothTileDialogDelegate(
-                        mContext,
                         BluetoothTileDialogViewModel.UiProperties.build(ENABLED, ENABLED),
                         MATCH_PARENT,
                         ENABLED,
@@ -334,7 +324,6 @@
                         uiEventLogger,
                         logger,
                         sysuiDialogFactory,
-                        LayoutInflater.from(mContext)
                     )
                     .createDialog()
             dialog.show()
diff --git a/packages/SystemUI/tests/src/com/android/systemui/qs/tiles/dialog/bluetooth/BluetoothTileDialogViewModelTest.kt b/packages/SystemUI/tests/src/com/android/systemui/qs/tiles/dialog/bluetooth/BluetoothTileDialogViewModelTest.kt
index 39e2413..d2724ff 100644
--- a/packages/SystemUI/tests/src/com/android/systemui/qs/tiles/dialog/bluetooth/BluetoothTileDialogViewModelTest.kt
+++ b/packages/SystemUI/tests/src/com/android/systemui/qs/tiles/dialog/bluetooth/BluetoothTileDialogViewModelTest.kt
@@ -148,7 +148,6 @@
         whenever(
                 mBluetoothTileDialogDelegateDelegateFactory.create(
                     any(),
-                    any(),
                     anyInt(),
                     ArgumentMatchers.anyBoolean(),
                     any(),
@@ -157,6 +156,7 @@
             )
             .thenReturn(bluetoothTileDialogDelegate)
         whenever(bluetoothTileDialogDelegate.createDialog()).thenReturn(sysuiDialog)
+        whenever(sysuiDialog.context).thenReturn(mContext)
         whenever(bluetoothTileDialogDelegate.bluetoothStateToggle)
             .thenReturn(getMutableStateFlow(false))
         whenever(bluetoothTileDialogDelegate.deviceItemClick)
@@ -169,7 +169,7 @@
     @Test
     fun testShowDialog_noAnimation() {
         testScope.runTest {
-            bluetoothTileDialogViewModel.showDialog(context, null)
+            bluetoothTileDialogViewModel.showDialog(null)
 
             verify(mDialogTransitionAnimator, never()).showFromView(any(), any(), any(), any())
         }
@@ -178,7 +178,7 @@
     @Test
     fun testShowDialog_animated() {
         testScope.runTest {
-            bluetoothTileDialogViewModel.showDialog(mContext, LinearLayout(mContext))
+            bluetoothTileDialogViewModel.showDialog(LinearLayout(mContext))
 
             verify(mDialogTransitionAnimator).showFromView(any(), any(), nullable(), anyBoolean())
         }
@@ -188,7 +188,7 @@
     fun testShowDialog_animated_callInBackgroundThread() {
         testScope.runTest {
             backgroundExecutor.execute {
-                bluetoothTileDialogViewModel.showDialog(mContext, LinearLayout(mContext))
+                bluetoothTileDialogViewModel.showDialog(LinearLayout(mContext))
 
                 verify(mDialogTransitionAnimator)
                     .showFromView(any(), any(), nullable(), anyBoolean())
@@ -199,7 +199,7 @@
     @Test
     fun testShowDialog_fetchDeviceItem() {
         testScope.runTest {
-            bluetoothTileDialogViewModel.showDialog(context, null)
+            bluetoothTileDialogViewModel.showDialog(null)
 
             verify(deviceItemInteractor).deviceItemUpdate
         }
@@ -208,7 +208,7 @@
     @Test
     fun testShowDialog_withBluetoothStateValue() {
         testScope.runTest {
-            bluetoothTileDialogViewModel.showDialog(context, null)
+            bluetoothTileDialogViewModel.showDialog(null)
 
             verify(bluetoothStateInteractor).bluetoothStateUpdate
         }
@@ -218,7 +218,7 @@
     fun testStartSettingsActivity_activityLaunched_dialogDismissed() {
         testScope.runTest {
             whenever(deviceItem.cachedBluetoothDevice).thenReturn(cachedBluetoothDevice)
-            bluetoothTileDialogViewModel.showDialog(context, null)
+            bluetoothTileDialogViewModel.showDialog(null)
 
             val clickedView = View(context)
             bluetoothTileDialogViewModel.onPairNewDeviceClicked(clickedView)