API dump for an AIDL interface consists of multiple AIDL files

API dump of an AIDL interface now consist of multiple AIDL files each of
which is for an AIDL type. We no longer has the single big AIDL file
having signatures for all defined types. This is in preparation for building
against API dumps of an AIDL interface.

The change is required because the build system needs to correctly track
all inputs and outputs; when the API dump is in a single file, the build
system can't tell the list of output files (sources and headers) because
that is dependent on the list of types in the dump and it can only be
known after actually parsing the dump.

Now, as each type in an API dump is recorded in a file whose path is
encoding the type name (e.g., <api_dir>/foo/bar/IFoo.aidl means an
interface named IFoo in package foo.bar), the build system can infer the
generated source code from the type names (e.g, foo.bar.IFoo.aidl is
generated to <out>/foo/bar/IFoo.[cpp|java] and [I|Bp|Bn]Foo.h).

This also includes a change that allows a type to be referenced without
requiring the import statement if the type name is a fully quallfied
one (just like Java).

Before:
import foo.bar.OtherType; // this was a must
interface My { void foo(in foo.bar.OtherType arg); }

After:
interface My { void foo(in foo.bar.OtherType arg); }
// ok as foo.bar.OtherType is a fully qualified name

This is also in preparation for the building against API dumps. The API
dump does not have import statements but all type references are fully
qualified.

Bug: 110758635
Test: m -j
Test: m update-aidl-api
Test: m check-aidl-api
Change-Id: I27d8a314558878baca81c8495644ea18db72dfce
diff --git a/io_delegate.cpp b/io_delegate.cpp
index 81f536d..4b2e00a 100644
--- a/io_delegate.cpp
+++ b/io_delegate.cpp
@@ -23,7 +23,9 @@
 #ifdef _WIN32
 #include <direct.h>
 #else
+#include <dirent.h>
 #include <sys/stat.h>
+#include <sys/types.h>
 #include <unistd.h>
 #endif
 
@@ -191,5 +193,36 @@
 #endif
 }
 
+#ifdef _WIN32
+vector<string> IoDelegate::ListFiles(const string&) const {
+  vector<string> result;
+  return result;
+}
+
+#else
+static void add_list_files(const string& dirname, vector<string>* result) {
+  CHECK(result != nullptr);
+  std::unique_ptr<DIR, decltype(&closedir)> dir(opendir(dirname.c_str()), closedir);
+  if (dir != nullptr) {
+    while (struct dirent* ent = readdir(dir.get())) {
+      if (!strcmp(ent->d_name, ".") || !strcmp(ent->d_name, "..")) {
+        continue;
+      }
+      if (ent->d_type == DT_REG) {
+        result->emplace_back(dirname + OS_PATH_SEPARATOR + ent->d_name);
+      } else if (ent->d_type == DT_DIR) {
+        add_list_files(dirname + OS_PATH_SEPARATOR + ent->d_name, result);
+      }
+    }
+  }
+}
+
+vector<string> IoDelegate::ListFiles(const string& dir) const {
+  vector<string> result;
+  add_list_files(dir, &result);
+  return result;
+}
+#endif
+
 }  // namespace android
 }  // namespace aidl