Switch flash in Camera2 API

You want to update the flash mode in your preview request as well; generally the camera device wants to know your desired flash mode when you trigger the precapture sequence (with AE_PRECAPTURE_TRIGGER), so that it knows if it should turn on the precapture flash, which it needs to determine the final flash power.

The usual sequence of events is:

  1. Set preview flash mode to desired mode
  2. Wait for user to hit the shutter button
  3. Issue single preview request with precapture trigger set (but keep preview request on repeat otherwise).
  4. Wait for AE_STATE_PRECAPTURE to stop being the AE state in your capture results
  5. Issue the final capture request (keep the same flash mode)
  6. Get final JPEG in your ImageReader

(This ignores ensuring focus is good, which generally is done before/in parallel to starting the precapture sequence)