From 7539f9e5bc6386e0812becfd8c4763b24b0f1ee6 Mon Sep 17 00:00:00 2001 From: Ashok Raj Deenadayalan Date: Thu, 28 Nov 2013 12:47:01 +0530 Subject: Camera: Check file existence before update Recorded file must exist for updation. Check if the file exists before you update to avoid crash. Treat file non-existence as a error case and proceed further. Change-Id: I31954d51f0c34ef3d0ee25cb30d243804bc93fc3 CRs-Fixed: 573040 --- src/com/android/camera/VideoModule.java | 8 ++++++++ src/com/android/camera/data/CameraDataAdapter.java | 14 +++++++++----- src/com/android/camera/data/LocalMediaData.java | 8 ++++++++ 3 files changed, 25 insertions(+), 5 deletions(-) (limited to 'src/com/android') diff --git a/src/com/android/camera/VideoModule.java b/src/com/android/camera/VideoModule.java index 057332b09..a50ad7b39 100644 --- a/src/com/android/camera/VideoModule.java +++ b/src/com/android/camera/VideoModule.java @@ -1298,6 +1298,14 @@ public class VideoModule implements CameraModule, } else { Log.w(TAG, "Video duration <= 0 : " + duration); } + + File origFile = new File(mCurrentVideoFilename); + if (!origFile.exists() || origFile.length() <= 0) { + Log.e(TAG, "Invalid file"); + mCurrentVideoValues = null; + return; + } + mActivity.getMediaSaveService().addVideo(mCurrentVideoFilename, duration, mCurrentVideoValues, mOnVideoSavedListener, mContentResolver); diff --git a/src/com/android/camera/data/CameraDataAdapter.java b/src/com/android/camera/data/CameraDataAdapter.java index f59b2099c..24a1ff75c 100644 --- a/src/com/android/camera/data/CameraDataAdapter.java +++ b/src/com/android/camera/data/CameraDataAdapter.java @@ -141,12 +141,16 @@ public class CameraDataAdapter implements LocalDataAdapter { } int pos = findDataByContentUri(uri); LocalMediaData.VideoData newData = LocalMediaData.VideoData.buildFromCursor(c); - if (pos != -1) { - // A duplicate one, just do a substitute. - updateData(pos, newData); + if (newData != null) { + if (pos != -1) { + // A duplicate one, just do a substitute. + updateData(pos, newData); + } else { + // A new data. + insertData(newData); + } } else { - // A new data. - insertData(newData); + Log.e(TAG, "video data not found"); } } diff --git a/src/com/android/camera/data/LocalMediaData.java b/src/com/android/camera/data/LocalMediaData.java index 1f9c725d0..bb451fa0f 100644 --- a/src/com/android/camera/data/LocalMediaData.java +++ b/src/com/android/camera/data/LocalMediaData.java @@ -636,6 +636,14 @@ public abstract class LocalMediaData implements LocalData { int height = c.getInt(COL_HEIGHT); MediaMetadataRetriever retriever = new MediaMetadataRetriever(); String rotation = null; + + File origFile = new File(path); + if (!origFile.exists() || origFile.length() <= 0) { + Log.e(TAG, "Invalid video file"); + retriever.release(); + return null; + } + try { retriever.setDataSource(path); } catch (RuntimeException ex) { -- cgit v1.2.3