在做展讯平板开发的时候,突然发现前置摄像头闪光灯打开时,拍照会白屏一下,然后拍照保存到相册 ,应该是闪光灯的bug.鉴于Camera2有点难调
所以就觉得前置摄像头去掉闪光灯功能
Camera2 app的路径为:
vendor\sprd\platform\packages\apps\DreamCamera2
而PhotoModule.java作为拍照的Module类 就先从这里寻找解决入口
vendor/sprd/platform/packages/apps/DreamCamera2/src/com/android/camera/PhotoModule.java
先看代码分析问题先:
/**
* The start/stop preview should only run on the UI thread.
*/
protected void startPreview(boolean optimize) {
if (mCameraDevice == null) {
Log.i(TAG, "attempted to start preview before camera device");
// do nothing
return;
}
if (!checkPreviewPreconditions()) {
updateSettingAfterOpencamera(true);
settingchange = true;
return;
}
// ui
/* SPRD: add for bug 380597: switch camera preview has a frame error @{ */
mActivity.getCameraAppUI().resetPreview();
/* @} */
if(settingchange){
settingchange = false;
} else {
updateSettingAfterOpencamera(optimize);
}
dosetPreviewDisplayspecial();
if (isUseSurfaceView()) {
if (optimize) {
mCameraDevice.setPreviewDisplay(mActivity.getCameraAppUI().getSurfaceHolder());
} else {
mCameraDevice.setPreviewDisplayWithoutOptimize(mActivity.getCameraAppUI().getSurfaceHolder());
}
} else {
if (optimize) {
mCameraDevice.setPreviewTexture(mActivity.getCameraAppUI().getSurfaceTexture());
} else {
mCameraDevice.setPreviewTextureWithoutOptimize(mActivity.getCameraAppUI()
.getSurfaceTexture());
}
}
if (CameraUtil.isSensorSelfShotEnable()
|| CameraUtil.getCurrentBackBlurRefocusVersion() == CameraUtil.BLUR_REFOCUS_VERSION_3
|| isBackRealDualCamVersion()
|| CameraUtil.getCurrentBlurCoveredId() != CameraUtil.BLUR_COVERED_ID_OFF) {
mCameraDevice.setSensorSelfShotCallback(mHandler, this);
}
// SPRD: Fix bug 677589 black preview occurs when we switch to video module from photo
// no need to handle surface update in process of the second onPreviewStarted()
final boolean handleSurfaceUpdate = !mPreviewing;
// If we're using API2 in portability layers, don't use
// startPreviewWithCallback()
// b/17576554
CameraAgent.CameraStartPreviewCallback startPreviewCallback = new CameraAgent.CameraStartPreviewCallback() {
@Override
public void onPreviewStarted() {
mHandler.post(new Runnable() {
public void run() {
mFocusManager.onPreviewStarted();
PhotoModule.this.onPreviewStarted();
}
});
if (mSnapshotOnIdle) {
mHandler.post(mDoSnapRunnable);
}
if(!isUseSurfaceView() || mHandler == null) {
return;
}
if (!handleSurfaceUpdate) {
return;
}
final Runnable hideModeCoverRunnable = new Runnable() {
@Override
public void run() {
if (!mPaused) {
final CameraAppUI cameraAppUI = mActivity.getCameraAppUI();
cameraAppUI.onSurfaceTextureUpdated(cameraAppUI.getSurfaceTexture());
cameraAppUI.pauseTextureViewRendering();
}
}
};
final Runnable takePictureRunnable = new Runnable() {
@Override
public void run() {
if (!mPaused) {
if (mActivity.getVoiceIntentCamera() && !mActivity.getOpenCameraOnly()) {
mDataModuleCurrent
.set(Keys.KEY_VOICE_COUNTDOWN_DURATION,mActivity.getTimeDurationS());
onShutterButtonClick();
setCaptureCount(0);
}
}
}
};
if (useNewApi()) {
mCameraDevice.setSurfaceViewPreviewCallback(
new CameraAgent.CameraSurfaceViewPreviewCallback() {
@Override
public void onSurfaceUpdate() {
Log.d(TAG, "SurfaceView: CameraSurfaceViewPreviewCallback");
if (mPaused || mCameraDevice == null) {//SPRD:fix bug681598
return;
}
mActivity.getCameraAppUI().hideModeCover();
mHandler.post(hideModeCoverRunnable);
Log.d(TAG,"Keys.KEY_VOICE_CAMERA_DONE is "+mDataModuleCurrent.getInt(Keys.KEY_VOICE_CAMERA_DONE,0));
if (mActivity.getVoiceIntentCamera() && mDataModuleCurrent.getInt(Keys.KEY_VOICE_CAMERA_DONE,0) != 1) {
mHandler.post(takePictureRunnable);
}
// set callback to null
mCameraDevice.setSurfaceViewPreviewCallback(null);
}
});
} else {
mHandler.postDelayed(hideModeCoverRunnable, 450);
}
}
};
doStartPreviewSpecial(isCameraIdle(), isHdr(), mActivity, mCameraDevice, mHandler,
mDisplayOrientation, isCameraFrontFacing(), mUI.getRootView(), mCameraSettings);//SPRD:fix bug624871
doStartPreview(startPreviewCallback, mCameraDevice);
if(getModuleTpye() != DreamModule.AUDIOPICTURE_MODULE||!isShutterClicked())
mAppController.getCameraAppUI().setBottomPanelLeftRightClickable(true);
Log.i(TAG, "startPreview end!");
}
从上面代码中可以看到 在摄像头预览中回调中调用 doStartPreview();
这方法 接下来看doStartPreview();
protected void doStartPreview(CameraAgent.CameraStartPreviewCallback startPreviewCallback, CameraAgent.CameraProxy cameraDevice) {
if (useNewApi()) {
mCameraDevice.startPreview();
startPreviewCallback.onPreviewStarted();
} else {
mCameraDevice.startPreviewWithCallback(new Handler(Looper.getMainLooper()),
startPreviewCallback);
}
mPreviewing = true;
// SPRD: Fix bug 659315, optimize camera launch time
mUI.onPreviewStarted();
//SPRD: Fix bug 1200379
if(mUI instanceof ManualPhotoUI){
((ManualPhotoUI) mUI).setManualControlEnable(true);
}
mActivity.getButtonManager().enableCameraButton();// SPRD: Fix bug839922, switch icon is disabled
OrientationManager orientationManager = mAppController
.getOrientationManager();
orientationManager.addOnOrientationChangeListener(this);
mUI.onOrientationChanged(orientationManager,
orientationManager.getDeviceOrientation());
}
而这里有调用了 PhotoUI 的onPreviewStarted()方法
路径为 :vendor/sprd/platform/packages/apps/DreamCamera2/src/com/android/camera/PhotoUI.java
public void onPreviewStarted() {
long start = System.currentTimeMillis();
if (mHasDelayWorkO