Reland "Use reference counted pointers for ApkAssets"

This reverts commit cf6e79f809034386b04ae551db815ab087f76c0a

Updates:
    Prepare the shared pointers for the whole operation at once
    instead of re-locking them on each iteration.
    Still a regression of about 5% for changing theme's
    AssetManager object, vs the original 40%

    + change the log message to a warning as it doesn't break
      the app

Original comment:

    Use reference counted pointers for ApkAssets

    The primary reason for memory corruption is freed ApkAssets
    Java expected them to only be freed in the finalizers, but
    there are explicit close() calls now, destroying objects that
    are still in use in some AssetManager2 objects

    This CL makes sure those AssetManagers don't assume ApkAssets
    always exist, but instead tries to lock them in memory for any
    access

    It also adds logging in case of deleting an assets object with
    any weak pointers still existing. Those will get into the
    bugreports attached to related bugs to help with investigation.

    Benchmarks don't regress, and the device appears to be working.
    Given that the crashes used to be pretty rare, let's wait for
    any new reports or lack of those.

    + add a missing .clang-format file to the jni directory
    + enabled C++23 in the project that uses AssetManager headers

    Bug: 197260547
    Bug: 276922628
    Test: unit tests + boot + benchmarks
    Old change id: I495fd9e012fe370a1f725dbb0265b4ee1be8d805

Change-Id: Id668fbcf07db17b09691a344c04e98df83006f97
diff --git a/libs/androidfw/tests/AttributeResolution_bench.cpp b/libs/androidfw/tests/AttributeResolution_bench.cpp
index 1c89c61..384f4a7 100644
--- a/libs/androidfw/tests/AttributeResolution_bench.cpp
+++ b/libs/androidfw/tests/AttributeResolution_bench.cpp
@@ -36,15 +36,14 @@
 constexpr const static uint32_t Theme_Material_Light = 0x01030237u;
 
 static void BM_ApplyStyle(benchmark::State& state) {
-  std::unique_ptr<const ApkAssets> styles_apk =
-      ApkAssets::Load(GetTestDataPath() + "/styles/styles.apk");
+  auto styles_apk = ApkAssets::Load(GetTestDataPath() + "/styles/styles.apk");
   if (styles_apk == nullptr) {
     state.SkipWithError("failed to load assets");
     return;
   }
 
   AssetManager2 assetmanager;
-  assetmanager.SetApkAssets({styles_apk.get()});
+  assetmanager.SetApkAssets({styles_apk});
 
   std::unique_ptr<Asset> asset =
       assetmanager.OpenNonAsset("res/layout/layout.xml", Asset::ACCESS_BUFFER);
@@ -80,21 +79,20 @@
 BENCHMARK(BM_ApplyStyle);
 
 static void BM_ApplyStyleFramework(benchmark::State& state) {
-  std::unique_ptr<const ApkAssets> framework_apk = ApkAssets::Load(kFrameworkPath);
+  auto framework_apk = ApkAssets::Load(kFrameworkPath);
   if (framework_apk == nullptr) {
     state.SkipWithError("failed to load framework assets");
     return;
   }
 
-  std::unique_ptr<const ApkAssets> basic_apk =
-      ApkAssets::Load(GetTestDataPath() + "/basic/basic.apk");
+  auto basic_apk = ApkAssets::Load(GetTestDataPath() + "/basic/basic.apk");
   if (basic_apk == nullptr) {
     state.SkipWithError("failed to load assets");
     return;
   }
 
   AssetManager2 assetmanager;
-  assetmanager.SetApkAssets({framework_apk.get(), basic_apk.get()});
+  assetmanager.SetApkAssets({framework_apk, basic_apk});
 
   ResTable_config device_config;
   memset(&device_config, 0, sizeof(device_config));