Add --min_sdk_version flag to the compiler

The flag is used to set the minimum SDK version that the generated code
should support. This will allow the compiler to generate code that
makes use of newer platform features (e.g. new APIs) when it is
guaranteed that the generated code always runs on such platforms.

For now, this flag is no-op.

Bug: 175819535
Test: aidl_unittests
Change-Id: I5297f940b0327f3e057db984b6efb454266e4923
diff --git a/options_unittest.cpp b/options_unittest.cpp
index 9f07400..e90c8b5 100644
--- a/options_unittest.cpp
+++ b/options_unittest.cpp
@@ -445,5 +445,52 @@
   EXPECT_THAT(GetCapturedStderr(), testing::HasSubstr("Unsupported --checkapi level: 'unknown'"));
 }
 
+TEST(OptionsTest, AcceptValidMinSdkVersion) {
+  const char* args[] = {
+      "aidl", "--lang=java", "--min_sdk_version=30", "--out=out", "input.aidl", nullptr,
+  };
+  auto options = GetOptions(args);
+  EXPECT_TRUE(options->Ok());
+  EXPECT_EQ(30u, options->GetMinSdkVersion());
+}
+
+TEST(OPtionsTests, AcceptCodeNameAsMinSdkVersion) {
+  const char* args[] = {
+      "aidl", "--lang=java", "--min_sdk_version=Tiramisu", "--out=out", "input.aidl", nullptr,
+  };
+  auto options = GetOptions(args);
+  EXPECT_TRUE(options->Ok());
+  EXPECT_EQ(10000u, options->GetMinSdkVersion());
+}
+
+TEST(OptionsTest, DefaultMinSdkVersion) {
+  const char* args[] = {
+      "aidl", "--lang=java", "--out=out", "input.aidl", nullptr,
+  };
+  auto options = GetOptions(args);
+  EXPECT_TRUE(options->Ok());
+  EXPECT_EQ(DEFAULT_SDK_VERSION_JAVA, options->GetMinSdkVersion());
+}
+
+TEST(OptionsTest, RejectInvalidMinSdkVersion) {
+  const char* args[] = {
+      "aidl", "--lang=java", "--min_sdk_version=NOT_A_VERSION", "--out=out", "input.aidl", nullptr,
+  };
+  CaptureStderr();
+  auto options = GetOptions(args);
+  EXPECT_FALSE(options->Ok());
+  EXPECT_THAT(GetCapturedStderr(), testing::HasSubstr("Invalid SDK version: NOT_A_VERSION"));
+}
+
+TEST(OptionsTest, RejectOldMinSdkVersion) {
+  const char* args[] = {
+      "aidl", "--lang=java", "--min_sdk_version=22", "--out=out", "input.aidl", nullptr,
+  };
+  CaptureStderr();
+  auto options = GetOptions(args);
+  EXPECT_FALSE(options->Ok());
+  EXPECT_THAT(GetCapturedStderr(), testing::HasSubstr("Min SDK version should at least be 23"));
+}
+
 }  // namespace aidl
 }  // namespace android