Merge change 4922

* changes:
  Enable storage tests in Dump Render Tree so we can run Database and DOM Storage layout tests.
diff --git a/api/current.xml b/api/current.xml
index 3174f09..55066f1 100644
--- a/api/current.xml
+++ b/api/current.xml
@@ -683,6 +683,17 @@
  visibility="public"
 >
 </field>
+<field name="READ_HISTORY_BOOKMARKS"
+ type="java.lang.String"
+ transient="false"
+ volatile="false"
+ value="&quot;android.permission.READ_HISTORY_BOOKMARKS&quot;"
+ static="true"
+ final="true"
+ deprecated="not deprecated"
+ visibility="public"
+>
+</field>
 <field name="READ_INPUT_STATE"
  type="java.lang.String"
  transient="false"
@@ -1134,6 +1145,17 @@
  visibility="public"
 >
 </field>
+<field name="WRITE_HISTORY_BOOKMARKS"
+ type="java.lang.String"
+ transient="false"
+ volatile="false"
+ value="&quot;android.permission.WRITE_HISTORY_BOOKMARKS&quot;"
+ static="true"
+ final="true"
+ deprecated="not deprecated"
+ visibility="public"
+>
+</field>
 <field name="WRITE_OWNER_DATA"
  type="java.lang.String"
  transient="false"
@@ -50478,6 +50500,17 @@
  visibility="public"
 >
 </method>
+<method name="prepareToDraw"
+ return="void"
+ abstract="false"
+ native="false"
+ synchronized="false"
+ static="false"
+ final="false"
+ deprecated="not deprecated"
+ visibility="public"
+>
+</method>
 <method name="recycle"
  return="void"
  abstract="false"
diff --git a/camera/libcameraservice/CameraService.cpp b/camera/libcameraservice/CameraService.cpp
index 81639ad..980ce78 100644
--- a/camera/libcameraservice/CameraService.cpp
+++ b/camera/libcameraservice/CameraService.cpp
@@ -42,6 +42,7 @@
 #include <sys/stat.h>
 #include <fcntl.h>
 #include <pthread.h>
+#include <signal.h>
 }
 
 // When you enable this, as well as DEBUG_REFS=1 and
@@ -63,6 +64,10 @@
 static int debug_frame_cnt;
 #endif
 
+static int getCallingPid() {
+    return IPCThreadState::self()->getCallingPid();
+}
+
 // ----------------------------------------------------------------------------
 
 void CameraService::instantiate() {
@@ -87,7 +92,9 @@
 
 sp<ICamera> CameraService::connect(const sp<ICameraClient>& cameraClient)
 {
-    LOGD("Connect E from ICameraClient %p", cameraClient->asBinder().get());
+    int callingPid = getCallingPid();
+    LOGD("CameraService::connect E (pid %d, client %p)", callingPid,
+            cameraClient->asBinder().get());
 
     Mutex::Autolock lock(mLock);
     sp<Client> client;
@@ -96,36 +103,46 @@
         if (currentClient != 0) {
             sp<ICameraClient> currentCameraClient(currentClient->getCameraClient());
             if (cameraClient->asBinder() == currentCameraClient->asBinder()) {
-                // this is the same client reconnecting...
-                LOGD("Connect X same client (%p) is reconnecting...", cameraClient->asBinder().get());
+                // This is the same client reconnecting...
+                LOGD("CameraService::connect X (pid %d, same client %p) is reconnecting...",
+                    callingPid, cameraClient->asBinder().get());
                 return currentClient;
             } else {
-                // it's another client... reject it
-                LOGD("new client (%p) attempting to connect - rejected", cameraClient->asBinder().get());
+                // It's another client... reject it
+                LOGD("CameraService::connect X (pid %d, new client %p) rejected. "
+                    "(old pid %d, old client %p)",
+                    callingPid, cameraClient->asBinder().get(),
+                    currentClient->mClientPid, currentCameraClient->asBinder().get());
+                if (kill(currentClient->mClientPid, 0) == ESRCH) {
+                    LOGD("The old client is dead!");
+                }
                 return client;
             }
         } else {
             // can't promote, the previous client has died...
-            LOGD("new client connecting, old reference was dangling...");
+            LOGD("New client (pid %d) connecting, old reference was dangling...",
+                    callingPid);
             mClient.clear();
         }
     }
 
     // create a new Client object
-    client = new Client(this, cameraClient, IPCThreadState::self()->getCallingPid());
+    client = new Client(this, cameraClient, callingPid);
     mClient = client;
 #if DEBUG_CLIENT_REFERENCES
     // Enable tracking for this object, and track increments and decrements of
     // the refcount.
     client->trackMe(true, true);
 #endif
-    LOGD("Connect X");
+    LOGD("CameraService::connect X");
     return client;
 }
 
 void CameraService::removeClient(const sp<ICameraClient>& cameraClient)
 {
-    // declar this outside the lock to make absolutely sure the
+    int callingPid = getCallingPid();
+
+    // Declare this outside the lock to make absolutely sure the
     // destructor won't be called with the lock held.
     sp<Client> client;
 
@@ -133,26 +150,28 @@
 
     if (mClient == 0) {
         // This happens when we have already disconnected.
-        LOGV("mClient is null.");
+        LOGD("removeClient (pid %d): already disconnected", callingPid);
         return;
     }
 
-    // Promote mClient. It should never fail because we're called from
-    // a binder call, so someone has to have a strong reference.
+    // Promote mClient. It can fail if we are called from this path:
+    // Client::~Client() -> disconnect() -> removeClient().
     client = mClient.promote();
     if (client == 0) {
-        LOGW("can't get a strong reference on mClient!");
+        LOGD("removeClient (pid %d): no more strong reference", callingPid);
         mClient.clear();
         return;
     }
 
     if (cameraClient->asBinder() != client->getCameraClient()->asBinder()) {
         // ugh! that's not our client!!
-        LOGW("removeClient() called, but mClient doesn't match!");
+        LOGW("removeClient (pid %d): mClient doesn't match!", callingPid);
     } else {
         // okay, good, forget about mClient
         mClient.clear();
     }
+
+    LOGD("removeClient (pid %d) done", callingPid);
 }
 
 static sp<MediaPlayer> newMediaPlayer(const char *file) 
@@ -177,7 +196,8 @@
 CameraService::Client::Client(const sp<CameraService>& cameraService,
         const sp<ICameraClient>& cameraClient, pid_t clientPid)
 {
-    LOGD("Client E constructor");
+    int callingPid = getCallingPid();
+    LOGD("Client::Client E (pid %d)", callingPid);
     mCameraService = cameraService;
     mCameraClient = cameraClient;
     mClientPid = clientPid;
@@ -189,22 +209,27 @@
 
     // Callback is disabled by default
     mPreviewCallbackFlag = FRAME_CALLBACK_FLAG_NOOP;
-    LOGD("Client X constructor");
+    LOGD("Client::Client X (pid %d)", callingPid);
 }
 
 status_t CameraService::Client::checkPid()
 {
-    if (mClientPid == IPCThreadState::self()->getCallingPid()) return NO_ERROR;
-    LOGW("Attempt to use locked camera (%p) from different process", getCameraClient()->asBinder().get());
+    int callingPid = getCallingPid();
+    if (mClientPid == callingPid) return NO_ERROR;
+    LOGW("Attempt to use locked camera (client %p) from different process "
+        " (old pid %d, new pid %d)",
+        getCameraClient()->asBinder().get(), mClientPid, callingPid);
     return -EBUSY;
 }
 
 status_t CameraService::Client::lock()
 {
+    int callingPid = getCallingPid();
+    LOGD("lock from pid %d (mClientPid %d)", callingPid, mClientPid);
     Mutex::Autolock _l(mLock);
     // lock camera to this client if the the camera is unlocked
     if (mClientPid == 0) {
-        mClientPid = IPCThreadState::self()->getCallingPid();
+        mClientPid = callingPid;
         return NO_ERROR;
     }
     // returns NO_ERROR if the client already owns the camera, -EBUSY otherwise
@@ -213,13 +238,14 @@
 
 status_t CameraService::Client::unlock()
 {
+    int callingPid = getCallingPid();
+    LOGD("unlock from pid %d (mClientPid %d)", callingPid, mClientPid);    
     Mutex::Autolock _l(mLock);
     // allow anyone to use camera
-    LOGD("unlock (%p)", getCameraClient()->asBinder().get());
     status_t result = checkPid();
     if (result == NO_ERROR) {
         mClientPid = 0;
-
+        LOGD("clear mCameraClient (pid %d)", callingPid);
         // we need to remove the reference so that when app goes
         // away, the reference count goes to 0.
         mCameraClient.clear();
@@ -229,15 +255,17 @@
 
 status_t CameraService::Client::connect(const sp<ICameraClient>& client)
 {
+    int callingPid = getCallingPid();
+
     // connect a new process to the camera
-    LOGD("connect (%p)", client->asBinder().get());
+    LOGD("Client::connect E (pid %d, client %p)", callingPid, client->asBinder().get());
 
     // I hate this hack, but things get really ugly when the media recorder
     // service is handing back the camera to the app. The ICameraClient
     // destructor will be called during the same IPC, making it look like
     // the remote client is trying to disconnect. This hack temporarily
     // sets the mClientPid to an invalid pid to prevent the hardware from
-    //  being torn down.
+    // being torn down.
     {
 
         // hold a reference to the old client or we will deadlock if the client is
@@ -246,24 +274,29 @@
         {
             Mutex::Autolock _l(mLock);
             if (mClientPid != 0 && checkPid() != NO_ERROR) {
-                LOGW("Tried to connect to locked camera");
+                LOGW("Tried to connect to locked camera (old pid %d, new pid %d)",
+                        mClientPid, callingPid);
                 return -EBUSY;
             }
             oldClient = mCameraClient;
 
             // did the client actually change?
-            if (client->asBinder() == mCameraClient->asBinder()) return NO_ERROR;
+            if (client->asBinder() == mCameraClient->asBinder()) {
+                LOGD("Connect to the same client");
+                return NO_ERROR;
+            }
 
             mCameraClient = client;
             mClientPid = -1;
             mPreviewCallbackFlag = FRAME_CALLBACK_FLAG_NOOP;
-            LOGD("connect new process (%d) to existing camera client", mClientPid);
+            LOGD("Connect to the new client (pid %d, client %p)",
+                callingPid, mCameraClient->asBinder().get());
         }
 
     }
     // the old client destructor is called when oldClient goes out of scope
     // now we set the new PID to lock the interface again
-    mClientPid = IPCThreadState::self()->getCallingPid();
+    mClientPid = callingPid;
 
     return NO_ERROR;
 }
@@ -280,8 +313,11 @@
 
 CameraService::Client::~Client()
 {
+    int callingPid = getCallingPid();
+
     // tear down client
-    LOGD("Client (%p)  E destructor", getCameraClient()->asBinder().get());
+    LOGD("Client::~Client E (pid %d, client %p)",
+            callingPid, getCameraClient()->asBinder().get());
     if (mSurface != 0 && !mUseOverlay) {
 #if HAVE_ANDROID_OS
         pthread_t thr;
@@ -307,19 +343,21 @@
     }
 
     // make sure we tear down the hardware
-    mClientPid = IPCThreadState::self()->getCallingPid();
+    mClientPid = callingPid;
     disconnect();
-    LOGD("Client X destructor");
+    LOGD("Client::~Client X (pid %d)", mClientPid);
 }
 
 void CameraService::Client::disconnect()
 {
-    LOGD("Client (%p) E disconnect from (%d)",
-            getCameraClient()->asBinder().get(),
-            IPCThreadState::self()->getCallingPid());
+    int callingPid = getCallingPid();    
+
+    LOGD("Client::disconnect() E (pid %d client %p)",
+            callingPid, getCameraClient()->asBinder().get());
+
     Mutex::Autolock lock(mLock);
     if (mClientPid <= 0) {
-        LOGD("camera is unlocked, don't tear down hardware");
+        LOGD("camera is unlocked (mClientPid = %d), don't tear down hardware", mClientPid);
         return;
     }
     if (checkPid() != NO_ERROR) {
@@ -339,13 +377,13 @@
         mHardware->release();
     }
     mHardware.clear();
-    LOGD("Client X disconnect");
+    LOGD("Client::disconnect() X (pid %d)", callingPid);
 }
 
 // pass the buffered ISurface to the camera service
 status_t CameraService::Client::setPreviewDisplay(const sp<ISurface>& surface)
 {
-    LOGD("setPreviewDisplay(%p)", surface.get());
+    LOGD("setPreviewDisplay(%p) (pid %d)", surface.get(), getCallingPid());
     Mutex::Autolock lock(mLock);
     status_t result = checkPid();
     if (result != NO_ERROR) return result;
@@ -365,7 +403,7 @@
 // preview are handled.
 void CameraService::Client::setPreviewCallbackFlag(int callback_flag)
 {
-    LOGV("setPreviewCallbackFlag");
+    LOGV("setPreviewCallbackFlag (pid %d)", getCallingPid());
     Mutex::Autolock lock(mLock);
     if (checkPid() != NO_ERROR) return;
     mPreviewCallbackFlag = callback_flag;
@@ -374,7 +412,9 @@
 // start preview mode, must call setPreviewDisplay first
 status_t CameraService::Client::startCameraMode(camera_mode mode)
 {
-    LOGD("startCameraMode(%d)", mode);
+    int callingPid = getCallingPid();
+
+    LOGD("startCameraMode(%d) (pid %d)", mode, callingPid);
 
     /* we cannot call into mHardware with mLock held because
      * mHardware has callbacks onto us which acquire this lock
@@ -405,7 +445,7 @@
 
 status_t CameraService::Client::startRecordingMode()
 {
-    LOGV("startRecordingMode");
+    LOGD("startRecordingMode (pid %d)", getCallingPid());
 
     status_t ret = UNKNOWN_ERROR;
 
@@ -433,7 +473,7 @@
 
 status_t CameraService::Client::startPreviewMode()
 {
-    LOGV("startPreviewMode");
+    LOGD("startPreviewMode (pid %d)", getCallingPid());
 
     // if preview has been enabled, nothing needs to be done
     if (mHardware->previewEnabled()) {
@@ -500,11 +540,15 @@
 
 status_t CameraService::Client::startPreview()
 {
+    LOGD("startPreview (pid %d)", getCallingPid());
+    
     return startCameraMode(CAMERA_PREVIEW_MODE);
 }
 
 status_t CameraService::Client::startRecording()
 {
+    LOGD("startRecording (pid %d)", getCallingPid());
+
     if (mMediaPlayerBeep.get() != NULL) {
         mMediaPlayerBeep->seekTo(0);
         mMediaPlayerBeep->start();
@@ -515,7 +559,7 @@
 // stop preview mode
 void CameraService::Client::stopPreview()
 {
-    LOGD("stopPreview()");
+    LOGD("stopPreview (pid %d)", getCallingPid());
 
     Mutex::Autolock lock(mLock);
     if (checkPid() != NO_ERROR) return;
@@ -537,7 +581,7 @@
 // stop recording mode
 void CameraService::Client::stopRecording()
 {
-    LOGV("stopRecording()");
+    LOGD("stopRecording (pid %d)", getCallingPid());
 
     Mutex::Autolock lock(mLock);
     if (checkPid() != NO_ERROR) return;
@@ -552,15 +596,13 @@
         mMediaPlayerBeep->start();
     }
     mHardware->stopRecording();
-    LOGV("stopRecording(), hardware stopped OK");
+    LOGD("stopRecording(), hardware stopped OK");
     mPreviewBuffer.clear();
 }
 
 // release a recording frame
 void CameraService::Client::releaseRecordingFrame(const sp<IMemory>& mem)
 {
-    LOGV("releaseRecordingFrame()");
-
     Mutex::Autolock lock(mLock);
     if (checkPid() != NO_ERROR) return;
 
@@ -704,7 +746,7 @@
 // take a picture - image is returned in callback
 status_t CameraService::Client::autoFocus()
 {
-    LOGV("autoFocus");
+    LOGD("autoFocus (pid %d)", getCallingPid());
 
     Mutex::Autolock lock(mLock);
     status_t result = checkPid();
@@ -722,7 +764,7 @@
 // take a picture - image is returned in callback
 status_t CameraService::Client::takePicture()
 {
-    LOGD("takePicture");
+    LOGD("takePicture (pid %d)", getCallingPid());
 
     Mutex::Autolock lock(mLock);
     status_t result = checkPid();
@@ -920,6 +962,7 @@
 
 void CameraService::Client::postShutter()
 {
+    LOGD("postShutter");
     mCameraClient->notifyCallback(CAMERA_MSG_SHUTTER, 0, 0);
 }
 
@@ -1029,7 +1072,7 @@
     if (checkCallingPermission(String16("android.permission.DUMP")) == false) {
         snprintf(buffer, SIZE, "Permission Denial: "
                 "can't dump CameraService from pid=%d, uid=%d\n",
-                IPCThreadState::self()->getCallingPid(),
+                getCallingPid(),
                 IPCThreadState::self()->getCallingUid());
         result.append(buffer);
         write(fd, result.string(), result.size());
diff --git a/core/java/android/app/ApplicationContext.java b/core/java/android/app/ApplicationContext.java
index 1666588..8ec1445 100644
--- a/core/java/android/app/ApplicationContext.java
+++ b/core/java/android/app/ApplicationContext.java
@@ -1053,11 +1053,6 @@
     }
 
     private SearchManager getSearchManager() {
-        // This is only useable in Activity Contexts
-        if (getActivityToken() == null) {
-            throw new AndroidRuntimeException(
-                "Acquiring SearchManager objects only valid in Activity Contexts.");
-        }
         synchronized (mSync) {
             if (mSearchManager == null) {
                 mSearchManager = new SearchManager(getOuterContext(), mMainThread.getHandler());
diff --git a/core/java/android/app/SearchDialog.java b/core/java/android/app/SearchDialog.java
index 3a3a983..5d1af52 100644
--- a/core/java/android/app/SearchDialog.java
+++ b/core/java/android/app/SearchDialog.java
@@ -310,15 +310,17 @@
                     + appSearchData + ", " + globalSearch + ")");
         }
         
+        SearchManager searchManager = (SearchManager)
+                mContext.getSystemService(Context.SEARCH_SERVICE);
         // Try to get the searchable info for the provided component (or for global search,
         // if globalSearch == true).
-        mSearchable = SearchManager.getSearchableInfo(componentName, globalSearch);
+        mSearchable = searchManager.getSearchableInfo(componentName, globalSearch);
         
         // If we got back nothing, and it wasn't a request for global search, then try again
         // for global search, as we'll try to launch that in lieu of any component-specific search.
         if (!globalSearch && mSearchable == null) {
             globalSearch = true;
-            mSearchable = SearchManager.getSearchableInfo(componentName, globalSearch);
+            mSearchable = searchManager.getSearchableInfo(componentName, globalSearch);
             
             // If we still get back null (i.e., there's not even a searchable info available
             // for global search), then really give up.
@@ -333,7 +335,7 @@
         mAppSearchData = appSearchData;
         // Using globalSearch here is just an optimization, just calling
         // isDefaultSearchable() should always give the same result.
-        mGlobalSearchMode = globalSearch || SearchManager.isDefaultSearchable(mSearchable); 
+        mGlobalSearchMode = globalSearch || searchManager.isDefaultSearchable(mSearchable);
         mActivityContext = mSearchable.getActivityContext(getContext());
         
         // show the dialog. this will call onStart().
diff --git a/core/java/android/app/SearchManager.java b/core/java/android/app/SearchManager.java
index eb80400..fd69ba4 100644
--- a/core/java/android/app/SearchManager.java
+++ b/core/java/android/app/SearchManager.java
@@ -1514,7 +1514,7 @@
     /**
      * Reference to the shared system search service.
      */
-    private static ISearchManager sService = getSearchManagerService();
+    private static ISearchManager mService;
 
     private final Context mContext;
 
@@ -1529,6 +1529,8 @@
     /*package*/ SearchManager(Context context, Handler handler)  {
         mContext = context;
         mHandler = handler;
+        mService = ISearchManager.Stub.asInterface(
+                ServiceManager.getService(Context.SEARCH_SERVICE));
     }
     
     /**
@@ -1581,7 +1583,7 @@
         try {
             mIsShowing = true;
             // activate the search manager and start it up!
-            sService.startSearch(initialQuery, selectInitialQuery, launchActivity, appSearchData,
+            mService.startSearch(initialQuery, selectInitialQuery, launchActivity, appSearchData,
                     globalSearch, mSearchManagerCallback);
         } catch (RemoteException ex) {
             Log.e(TAG, "startSearch() failed: " + ex);
@@ -1603,7 +1605,7 @@
         if (DBG) debug("stopSearch(), mIsShowing=" + mIsShowing);
         if (!mIsShowing) return;
         try {
-            sService.stopSearch();
+            mService.stopSearch();
             // onDismiss will also clear this, but we do it here too since onDismiss() is
             // called asynchronously.
             mIsShowing = false;
@@ -1725,7 +1727,7 @@
         if (DBG) debug("saveSearchDialog(), mIsShowing=" + mIsShowing);
         if (!mIsShowing) return null;
         try {
-            return sService.onSaveInstanceState();
+            return mService.onSaveInstanceState();
         } catch (RemoteException ex) {
             Log.e(TAG, "onSaveInstanceState() failed: " + ex);
             return null;
@@ -1743,7 +1745,7 @@
         if (DBG) debug("restoreSearchDialog(" + searchDialogState + ")");
         if (searchDialogState == null) return;
         try {
-            sService.onRestoreInstanceState(searchDialogState);
+            mService.onRestoreInstanceState(searchDialogState);
         } catch (RemoteException ex) {
             Log.e(TAG, "onRestoreInstanceState() failed: " + ex);
         }
@@ -1760,17 +1762,12 @@
         if (DBG) debug("onConfigurationChanged(" + newConfig + "), mIsShowing=" + mIsShowing);
         if (!mIsShowing) return;
         try {
-            sService.onConfigurationChanged(newConfig);
+            mService.onConfigurationChanged(newConfig);
         } catch (RemoteException ex) {
             Log.e(TAG, "onConfigurationChanged() failed:" + ex);
         }
     }
 
-    private static ISearchManager getSearchManagerService() {
-        return ISearchManager.Stub.asInterface(
-            ServiceManager.getService(Context.SEARCH_SERVICE));
-    }
-    
     /**
      * Gets information about a searchable activity. This method is static so that it can
      * be used from non-Activity contexts.
@@ -1782,10 +1779,10 @@
      * 
      * @hide because SearchableInfo is not part of the API.
      */
-    public static SearchableInfo getSearchableInfo(ComponentName componentName, 
+    public SearchableInfo getSearchableInfo(ComponentName componentName,
             boolean globalSearch) {
         try {
-            return sService.getSearchableInfo(componentName, globalSearch);
+            return mService.getSearchableInfo(componentName, globalSearch);
         } catch (RemoteException ex) {
             Log.e(TAG, "getSearchableInfo() failed: " + ex);
             return null;
@@ -1797,23 +1794,22 @@
      * 
      * @hide because SearchableInfo is not part of the API.
      */
-    public static boolean isDefaultSearchable(SearchableInfo searchable) {
-        SearchableInfo defaultSearchable = SearchManager.getSearchableInfo(null, true);
+    public boolean isDefaultSearchable(SearchableInfo searchable) {
+        SearchableInfo defaultSearchable = getSearchableInfo(null, true);
         return defaultSearchable != null 
                 && defaultSearchable.getSearchActivity().equals(searchable.getSearchActivity());
     }
-    
+
     /**
-     * Gets a cursor with search suggestions. This method is static so that it can
-     * be used from non-Activity context.
+     * Gets a cursor with search suggestions.
      *
      * @param searchable Information about how to get the suggestions.
      * @param query The search text entered (so far).
-     * @return a cursor with suggestions, or <code>null</null> the suggestion query failed. 
-     * 
+     * @return a cursor with suggestions, or <code>null</null> the suggestion query failed.
+     *
      * @hide because SearchableInfo is not part of the API.
      */
-    public static Cursor getSuggestions(Context context, SearchableInfo searchable, String query) {
+    public Cursor getSuggestions(SearchableInfo searchable, String query) {
         if (searchable == null) {
             return null;
         }
@@ -1852,7 +1848,7 @@
                 .build();
 
         // finally, make the query
-        return context.getContentResolver().query(uri, null, selection, selArgs, null);
+        return mContext.getContentResolver().query(uri, null, selection, selArgs, null);
     }
      
     /**
@@ -1864,9 +1860,9 @@
      * 
      * @hide because SearchableInfo is not part of the API.
      */
-    public static List<SearchableInfo> getSearchablesInGlobalSearch() {
+    public List<SearchableInfo> getSearchablesInGlobalSearch() {
         try {
-            return sService.getSearchablesInGlobalSearch();
+            return mService.getSearchablesInGlobalSearch();
         } catch (RemoteException e) {
             Log.e(TAG, "getSearchablesInGlobalSearch() failed: " + e);
             return null;
@@ -1881,9 +1877,9 @@
      *
      * @hide because SearchableInfo is not part of the API.
      */
-    public static List<SearchableInfo> getSearchablesForWebSearch() {
+    public List<SearchableInfo> getSearchablesForWebSearch() {
         try {
-            return sService.getSearchablesForWebSearch();
+            return mService.getSearchablesForWebSearch();
         } catch (RemoteException e) {
             Log.e(TAG, "getSearchablesForWebSearch() failed: " + e);
             return null;
@@ -1897,9 +1893,9 @@
      *
      * @hide because SearchableInfo is not part of the API.
      */
-    public static SearchableInfo getDefaultSearchableForWebSearch() {
+    public SearchableInfo getDefaultSearchableForWebSearch() {
         try {
-            return sService.getDefaultSearchableForWebSearch();
+            return mService.getDefaultSearchableForWebSearch();
         } catch (RemoteException e) {
             Log.e(TAG, "getDefaultSearchableForWebSearch() failed: " + e);
             return null;
@@ -1913,9 +1909,9 @@
      *
      * @hide
      */
-    public static void setDefaultWebSearch(ComponentName component) {
+    public void setDefaultWebSearch(ComponentName component) {
         try {
-            sService.setDefaultWebSearch(component);
+            mService.setDefaultWebSearch(component);
         } catch (RemoteException e) {
             Log.e(TAG, "setDefaultWebSearch() failed: " + e);
         }
diff --git a/core/java/android/app/SuggestionsAdapter.java b/core/java/android/app/SuggestionsAdapter.java
index ed76f4e..0bdb10b 100644
--- a/core/java/android/app/SuggestionsAdapter.java
+++ b/core/java/android/app/SuggestionsAdapter.java
@@ -54,6 +54,7 @@
     private static final boolean DBG = false;
     private static final String LOG_TAG = "SuggestionsAdapter";
 
+    private SearchManager mSearchManager;
     private SearchDialog mSearchDialog;
     private SearchableInfo mSearchable;
     private Context mProviderContext;
@@ -92,6 +93,7 @@
                 com.android.internal.R.layout.search_dropdown_item_icons_2line,
                 null,   // no initial cursor
                 true);  // auto-requery
+        mSearchManager = (SearchManager) mContext.getSystemService(Context.SEARCH_SERVICE);
         mSearchDialog = searchDialog;
         mSearchable = searchable;
 
@@ -142,7 +144,7 @@
             mSearchDialog.getWindow().getDecorView().post(mStartSpinnerRunnable);
         }
         try {
-            final Cursor cursor = SearchManager.getSuggestions(mContext, mSearchable, query);
+            final Cursor cursor = mSearchManager.getSuggestions(mSearchable, query);
             // trigger fill window so the spinner stays up until the results are copied over and
             // closer to being ready
             if (!mGlobalSearchMode) cursor.getCount();
diff --git a/core/java/android/provider/Browser.java b/core/java/android/provider/Browser.java
index 94254de..2490b8a 100644
--- a/core/java/android/provider/Browser.java
+++ b/core/java/android/provider/Browser.java
@@ -172,6 +172,7 @@
 
     /**
      *  Return a cursor pointing to a list of all the bookmarks.
+     *  Requires {@link android.Manifest.permission#READ_HISTORY_BOOKMARKS}
      *  @param cr   The ContentResolver used to access the database.
      */
     public static final Cursor getAllBookmarks(ContentResolver cr) throws 
@@ -183,6 +184,7 @@
 
     /**
      *  Return a cursor pointing to a list of all visited site urls.
+     *  Requires {@link android.Manifest.permission#READ_HISTORY_BOOKMARKS}
      *  @param cr   The ContentResolver used to access the database.
      */
     public static final Cursor getAllVisitedUrls(ContentResolver cr) throws
@@ -194,6 +196,8 @@
     /**
      *  Update the visited history to acknowledge that a site has been
      *  visited.
+     *  Requires {@link android.Manifest.permission#READ_HISTORY_BOOKMARKS}
+     *  Requires {@link android.Manifest.permission#WRITE_HISTORY_BOOKMARKS}
      *  @param cr   The ContentResolver used to access the database.
      *  @param url  The site being visited.
      *  @param real Whether this is an actual visit, and should be added to the
@@ -243,6 +247,8 @@
      * of them.  This is used to keep our history table to a
      * reasonable size.  Note: it does not prune bookmarks.  If the
      * user wants 1000 bookmarks, the user gets 1000 bookmarks.
+     *  Requires {@link android.Manifest.permission#READ_HISTORY_BOOKMARKS}
+     *  Requires {@link android.Manifest.permission#WRITE_HISTORY_BOOKMARKS}
      *
      * @param cr The ContentResolver used to access the database.
      */
@@ -276,6 +282,7 @@
 
     /**
      * Returns whether there is any history to clear.
+     *  Requires {@link android.Manifest.permission#READ_HISTORY_BOOKMARKS}
      * @param cr   The ContentResolver used to access the database.
      * @return boolean  True if the history can be cleared.
      */
@@ -301,6 +308,7 @@
     /**
      *  Delete all entries from the bookmarks/history table which are
      *  not bookmarks.  Also set all visited bookmarks to unvisited.
+     *  Requires {@link android.Manifest.permission#WRITE_HISTORY_BOOKMARKS}
      *  @param cr   The ContentResolver used to access the database.
      */
     public static final void clearHistory(ContentResolver cr) {
@@ -310,6 +318,8 @@
     /**
      * Helper function to delete all history items and revert all
      * bookmarks to zero visits which meet the criteria provided.
+     *  Requires {@link android.Manifest.permission#READ_HISTORY_BOOKMARKS}
+     *  Requires {@link android.Manifest.permission#WRITE_HISTORY_BOOKMARKS}
      * @param cr   The ContentResolver used to access the database.
      * @param whereClause   String to limit the items affected.
      *                      null means all items.
@@ -372,6 +382,7 @@
 
     /**
      * Delete all history items from begin to end.
+     *  Requires {@link android.Manifest.permission#WRITE_HISTORY_BOOKMARKS}
      * @param cr    The ContentResolver used to access the database.
      * @param begin First date to remove.  If -1, all dates before end.
      *              Inclusive.
@@ -399,6 +410,7 @@
 
     /**
      * Remove a specific url from the history database.
+     *  Requires {@link android.Manifest.permission#WRITE_HISTORY_BOOKMARKS}
      * @param cr    The ContentResolver used to access the database.
      * @param url   url to remove.
      */
@@ -412,6 +424,8 @@
 
     /**
      * Add a search string to the searches database.
+     *  Requires {@link android.Manifest.permission#READ_HISTORY_BOOKMARKS}
+     *  Requires {@link android.Manifest.permission#WRITE_HISTORY_BOOKMARKS}
      * @param cr   The ContentResolver used to access the database.
      * @param search    The string to add to the searches database.
      */
@@ -441,6 +455,7 @@
     }
     /**
      * Remove all searches from the search database.
+     *  Requires {@link android.Manifest.permission#WRITE_HISTORY_BOOKMARKS}
      * @param cr   The ContentResolver used to access the database.
      */
     public static final void clearSearches(ContentResolver cr) {
@@ -455,6 +470,7 @@
     
     /**
      *  Request all icons from the database.
+     *  Requires {@link android.Manifest.permission#READ_HISTORY_BOOKMARKS}
      *  @param  cr The ContentResolver used to access the database.
      *  @param  where Clause to be used to limit the query from the database.
      *          Must be an allowable string to be passed into a database query.
diff --git a/core/java/android/syncml/pim/vcard/ContactStruct.java b/core/java/android/syncml/pim/vcard/ContactStruct.java
index 5a29112..4b4c394 100644
--- a/core/java/android/syncml/pim/vcard/ContactStruct.java
+++ b/core/java/android/syncml/pim/vcard/ContactStruct.java
@@ -38,6 +38,7 @@
 
 import java.util.ArrayList;
 import java.util.HashMap;
+import java.util.Iterator;
 import java.util.List;
 import java.util.Locale;
 import java.util.Map;
@@ -181,6 +182,34 @@
         organizationList.add(organizationData);
     }
 
+    /**
+     * Set "position" value to the appropriate data. If there's more than one
+     * OrganizationData objects, the value is set to the last one. If there's no
+     * OrganizationData object, a new OrganizationData is created, whose company name is
+     * empty.  
+     * 
+     * TODO: incomplete logic. fix this:
+     * 
+     * e.g. This assumes ORG comes earlier, but TITLE may come earlier like this, though we do not
+     * know how to handle it in general cases...
+     * ----
+     * TITLE:Software Engineer
+     * ORG:Google
+     * ----
+     */
+    public void setPosition(String positionValue) {
+        if (organizationList == null) {
+            organizationList = new ArrayList<OrganizationData>();
+        }
+        int size = organizationList.size();
+        if (size == 0) {
+            addOrganization(Contacts.OrganizationColumns.TYPE_OTHER, "", null, false);
+            size = 1;
+        }
+        OrganizationData lastData = organizationList.get(size - 1);
+        lastData.positionName = positionValue;
+    }
+    
     public void addExtension(PropertyNode propertyNode) {
         if (propertyNode.propValue.length() == 0) {
             return;
@@ -427,8 +456,6 @@
             } else if (name.equals("ORG")) {
                 // vCard specification does not specify other types.
                 int type = Contacts.OrganizationColumns.TYPE_WORK;
-                String companyName = "";
-                String positionName = "";
                 boolean isPrimary = false;
                 
                 for (String typeString : propertyNode.paramMap_TYPE) {
@@ -442,29 +469,20 @@
                 }
 
                 List<String> list = propertyNode.propValue_vector; 
-                int size = list.size(); 
-                if (size > 1) {
-                    companyName = list.get(0);
-                    StringBuilder builder = new StringBuilder();
-                    for (int i = 1; i < size; i++) {
-                        builder.append(list.get(1));
-                        if (i != size - 1) {
-                            builder.append(", ");
-                        }
+                int size = list.size();
+                StringBuilder builder = new StringBuilder();
+                for (Iterator<String> iter = list.iterator(); iter.hasNext();) {
+                    builder.append(iter.next());
+                    if (iter.hasNext()) {
+                        builder.append(' ');
                     }
-                    positionName = builder.toString();
-                } else if (size == 1) {
-                    companyName = propertyNode.propValue;
-                    positionName = "";
                 }
-                contact.addOrganization(type, companyName, positionName, isPrimary);
+
+                contact.addOrganization(type, builder.toString(), "", isPrimary);
             } else if (name.equals("TITLE")) {
-                contact.title = propertyNode.propValue;
-                // XXX: What to do this? Isn't ORG enough?
-                contact.addExtension(propertyNode);
+                contact.setPosition(propertyNode.propValue);
             } else if (name.equals("ROLE")) {
-                // XXX: What to do this? Isn't ORG enough?
-                contact.addExtension(propertyNode);
+                contact.setPosition(propertyNode.propValue);
             } else if (name.equals("PHOTO")) {
                 // We prefer PHOTO to LOGO.
                 String valueType = propertyNode.paramMap.getAsString("VALUE");
diff --git a/core/jni/android/graphics/Bitmap.cpp b/core/jni/android/graphics/Bitmap.cpp
index 29d8d3c..957b825 100644
--- a/core/jni/android/graphics/Bitmap.cpp
+++ b/core/jni/android/graphics/Bitmap.cpp
@@ -28,7 +28,7 @@
 static void FromColor_D32(void* dst, const SkColor src[], int width,

                           int, int) {

     SkPMColor* d = (SkPMColor*)dst;

-    

+

     for (int i = 0; i < width; i++) {

         *d++ = SkPreMultiplyColor(*src++);

     }

@@ -37,7 +37,7 @@
 static void FromColor_D565(void* dst, const SkColor src[], int width,

                            int x, int y) {

     uint16_t* d = (uint16_t*)dst;

-    

+

     DITHER_565_SCAN(y);

     for (int stop = x + width; x < stop; x++) {

         SkColor c = *src++;

@@ -49,7 +49,7 @@
 static void FromColor_D4444(void* dst, const SkColor src[], int width,

                             int x, int y) {

     SkPMColor16* d = (SkPMColor16*)dst;

-    

+

     DITHER_4444_SCAN(y);

     for (int stop = x + width; x < stop; x++) {

         SkPMColor c = SkPreMultiplyColor(*src++);

@@ -80,14 +80,14 @@
     SkAutoLockPixels alp(dstBitmap);

     void* dst = dstBitmap.getPixels();

     FromColorProc proc = ChooseFromColorProc(dstBitmap.config());

-    

+

     if (NULL == dst || NULL == proc) {

         return false;

     }

-    

+

     const jint* array = env->GetIntArrayElements(srcColors, NULL);

     const SkColor* src = (const SkColor*)array + srcOffset;

-    

+

     // reset to to actual choice from caller

     dst = dstBitmap.getAddr(x, y);

     // now copy/convert each scanline

@@ -96,7 +96,7 @@
         src += srcStride;

         dst = (char*)dst + dstBitmap.rowBytes();

     }

-    

+

     env->ReleaseIntArrayElements(srcColors, const_cast<jint*>(array),

                                  JNI_ABORT);

     return true;

@@ -212,7 +212,7 @@
         doThrowIAE(env, "width and height must be > 0");

         return NULL;

     }

-    

+

     if (NULL != jColors) {

         size_t n = env->GetArrayLength(jColors);

         if (n < SkAbs32(stride) * (size_t)height) {

@@ -222,7 +222,7 @@
     }

 

     SkBitmap bitmap;

-    

+

     bitmap.setConfig(config, width, height);

     if (!GraphicsJNI::setJavaPixelRef(env, &bitmap, NULL)) {

         return NULL;

@@ -232,7 +232,7 @@
         GraphicsJNI::SetPixels(env, jColors, offset, stride,

                                0, 0, width, height, bitmap);

     }

-    

+

     return GraphicsJNI::createBitmap(env, new SkBitmap(bitmap), isMutable,

                                      NULL);

 }

@@ -245,7 +245,7 @@
     if (!src->copyTo(&result, dstConfig, &allocator)) {

         return NULL;

     }

-    

+

     return GraphicsJNI::createBitmap(env, new SkBitmap(result), isMutable,

                                      NULL);

 }

@@ -324,15 +324,15 @@
         SkDebugf("-------- unparcel parcel is NULL\n");

         return NULL;

     }

-    

+

     android::Parcel* p = android::parcelForJavaObject(env, parcel);

-    

+

     const bool              isMutable = p->readInt32() != 0;

     const SkBitmap::Config  config = (SkBitmap::Config)p->readInt32();

     const int               width = p->readInt32();

     const int               height = p->readInt32();

     const int               rowBytes = p->readInt32();

-    

+

     if (SkBitmap::kARGB_8888_Config != config &&

             SkBitmap::kRGB_565_Config != config &&

             SkBitmap::kARGB_4444_Config != config &&

@@ -355,7 +355,7 @@
             ctable = new SkColorTable(src, count);

         }

     }

-    

+

     if (!GraphicsJNI::setJavaPixelRef(env, bitmap, ctable)) {

         ctable->safeUnref();

         delete bitmap;

@@ -368,7 +368,7 @@
     bitmap->lockPixels();

     memcpy(bitmap->getPixels(), p->readInplace(size), size);

     bitmap->unlockPixels();

-    

+

     return GraphicsJNI::createBitmap(env, bitmap, isMutable, NULL);

 }

 

@@ -381,7 +381,7 @@
     }

 

     android::Parcel* p = android::parcelForJavaObject(env, parcel);

-    

+

     p->writeInt32(isMutable);

     p->writeInt32(bitmap->config());

     p->writeInt32(bitmap->width());

@@ -413,7 +413,7 @@
                                    jintArray offsetXY) {

     SkIPoint  offset;

     SkBitmap* dst = new SkBitmap;

-    

+

     src->extractAlpha(dst, paint, &offset);

     if (offsetXY != 0 && env->GetArrayLength(offsetXY) >= 2) {

         int* array = env->GetIntArrayElements(offsetXY, NULL);

@@ -421,7 +421,7 @@
         array[1] = offset.fY;

         env->ReleaseIntArrayElements(offsetXY, array, 0);

     }

-    

+

     return GraphicsJNI::createBitmap(env, dst, true, NULL);

 }

 

@@ -439,7 +439,7 @@
     if (NULL == src) {

         return 0;

     }

-    

+

     SkColor dst[1];

     proc(dst, src, 1, bitmap->getColorTable());

     return dst[0];

@@ -449,7 +449,7 @@
                              jintArray pixelArray, int offset, int stride,

                              int x, int y, int width, int height) {

     SkAutoLockPixels alp(*bitmap);

-    

+

     ToColorProc proc = ChooseToColorProc(*bitmap);

     if (NULL == proc) {

         return;

@@ -498,7 +498,7 @@
                                       const SkBitmap* bitmap, jobject jbuffer) {

     SkAutoLockPixels alp(*bitmap);

     const void* src = bitmap->getPixels();

-    

+

     if (NULL != src) {

         android::AutoBufferPointer abp(env, jbuffer, JNI_TRUE);

 

@@ -511,7 +511,7 @@
                                     const SkBitmap* bitmap, jobject jbuffer) {

     SkAutoLockPixels alp(*bitmap);

     void* dst = bitmap->getPixels();

-    

+

     if (NULL != dst) {

         android::AutoBufferPointer abp(env, jbuffer, JNI_FALSE);

         // the java side has already checked that buffer is large enough

@@ -519,6 +519,11 @@
     }

 }

 

+static void Bitmap_prepareToDraw(JNIEnv* env, jobject, SkBitmap* bitmap) {

+    bitmap->lockPixels();

+    bitmap->unlockPixels();

+}

+

 ///////////////////////////////////////////////////////////////////////////////

 

 #include <android_runtime/AndroidRuntime.h>

@@ -552,7 +557,8 @@
     {   "nativeCopyPixelsToBuffer", "(ILjava/nio/Buffer;)V",

                                             (void*)Bitmap_copyPixelsToBuffer },

     {   "nativeCopyPixelsFromBuffer", "(ILjava/nio/Buffer;)V",

-                                            (void*)Bitmap_copyPixelsFromBuffer }

+                                            (void*)Bitmap_copyPixelsFromBuffer },

+    {   "nativePrepareToDraw",      "(I)V", (void*)Bitmap_prepareToDraw }

 };

 

 #define kClassPathName  "android/graphics/Bitmap"

diff --git a/core/res/AndroidManifest.xml b/core/res/AndroidManifest.xml
index c1017d4..0c90769 100644
--- a/core/res/AndroidManifest.xml
+++ b/core/res/AndroidManifest.xml
@@ -175,6 +175,22 @@
         android:label="@string/permlab_writeDictionary"
         android:description="@string/permdesc_writeDictionary" />
 
+    <!-- Allows an application to read (but not write) the user's
+        browsing history and bookmarks. -->
+    <permission android:name="android.permission.READ_HISTORY_BOOKMARKS"
+        android:permissionGroup="android.permission-group.PERSONAL_INFO"
+        android:label="@string/permlab_readHistoryBookmarks"
+        android:description="@string/permdesc_readHistoryBookmarks"
+        android:protectionLevel="dangerous" />
+
+    <!-- Allows an application to write (but not read) the user's
+        browsing history and bookmarks. -->
+    <permission android:name="android.permission.WRITE_HISTORY_BOOKMARKS"
+        android:permissionGroup="android.permission-group.PERSONAL_INFO"
+        android:label="@string/permlab_writeHistoryBookmarks"
+        android:description="@string/permdesc_writeHistoryBookmarks"
+        android:protectionLevel="dangerous" />
+
     <!-- ======================================= -->
     <!-- Permissions for accessing location info -->
     <!-- ======================================= -->
diff --git a/core/res/res/layout/search_bar.xml b/core/res/res/layout/search_bar.xml
index 7b7f8a6..54ab6de 100644
--- a/core/res/res/layout/search_bar.xml
+++ b/core/res/res/layout/search_bar.xml
@@ -73,6 +73,7 @@
                 android:paddingRight="6dip"
                 android:drawablePadding="2dip"
                 android:singleLine="true"
+                android:ellipsize="end"
                 android:inputType="text|textAutoComplete"
                 android:dropDownWidth="fill_parent"
                 android:dropDownAnchor="@id/search_plate"
diff --git a/core/res/res/values/strings.xml b/core/res/res/values/strings.xml
index 91b6609..33d550a 100644
--- a/core/res/res/values/strings.xml
+++ b/core/res/res/values/strings.xml
@@ -1338,6 +1338,22 @@
     <!-- Title of the WebView save password dialog.  If the user enters a password in a form on a website, a dialog will come up asking if they want to save the password. -->
     <string name="save_password_label">Confirm</string>
 
+    <!-- Title of an application permission, listed so the user can choose whether
+        they want to allow the application to do this. -->
+    <string name="permlab_readHistoryBookmarks">read Browser\'s history and bookmarks</string>
+    <!-- Description of an application permission, listed so the user can choose whether
+        they want to allow the application to do this. -->
+    <string name="permdesc_readHistoryBookmarks">Allows the application to read all
+        the URLs that the Browser has visited, and all of the Browser\'s bookmarks.</string>
+    <!-- Title of an application permission, listed so the user can choose whether
+        they want to allow the application to do this. -->
+    <string name="permlab_writeHistoryBookmarks">write Browser\'s history and bookmarks</string>
+    <!-- Description of an application permission, listed so the user can choose whether
+        they want to allow the application to do this. -->
+    <string name="permdesc_writeHistoryBookmarks">Allows an application to modify the
+        Browser\'s history or bookmarks stored on your phone. Malicious applications
+        can use this to erase or modify your Browser\'s data.</string>
+
     <!-- If the user enters a password in a form on a website, a dialog will come up asking if they want to save the password. Text in the save password dialog, asking if the browser should remember a password. -->
     <string name="save_password_message">Do you want the browser to remember this password?</string>
     <!-- If the user enters a password in a form on a website, a dialog will come up asking if they want to save the password. Button in the save password dialog, saying not to remember this password. -->
diff --git a/graphics/java/android/graphics/Bitmap.java b/graphics/java/android/graphics/Bitmap.java
index fda584d..e2e93eb 100644
--- a/graphics/java/android/graphics/Bitmap.java
+++ b/graphics/java/android/graphics/Bitmap.java
@@ -16,14 +16,14 @@
 
 package android.graphics;
 
-import android.os.Parcelable;
 import android.os.Parcel;
+import android.os.Parcelable;
 
+import java.io.OutputStream;
 import java.nio.Buffer;
 import java.nio.ByteBuffer;
-import java.nio.ShortBuffer;
 import java.nio.IntBuffer;
-import java.io.OutputStream;
+import java.nio.ShortBuffer;
 
 public final class Bitmap implements Parcelable {
     /**
@@ -32,14 +32,14 @@
      * @see Bitmap#getDensityScale()
      * @see Bitmap#setDensityScale(float)
      *
-     * @hide pending API council approval 
+     * @hide pending API council approval
      */
     public static final float DENSITY_SCALE_UNKNOWN = -1.0f;
 
     // Note:  mNativeBitmap is used by FaceDetector_jni.cpp
     // Don't change/rename without updating FaceDetector_jni.cpp
     private final int mNativeBitmap;
-    
+
     private final boolean mIsMutable;
     private byte[] mNinePatchChunk;   // may be null
     private int mWidth = -1;
@@ -63,7 +63,7 @@
         if (nativeBitmap == 0) {
             throw new RuntimeException("internal error: native bitmap is 0");
         }
-        
+
         // we delete this in our finalizer
         mNativeBitmap = nativeBitmap;
         mIsMutable = isMutable;
@@ -83,7 +83,7 @@
      *
      * @see #setDensityScale(float)
      * @see #isAutoScalingEnabled()
-     * @see #setAutoScalingEnabled(boolean) 
+     * @see #setAutoScalingEnabled(boolean)
      * @see android.util.DisplayMetrics#DEFAULT_DENSITY
      * @see android.util.DisplayMetrics#density
      * @see #DENSITY_SCALE_UNKNOWN
@@ -105,7 +105,7 @@
      *
      * @see #getDensityScale()
      * @see #isAutoScalingEnabled()
-     * @see #setAutoScalingEnabled(boolean) 
+     * @see #setAutoScalingEnabled(boolean)
      * @see android.util.DisplayMetrics#DEFAULT_DENSITY
      * @see android.util.DisplayMetrics#density
      * @see #DENSITY_SCALE_UNKNOWN
@@ -126,7 +126,7 @@
      * <p>Auto scaling is turned off by default. If auto scaling is enabled but the
      * bitmap has an unknown density scale, then the bitmap will never be automatically
      * scaled at drawing time.</p>
-     * 
+     *
      * @return True if the bitmap must be scaled at drawing time, false otherwise.
      *
      * @see #setAutoScalingEnabled(boolean)
@@ -167,7 +167,7 @@
     public void setNinePatchChunk(byte[] chunk) {
         mNinePatchChunk = chunk;
     }
-    
+
     /**
      * Free up the memory associated with this bitmap's pixels, and mark the
      * bitmap as "dead", meaning it will throw an exception if getPixels() or
@@ -194,7 +194,7 @@
     public final boolean isRecycled() {
         return mRecycled;
     }
-    
+
     /**
      * This is called by methods that want to throw an exception if the bitmap
      * has already been recycled.
@@ -204,7 +204,7 @@
             throw new IllegalStateException(errorMessage);
         }
     }
-    
+
     /**
      * Common code for checking that x and y are >= 0
      *
@@ -246,16 +246,16 @@
             this.nativeInt = ni;
         }
         final int nativeInt;
-        
+
         /* package */ static Config nativeToConfig(int ni) {
             return sConfigs[ni];
         }
-        
+
         private static Config sConfigs[] = {
             null, null, ALPHA_8, null, RGB_565, ARGB_4444, ARGB_8888
         };
     }
-    
+
     /**
      * Copy the bitmap's pixels into the specified buffer (allocated by the
      * caller). An exception is thrown if the buffer is not large enough to
@@ -275,16 +275,16 @@
         } else {
             throw new RuntimeException("unsupported Buffer subclass");
         }
-        
+
         long bufferSize = (long)elements << shift;
         long pixelSize = (long)getRowBytes() * getHeight();
-        
+
         if (bufferSize < pixelSize) {
             throw new RuntimeException("Buffer not large enough for pixels");
         }
-        
+
         nativeCopyPixelsToBuffer(mNativeBitmap, dst);
-        
+
         // now update the buffer's position
         int position = dst.position();
         position += pixelSize >> shift;
@@ -299,7 +299,7 @@
      */
     public void copyPixelsFromBuffer(Buffer src) {
         checkRecycled("copyPixelsFromBuffer called on recycled bitmap");
-        
+
         int elements = src.remaining();
         int shift;
         if (src instanceof ByteBuffer) {
@@ -311,17 +311,17 @@
         } else {
             throw new RuntimeException("unsupported Buffer subclass");
         }
-        
+
         long bufferBytes = (long)elements << shift;
         long bitmapBytes = (long)getRowBytes() * getHeight();
-        
+
         if (bufferBytes < bitmapBytes) {
             throw new RuntimeException("Buffer not large enough for pixels");
         }
-        
+
         nativeCopyPixelsFromBuffer(mNativeBitmap, src);
     }
-        
+
     /**
      * Tries to make a new bitmap based on the dimensions of this bitmap,
      * setting the new bitmap's config to the one specified, and then copying
@@ -350,7 +350,7 @@
         if (m == null) {
             m = new Matrix();
         }
-        
+
         final int width = src.getWidth();
         final int height = src.getHeight();
         final float sx = dstWidth  / (float)width;
@@ -365,9 +365,9 @@
             }
         }
 
-        return b; 
+        return b;
     }
-    
+
     /**
      * Returns an immutable bitmap from the source bitmap. The new bitmap may
      * be the same object as source, or a copy may have been made.
@@ -390,7 +390,7 @@
     public static Bitmap createBitmap(Bitmap source, int x, int y, int width, int height) {
         return createBitmap(source, x, y, width, height, null, false);
     }
-    
+
     /**
      * Returns an immutable bitmap from subset of the source bitmap,
      * transformed by the optional matrix.
@@ -425,7 +425,7 @@
                 height == source.getHeight() && (m == null || m.isIdentity())) {
             return source;
         }
-        
+
         int neww = width;
         int newh = height;
         Canvas canvas = new Canvas();
@@ -470,7 +470,7 @@
 
         return bitmap;
     }
-    
+
     /**
      * Returns a mutable bitmap with the specified width and height.
      *
@@ -484,7 +484,7 @@
         bm.eraseColor(0);    // start with black/transparent pixels
         return bm;
     }
-    
+
     /**
      * Returns a immutable bitmap with the specified width and height, with each
      * pixel value set to the corresponding value in the colors array.
@@ -593,7 +593,7 @@
         return nativeCompress(mNativeBitmap, format.nativeInt, quality,
                               stream, new byte[WORKING_COMPRESS_STORAGE]);
     }
-    
+
     /**
      * Returns true if the bitmap is marked as mutable (i.e. can be drawn into)
      */
@@ -610,7 +610,7 @@
     public final int getHeight() {
         return mHeight == -1 ? mHeight = nativeHeight(mNativeBitmap) : mHeight;
     }
-    
+
     /**
      * Convenience method that returns the width of this bitmap divided
      * by the density scale factor.
@@ -648,7 +648,7 @@
     public final int getRowBytes() {
         return nativeRowBytes(mNativeBitmap);
     }
-    
+
     /**
      * If the bitmap's internal config is in one of the public formats, return
      * that config, otherwise return null.
@@ -690,7 +690,7 @@
         checkPixelAccess(x, y);
         return nativeGetPixel(mNativeBitmap, x, y);
     }
-    
+
     /**
      * Returns in pixels[] a copy of the data in the bitmap. Each value is
      * a packed int representing a {@link Color}. The stride parameter allows
@@ -722,7 +722,7 @@
         nativeGetPixels(mNativeBitmap, pixels, offset, stride,
                         x, y, width, height);
     }
-    
+
     /**
      * Shared code to check for illegal arguments passed to getPixel()
      * or setPixel()
@@ -779,7 +779,7 @@
             throw new ArrayIndexOutOfBoundsException();
         }
     }
-    
+
     /**
      * Write the specified {@link Color} into the bitmap (assuming it is
      * mutable) at the x,y coordinate.
@@ -799,10 +799,10 @@
         checkPixelAccess(x, y);
         nativeSetPixel(mNativeBitmap, x, y, color);
     }
-    
+
     /**
      * Replace pixels in the bitmap with the colors in the array. Each element
-     * in the array is a packed int prepresenting a {@link Color} 
+     * in the array is a packed int prepresenting a {@link Color}
      *
      * @param pixels   The colors to write to the bitmap
      * @param offset   The index of the first color to read from pixels[]
@@ -834,7 +834,7 @@
         nativeSetPixels(mNativeBitmap, pixels, offset, stride,
                         x, y, width, height);
     }
-    
+
     public static final Parcelable.Creator<Bitmap> CREATOR
             = new Parcelable.Creator<Bitmap>() {
         /**
@@ -884,7 +884,7 @@
     public Bitmap extractAlpha() {
         return extractAlpha(null, null);
     }
-    
+
     /**
      * Returns a new bitmap that captures the alpha values of the original.
      * These values may be affected by the optional Paint parameter, which
@@ -917,6 +917,22 @@
         return bm;
     }
 
+    /**
+     * Rebuilds any caches associated with the bitmap that are used for
+     * drawing it. In the case of purgeable bitmaps, this call will attempt to
+     * ensure that the pixels have been decoded.
+     * If this is called on more than one bitmap in sequence, the priority is
+     * given in LRU order (i.e. the last bitmap called will be given highest
+     * priority).
+     *
+     * For bitmaps with no associated caches, this call is effectively a no-op,
+     * and therefore is harmless.
+     */
+    public void prepareToDraw() {
+        nativePrepareToDraw(mNativeBitmap);
+    }
+
+    @Override
     protected void finalize() throws Throwable {
         try {
             nativeDestructor(mNativeBitmap);
@@ -924,7 +940,7 @@
             super.finalize();
         }
     }
-    
+
     //////////// native methods
 
     private static native Bitmap nativeCreate(int[] colors, int offset,
@@ -944,12 +960,12 @@
     private static native int nativeRowBytes(int nativeBitmap);
     private static native int nativeConfig(int nativeBitmap);
     private static native boolean nativeHasAlpha(int nativeBitmap);
-    
+
     private static native int nativeGetPixel(int nativeBitmap, int x, int y);
     private static native void nativeGetPixels(int nativeBitmap, int[] pixels,
                                                int offset, int stride, int x,
                                                int y, int width, int height);
-    
+
     private static native void nativeSetPixel(int nativeBitmap, int x, int y,
                                               int color);
     private static native void nativeSetPixels(int nativeBitmap, int[] colors,
@@ -969,6 +985,8 @@
                                                     int nativePaint,
                                                     int[] offsetXY);
 
+    private static native void nativePrepareToDraw(int nativeBitmap);
+
     /* package */ final int ni() {
         return mNativeBitmap;
     }
diff --git a/services/java/com/android/server/PackageManagerService.java b/services/java/com/android/server/PackageManagerService.java
index 4b583e4..d2e5555 100644
--- a/services/java/com/android/server/PackageManagerService.java
+++ b/services/java/com/android/server/PackageManagerService.java
@@ -5937,7 +5937,7 @@
                     continue;
                 }
                 for (PackageSetting pkg:sus.packages) {
-                    if (pkg.grantedPermissions.contains (eachPerm)) {
+                    if (pkg.pkg.requestedPermissions.contains(eachPerm)) {
                         used = true;
                         break;
                     }
diff --git a/telephony/java/com/android/internal/telephony/RIL.java b/telephony/java/com/android/internal/telephony/RIL.java
index c6b7601..9f780c9 100644
--- a/telephony/java/com/android/internal/telephony/RIL.java
+++ b/telephony/java/com/android/internal/telephony/RIL.java
@@ -2067,13 +2067,13 @@
  | sed -re 's/\{([^,]+),[^,]+,([^}]+).+/case \1: ret = \2(p); break;/'
              */
             case RIL_REQUEST_GET_SIM_STATUS: ret =  responseIccCardStatus(p); break;
-            case RIL_REQUEST_ENTER_SIM_PIN: ret =  responseVoid(p); break;
-            case RIL_REQUEST_ENTER_SIM_PUK: ret =  responseVoid(p); break;
-            case RIL_REQUEST_ENTER_SIM_PIN2: ret =  responseVoid(p); break;
-            case RIL_REQUEST_ENTER_SIM_PUK2: ret =  responseVoid(p); break;
-            case RIL_REQUEST_CHANGE_SIM_PIN: ret =  responseVoid(p); break;
-            case RIL_REQUEST_CHANGE_SIM_PIN2: ret =  responseVoid(p); break;
-            case RIL_REQUEST_ENTER_NETWORK_DEPERSONALIZATION: ret =  responseVoid(p); break;
+            case RIL_REQUEST_ENTER_SIM_PIN: ret =  responseInts(p); break;
+            case RIL_REQUEST_ENTER_SIM_PUK: ret =  responseInts(p); break;
+            case RIL_REQUEST_ENTER_SIM_PIN2: ret =  responseInts(p); break;
+            case RIL_REQUEST_ENTER_SIM_PUK2: ret =  responseInts(p); break;
+            case RIL_REQUEST_CHANGE_SIM_PIN: ret =  responseInts(p); break;
+            case RIL_REQUEST_CHANGE_SIM_PIN2: ret =  responseInts(p); break;
+            case RIL_REQUEST_ENTER_NETWORK_DEPERSONALIZATION: ret =  responseInts(p); break;
             case RIL_REQUEST_GET_CURRENT_CALLS: ret =  responseCallList(p); break;
             case RIL_REQUEST_DIAL: ret =  responseVoid(p); break;
             case RIL_REQUEST_GET_IMSI: ret =  responseString(p); break;
@@ -2108,7 +2108,7 @@
             case RIL_REQUEST_ANSWER: ret =  responseVoid(p); break;
             case RIL_REQUEST_DEACTIVATE_DATA_CALL: ret =  responseVoid(p); break;
             case RIL_REQUEST_QUERY_FACILITY_LOCK: ret =  responseInts(p); break;
-            case RIL_REQUEST_SET_FACILITY_LOCK: ret =  responseVoid(p); break;
+            case RIL_REQUEST_SET_FACILITY_LOCK: ret =  responseInts(p); break;
             case RIL_REQUEST_CHANGE_BARRING_PASSWORD: ret =  responseVoid(p); break;
             case RIL_REQUEST_QUERY_NETWORK_SELECTION_MODE: ret =  responseInts(p); break;
             case RIL_REQUEST_SET_NETWORK_SELECTION_AUTOMATIC: ret =  responseVoid(p); break;
diff --git a/tests/AndroidTests/src/com/android/unit_tests/SearchManagerTest.java b/tests/AndroidTests/src/com/android/unit_tests/SearchManagerTest.java
index f03a779..c4f1ab6 100644
--- a/tests/AndroidTests/src/com/android/unit_tests/SearchManagerTest.java
+++ b/tests/AndroidTests/src/com/android/unit_tests/SearchManagerTest.java
@@ -126,26 +126,6 @@
     }
     
     /**
-     * The goal of this test is to confirm that we can *only* obtain a search manager
-     * interface from an Activity context.
-     */
-    @MediumTest
-    public void testSearchManagerContextRestrictions() {
-        SearchManager searchManager1 = (SearchManager)
-                mContext.getSystemService(Context.SEARCH_SERVICE);
-        assertNotNull(searchManager1);
-        
-        Context applicationContext = mContext.getApplicationContext();
-        // this should fail, because you can't get a SearchManager from a non-Activity context
-        try {
-            applicationContext.getSystemService(Context.SEARCH_SERVICE);
-            assertFalse("Shouldn't retrieve SearchManager from a non-Activity context", true);
-        } catch (AndroidRuntimeException e) {
-            // happy here - we should catch this.
-        }
-    }
-    
-    /**
      * The goal of this test is to confirm that we can obtain
      * a search manager at any time, and that for any given context,
      * it is a singleton.
@@ -163,17 +143,19 @@
 
     @MediumTest
     public void testSearchables() {
+        SearchManager searchManager = (SearchManager)
+                mContext.getSystemService(Context.SEARCH_SERVICE);
         SearchableInfo si;
 
-        si = SearchManager.getSearchableInfo(SEARCHABLE_ACTIVITY, false);
+        si = searchManager.getSearchableInfo(SEARCHABLE_ACTIVITY, false);
         assertNotNull(si);
-        assertFalse(SearchManager.isDefaultSearchable(si));
-        si = SearchManager.getSearchableInfo(SEARCHABLE_ACTIVITY, true);
+        assertFalse(searchManager.isDefaultSearchable(si));
+        si = searchManager.getSearchableInfo(SEARCHABLE_ACTIVITY, true);
         assertNotNull(si);
-        assertTrue(SearchManager.isDefaultSearchable(si));
-        si = SearchManager.getSearchableInfo(null, true);
+        assertTrue(searchManager.isDefaultSearchable(si));
+        si = searchManager.getSearchableInfo(null, true);
         assertNotNull(si);
-        assertTrue(SearchManager.isDefaultSearchable(si));
+        assertTrue(searchManager.isDefaultSearchable(si));
     }
 
     /**