ImageReader: Fix rogue RuntimeException in #detachImage

ImageReader#detach documents that an IllegalStateException will be thrown
if there are any errors detaching Image from a Surface. As ImageReaders
are set up, it is common for this exception to be thrown. Applications
are expected to catch and recover from the exception. However,
ImageReader#nativeDetachImage, that ImageReader#detachImage calls into,
explicitly threw a RuntimeException causing applications that didn't
expect RuntimeException to crash.

This behavior has stuck around for a few years, so changing the behavior
to match the documentation will break backwards compatibility for many
apps. However, RuntimeException is an incredibly generic exception that
applications shouldn't be forced to catch as it can hide more serious
bugs.

This CL updates #nativeDetachImage to accept an additional flag.
When this flag is set to True, #nativeDetachImage only throws
IllegalStateException and preserves previous behavior when the flag is
set to False.

The flag is populated through the App Compatibility Framework which
changes the behavior only for apps that set their targetSdk to > 33.

Bug: 236825255
Bug: 204438677
Test: Manually tested that the flag is set to true for Apps targetting
      Android SDK > 33
Change-Id: I20bd986f11dbe7acf4898cf0ce794c27f42e1ee2
2 files changed