diff options
| author | 2022-03-01 18:21:02 -0500 | |
|---|---|---|
| committer | 2022-03-01 18:23:50 -0500 | |
| commit | bf4b035bf05c362e0103ecbb025c6a648f472fba (patch) | |
| tree | d0367c9a32f500002d32888e9e91dd6e74bdf931 | |
| parent | be091340e3923550e8a5d1efe73cef20c3489417 (diff) | |
Replace reflection with Suppliers.
Reflection was causing proguard to turn the empty constructors on
Behavior classes into NPE's. I don't know why it does this, but
removing reflection from the code seems to resolve the issue.
Fixes: 221190784
Test: manual && atest SystemUITests
Change-Id: I5f45e9c06b6c466d666057a056537a08afd9c9ec
| -rw-r--r-- | packages/SystemUI/src/com/android/systemui/controls/ui/ControlViewHolder.kt | 31 |
1 files changed, 16 insertions, 15 deletions
diff --git a/packages/SystemUI/src/com/android/systemui/controls/ui/ControlViewHolder.kt b/packages/SystemUI/src/com/android/systemui/controls/ui/ControlViewHolder.kt index 4819bf565cbc..a4f9f3a9bc08 100644 --- a/packages/SystemUI/src/com/android/systemui/controls/ui/ControlViewHolder.kt +++ b/packages/SystemUI/src/com/android/systemui/controls/ui/ControlViewHolder.kt @@ -54,7 +54,7 @@ import com.android.systemui.animation.Interpolators import com.android.systemui.controls.ControlsMetricsLogger import com.android.systemui.controls.controller.ControlsController import com.android.systemui.util.concurrency.DelayableExecutor -import kotlin.reflect.KClass +import java.util.function.Supplier /** * Wraps the widgets that make up the UI representation of a {@link Control}. Updates to the view @@ -90,20 +90,20 @@ class ControlViewHolder( status: Int, template: ControlTemplate, deviceType: Int - ): KClass<out Behavior> { + ): Supplier<out Behavior> { return when { - status != Control.STATUS_OK -> StatusBehavior::class - template == ControlTemplate.NO_TEMPLATE -> TouchBehavior::class - template is ThumbnailTemplate -> ThumbnailBehavior::class + status != Control.STATUS_OK -> Supplier { StatusBehavior() } + template == ControlTemplate.NO_TEMPLATE -> Supplier { TouchBehavior() } + template is ThumbnailTemplate -> Supplier { ThumbnailBehavior() } // Required for legacy support, or where cameras do not use the new template - deviceType == DeviceTypes.TYPE_CAMERA -> TouchBehavior::class - template is ToggleTemplate -> ToggleBehavior::class - template is StatelessTemplate -> TouchBehavior::class - template is ToggleRangeTemplate -> ToggleRangeBehavior::class - template is RangeTemplate -> ToggleRangeBehavior::class - template is TemperatureControlTemplate -> TemperatureControlBehavior::class - else -> DefaultBehavior::class + deviceType == DeviceTypes.TYPE_CAMERA -> Supplier { TouchBehavior() } + template is ToggleTemplate -> Supplier { ToggleBehavior() } + template is StatelessTemplate -> Supplier { TouchBehavior() } + template is ToggleRangeTemplate -> Supplier { ToggleRangeBehavior() } + template is RangeTemplate -> Supplier { ToggleRangeBehavior() } + template is TemperatureControlTemplate -> Supplier { TemperatureControlBehavior() } + else -> Supplier { DefaultBehavior() } } } } @@ -253,13 +253,14 @@ class ControlViewHolder( fun bindBehavior( existingBehavior: Behavior?, - clazz: KClass<out Behavior>, + supplier: Supplier<out Behavior>, offset: Int = 0 ): Behavior { - val behavior = if (existingBehavior == null || existingBehavior!!::class != clazz) { + val newBehavior = supplier.get() + val behavior = if (existingBehavior == null || + existingBehavior::class != newBehavior::class) { // Behavior changes can signal a change in template from the app or // first time setup - val newBehavior = clazz.java.newInstance() newBehavior.initialize(this) // let behaviors define their own, if necessary, and clear any existing ones |