/*
 * Copyright 2017, Flávio Keglevich
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package com.fkeglevich.rawdumper.camera.async;

import android.hardware.Camera;

import com.intel.camera.extensions.IntelCamera;

/**
 * Created by Flávio Keglevich on 29/06/2017.
 * TODO: Add a class header comment!
 */

class CameraLock
{
    private IntelCamera intelCamera = null;
    private Camera.CameraInfo cameraInfo = null;

    CameraLock()
    {   }

    private void checkThreadAccess()
    {
        if (!Thread.holdsLock(this))
            throw new RuntimeException("This method should be called inside a proper synchronized block!");
    }

    IntelCamera getCamera()
    {
        checkThreadAccess();
        return intelCamera;
    }

    void setCamera(IntelCamera intelCamera)
    {
        checkThreadAccess();
        this.intelCamera = intelCamera;
    }

    Camera.CameraInfo getCameraInfo()
    {
        checkThreadAccess();
        return cameraInfo;
    }

    void setCameraInfo(Camera.CameraInfo cameraInfo)
    {
        checkThreadAccess();
        this.cameraInfo = cameraInfo;
    }
}

@@ -676,16 +676,65 @@
 amera;%0A%0A
+import com.fkeglevich.rawdumper.util.ThreadUtil;%0A
 import c
@@ -1015,38 +1015,29 @@
     
-private void checkThreadAccess
+IntelCamera getCamera
 ()%0A 
@@ -1053,212 +1053,43 @@
     
-if (!
 Thread
-.holdsLock(this))%0A            throw new RuntimeException(%22This method should be called inside a proper synchronized block!%22);%0A    %7D%0A%0A    IntelCamera getCamera()%0A    %7B%0A        checkThreadAccess(
+Util.checkIfSynchronized(this
 );%0A 
@@ -1180,34 +1180,51 @@
         
-checkThreadAccess(
+ThreadUtil.checkIfSynchronized(this
 );%0A     
@@ -1317,34 +1317,51 @@
         
-checkThreadAccess(
+ThreadUtil.checkIfSynchronized(this
 );%0A     
@@ -1460,26 +1460,43 @@
     
-checkThreadAccess(
+ThreadUtil.checkIfSynchronized(this
 );%0A 

Use ThreadUtil class