title: Android Camera2 API - lack of privileges on resume
body: <p>I'm developing the app using Camera2 API. My problem looks like that:
   when I hit the device's sleep button while the camera fragment is working and after that I wake up the device, the application restarts</p>
  
  <pre><code>12-10 10:59:10.423 5081-5081/com.snapsportz.nexus5camera.app E/AndroidRuntime: FATAL EXCEPTION: main
  12-10 10:59:10.423 5081-5081/com.snapsportz.nexus5camera.app E/AndroidRuntime: Process: com.snapsportz.nexus5camera.app, PID: 5081
  12-10 10:59:10.423 5081-5081/com.snapsportz.nexus5camera.app E/AndroidRuntime: java.lang.RuntimeException: Unable to pause activity {com.snapsportz.nexus5camera.app/com.snapsportz.handheldcamera.app.CameraActivity}: java.lang.SecurityException: Lacking privileges to access camera service
  12-10 10:59:10.423 5081-5081/com.snapsportz.nexus5camera.app E/AndroidRuntime:     at android.app.ActivityThread.performPauseActivity(ActivityThread.java:3381)
  12-10 10:59:10.423 5081-5081/com.snapsportz.nexus5camera.app E/AndroidRuntime:     at android.app.ActivityThread.performPauseActivity(ActivityThread.java:3340)
  12-10 10:59:10.423 5081-5081/com.snapsportz.nexus5camera.app E/AndroidRuntime:     at android.app.ActivityThread.handleRelaunchActivity(ActivityThread.java:4047)
  12-10 10:59:10.423 5081-5081/com.snapsportz.nexus5camera.app E/AndroidRuntime:     at android.app.ActivityThread.-wrap15(ActivityThread.java)
  12-10 10:59:10.423 5081-5081/com.snapsportz.nexus5camera.app E/AndroidRuntime:     at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1350)
  12-10 10:59:10.423 5081-5081/com.snapsportz.nexus5camera.app E/AndroidRuntime:     at android.os.Handler.dispatchMessage(Handler.java:102)
  12-10 10:59:10.423 5081-5081/com.snapsportz.nexus5camera.app E/AndroidRuntime:     at android.os.Looper.loop(Looper.java:148)
  12-10 10:59:10.423 5081-5081/com.snapsportz.nexus5camera.app E/AndroidRuntime:     at android.app.ActivityThread.main(ActivityThread.java:5417)
  12-10 10:59:10.423 5081-5081/com.snapsportz.nexus5camera.app E/AndroidRuntime:     at java.lang.reflect.Method.invoke(Native Method)
  12-10 10:59:10.423 5081-5081/com.snapsportz.nexus5camera.app E/AndroidRuntime:     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726)
  12-10 10:59:10.423 5081-5081/com.snapsportz.nexus5camera.app E/AndroidRuntime:     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616)
  12-10 10:59:10.423 5081-5081/com.snapsportz.nexus5camera.app E/AndroidRuntime:  Caused by: java.lang.SecurityException: Lacking privileges to access camera service
  12-10 10:59:10.423 5081-5081/com.snapsportz.nexus5camera.app E/AndroidRuntime:     at android.hardware.camera2.utils.CameraBinderDecorator.throwOnError(CameraBinderDecorator.java:108)
  12-10 10:59:10.423 5081-5081/com.snapsportz.nexus5camera.app E/AndroidRuntime:     at android.hardware.camera2.utils.CameraBinderDecorator$CameraBinderDecoratorListener.onAfterInvocation(CameraBinderDecorator.java:73)
  12-10 10:59:10.423 5081-5081/com.snapsportz.nexus5camera.app E/AndroidRuntime:     at android.hardware.camera2.utils.Decorator.invoke(Decorator.java:81)
  12-10 10:59:10.423 5081-5081/com.snapsportz.nexus5camera.app E/AndroidRuntime:     at java.lang.reflect.Proxy.invoke(Proxy.java:393)
  12-10 10:59:10.423 5081-5081/com.snapsportz.nexus5camera.app E/AndroidRuntime:     at $Proxy1.cancelRequest(Unknown Source)
  12-10 10:59:10.423 5081-5081/com.snapsportz.nexus5camera.app E/AndroidRuntime:     at android.hardware.camera2.impl.CameraDeviceImpl.stopRepeating(CameraDeviceImpl.java:899)
  12-10 10:59:10.423 5081-5081/com.snapsportz.nexus5camera.app E/AndroidRuntime:     at android.hardware.camera2.impl.CameraCaptureSessionImpl.close(CameraCaptureSessionImpl.java:373)
  12-10 10:59:10.423 5081-5081/com.snapsportz.nexus5camera.app E/AndroidRuntime:     at com.snapsportz.handheldcamera.app.Camera2BasicFragment.closeCamera(Camera2BasicFragment.java:899)
  12-10 10:59:10.423 5081-5081/com.snapsportz.nexus5camera.app E/AndroidRuntime:     at com.snapsportz.handheldcamera.app.Camera2BasicFragment.onPause(Camera2BasicFragment.java:771)
  12-10 10:59:10.423 5081-5081/com.snapsportz.nexus5camera.app E/AndroidRuntime:     at android.app.Fragment.performPause(Fragment.java:2379)
  12-10 10:59:10.423 5081-5081/com.snapsportz.nexus5camera.app E/AndroidRuntime:     at android.app.FragmentManagerImpl.moveToState(FragmentManager.java:1019)
  12-10 10:59:10.423 5081-5081/com.snapsportz.nexus5camera.app E/AndroidRuntime:     at android.app.FragmentManagerImpl.moveToState(FragmentManager.java:1148)
  12-10 10:59:10.423 5081-5081/com.snapsportz.nexus5camera.app E/AndroidRuntime:     at android.app.FragmentManagerImpl.moveToState(FragmentManager.java:1130)
  12-10 10:59:10.423 5081-5081/com.snapsportz.nexus5camera.app E/AndroidRuntime:     at android.app.FragmentManagerImpl.dispatchPause(FragmentManager.java:1967)
  12-10 10:59:10.423 5081-5081/com.snapsportz.nexus5camera.app E/AndroidRuntime:     at android.app.FragmentController.dispatchPause(FragmentController.java:185)
  12-10 10:59:10.423 5081-5081/com.snapsportz.nexus5camera.app E/AndroidRuntime:     at android.app.Activity.performPause(Activity.java:6346)
  12-10 10:59:10.423 5081-5081/com.snapsportz.nexus5camera.app E/AndroidRuntime:     at android.app.Instrumentation.callActivityOnPause(Instrumentation.java:1311)
  12-10 10:59:10.423 5081-5081/com.snapsportz.nexus5camera.app E/AndroidRuntime:     at android.app.ActivityThread.performPauseActivity(ActivityThread.java:3367)
  12-10 10:59:10.423 5081-5081/com.snapsportz.nexus5camera.app E/AndroidRuntime:     at android.app.ActivityThread.performPauseActivity(ActivityThread.java:3340) 
  12-10 10:59:10.423 5081-5081/com.snapsportz.nexus5camera.app E/AndroidRuntime:     at android.app.ActivityThread.handleRelaunchActivity(ActivityThread.java:4047) 
  12-10 10:59:10.423 5081-5081/com.snapsportz.nexus5camera.app E/AndroidRuntime:     at android.app.ActivityThread.-wrap15(ActivityThread.java) 
  12-10 10:59:10.423 5081-5081/com.snapsportz.nexus5camera.app E/AndroidRuntime:     at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1350) 
  12-10 10:59:10.423 5081-5081/com.snapsportz.nexus5camera.app E/AndroidRuntime:     at android.os.Handler.dispatchMessage(Handler.java:102) 
  12-10 10:59:10.423 5081-5081/com.snapsportz.nexus5camera.app E/AndroidRuntime:     at android.os.Looper.loop(Looper.java:148) 
  12-10 10:59:10.423 5081-5081/com.snapsportz.nexus5camera.app E/AndroidRuntime:     at android.app.ActivityThread.main(ActivityThread.java:5417) 
  12-10 10:59:10.423 5081-5081/com.snapsportz.nexus5camera.app E/AndroidRuntime:     at java.lang.reflect.Method.invoke(Native Method) 
  12-10 10:59:10.423 5081-5081/com.snapsportz.nexus5camera.app E/AndroidRuntime:     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726) 
  12-10 10:59:10.423 5081-5081/com.snapsportz.nexus5camera.app E/AndroidRuntime:     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616) 
  </code></pre>
  
  <p>I believe that it's not a lack of camera permission in manifest file because it is included in it and the app works fine unless I try to wake it up.</p>
  
  <p>I'll be really glad for any hint.</p>