[Wi-Fi] Release the camera before opening
As per the Google's design mentioned at https://developer.android.com/training/camera/cameradirect.html Calling Camera.open() throws an exception if the camera is already in use by another application, so we wrap it in a try block one must release the camera before opening Bug: 141662635 Test: Manual occurs once while testing 10 times 1.Open wifi settings,tap QR code icon 2.Make a incoming VoLTE call,tap incoming VoLTE call dialog 3.Check device Signed-off-by: JeiFeng Lee <linger.lee@mediatek.com> Change-Id: Ief62600af8b745cb4eae2e5ae277a2cebdda68eb
This commit is contained in:
@@ -288,32 +288,43 @@ public class QrCamera extends Handler {
|
|||||||
for (int i = 0; i < numberOfCameras; ++i) {
|
for (int i = 0; i < numberOfCameras; ++i) {
|
||||||
Camera.getCameraInfo(i, cameraInfo);
|
Camera.getCameraInfo(i, cameraInfo);
|
||||||
if (cameraInfo.facing == CameraInfo.CAMERA_FACING_BACK) {
|
if (cameraInfo.facing == CameraInfo.CAMERA_FACING_BACK) {
|
||||||
|
releaseCamera();
|
||||||
mCamera = Camera.open(i);
|
mCamera = Camera.open(i);
|
||||||
mCamera.setPreviewTexture(surface);
|
|
||||||
mCameraOrientation = cameraInfo.orientation;
|
mCameraOrientation = cameraInfo.orientation;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (mCamera == null) {
|
} catch (RuntimeException e) {
|
||||||
Log.e(TAG, "Cannot find available back camera.");
|
Log.e(TAG, "Fail to open camera: " + e);
|
||||||
mScannerCallback.handleCameraFailure();
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
setCameraParameter();
|
|
||||||
setTransformationMatrix();
|
|
||||||
if (!startPreview()) {
|
|
||||||
Log.e(TAG, "Error to init Camera");
|
|
||||||
mCamera = null;
|
|
||||||
mScannerCallback.handleCameraFailure();
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
return true;
|
|
||||||
} catch (IOException e) {
|
|
||||||
Log.e(TAG, "Error to init Camera");
|
|
||||||
mCamera = null;
|
mCamera = null;
|
||||||
mScannerCallback.handleCameraFailure();
|
mScannerCallback.handleCameraFailure();
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
if (mCamera == null) {
|
||||||
|
throw new IOException("Cannot find available back camera");
|
||||||
|
}
|
||||||
|
mCamera.setPreviewTexture(surface);
|
||||||
|
setCameraParameter();
|
||||||
|
setTransformationMatrix();
|
||||||
|
if (!startPreview()) {
|
||||||
|
throw new IOException("Lost contex");
|
||||||
|
}
|
||||||
|
} catch (IOException ioe) {
|
||||||
|
Log.e(TAG, "Fail to startPreview camera: " + ioe);
|
||||||
|
mCamera = null;
|
||||||
|
mScannerCallback.handleCameraFailure();
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void releaseCamera() {
|
||||||
|
if (mCamera != null) {
|
||||||
|
mCamera.release();
|
||||||
|
mCamera = null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user