From 3468f310619c4ac9dba1539e93bd6f7cbbee3e53 Mon Sep 17 00:00:00 2001 From: Shawn Lee Date: Mon, 14 Aug 2023 12:05:08 -0700 Subject: Remove requirement for view attachment to refresh date format Since the date format is not read until the next call to updateClock, this simply eliminates the possibility of ignoring a timezone change due to lack of a handler. Also adds some logging in case this is not the culprit. Bug: 284541914 Test: Verified timezone change is handled correctly Change-Id: Ia733f72f0b2b9ee0389c7114a50b362a0e3e324d Merged-In: Ia733f72f0b2b9ee0389c7114a50b362a0e3e324d --- .../statusbar/policy/VariableDateViewController.kt | 29 ++++++++++++++-------- .../policy/VariableDateViewControllerTest.kt | 2 ++ 2 files changed, 21 insertions(+), 10 deletions(-) diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/policy/VariableDateViewController.kt b/packages/SystemUI/src/com/android/systemui/statusbar/policy/VariableDateViewController.kt index f040d0a0efcf..369f9ca3e5ca 100644 --- a/packages/SystemUI/src/com/android/systemui/statusbar/policy/VariableDateViewController.kt +++ b/packages/SystemUI/src/com/android/systemui/statusbar/policy/VariableDateViewController.kt @@ -31,6 +31,7 @@ import android.util.Log import androidx.annotation.VisibleForTesting import com.android.systemui.Dependency import com.android.systemui.broadcast.BroadcastDispatcher +import com.android.systemui.shade.ShadeLogger import com.android.systemui.util.ViewController import com.android.systemui.util.time.SystemClock import java.text.FieldPosition @@ -80,6 +81,7 @@ private const val TAG = "VariableDateViewController" class VariableDateViewController( private val systemClock: SystemClock, private val broadcastDispatcher: BroadcastDispatcher, + private val shadeLogger: ShadeLogger, private val timeTickHandler: Handler, view: VariableDateView ) : ViewController(view) { @@ -107,24 +109,29 @@ class VariableDateViewController( private val intentReceiver: BroadcastReceiver = object : BroadcastReceiver() { override fun onReceive(context: Context, intent: Intent) { + val action = intent.action + if ( + Intent.ACTION_LOCALE_CHANGED == action || + Intent.ACTION_TIMEZONE_CHANGED == action + ) { + // need to get a fresh date format + dateFormat = null + shadeLogger.d("VariableDateViewController received intent to refresh date format") + } + + val handler = mView.handler + // If the handler is null, it means we received a broadcast while the view has not // finished being attached or in the process of being detached. // In that case, do not post anything. - val handler = mView.handler ?: return - val action = intent.action - if ( + if (handler == null) { + shadeLogger.d("VariableDateViewController received intent but handler was null") + } else if ( Intent.ACTION_TIME_TICK == action || Intent.ACTION_TIME_CHANGED == action || Intent.ACTION_TIMEZONE_CHANGED == action || Intent.ACTION_LOCALE_CHANGED == action ) { - if ( - Intent.ACTION_LOCALE_CHANGED == action || - Intent.ACTION_TIMEZONE_CHANGED == action - ) { - // need to get a fresh date format - handler.post { dateFormat = null } - } handler.post(::updateClock) } } @@ -211,12 +218,14 @@ class VariableDateViewController( class Factory @Inject constructor( private val systemClock: SystemClock, private val broadcastDispatcher: BroadcastDispatcher, + private val shadeLogger: ShadeLogger, @Named(Dependency.TIME_TICK_HANDLER_NAME) private val handler: Handler ) { fun create(view: VariableDateView): VariableDateViewController { return VariableDateViewController( systemClock, broadcastDispatcher, + shadeLogger, handler, view ) diff --git a/packages/SystemUI/tests/src/com/android/systemui/statusbar/policy/VariableDateViewControllerTest.kt b/packages/SystemUI/tests/src/com/android/systemui/statusbar/policy/VariableDateViewControllerTest.kt index 871a48c503be..12c1335818cd 100644 --- a/packages/SystemUI/tests/src/com/android/systemui/statusbar/policy/VariableDateViewControllerTest.kt +++ b/packages/SystemUI/tests/src/com/android/systemui/statusbar/policy/VariableDateViewControllerTest.kt @@ -24,6 +24,7 @@ import com.android.systemui.SysuiTestCase import com.android.systemui.broadcast.BroadcastDispatcher import com.android.systemui.util.mockito.any import com.android.systemui.util.mockito.capture +import com.android.systemui.util.mockito.mock import com.android.systemui.util.time.FakeSystemClock import com.google.common.truth.Truth.assertThat import org.junit.Before @@ -99,6 +100,7 @@ class VariableDateViewControllerTest : SysuiTestCase() { controller = VariableDateViewController( systemClock, broadcastDispatcher, + mock(), testableHandler, view ) -- cgit v1.2.3-59-g8ed1b