Add ignored controls metadata.

Ignored controls are optioned controls where the value
set by the user is tracked, but doesn't actually matter.

BUG: 30140438
Change-Id: I45819c3c6c855922418f76fd34309a44660fc3f0
TEST: unit tests pass
diff --git a/modules/camera/3_4/Android.mk b/modules/camera/3_4/Android.mk
index 01574b9..7b644c3 100644
--- a/modules/camera/3_4/Android.mk
+++ b/modules/camera/3_4/Android.mk
@@ -51,6 +51,7 @@
 v4l2_test_files := \
   metadata/control_test.cpp \
   metadata/fixed_property_test.cpp \
+  metadata/ignored_control_test.cpp \
   metadata/metadata_test.cpp \
   metadata/optioned_control_test.cpp \
 
diff --git a/modules/camera/3_4/metadata/ignored_control.h b/modules/camera/3_4/metadata/ignored_control.h
new file mode 100644
index 0000000..ef36784
--- /dev/null
+++ b/modules/camera/3_4/metadata/ignored_control.h
@@ -0,0 +1,69 @@
+/*
+ * 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 V4L2_CAMERA_HAL_METADATA_IGNORED_CONTROL_H_
+#define V4L2_CAMERA_HAL_METADATA_IGNORED_CONTROL_H_
+
+#include <vector>
+
+#include <gtest/gtest_prod.h>
+
+#include "../common.h"
+#include "optioned_control.h"
+
+namespace v4l2_camera_hal {
+
+// A IgnoredControl is a PartialMetadata with a few static options that can
+// be chosen from, but they do nothing.
+template <typename T>
+class IgnoredControl : public OptionedControl<T> {
+ public:
+  IgnoredControl(int32_t control_tag, int32_t options_tag,
+                 std::vector<T> options, T default_option)
+      : OptionedControl<T>(control_tag, options_tag, options),
+        // Note: default option is not enforced as being in |options|,
+        // but it may be confusing if it isn't.
+        current_setting_(default_option) {
+    HAL_LOG_ENTER();
+  };
+
+ protected:
+  virtual int GetValue(T* value) const override {
+    HAL_LOG_ENTER();
+    *value = current_setting_;
+    return 0;
+  };
+  virtual int SetValue(const T& value) override {
+    HAL_LOG_ENTER();
+    if (!OptionedControl<T>::IsSupported(value)) {
+      return -EINVAL;
+    }
+    current_setting_ = value;
+    return 0;
+  };
+
+ private:
+  T current_setting_;
+
+  FRIEND_TEST(IgnoredControlTest, GetDefaultValue);
+  FRIEND_TEST(IgnoredControlTest, SetAndGetValue);
+  FRIEND_TEST(IgnoredControlTest, SetAndGetBadValue);
+  DISALLOW_COPY_AND_ASSIGN(IgnoredControl);
+};
+
+}  // namespace v4l2_camera_hal
+
+#endif  // V4L2_CAMERA_HAL_METADATA_IGNORED_CONTROL_H_
diff --git a/modules/camera/3_4/metadata/ignored_control_test.cpp b/modules/camera/3_4/metadata/ignored_control_test.cpp
new file mode 100644
index 0000000..bab3754
--- /dev/null
+++ b/modules/camera/3_4/metadata/ignored_control_test.cpp
@@ -0,0 +1,104 @@
+/*
+ * 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 "ignored_control.h"
+
+#include <array>
+
+#include <camera/CameraMetadata.h>
+#include <gmock/gmock.h>
+#include <gtest/gtest.h>
+
+#include "array_vector.h"
+
+using testing::AtMost;
+using testing::Return;
+using testing::ReturnRef;
+using testing::Test;
+using testing::_;
+
+namespace v4l2_camera_hal {
+
+class IgnoredControlTest : public Test {
+ protected:
+  IgnoredControlTest()
+      : options_({ANDROID_COLOR_CORRECTION_ABERRATION_MODE_OFF,
+                  ANDROID_COLOR_CORRECTION_ABERRATION_MODE_FAST,
+                  ANDROID_COLOR_CORRECTION_ABERRATION_MODE_HIGH_QUALITY}),
+        default_option_(options_[2]) {}
+
+  virtual void SetUp() {
+    control_.reset(new IgnoredControl<uint8_t>(control_tag_, options_tag_,
+                                               options_, default_option_));
+  }
+
+  std::unique_ptr<IgnoredControl<uint8_t>> control_;
+
+  // Need tags that match the data type (uint8_t) being passed.
+  static constexpr int32_t options_tag_ =
+      ANDROID_COLOR_CORRECTION_AVAILABLE_ABERRATION_MODES;
+  static constexpr int32_t control_tag_ =
+      ANDROID_COLOR_CORRECTION_ABERRATION_MODE;
+
+  const std::vector<uint8_t> options_;
+  const uint8_t default_option_;
+};
+
+TEST_F(IgnoredControlTest, Tags) {
+  // The macro doesn't like the static variables
+  // being passed directly to assertions.
+  int32_t expected_tag = options_tag_;
+  ASSERT_EQ(control_->StaticTags().size(), 1);
+  EXPECT_EQ(control_->StaticTags()[0], expected_tag);
+
+  // Controls use the same tag for getting and setting.
+  expected_tag = control_tag_;
+  ASSERT_EQ(control_->ControlTags().size(), 1);
+  EXPECT_EQ(control_->ControlTags()[0], expected_tag);
+  ASSERT_EQ(control_->DynamicTags().size(), 1);
+  EXPECT_EQ(control_->DynamicTags()[0], expected_tag);
+}
+
+TEST_F(IgnoredControlTest, GetDefaultValue) {
+  uint8_t value;
+  EXPECT_EQ(control_->GetValue(&value), 0);
+  EXPECT_EQ(value, default_option_);
+}
+
+TEST_F(IgnoredControlTest, SetAndGetValue) {
+  uint8_t new_value = options_[0];
+  // Make sure this isn't just testing overwriting the default with itself.
+  ASSERT_NE(new_value, default_option_);
+
+  EXPECT_EQ(control_->SetValue(new_value), 0);
+  uint8_t result = new_value + 1;  // Initialize to something incorrect.
+  EXPECT_EQ(control_->GetValue(&result), 0);
+  EXPECT_EQ(result, new_value);
+}
+
+TEST_F(IgnoredControlTest, SetAndGetBadValue) {
+  uint8_t unsupported_value = 99;
+  // Make sure this is actually unsupported
+  ASSERT_FALSE(control_->IsSupported(unsupported_value));
+
+  EXPECT_EQ(control_->SetValue(unsupported_value), -EINVAL);
+  // Value shouldn't have changed.
+  uint8_t result = default_option_ + 1;  // Initialize to something incorrect.
+  EXPECT_EQ(control_->GetValue(&result), 0);
+  EXPECT_EQ(result, default_option_);
+}
+
+}  // namespace v4l2_camera_hal