OSDN Git Service

Add TestApi to disable the TextClock clock tick.
authorGeorge Mount <mount@google.com>
Wed, 20 Dec 2017 21:36:10 +0000 (13:36 -0800)
committerGeorge Mount <mount@google.com>
Wed, 20 Dec 2017 21:54:39 +0000 (13:54 -0800)
Bug: 70771205

In order to test TextClock being only updated by the 12/24
hour setting, we must disable the clock tick from causing
the text to change. Otherwise whenever the minute changes,
the clock text would update. This leads to a flaky test.

Test: I4917a2296744697f1b50a17e3c5eb5873d567a47
Change-Id: Ifb669af3e6b882eb7c158b7de16e7eb2f0c48f61

api/test-current.txt
core/java/android/widget/TextClock.java

index e64c320..fb6e8e2 100644 (file)
@@ -984,6 +984,10 @@ package android.widget {
     method public boolean isPopupShowing();
   }
 
+  public class TextClock extends android.widget.TextView {
+    method public void disableClockTick();
+  }
+
   public class TimePicker extends android.widget.FrameLayout {
     method public android.view.View getAmView();
     method public android.view.View getHourView();
index 7156300..53318c9 100644 (file)
@@ -20,6 +20,7 @@ import static android.view.ViewDebug.ExportedProperty;
 import static android.widget.RemoteViews.RemoteView;
 
 import android.annotation.NonNull;
+import android.annotation.TestApi;
 import android.app.ActivityManager;
 import android.content.BroadcastReceiver;
 import android.content.ContentResolver;
@@ -141,6 +142,9 @@ public class TextClock extends TextView {
     private boolean mShowCurrentUserTime;
 
     private ContentObserver mFormatChangeObserver;
+    // Used by tests to stop time change events from triggering the text update
+    private boolean mStopTicking;
+
     private class FormatChangeObserver extends ContentObserver {
 
         public FormatChangeObserver(Handler handler) {
@@ -163,6 +167,9 @@ public class TextClock extends TextView {
     private final BroadcastReceiver mIntentReceiver = new BroadcastReceiver() {
         @Override
         public void onReceive(Context context, Intent intent) {
+            if (mStopTicking) {
+                return; // Test disabled the clock ticks
+            }
             if (mTimeZone == null && Intent.ACTION_TIMEZONE_CHANGED.equals(intent.getAction())) {
                 final String timeZone = intent.getStringExtra("time-zone");
                 createTime(timeZone);
@@ -173,6 +180,9 @@ public class TextClock extends TextView {
 
     private final Runnable mTicker = new Runnable() {
         public void run() {
+            if (mStopTicking) {
+                return; // Test disabled the clock ticks
+            }
             onTimeChanged();
 
             long now = SystemClock.uptimeMillis();
@@ -546,6 +556,15 @@ public class TextClock extends TextView {
         }
     }
 
+    /**
+     * Used by tests to stop the clock tick from updating the text.
+     * @hide
+     */
+    @TestApi
+    public void disableClockTick() {
+        mStopTicking = true;
+    }
+
     private void registerReceiver() {
         final IntentFilter filter = new IntentFilter();