Merge "Stop 1 sec updates of ECBM Notification" into oc-dev
diff --git a/res/values/strings.xml b/res/values/strings.xml
index b0aae34..7009fd8 100644
--- a/res/values/strings.xml
+++ b/res/values/strings.xml
@@ -1193,12 +1193,8 @@
     <string name="phone_in_ecm_notification_title">Emergency Callback Mode</string>
     <!-- ECM: Notification body -->
     <string name="phone_in_ecm_call_notification_text">Data connection disabled</string>
-    <plurals name="phone_in_ecm_notification_time">
-        <!-- number of minutes is one -->
-        <item quantity="one">No data connection for <xliff:g id="count">%s</xliff:g> minute</item>
-        <!-- number of minutes is not equal to one -->
-        <item quantity="other">No data connection for <xliff:g id="count">%s</xliff:g> minutes</item>
-    </plurals>
+    <!-- ECM: Displays the time when ECM will end, Example: "No Data Connection until 10:45 AM" -->
+    <string name="phone_in_ecm_notification_complete_time">No data connection until <xliff:g id="completeTime">%s</xliff:g></string>
     <!-- ECM: Dialog box message for exiting from the notifications screen -->
     <plurals name="alert_dialog_exit_ecm">
         <!-- number of minutes is one -->
diff --git a/src/com/android/phone/EmergencyCallbackModeService.java b/src/com/android/phone/EmergencyCallbackModeService.java
index 3219c69..a07f7aa 100644
--- a/src/com/android/phone/EmergencyCallbackModeService.java
+++ b/src/com/android/phone/EmergencyCallbackModeService.java
@@ -39,6 +39,8 @@
 import com.android.internal.telephony.TelephonyProperties;
 import com.android.internal.telephony.util.NotificationChannelController;
 
+import java.text.SimpleDateFormat;
+
 /**
  * Application service that inserts/removes Emergency Callback Mode notification and
  * updates Emergency Callback Mode countdown clock in the notification
@@ -152,7 +154,6 @@
                 @Override
                 public void onTick(long millisUntilFinished) {
                     mTimeLeft = millisUntilFinished;
-                    EmergencyCallbackModeService.this.showNotification(millisUntilFinished);
                 }
 
                 @Override
@@ -197,10 +198,17 @@
         if(mInEmergencyCall) {
             text = getText(R.string.phone_in_ecm_call_notification_text).toString();
         } else {
-            int minutes = (int)(millisUntilFinished / 60000);
-            String time = String.format("%d:%02d", minutes, (millisUntilFinished % 60000) / 1000);
-            text = String.format(getResources().getQuantityText(
-                     R.plurals.phone_in_ecm_notification_time, minutes).toString(), time);
+            // Calculate the time in ms when the notification will be finished.
+            long finishedCountMs = millisUntilFinished + System.currentTimeMillis();
+            builder.setShowWhen(true);
+            builder.setChronometerCountDown(true);
+            builder.setUsesChronometer(true);
+            builder.setWhen(finishedCountMs);
+
+            String completeTime = SimpleDateFormat.getTimeInstance(SimpleDateFormat.SHORT).format(
+                    finishedCountMs);
+            text = getResources().getString(R.string.phone_in_ecm_notification_complete_time,
+                    completeTime);
         }
         builder.setContentText(text);
         builder.setChannelId(NotificationChannelController.CHANNEL_ID_ALERT);