Update date during time tick event

Remove extra broadcast action and use existing doze_time_tick alarm to
update slice.

Change-Id: If167c8d81e5f5a67050d7904ce2497c1bdb70e9a
Fixes: 77988364
Test: atest packages/SystemUI/tests/src/com/android/keyguard/KeyguardSliceViewTest.java
Test: atest packages/SystemUI/tests/src/com/android/keyguard/KeyguardStatusViewTest.java
Test: atest packages/SystemUI/tests/src/com/android/systemui/keyguard/KeyguardSliceProviderTest.java
diff --git a/packages/SystemUI/src/com/android/keyguard/KeyguardSliceView.java b/packages/SystemUI/src/com/android/keyguard/KeyguardSliceView.java
index 30a17a1..f066e34 100644
--- a/packages/SystemUI/src/com/android/keyguard/KeyguardSliceView.java
+++ b/packages/SystemUI/src/com/android/keyguard/KeyguardSliceView.java
@@ -57,6 +57,7 @@
 
 import androidx.slice.Slice;
 import androidx.slice.SliceItem;
+import androidx.slice.SliceManager;
 import androidx.slice.core.SliceQuery;
 import androidx.slice.widget.ListContent;
 import androidx.slice.widget.RowContent;
@@ -390,6 +391,11 @@
         }
     }
 
+    public void refresh() {
+        Slice slice = SliceManager.getInstance(getContext()).bindSlice(mKeyguardSliceUri);
+        onChanged(slice);
+    }
+
     public static class Row extends LinearLayout {
 
         /**
diff --git a/packages/SystemUI/src/com/android/keyguard/KeyguardStatusView.java b/packages/SystemUI/src/com/android/keyguard/KeyguardStatusView.java
index 454528e..f6b5d69 100644
--- a/packages/SystemUI/src/com/android/keyguard/KeyguardStatusView.java
+++ b/packages/SystemUI/src/com/android/keyguard/KeyguardStatusView.java
@@ -287,7 +287,12 @@
         }
     }
 
-    public void refreshTime() {
+    public void dozeTimeTick() {
+        refreshTime();
+        mKeyguardSlice.refresh();
+    }
+
+    private void refreshTime() {
         mClockView.refresh();
     }
 
diff --git a/packages/SystemUI/src/com/android/systemui/keyguard/KeyguardSliceProvider.java b/packages/SystemUI/src/com/android/systemui/keyguard/KeyguardSliceProvider.java
index f867b34..c5e66f9 100644
--- a/packages/SystemUI/src/com/android/systemui/keyguard/KeyguardSliceProvider.java
+++ b/packages/SystemUI/src/com/android/systemui/keyguard/KeyguardSliceProvider.java
@@ -79,7 +79,6 @@
     private DateFormat mDateFormat;
     private String mLastText;
     private boolean mRegistered;
-    private boolean mRegisteredEveryMinute;
     private String mNextAlarm;
     private NextAlarmController mNextAlarmController;
     protected AlarmManager mAlarmManager;
@@ -175,7 +174,7 @@
         mZenModeController = new ZenModeControllerImpl(getContext(), mHandler);
         mZenModeController.addCallback(this);
         mDatePattern = getContext().getString(R.string.system_ui_aod_date_pattern);
-        registerClockUpdate(false /* everyMinute */);
+        registerClockUpdate();
         updateClock();
         return true;
     }
@@ -214,22 +213,13 @@
     /**
      * Registers a broadcast receiver for clock updates, include date, time zone and manually
      * changing the date/time via the settings app.
-     *
-     * @param everyMinute {@code true} if you also want updates every minute.
      */
-    protected void registerClockUpdate(boolean everyMinute) {
+    private void registerClockUpdate() {
         if (mRegistered) {
-            if (mRegisteredEveryMinute == everyMinute) {
-                return;
-            } else {
-                unregisterClockUpdate();
-            }
+            return;
         }
 
         IntentFilter filter = new IntentFilter();
-        if (everyMinute) {
-            filter.addAction(Intent.ACTION_TIME_TICK);
-        }
         filter.addAction(Intent.ACTION_DATE_CHANGED);
         filter.addAction(Intent.ACTION_TIME_CHANGED);
         filter.addAction(Intent.ACTION_TIMEZONE_CHANGED);
@@ -237,15 +227,6 @@
         getContext().registerReceiver(mIntentReceiver, filter, null /* permission*/,
                 null /* scheduler */);
         mRegistered = true;
-        mRegisteredEveryMinute = everyMinute;
-    }
-
-    protected void unregisterClockUpdate() {
-        if (!mRegistered) {
-            return;
-        }
-        getContext().unregisterReceiver(mIntentReceiver);
-        mRegistered = false;
     }
 
     @VisibleForTesting
diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/phone/NotificationPanelView.java b/packages/SystemUI/src/com/android/systemui/statusbar/phone/NotificationPanelView.java
index b650944..b475b64 100644
--- a/packages/SystemUI/src/com/android/systemui/statusbar/phone/NotificationPanelView.java
+++ b/packages/SystemUI/src/com/android/systemui/statusbar/phone/NotificationPanelView.java
@@ -2267,7 +2267,7 @@
     }
 
     public void onScreenTurningOn() {
-        mKeyguardStatusView.refreshTime();
+        mKeyguardStatusView.dozeTimeTick();
     }
 
     @Override
@@ -2690,7 +2690,7 @@
     }
 
     public void dozeTimeTick() {
-        mKeyguardStatusView.refreshTime();
+        mKeyguardStatusView.dozeTimeTick();
         mKeyguardBottomArea.dozeTimeTick();
         if (mDarkAmount > 0) {
             positionClockAndNotifications();
diff --git a/packages/SystemUI/tests/src/com/android/keyguard/KeyguardSliceViewTest.java b/packages/SystemUI/tests/src/com/android/keyguard/KeyguardSliceViewTest.java
index 210764a..17a4fbc 100644
--- a/packages/SystemUI/tests/src/com/android/keyguard/KeyguardSliceViewTest.java
+++ b/packages/SystemUI/tests/src/com/android/keyguard/KeyguardSliceViewTest.java
@@ -90,6 +90,17 @@
     }
 
     @Test
+    public void refresh_replacesSliceContentAndNotifiesListener() {
+        AtomicBoolean notified = new AtomicBoolean();
+        mKeyguardSliceView.setContentChangeListener((hasHeader)-> {
+            notified.set(true);
+        });
+        mKeyguardSliceView.refresh();
+        Assert.assertTrue("Listener should be notified about slice changes.",
+                notified.get());
+    }
+
+    @Test
     public void getTextColor_whiteTextWhenAOD() {
         // Set text color to red since the default is white and test would always pass
         mKeyguardSliceView.setTextColor(Color.RED);
diff --git a/packages/SystemUI/tests/src/com/android/keyguard/KeyguardStatusViewTest.java b/packages/SystemUI/tests/src/com/android/keyguard/KeyguardStatusViewTest.java
new file mode 100644
index 0000000..1d8de2f
--- /dev/null
+++ b/packages/SystemUI/tests/src/com/android/keyguard/KeyguardStatusViewTest.java
@@ -0,0 +1,67 @@
+/*
+ * Copyright (C) 2018 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.keyguard;
+
+import static org.mockito.Mockito.verify;
+
+import android.test.suitebuilder.annotation.SmallTest;
+import android.testing.AndroidTestingRunner;
+import android.testing.TestableLooper.RunWithLooper;
+import android.view.LayoutInflater;
+import android.widget.TextClock;
+
+import com.android.systemui.SysuiTestCase;
+
+import org.junit.Before;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.mockito.InjectMocks;
+import org.mockito.Mock;
+
+@SmallTest
+@RunWithLooper(setAsMainLooper = true)
+@RunWith(AndroidTestingRunner.class)
+public class KeyguardStatusViewTest extends SysuiTestCase {
+
+    @Mock
+    KeyguardSliceView mKeyguardSlice;
+    @Mock
+    TextClock mClockView;
+    @InjectMocks
+    KeyguardStatusView mKeyguardStatusView;
+
+    @Before
+    public void setUp() {
+        LayoutInflater layoutInflater = LayoutInflater.from(getContext());
+        mKeyguardStatusView =
+                (KeyguardStatusView) layoutInflater.inflate(R.layout.keyguard_status_view, null);
+        org.mockito.MockitoAnnotations.initMocks(this);
+    }
+
+    @Test
+    public void dozeTimeTick_updatesSlice() {
+        mKeyguardStatusView.dozeTimeTick();
+        verify(mKeyguardSlice).refresh();
+    }
+
+    @Test
+    public void dozeTimeTick_updatesClock() {
+        mKeyguardStatusView.dozeTimeTick();
+        verify(mClockView).refresh();
+    }
+
+}
diff --git a/packages/SystemUI/tests/src/com/android/systemui/keyguard/KeyguardSliceProviderTest.java b/packages/SystemUI/tests/src/com/android/systemui/keyguard/KeyguardSliceProviderTest.java
index a45e690..46e2bfb 100644
--- a/packages/SystemUI/tests/src/com/android/systemui/keyguard/KeyguardSliceProviderTest.java
+++ b/packages/SystemUI/tests/src/com/android/systemui/keyguard/KeyguardSliceProviderTest.java
@@ -85,13 +85,6 @@
     }
 
     @Test
-    public void unregisterClockUpdate() {
-        mProvider.unregisterClockUpdate();
-        Assert.assertFalse("Clock updates should have been unregistered.",
-                mProvider.isRegistered());
-    }
-
-    @Test
     public void returnsValidSlice() {
         Slice slice = mProvider.onBindSlice(mProvider.getUri());
         SliceItem text = SliceQuery.find(slice, android.app.slice.SliceItem.FORMAT_TEXT,