Merge change 20144 into donut

* changes:
  Remove flaky MonitorTest#testInterrupt from continuous, and attempt to make AutoCompletePopup tests more reliable.
diff --git a/core/java/android/app/SearchDialog.java b/core/java/android/app/SearchDialog.java
index 18e4a528..70aceeb 100644
--- a/core/java/android/app/SearchDialog.java
+++ b/core/java/android/app/SearchDialog.java
@@ -693,39 +693,6 @@
         return mLaunchComponent.flattenToShortString().startsWith("com.android.browser/");
     }
 
-    /*
-     * Menu.
-     */
-
-    @Override
-    public boolean onCreateOptionsMenu(Menu menu) {
-        // Show search settings menu item if anyone handles the intent for it
-        Intent settingsIntent = new Intent(SearchManager.INTENT_ACTION_SEARCH_SETTINGS);
-        settingsIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
-        PackageManager pm = getContext().getPackageManager();
-        ActivityInfo activityInfo = settingsIntent.resolveActivityInfo(pm, 0);
-        if (activityInfo != null) {
-            settingsIntent.setClassName(activityInfo.applicationInfo.packageName,
-                    activityInfo.name);
-            CharSequence label = activityInfo.loadLabel(getContext().getPackageManager());
-            menu.add(Menu.NONE, Menu.NONE, Menu.NONE, label)
-                    .setIcon(android.R.drawable.ic_menu_preferences)
-                    .setAlphabeticShortcut('P')
-                    .setIntent(settingsIntent);
-            return true;
-        }
-        return super.onCreateOptionsMenu(menu);
-    }
-
-    @Override
-    public boolean onMenuOpened(int featureId, Menu menu) {
-        // The menu shows up above the IME, regardless of whether it is in front
-        // of the drop-down or not. This looks weird when there is no IME, so
-        // we make sure it is visible.
-        mSearchAutoComplete.ensureImeVisible();
-        return super.onMenuOpened(featureId, menu);
-    }
-
     /**
      * Listeners of various types
      */
@@ -899,16 +866,15 @@
                 return;
             }
             try {
+                // First stop the existing search before starting voice search, or else we'll end
+                // up showing the search dialog again once we return to the app.
+                ((SearchManager) getContext().getSystemService(Context.SEARCH_SERVICE)).
+                        stopSearch();
+                
                 if (mSearchable.getVoiceSearchLaunchWebSearch()) {
                     getContext().startActivity(mVoiceWebSearchIntent);
                 } else if (mSearchable.getVoiceSearchLaunchRecognizer()) {
-                    Intent appSearchIntent = createVoiceAppSearchIntent(mVoiceAppSearchIntent);
-                    
-                    // Stop the existing search before starting voice search, or else we'll end
-                    // up showing the search dialog again once we return to the app.
-                    ((SearchManager) getContext().getSystemService(Context.SEARCH_SERVICE)).
-                            stopSearch();
-                    
+                    Intent appSearchIntent = createVoiceAppSearchIntent(mVoiceAppSearchIntent);                    
                     getContext().startActivity(appSearchIntent);
                 }
             } catch (ActivityNotFoundException e) {
diff --git a/core/java/android/app/SuggestionsAdapter.java b/core/java/android/app/SuggestionsAdapter.java
index 4a00e48..bd4e66e 100644
--- a/core/java/android/app/SuggestionsAdapter.java
+++ b/core/java/android/app/SuggestionsAdapter.java
@@ -658,7 +658,14 @@
         if (col == NONE) {
             return null;
         }
-        return cursor.getString(col);
+        try {
+            return cursor.getString(col);
+        } catch (Exception e) {
+            Log.e(LOG_TAG,
+                    "unexpected error retrieving valid column from cursor, "
+                            + "did the remote process die?", e);
+            return null;
+        }
     }
 
 }
diff --git a/core/java/android/provider/Checkin.java b/core/java/android/provider/Checkin.java
index f2c275e..6b491ab 100644
--- a/core/java/android/provider/Checkin.java
+++ b/core/java/android/provider/Checkin.java
@@ -109,6 +109,11 @@
             SYSTEM_TOMBSTONE,
             TEST, 
             BATTERY_DISCHARGE_INFO,
+            MARKET_DOWNLOAD,
+            MARKET_INSTALL,
+            MARKET_REMOVE,
+            MARKET_REFUND,
+            MARKET_UNINSTALL,
         }
     }
 
@@ -147,43 +152,6 @@
             TEST,
             NETWORK_RX_MOBILE,
             NETWORK_TX_MOBILE,
-            MARKET_DOWNLOAD_REQUESTED,
-            MARKET_DOWNLOAD_SCHEDULED,
-            MARKET_DOWNLOAD_CANCELLED_PENDING,
-            MARKET_DOWNLOAD_CANCELLED,
-            MARKET_DOWNLOAD_OK,
-            MARKET_DOWNLOAD_FAILED,
-            MARKET_DOWNLOAD_DECLINED,
-            MARKET_INSTALL_SCHEDULED,
-            MARKET_INSTALL_FAILED,
-            MARKET_INSTALL_OK,
-            MARKET_REMOVE_SCHEDULED,
-            MARKET_REMOVE_MALICIOUS_SCHEDULED,
-            MARKET_REMOVE_ABORTED,
-            MARKET_REMOVE_FAILED,
-            MARKET_REMOVE_OK,
-            MARKET_UNINSTALL_SCHEDULED,
-            MARKET_REFUND_REQUESTED,
-            MARKET_REFUND_OK,
-            MARKET_REFUND_FAILED,
-            MARKET_REASON_ALREADY_EXISTS,
-            MARKET_REASON_INVALID_APK,
-            MARKET_REASON_INSUFFICIENT_STORAGE,
-            MARKET_REASON_DUPLICATE_PACKAGE,
-            MARKET_REASON_UPDATE_INCOMPATIBLE,
-            MARKET_REASON_MISSING_SHARED_LIBRARY,
-            MARKET_REASON_REPLACE_COULDNT_DELETE,
-            MARKET_REASON_PARSE_NOT_APK,
-            MARKET_REASON_PARSE_BAD_MANIFEST,
-            MARKET_REASON_PARSE_NO_CERTIFICATES,
-            MARKET_REASON_PARSE_INCONSISTENT_CERTIFICATES,
-            MARKET_REASON_PARSE_CERTIFICATE_ENCODING,
-            MARKET_REASON_PARSE_BAD_PACKAGE_NAME,
-            MARKET_REASON_PARSE_BAD_SHARED_USER_ID,
-            MARKET_REASON_PARSE_MANIFEST_MALFORMED,
-            MARKET_REASON_PARSE_MANIFEST_EMPTY,
-            MARKET_REASON_UNKNOWN,
-            MARKET_STALE_INSTALL_ATTEMPT,
             PHONE_CDMA_REGISTERED,
             PHONE_CDMA_DATA_ATTEMPTED,
             PHONE_CDMA_DATA_CONNECTED,
diff --git a/core/java/com/android/internal/widget/LockPatternView.java b/core/java/com/android/internal/widget/LockPatternView.java
index 53be891..cfcf111 100644
--- a/core/java/com/android/internal/widget/LockPatternView.java
+++ b/core/java/com/android/internal/widget/LockPatternView.java
@@ -581,14 +581,14 @@
                     mInProgressX = x;
                     mInProgressY = y;
 
-                    if (mPatternInProgress) {
+                    if (mPatternInProgress && patternSize > 0) {
                         final ArrayList<Cell> pattern = mPattern;
                         final float radius = mSquareWidth * mDiameterFactor * 0.5f;
 
-                        Cell cell = pattern.get(patternSize - 1);
+                        final Cell lastCell = pattern.get(patternSize - 1);
 
-                        float startX = getCenterXForColumn(cell.column);
-                        float startY = getCenterYForRow(cell.row);
+                        float startX = getCenterXForColumn(lastCell.column);
+                        float startY = getCenterYForRow(lastCell.row);
 
                         float left;
                         float top;
diff --git a/media/tests/MediaFrameworkTest/src/com/android/mediaframeworktest/performance/MediaPlayerPerformance.java b/media/tests/MediaFrameworkTest/src/com/android/mediaframeworktest/performance/MediaPlayerPerformance.java
index 84058f5..bd4c88e 100644
--- a/media/tests/MediaFrameworkTest/src/com/android/mediaframeworktest/performance/MediaPlayerPerformance.java
+++ b/media/tests/MediaFrameworkTest/src/com/android/mediaframeworktest/performance/MediaPlayerPerformance.java
@@ -336,7 +336,6 @@
         File h263MemoryOut = new File(MEDIA_MEMORY_OUTPUT);
         Writer output = new BufferedWriter(new FileWriter(h263MemoryOut, true));
         output.write("H263 Video Playback Only\n");
-        getMemoryWriteToLog(output);
         for (int i = 0; i < NUM_STRESS_LOOP; i++) {
             mediaStressPlayback(MediaNames.VIDEO_HIGHRES_H263);
             getMemoryWriteToLog(output);
@@ -357,7 +356,6 @@
         File h264MemoryOut = new File(MEDIA_MEMORY_OUTPUT);
         Writer output = new BufferedWriter(new FileWriter(h264MemoryOut, true));
         output.write("H264 Video Playback only\n");
-        getMemoryWriteToLog(output);
         for (int i = 0; i < NUM_STRESS_LOOP; i++) {
             mediaStressPlayback(MediaNames.VIDEO_H264_AMR);
             getMemoryWriteToLog(output);
@@ -378,7 +376,6 @@
         File wmvMemoryOut = new File(MEDIA_MEMORY_OUTPUT);
         Writer output = new BufferedWriter(new FileWriter(wmvMemoryOut, true));
         output.write("WMV video playback only\n");
-        getMemoryWriteToLog(output);
         for (int i = 0; i < NUM_STRESS_LOOP; i++) {
             mediaStressPlayback(MediaNames.VIDEO_WMV);
             getMemoryWriteToLog(output);
@@ -399,7 +396,6 @@
         File videoH263RecordOnlyMemoryOut = new File(MEDIA_MEMORY_OUTPUT);
         Writer output = new BufferedWriter(new FileWriter(videoH263RecordOnlyMemoryOut, true));
         output.write("H263 video record only\n");
-        getMemoryWriteToLog(output);
         for (int i = 0; i < NUM_STRESS_LOOP; i++) {
             stressVideoRecord(20, 352, 288, MediaRecorder.VideoEncoder.H263,
                     MediaRecorder.OutputFormat.MPEG_4, MediaNames.RECORDED_VIDEO_3GP, true);
@@ -421,7 +417,6 @@
         File videoMp4RecordOnlyMemoryOut = new File(MEDIA_MEMORY_OUTPUT);
         Writer output = new BufferedWriter(new FileWriter(videoMp4RecordOnlyMemoryOut, true));
         output.write("MPEG4 video record only\n");
-        getMemoryWriteToLog(output);
         for (int i = 0; i < NUM_STRESS_LOOP; i++) {
             stressVideoRecord(20, 352, 288, MediaRecorder.VideoEncoder.MPEG_4_SP,
                     MediaRecorder.OutputFormat.MPEG_4, MediaNames.RECORDED_VIDEO_3GP, true);
@@ -444,7 +439,6 @@
         File videoRecordAudioMemoryOut = new File(MEDIA_MEMORY_OUTPUT);
         Writer output = new BufferedWriter(new FileWriter(videoRecordAudioMemoryOut, true));
         output.write("Audio and h263 video record\n");
-        getMemoryWriteToLog(output);
         for (int i = 0; i < NUM_STRESS_LOOP; i++) {
             stressVideoRecord(20, 352, 288, MediaRecorder.VideoEncoder.H263,
                     MediaRecorder.OutputFormat.MPEG_4, MediaNames.RECORDED_VIDEO_3GP, false);
@@ -466,7 +460,6 @@
         File audioOnlyMemoryOut = new File(MEDIA_MEMORY_OUTPUT);
         Writer output = new BufferedWriter(new FileWriter(audioOnlyMemoryOut, true));
         output.write("Audio record only\n");
-        getMemoryWriteToLog(output);
         for (int i = 0; i < NUM_STRESS_LOOP; i++) {
             stressAudioRecord(MediaNames.RECORDER_OUTPUT);
             getMemoryWriteToLog(output);
diff --git a/services/java/com/android/server/PackageManagerService.java b/services/java/com/android/server/PackageManagerService.java
index bd79d1d..89f854e 100644
--- a/services/java/com/android/server/PackageManagerService.java
+++ b/services/java/com/android/server/PackageManagerService.java
@@ -2884,7 +2884,7 @@
         if (gp.gids == null) {
             gp.gids = mGlobalGids;
         }
-        
+       
         final int N = pkg.requestedPermissions.size();
         for (int i=0; i<N; i++) {
             String name = pkg.requestedPermissions.get(i);
@@ -3755,7 +3755,7 @@
             }
         }
     }
-    
+   
     private void updateSettingsLI(String pkgName, File tmpPackageFile, 
             String destFilePath, File destPackageFile,
             File destResourceFile, 
@@ -4220,7 +4220,7 @@
         synchronized (mPackages) {
             if ( (deletedPs != null) && (deletedPs.sharedUser != null)) {
                 // remove permissions associated with package
-                mSettings.updateSharedUserPerms (deletedPs);
+                mSettings.updateSharedUserPermsLP(deletedPs, mGlobalGids);
             }
             // Save settings now
             mSettings.writeLP ();
@@ -6008,7 +6008,15 @@
             }
         }
 
-        private void updateSharedUserPerms (PackageSetting deletedPs) {
+        /*
+         * Update the shared user setting when a package using
+         * specifying the shared user id is removed. The gids
+         * associated with each permission of the deleted package
+         * are removed from the shared user's gid list only if its
+         * not in use by other permissions of packages in the
+         * shared user setting.
+         */
+        private void updateSharedUserPermsLP(PackageSetting deletedPs, int[] globalGids) {
             if ( (deletedPs == null) || (deletedPs.pkg == null)) {
                 Log.i(TAG, "Trying to update info for null package. Just ignoring");
                 return;
@@ -6037,13 +6045,14 @@
                 }
             }
             // Update gids
-            int newGids[] = null;
-            for (PackageSetting pkg:sus.packages) {
-                newGids = appendInts(newGids, pkg.gids);
+            int newGids[] = globalGids;
+            for (String eachPerm : sus.grantedPermissions) {
+                BasePermission bp = mPermissions.get(eachPerm);
+                newGids = appendInts(newGids, bp.gids);
             }
             sus.gids = newGids;
         }
-        
+
         private int removePackageLP(String name) {
             PackageSetting p = mPackages.get(name);
             if (p != null) {
diff --git a/services/java/com/android/server/WindowManagerService.java b/services/java/com/android/server/WindowManagerService.java
index 5a02c4d..d4c27b7 100644
--- a/services/java/com/android/server/WindowManagerService.java
+++ b/services/java/com/android/server/WindowManagerService.java
@@ -533,6 +533,17 @@
         mTransitionAnimationScale = Settings.System.getFloat(context.getContentResolver(),
                 Settings.System.TRANSITION_ANIMATION_SCALE, mTransitionAnimationScale);
 
+        int max_events_per_sec = 35;
+        try {
+            max_events_per_sec = Integer.parseInt(SystemProperties
+                    .get("windowsmgr.max_events_per_sec"));
+            if (max_events_per_sec < 1) {
+                max_events_per_sec = 35;
+            }
+        } catch (NumberFormatException e) {
+        }
+        mMinWaitTimeBetweenTouchEvents = 1000 / max_events_per_sec;
+
         mQueue = new KeyQ();
 
         mInputThread = new InputDispatcherThread();
@@ -3989,8 +4000,8 @@
             }
         } //end if target
 
-        // TODO remove once we settle on a value or make it app specific
-        if (action == MotionEvent.ACTION_DOWN) {
+        // Enable this for testing the "right" value
+        if (false && action == MotionEvent.ACTION_DOWN) {
             int max_events_per_sec = 35;
             try {
                 max_events_per_sec = Integer.parseInt(SystemProperties
diff --git a/tests/DumpRenderTree/src/com/android/dumprendertree/ReliabilityTestActivity.java b/tests/DumpRenderTree/src/com/android/dumprendertree/ReliabilityTestActivity.java
index db40daf..995c129 100644
--- a/tests/DumpRenderTree/src/com/android/dumprendertree/ReliabilityTestActivity.java
+++ b/tests/DumpRenderTree/src/com/android/dumprendertree/ReliabilityTestActivity.java
@@ -124,6 +124,7 @@
     protected void onDestroy() {
         super.onDestroy();
         Log.v(LOGTAG, "onDestroy, inst=" + Integer.toHexString(hashCode()));
+        webView.clearCache(true);
         webView.destroy();
     }