From 9cd0bf545d95c7014440125adb4f702d2f1a2737 Mon Sep 17 00:00:00 2001 From: Nicolo' Mazzucato Date: Fri, 29 Sep 2023 15:31:24 +0000 Subject: Fix resources used for secondary display presentation The secondary display keyguard presentation was using the context from main display. This ended up causing clocks being shown with wrong sizes. Now the display is expliticly passed into the KeyguardStatusViewComponent factory, and used when appropriate. More tests for multiple resolutions coming soon. Test: KeyguardClockSwitchScreenshotTest Bug: 299256162 Change-Id: I113cf97bb63121b89857a2204625d15b254e5876 --- .../customization/res/values-sw400dp/dimens.xml | 20 +++++++++++ .../SystemUI/customization/res/values/dimens.xml | 1 + .../layout/keyguard_clock_presentation.xml | 20 +++++++---- .../systemui/dagger/qualifiers/DisplaySpecific.kt | 24 +++++++++++++ .../com/android/keyguard/ClockEventController.kt | 32 +++++++++++++---- .../ConnectedDisplayKeyguardPresentation.kt | 11 +++--- .../keyguard/KeyguardClockSwitchController.java | 2 +- .../android/keyguard/KeyguardDisplayManager.java | 2 +- .../keyguard/dagger/KeyguardDisplayModule.kt | 40 ++++++++++++++++++++++ .../dagger/KeyguardStatusViewComponent.java | 10 ++++-- .../systemui/keyguard/KeyguardViewConfigurator.kt | 3 +- .../systemui/keyguard/dagger/KeyguardModule.java | 2 ++ .../layout/sections/DefaultStatusViewSection.kt | 5 +-- .../shade/NotificationPanelViewController.java | 3 +- .../android/keyguard/KeyguardPresentationTest.java | 3 +- .../NotificationPanelViewControllerBaseTest.java | 2 +- 16 files changed, 154 insertions(+), 26 deletions(-) create mode 100644 packages/SystemUI/customization/res/values-sw400dp/dimens.xml create mode 100644 packages/SystemUI/shared/src/com/android/systemui/dagger/qualifiers/DisplaySpecific.kt create mode 100644 packages/SystemUI/src/com/android/keyguard/dagger/KeyguardDisplayModule.kt diff --git a/packages/SystemUI/customization/res/values-sw400dp/dimens.xml b/packages/SystemUI/customization/res/values-sw400dp/dimens.xml new file mode 100644 index 000000000000..3c9e0789b5f2 --- /dev/null +++ b/packages/SystemUI/customization/res/values-sw400dp/dimens.xml @@ -0,0 +1,20 @@ + + + + 170dp + \ No newline at end of file diff --git a/packages/SystemUI/customization/res/values/dimens.xml b/packages/SystemUI/customization/res/values/dimens.xml index 8eb8132b07b9..c574d1fc674b 100644 --- a/packages/SystemUI/customization/res/values/dimens.xml +++ b/packages/SystemUI/customization/res/values/dimens.xml @@ -17,6 +17,7 @@ --> + 50dp 150dp 86dp diff --git a/packages/SystemUI/res-keyguard/layout/keyguard_clock_presentation.xml b/packages/SystemUI/res-keyguard/layout/keyguard_clock_presentation.xml index 593f507f3c88..f68ab8110b6d 100644 --- a/packages/SystemUI/res-keyguard/layout/keyguard_clock_presentation.xml +++ b/packages/SystemUI/res-keyguard/layout/keyguard_clock_presentation.xml @@ -16,22 +16,30 @@ */ --> - + android:orientation="vertical" + app:layout_constraintBottom_toBottomOf="parent" + app:layout_constraintDimensionRatio="1:1" + app:layout_constraintEnd_toEndOf="parent" + app:layout_constraintStart_toStartOf="parent" + app:layout_constraintTop_toTopOf="parent"> + + android:layout_height="wrap_content"/> - + \ No newline at end of file diff --git a/packages/SystemUI/shared/src/com/android/systemui/dagger/qualifiers/DisplaySpecific.kt b/packages/SystemUI/shared/src/com/android/systemui/dagger/qualifiers/DisplaySpecific.kt new file mode 100644 index 000000000000..57a49c83ae17 --- /dev/null +++ b/packages/SystemUI/shared/src/com/android/systemui/dagger/qualifiers/DisplaySpecific.kt @@ -0,0 +1,24 @@ +/* + * Copyright (C) 2023 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.android.systemui.dagger.qualifiers + +import java.lang.annotation.Documented +import java.lang.annotation.Retention +import java.lang.annotation.RetentionPolicy.RUNTIME +import javax.inject.Qualifier + +/** Annotates a class that is display specific. */ +@Qualifier @Documented @Retention(RUNTIME) annotation class DisplaySpecific diff --git a/packages/SystemUI/src/com/android/keyguard/ClockEventController.kt b/packages/SystemUI/src/com/android/keyguard/ClockEventController.kt index 2f3c1f263782..bb0cf6d470a2 100644 --- a/packages/SystemUI/src/com/android/keyguard/ClockEventController.kt +++ b/packages/SystemUI/src/com/android/keyguard/ClockEventController.kt @@ -34,6 +34,7 @@ import androidx.lifecycle.repeatOnLifecycle import com.android.systemui.customization.R import com.android.systemui.broadcast.BroadcastDispatcher import com.android.systemui.dagger.qualifiers.Background +import com.android.systemui.dagger.qualifiers.DisplaySpecific import com.android.systemui.dagger.qualifiers.Main import com.android.systemui.flags.FeatureFlags import com.android.systemui.flags.Flags.DOZING_MIGRATION_1 @@ -79,8 +80,8 @@ constructor( private val batteryController: BatteryController, private val keyguardUpdateMonitor: KeyguardUpdateMonitor, private val configurationController: ConfigurationController, - @Main private val resources: Resources, - private val context: Context, + @DisplaySpecific private val resources: Resources, + @DisplaySpecific private val context: Context, @Main private val mainExecutor: DelayableExecutor, @Background private val bgExecutor: Executor, @KeyguardSmallClockLog private val smallLogBuffer: LogBuffer?, @@ -205,7 +206,7 @@ constructor( private var isRegistered = false private var disposableHandle: DisposableHandle? = null private val regionSamplingEnabled = featureFlags.isEnabled(REGION_SAMPLING) - + private var largeClockOnSecondaryDisplay = false private fun updateColors() { if (regionSamplingEnabled) { @@ -381,6 +382,19 @@ constructor( ?.removeOnAttachStateChangeListener(largeClockOnAttachStateChangeListener) } + /** + * Sets this clock as showing in a secondary display. + * + * Not that this is not necessarily needed, as we could get the displayId from [Context] + * directly and infere [largeClockOnSecondaryDisplay] from the id being different than the + * default display one. However, if we do so, current screenshot tests would not work, as they + * pass an activity context always from the default display. + */ + fun setLargeClockOnSecondaryDisplay(onSecondaryDisplay: Boolean) { + largeClockOnSecondaryDisplay = onSecondaryDisplay + updateFontSizes() + } + private fun updateTimeListeners() { smallTimeListener?.stop() largeTimeListener?.stop() @@ -403,9 +417,15 @@ constructor( smallClock.events.onFontSettingChanged( resources.getDimensionPixelSize(R.dimen.small_clock_text_size).toFloat() ) - largeClock.events.onFontSettingChanged( - resources.getDimensionPixelSize(R.dimen.large_clock_text_size).toFloat() - ) + largeClock.events.onFontSettingChanged(getLargeClockSizePx()) + } + } + + private fun getLargeClockSizePx(): Float { + return if (largeClockOnSecondaryDisplay) { + resources.getDimensionPixelSize(R.dimen.presentation_clock_text_size).toFloat() + } else { + resources.getDimensionPixelSize(R.dimen.large_clock_text_size).toFloat() } } diff --git a/packages/SystemUI/src/com/android/keyguard/ConnectedDisplayKeyguardPresentation.kt b/packages/SystemUI/src/com/android/keyguard/ConnectedDisplayKeyguardPresentation.kt index d677a15862de..dec7d7992596 100644 --- a/packages/SystemUI/src/com/android/keyguard/ConnectedDisplayKeyguardPresentation.kt +++ b/packages/SystemUI/src/com/android/keyguard/ConnectedDisplayKeyguardPresentation.kt @@ -68,10 +68,13 @@ constructor( clock = requireViewById(R.id.clock) keyguardStatusViewController = - keyguardStatusViewComponentFactory.build(clock).keyguardStatusViewController.apply { - setDisplayedOnSecondaryDisplay() - init() - } + keyguardStatusViewComponentFactory + .build(clock, display) + .keyguardStatusViewController + .apply { + setDisplayedOnSecondaryDisplay() + init() + } } /** [ConnectedDisplayKeyguardPresentation] factory. */ diff --git a/packages/SystemUI/src/com/android/keyguard/KeyguardClockSwitchController.java b/packages/SystemUI/src/com/android/keyguard/KeyguardClockSwitchController.java index ff8e489528b7..3c8301fe1b26 100644 --- a/packages/SystemUI/src/com/android/keyguard/KeyguardClockSwitchController.java +++ b/packages/SystemUI/src/com/android/keyguard/KeyguardClockSwitchController.java @@ -84,7 +84,6 @@ public class KeyguardClockSwitchController extends ViewController): Context { + return if (display.isPresent) { + context.createDisplayContext(display.get()) + } else { + context + } + } + + @Provides + @DisplaySpecific + fun getDisplayResources(@DisplaySpecific context: Context): Resources { + return context.resources + } + } +} diff --git a/packages/SystemUI/src/com/android/keyguard/dagger/KeyguardStatusViewComponent.java b/packages/SystemUI/src/com/android/keyguard/dagger/KeyguardStatusViewComponent.java index d342377da49b..f3014f1ecc58 100644 --- a/packages/SystemUI/src/com/android/keyguard/dagger/KeyguardStatusViewComponent.java +++ b/packages/SystemUI/src/com/android/keyguard/dagger/KeyguardStatusViewComponent.java @@ -16,6 +16,8 @@ package com.android.keyguard.dagger; +import android.view.Display; + import com.android.keyguard.KeyguardClockSwitchController; import com.android.keyguard.KeyguardStatusView; import com.android.keyguard.KeyguardStatusViewController; @@ -28,13 +30,17 @@ import dagger.Subcomponent; * * TODO: unify this with {@link KeyguardStatusBarViewComponent} */ -@Subcomponent(modules = {KeyguardStatusViewModule.class}) +@Subcomponent(modules = {KeyguardStatusViewModule.class, KeyguardDisplayModule.class}) @KeyguardStatusViewScope public interface KeyguardStatusViewComponent { /** Simple factory for {@link KeyguardStatusViewComponent}. */ @Subcomponent.Factory interface Factory { - KeyguardStatusViewComponent build(@BindsInstance KeyguardStatusView presentation); + /** Creates {@link KeyguardStatusViewComponent} for a given display. */ + KeyguardStatusViewComponent build( + @BindsInstance KeyguardStatusView presentation, + @BindsInstance Display display + ); } /** Builds a {@link com.android.keyguard.KeyguardClockSwitchController}. */ diff --git a/packages/SystemUI/src/com/android/systemui/keyguard/KeyguardViewConfigurator.kt b/packages/SystemUI/src/com/android/systemui/keyguard/KeyguardViewConfigurator.kt index f500017e3a33..86bf368791bc 100644 --- a/packages/SystemUI/src/com/android/systemui/keyguard/KeyguardViewConfigurator.kt +++ b/packages/SystemUI/src/com/android/systemui/keyguard/KeyguardViewConfigurator.kt @@ -82,7 +82,8 @@ constructor( val statusViewComponent = keyguardStatusViewComponentFactory.build( LayoutInflater.from(context).inflate(R.layout.keyguard_status_view, null) - as KeyguardStatusView + as KeyguardStatusView, + context.display ) val controller = statusViewComponent.keyguardStatusViewController controller.init() diff --git a/packages/SystemUI/src/com/android/systemui/keyguard/dagger/KeyguardModule.java b/packages/SystemUI/src/com/android/systemui/keyguard/dagger/KeyguardModule.java index 03c166c05a62..41bde91d9a01 100644 --- a/packages/SystemUI/src/com/android/systemui/keyguard/dagger/KeyguardModule.java +++ b/packages/SystemUI/src/com/android/systemui/keyguard/dagger/KeyguardModule.java @@ -28,6 +28,7 @@ import com.android.keyguard.KeyguardDisplayManager; import com.android.keyguard.KeyguardUpdateMonitor; import com.android.keyguard.KeyguardViewController; import com.android.keyguard.ViewMediatorCallback; +import com.android.keyguard.dagger.KeyguardDisplayModule; import com.android.keyguard.dagger.KeyguardQsUserSwitchComponent; import com.android.keyguard.dagger.KeyguardStatusBarViewComponent; import com.android.keyguard.dagger.KeyguardStatusViewComponent; @@ -100,6 +101,7 @@ import kotlinx.coroutines.CoroutineDispatcher; KeyguardDataQuickAffordanceModule.class, KeyguardRepositoryModule.class, KeyguardFaceAuthModule.class, + KeyguardDisplayModule.class, StartKeyguardTransitionModule.class, ResourceTrimmerModule.class, }) diff --git a/packages/SystemUI/src/com/android/systemui/keyguard/ui/view/layout/sections/DefaultStatusViewSection.kt b/packages/SystemUI/src/com/android/systemui/keyguard/ui/view/layout/sections/DefaultStatusViewSection.kt index 1a9f021a7622..0b0f21d7a281 100644 --- a/packages/SystemUI/src/com/android/systemui/keyguard/ui/view/layout/sections/DefaultStatusViewSection.kt +++ b/packages/SystemUI/src/com/android/systemui/keyguard/ui/view/layout/sections/DefaultStatusViewSection.kt @@ -31,12 +31,12 @@ import androidx.constraintlayout.widget.ConstraintSet.START import androidx.constraintlayout.widget.ConstraintSet.TOP import com.android.keyguard.KeyguardStatusView import com.android.keyguard.dagger.KeyguardStatusViewComponent -import com.android.systemui.res.R import com.android.systemui.flags.FeatureFlags import com.android.systemui.flags.Flags import com.android.systemui.keyguard.KeyguardViewConfigurator import com.android.systemui.keyguard.shared.model.KeyguardSection import com.android.systemui.media.controls.ui.KeyguardMediaController +import com.android.systemui.res.R import com.android.systemui.shade.NotificationPanelView import com.android.systemui.shade.NotificationPanelViewController import com.android.systemui.statusbar.policy.SplitShadeStateController @@ -84,7 +84,8 @@ constructor( override fun bindData(constraintLayout: ConstraintLayout) { if (featureFlags.isEnabled(Flags.MIGRATE_KEYGUARD_STATUS_VIEW)) { constraintLayout.findViewById(R.id.keyguard_status_view)?.let { - val statusViewComponent = keyguardStatusViewComponentFactory.build(it) + val statusViewComponent = + keyguardStatusViewComponentFactory.build(it, context.display) val controller = statusViewComponent.keyguardStatusViewController controller.init() keyguardMediaController.attachSplitShadeContainer( diff --git a/packages/SystemUI/src/com/android/systemui/shade/NotificationPanelViewController.java b/packages/SystemUI/src/com/android/systemui/shade/NotificationPanelViewController.java index d3d38e5c21cd..1c62b6a184fa 100644 --- a/packages/SystemUI/src/com/android/systemui/shade/NotificationPanelViewController.java +++ b/packages/SystemUI/src/com/android/systemui/shade/NotificationPanelViewController.java @@ -1275,7 +1275,8 @@ public final class NotificationPanelViewController implements ShadeSurface, Dump KeyguardStatusView keyguardStatusView = mView.getRootView().findViewById( R.id.keyguard_status_view); KeyguardStatusViewComponent statusViewComponent = - mKeyguardStatusViewComponentFactory.build(keyguardStatusView); + mKeyguardStatusViewComponentFactory.build(keyguardStatusView, + mView.getContext().getDisplay()); mKeyguardStatusViewController = statusViewComponent.getKeyguardStatusViewController(); mKeyguardStatusViewController.init(); } diff --git a/packages/SystemUI/tests/src/com/android/keyguard/KeyguardPresentationTest.java b/packages/SystemUI/tests/src/com/android/keyguard/KeyguardPresentationTest.java index f3a1b68a87ae..5102957c71ed 100644 --- a/packages/SystemUI/tests/src/com/android/keyguard/KeyguardPresentationTest.java +++ b/packages/SystemUI/tests/src/com/android/keyguard/KeyguardPresentationTest.java @@ -69,7 +69,8 @@ public class KeyguardPresentationTest extends SysuiTestCase { when(mMockKeyguardSliceView.getContext()).thenReturn(mContext); when(mMockKeyguardStatusView.getContext()).thenReturn(mContext); when(mMockKeyguardStatusView.findViewById(R.id.clock)).thenReturn(mMockKeyguardStatusView); - when(mKeyguardStatusViewComponentFactory.build(any(KeyguardStatusView.class))) + when(mKeyguardStatusViewComponentFactory.build(any(KeyguardStatusView.class), + any(Display.class))) .thenReturn(mKeyguardStatusViewComponent); when(mKeyguardStatusViewComponent.getKeyguardClockSwitchController()) .thenReturn(mKeyguardClockSwitchController); diff --git a/packages/SystemUI/tests/src/com/android/systemui/shade/NotificationPanelViewControllerBaseTest.java b/packages/SystemUI/tests/src/com/android/systemui/shade/NotificationPanelViewControllerBaseTest.java index 7b12931b2b47..dd77da38422f 100644 --- a/packages/SystemUI/tests/src/com/android/systemui/shade/NotificationPanelViewControllerBaseTest.java +++ b/packages/SystemUI/tests/src/com/android/systemui/shade/NotificationPanelViewControllerBaseTest.java @@ -547,7 +547,7 @@ public class NotificationPanelViewControllerBaseTest extends SysuiTestCase { mLockscreenShadeTransitionController, new FalsingCollectorFake(), mDumpManager); - when(mKeyguardStatusViewComponentFactory.build(any())) + when(mKeyguardStatusViewComponentFactory.build(any(), any())) .thenReturn(mKeyguardStatusViewComponent); when(mKeyguardStatusViewComponent.getKeyguardClockSwitchController()) .thenReturn(mKeyguardClockSwitchController); -- cgit v1.2.3-59-g8ed1b