Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

MultiCamera App Changes for Coverity Fix #46

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 0 additions & 14 deletions camera/MultiCameraApplication/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -28,20 +28,6 @@
android:label="@string/app_name"
android:theme="@style/AppTheme.NoActionBar"
/>
<activity
android:name=".CtsCameraIntentsActivity"
android:excludeFromRecents="true"
android:exported="false"
android:theme="@style/AppTheme.NoActionBar">
<intent-filter>
<action android:name="android.media.action.IMAGE_CAPTURE" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
<intent-filter>
<action android:name="android.media.action.VIDEO_CAPTURE" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>

<activity
android:name=".FullScreenActivity"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,14 +74,12 @@ public class CameraBase {
* An {@link AutoFitTextureView} for camera preview.
*/
private AutoFitTextureView textureView;
private ImageButton FullScrn, SettingsView, takePictureButton, TakeVideoButton;

private ImageButton SettingsView, takePictureButton, TakeVideoButton;
private String cameraId;
private CameraDevice mCameraDevice;
private CameraCaptureSession cameraCaptureSessions;
private CaptureRequest.Builder captureRequestBuilder;
private Size previewSize;
private ImageReader imageReader;
private Handler mBackgroundHandler;
private HandlerThread mBackgroundThread;
private static final SparseIntArray ORIENTATIONS = new SparseIntArray();
Expand Down Expand Up @@ -115,8 +113,6 @@ public class CameraBase {

static final Size SIZE_720P = new Size(1280, 720);
static final Size SIZE_480P = new Size(640, 480);

private RoundedThumbnailView mRoundedThumbnailView;
FrameLayout roundedThumbnailViewControlLayout;

private String[] ImageFileDetails;
Expand All @@ -126,10 +122,10 @@ public CameraBase(Activity activity, AutoFitTextureView mtextureView, ImageButto
RoundedThumbnailView roundedThumbnailView) {
this.mActivity = activity;
this.textureView = mtextureView;
mBackgroundHandler=null;
if (Button != null) {
this.ClickListeners(Button[0], Button[1], Button[2], Button[4], Button[5]);
SettingsView = Button[2];
FullScrn = Button[3];
}
this.settings = PreferenceManager.getDefaultSharedPreferences(activity);
cameraId = data[1];
Expand Down Expand Up @@ -201,7 +197,6 @@ public void onClick(View v) {
Toast.makeText(mActivity, "camera split clicked ", Toast.LENGTH_LONG).show();
System.out.println("camera split");
MultiCamera ic_camera = MultiCamera.getInstance();
MultiViewActivity Mactivity = (MultiViewActivity) mActivity;
if (ic_camera.getIsCameraOrSurveillance() == 0) {
ic_camera.setIsCameraOrSurveillance(1);
Intent intent = new Intent(mActivity, MultiViewActivity.class);
Expand Down Expand Up @@ -530,11 +525,6 @@ public void run() {
System.out.println(TAG +" camera close exception");
}

if (null != imageReader) {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this wont create leak ?

imageReader.close();
imageReader = null;
}

mRecord.releaseMedia();

} catch (Exception e) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,6 @@ public class CtsCamIntents {
protected CameraCaptureSession cameraCaptureSessions;
protected CaptureRequest.Builder captureRequestBuilder;
private Size previewSize;
private ImageReader imageReader;
private File file;
private Handler mBackgroundHandler;
private HandlerThread mBackgroundThread;
Expand Down Expand Up @@ -103,7 +102,7 @@ public class CtsCamIntents {
// The video file that the hardware camera is about to record into
// (or is recording into.
private String mVideoFilename, mPictureFilename;
private ContentValues mCurrentVideoValues, mCurrentPictureValues;
private ContentValues mCurrentPictureValues;
byte[] jpegLength;

private boolean mIsVideoCaptureIntent, mIsImageCaptureIntent;
Expand Down Expand Up @@ -480,10 +479,6 @@ public void closeCamera() {
cameraDevice.close();
cameraDevice = null;
}
if (null != imageReader) {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same here, it wont create leak ?

imageReader.close();
imageReader = null;
}
if (null != mMediaRecorder) {
releaseMedia();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -189,6 +189,7 @@ public View getView(int position, View convertView, ViewGroup parent) {
tv = (TextView)LayoutInflater.from(mContext).inflate(R.layout.details, parent,
false);
} else {
assert convertView instanceof TextView : convertView;//Coverity Fix: Asserted View is TextView here
tv = (TextView)convertView;
}
tv.setText(mItems.get(position));
Expand Down Expand Up @@ -234,9 +235,9 @@ private String toLocalNumber(int n) {
}

/** Converts the given double to a localized String version. */
private String toLocalNumber(double n) {
/*private String toLocalNumber(double n) {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

remove this commented code, if not used

return mDecimalFormat.format(n);
}
}*/
}

public static String getDetailsName(Context context, int key) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@
import java.io.File;
import java.util.Optional;
import java.util.concurrent.TimeUnit;
import java.util.Objects;

import static com.intel.multicamera.MultiViewActivity.updateStorageSpace;

Expand Down Expand Up @@ -106,6 +107,7 @@ protected void onCreate(Bundle savedInstanceState) {

checkPermissions();


Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

remove newly added unwanted line

OpenCamera();
try {
final IntentFilter filter = new IntentFilter();
Expand Down Expand Up @@ -165,6 +167,7 @@ public void onReceive(Context context, Intent intent) {

registerReceiver(mUsbReceiver , filter);
} catch (Exception e) {
Log.e(TAG, "Exception OnCreate()");
}

mCameraSwitch.setOnClickListener(new View.OnClickListener() {
Expand Down Expand Up @@ -228,7 +231,6 @@ public void onClick(View v) {
public void onClick(View v) {

getFragmentManager().beginTransaction().remove(Fragment).commit();
MultiCamera ic_camera = MultiCamera.getInstance();
v.setVisibility(v.GONE);
mSettings.setVisibility(View.VISIBLE);

Expand Down Expand Up @@ -344,7 +346,6 @@ private void closeCamera() {
}
}


public void GetCameraCnt() {
CameraManager manager = (CameraManager)getSystemService(Context.CAMERA_SERVICE);

Expand All @@ -367,15 +368,17 @@ private void Open_Camera() {
Log.e(TAG, "fail to find surface for back camera");
return;
}
if (mCamera == null) {
if (Objects.isNull(mCamera))
{
Open_Camera_ById();
}
if (mCamera_BackView.isAvailable()) {
mCamera.textureListener.onSurfaceTextureAvailable(
mCamera_BackView.getSurfaceTexture(), mCamera_BackView.getWidth(),
mCamera_BackView.getHeight());
} else {
mCamera_BackView.setSurfaceTextureListener(mCamera.textureListener);
if(mCamera != null)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can use Objects.isNull

mCamera_BackView.setSurfaceTextureListener(mCamera.textureListener);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
import androidx.core.app.ActivityCompat;
import java.io.IOException;
import java.util.concurrent.TimeUnit;
import java.util.Objects;

public class MultiViewActivity extends AppCompatActivity {
private static final String TAG = "MultiViewActivity";
Expand Down Expand Up @@ -524,7 +525,7 @@ private void manageTopLeftCam() {
mTopLeftCam_textureView.getHeight());
}
} else {
if (ic_camera.getTopLeftCam() != null && mTopLeftCam_textureView != null) {
if(ic_camera.getTopLeftCam() != null ){
mTopLeftCam_textureView.setSurfaceTextureListener(
ic_camera.getTopLeftCam().textureListener);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@

public class PhotoPreview {
private static final String TAG = "PhotoPreview";
private Uri mCurrentUri;

private MultiCamera ic_camera;
private RoundedThumbnailView mRoundedThumbnailView;
Expand Down Expand Up @@ -102,16 +101,19 @@ public void onClick(View v) {

@Override
public void onClick(View v) {
preView = mActivity.findViewById(R.id.preview);

Uri uri = ic_camera.getCurrentUri();
File file = new File(ic_camera.getImagePath());
if (file.exists()) {
Log.v(TAG, " Thumbnail Preview File Deleted ");
file.delete();

boolean isSuccess = file.delete();
if(!isSuccess)
{
Log.e(TAG,"file.delete() failed ");
}
// request scan
Intent scanIntent = new Intent(Intent.ACTION_MEDIA_SCANNER_SCAN_FILE);
scanIntent.setData(Uri.fromFile(file));
scanIntent.setPackage(mActivity.getPackageName()); //To check
mActivity.sendBroadcast(scanIntent);
FrameLayout previewLayout;
previewLayout = mActivity.findViewById(R.id.previewLayout);
Expand Down Expand Up @@ -172,7 +174,6 @@ public void onClick(View v) {
}

private void photoPreview(ImageButton playButton, ImageView preView) {
Uri PhotoUri = ic_camera.getCurrentUri();

preView.setVisibility(View.VISIBLE);
playButton.setVisibility(View.GONE);
Expand Down Expand Up @@ -210,7 +211,7 @@ private int getOrientation(int rotation) {
CameraCharacteristics characteristics = manager.getCameraCharacteristics(mCameraId);
mSensorOrientation = characteristics.get(CameraCharacteristics.SENSOR_ORIENTATION);
} catch (Exception e) {

Log.e(TAG, "getOrientation Issue: ");
}
return (ORIENTATIONS.get(rotation) + mSensorOrientation + 270) % 360;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -326,8 +326,8 @@ protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
protected void onDraw(Canvas canvas) {
super.onDraw(canvas);

final float centerX = canvas.getWidth() / 2;
final float centerY = canvas.getHeight() / 2;
final float centerX = ((float)canvas.getWidth()) / 2;
final float centerY = ((float)canvas.getHeight()) / 2;

final float viewDiameter = mRippleRingDiameterEnd;
final float finalDiameter = mThumbnailShrinkDiameterEnd;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,7 @@
import androidx.preference.PreferenceFragment;

public class SettingsActivity extends AppCompatActivity {
private String TAG = "settings";


Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

remove

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
Expand Down Expand Up @@ -74,4 +73,4 @@ public void onPause() {
public void onSharedPreferenceChanged(SharedPreferences sharedPreferences, String Key) {
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@

import java.util.Optional;
import java.util.concurrent.TimeUnit;
import java.util.Objects;

import static android.hardware.usb.UsbManager.ACTION_USB_DEVICE_ATTACHED;
import static com.intel.multicamera.MultiViewActivity.updateStorageSpace;
Expand Down Expand Up @@ -99,6 +100,7 @@ protected void onCreate(Bundle savedInstanceState) {
mRoundedThumbnailView = findViewById(R.id.rounded_thumbnail_view);

checkPermissions();

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

remove

OpenCamera();
try {
final IntentFilter filter = new IntentFilter();
Expand Down Expand Up @@ -260,7 +262,6 @@ public void onClick(View v) {
mSettingClose.setVisibility(View.VISIBLE);

bundle = new Bundle();
MultiCamera ic_camera = MultiCamera.getInstance();
bundle.putString("Camera_id", CameraIds[0]);
bundle.putInt("root_preferences", R.xml.root_preferences);
bundle.putString("pref_resolution", "pref_resolution");
Expand Down Expand Up @@ -355,15 +356,16 @@ private void Open_Camera() {
return;
}

if (mCamera == null) {
if (Objects.isNull(mCamera)) {
Open_Camera_ById();
}
if (mCamera_BackView.isAvailable()) {
mCamera.textureListener.onSurfaceTextureAvailable(
mCamera_BackView.getSurfaceTexture(), mCamera_BackView.getWidth(),
mCamera_BackView.getHeight());
} else {
mCamera_BackView.setSurfaceTextureListener(mCamera.textureListener);
if(mCamera != null)
mCamera_BackView.setSurfaceTextureListener(mCamera.textureListener);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,7 @@ public View getView(int position, View convertView, ViewGroup parent) {
tv = (TextView)LayoutInflater.from(mContext).inflate(R.layout.details, parent,
false);
} else {
assert convertView instanceof TextView : convertView;
tv = (TextView)convertView;
}
return tv;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ public class Utils {
public static final long UNKNOWN_SIZE = -3L;
public static final long LOW_STORAGE_THRESHOLD_BYTES = 50000000;

private static Uri mCurrentPictureUri, mCurrentVideoUri;
private static Uri mCurrentPictureUri;

/**
* Has to be in sync with the receiving MovieActivity.
Expand Down Expand Up @@ -126,8 +126,9 @@ public static Uri broadcastNewPicture(Context context, ContentValues values) {
} finally {
Log.v(TAG, "Current Picture URI: " + uri);
}

context.sendBroadcast(new Intent(ACTION_NEW_PICTURE, uri));
Intent pictureIntent = new Intent(ACTION_NEW_PICTURE, uri);
pictureIntent.setPackage(context.getPackageName());
context.sendBroadcast(pictureIntent);
return uri;
}

Expand Down Expand Up @@ -176,6 +177,7 @@ public static String[] generateFileDetails(int type) {
fileDetails[0] = dateFormat.format(date);
fileDetails[1] = fileDetails[0] + ".jpg";
fileDetails[2] = "image/jpeg";

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

remove

} else if (type == MEDIA_TYPE_VIDEO) {
dateFormat = new SimpleDateFormat(VIDEO_FILE_NAME_FORMAT);
fileDetails[0] = dateFormat.format(date);
Expand Down Expand Up @@ -394,13 +396,6 @@ public static Optional<Bitmap> generateThumbnail(File path, int boundingWidthPx,

Point dim = resizeToFill(width, height, orientation, boundingWidthPx, boundingHeightPx);

// If the orientation is not vertical
if (orientation % 180 != 0) {
int dummy = dim.x;
dim.x = dim.y;
dim.y = dummy;
}

bitmap = loadImageThumbnailFromStream(stream, width, height, (int)(dim.x * 0.7f),
(int)(dim.y * 0.7), 0, MAX_PEEK_BITMAP_PIXELS);

Expand Down Expand Up @@ -566,7 +561,6 @@ public static Optional<MediaDetails> getMediaDetails(Context mContext, ContentVa
final DateFormat mDateFormatter = DateFormat.getDateTimeInstance();

if (info.get(MediaStore.Video.Media.MIME_TYPE).equals("video/mp4") == true) {
File file = new File(info.getAsString(MediaStore.Video.Media.DATA));

mediaDetails.addDetail(MediaDetails.INDEX_TITLE,
info.get(MediaStore.Video.Media.TITLE));
Expand Down Expand Up @@ -598,7 +592,6 @@ public static Optional<MediaDetails> getMediaDetails(Context mContext, ContentVa
mediaDetails.addDetail(MediaDetails.INDEX_DURATION, duration);

} else if (info.get(MediaStore.Video.Media.MIME_TYPE).equals("image/jpeg") == true) {
File file = new File(info.getAsString(MediaStore.Images.ImageColumns.DATA));
mediaDetails.addDetail(MediaDetails.INDEX_TITLE,
info.get(MediaStore.Images.ImageColumns.TITLE));
mediaDetails.addDetail(MediaDetails.INDEX_PATH,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -144,8 +144,8 @@ public void onError(MediaRecorder mr, int what, int extra) {
// from MediaRecorder.OnInfoListener
@Override
public void onInfo(MediaRecorder mr, int what, int extra) {
String[] VideofileDetails = new String[0];
if (what == MediaRecorder.MEDIA_RECORDER_INFO_MAX_FILESIZE_APPROACHING) {
String[] VideofileDetails = new String[0];
Toast.makeText(mActivity, R.string.video_reach_size_limit, Toast.LENGTH_SHORT).show();

if (mIsRecordingVideo) {
Expand Down