title: Camera2 freezing on Samsung 8
body: <p>I've got a problem with an app I've developed for my final thesis for my Data Science degree. The issue is that it won't work on my brand new Samsung8, while it's worked on my previous phone, an HTC. And while I can see where the problem might lie, I've got no idea as to how to properly fix it. I'll dump the logcat output from the phone below, as well as the code snippits from the guilty file.</p>
  
  <p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false">
  <div class="snippet-code">
  <pre class="snippet-code-html lang-html prettyprint-override"><code>--------- beginning of main
  12-26 13:26:20.829 21890 21890 D InputTransport: Input channel constructed: fd=87
  12-26 13:26:20.829 21890 21890 D InputTransport: Input channel destroyed: fd=83
  12-26 13:26:20.853 21890 21909 D OpenGLRenderer: endAllActiveAnimators on 0x7bac793400 (RippleDrawable) with handle 0x7bac9e6160
  12-26 13:26:20.853 21890 21890 D ViewRootImpl@a565c5e[PictureActivity]: mHardwareRenderer.destroy()#1
  12-26 13:26:20.856 21890 21890 D ViewRootImpl@a565c5e[PictureActivity]: Relayout returned: oldFrame=[0,0][1080,2220] newFrame=[0,0][1080,2220] result=0x5 surface={isValid=false 0} surfaceGenerationChanged=true
  12-26 13:26:25.068 21890 21890 D ViewRootImpl@21abbe6[Camera2Activity]: ViewPostImeInputStage processPointer 0
  12-26 13:26:25.159 21890 21890 D ViewRootImpl@21abbe6[Camera2Activity]: ViewPostImeInputStage processPointer 1
  12-26 13:26:25.676 21890 21890 W System.err: android.hardware.camera2.CameraAccessException: CAMERA_ERROR (3): submitRequestList:270: Camera 1: Got error Function not implemented (-38) after trying to submit capture request
  12-26 13:26:25.677 21890 21890 W System.err:  at android.hardware.camera2.CameraManager.throwAsPublicException(CameraManager.java:634)
  12-26 13:26:25.678 21890 21890 W System.err:  at android.hardware.camera2.impl.ICameraDeviceUserWrapper.submitRequestList(ICameraDeviceUserWrapper.java:86)
  12-26 13:26:25.678 21890 21890 W System.err:  at android.hardware.camera2.impl.CameraDeviceImpl.submitCaptureRequest(CameraDeviceImpl.java:865)
  12-26 13:26:25.678 21890 21890 W System.err:  at android.hardware.camera2.impl.CameraDeviceImpl.capture(CameraDeviceImpl.java:754)
  12-26 13:26:25.678 21890 21890 W System.err:  at android.hardware.camera2.impl.CameraCaptureSessionImpl.capture(CameraCaptureSessionImpl.java:179)
  12-26 13:26:25.678 21890 21890 W System.err:  at com.example.joachim.faceapp.Camera2Fragment.captureStillPicture(Camera2Fragment.java:869)
  12-26 13:26:25.679 21890 21890 W System.err:  at com.example.joachim.faceapp.Camera2Fragment.lockFocus(Camera2Fragment.java:803)
  12-26 13:26:25.679 21890 21890 W System.err:  at com.example.joachim.faceapp.Camera2Fragment.takePicture(Camera2Fragment.java:790)
  12-26 13:26:25.679 21890 21890 W System.err:  at com.example.joachim.faceapp.Camera2Fragment.onClick(Camera2Fragment.java:913)
  12-26 13:26:25.679 21890 21890 W System.err:  at android.view.View.performClick(View.java:6261)
  12-26 13:26:25.679 21890 21890 W System.err:  at android.view.View$PerformClick.run(View.java:23748)
  12-26 13:26:25.679 21890 21890 W System.err:  at android.os.Handler.handleCallback(Handler.java:751)
  12-26 13:26:25.679 21890 21890 W System.err:  at android.os.Handler.dispatchMessage(Handler.java:95)
  12-26 13:26:25.679 21890 21890 W System.err:  at android.os.Looper.loop(Looper.java:154)
  12-26 13:26:25.679 21890 21890 W System.err:  at android.app.ActivityThread.main(ActivityThread.java:6776)
  12-26 13:26:25.680 21890 21890 W System.err:  at java.lang.reflect.Method.invoke(Native Method)
  12-26 13:26:25.680 21890 21890 W System.err:  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1520)
  12-26 13:26:25.680 21890 21890 W System.err:  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1410)
  12-26 13:26:25.681 21890 21890 W System.err: Caused by: android.os.ServiceSpecificException: submitRequestList:270: Camera 1: Got error Function not implemented (-38) after trying to submit capture request
  12-26 13:26:25.681 21890 21890 W System.err:  at android.os.Parcel.readException(Parcel.java:1707)
  12-26 13:26:25.681 21890 21890 W System.err:  at android.os.Parcel.readException(Parcel.java:1646)
  12-26 13:26:25.681 21890 21890 W System.err:  at android.hardware.camera2.ICameraDeviceUser$Stub$Proxy.submitRequestList(ICameraDeviceUser.java:318)
  12-26 13:26:25.681 21890 21890 W System.err:  at android.hardware.camera2.impl.ICameraDeviceUserWrapper.submitRequestList(ICameraDeviceUserWrapper.java:84)
  12-26 13:26:25.681 21890 21890 W System.err:  ... 16 more
  12-26 13:26:25.689 21890 21890 W System.err: android.hardware.camera2.CameraAccessException: CAMERA_ERROR (3): submitRequestList:270: Camera 1: Got error Function not implemented (-38) after trying to submit capture request
  12-26 13:26:25.689 21890 21890 W System.err:  at android.hardware.camera2.CameraManager.throwAsPublicException(CameraManager.java:634)
  12-26 13:26:25.690 21890 21890 W System.err:  at android.hardware.camera2.impl.ICameraDeviceUserWrapper.submitRequestList(ICameraDeviceUserWrapper.java:86)
  12-26 13:26:25.690 21890 21890 W System.err:  at android.hardware.camera2.impl.CameraDeviceImpl.submitCaptureRequest(CameraDeviceImpl.java:865)
  12-26 13:26:25.690 21890 21890 W System.err:  at android.hardware.camera2.impl.CameraDeviceImpl.capture(CameraDeviceImpl.java:754)
  12-26 13:26:25.690 21890 21890 W System.err:  at android.hardware.camera2.impl.CameraCaptureSessionImpl.capture(CameraCaptureSessionImpl.java:179)
  12-26 13:26:25.690 21890 21890 W System.err:  at com.example.joachim.faceapp.Camera2Fragment.lockFocus(Camera2Fragment.java:805)
  12-26 13:26:25.690 21890 21890 W System.err:  at com.example.joachim.faceapp.Camera2Fragment.takePicture(Camera2Fragment.java:790)
  12-26 13:26:25.691 21890 21890 W System.err:  at com.example.joachim.faceapp.Camera2Fragment.onClick(Camera2Fragment.java:913)
  12-26 13:26:25.691 21890 21890 W System.err:  at android.view.View.performClick(View.java:6261)
  12-26 13:26:25.691 21890 21890 W System.err:  at android.view.View$PerformClick.run(View.java:23748)
  12-26 13:26:25.691 21890 21890 W System.err:  at android.os.Handler.handleCallback(Handler.java:751)
  12-26 13:26:25.691 21890 21890 W System.err:  at android.os.Handler.dispatchMessage(Handler.java:95)
  12-26 13:26:25.691 21890 21890 W System.err:  at android.os.Looper.loop(Looper.java:154)
  12-26 13:26:25.691 21890 21890 W System.err:  at android.app.ActivityThread.main(ActivityThread.java:6776)
  12-26 13:26:25.691 21890 21890 W System.err:  at java.lang.reflect.Method.invoke(Native Method)
  12-26 13:26:25.692 21890 21890 W System.err:  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1520)
  12-26 13:26:25.692 21890 21890 W System.err:  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1410)
  12-26 13:26:25.692 21890 21890 W System.err: Caused by: android.os.ServiceSpecificException: submitRequestList:270: Camera 1: Got error Function not implemented (-38) after trying to submit capture request
  12-26 13:26:25.693 21890 21890 W System.err:  at android.os.Parcel.readException(Parcel.java:1707)
  12-26 13:26:25.693 21890 21890 W System.err:  at android.os.Parcel.readException(Parcel.java:1646)
  12-26 13:26:25.693 21890 21890 W System.err:  at android.hardware.camera2.ICameraDeviceUser$Stub$Proxy.submitRequestList(ICameraDeviceUser.java:318)
  12-26 13:26:25.693 21890 21890 W System.err:  at android.hardware.camera2.impl.ICameraDeviceUserWrapper.submitRequestList(ICameraDeviceUserWrapper.java:84)
  12-26 13:26:25.693 21890 21890 W System.err:  ... 15 more
  12-26 13:26:25.695 21890 21890 I Choreographer: Skipped 31 frames!  The application may be doing too much work on its main thread.
  12-26 13:26:25.697 21890 21998 W System.err: android.hardware.camera2.CameraAccessException: CAMERA_ERROR (3): createDefaultRequest:742: Camera 1: Error creating default request for template 2: Function not implemented (-38)
  12-26 13:26:25.697 21890 21998 W System.err:  at android.hardware.camera2.CameraManager.throwAsPublicException(CameraManager.java:634)
  12-26 13:26:25.697 21890 21998 W System.err:  at android.hardware.camera2.impl.ICameraDeviceUserWrapper.createDefaultRequest(ICameraDeviceUserWrapper.java:159)
  12-26 13:26:25.698 21890 21998 W System.err:  at android.hardware.camera2.impl.CameraDeviceImpl.createCaptureRequest(CameraDeviceImpl.java:665)
  12-26 13:26:25.698 21890 21998 W System.err:  at com.example.joachim.faceapp.Camera2Fragment.captureStillPicture(Camera2Fragment.java:843)
  12-26 13:26:25.698 21890 21998 W System.err:  at com.example.joachim.faceapp.Camera2Fragment.access$800(Camera2Fragment.java:79)
  12-26 13:26:25.698 21890 21998 W System.err:  at com.example.joachim.faceapp.Camera2Fragment$4.process(Camera2Fragment.java:307)
  12-26 13:26:25.698 21890 21998 W System.err:  at com.example.joachim.faceapp.Camera2Fragment$4.onCaptureProgressed(Camera2Fragment.java:348)
  12-26 13:26:25.698 21890 21998 W System.err:  at java.lang.reflect.Method.invoke(Native Method)
  12-26 13:26:25.698 21890 21998 W System.err:  at android.hardware.camera2.dispatch.InvokeDispatcher.dispatch(InvokeDispatcher.java:39)
  12-26 13:26:25.698 21890 21998 W System.err:  at android.hardware.camera2.dispatch.HandlerDispatcher$1.run(HandlerDispatcher.java:65)
  12-26 13:26:25.699 21890 21998 W System.err:  at android.os.Handler.handleCallback(Handler.java:751)
  12-26 13:26:25.699 21890 21998 W System.err:  at android.os.Handler.dispatchMessage(Handler.java:95)
  12-26 13:26:25.700 21890 21998 W System.err:  at android.os.Looper.loop(Looper.java:154)
  12-26 13:26:25.700 21890 21998 W System.err:  at android.os.HandlerThread.run(HandlerThread.java:61)
  12-26 13:26:25.701 21890 21998 W System.err: Caused by: android.os.ServiceSpecificException: createDefaultRequest:742: Camera 1: Error creating default request for template 2: Function not implemented (-38)
  12-26 13:26:25.701 21890 21998 W System.err:  at android.os.Parcel.readException(Parcel.java:1707)
  12-26 13:26:25.701 21890 21998 W System.err:  at android.os.Parcel.readException(Parcel.java:1646)
  12-26 13:26:25.701 21890 21998 W System.err:  at android.hardware.camera2.ICameraDeviceUser$Stub$Proxy.createDefaultRequest(ICameraDeviceUser.java:503)
  12-26 13:26:25.701 21890 21998 W System.err:  at android.hardware.camera2.impl.ICameraDeviceUserWrapper.createDefaultRequest(ICameraDeviceUserWrapper.java:157)
  12-26 13:26:25.701 21890 21998 W System.err:  ... 12 more</code></pre>
  </div>
  </div>
  </p>
  
  <p>And here's the suspect.</p>
  
  <p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false">
  <div class="snippet-code">
  <pre class="snippet-code-html lang-html prettyprint-override"><code>private void captureStillPicture() {
          try {
              final Activity activity = getActivity();
              if (null == activity || null == mCameraDevice) {
                  return;
              }
              // This is the CaptureRequest.Builder that we use to take a picture.
              final CaptureRequest.Builder captureBuilder =
                      mCameraDevice.createCaptureRequest(CameraDevice.TEMPLATE_STILL_CAPTURE);
              captureBuilder.addTarget(mImageReader.getSurface());
  
              // Use the same AE and AF modes as the preview.
              captureBuilder.set(CaptureRequest.CONTROL_AF_MODE,
                      CaptureRequest.CONTROL_AF_MODE_CONTINUOUS_PICTURE);
  
              // Orientation
              int rotation = activity.getWindowManager().getDefaultDisplay().getRotation();
              captureBuilder.set(CaptureRequest.JPEG_ORIENTATION, getOrientation(rotation));
  
              CameraCaptureSession.CaptureCallback CaptureCallback
                      = new CameraCaptureSession.CaptureCallback() {
  
                  @Override
                  public void onCaptureCompleted(@NonNull CameraCaptureSession session,
                                                 @NonNull CaptureRequest request,
                                                 @NonNull TotalCaptureResult result) {
                      showToast("Saved: " + mFile);
                      Log.d(TAG, mFile.toString());
                      unlockFocus();
                  }
              };
  
              mCaptureSession.stopRepeating();
              mCaptureSession.abortCaptures();
              mCaptureSession.capture(captureBuilder.build(), CaptureCallback, null);
          } catch (CameraAccessException e) {
              e.printStackTrace();
          }
      }
      
      
      </code></pre>
  </div>
  </div>
  </p>
  
  <p>If anybody can help me, please. I have a way to show off the app in its functional state, but I'd love to see if it's an issue that i can fix on the new phone or not.</p>