diff options
author | Linux Build Service Account <lnxbuild@localhost> | 2014-06-20 10:48:55 -0700 |
---|---|---|
committer | Gerrit - the friendly Code Review server <code-review@localhost> | 2014-06-20 10:48:55 -0700 |
commit | 5bf10cc095044440c95c704307c79370f0510f6c (patch) | |
tree | b995315c4f1cf785bae1c275bf94c8ebcfdccbee | |
parent | cfe9d2fa84f969a5e70bf82f8df45a9f252b8f98 (diff) | |
parent | 3d391b59b85e551ed8c773d9c3b97380448e326b (diff) | |
download | android_packages_apps_Snap-5bf10cc095044440c95c704307c79370f0510f6c.tar.gz android_packages_apps_Snap-5bf10cc095044440c95c704307c79370f0510f6c.tar.bz2 android_packages_apps_Snap-5bf10cc095044440c95c704307c79370f0510f6c.zip |
Merge "Camera2: Check memory status when in longshot mode"
-rw-r--r-- | res/values/qcomstrings.xml | 1 | ||||
-rw-r--r-- | src/com/android/camera/PhotoModule.java | 55 |
2 files changed, 55 insertions, 1 deletions
diff --git a/res/values/qcomstrings.xml b/res/values/qcomstrings.xml index b54fb1f91..5314b70f0 100644 --- a/res/values/qcomstrings.xml +++ b/res/values/qcomstrings.xml @@ -662,6 +662,7 @@ <!-- longshot value --> <string name="pref_camera_longshot_default" translatable="false">off</string> <string name="pref_camera_longshot_title">Continuous Shot</string> + <string name="msg_cancel_longshot_for_limited_memory">run out of memory, canceling longshot</string> <!-- Toast showing non-supported functionality for flash in AE bracket --> <string name="flash_aebracket_message">Flash is not supported in AE-Bracket Mode</string> diff --git a/src/com/android/camera/PhotoModule.java b/src/com/android/camera/PhotoModule.java index 5d92c75c9..595707c56 100644 --- a/src/com/android/camera/PhotoModule.java +++ b/src/com/android/camera/PhotoModule.java @@ -76,6 +76,9 @@ import com.android.camera.util.GcamHelper; import com.android.camera.util.UsageStatistics; import com.android.camera2.R; +import com.android.internal.util.MemInfoReader; +import android.app.ActivityManager; + import java.io.File; import java.io.FileNotFoundException; import java.io.FileOutputStream; @@ -225,6 +228,16 @@ public class PhotoModule private Uri mDebugUri; + // Used for check memory status for longshot mode + // Currently, this cancel threshold selection is based on test experiments, + // we can change it based on memory status or other requirements. + private static final int LONGSHOT_CANCEL_THRESHOLD = 40; + private MemInfoReader mMemInfoReader = new MemInfoReader(); + private ActivityManager mAm; + private long SECONDARY_SERVER_MEM; + private long mMB = 1024 * 1024; + private boolean mLongshotActive = false; + // We use a queue to generated names of the images to be used later // when the image is ready to be saved. private NamedImages mNamedImages; @@ -469,6 +482,7 @@ public class PhotoModule mCameraId = getPreferredCameraId(mPreferences); mContentResolver = mActivity.getContentResolver(); + mAm = (ActivityManager)(mActivity.getSystemService(Context.ACTIVITY_SERVICE)); // Surface texture is from camera screen nail and startPreview needs it. // This must be done before startPreview. @@ -500,6 +514,10 @@ public class PhotoModule Storage.setSaveSDCard( mPreferences.getString(CameraSettings.KEY_CAMERA_SAVEPATH, "0").equals("1")); + ActivityManager.MemoryInfo memInfo = new ActivityManager.MemoryInfo(); + mAm.getMemoryInfo(memInfo); + SECONDARY_SERVER_MEM = memInfo.secondaryServerThreshold; + } private void initializeControlByIntent() { @@ -805,6 +823,29 @@ public class PhotoModule } } + private boolean isLongshotNeedCancel() { + + long totalMemory = Runtime.getRuntime().totalMemory() / mMB; + long maxMemory = Runtime.getRuntime().maxMemory() / mMB; + long remainMemory = maxMemory - totalMemory; + + mMemInfoReader.readMemInfo(); + long availMem = mMemInfoReader.getFreeSize() + mMemInfoReader.getCachedSize() + - SECONDARY_SERVER_MEM; + availMem = availMem/ mMB; + + if(availMem <= 0 || + remainMemory <= LONGSHOT_CANCEL_THRESHOLD) { + Log.d(TAG, "memory used up, need cancel longshot."); + mLongshotActive = false; + Toast.makeText(mActivity,R.string.msg_cancel_longshot_for_limited_memory, + Toast.LENGTH_SHORT).show(); + return true; + } + + return false; + } + private final class LongshotShutterCallback implements CameraShutterCallback { @@ -815,7 +856,12 @@ public class PhotoModule Log.e(TAG, "[KPI Perf] PROFILE_SHUTTER_LAG mShutterLag = " + mShutterLag + "ms"); synchronized(mCameraDevice) { - if (mCameraState != LONGSHOT) { + if (mCameraState != LONGSHOT || + !mLongshotActive) { + return; + } + + if(isLongshotNeedCancel()) { return; } @@ -1737,6 +1783,7 @@ public class PhotoModule synchronized(mCameraDevice) { if (mCameraState == LONGSHOT) { + mLongshotActive = false; mCameraDevice.setLongshot(false); if (!mFocusManager.isZslEnabled()) { setupPreview(); @@ -1846,6 +1893,12 @@ public class PhotoModule if (longshot_enable.equals("on")) { boolean enable = SystemProperties.getBoolean(PERSIST_LONG_SAVE, false); mLongshotSave = enable; + + //check whether current memory is enough for longshot. + if(isLongshotNeedCancel()) { + return; + } + mLongshotActive = true; mCameraDevice.setLongshot(true); setCameraState(PhotoController.LONGSHOT); mFocusManager.doSnap(); |