Audit object lifetime management: Fix documentation, add tests, add defensive code

When we designed the API, we documented that
ANeuralNetworksExecution_free could be called on an
ANeuralNetworksExecution with an execution in flight, but we never
implemented support for that, so the behavior would have been
undefined.  This CL changes the documentation to forbid this and adds
some defensive code to detect an attempt to free an in-flight
execution and respond by logging an error and ignoring the free.

Other documentation changes:
- Fix typo in ANeuralNetworksCompilation_free
- Clarify use of ANeuralNetworksEvent_free
- Clarify use of ANeuralNetworksExecution_free
- Clarify use of ANeuralNetworksMemory_free

Adds tests to confirm that we can ANeuralNetworks*_free() nullptr or
unfinished object without crashing.

Test: NeuralNetworksTest_static

Test: To verify that we gracefully handle
      ANeuralNetworksExecution_free with an execution in flight, added
      "sleep(5)" after ExecutionBuilder field mStarted is set to true;
      modified test IntrospectionControlTest.SimpleAddModel to add
      ANeuralNetworksExecution_free between
      ANeuralNetworksExecution_startCompute and
      ANeuralNetworksEvent_wait; ran "NeuralNetworksTest_static
      --gtest_filter=IntrospectionControlTest.SimpleAddModel 1024";
      and verified that test passes and that logcat contains expected
      message.

Bug: 123242704
Bug: 129494032
Change-Id: I59183c70b4f5794fdc122cfbc50ffd383ae066c3
Merged-In: I59183c70b4f5794fdc122cfbc50ffd383ae066c3
(cherry picked from commit 9ce80efa23fb0a598163b564411e560128684721)
5 files changed
tree: b0ca007fd87167008b9dd149a8eebd9eebf8de27
  1. nn/
  2. .clang-format
  3. CleanSpec.mk
  4. CPPLINT.cfg
  5. OWNERS
  6. PREUPLOAD.cfg