Merge "Import translations. DO NOT MERGE"
diff --git a/api/current.txt b/api/current.txt
index e4d5fd1..72e7601 100644
--- a/api/current.txt
+++ b/api/current.txt
@@ -13785,12 +13785,18 @@
     method public void setNdefPushMessage(android.nfc.NdefMessage, android.app.Activity, android.app.Activity...);
     method public void setNdefPushMessageCallback(android.nfc.NfcAdapter.CreateNdefMessageCallback, android.app.Activity, android.app.Activity...);
     method public void setOnNdefPushCompleteCallback(android.nfc.NfcAdapter.OnNdefPushCompleteCallback, android.app.Activity, android.app.Activity...);
+    field public static final java.lang.String ACTION_ADAPTER_STATE_CHANGED = "android.nfc.action.ADAPTER_STATE_CHANGED";
     field public static final java.lang.String ACTION_NDEF_DISCOVERED = "android.nfc.action.NDEF_DISCOVERED";
     field public static final java.lang.String ACTION_TAG_DISCOVERED = "android.nfc.action.TAG_DISCOVERED";
     field public static final java.lang.String ACTION_TECH_DISCOVERED = "android.nfc.action.TECH_DISCOVERED";
+    field public static final java.lang.String EXTRA_ADAPTER_STATE = "android.nfc.extra.ADAPTER_STATE";
     field public static final java.lang.String EXTRA_ID = "android.nfc.extra.ID";
     field public static final java.lang.String EXTRA_NDEF_MESSAGES = "android.nfc.extra.NDEF_MESSAGES";
     field public static final java.lang.String EXTRA_TAG = "android.nfc.extra.TAG";
+    field public static final int STATE_OFF = 1; // 0x1
+    field public static final int STATE_ON = 3; // 0x3
+    field public static final int STATE_TURNING_OFF = 4; // 0x4
+    field public static final int STATE_TURNING_ON = 2; // 0x2
   }
 
   public static abstract interface NfcAdapter.CreateBeamUrisCallback {
diff --git a/core/java/android/nfc/NfcAdapter.java b/core/java/android/nfc/NfcAdapter.java
index 4baceed..6ad382b 100644
--- a/core/java/android/nfc/NfcAdapter.java
+++ b/core/java/android/nfc/NfcAdapter.java
@@ -174,31 +174,25 @@
      * Broadcast Action: The state of the local NFC adapter has been
      * changed.
      * <p>For example, NFC has been turned on or off.
-     * <p>Always contains the extra field {@link #EXTRA_STATE}
-     * @hide
+     * <p>Always contains the extra field {@link #EXTRA_ADAPTER_STATE}
      */
     @SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION)
     public static final String ACTION_ADAPTER_STATE_CHANGED =
             "android.nfc.action.ADAPTER_STATE_CHANGED";
 
     /**
-     * Used as an int extra field in {@link #ACTION_STATE_CHANGED}
+     * Used as an int extra field in {@link #ACTION_ADAPTER_STATE_CHANGED}
      * intents to request the current power state. Possible values are:
      * {@link #STATE_OFF},
      * {@link #STATE_TURNING_ON},
      * {@link #STATE_ON},
      * {@link #STATE_TURNING_OFF},
-     * @hide
      */
     public static final String EXTRA_ADAPTER_STATE = "android.nfc.extra.ADAPTER_STATE";
 
-    /** @hide */
     public static final int STATE_OFF = 1;
-    /** @hide */
     public static final int STATE_TURNING_ON = 2;
-    /** @hide */
     public static final int STATE_ON = 3;
-    /** @hide */
     public static final int STATE_TURNING_OFF = 4;
 
     /** @hide */
diff --git a/core/java/android/text/DynamicLayout.java b/core/java/android/text/DynamicLayout.java
index d909362..122f8a1 100644
--- a/core/java/android/text/DynamicLayout.java
+++ b/core/java/android/text/DynamicLayout.java
@@ -503,8 +503,15 @@
 
         mNumberOfBlocks = newNumberOfBlocks;
         final int deltaLines = newLineCount - (endLine - startLine + 1);
-        for (int i = firstBlock + numAddedBlocks; i < mNumberOfBlocks; i++) {
-            mBlockEndLines[i] += deltaLines;
+        if (deltaLines != 0) {
+            // Display list whose index is >= mIndexFirstChangedBlock is valid
+            // but it needs to update its drawing location.
+            mIndexFirstChangedBlock = firstBlock + numAddedBlocks;
+            for (int i = mIndexFirstChangedBlock; i < mNumberOfBlocks; i++) {
+                mBlockEndLines[i] += deltaLines;
+            }
+        } else {
+            mIndexFirstChangedBlock = mNumberOfBlocks;
         }
 
         int blockIndex = firstBlock;
@@ -559,6 +566,20 @@
         return mNumberOfBlocks;
     }
 
+    /**
+     * @hide
+     */
+    public int getIndexFirstChangedBlock() {
+        return mIndexFirstChangedBlock;
+    }
+
+    /**
+     * @hide
+     */
+    public void setIndexFirstChangedBlock(int i) {
+        mIndexFirstChangedBlock = i;
+    }
+
     @Override
     public int getLineCount() {
         return mInts.size() - 1;
@@ -697,6 +718,8 @@
     private int[] mBlockIndices;
     // Number of items actually currently being used in the above 2 arrays
     private int mNumberOfBlocks;
+    // The first index of the blocks whose locations are changed
+    private int mIndexFirstChangedBlock;
 
     private int mTopPadding, mBottomPadding;
 
diff --git a/core/java/android/widget/Editor.java b/core/java/android/widget/Editor.java
index 41d6033..4eaa78a 100644
--- a/core/java/android/widget/Editor.java
+++ b/core/java/android/widget/Editor.java
@@ -124,7 +124,6 @@
     InputMethodState mInputMethodState;
 
     DisplayList[] mTextDisplayLists;
-    int mLastLayoutHeight;
 
     boolean mFrozenWithFocus;
     boolean mSelectionMoved;
@@ -1289,20 +1288,11 @@
                 mTextDisplayLists = new DisplayList[ArrayUtils.idealObjectArraySize(0)];
             }
 
-            // If the height of the layout changes (usually when inserting or deleting a line,
-            // but could be changes within a span), invalidate everything. We could optimize
-            // more aggressively (for example, adding offsets to blocks) but it would be more
-            // complex and we would only get the benefit in some cases.
-            int layoutHeight = layout.getHeight();
-            if (mLastLayoutHeight != layoutHeight) {
-                invalidateTextDisplayList();
-                mLastLayoutHeight = layoutHeight;
-            }
-
             DynamicLayout dynamicLayout = (DynamicLayout) layout;
             int[] blockEndLines = dynamicLayout.getBlockEndLines();
             int[] blockIndices = dynamicLayout.getBlockIndices();
             final int numberOfBlocks = dynamicLayout.getNumberOfBlocks();
+            final int indexFirstChangedBlock = dynamicLayout.getIndexFirstChangedBlock();
 
             int endOfPreviousBlock = -1;
             int searchStartIndex = 0;
@@ -1327,7 +1317,8 @@
                     if (blockIsInvalid) blockDisplayList.invalidate();
                 }
 
-                if (!blockDisplayList.isValid()) {
+                final boolean blockDisplayListIsInvalid = !blockDisplayList.isValid();
+                if (i >= indexFirstChangedBlock || blockDisplayListIsInvalid) {
                     final int blockBeginLine = endOfPreviousBlock + 1;
                     final int top = layout.getLineTop(blockBeginLine);
                     final int bottom = layout.getLineBottom(blockEndLine);
@@ -1344,24 +1335,30 @@
                         right = (int) (max + 0.5f);
                     }
 
-                    final HardwareCanvas hardwareCanvas = blockDisplayList.start();
-                    try {
-                        // Tighten the bounds of the viewport to the actual text size
-                        hardwareCanvas.setViewport(right - left, bottom - top);
-                        // The dirty rect should always be null for a display list
-                        hardwareCanvas.onPreDraw(null);
-                        // drawText is always relative to TextView's origin, this translation brings
-                        // this range of text back to the top left corner of the viewport
-                        hardwareCanvas.translate(-left, -top);
-                        layout.drawText(hardwareCanvas, blockBeginLine, blockEndLine);
-                        // No need to untranslate, previous context is popped after drawDisplayList
-                    } finally {
-                        hardwareCanvas.onPostDraw();
-                        blockDisplayList.end();
-                        blockDisplayList.setLeftTopRightBottom(left, top, right, bottom);
-                        // Same as drawDisplayList below, handled by our TextView's parent
-                        blockDisplayList.setClipChildren(false);
+                    // Rebuild display list if it is invalid
+                    if (blockDisplayListIsInvalid) {
+                        final HardwareCanvas hardwareCanvas = blockDisplayList.start();
+                        try {
+                            // Tighten the bounds of the viewport to the actual text size
+                            hardwareCanvas.setViewport(right - left, bottom - top);
+                            // The dirty rect should always be null for a display list
+                            hardwareCanvas.onPreDraw(null);
+                            // drawText is always relative to TextView's origin, this translation brings
+                            // this range of text back to the top left corner of the viewport
+                            hardwareCanvas.translate(-left, -top);
+                            layout.drawText(hardwareCanvas, blockBeginLine, blockEndLine);
+                            // No need to untranslate, previous context is popped after drawDisplayList
+                        } finally {
+                            hardwareCanvas.onPostDraw();
+                            blockDisplayList.end();
+                            // Same as drawDisplayList below, handled by our TextView's parent
+                            blockDisplayList.setClipChildren(false);
+                        }
                     }
+
+                    // Valid disply list whose index is >= indexFirstChangedBlock
+                    // only needs to update its drawing location.
+                    blockDisplayList.setLeftTopRightBottom(left, top, right, bottom);
                 }
 
                 ((HardwareCanvas) canvas).drawDisplayList(blockDisplayList, null,
@@ -1369,6 +1366,8 @@
 
                 endOfPreviousBlock = blockEndLine;
             }
+
+            dynamicLayout.setIndexFirstChangedBlock(numberOfBlocks);
         } else {
             // Boring layout is used for empty and hint text
             layout.drawText(canvas, firstLine, lastLine);
diff --git a/core/java/android/widget/ImageView.java b/core/java/android/widget/ImageView.java
index b40260c..8c710ce 100644
--- a/core/java/android/widget/ImageView.java
+++ b/core/java/android/widget/ImageView.java
@@ -567,7 +567,10 @@
         applied to the drawable, be sure to call setImageMatrix().
     */
     public Matrix getImageMatrix() {
-        return mMatrix;
+        if (mDrawMatrix == null) {
+            return Matrix.IDENTITY_MATRIX;
+        }
+        return mDrawMatrix;
     }
 
     public void setImageMatrix(Matrix matrix) {
diff --git a/core/java/android/widget/TextView.java b/core/java/android/widget/TextView.java
index d635de6..f8db622 100644
--- a/core/java/android/widget/TextView.java
+++ b/core/java/android/widget/TextView.java
@@ -6459,7 +6459,6 @@
             mDeferScroll = -1;
             bringPointIntoView(Math.min(curs, mText.length()));
         }
-        if (changed && mEditor != null) mEditor.invalidateTextDisplayList();
     }
 
     private boolean isShowingHint() {
diff --git a/media/java/android/media/MediaScanner.java b/media/java/android/media/MediaScanner.java
index fbbcb0a..7768a61 100644
--- a/media/java/android/media/MediaScanner.java
+++ b/media/java/android/media/MediaScanner.java
@@ -958,7 +958,9 @@
                 // If the rowId of the inserted file is needed, it gets inserted immediately,
                 // bypassing the bulk inserter.
                 if (inserter == null || needToSetSettings) {
-                    inserter.flushAll();
+                    if (inserter != null) {
+                        inserter.flushAll();
+                    }
                     result = mMediaProvider.insert(tableUri, values);
                 } else if (entry.mFormat == MtpConstants.FORMAT_ASSOCIATION) {
                     inserter.insertwithPriority(tableUri, values);
diff --git a/media/tests/MediaFrameworkTest/src/com/android/mediaframeworktest/MediaRecorderStressTestRunner.java b/media/tests/MediaFrameworkTest/src/com/android/mediaframeworktest/MediaRecorderStressTestRunner.java
index 95e7b5e..5c74552 100644
--- a/media/tests/MediaFrameworkTest/src/com/android/mediaframeworktest/MediaRecorderStressTestRunner.java
+++ b/media/tests/MediaFrameworkTest/src/com/android/mediaframeworktest/MediaRecorderStressTestRunner.java
@@ -33,18 +33,16 @@
     // the test must be supported by the corresponding camera.
     public static int mCameraId = 0;
     public static int mProfileQuality = CamcorderProfile.QUALITY_HIGH;
-    public static CamcorderProfile profile =
-                        CamcorderProfile.get(mCameraId, mProfileQuality);
-
-    public static int mIterations = 100;
+    public static CamcorderProfile profile = CamcorderProfile.get(mCameraId, mProfileQuality);
+    public static int mIterations = 15;
     public static int mVideoEncoder = profile.videoCodec;
-    public static int mAudioEncdoer = profile.audioCodec;
+    public static int mAudioEncoder = profile.audioCodec;
     public static int mFrameRate = profile.videoFrameRate;
     public static int mVideoWidth = profile.videoFrameWidth;
     public static int mVideoHeight = profile.videoFrameHeight;
     public static int mBitRate = profile.videoBitRate;
     public static boolean mRemoveVideo = true;
-    public static int mDuration = 10 * 1000; // 10 seconds
+    public static int mDuration = 60 * 1000; // 60 seconds
     public static int mTimeLapseDuration = 180 * 1000; // 3 minutes
     public static double mCaptureRate = 0.5; // 2 sec timelapse interval
 
@@ -64,41 +62,41 @@
     public void onCreate(Bundle icicle) {
         super.onCreate(icicle);
         String iterations = (String) icicle.get("iterations");
-        String video_encoder = (String) icicle.get("video_encoder");
-        String audio_encoder = (String) icicle.get("audio_encoder");
-        String frame_rate = (String) icicle.get("frame_rate");
-        String video_width = (String) icicle.get("video_width");
-        String video_height = (String) icicle.get("video_height");
-        String bit_rate = (String) icicle.get("bit_rate");
-        String record_duration = (String) icicle.get("record_duration");
-        String remove_videos = (String) icicle.get("remove_videos");
+        String videoEncoder = (String) icicle.get("video_encoder");
+        String audioEncoder = (String) icicle.get("audio_encoder");
+        String frameRate = (String) icicle.get("frame_rate");
+        String videoWidth = (String) icicle.get("video_width");
+        String videoHeight = (String) icicle.get("video_height");
+        String bitRate = (String) icicle.get("bit_rate");
+        String recordDuration = (String) icicle.get("record_duration");
+        String removeVideos = (String) icicle.get("remove_videos");
 
         if (iterations != null ) {
             mIterations = Integer.parseInt(iterations);
         }
-        if ( video_encoder != null) {
-            mVideoEncoder = Integer.parseInt(video_encoder);
+        if (videoEncoder != null) {
+            mVideoEncoder = Integer.parseInt(videoEncoder);
         }
-        if ( audio_encoder != null) {
-            mAudioEncdoer = Integer.parseInt(audio_encoder);
+        if (audioEncoder != null) {
+            mAudioEncoder = Integer.parseInt(audioEncoder);
         }
-        if (frame_rate != null) {
-            mFrameRate = Integer.parseInt(frame_rate);
+        if (frameRate != null) {
+            mFrameRate = Integer.parseInt(frameRate);
         }
-        if (video_width != null) {
-            mVideoWidth = Integer.parseInt(video_width);
+        if (videoWidth != null) {
+            mVideoWidth = Integer.parseInt(videoWidth);
         }
-        if (video_height != null) {
-            mVideoHeight = Integer.parseInt(video_height);
+        if (videoHeight != null) {
+            mVideoHeight = Integer.parseInt(videoHeight);
         }
-        if (bit_rate != null) {
-            mBitRate = Integer.parseInt(bit_rate);
+        if (bitRate != null) {
+            mBitRate = Integer.parseInt(bitRate);
         }
-        if (record_duration != null) {
-            mDuration = Integer.parseInt(record_duration);
+        if (recordDuration != null) {
+            mDuration = Integer.parseInt(recordDuration);
         }
-        if (remove_videos != null) {
-            if (remove_videos.compareTo("true") == 0) {
+        if (removeVideos != null) {
+            if (removeVideos.compareTo("true") == 0) {
                 mRemoveVideo = true;
             } else {
                 mRemoveVideo = false;
diff --git a/media/tests/MediaFrameworkTest/src/com/android/mediaframeworktest/stress/CameraStressTest.java b/media/tests/MediaFrameworkTest/src/com/android/mediaframeworktest/stress/CameraStressTest.java
index ab9e36c3..ed1d8fc 100644
--- a/media/tests/MediaFrameworkTest/src/com/android/mediaframeworktest/stress/CameraStressTest.java
+++ b/media/tests/MediaFrameworkTest/src/com/android/mediaframeworktest/stress/CameraStressTest.java
@@ -28,6 +28,7 @@
 import java.io.Writer;
 import java.util.concurrent.Semaphore;
 import java.util.concurrent.TimeUnit;
+import java.util.List;
 
 import android.hardware.Camera;
 import android.hardware.Camera.PictureCallback;
@@ -44,7 +45,7 @@
 import junit.framework.Assert;
 
 /**
- * Junit / Instrumentation test case for the camera zoom api
+ * Junit / Instrumentation test case for the camera zoom and scene mode APIs
  *
  * adb shell am instrument
  *  -e class com.android.mediaframeworktest.stress.CameraStressTest
@@ -54,18 +55,22 @@
     private String TAG = "CameraStressTest";
     private Camera mCamera;
 
+    private static final int CAMERA_ID = 0;
     private static final int NUMBER_OF_ZOOM_LOOPS = 100;
+    private static final int NUMBER_OF_SCENE_MODE_LOOPS = 10;
     private static final long WAIT_GENERIC = 3 * 1000; // 3 seconds
     private static final long WAIT_TIMEOUT = 10 * 1000; // 10 seconds
     private static final long WAIT_ZOOM_ANIMATION = 5 * 1000; // 5 seconds
-    private static final String CAMERA_STRESS_OUTPUT =
-            "/sdcard/cameraStressOutput.txt";
-    private static final int CAMERA_ID = 0;
+    private static final String CAMERA_STRESS_IMAGES_DIRECTORY = "cameraStressImages";
+    private static final String CAMERA_STRESS_IMAGES_PREFIX = "camera-stress-test";
+    private static final String CAMERA_STRESS_OUTPUT = "cameraStressOutput.txt";
     private final CameraErrorCallback mCameraErrorCallback = new CameraErrorCallback();
 
     private Thread mLooperThread;
     private Handler mHandler;
 
+    private Writer mOutput;
+
     public CameraStressTest() {
         super("com.android.mediaframeworktest", MediaFrameworkTest.class);
     }
@@ -89,6 +94,20 @@
         }
         getActivity();
         super.setUp();
+
+        File sdcard = Environment.getExternalStorageDirectory();
+
+        // Create the test images directory if it doesn't exist
+        File stressImagesDirectory = new File(String.format("%s/%s", sdcard,
+                CAMERA_STRESS_IMAGES_DIRECTORY));
+        if (!stressImagesDirectory.exists()) {
+            stressImagesDirectory.mkdir();
+        }
+
+        // Start writing output file
+        File stressOutFile = new File(String.format("%s/%s",sdcard, CAMERA_STRESS_OUTPUT));
+        mOutput = new BufferedWriter(new FileWriter(stressOutFile, true));
+        mOutput.write(this.getName() + ":\n");
     }
 
     @Override
@@ -105,6 +124,9 @@
             mLooperThread = null;
         }
 
+        mOutput.write("\n\n");
+        mOutput.close();
+
         super.tearDown();
     }
 
@@ -127,9 +149,7 @@
 
     private final class CameraErrorCallback implements android.hardware.Camera.ErrorCallback {
         public void onError(int error, android.hardware.Camera camera) {
-            if (error == android.hardware.Camera.CAMERA_ERROR_SERVER_DIED) {
-                assertTrue("Camera test mediaserver died", false);
-            }
+            fail(String.format("Camera error, code: %d", error));
         }
     }
 
@@ -154,49 +174,76 @@
 
             try {
                 Log.v(TAG, "JPEG picture taken");
-                fos = new FileOutputStream(String.format("%s/zoom-test-%d.jpg",
-                        Environment.getExternalStorageDirectory(), System.currentTimeMillis()));
+                fos = new FileOutputStream(String.format("%s/%s/%s-%d.jpg",
+                        Environment.getExternalStorageDirectory(), CAMERA_STRESS_IMAGES_DIRECTORY,
+                        CAMERA_STRESS_IMAGES_PREFIX, System.currentTimeMillis()));
                 fos.write(data);
-            }
-            catch (FileNotFoundException e) {
-                Log.v(TAG, "File not found: " + e.toString());
-            }
-            catch (IOException e) {
-                Log.v(TAG, "Error accessing file: " + e.toString());
-            }
-            finally {
+            } catch (FileNotFoundException e) {
+                Log.e(TAG, "File not found: " + e.toString());
+            } catch (IOException e) {
+                Log.e(TAG, "Error accessing file: " + e.toString());
+            } finally {
                 try {
                     if (fos != null) {
                         fos.close();
                     }
-                }
-                catch (IOException e) {
-                    Log.v(TAG, "Error closing file: " + e.toString());
+                } catch (IOException e) {
+                    Log.e(TAG, "Error closing file: " + e.toString());
                 }
             }
         }
     };
 
     // Helper method for cleaning up pics taken during testStressCameraZoom
-    private void cleanupZoomImages() {
+    private void cleanupStressTestImages() {
         try {
-            File sdcard = Environment.getExternalStorageDirectory();
+            File stressImagesDirectory = new File(String.format("%s/%s",
+                    Environment.getExternalStorageDirectory(), CAMERA_STRESS_IMAGES_DIRECTORY));
             File[] zoomImages = null;
 
             FilenameFilter filter = new FilenameFilter() {
                 public boolean accept(File dir, String name) {
-                    return name.startsWith("zoom-test-");
+                    return name.startsWith(CAMERA_STRESS_IMAGES_PREFIX);
                 }
             };
 
-            zoomImages = sdcard.listFiles(filter);
+            zoomImages = stressImagesDirectory.listFiles(filter);
 
             for (File f : zoomImages) {
                 f.delete();
             }
+        } catch (SecurityException e) {
+            Log.e(TAG, "Security manager access violation: " + e.toString());
         }
-        catch (SecurityException e) {
-            Log.v(TAG, "Security manager access violation: " + e.toString());
+    }
+
+    // Helper method for starting up the camera preview
+    private void startCameraPreview(SurfaceHolder surfaceHolder) {
+        try {
+            mCamera.setErrorCallback(mCameraErrorCallback);
+            mCamera.setPreviewDisplay(surfaceHolder);
+            mCamera.startPreview();
+            Thread.sleep(WAIT_GENERIC);
+        } catch (IOException e) {
+            Log.e(TAG, "Error setting preview display: " + e.toString());
+        } catch (InterruptedException e) {
+            Log.e(TAG, "Error waiting for preview to come up: " + e.toString());
+        } catch (Exception e) {
+            Log.e(TAG, "Error starting up camera preview: " + e.toString());
+        }
+    }
+
+    // Helper method for taking a photo
+    private void capturePhoto() {
+        try {
+            mCamera.takePicture(shutterCallback, rawCallback, jpegCallback);
+            Thread.sleep(WAIT_GENERIC);
+            mCamera.stopPreview();
+            mCamera.release();
+        } catch (InterruptedException e) {
+            Log.e(TAG, "Error waiting for photo to be taken: " + e.toString());
+        } catch (Exception e) {
+            Log.e(TAG, "Error capturing photo: " + e.toString());
         }
     }
 
@@ -205,14 +252,11 @@
     public void testStressCameraZoom() throws Exception {
         SurfaceHolder mSurfaceHolder;
         mSurfaceHolder = MediaFrameworkTest.mSurfaceView.getHolder();
-        File stressOutFile = new File(CAMERA_STRESS_OUTPUT);
-        Writer output = new BufferedWriter(new FileWriter(stressOutFile, true));
-        output.write("Camera zoom stress:\n");
-        output.write("Total number of loops: " +  NUMBER_OF_ZOOM_LOOPS + "\n");
+        mOutput.write("Total number of loops: " + NUMBER_OF_ZOOM_LOOPS + "\n");
 
         try {
             Log.v(TAG, "Start preview");
-            output.write("No of loop: ");
+            mOutput.write("No of loop: ");
 
             mCamera = Camera.open(CAMERA_ID);
             Camera.Parameters params = mCamera.getParameters();
@@ -220,9 +264,8 @@
 
             if (!params.isSmoothZoomSupported() && !params.isZoomSupported()) {
                 Log.v(TAG, "Device camera does not support zoom");
-                assertTrue("Camera zoom stress test", false);
-            }
-            else {
+                fail("Camera zoom stress test failed");
+            } else {
                 Log.v(TAG, "Device camera does support zoom");
 
                 int nextZoomLevel = 0;
@@ -235,11 +278,7 @@
                         }
                     });
 
-                    mCamera.setErrorCallback(mCameraErrorCallback);
-                    mCamera.setPreviewDisplay(mSurfaceHolder);
-                    mCamera.startPreview();
-                    Thread.sleep(WAIT_GENERIC);
-
+                    startCameraPreview(mSurfaceHolder);
                     params = mCamera.getParameters();
                     int currentZoomLevel = params.getZoom();
 
@@ -250,8 +289,7 @@
 
                     if (params.isSmoothZoomSupported()) {
                         mCamera.startSmoothZoom(nextZoomLevel);
-                    }
-                    else {
+                    } else {
                         params.setZoom(nextZoomLevel);
                         mCamera.setParameters(params);
                     }
@@ -259,23 +297,66 @@
 
                     // sleep allows for zoom animation to finish
                     Thread.sleep(WAIT_ZOOM_ANIMATION);
+                    capturePhoto();
 
-                    // take picture
-                    mCamera.takePicture(shutterCallback, rawCallback, jpegCallback);
-                    Thread.sleep(WAIT_GENERIC);
-                    mCamera.stopPreview();
-                    mCamera.release();
-                    output.write(" ," + i);
+                    if (i == 0) {
+                        mOutput.write(Integer.toString(i));
+                    } else {
+                        mOutput.write(", " + i);
+                    }
                 }
             }
+            cleanupStressTestImages();
+        } catch (Exception e) {
+            Log.e(TAG, e.toString());
+            fail("Camera zoom stress test Exception");
+        }
+    }
 
-            cleanupZoomImages();
+    // Test case for stressing the camera scene mode feature
+    @LargeTest
+    public void testStressCameraSceneModes() throws Exception {
+        SurfaceHolder mSurfaceHolder;
+        mSurfaceHolder = MediaFrameworkTest.mSurfaceView.getHolder();
+
+        try {
+            mCamera = Camera.open(CAMERA_ID);
+            Camera.Parameters params = mCamera.getParameters();
+            mCamera.release();
+            List<String> supportedSceneModes = params.getSupportedSceneModes();
+            assertNotNull("No scene modes supported", supportedSceneModes);
+
+            mOutput.write("Total number of loops: " +
+                    (NUMBER_OF_SCENE_MODE_LOOPS * supportedSceneModes.size()) + "\n");
+            Log.v(TAG, "Start preview");
+            mOutput.write("No of loop: ");
+
+            for (int i = 0; i < supportedSceneModes.size(); i++) {
+                for (int j = 0; j < NUMBER_OF_SCENE_MODE_LOOPS; j++) {
+                    runOnLooper(new Runnable() {
+                        @Override
+                        public void run() {
+                            mCamera = Camera.open(CAMERA_ID);
+                        }
+                    });
+
+                    startCameraPreview(mSurfaceHolder);
+                    Log.v(TAG, "Setting mode to " + supportedSceneModes.get(i));
+                    params.setSceneMode(supportedSceneModes.get(i));
+                    mCamera.setParameters(params);
+                    capturePhoto();
+
+                    if ((i == 0) && (j == 0)) {
+                        mOutput.write(Integer.toString(j + i * NUMBER_OF_SCENE_MODE_LOOPS));
+                    } else {
+                        mOutput.write(", " + (j + i * NUMBER_OF_SCENE_MODE_LOOPS));
+                    }
+                }
+            }
+            cleanupStressTestImages();
+        } catch (Exception e) {
+            Log.e(TAG, e.toString());
+            fail("Camera scene mode test Exception");
         }
-        catch (Exception e) {
-            assertTrue("Camera zoom stress test Exception", false);
-            Log.v(TAG, e.toString());
-        }
-        output.write("\n\n");
-        output.close();
     }
 }
diff --git a/media/tests/MediaFrameworkTest/src/com/android/mediaframeworktest/stress/MediaRecorderStressTest.java b/media/tests/MediaFrameworkTest/src/com/android/mediaframeworktest/stress/MediaRecorderStressTest.java
index 6995c60..6eb9891 100644
--- a/media/tests/MediaFrameworkTest/src/com/android/mediaframeworktest/stress/MediaRecorderStressTest.java
+++ b/media/tests/MediaFrameworkTest/src/com/android/mediaframeworktest/stress/MediaRecorderStressTest.java
@@ -31,6 +31,7 @@
 import android.media.CamcorderProfile;
 import android.media.MediaPlayer;
 import android.media.MediaRecorder;
+import android.os.Environment;
 import android.os.Handler;
 import android.os.Looper;
 import android.test.ActivityInstrumentationTestCase2;
@@ -48,26 +49,26 @@
     private MediaRecorder mRecorder;
     private Camera mCamera;
 
+    private static final int CAMERA_ID = 0;
     private static final int NUMBER_OF_CAMERA_STRESS_LOOPS = 100;
     private static final int NUMBER_OF_RECORDER_STRESS_LOOPS = 100;
     private static final int NUMBER_OF_RECORDERANDPLAY_STRESS_LOOPS = 50;
     private static final int NUMBER_OF_SWTICHING_LOOPS_BW_CAMERA_AND_RECORDER = 200;
     private static final int NUMBER_OF_TIME_LAPSE_LOOPS = 25;
     private static final int TIME_LAPSE_PLAYBACK_WAIT_TIME = 5* 1000; // 5 seconds
+    private static final int USE_TEST_RUNNER_PROFILE = -1;
+    private static final long WAIT_TIMEOUT = 10 * 1000; // 10 seconds
     private static final long WAIT_TIME_CAMERA_TEST = 3 * 1000; // 3 seconds
     private static final long WAIT_TIME_RECORDER_TEST = 6 * 1000; // 6 seconds
-    private static final String OUTPUT_FILE = "/sdcard/temp";
     private static final String OUTPUT_FILE_EXT = ".3gp";
-    private static final String MEDIA_STRESS_OUTPUT =
-        "/sdcard/mediaStressOutput.txt";
-    private static final int CAMERA_ID = 0;
+    private static final String MEDIA_STRESS_OUTPUT = "mediaStressOutput.txt";
 
     private final CameraErrorCallback mCameraErrorCallback = new CameraErrorCallback();
     private final RecorderErrorCallback mRecorderErrorCallback = new RecorderErrorCallback();
 
-    private final static int WAIT_TIMEOUT = 10 * 1000; // 10 seconds
-    private Thread mLooperThread;
     private Handler mHandler;
+    private Thread mLooperThread;
+    private Writer mOutput;
 
     public MediaRecorderStressTest() {
         super("com.android.mediaframeworktest", MediaFrameworkTest.class);
@@ -95,6 +96,11 @@
         Thread.sleep(2000);
         getActivity();
         super.setUp();
+
+        File stressOutFile = new File(String.format("%s/%s",
+                Environment.getExternalStorageDirectory(), MEDIA_STRESS_OUTPUT));
+        mOutput = new BufferedWriter(new FileWriter(stressOutFile, true));
+        mOutput.write(this.getName() + "\n");
     }
 
     @Override
@@ -110,7 +116,8 @@
             }
             mLooperThread = null;
         }
-
+        mOutput.write("\n\n");
+        mOutput.close();
         super.tearDown();
     }
 
@@ -133,16 +140,13 @@
 
     private final class CameraErrorCallback implements android.hardware.Camera.ErrorCallback {
         public void onError(int error, android.hardware.Camera camera) {
-            if (error == android.hardware.Camera.CAMERA_ERROR_SERVER_DIED) {
-                assertTrue("Camera test mediaserver died", false);
-            }
+            fail(String.format("Camera error, code: %d", error));
         }
     }
 
     private final class RecorderErrorCallback implements MediaRecorder.OnErrorListener {
         public void onError(MediaRecorder mr, int what, int extra) {
-            // fail the test case no matter what error come up
-            assertTrue("mediaRecorder error", false);
+            fail(String.format("Media recorder error, code: %d\textra: %d", what, extra));
         }
     }
 
@@ -151,14 +155,11 @@
     public void testStressCamera() throws Exception {
         SurfaceHolder mSurfaceHolder;
         mSurfaceHolder = MediaFrameworkTest.mSurfaceView.getHolder();
-        File stressOutFile = new File(MEDIA_STRESS_OUTPUT);
-        Writer output = new BufferedWriter(new FileWriter(stressOutFile, true));
-        output.write("Camera start preview stress:\n");
-        output.write("Total number of loops:" +
-                NUMBER_OF_CAMERA_STRESS_LOOPS + "\n");
+        Log.v(TAG, "Camera start preview stress test");
+        mOutput.write("Total number of loops:" + NUMBER_OF_CAMERA_STRESS_LOOPS + "\n");
         try {
             Log.v(TAG, "Start preview");
-            output.write("No of loop: ");
+            mOutput.write("No of loop: ");
 
             for (int i = 0; i< NUMBER_OF_CAMERA_STRESS_LOOPS; i++) {
                 runOnLooper(new Runnable() {
@@ -173,29 +174,27 @@
                 Thread.sleep(WAIT_TIME_CAMERA_TEST);
                 mCamera.stopPreview();
                 mCamera.release();
-                output.write(" ," + i);
+                if (i == 0) {
+                    mOutput.write(i + 1);
+                } else {
+                    mOutput.write(String.format(", %d", (i + 1)));
+                }
             }
         } catch (Exception e) {
-            assertTrue("CameraStressTest", false);
-            Log.v(TAG, e.toString());
+            Log.e(TAG, e.toString());
+            fail("Camera startup preview stress test");
         }
-        output.write("\n\n");
-        output.close();
     }
 
     //Test case for stressing the camera preview.
     @LargeTest
     public void testStressRecorder() throws Exception {
-        String filename;
         SurfaceHolder mSurfaceHolder;
         mSurfaceHolder = MediaFrameworkTest.mSurfaceView.getHolder();
-        File stressOutFile = new File(MEDIA_STRESS_OUTPUT);
-        Writer output = new BufferedWriter(new FileWriter(stressOutFile, true));
-        output.write("H263 video record- reset after prepare Stress test\n");
-        output.write("Total number of loops:" +
-                NUMBER_OF_RECORDER_STRESS_LOOPS + "\n");
+        Log.v(TAG, "H263 video record: reset after prepare Stress test");
+        mOutput.write("Total number of loops:" + NUMBER_OF_RECORDER_STRESS_LOOPS + "\n");
         try {
-            output.write("No of loop: ");
+            mOutput.write("No of loop: ");
             Log.v(TAG, "Start preview");
             for (int i = 0; i < NUMBER_OF_RECORDER_STRESS_LOOPS; i++) {
                 runOnLooper(new Runnable() {
@@ -205,12 +204,15 @@
                     }
                 });
                 Log.v(TAG, "counter = " + i);
-                filename = OUTPUT_FILE + i + OUTPUT_FILE_EXT;
-                Log.v(TAG, filename);
+                String fileName = String.format("%s/temp%d%s",
+                        Environment.getExternalStorageDirectory(),
+                        i, OUTPUT_FILE_EXT);
+
+                Log.v(TAG, fileName);
                 mRecorder.setOnErrorListener(mRecorderErrorCallback);
                 mRecorder.setVideoSource(MediaRecorder.VideoSource.CAMERA);
                 mRecorder.setOutputFormat(MediaRecorder.OutputFormat.THREE_GPP);
-                mRecorder.setOutputFile(filename);
+                mRecorder.setOutputFile(fileName);
                 mRecorder.setVideoFrameRate(MediaRecorderStressTestRunner.mFrameRate);
                 mRecorder.setVideoSize(176,144);
                 Log.v(TAG, "setEncoder");
@@ -224,30 +226,29 @@
                 Thread.sleep(WAIT_TIME_RECORDER_TEST);
                 mRecorder.reset();
                 mRecorder.release();
-                output.write(", " + i);
+                if (i == 0) {
+                    mOutput.write(i + 1);
+                } else {
+                    mOutput.write(String.format(", %d", (i + 1)));
+                }
             }
         } catch (Exception e) {
-            assertTrue("Recorder Stress test", false);
-            Log.v(TAG, e.toString());
+            Log.e(TAG, e.toString());
+            fail("H263 video recording stress test");
         }
-        output.write("\n\n");
-        output.close();
     }
 
     //Stress test case for switching camera and video recorder preview.
     @LargeTest
     public void testStressCameraSwitchRecorder() throws Exception {
-        String filename;
         SurfaceHolder mSurfaceHolder;
         mSurfaceHolder = MediaFrameworkTest.mSurfaceView.getHolder();
-        File stressOutFile = new File(MEDIA_STRESS_OUTPUT);
-        Writer output = new BufferedWriter(new FileWriter(stressOutFile, true));
-        output.write("Camera and video recorder preview switching\n");
-        output.write("Total number of loops:"
-                + NUMBER_OF_SWTICHING_LOOPS_BW_CAMERA_AND_RECORDER + "\n");
+        Log.v(TAG, "Camera and video recorder preview switching");
+        mOutput.write("Total number of loops: " +
+                NUMBER_OF_SWTICHING_LOOPS_BW_CAMERA_AND_RECORDER + "\n");
         try {
             Log.v(TAG, "Start preview");
-            output.write("No of loop: ");
+            mOutput.write("No of loop: ");
             for (int i = 0; i < NUMBER_OF_SWTICHING_LOOPS_BW_CAMERA_AND_RECORDER; i++) {
                 runOnLooper(new Runnable() {
                     @Override
@@ -263,8 +264,10 @@
                 mCamera.release();
                 mCamera = null;
                 Log.v(TAG, "release camera");
-                filename = OUTPUT_FILE + i + OUTPUT_FILE_EXT;
-                Log.v(TAG, filename);
+                String fileName = String.format("%s/temp%d%s",
+                        Environment.getExternalStorageDirectory(),
+                        i, OUTPUT_FILE_EXT);
+                Log.v(TAG, fileName);
                 runOnLooper(new Runnable() {
                     @Override
                     public void run() {
@@ -274,7 +277,7 @@
                 mRecorder.setOnErrorListener(mRecorderErrorCallback);
                 mRecorder.setVideoSource(MediaRecorder.VideoSource.CAMERA);
                 mRecorder.setOutputFormat(MediaRecorder.OutputFormat.THREE_GPP);
-                mRecorder.setOutputFile(filename);
+                mRecorder.setOutputFile(fileName);
                 mRecorder.setVideoFrameRate(MediaRecorderStressTestRunner.mFrameRate);
                 mRecorder.setVideoSize(176,144);
                 Log.v(TAG, "Media recorder setEncoder");
@@ -287,117 +290,167 @@
                 Thread.sleep(WAIT_TIME_CAMERA_TEST);
                 mRecorder.release();
                 Log.v(TAG, "release video recorder");
-                output.write(", " + i);
+                if (i == 0) {
+                    mOutput.write(i + 1);
+                } else {
+                    mOutput.write(String.format(", %d", (i + 1)));
+                }
             }
         } catch (Exception e) {
-            assertTrue("Camer and recorder switch mode", false);
-                Log.v(TAG, e.toString());
+            Log.e(TAG, e.toString());
+            fail("Camera and recorder switch mode");
         }
-        output.write("\n\n");
-        output.close();
     }
 
-    public void validateRecordedVideo(String recorded_file) {
+    public void validateRecordedVideo(String recordedFile) {
         try {
             MediaPlayer mp = new MediaPlayer();
-            mp.setDataSource(recorded_file);
+            mp.setDataSource(recordedFile);
             mp.prepare();
             int duration = mp.getDuration();
             if (duration <= 0){
-                assertTrue("stressRecordAndPlayback", false);
+                fail("stressRecordAndPlayback");
             }
             mp.release();
         } catch (Exception e) {
-            assertTrue("stressRecordAndPlayback", false);
+            fail("stressRecordAndPlayback");
         }
     }
 
-    public void removeRecordedVideo(String filename){
-        File video = new File(filename);
-        Log.v(TAG, "remove recorded video " + filename);
+    public void removeRecordedVideo(String fileName){
+        File video = new File(fileName);
+        Log.v(TAG, "remove recorded video " + fileName);
         video.delete();
     }
 
-    //Stress test case for record a video and play right away.
-    @LargeTest
-    public void testStressRecordVideoAndPlayback() throws Exception {
-        int iterations = MediaRecorderStressTestRunner.mIterations;
-        int video_encoder = MediaRecorderStressTestRunner.mVideoEncoder;
-        int audio_encoder = MediaRecorderStressTestRunner.mAudioEncdoer;
-        int frame_rate = MediaRecorderStressTestRunner.mFrameRate;
-        int video_width = MediaRecorderStressTestRunner.mVideoWidth;
-        int video_height = MediaRecorderStressTestRunner.mVideoHeight;
-        int bit_rate = MediaRecorderStressTestRunner.mBitRate;
-        boolean remove_video = MediaRecorderStressTestRunner.mRemoveVideo;
-        int record_duration = MediaRecorderStressTestRunner.mDuration;
+    // Helper method for record & playback testing with different camcorder profiles
+    private void recordVideoAndPlayback(int profile) throws Exception {
+        int iterations;
+        int recordDuration;
+        boolean removeVideo;
 
-        String filename;
-        SurfaceHolder mSurfaceHolder;
-        mSurfaceHolder = MediaFrameworkTest.mSurfaceView.getHolder();
-        File stressOutFile = new File(MEDIA_STRESS_OUTPUT);
-        Writer output = new BufferedWriter(
-                new FileWriter(stressOutFile, true));
-        output.write("Video record and play back stress test:\n");
-        output.write("Total number of loops:"
-                + NUMBER_OF_RECORDERANDPLAY_STRESS_LOOPS + "\n");
+        int videoEncoder;
+        int audioEncoder;
+        int frameRate;
+        int videoWidth;
+        int videoHeight;
+        int bitRate;
+
+        if (profile != USE_TEST_RUNNER_PROFILE) {
+            assertTrue(String.format("Camera doesn't support profile %d", profile),
+                    CamcorderProfile.hasProfile(CAMERA_ID, profile));
+            CamcorderProfile camcorderProfile = CamcorderProfile.get(CAMERA_ID, profile);
+            videoEncoder = camcorderProfile.videoCodec;
+            audioEncoder = camcorderProfile.audioCodec;
+            frameRate = camcorderProfile.videoFrameRate;
+            videoWidth = camcorderProfile.videoFrameWidth;
+            videoHeight = camcorderProfile.videoFrameHeight;
+            bitRate = camcorderProfile.videoBitRate;
+        } else {
+            videoEncoder = MediaRecorderStressTestRunner.mVideoEncoder;
+            audioEncoder = MediaRecorderStressTestRunner.mAudioEncoder;
+            frameRate = MediaRecorderStressTestRunner.mFrameRate;
+            videoWidth = MediaRecorderStressTestRunner.mVideoWidth;
+            videoHeight = MediaRecorderStressTestRunner.mVideoHeight;
+            bitRate = MediaRecorderStressTestRunner.mBitRate;
+        }
+        iterations = MediaRecorderStressTestRunner.mIterations;
+        recordDuration = MediaRecorderStressTestRunner.mDuration;
+        removeVideo = MediaRecorderStressTestRunner.mRemoveVideo;
+
+        SurfaceHolder surfaceHolder = MediaFrameworkTest.mSurfaceView.getHolder();
+        mOutput.write("Total number of loops: " + iterations + "\n");
+
         try {
-            output.write("No of loop: ");
-            for (int i = 0; i < iterations; i++){
-                filename = OUTPUT_FILE + i + OUTPUT_FILE_EXT;
-                Log.v(TAG, filename);
+            mOutput.write("No of loop: ");
+            for (int i = 0; i < iterations; i++) {
+                String fileName = String.format("%s/temp%d%s",
+                        Environment.getExternalStorageDirectory(), i, OUTPUT_FILE_EXT);
+                Log.v(TAG, fileName);
+
                 runOnLooper(new Runnable() {
                     @Override
                     public void run() {
                         mRecorder = new MediaRecorder();
                     }
                 });
+
                 Log.v(TAG, "iterations : " + iterations);
-                Log.v(TAG, "video_encoder : " + video_encoder);
-                Log.v(TAG, "audio_encoder : " + audio_encoder);
-                Log.v(TAG, "frame_rate : " + frame_rate);
-                Log.v(TAG, "video_width : " + video_width);
-                Log.v(TAG, "video_height : " + video_height);
-                Log.v(TAG, "bit rate : " + bit_rate);
-                Log.v(TAG, "record_duration : " + record_duration);
+                Log.v(TAG, "video encoder : " + videoEncoder);
+                Log.v(TAG, "audio encoder : " + audioEncoder);
+                Log.v(TAG, "frame rate : " + frameRate);
+                Log.v(TAG, "video width : " + videoWidth);
+                Log.v(TAG, "video height : " + videoHeight);
+                Log.v(TAG, "bit rate : " + bitRate);
+                Log.v(TAG, "record duration : " + recordDuration);
 
                 mRecorder.setOnErrorListener(mRecorderErrorCallback);
                 mRecorder.setVideoSource(MediaRecorder.VideoSource.CAMERA);
                 mRecorder.setAudioSource(MediaRecorder.AudioSource.MIC);
                 mRecorder.setOutputFormat(MediaRecorder.OutputFormat.THREE_GPP);
-                mRecorder.setOutputFile(filename);
-                mRecorder.setVideoFrameRate(frame_rate);
-                mRecorder.setVideoSize(video_width, video_height);
-                mRecorder.setVideoEncoder(video_encoder);
-                mRecorder.setAudioEncoder(audio_encoder);
-                mRecorder.setVideoEncodingBitRate(bit_rate);
+                mRecorder.setOutputFile(fileName);
+                mRecorder.setVideoFrameRate(frameRate);
+                mRecorder.setVideoSize(videoWidth, videoHeight);
+                mRecorder.setVideoEncoder(videoEncoder);
+                mRecorder.setAudioEncoder(audioEncoder);
+                mRecorder.setVideoEncodingBitRate(bitRate);
+
                 Log.v(TAG, "mediaRecorder setPreview");
-                mRecorder.setPreviewDisplay(mSurfaceHolder.getSurface());
+                mRecorder.setPreviewDisplay(surfaceHolder.getSurface());
                 mRecorder.prepare();
                 mRecorder.start();
-                Thread.sleep(record_duration);
+                Thread.sleep(recordDuration);
                 Log.v(TAG, "Before stop");
                 mRecorder.stop();
                 mRecorder.release();
+
                 //start the playback
                 MediaPlayer mp = new MediaPlayer();
-                mp.setDataSource(filename);
+                mp.setDataSource(fileName);
                 mp.setDisplay(MediaFrameworkTest.mSurfaceView.getHolder());
                 mp.prepare();
                 mp.start();
-                Thread.sleep(record_duration);
+                Thread.sleep(recordDuration);
                 mp.release();
-                validateRecordedVideo(filename);
-                if (remove_video) {
-                    removeRecordedVideo(filename);
+                validateRecordedVideo(fileName);
+                if (removeVideo) {
+                    removeRecordedVideo(fileName);
                 }
-                output.write(", " + i);
+                if (i == 0) {
+                    mOutput.write(i + 1);
+                } else {
+                    mOutput.write(String.format(", %d", (i + 1)));
+                }
             }
         } catch (Exception e) {
-            Log.v(TAG, e.toString());
-            assertTrue("record and playback", false);
+            Log.e(TAG, e.toString());
+            fail("Record and playback");
         }
-        output.write("\n\n");
-        output.close();
+    }
+
+    // Record and playback stress test @ 1080P quality
+    @LargeTest
+    public void testStressRecordVideoAndPlayback1080P() throws Exception {
+        recordVideoAndPlayback(CamcorderProfile.QUALITY_1080P);
+    }
+
+    // Record and playback stress test @ 720P quality
+    @LargeTest
+    public void testStressRecordVideoAndPlayback720P() throws Exception {
+        recordVideoAndPlayback(CamcorderProfile.QUALITY_720P);
+    }
+
+    // Record and playback stress test @ 480P quality
+    @LargeTest
+    public void testStressRecordVideoAndPlayback480P() throws Exception {
+        recordVideoAndPlayback(CamcorderProfile.QUALITY_480P);
+    }
+
+    // This test method uses the codec info from the test runner. Use this
+    // for more granular control of video encoding.
+    @LargeTest
+    public void defaultStressRecordVideoAndPlayback() throws Exception {
+        recordVideoAndPlayback(USE_TEST_RUNNER_PROFILE);
     }
 
     // Test case for stressing time lapse
@@ -405,21 +458,19 @@
     public void testStressTimeLapse() throws Exception {
         SurfaceHolder mSurfaceHolder;
         mSurfaceHolder = MediaFrameworkTest.mSurfaceView.getHolder();
-        int record_duration = MediaRecorderStressTestRunner.mTimeLapseDuration;
-        boolean remove_video = MediaRecorderStressTestRunner.mRemoveVideo;
+        int recordDuration = MediaRecorderStressTestRunner.mTimeLapseDuration;
+        boolean removeVideo = MediaRecorderStressTestRunner.mRemoveVideo;
         double captureRate = MediaRecorderStressTestRunner.mCaptureRate;
-        String filename;
-        File stressOutFile = new File(MEDIA_STRESS_OUTPUT);
-        Writer output = new BufferedWriter(new FileWriter(stressOutFile, true));
-        output.write("Start camera time lapse stress:\n");
-        output.write("Total number of loops: " + NUMBER_OF_TIME_LAPSE_LOOPS + "\n");
+        Log.v(TAG, "Start camera time lapse stress:");
+        mOutput.write("Total number of loops: " + NUMBER_OF_TIME_LAPSE_LOOPS + "\n");
 
         try {
-            for (int j = 0, n = Camera.getNumberOfCameras(); j < n; j++) {
-                output.write("No of loop: camera " + j);
-                for (int i = 0; i < NUMBER_OF_TIME_LAPSE_LOOPS; i++) {
-                    filename = OUTPUT_FILE + j + "_" + i + OUTPUT_FILE_EXT;
-                    Log.v(TAG, filename);
+            for (int i = 0, n = Camera.getNumberOfCameras(); i < n; i++) {
+                mOutput.write("No of loop: camera " + i);
+                for (int j = 0; j < NUMBER_OF_TIME_LAPSE_LOOPS; j++) {
+                    String fileName = String.format("%s/temp%d_%d%s",
+                            Environment.getExternalStorageDirectory(), i, j, OUTPUT_FILE_EXT);
+                    Log.v(TAG, fileName);
                     runOnLooper(new Runnable() {
                         @Override
                         public void run() {
@@ -438,12 +489,12 @@
                         CamcorderProfile.get(j, CamcorderProfile.QUALITY_TIME_LAPSE_HIGH);
                     mRecorder.setProfile(profile);
 
-                    // Set the timelapse setting; 0.1 = 10 sec timelapse, 0.5 = 2 sec timelapse, etc.
+                    // Set the timelapse setting; 0.1 = 10 sec timelapse, 0.5 = 2 sec timelapse, etc
                     // http://developer.android.com/guide/topics/media/camera.html#time-lapse-video
                     mRecorder.setCaptureRate(captureRate);
 
                     // Set output file
-                    mRecorder.setOutputFile(filename);
+                    mRecorder.setOutputFile(fileName);
 
                     // Set the preview display
                     Log.v(TAG, "mediaRecorder setPreviewDisplay");
@@ -451,40 +502,40 @@
 
                     mRecorder.prepare();
                     mRecorder.start();
-                    Thread.sleep(record_duration);
+                    Thread.sleep(recordDuration);
                     Log.v(TAG, "Before stop");
                     mRecorder.stop();
                     mRecorder.release();
 
                     // Start the playback
                     MediaPlayer mp = new MediaPlayer();
-                    mp.setDataSource(filename);
+                    mp.setDataSource(fileName);
                     mp.setDisplay(mSurfaceHolder);
                     mp.prepare();
                     mp.start();
                     Thread.sleep(TIME_LAPSE_PLAYBACK_WAIT_TIME);
                     mp.release();
-                    validateRecordedVideo(filename);
-                    if (remove_video) {
-                        removeRecordedVideo(filename);
+                    validateRecordedVideo(fileName);
+                    if (removeVideo) {
+                        removeRecordedVideo(fileName);
                     }
-                    output.write(", " + i);
+
+                    if (j == 0) {
+                        mOutput.write(j + 1);
+                    } else {
+                        mOutput.write(String.format(", %d", (j + 1)));
+                    }
                 }
             }
+        } catch (IllegalStateException e) {
+            Log.e(TAG, e.toString());
+            fail("Camera time lapse stress test IllegalStateException");
+        } catch (IOException e) {
+            Log.e(TAG, e.toString());
+            fail("Camera time lapse stress test IOException");
+        } catch (Exception e) {
+            Log.e(TAG, e.toString());
+            fail("Camera time lapse stress test Exception");
         }
-        catch (IllegalStateException e) {
-            assertTrue("Camera time lapse stress test IllegalStateException", false);
-            Log.v(TAG, e.toString());
-        }
-        catch (IOException e) {
-            assertTrue("Camera time lapse stress test IOException", false);
-            Log.v(TAG, e.toString());
-        }
-        catch (Exception e) {
-            assertTrue("Camera time lapse stress test Exception", false);
-            Log.v(TAG, e.toString());
-        }
-        output.write("\n\n");
-        output.close();
     }
 }