Merge "Retrieving nameAlternative for ContactInfo" into ub-contactsdialer-a-dev
diff --git a/InCallUI/res/values-eu-rES/strings.xml b/InCallUI/res/values-eu-rES/strings.xml
index c5ae3e3..e80dbda 100644
--- a/InCallUI/res/values-eu-rES/strings.xml
+++ b/InCallUI/res/values-eu-rES/strings.xml
@@ -170,7 +170,7 @@
     <string name="distance_imperial_away" msgid="437508440176409037">"Hemendik <xliff:g id="DISTANCE">%.1f</xliff:g> miliara"</string>
     <string name="distance_metric_away" msgid="166931929505893599">"Hemendik <xliff:g id="DISTANCE">%.1f</xliff:g> km-ra"</string>
     <string name="display_address" msgid="7307400970699471708">"<xliff:g id="STREET_ADDRESS">%1$s</xliff:g>, <xliff:g id="LOCALITY">%2$s</xliff:g>"</string>
-    <string name="opening_hours" msgid="3064872780183247123">"<xliff:g id="OPEN_TIME">%1$s</xliff:g> - <xliff:g id="CLOSE_TIME">%2$s</xliff:g>"</string>
+    <string name="opening_hours" msgid="3064872780183247123">"<xliff:g id="OPEN_TIME">%1$s</xliff:g> – <xliff:g id="CLOSE_TIME">%2$s</xliff:g>"</string>
     <string name="open_now" msgid="6439301193613349163">"Irekita dago"</string>
     <string name="closed_now" msgid="9175774453982778909">"Itxita dago"</string>
 </resources>
diff --git a/InCallUI/res/values-ro/strings.xml b/InCallUI/res/values-ro/strings.xml
index ff5384f..712f8fe 100644
--- a/InCallUI/res/values-ro/strings.xml
+++ b/InCallUI/res/values-ro/strings.xml
@@ -79,7 +79,7 @@
     <string name="notification_missedCall_call_back" msgid="2684890353590890187">"Sunați"</string>
     <string name="notification_missedCall_message" msgid="3049928912736917988">"Mesaj"</string>
     <string name="incall_error_power_off" msgid="6550191216405193368">"Pentru a efectua un apel, mai întâi dezactivați modul Avion."</string>
-    <string name="incall_error_emergency_only" msgid="4678640422710818317">"Neînregistrat în reţea."</string>
+    <string name="incall_error_emergency_only" msgid="4678640422710818317">"Neînregistrat în rețea."</string>
     <string name="incall_error_out_of_service" msgid="4100065333878929223">"Rețeaua mobilă nu este disponibilă"</string>
     <string name="incall_error_no_phone_number_supplied" msgid="1150414018684246528">"Pentru a apela, introduceți un număr valid."</string>
     <string name="incall_error_call_failed" msgid="6302746943230078197">"Nu se poate apela."</string>
diff --git a/InCallUI/src/com/android/incallui/Call.java b/InCallUI/src/com/android/incallui/Call.java
index d1cb623..ab4e2ca 100644
--- a/InCallUI/src/com/android/incallui/Call.java
+++ b/InCallUI/src/com/android/incallui/Call.java
@@ -213,7 +213,10 @@
         public boolean isIncoming = false;
         public int contactLookupResult = LOOKUP_UNKNOWN;
         public int callInitiationMethod = INITIATION_UNKNOWN;
+        // If this was a conference call, the total number of calls involved in the conference.
+        public int conferencedCalls = 0;
         public long duration = 0;
+        public boolean isLogged = false;
 
         @Override
         public String toString() {
@@ -433,12 +436,17 @@
         }
 
         mChildCallIds.clear();
-        for (int i = 0; i < mTelecomCall.getChildren().size(); i++) {
+        final int numChildCalls = mTelecomCall.getChildren().size();
+        for (int i = 0; i < numChildCalls; i++) {
             mChildCallIds.add(
                     CallList.getInstance().getCallByTelecomCall(
                             mTelecomCall.getChildren().get(i)).getId());
         }
 
+        // The number of conferenced calls can change over the course of the call, so use the
+        // maximum number of conferenced child calls as the metric for conference call usage.
+        mLogState.conferencedCalls = Math.max(numChildCalls, mLogState.conferencedCalls);
+
         Bundle callExtras = mTelecomCall.getDetails().getExtras();
         if (callExtras != null) {
             // Child address arrives when the call is first set up, so we do not need to notify the
diff --git a/InCallUI/src/com/android/incallui/InCallContactInteractions.java b/InCallUI/src/com/android/incallui/InCallContactInteractions.java
index 918d39b..21660cb 100644
--- a/InCallUI/src/com/android/incallui/InCallContactInteractions.java
+++ b/InCallUI/src/com/android/incallui/InCallContactInteractions.java
@@ -139,23 +139,22 @@
         BusinessContextInfo hoursInfo = new BusinessContextInfo();
         hoursInfo.iconId = R.drawable.ic_schedule_white_24dp;
 
-        Calendar openTime = getCalendarFromTime(currentTime, openingHours.first);
-        Calendar closeTime = getCalendarFromTime(currentTime, openingHours.second);
+        // Note: the date of these {@link Date}s are set to January 1, 1970. The object is just
+        // used as a storage for the time.
+        Date openingDateTime = getSimpleDateTime(openingHours.first);
+        Date closingDateTime = getSimpleDateTime(openingHours.second);
 
-        if (openTime == null || closeTime == null) {
+        if (openingDateTime == null || closingDateTime == null) {
             return null;
         }
 
-        if (currentTime.after(openTime) && currentTime.before(closeTime)) {
-            hoursInfo.heading = mContext.getString(R.string.open_now);
-        } else {
-            hoursInfo.heading = mContext.getString(R.string.closed_now);
-        }
+        hoursInfo.heading = isOpen(openingDateTime, closingDateTime, currentTime)
+                ? mContext.getString(R.string.open_now) : mContext.getString(R.string.closed_now);
 
         hoursInfo.detail = mContext.getString(
                 R.string.opening_hours,
-                DateFormat.getTimeFormat(mContext).format(openTime.getTime()),
-                DateFormat.getTimeFormat(mContext).format(closeTime.getTime()));
+                DateFormat.getTimeFormat(mContext).format(openingDateTime),
+                DateFormat.getTimeFormat(mContext).format(closingDateTime));
         return hoursInfo;
     }
 
@@ -205,25 +204,57 @@
     }
 
     /**
-     * Get a calendar object set to the current calendar date and the time set to the "hhmm" string
-     * passed in.
+     * Get a {@link Date} object corresponding to a particular time.
+     *
+     * @param time A string containing a time in the format "hhmm".
+     * @return A {@link Date} object with the time set to the parsed value of the "time" parameter
+     * and the date set to January 1, 1970. Or {@code null} if the input string is not able to be
+     * parsed.
      */
-    private Calendar getCalendarFromTime(Calendar currentTime, String time) {
+    private Date getSimpleDateTime(String time) {
         try {
-            Calendar newCalendar = Calendar.getInstance();
-            newCalendar.setTime(new SimpleDateFormat("hhmm").parse(time));
-            newCalendar.set(
-                    currentTime.get(Calendar.YEAR),
-                    currentTime.get(Calendar.MONTH),
-                    currentTime.get(Calendar.DATE));
-            return newCalendar;
+            return new SimpleDateFormat("hhmm").parse(time);
         } catch (ParseException e) {
-            Log.w(TAG, "Could not parse time string" + time);
+            Log.w(TAG, "Could not parse time string " + time);
         }
         return null;
     }
 
     /**
+     * Check whether the current time falls between the opening time and the closing time.
+     *
+     * @param openingTime A {@link Date} object with the time set to the opening time and the date
+     * set to January 1, 1970.
+     * @param closingTime A {@link Date} object with the time set to the closing time and the date
+     * set to January 1, 1970.
+     * @param currentDateTime A {@link Calendar} object with the current date and time.
+     * @return {@code true} if the current time falls within the opening and closing time bounds and
+     * {@code false} otherwise.
+     */
+    private boolean isOpen(Date openingTime, Date closingTime, Calendar currentDateTime) {
+        Calendar openTimeCalendar = Calendar.getInstance();
+        openTimeCalendar.setTime(openingTime);
+
+        Calendar closeTimeCalendar = Calendar.getInstance();
+        closeTimeCalendar.setTime(closingTime);
+
+        if (openTimeCalendar.compareTo(closeTimeCalendar) >= 0) {
+            // If the open time is the same or after the close time, add a day to the close time
+            // calendar.
+            closeTimeCalendar.add(Calendar.DATE, 1);
+        }
+
+        // Since the date doesn't actually matter, it's easier to set the current date to the
+        // opening date rather than change both the calendars for the open time and the close time.
+        currentDateTime.set(
+                openTimeCalendar.get(Calendar.YEAR),
+                openTimeCalendar.get(Calendar.MONTH),
+                openTimeCalendar.get(Calendar.DATE));
+
+        return currentDateTime.after(openTimeCalendar) && currentDateTime.before(closeTimeCalendar);
+    }
+
+    /**
      * Get the appropriate title for the context.
      * @return The "Business info" title for a business contact and the "Recent messages" title for
      *         personal contacts.
diff --git a/InCallUI/tests/src/com/android/incallui/InCallContactInteractionsTest.java b/InCallUI/tests/src/com/android/incallui/InCallContactInteractionsTest.java
index b97be01..50d0aaf 100644
--- a/InCallUI/tests/src/com/android/incallui/InCallContactInteractionsTest.java
+++ b/InCallUI/tests/src/com/android/incallui/InCallContactInteractionsTest.java
@@ -44,6 +44,26 @@
         assertEquals(mContext.getString(R.string.open_now), info.heading);
     }
 
+    public void testIsOpenNow_ClosingAfterMidnight() {
+        Calendar currentTimeForTest = Calendar.getInstance();
+        currentTimeForTest.set(Calendar.HOUR_OF_DAY, 10);
+        BusinessContextInfo info =
+                mInCallContactInteractions.constructHoursInfo(
+                        currentTimeForTest,
+                        Pair.create("0800", "0100"));
+        assertEquals(mContext.getString(R.string.open_now), info.heading);
+    }
+
+    public void testIsOpenNow_Open24Hours() {
+        Calendar currentTimeForTest = Calendar.getInstance();
+        currentTimeForTest.set(Calendar.HOUR_OF_DAY, 10);
+        BusinessContextInfo info =
+                mInCallContactInteractions.constructHoursInfo(
+                        currentTimeForTest,
+                        Pair.create("0800", "0800"));
+        assertEquals(mContext.getString(R.string.open_now), info.heading);
+    }
+
     public void testIsClosedNow_BeforeOpen() {
         Calendar currentTimeForTest = Calendar.getInstance();
         currentTimeForTest.set(Calendar.HOUR_OF_DAY, 6);