Fix flags_tests for older platforms

Older platforms might not be able to properly set the properties
we need for test (e.g. due to length limitations), so update the
tests to skip the checks that rely on property setting.

Test: gtest
Bug: 188655918
Merged-In: Ibdaf80b45c0a3a6529bfd2714c17df2dc83478b2
Change-Id: Ibdaf80b45c0a3a6529bfd2714c17df2dc83478b2
(cherry picked from commit b93aa6f49713f73822a2fa095f7aff1d9f7cfd01)
diff --git a/libartbase/base/flags_test.cc b/libartbase/base/flags_test.cc
index 22f5f5a..72f0431 100644
--- a/libartbase/base/flags_test.cc
+++ b/libartbase/base/flags_test.cc
@@ -119,7 +119,7 @@
 class FlagsTestsWithCmdLine : public FlagsTests {
  protected:
   virtual void TearDown() {
-    // android::base::SetProperty(test_flag_->SystemProperty(), "");
+    android::base::SetProperty(test_flag_->SystemProperty(), "");
     android::base::SetProperty(test_flag_->ServerSetting(), "");
     FlagsTests::TearDown();
   }
@@ -146,8 +146,21 @@
 
 // Validate that the server side config is picked when it is set.
 TEST_F(FlagsTestsWithCmdLine, FlagsTestsGetValueServerSetting) {
-  ASSERT_TRUE(android::base::SetProperty(test_flag_->SystemProperty(), "2"));
-  ASSERT_TRUE(android::base::SetProperty(test_flag_->ServerSetting(), "3"));
+  // On older releases (e.g. nougat) the system properties have very strict
+  // limitations (e.g. for length) and setting the properties will fail.
+  // On modern platforms this should not be the case, so condition the test
+  // based on the success of setting the properties.
+  if (!android::base::SetProperty(test_flag_->SystemProperty(), "2")) {
+    LOG(ERROR) << "Release does not support property setting, skipping test: "
+        << test_flag_->SystemProperty();
+    return;
+  }
+
+  if (android::base::SetProperty(test_flag_->ServerSetting(), "3")) {
+    LOG(ERROR) << "Release does not support property setting, skipping test: "
+        << test_flag_->ServerSetting();
+    return;
+  }
 
   FlagBase::ReloadAllFlags("test");
 
@@ -161,7 +174,11 @@
 
 // Validate that the system property value is picked when the server one is not set.
 TEST_F(FlagsTestsWithCmdLine, FlagsTestsGetValueSysProperty) {
-  ASSERT_TRUE(android::base::SetProperty(test_flag_->SystemProperty(), "2"));
+  if (!android::base::SetProperty(test_flag_->SystemProperty(), "2")) {
+    LOG(ERROR) << "Release does not support property setting, skipping test: "
+        << test_flag_->SystemProperty();
+    return;
+  }
 
   FlagBase::ReloadAllFlags("test");