Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 3468f310 authored by Shawn Lee's avatar Shawn Lee
Browse files

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
parent 4449546b
Loading
Loading
Loading
Loading
+19 −10
Original line number Diff line number Diff line
@@ -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<VariableDateView>(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
            )
+2 −0
Original line number Diff line number Diff line
@@ -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
        )