Android Camera2 API Flash doesnt work on galaxy devices

Actually using camera2 API is very special in android devices. Some methods may not be implemented. For example: this and this. For the others, proper flash modes should be set depends on the other properties. This code works for me in most Samsung devices that support camera2API:

 if (mIsFlashSupported) {
        switch (mFlashMode) {
            case FLASH_MODE_ON:
                requestBuilder.set(CaptureRequest.CONTROL_AE_MODE, CaptureRequest.CONTROL_AE_MODE_ON);
                requestBuilder.set(CaptureRequest.FLASH_MODE, CameraMetadata.FLASH_MODE_SINGLE);
                requestBuilder.set(CaptureRequest.CONTROL_AWB_MODE, CaptureRequest.CONTROL_AWB_MODE_FLUORESCENT);
                break;

            case FLASH_MODE_OFF:
                requestBuilder.set(CaptureRequest.CONTROL_AE_MODE, CameraMetadata.CONTROL_AE_MODE_ON);
                requestBuilder.set(CaptureRequest.FLASH_MODE, CameraMetadata.FLASH_MODE_OFF);
                requestBuilder.set(CaptureRequest.CONTROL_AWB_MODE, CaptureRequest.CONTROL_AWB_MODE_DAYLIGHT);
                break;

            case FLASH_MODE_AUTO:
            default:
                requestBuilder.set(CaptureRequest.CONTROL_AE_MODE, CameraMetadata.CONTROL_AE_MODE_ON_AUTO_FLASH);
                requestBuilder.set(CaptureRequest.FLASH_MODE, CameraMetadata.FLASH_MODE_SINGLE);
                requestBuilder.set(CaptureRequest.CONTROL_AWB_MODE, CaptureRequest.CONTROL_AWB_MODE_DAYLIGHT);
                break;
        }
    }

After working at this on and off for a bit I realized a few things. I mentioned that ZCamera (from the play store) works with flash, and I thought they accomplished this by using the Samsung SDK. I checked the app and it does not use the Samsung SDK.

I also incorporated the Samsung SDK into my app and that didn't change anything. The Samsung SDK is really just a wrapper around google's camera 2 so you can add some Samsung specific features, adding it to your project wont fix any Samsung compatibilities.

What I finally realized was that the touch metering flow I had programmed myself (touch to focus/then take a photo) worked very differently than my logic that ran when we take a photo without touch to focus. The regular photo logic was borrowed from googles camera2 api example code and it wasnt working propery.

The trick to get the flash to fire on Samsung devices (or at least what worked for me) was to first trigger a check for AE levels, and once that converges then start the auto focus trigger. If flash is turned on this will fire the flash to check AE levels and to focus, and then fire the flash once more to take the photo