/*
 * Copyright (C) 2019 The Android Open Source Project
 *
 * 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 androidx.camera.testapp.camera2interopburst;

import android.hardware.camera2.CameraCaptureSession;
import android.support.annotation.GuardedBy;
import android.util.Log;
import android.view.Surface;

/** A capture session state callback which updates a reference to the capture session. */
final class SessionUpdatingSessionStateCallback extends CameraCaptureSession.StateCallback {
    private static final String TAG = "SessionUpdatingSessionStateCallback";

    private final Object sessionLock = new Object();

    @GuardedBy("sessionLock")
    private CameraCaptureSession session;

    @Override
    public void onConfigured(CameraCaptureSession session) {
        Log.d(TAG, "onConfigured: session=" + session);
        synchronized (sessionLock) {
            this.session = session;
        }
    }

    @Override
    public void onActive(CameraCaptureSession session) {
        Log.d(TAG, "onActive: session=" + session);
    }

    @Override
    public void onClosed(CameraCaptureSession session) {
        Log.d(TAG, "onClosed: session=" + session);
        synchronized (sessionLock) {
            if (this.session == session) {
                this.session = null;
            }
        }
    }

    @Override
    public void onReady(CameraCaptureSession session) {
        Log.d(TAG, "onReady: session=" + session);
    }

    @Override
    public void onCaptureQueueEmpty(CameraCaptureSession session) {
        Log.d(TAG, "onCaptureQueueEmpty: session=" + session);
    }

    @Override
    public void onSurfacePrepared(CameraCaptureSession session, Surface surface) {
        Log.d(TAG, "onSurfacePrepared: session=" + session + ", surface=" + surface);
    }

    @Override
    public void onConfigureFailed(CameraCaptureSession session) {
        Log.d(TAG, "onConfigureFailed: session=" + session);
        synchronized (sessionLock) {
            if (this.session == session) {
                this.session = null;
            }
        }
    }

    CameraCaptureSession getSession() {
        synchronized (sessionLock) {
            return session;
        }
    }
}

@@ -1108,17 +1108,18 @@
  Object 
-s
+mS
 essionLo
@@ -1154,17 +1154,18 @@
 rdedBy(%22
-s
+mS
 essionLo
@@ -1198,25 +1198,26 @@
 tureSession 
-s
+mS
 ession;%0A%0A   
@@ -1358,33 +1358,34 @@
   synchronized (
-s
+mS
 essionLock) %7B%0A  
@@ -1386,38 +1386,34 @@
 ) %7B%0A            
-this.s
+mS
 ession = session
@@ -1698,33 +1698,34 @@
   synchronized (
-s
+mS
 essionLock) %7B%0A  
@@ -1730,38 +1730,34 @@
             if (
-this.s
+mS
 ession == sessio
@@ -1769,38 +1769,34 @@
                 
-this.s
+mS
 ession = null;%0A 
@@ -2450,33 +2450,34 @@
   synchronized (
-s
+mS
 essionLock) %7B%0A  
@@ -2490,22 +2490,18 @@
     if (
-this.s
+mS
 ession =
@@ -2533,14 +2533,10 @@
     
-this.s
+mS
 essi
@@ -2639,17 +2639,18 @@
 onized (
-s
+mS
 essionLo
@@ -2674,17 +2674,18 @@
  return 
-s
+mS
 ession;%0A

Migrate codestyle to AOSP