From 996546fcf4058d98d9aceecb4086283e17ae6c9d Mon Sep 17 00:00:00 2001 From: Lingfeng Yang Date: Wed, 27 Apr 2016 09:12:25 -0700 Subject: Prevent camera app crashes on changing hw.camera.* settings If the AVD's config.ini changes hw.camera.*, this is effectively, connecting/disconnecting camera hardware, and the current way in which camera settings are handled assumes that the set of cameras never changes, which can lead to the camera app crashing if the camera app was used successfuly with one configuration of hw.camera.* and then the AVD was restarted with a different configuration. In particular, the crash happens if the number of cameras has been reduced since the last run, and the camera app is looking up a preferred camera ID that is not supported by the new number of cameras. bug: 28417929 BUG: https://code.google.com/p/android/issues/detail?id=206945 Change-Id: Ib0e26ae77d376f31f3cc281e386d3c67291c1edc (cherry picked from commit 8f339abd9245577c348f5ba22322e8801c21faf8) --- src/com/android/camera/Camera.java | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/src/com/android/camera/Camera.java b/src/com/android/camera/Camera.java index 2ca7944..b50ab18 100644 --- a/src/com/android/camera/Camera.java +++ b/src/com/android/camera/Camera.java @@ -1085,7 +1085,21 @@ public class Camera extends ActivityBase implements FocusManager.Listener, private void getPreferredCameraId() { mPreferences = new ComboPreferences(this); CameraSettings.upgradeGlobalPreferences(mPreferences.getGlobal()); - mCameraId = CameraSettings.readPreferredCameraId(mPreferences); + + mNumberOfCameras = CameraHolder.instance().getNumberOfCameras(); + int attemptedCameraId = CameraSettings.readPreferredCameraId(mPreferences); + + // It is possible that the user can connect/disconnect cameras + // between device boots. + // We need to check that the preferred camera ID + // does not refer to a disconnected camera. + if (attemptedCameraId >= mNumberOfCameras) { + Log.v(TAG, "Preferred camera (id= " + attemptedCameraId + + ") missing. Defaulting to the first one"); + mCameraId = 0; + } else { + mCameraId = attemptedCameraId; + } // Testing purpose. Launch a specific camera through the intent extras. int intentCameraId = Util.getCameraFacingIntentExtras(this); @@ -1144,7 +1158,6 @@ public class Camera extends ActivityBase implements FocusManager.Listener, mPreferences.setLocalId(this, mCameraId); CameraSettings.upgradeLocalPreferences(mPreferences.getLocal()); - mNumberOfCameras = CameraHolder.instance().getNumberOfCameras(); mQuickCapture = getIntent().getBooleanExtra(EXTRA_QUICK_CAPTURE, false); // we need to reset exposure for the preview -- cgit v1.1 From a00c8e757493669d38c16e767e7d18712ffe4a41 Mon Sep 17 00:00:00 2001 From: Chih-Hung Hsieh Date: Thu, 12 May 2016 10:19:46 -0700 Subject: Fix misc-macro-parentheses warnings. Bug: 28705665 Change-Id: I034d8a7ff0ca6dbe179f5362f601cffc5b9522cf --- jni/feature_mos/src/mosaic/Delaunay.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/jni/feature_mos/src/mosaic/Delaunay.cpp b/jni/feature_mos/src/mosaic/Delaunay.cpp index 0ce09fc..82f5d20 100644 --- a/jni/feature_mos/src/mosaic/Delaunay.cpp +++ b/jni/feature_mos/src/mosaic/Delaunay.cpp @@ -24,7 +24,7 @@ #define QQ 9 // Optimal value as determined by testing #define DM 38 // 2^(1+DM/2) element sort capability. DM=38 for >10^6 elements -#define NYL -1 +#define NYL (-1) #define valid(l) ccw(orig(basel), dest(l), dest(basel)) -- cgit v1.1 From 54fe973a8100a994a111112416e906c17bc342e7 Mon Sep 17 00:00:00 2001 From: Chih-Hung Hsieh Date: Wed, 29 Jun 2016 11:46:40 -0700 Subject: Fix misc-macro-parentheses warnings in LegacyCamera. Add parentheses around negative literals and parameters beside operators. Bug: 28705665 Test: build with clang-tidy Change-Id: I137330a75fecd571ad6444ebde3d9c5c70e15ef1 --- jni/feature_stab/db_vlvm/db_utilities_constants.h | 2 +- jni/feature_stab/src/dbreg/vp_motionmodel.h | 34 +++++++++++------------ 2 files changed, 18 insertions(+), 18 deletions(-) diff --git a/jni/feature_stab/db_vlvm/db_utilities_constants.h b/jni/feature_stab/db_vlvm/db_utilities_constants.h index 07565ef..612fc78 100644 --- a/jni/feature_stab/db_vlvm/db_utilities_constants.h +++ b/jni/feature_stab/db_vlvm/db_utilities_constants.h @@ -64,7 +64,7 @@ #define DB_DEFAULT_ABS_CORNER_THRESHOLD 50000000.0 #define DB_DEFAULT_REL_CORNER_THRESHOLD 0.00005 #define DB_DEFAULT_MAX_DISPARITY 0.1 -#define DB_DEFAULT_NO_DISPARITY -1.0 +#define DB_DEFAULT_NO_DISPARITY (-1.0) #define DB_DEFAULT_MAX_TRACK_LENGTH 300 #define DB_DEFAULT_MAX_NR_CAMERAS 1000 diff --git a/jni/feature_stab/src/dbreg/vp_motionmodel.h b/jni/feature_stab/src/dbreg/vp_motionmodel.h index a63ac00..71a7f7e 100644 --- a/jni/feature_stab/src/dbreg/vp_motionmodel.h +++ b/jni/feature_stab/src/dbreg/vp_motionmodel.h @@ -120,7 +120,7 @@ enum VP_MOTION_MODEL { VP_VFE_AFFINE=120 }; -#define VP_REFID -1 /* Default ID used for reference frame */ +#define VP_REFID (-1) /* Default ID used for reference frame */ typedef struct { VP_TRS par; /* Contains the motion paramerers. @@ -205,16 +205,16 @@ typedef struct { /* Warp a 2d point (assuming the z component is zero) */ #define VP_WARP_POINT_2D(inx,iny,m,outx,outy) do {\ VP_PAR vpTmpWarpPnt___= MWX(m)*(inx)+MWY(m)*(iny)+MWW(m); \ - outx = (MXX(m)*((VP_PAR)inx)+MXY(m)*((VP_PAR)iny)+MXW(m))/vpTmpWarpPnt___; \ - outy = (MYX(m)*((VP_PAR)inx)+MYY(m)*((VP_PAR)iny)+MYW(m))/vpTmpWarpPnt___; } while (0) + (outx) = (MXX(m)*((VP_PAR)(inx))+MXY(m)*((VP_PAR)(iny))+MXW(m))/vpTmpWarpPnt___; \ + (outy) = (MYX(m)*((VP_PAR)(inx))+MYY(m)*((VP_PAR)(iny))+MYW(m))/vpTmpWarpPnt___; } while (0) /* Warp a 3d point */ #define VP_WARP_POINT_3D(inx,iny,inz,m,outx,outy,outz) do {\ - VP_PAR vpTmpWarpPnt___= MWX(m)*(inx)+MWY(m)*(iny)+MWZ(m)*((VP_PAR)inz)+MWW(m); \ - outx = (MXX(m)*((VP_PAR)inx)+MXY(m)*((VP_PAR)iny)+MXZ(m)*((VP_PAR)inz)+MXW(m))/vpTmpWarpPnt___; \ - outy = (MYX(m)*((VP_PAR)inx)+MYY(m)*((VP_PAR)iny)+MYZ(m)*((VP_PAR)inz)+MYW(m))/vpTmpWarpPnt___; \ - outz = MZX(m)*((VP_PAR)inx)+MZY(m)*((VP_PAR)iny)+MZZ(m)*((VP_PAR)inz)+MZW(m); \ - if ((m).type==VP_MOTION_PROJ_3D) outz/=vpTmpWarpPnt___; } while (0) + VP_PAR vpTmpWarpPnt___= MWX(m)*(inx)+MWY(m)*(iny)+MWZ(m)*((VP_PAR)(inz))+MWW(m); \ + (outx) = (MXX(m)*((VP_PAR)(inx))+MXY(m)*((VP_PAR)(iny))+MXZ(m)*((VP_PAR)(inz))+MXW(m))/vpTmpWarpPnt___; \ + (outy) = (MYX(m)*((VP_PAR)(inx))+MYY(m)*((VP_PAR)(iny))+MYZ(m)*((VP_PAR)(inz))+MYW(m))/vpTmpWarpPnt___; \ + (outz) = MZX(m)*((VP_PAR)(inx))+MZY(m)*((VP_PAR)(iny))+MZZ(m)*((VP_PAR)(inz))+MZW(m); \ + if ((m).type==VP_MOTION_PROJ_3D) (outz)/=vpTmpWarpPnt___; } while (0) /* Projections of each component */ #define VP_PROJW_3D(m,x,y,z,f) ( MWX(m)*(x)+MWY(m)*(y)+MWZ(m)*(z)+MWW(m) ) @@ -224,15 +224,15 @@ typedef struct { /* Scale Down a matrix by Sfactor */ #define VP_SCALEDOWN(m,Sfactor) do { \ - MXW(m) /= (VP_PAR)Sfactor; MWX(m) *= (VP_PAR)Sfactor; \ - MYW(m) /= (VP_PAR)Sfactor; MWY(m) *= (VP_PAR)Sfactor; \ - MZW(m) /= (VP_PAR)Sfactor; MWZ(m) *= (VP_PAR)Sfactor; } while (0) + MXW(m) /= (VP_PAR)(Sfactor); MWX(m) *= (VP_PAR)(Sfactor); \ + MYW(m) /= (VP_PAR)(Sfactor); MWY(m) *= (VP_PAR)(Sfactor); \ + MZW(m) /= (VP_PAR)(Sfactor); MWZ(m) *= (VP_PAR)(Sfactor); } while (0) /* Scale Up a matrix by Sfactor */ #define VP_SCALEUP(m,Sfactor) do { \ - MXW(m) *= (VP_PAR)Sfactor; MWX(m) /= (VP_PAR)Sfactor; \ - MYW(m) *= (VP_PAR)Sfactor; MWY(m) /= (VP_PAR)Sfactor; \ - MZW(m) *= (VP_PAR)Sfactor; MWZ(m) /= (VP_PAR)Sfactor; } while (0) + MXW(m) *= (VP_PAR)(Sfactor); MWX(m) /= (VP_PAR)(Sfactor); \ + MYW(m) *= (VP_PAR)(Sfactor); MWY(m) /= (VP_PAR)(Sfactor); \ + MZW(m) *= (VP_PAR)(Sfactor); MWZ(m) /= (VP_PAR)(Sfactor); } while (0) /* Normalize the transformation matrix so that MWW is 1 */ #define VP_NORMALIZE(m) if (MWW(m)!=(VP_PAR)0.0) do { \ @@ -253,15 +253,15 @@ typedef struct { /* w' projection given a point x,y,0,f */ #define VP_PROJZ(m,x,y,f) ( \ - MWX(m)*((VP_PAR)x)+MWY(m)*((VP_PAR)y)+MWW(m)*((VP_PAR)f)) + MWX(m)*((VP_PAR)(x))+MWY(m)*((VP_PAR)(y))+MWW(m)*((VP_PAR)(f))) /* X Projection given a point x,y,0,f and w' */ #define VP_PROJX(m,x,y,w,f) (\ - (MXX(m)*((VP_PAR)x)+MXY(m)*((VP_PAR)y)+MXW(m)*((VP_PAR)f))/((VP_PAR)w)) + (MXX(m)*((VP_PAR)(x))+MXY(m)*((VP_PAR)(y))+MXW(m)*((VP_PAR)(f)))/((VP_PAR)(w))) /* Y Projection given a point x,y,0,f and the w' */ #define VP_PROJY(m,x,y,w,f) (\ - (MYX(m)*((VP_PAR)x)+MYY(m)*((VP_PAR)y)+MYW(m)*((VP_PAR)f))/((VP_PAR)w)) + (MYX(m)*((VP_PAR)(x))+MYY(m)*((VP_PAR)(y))+MYW(m)*((VP_PAR)(f)))/((VP_PAR)(w))) /* Set the reference id for a motion */ #define VP_SET_REFID(m,id) do { (m).refid=id; } while (0) -- cgit v1.1