Delete cuttlefish_auto_resources

There are no more users of this code.

Bug: 144387776
Test: make installclean && make -j && launch_cvd
Change-Id: I8db70696a398cfe7f6fcfc38f76afc49536480ea
diff --git a/common/libs/Android.bp b/common/libs/Android.bp
index e70e6ab..40b7f0c 100644
--- a/common/libs/Android.bp
+++ b/common/libs/Android.bp
@@ -14,7 +14,6 @@
 // limitations under the License.
 
 subdirs = [
-    "auto_resources",
     "device_config",
     "fs",
     "net",
diff --git a/common/libs/auto_resources/Android.bp b/common/libs/auto_resources/Android.bp
deleted file mode 100644
index f943211..0000000
--- a/common/libs/auto_resources/Android.bp
+++ /dev/null
@@ -1,45 +0,0 @@
-//
-// Copyright (C) 2017 The Android Open Source Project
-//
-// Licensed under the Apache License, Version 2.0 (the "License");
-// you may not use this file except in compliance with the License.
-// You may obtain a copy of the License at
-//
-//      http://www.apache.org/licenses/LICENSE-2.0
-//
-// Unless required by applicable law or agreed to in writing, software
-// distributed under the License is distributed on an "AS IS" BASIS,
-// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-// See the License for the specific language governing permissions and
-// limitations under the License.
-
-cc_library {
-    name: "cuttlefish_auto_resources",
-    srcs: [
-        "auto_resources.cpp",
-    ],
-    defaults: ["cuttlefish_host_and_guest"],
-}
-
-cc_library_static {
-    name: "cuttlefish_auto_resources_product",
-    srcs: [
-        "auto_resources.cpp",
-    ],
-    defaults: ["cuttlefish_guest_product_only"],
-}
-
-cc_test_host {
-    name: "auto_free_buffer_test",
-    srcs: [
-        "auto_free_buffer_test.cpp",
-    ],
-    shared_libs: [
-        "cuttlefish_auto_resources",
-    ],
-    static_libs: [
-        "libgmock",
-    ],
-    defaults: ["cuttlefish_host_only"],
-    test_suites: ["general-tests"],
-}
diff --git a/common/libs/auto_resources/TEST_MAPPING b/common/libs/auto_resources/TEST_MAPPING
deleted file mode 100644
index 1e34e75..0000000
--- a/common/libs/auto_resources/TEST_MAPPING
+++ /dev/null
@@ -1,8 +0,0 @@
-{
-  "presubmit": [
-    {
-      "name": "auto_free_buffer_test",
-      "host": true
-    }
-  ]
-}
diff --git a/common/libs/auto_resources/auto_free_buffer_test.cpp b/common/libs/auto_resources/auto_free_buffer_test.cpp
deleted file mode 100644
index b1bbf34..0000000
--- a/common/libs/auto_resources/auto_free_buffer_test.cpp
+++ /dev/null
@@ -1,135 +0,0 @@
-/*
- * Copyright (C) 2016 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- *      http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-#include "common/libs/auto_resources/auto_resources.h"
-
-#include <stdio.h>
-
-#include <gtest/gtest.h>
-#include <gmock/gmock.h>
-
-using ::testing::StrEq;
-
-namespace test {
-static constexpr size_t kImmutableReserveSize =
-    AutoFreeBuffer::kAutoBufferShrinkReserveThreshold;
-
-class AutoFreeBufferTest : public ::testing::Test {
- public:
-  AutoFreeBufferTest() = default;
-  ~AutoFreeBufferTest() override = default;
-
-  void SetUp() override {}
-  void TearDown() override {}
-
- protected:
-  AutoFreeBuffer buffer_;
-};
-
-TEST_F(AutoFreeBufferTest, ShrinkingSmallReservationsDoesNotRealloc) {
-
-  buffer_.Reserve(kImmutableReserveSize);
-  const void* const data = buffer_.data();
-
-  EXPECT_EQ(0u, buffer_.size());
-  EXPECT_EQ(kImmutableReserveSize, buffer_.reserve_size());
-  EXPECT_NE(nullptr, data);
-
-  buffer_.Resize(kImmutableReserveSize);
-  EXPECT_EQ(kImmutableReserveSize, buffer_.size());
-  EXPECT_EQ(data, buffer_.data());
-
-  // Reduce size of buffer.
-  buffer_.Reserve(kImmutableReserveSize / 2);
-  EXPECT_EQ(kImmutableReserveSize, buffer_.reserve_size());
-  EXPECT_EQ(kImmutableReserveSize / 2, buffer_.size());
-  EXPECT_EQ(data, buffer_.data());
-
-  buffer_.Clear();
-
-  EXPECT_EQ(0u, buffer_.size());
-  EXPECT_EQ(kImmutableReserveSize, buffer_.reserve_size());
-  EXPECT_EQ(data, buffer_.data());
-}
-
-TEST_F(AutoFreeBufferTest, ShrinkingLargeReservationDoesRealloc) {
-  buffer_.Reserve(kImmutableReserveSize + 1);
-
-  EXPECT_EQ(0u, buffer_.size());
-  EXPECT_EQ(kImmutableReserveSize + 1, buffer_.reserve_size());
-
-  buffer_.Reserve(kImmutableReserveSize);
-
-  EXPECT_EQ(0u, buffer_.size());
-  EXPECT_EQ(kImmutableReserveSize, buffer_.reserve_size());
-  // Note: realloc may re-use current memory pointer, so testing data pointer
-  // makes no sense.
-}
-
-TEST_F(AutoFreeBufferTest, ResizeClearsMemory) {
-  constexpr char kTruncWords[] = "This string";
-  constexpr char kLastWords[] = "will be truncated to first two words.";
-  constexpr char kFullText[] =
-      "This string will be truncated to first two words.";
-  // Ignore padding \0.
-  constexpr size_t kTruncLength = sizeof(kTruncWords) - 1;
-
-  buffer_.SetToString(kFullText);
-
-  // Note: this call treats buffer as raw data, so no padding happens yet.
-  buffer_.Resize(kTruncLength);
-  EXPECT_THAT(buffer_.data(), StrEq(kFullText));
-
-  buffer_.Resize(kTruncLength + 1);
-  EXPECT_THAT(buffer_.data(), StrEq(kTruncWords));
-
-  // Note: we're accessing buffer out of size() bounds, but still within
-  // reserve_size() bounds.
-  // This confirms that only 1 byte of data has been appended.
-  EXPECT_THAT(&buffer_.data()[sizeof(kTruncWords)], StrEq(kLastWords));
-}
-
-TEST_F(AutoFreeBufferTest, PrintFTest) {
-  constexpr char kFormatString[] = "Printf %s %d %03d %02x Test.";
-  constexpr char kParam1[] = "string";
-  constexpr int kParam2 = 1234;
-  constexpr int kParam3 = 7;
-  constexpr int kParam4 = 0x42;
-
-  char temp_buffer[1024];
-  size_t vsize = snprintf(&temp_buffer[0], sizeof(temp_buffer),
-                          kFormatString, kParam1, kParam2, kParam3, kParam4);
-
-  // Test 1: no reservation => allocate buffer.
-  EXPECT_EQ(vsize,
-            buffer_.PrintF(kFormatString, kParam1, kParam2, kParam3, kParam4));
-  // Check for size + null termination.
-  EXPECT_EQ(vsize + 1, buffer_.size());
-  EXPECT_THAT(buffer_.data(), StrEq(temp_buffer));
-
-  size_t reservation = buffer_.reserve_size();
-
-  buffer_.Clear();
-
-  // Test 2: buffer reserved: just print and return.
-  EXPECT_EQ(vsize,
-            buffer_.PrintF(kFormatString, kParam1, kParam2, kParam3, kParam4));
-  // Check for size + null termination.
-  EXPECT_EQ(vsize + 1, buffer_.size());
-  EXPECT_THAT(buffer_.data(), StrEq(temp_buffer));
-  EXPECT_EQ(reservation, buffer_.reserve_size());
-}
-
-}  // namespace test
diff --git a/common/libs/auto_resources/auto_resources.cpp b/common/libs/auto_resources/auto_resources.cpp
deleted file mode 100644
index a57c968..0000000
--- a/common/libs/auto_resources/auto_resources.cpp
+++ /dev/null
@@ -1,98 +0,0 @@
-/*
- * Copyright (C) 2016 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- *      http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-#include "common/libs/auto_resources/auto_resources.h"
-
-#include <errno.h>
-#include <stdlib.h>
-#include <string.h>
-
-AutoFreeBuffer::~AutoFreeBuffer() {
-  if (data_) free(data_);
-}
-
-void AutoFreeBuffer::Clear() {
-  size_ = 0;
-}
-
-bool AutoFreeBuffer::Reserve(size_t newsize) {
-  if (newsize > reserve_size_ ||
-      reserve_size_ > kAutoBufferShrinkReserveThreshold) {
-    char* newdata = static_cast<char*>(realloc(data_, newsize));
-    // If realloc fails, everything remains unchanged.
-    if (!newdata && newsize) return false;
-
-    reserve_size_ = newsize;
-    data_ = newdata;
-  }
-  if (size_ > newsize) size_ = newsize;
-  return true;
-}
-
-bool AutoFreeBuffer::Resize(size_t newsize) {
-  // If reservation is small, and we get a shrink request, simply reduce size_.
-  if (reserve_size_ < kAutoBufferShrinkReserveThreshold && newsize < size_) {
-    size_ = newsize;
-    return true;
-  }
-
-  if (!Reserve(newsize)) return false;
-
-  // Should we keep this? Sounds like it should be called Grow().
-  if (newsize > size_) memset(&data_[size_], 0, newsize - size_);
-  size_ = newsize;
-  return true;
-}
-
-bool AutoFreeBuffer::SetToString(const char* in) {
-  size_t newsz = strlen(in) + 1;
-  if (!Resize(newsz)) return false;
-  memcpy(data_, in, newsz);
-  return true;
-}
-
-bool AutoFreeBuffer::Append(const void* new_data, size_t new_data_size) {
-  size_t offset = size_;
-  if (!Resize(offset + new_data_size)) return false;
-  memcpy(&data_[offset], new_data, new_data_size);
-  return true;
-}
-
-size_t AutoFreeBuffer::PrintF(const char* format, ... ) {
-  va_list args;
-
-  // Optimize: Use whatever reservation left we have for initial printf.
-  // If reservation is not long enough, resize and try again.
-
-  va_start(args, format);
-  size_t printf_size = vsnprintf(data_, reserve_size_, format, args);
-  va_end(args);
-
-  // vsnprintf write no more than |reserve_size_| bytes including trailing \0.
-  // Result value equal or greater than |reserve_size_| signals truncated
-  // output.
-  if (printf_size < reserve_size_) {
-    size_ = printf_size + 1;
-    return printf_size;
-  }
-
-  // Grow buffer and re-try printf.
-  if (!Resize(printf_size + 1)) return 0;
-  va_start(args, format);
-  vsprintf(data_, format, args);
-  va_end(args);
-  return printf_size;
-}
-
diff --git a/common/libs/auto_resources/auto_resources.h b/common/libs/auto_resources/auto_resources.h
deleted file mode 100644
index 6dca6a8..0000000
--- a/common/libs/auto_resources/auto_resources.h
+++ /dev/null
@@ -1,124 +0,0 @@
-/*
- * Copyright (C) 2016 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- *      http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-#ifndef CUTTLEFISH_COMMON_COMMON_LIBS_AUTO_RESOURCES_AUTO_RESOURCES_H_
-#define CUTTLEFISH_COMMON_COMMON_LIBS_AUTO_RESOURCES_AUTO_RESOURCES_H_
-
-#include <stdarg.h>
-#include <stdio.h>
-#include <string.h>
-#include <unistd.h>
-#include <pthread.h>
-#include <sys/types.h>
-#include <sys/stat.h>
-
-template <typename T, size_t N>
-char (&ArraySizeHelper(T (&array)[N]))[N];
-
-template <typename T, size_t N>
-char (&ArraySizeHelper(const T (&array)[N]))[N];
-
-#define arraysize(array) (sizeof(ArraySizeHelper(array)))
-
-// In C++11 this is just std::vector<char>, but Android isn't
-// there yet.
-class AutoFreeBuffer {
- public:
-  enum {
-    // Minimum reserve size of AutoFreeBuffer to consider shrinking reservation.
-    // Any buffer shorter than this will not be shrunk.
-    kAutoBufferShrinkReserveThreshold = 8192
-  };
-
-  AutoFreeBuffer()
-      : data_(NULL), size_(0), reserve_size_(0) {}
-
-  AutoFreeBuffer(size_t reserve_size)
-      : data_(NULL), size_(0), reserve_size_(0) {
-    Reserve(reserve_size);
-  }
-
-  ~AutoFreeBuffer();
-  void Clear();
-  bool Resize(size_t newsize);
-  bool Reserve(size_t newsize);
-  bool SetToString(const char* in);
-  bool Append(const void* new_data, size_t new_data_size);
-  size_t PrintF(const char* format, ... );
-
-  char* data() {
-    return data_;
-  }
-
-  const char* data() const {
-    return data_;
-  }
-
-  char* begin() {
-    return data_;
-  }
-
-  const char* begin() const {
-    return data_;
-  }
-
-  char* end() {
-    return data_ + size_;
-  }
-
-  const char* end() const {
-    return data_ + size_;
-  }
-
-  size_t size() const {
-    return size_;
-  }
-
-  size_t reserve_size() const {
-    return reserve_size_;
-  }
-
-  void Swap(AutoFreeBuffer& other) {
-    char* temp_ptr = data_;
-    data_ = other.data_;
-    other.data_ = temp_ptr;
-
-    size_t temp_size = size_;
-    size_ = other.size_;
-    other.size_ = temp_size;
-
-    temp_size = reserve_size_;
-    reserve_size_ = other.reserve_size_;
-    other.reserve_size_ = temp_size;
-  }
-
-  bool operator==(const AutoFreeBuffer& other) const {
-    return (size_ == other.size_) && !memcmp(data_, other.data_, size_);
-  }
-
-  bool operator!=(const AutoFreeBuffer& other) const {
-    return !(*this == other);
-  }
-
- protected:
-  char *data_;
-  size_t size_;
-  size_t reserve_size_;
-
- private:
-  AutoFreeBuffer& operator=(const AutoFreeBuffer&);
-  explicit AutoFreeBuffer(const AutoFreeBuffer&);
-};
-#endif  // CUTTLEFISH_COMMON_COMMON_LIBS_AUTO_RESOURCES_AUTO_RESOURCES_H_
diff --git a/common/libs/fs/shared_fd.cpp b/common/libs/fs/shared_fd.cpp
index 061432a..82baad3 100644
--- a/common/libs/fs/shared_fd.cpp
+++ b/common/libs/fs/shared_fd.cpp
@@ -25,7 +25,6 @@
 #include <algorithm>
 #include <vector>
 
-#include "common/libs/auto_resources/auto_resources.h"
 #include "common/libs/glog/logging.h"
 #include "common/libs/fs/shared_select.h"
 
diff --git a/common/libs/fs/shared_fd.h b/common/libs/fs/shared_fd.h
index b64ad09..99deef1 100644
--- a/common/libs/fs/shared_fd.h
+++ b/common/libs/fs/shared_fd.h
@@ -40,7 +40,6 @@
 #include <string.h>
 #include <unistd.h>
 
-#include "common/libs/auto_resources/auto_resources.h"
 #include "vm_sockets.h"
 
 /**
diff --git a/guest/hals/camera/EmulatedFakeCamera2.cpp b/guest/hals/camera/EmulatedFakeCamera2.cpp
index e292361..393adf1 100644
--- a/guest/hals/camera/EmulatedFakeCamera2.cpp
+++ b/guest/hals/camera/EmulatedFakeCamera2.cpp
@@ -32,12 +32,19 @@
 #include "EmulatedCameraFactory.h"
 #include "EmulatedFakeCamera2.h"
 #include "GrallocModule.h"
-#include "common/libs/auto_resources/auto_resources.h"
 
 #define ERROR_CAMERA_NOT_PRESENT -EPIPE
 
 #define CAMERA2_EXT_TRIGGER_TESTING_DISCONNECT 0xFFFFFFFF
 
+template <typename T, size_t N>
+char (&ArraySizeHelper(T (&array)[N]))[N];
+
+template <typename T, size_t N>
+char (&ArraySizeHelper(const T (&array)[N]))[N];
+
+#define arraysize(array) (sizeof(ArraySizeHelper(array)))
+
 namespace android {
 
 const int64_t USEC = 1000LL;
diff --git a/guest/hals/gralloc/legacy/gralloc.cpp b/guest/hals/gralloc/legacy/gralloc.cpp
index dbe2838..28e71eb 100644
--- a/guest/hals/gralloc/legacy/gralloc.cpp
+++ b/guest/hals/gralloc/legacy/gralloc.cpp
@@ -35,7 +35,6 @@
 #include <hardware/hardware.h>
 #include <hardware/gralloc.h>
 
-#include "common/libs/auto_resources/auto_resources.h"
 #include "gralloc_vsoc_priv.h"
 #include "region_registry.h"