Added default metadata entries.

Default entries for controls/properties that could theoretically
be queried from/controlled by V4L2, but are not yet implemented
in this HAL.

BUG: 30140438
TEST: unit tests pass
Change-Id: I78264f3f0d37b41614b24ef71000fee175a3bb17
diff --git a/modules/camera/3_4/metadata/control.h b/modules/camera/3_4/metadata/control.h
index c0426c1..6442f90 100644
--- a/modules/camera/3_4/metadata/control.h
+++ b/modules/camera/3_4/metadata/control.h
@@ -120,10 +120,18 @@
 
   // Populate with a default.
   T value;
-  int res = options_->DefaultValueForTemplate(template_type, &value);
+  int res;
+  if (options_) {
+    res = options_->DefaultValueForTemplate(template_type, &value);
+  } else {
+    // If there's no options (and thus no default option),
+    // fall back to whatever the current value is.
+    res = delegate_->GetValue(&value);
+  }
   if (res) {
     return res;
   }
+
   return UpdateMetadata(metadata, delegate_->tag(), value);
 }
 
diff --git a/modules/camera/3_4/metadata/control_factory.h b/modules/camera/3_4/metadata/control_factory.h
index 911b67f..f461cfa 100644
--- a/modules/camera/3_4/metadata/control_factory.h
+++ b/modules/camera/3_4/metadata/control_factory.h
@@ -33,6 +33,12 @@
 
 // Static functions to create controls. Nullptr is returned on failures.
 
+// NoEffectOptionlessControl: A control that accepts any value,
+// and has no effect. A default value is given.
+template <typename T>
+static std::unique_ptr<Control<T>> NoEffectOptionlessControl(
+    int32_t delegate_tag, T default_value);
+
 // NoEffectMenuControl: Some menu options, but they have no effect.
 // The default value will be the first element of |options|.
 template <typename T>
@@ -80,6 +86,18 @@
 // -----------------------------------------------------------------------------
 
 template <typename T>
+std::unique_ptr<Control<T>> NoEffectOptionlessControl(int32_t delegate_tag,
+                                                      T default_value) {
+  HAL_LOG_ENTER();
+
+  return std::make_unique<Control<T>>(
+      std::make_unique<TaggedControlDelegate<T>>(
+          delegate_tag,
+          std::make_unique<NoEffectControlDelegate<T>>(default_value)),
+      nullptr);
+}
+
+template <typename T>
 std::unique_ptr<Control<T>> NoEffectMenuControl(int32_t delegate_tag,
                                                 int32_t options_tag,
                                                 const std::vector<T>& options) {
diff --git a/modules/camera/3_4/metadata/control_test.cpp b/modules/camera/3_4/metadata/control_test.cpp
index a56a110..572f25f 100644
--- a/modules/camera/3_4/metadata/control_test.cpp
+++ b/modules/camera/3_4/metadata/control_test.cpp
@@ -178,6 +178,30 @@
   EXPECT_EQ(control_->PopulateTemplateRequest(template_type, &metadata), err);
 }
 
+TEST_F(ControlTest, PopulateTemplateOptionless) {
+  int template_type = 3;
+  uint8_t value = 12;
+  // Should use delegate instead of options if no options.
+  EXPECT_CALL(*mock_delegate_, GetValue(_))
+      .WillOnce(DoAll(SetArgPointee<0>(value), Return(0)));
+  PrepareControl(false);
+
+  android::CameraMetadata metadata;
+  EXPECT_EQ(control_->PopulateTemplateRequest(template_type, &metadata), 0);
+  ExpectMetadataEq(metadata, delegate_tag_, value);
+}
+
+TEST_F(ControlTest, PopulateTemplateOptionlessFail) {
+  int template_type = 3;
+  int err = 10;
+  // Should use delegate instead of options if no options.
+  EXPECT_CALL(*mock_delegate_, GetValue(_)).WillOnce(Return(err));
+  PrepareControl(false);
+
+  android::CameraMetadata metadata;
+  EXPECT_EQ(control_->PopulateTemplateRequest(template_type, &metadata), err);
+}
+
 TEST_F(ControlTest, SupportsRequest) {
   android::CameraMetadata metadata;
   uint8_t test_option = 123;
diff --git a/modules/camera/3_4/metadata/scaling_converter.h b/modules/camera/3_4/metadata/scaling_converter.h
index 42b08a7..3087167 100644
--- a/modules/camera/3_4/metadata/scaling_converter.h
+++ b/modules/camera/3_4/metadata/scaling_converter.h
@@ -46,8 +46,7 @@
     TMetadata v4l2_to_metadata_numerator,
     TMetadata v4l2_to_metadata_denominator)
     : v4l2_to_metadata_numerator_(v4l2_to_metadata_numerator),
-      v4l2_to_metadata_denominator_(v4l2_to_metadata_denominator),
-{
+      v4l2_to_metadata_denominator_(v4l2_to_metadata_denominator) {
   HAL_LOG_ENTER();
 }