Merge "Fix issue #2468687: back and home keys don't work on InCallScreen"
diff --git a/api/current.xml b/api/current.xml
index 85367d0..d74127a 100644
--- a/api/current.xml
+++ b/api/current.xml
@@ -90816,7 +90816,7 @@
  type="android.net.http.SslCertificate"
  static="false"
  final="false"
- deprecated="not deprecated"
+ deprecated="deprecated"
  visibility="public"
 >
 <parameter name="issuedTo" type="java.lang.String">
@@ -90835,6 +90835,22 @@
  deprecated="not deprecated"
  visibility="public"
 >
+<parameter name="issuedTo" type="java.lang.String">
+</parameter>
+<parameter name="issuedBy" type="java.lang.String">
+</parameter>
+<parameter name="validNotBefore" type="java.util.Date">
+</parameter>
+<parameter name="validNotAfter" type="java.util.Date">
+</parameter>
+</constructor>
+<constructor name="SslCertificate"
+ type="android.net.http.SslCertificate"
+ static="false"
+ final="false"
+ deprecated="not deprecated"
+ visibility="public"
+>
 <parameter name="certificate" type="java.security.cert.X509Certificate">
 </parameter>
 </constructor>
@@ -90867,6 +90883,17 @@
  synchronized="false"
  static="false"
  final="false"
+ deprecated="deprecated"
+ visibility="public"
+>
+</method>
+<method name="getValidNotAfterDate"
+ return="java.util.Date"
+ abstract="false"
+ native="false"
+ synchronized="false"
+ static="false"
+ final="false"
  deprecated="not deprecated"
  visibility="public"
 >
@@ -90878,6 +90905,17 @@
  synchronized="false"
  static="false"
  final="false"
+ deprecated="deprecated"
+ visibility="public"
+>
+</method>
+<method name="getValidNotBeforeDate"
+ return="java.util.Date"
+ abstract="false"
+ native="false"
+ synchronized="false"
+ static="false"
+ final="false"
  deprecated="not deprecated"
  visibility="public"
 >
@@ -163934,7 +163972,7 @@
 <method name="println"
  return="int"
  abstract="false"
- native="true"
+ native="false"
  synchronized="false"
  static="true"
  final="false"
@@ -209733,7 +209771,7 @@
  deprecated="not deprecated"
  visibility="public"
 >
-<parameter name="drawBottomStrips" type="boolean">
+<parameter name="stripEnabled" type="boolean">
 </parameter>
 </method>
 </class>
diff --git a/core/java/android/net/http/SslCertificate.java b/core/java/android/net/http/SslCertificate.java
index 4ba4b80..e2d687d 100644
--- a/core/java/android/net/http/SslCertificate.java
+++ b/core/java/android/net/http/SslCertificate.java
@@ -173,7 +173,7 @@
      * @return Not-after date from the certificate validity period in
      * ISO 8601 format or "" if none has been set
      *
-     * {@link #getValidNotAfterDate()}
+     * @deprecated Use {@link #getValidNotAfterDate()}
      */
     public String getValidNotAfter() {
         return formatDate(mValidNotAfter);
diff --git a/core/java/android/view/View.java b/core/java/android/view/View.java
index 11b0b14..639441b 100644
--- a/core/java/android/view/View.java
+++ b/core/java/android/view/View.java
@@ -2283,7 +2283,7 @@
             scrollabilityCache.scrollBar = new ScrollBarDrawable();
         }
         
-        final boolean fadeScrollbars = a.getBoolean(R.styleable.View_fadeScrollbars, false);
+        final boolean fadeScrollbars = a.getBoolean(R.styleable.View_fadeScrollbars, true);
 
         if (!fadeScrollbars) {
             scrollabilityCache.state = ScrollabilityCache.ON;
diff --git a/core/java/android/webkit/CallbackProxy.java b/core/java/android/webkit/CallbackProxy.java
index 61a2d2ef..a013a9b 100644
--- a/core/java/android/webkit/CallbackProxy.java
+++ b/core/java/android/webkit/CallbackProxy.java
@@ -69,6 +69,8 @@
     private volatile int mLatestProgress = 100;
     // Back/Forward list
     private final WebBackForwardList mBackForwardList;
+    // Back/Forward list client
+    private volatile WebBackForwardListClient mWebBackForwardListClient;
     // Used to call startActivity during url override.
     private final Context mContext;
 
@@ -107,6 +109,8 @@
     private static final int RECEIVED_TOUCH_ICON_URL             = 132;
     private static final int GET_VISITED_HISTORY                 = 133;
     private static final int OPEN_FILE_CHOOSER                   = 134;
+    private static final int ADD_HISTORY_ITEM                    = 135;
+    private static final int HISTORY_INDEX_CHANGED               = 136;
 
     // Message triggered by the client to resume execution
     private static final int NOTIFY                              = 200;
@@ -137,7 +141,7 @@
         // Used to start a default activity.
         mContext = context;
         mWebView = w;
-        mBackForwardList = new WebBackForwardList();
+        mBackForwardList = new WebBackForwardList(this);
     }
 
     /**
@@ -190,6 +194,14 @@
         return mBackForwardList;
     }
 
+    void setWebBackForwardListClient(WebBackForwardListClient client) {
+        mWebBackForwardListClient = client;
+    }
+
+    WebBackForwardListClient getWebBackForwardListClient() {
+        return mWebBackForwardListClient;
+    }
+
     /**
      * Called by the UI side.  Calling overrideUrlLoading from the WebCore
      * side will post a message to call this method.
@@ -700,6 +712,20 @@
                     mWebChromeClient.openFileChooser((UploadFile) msg.obj);
                 }
                 break;
+
+            case ADD_HISTORY_ITEM:
+                if (mWebBackForwardListClient != null) {
+                    mWebBackForwardListClient.onNewHistoryItem(
+                            (WebHistoryItem) msg.obj);
+                }
+                break;
+
+            case HISTORY_INDEX_CHANGED:
+                if (mWebBackForwardListClient != null) {
+                    mWebBackForwardListClient.onIndexChanged(
+                            (WebHistoryItem) msg.obj, msg.arg1);
+                }
+                break;
         }
     }
 
@@ -1400,4 +1426,20 @@
         }
         return uploadFile.getResult();
     }
+
+    void onNewHistoryItem(WebHistoryItem item) {
+        if (mWebBackForwardListClient == null) {
+            return;
+        }
+        Message msg = obtainMessage(ADD_HISTORY_ITEM, item);
+        sendMessage(msg);
+    }
+
+    void onIndexChanged(WebHistoryItem item, int index) {
+        if (mWebBackForwardListClient == null) {
+            return;
+        }
+        Message msg = obtainMessage(HISTORY_INDEX_CHANGED, index, 0, item);
+        sendMessage(msg);
+    }
 }
diff --git a/core/java/android/webkit/WebBackForwardList.java b/core/java/android/webkit/WebBackForwardList.java
index 62a5531..79e634e 100644
--- a/core/java/android/webkit/WebBackForwardList.java
+++ b/core/java/android/webkit/WebBackForwardList.java
@@ -31,13 +31,16 @@
     private ArrayList<WebHistoryItem> mArray;
     // Flag to indicate that the list is invalid
     private boolean mClearPending;
+    // CallbackProxy to issue client callbacks.
+    private final CallbackProxy mCallbackProxy;
 
     /**
      * Construct a back/forward list used by clients of WebView.
      */
-    /*package*/ WebBackForwardList() {
+    /*package*/ WebBackForwardList(CallbackProxy proxy) {
         mCurrentIndex = -1;
         mArray = new ArrayList<WebHistoryItem>();
+        mCallbackProxy = proxy;
     }
 
     /**
@@ -116,6 +119,9 @@
         }
         // Add the item to the list.
         mArray.add(item);
+        if (mCallbackProxy != null) {
+            mCallbackProxy.onNewHistoryItem(item);
+        }
     }
 
     /**
@@ -152,7 +158,7 @@
      * webkit package classes.
      */
     protected synchronized WebBackForwardList clone() {
-        WebBackForwardList l = new WebBackForwardList();
+        WebBackForwardList l = new WebBackForwardList(null);
         if (mClearPending) {
             // If a clear is pending, return a copy with only the current item.
             l.addHistoryItem(getCurrentItem());
@@ -174,6 +180,9 @@
      */
     /*package*/ synchronized void setCurrentIndex(int newIndex) {
         mCurrentIndex = newIndex;
+        if (mCallbackProxy != null) {
+            mCallbackProxy.onIndexChanged(getItemAtIndex(newIndex), newIndex);
+        }
     }
 
     /**
diff --git a/core/java/android/webkit/WebBackForwardListClient.java b/core/java/android/webkit/WebBackForwardListClient.java
new file mode 100644
index 0000000..7fe9281
--- /dev/null
+++ b/core/java/android/webkit/WebBackForwardListClient.java
@@ -0,0 +1,40 @@
+/*
+ * Copyright (C) 2010 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 android.webkit;
+
+/**
+ * Interface to receive notifications when items are added to the
+ * {@link WebBackForwardList}.
+ * {@hide}
+ */
+public abstract class WebBackForwardListClient {
+
+    /**
+     * Notify the client that <var>item</var> has been added to the
+     * WebBackForwardList.
+     * @param item The newly created WebHistoryItem
+     */
+    public void onNewHistoryItem(WebHistoryItem item) { }
+
+    /**
+     * Notify the client that the <var>item</var> at <var>index</var> is now
+     * the current history item.
+     * @param item A WebHistoryItem
+     * @param index The new history index
+     */
+    public void onIndexChanged(WebHistoryItem item, int index) { }
+}
diff --git a/core/java/android/webkit/WebHistoryItem.java b/core/java/android/webkit/WebHistoryItem.java
index abd8237..428a59c 100644
--- a/core/java/android/webkit/WebHistoryItem.java
+++ b/core/java/android/webkit/WebHistoryItem.java
@@ -41,6 +41,8 @@
     private byte[] mFlattenedData;
     // The apple-touch-icon url for use when adding the site to the home screen
     private String mTouchIconUrl;
+    // Custom client data that is not flattened or read by native code.
+    private Object mCustomData;
 
     /**
      * Basic constructor that assigns a unique id to the item. Called by JNI
@@ -137,6 +139,28 @@
     }
 
     /**
+     * Return the custom data provided by the client.
+     * @hide
+     */
+    public Object getCustomData() {
+        return mCustomData;
+    }
+
+    /**
+     * Set the custom data field.
+     * @param data An Object containing any data the client wishes to associate
+     *             with the item.
+     * @hide
+     */
+    public void setCustomData(Object data) {
+        // NOTE: WebHistoryItems are used in multiple threads. However, the
+        // public facing apis are all getters with the exception of this one
+        // api. Since this api is exclusive to clients, we don't make any
+        // promises about thread safety.
+        mCustomData = data;
+    }
+
+    /**
      * Set the favicon.
      * @param icon A Bitmap containing the favicon for this history item.
      * Note: The VM ensures 32-bit atomic read/write operations so we don't have
diff --git a/core/java/android/webkit/WebView.java b/core/java/android/webkit/WebView.java
index 5772497..72791fb 100644
--- a/core/java/android/webkit/WebView.java
+++ b/core/java/android/webkit/WebView.java
@@ -2860,6 +2860,25 @@
     }
 
     /**
+     * Set the back/forward list client. This is an implementation of
+     * WebBackForwardListClient for handling new items and changes in the
+     * history index.
+     * @param client An implementation of WebBackForwardListClient.
+     * {@hide}
+     */
+    public void setWebBackForwardListClient(WebBackForwardListClient client) {
+        mCallbackProxy.setWebBackForwardListClient(client);
+    }
+
+    /**
+     * Gets the WebBackForwardListClient.
+     * {@hide}
+     */
+    public WebBackForwardListClient getWebBackForwardListClient() {
+        return mCallbackProxy.getWebBackForwardListClient();
+    }
+
+    /**
      * Set the Picture listener. This is an interface used to receive
      * notifications of a new Picture.
      * @param listener An implementation of WebView.PictureListener.
diff --git a/core/java/android/widget/HeaderViewListAdapter.java b/core/java/android/widget/HeaderViewListAdapter.java
index b0e5f7e..981996a 100644
--- a/core/java/android/widget/HeaderViewListAdapter.java
+++ b/core/java/android/widget/HeaderViewListAdapter.java
@@ -34,6 +34,8 @@
 
     private ListAdapter mAdapter;
 
+    // These two ArrayList are assumed to NOT be null.
+    // They are indeed created when declared in ListView and then shared. 
     ArrayList<ListView.FixedViewInfo> mHeaderViewInfos;
     ArrayList<ListView.FixedViewInfo> mFooterViewInfos;
     boolean mAreAllFixedViewsSelectable;
@@ -55,11 +57,11 @@
     }
 
     public int getHeadersCount() {
-        return mHeaderViewInfos == null ? 0 : mHeaderViewInfos.size();
+        return mHeaderViewInfos.size();
     }
 
     public int getFootersCount() {
-        return mFooterViewInfos == null ? 0 : mFooterViewInfos.size();
+        return mFooterViewInfos.size();
     }
 
     public boolean isEmpty() {
@@ -132,12 +134,12 @@
         if (mAdapter != null && position >= numHeaders) {
             int adjPosition = position - numHeaders;
             int adapterCount = mAdapter.getCount();
-            if (adjPosition >= adapterCount && mFooterViewInfos != null) {
+            if (adjPosition >= adapterCount) {
                 return mFooterViewInfos.get(adjPosition - adapterCount).isSelectable;
             } else {
                 return mAdapter.isEnabled(adjPosition);
             }
-        } else if (position < numHeaders && mHeaderViewInfos != null) {
+        } else if (position < numHeaders) {
             return mHeaderViewInfos.get(position).isSelectable;
         }
         return true;
@@ -148,12 +150,12 @@
         if (mAdapter != null && position >= numHeaders) {
             int adjPosition = position - numHeaders;
             int adapterCount = mAdapter.getCount();
-            if (adjPosition >= adapterCount && mFooterViewInfos != null) {
+            if (adjPosition >= adapterCount) {
                 return mFooterViewInfos.get(adjPosition - adapterCount).data;
             } else {
                 return mAdapter.getItem(adjPosition);
             }
-        } else if (position < numHeaders && mHeaderViewInfos != null) {
+        } else if (position < numHeaders) {
             return mHeaderViewInfos.get(position).data;
         }
         return null;
@@ -184,9 +186,7 @@
             int adjPosition = position - numHeaders;
             int adapterCount = mAdapter.getCount();
             if (adjPosition >= adapterCount) {
-                if (mFooterViewInfos != null) {
-                    return mFooterViewInfos.get(adjPosition - adapterCount).view;
-                }
+                return mFooterViewInfos.get(adjPosition - adapterCount).view;
             } else {
                 return mAdapter.getView(adjPosition, convertView, parent);
             }
diff --git a/core/java/android/widget/ListView.java b/core/java/android/widget/ListView.java
index 7f77fa9..88f2e12 100644
--- a/core/java/android/widget/ListView.java
+++ b/core/java/android/widget/ListView.java
@@ -246,7 +246,7 @@
      * added. Views added using this call can take focus if they want.
      * <p>
      * NOTE: Call this before calling setAdapter. This is so ListView can wrap
-     * the supplied cursor with one that that will also account for header
+     * the supplied cursor with one that will also account for header and footer
      * views.
      *
      * @param v The view to add.
@@ -273,7 +273,7 @@
      * added. Views added using this call can take focus if they want.
      * <p>
      * NOTE: Call this before calling setAdapter. This is so ListView can wrap
-     * the supplied cursor with one that that will also account for header
+     * the supplied cursor with one that will also account for header and footer
      * views.
      *
      * @param v The view to add.
@@ -324,7 +324,7 @@
      * added. Views added using this call can take focus if they want.
      * <p>
      * NOTE: Call this before calling setAdapter. This is so ListView can wrap
-     * the supplied cursor with one that that will also account for header
+     * the supplied cursor with one that will also account for header and footer
      * views.
      *
      * @param v The view to add.
@@ -350,7 +350,7 @@
      * than once, the views will appear in the order they were added. Views added using
      * this call can take focus if they want.
      * <p>NOTE: Call this before calling setAdapter. This is so ListView can wrap the supplied
-     * cursor with one that that will also account for header views.
+     * cursor with one that will also account for header and footer views.
      *
      *
      * @param v The view to add.