weaved: Remove brillo::Any from public weaved APIs

Replaced brillo::Any with base::Value in weaved client library
APIs in order to remove remaining dependency on D-Bus libraries.

BUG: 26558300
Change-Id: I8365743c31022a2f76a8a8768adf6ad19d509749
diff --git a/Android.mk b/Android.mk
index d1b171d..7f2e483 100644
--- a/Android.mk
+++ b/Android.mk
@@ -84,7 +84,6 @@
 	brillo/android/weave/IWeaveServiceManagerNotificationListener.aidl \
 	common/binder_constants.cc \
 	common/binder_utils.cc \
-	common/data_conversion.cc \
 
 include $(BUILD_STATIC_LIBRARY)
 
@@ -165,7 +164,13 @@
 LOCAL_CPPFLAGS := $(buffetCommonCppFlags)
 LOCAL_C_INCLUDES := external/gtest/include
 LOCAL_EXPORT_C_INCLUDE_DIRS := $(LOCAL_PATH)
-LOCAL_SHARED_LIBRARIES := $(buffetSharedLibraries)
+LOCAL_SHARED_LIBRARIES := \
+	libbinder \
+	libbinderwrapper \
+	libbrillo \
+	libchrome \
+	libutils \
+
 LOCAL_STATIC_LIBRARIES := weave-common
 
 LOCAL_CLANG := true
@@ -206,6 +211,5 @@
 	buffet/binder_command_proxy_unittest.cc \
 	buffet/buffet_config_unittest.cc \
 	buffet/buffet_testrunner.cc \
-	common/data_conversion_unittest.cc \
 
 include $(BUILD_NATIVE_TEST)
diff --git a/common/binder_utils.cc b/common/binder_utils.cc
index 6f66040..641019a 100644
--- a/common/binder_utils.cc
+++ b/common/binder_utils.cc
@@ -16,6 +16,7 @@
 
 #include <base/json/json_reader.h>
 #include <base/json/json_writer.h>
+#include <weave/error.h>
 
 namespace weaved {
 namespace binder_utils {
diff --git a/common/binder_utils.h b/common/binder_utils.h
index 65b462d..3aa5eda 100644
--- a/common/binder_utils.h
+++ b/common/binder_utils.h
@@ -22,9 +22,13 @@
 #include <binder/Status.h>
 #include <utils/String8.h>
 #include <utils/String16.h>
-#include <weave/error.h>
 #include <brillo/errors/error.h>
 
+namespace weave {
+class Error;  // Forward declaration.
+using ErrorPtr = std::unique_ptr<Error>;
+}  // namespace weave
+
 namespace weaved {
 namespace binder_utils {
 
diff --git a/common/data_conversion.cc b/common/data_conversion.cc
deleted file mode 100644
index fd20ad4..0000000
--- a/common/data_conversion.cc
+++ /dev/null
@@ -1,263 +0,0 @@
-// Copyright 2015 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 "common/data_conversion.h"
-
-#include <string>
-#include <vector>
-
-#include <brillo/type_name_undecorate.h>
-
-namespace weaved {
-
-namespace {
-
-// Helpers for JsonToAny().
-template <typename T>
-brillo::Any ValueToAny(const base::Value& json,
-                       bool (base::Value::*fnc)(T*) const) {
-  T val;
-  CHECK((json.*fnc)(&val));
-  return val;
-}
-
-brillo::Any ValueToAny(const base::Value& json);
-
-template <typename T>
-brillo::Any ListToAny(const base::ListValue& list,
-                      bool (base::Value::*fnc)(T*) const) {
-  std::vector<T> result;
-  result.reserve(list.GetSize());
-  for (const base::Value* v : list) {
-    T val;
-    CHECK((v->*fnc)(&val));
-    result.push_back(val);
-  }
-  return result;
-}
-
-brillo::Any DictListToAny(const base::ListValue& list) {
-  std::vector<brillo::VariantDictionary> result;
-  result.reserve(list.GetSize());
-  for (const base::Value* v : list) {
-    const base::DictionaryValue* dict = nullptr;
-    CHECK(v->GetAsDictionary(&dict));
-    result.push_back(details::DictionaryValueToVariantDictionary(*dict));
-  }
-  return result;
-}
-
-brillo::Any ListListToAny(const base::ListValue& list) {
-  std::vector<brillo::Any> result;
-  result.reserve(list.GetSize());
-  for (const base::Value* v : list)
-    result.push_back(ValueToAny(*v));
-  return result;
-}
-
-// Converts a JSON value into an Any so it can be sent over D-Bus using
-// UpdateState D-Bus method from Buffet.
-brillo::Any ValueToAny(const base::Value& json) {
-  brillo::Any prop_value;
-  switch (json.GetType()) {
-    case base::Value::TYPE_BOOLEAN:
-      prop_value = ValueToAny<bool>(json, &base::Value::GetAsBoolean);
-      break;
-    case base::Value::TYPE_INTEGER:
-      prop_value = ValueToAny<int>(json, &base::Value::GetAsInteger);
-      break;
-    case base::Value::TYPE_DOUBLE:
-      prop_value = ValueToAny<double>(json, &base::Value::GetAsDouble);
-      break;
-    case base::Value::TYPE_STRING:
-      prop_value = ValueToAny<std::string>(json, &base::Value::GetAsString);
-      break;
-    case base::Value::TYPE_DICTIONARY: {
-      const base::DictionaryValue* dict = nullptr;
-      CHECK(json.GetAsDictionary(&dict));
-      prop_value = details::DictionaryValueToVariantDictionary(*dict);
-      break;
-    }
-    case base::Value::TYPE_LIST: {
-      const base::ListValue* list = nullptr;
-      CHECK(json.GetAsList(&list));
-      if (list->empty()) {
-        // We don't know type of objects this list intended for, so we just use
-        // vector<brillo::Any>.
-        prop_value = ListListToAny(*list);
-        break;
-      }
-      auto type = (*list->begin())->GetType();
-      for (const base::Value* v : *list)
-        CHECK_EQ(v->GetType(), type) << "Unsupported different type elements";
-
-      switch (type) {
-        case base::Value::TYPE_BOOLEAN:
-          prop_value = ListToAny<bool>(*list, &base::Value::GetAsBoolean);
-          break;
-        case base::Value::TYPE_INTEGER:
-          prop_value = ListToAny<int>(*list, &base::Value::GetAsInteger);
-          break;
-        case base::Value::TYPE_DOUBLE:
-          prop_value = ListToAny<double>(*list, &base::Value::GetAsDouble);
-          break;
-        case base::Value::TYPE_STRING:
-          prop_value = ListToAny<std::string>(*list, &base::Value::GetAsString);
-          break;
-        case base::Value::TYPE_DICTIONARY:
-          prop_value = DictListToAny(*list);
-          break;
-        case base::Value::TYPE_LIST:
-          // We can't support Any{vector<vector<>>} as the type is only known
-          // in runtime when we need to instantiate templates in compile time.
-          // We can use Any{vector<Any>} instead.
-          prop_value = ListListToAny(*list);
-          break;
-        default:
-          LOG(FATAL) << "Unsupported JSON value type for list element: "
-                     << (*list->begin())->GetType();
-      }
-      break;
-    }
-    default:
-      LOG(FATAL) << "Unexpected JSON value type: " << json.GetType();
-      break;
-  }
-  return prop_value;
-}
-
-template <typename T>
-std::unique_ptr<base::Value> CreateValue(const T& value,
-                                         brillo::ErrorPtr* error) {
-  return std::unique_ptr<base::Value>{new base::FundamentalValue{value}};
-}
-
-std::unique_ptr<base::Value> CreateValue(const std::string& value,
-                                         brillo::ErrorPtr* error) {
-  return std::unique_ptr<base::Value>{new base::StringValue{value}};
-}
-
-std::unique_ptr<base::Value> CreateValue(const char* value,
-                                         brillo::ErrorPtr* error) {
-  return std::unique_ptr<base::Value>{new base::StringValue{value}};
-}
-
-template <>
-std::unique_ptr<base::Value> CreateValue<brillo::VariantDictionary>(
-    const brillo::VariantDictionary& value,
-    brillo::ErrorPtr* error) {
-  return details::VariantDictionaryToDictionaryValue(value, error);
-}
-
-template <typename T>
-std::unique_ptr<base::ListValue> CreateListValue(const std::vector<T>& value,
-                                                 brillo::ErrorPtr* error) {
-  std::unique_ptr<base::ListValue> list{new base::ListValue};
-
-  for (const T& i : value) {
-    auto item = CreateValue(i, error);
-    if (!item)
-      return nullptr;
-    list->Append(item.release());
-  }
-
-  return list;
-}
-
-// Returns false only in case of error. True can be returned if type is not
-// matched.
-template <typename T>
-bool TryCreateValue(const brillo::Any& any,
-                    std::unique_ptr<base::Value>* value,
-                    brillo::ErrorPtr* error) {
-  if (any.IsTypeCompatible<T>()) {
-    *value = CreateValue(any.Get<T>(), error);
-    return *value != nullptr;
-  }
-
-  if (any.IsTypeCompatible<std::vector<T>>()) {
-    *value = CreateListValue(any.Get<std::vector<T>>(), error);
-    return *value != nullptr;
-  }
-
-  return true;  // Not an error, we will try different type.
-}
-
-template <>
-std::unique_ptr<base::Value> CreateValue<brillo::Any>(
-    const brillo::Any& any,
-    brillo::ErrorPtr* error) {
-  std::unique_ptr<base::Value> result;
-  if (!TryCreateValue<bool>(any, &result, error) || result)
-    return result;
-
-  if (!TryCreateValue<int>(any, &result, error) || result)
-    return result;
-
-  if (!TryCreateValue<double>(any, &result, error) || result)
-    return result;
-
-  if (!TryCreateValue<std::string>(any, &result, error) || result)
-    return result;
-
-  if (any.IsTypeCompatible<const char*>())
-    return CreateValue(any.Get<const char*>(), error);
-
-  if (!TryCreateValue<brillo::VariantDictionary>(any, &result, error) ||
-      result) {
-    return result;
-  }
-
-  // This will collapse Any{Any{T}} and vector{Any{T}}.
-  if (!TryCreateValue<brillo::Any>(any, &result, error) || result)
-    return result;
-
-  brillo::Error::AddToPrintf(
-      error, FROM_HERE, "buffet", "unknown_type", "Type '%s' is not supported.",
-      any.GetUndecoratedTypeName().c_str());
-
-  return nullptr;
-}
-
-}  // namespace
-
-namespace details {
-
-brillo::VariantDictionary DictionaryValueToVariantDictionary(
-    const base::DictionaryValue& object) {
-  brillo::VariantDictionary result;
-
-  for (base::DictionaryValue::Iterator it(object); !it.IsAtEnd(); it.Advance())
-    result.emplace(it.key(), ValueToAny(it.value()));
-
-  return result;
-}
-
-std::unique_ptr<base::DictionaryValue> VariantDictionaryToDictionaryValue(
-    const brillo::VariantDictionary& object,
-    brillo::ErrorPtr* error) {
-  std::unique_ptr<base::DictionaryValue> result{new base::DictionaryValue};
-
-  for (const auto& pair : object) {
-    auto value = CreateValue(pair.second, error);
-    if (!value)
-      return nullptr;
-    result->Set(pair.first, value.release());
-  }
-
-  return result;
-}
-
-}  // namespace details
-}  // namespace weaved
diff --git a/common/data_conversion.h b/common/data_conversion.h
deleted file mode 100644
index accc520..0000000
--- a/common/data_conversion.h
+++ /dev/null
@@ -1,38 +0,0 @@
-// Copyright 2015 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 COMMON_DATA_CONVERSION_H_
-#define COMMON_DATA_CONVERSION_H_
-
-#include <base/values.h>
-#include <brillo/any.h>
-#include <brillo/errors/error.h>
-#include <brillo/variant_dictionary.h>
-
-namespace weaved {
-namespace details {
-
-// Converts DictionaryValue to variant dictionary.
-brillo::VariantDictionary DictionaryValueToVariantDictionary(
-    const base::DictionaryValue& object);
-
-// Converts variant dictionary to DictionaryValue.
-std::unique_ptr<base::DictionaryValue> VariantDictionaryToDictionaryValue(
-    const brillo::VariantDictionary& object,
-    brillo::ErrorPtr* error);
-
-}  // namespace details
-}  // namespace weaved
-
-#endif  // COMMON_DATA_CONVERSION_H_
diff --git a/common/data_conversion_unittest.cc b/common/data_conversion_unittest.cc
deleted file mode 100644
index 7f84cdb..0000000
--- a/common/data_conversion_unittest.cc
+++ /dev/null
@@ -1,200 +0,0 @@
-// Copyright 2015 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 "common/data_conversion.h"
-
-#include <limits>
-#include <memory>
-#include <string>
-#include <vector>
-
-#include <base/guid.h>
-#include <base/rand_util.h>
-#include <base/values.h>
-#include <brillo/variant_dictionary.h>
-#include <gtest/gtest.h>
-#include <weave/test/unittest_utils.h>
-
-namespace weaved {
-
-namespace {
-
-using brillo::Any;
-using brillo::VariantDictionary;
-using weave::test::CreateDictionaryValue;
-using weave::test::IsEqualValue;
-
-brillo::VariantDictionary ToVariant(const base::DictionaryValue& object) {
-  return details::DictionaryValueToVariantDictionary(object);
-}
-
-std::unique_ptr<base::DictionaryValue> FromVariant(
-    const brillo::VariantDictionary& object) {
-  brillo::ErrorPtr error;
-  auto result = details::VariantDictionaryToDictionaryValue(object, &error);
-  EXPECT_TRUE(result || error);
-  return result;
-}
-
-std::unique_ptr<base::Value> CreateRandomValue(int children);
-std::unique_ptr<base::Value> CreateRandomValue(int children,
-                                               base::Value::Type type);
-
-const base::Value::Type kRandomTypes[] = {
-    base::Value::TYPE_BOOLEAN,    base::Value::TYPE_INTEGER,
-    base::Value::TYPE_DOUBLE,     base::Value::TYPE_STRING,
-    base::Value::TYPE_DICTIONARY, base::Value::TYPE_LIST,
-};
-
-const base::Value::Type kRandomTypesWithChildren[] = {
-    base::Value::TYPE_DICTIONARY, base::Value::TYPE_LIST,
-};
-
-base::Value::Type CreateRandomValueType(bool with_children) {
-  if (with_children) {
-    return kRandomTypesWithChildren[base::RandInt(
-        0, arraysize(kRandomTypesWithChildren) - 1)];
-  }
-  return kRandomTypes[base::RandInt(0, arraysize(kRandomTypes) - 1)];
-}
-
-std::unique_ptr<base::DictionaryValue> CreateRandomDictionary(int children) {
-  std::unique_ptr<base::DictionaryValue> result{new base::DictionaryValue};
-
-  while (children > 0) {
-    int sub_children = base::RandInt(1, children);
-    children -= sub_children;
-    result->Set(base::GenerateGUID(),
-                CreateRandomValue(sub_children).release());
-  }
-
-  return result;
-}
-
-std::unique_ptr<base::ListValue> CreateRandomList(int children) {
-  std::unique_ptr<base::ListValue> result{new base::ListValue};
-
-  base::Value::Type type = CreateRandomValueType(children > 0);
-  while (children > 0) {
-    size_t max_children =
-        (type != base::Value::TYPE_DICTIONARY && type != base::Value::TYPE_LIST)
-            ? 1
-            : children;
-    size_t sub_children = base::RandInt(1, max_children);
-    children -= sub_children;
-    result->Append(CreateRandomValue(sub_children, type).release());
-  }
-
-  return result;
-}
-
-std::unique_ptr<base::Value> CreateRandomValue(int children,
-                                               base::Value::Type type) {
-  CHECK_GE(children, 1);
-  switch (type) {
-    case base::Value::TYPE_INTEGER:
-      return std::unique_ptr<base::Value>{new base::FundamentalValue{
-          base::RandInt(std::numeric_limits<int>::min(),
-                        std::numeric_limits<int>::max())}};
-    case base::Value::TYPE_DOUBLE:
-      return std::unique_ptr<base::Value>{
-          new base::FundamentalValue{base::RandDouble()}};
-    case base::Value::TYPE_STRING:
-      return std::unique_ptr<base::Value>{
-          new base::StringValue{base::GenerateGUID()}};
-    case base::Value::TYPE_DICTIONARY:
-      CHECK_GE(children, 1);
-      return CreateRandomDictionary(children - 1);
-    case base::Value::TYPE_LIST:
-      CHECK_GE(children, 1);
-      return CreateRandomList(children - 1);
-    default:
-      return std::unique_ptr<base::Value>{
-          new base::FundamentalValue{base::RandInt(0, 1) != 0}};
-  }
-}
-
-std::unique_ptr<base::Value> CreateRandomValue(int children) {
-  return CreateRandomValue(children, CreateRandomValueType(children > 0));
-}
-
-}  // namespace
-
-TEST(DBusConversionTest, DictionaryToDBusVariantDictionary) {
-  EXPECT_EQ((VariantDictionary{{"bool", true}}),
-            ToVariant(*CreateDictionaryValue("{'bool': true}")));
-  EXPECT_EQ((VariantDictionary{{"int", 5}}),
-            ToVariant(*CreateDictionaryValue("{'int': 5}")));
-  EXPECT_EQ((VariantDictionary{{"double", 6.7}}),
-            ToVariant(*CreateDictionaryValue("{'double': 6.7}")));
-  EXPECT_EQ((VariantDictionary{{"string", std::string{"abc"}}}),
-            ToVariant(*CreateDictionaryValue("{'string': 'abc'}")));
-  EXPECT_EQ((VariantDictionary{{"object", VariantDictionary{{"bool", true}}}}),
-            ToVariant(*CreateDictionaryValue("{'object': {'bool': true}}")));
-  EXPECT_EQ((VariantDictionary{{"emptyList", std::vector<Any>{}}}),
-            ToVariant(*CreateDictionaryValue("{'emptyList': []}")));
-  EXPECT_EQ((VariantDictionary{{"intList", std::vector<int>{5}}}),
-            ToVariant(*CreateDictionaryValue("{'intList': [5]}")));
-  EXPECT_EQ((VariantDictionary{
-                {"intListList", std::vector<Any>{std::vector<int>{5},
-                                                 std::vector<int>{6, 7}}}}),
-            ToVariant(*CreateDictionaryValue(
-                "{'intListList': [[5], [6, 7]]}")));
-  EXPECT_EQ((VariantDictionary{{"objList",
-                                std::vector<VariantDictionary>{
-                                    {{"string", std::string{"abc"}}}}}}),
-            ToVariant(*CreateDictionaryValue(
-                "{'objList': [{'string': 'abc'}]}")));
-}
-
-TEST(DBusConversionTest, VariantDictionaryToDictionaryValue) {
-  EXPECT_JSON_EQ("{'bool': true}", *FromVariant({{"bool", true}}));
-  EXPECT_JSON_EQ("{'int': 5}", *FromVariant({{"int", 5}}));
-  EXPECT_JSON_EQ("{'double': 6.7}", *FromVariant({{"double", 6.7}}));
-  EXPECT_JSON_EQ("{'cString': 'abc'}", *FromVariant({{"cString", "abc"}}));
-  EXPECT_JSON_EQ("{'string': 'abc'}",
-                 *FromVariant({{"string", std::string{"abc"}}}));
-  EXPECT_JSON_EQ("{'object': {'bool': true}}",
-                 *FromVariant({{"object", VariantDictionary{{"bool", true}}}}));
-  EXPECT_JSON_EQ("{'emptyList': []}",
-                 *FromVariant({{"emptyList", std::vector<bool>{}}}));
-  EXPECT_JSON_EQ("{'intList': [5]}",
-                 *FromVariant({{"intList", std::vector<int>{5}}}));
-  EXPECT_JSON_EQ(
-      "{'intListList': [[5], [6, 7]]}",
-      *FromVariant({{"intListList",
-                   std::vector<Any>{std::vector<int>{5},
-                                    std::vector<int>{6, 7}}}}));
-  EXPECT_JSON_EQ(
-      "{'objList': [{'string': 'abc'}]}",
-      *FromVariant({{"objList", std::vector<VariantDictionary>{
-                                    {{"string", std::string{"abc"}}}}}}));
-  EXPECT_JSON_EQ("{'int': 5}", *FromVariant({{"int", Any{Any{5}}}}));
-}
-
-TEST(DBusConversionTest, VariantDictionaryToDictionaryValueErrors) {
-  EXPECT_FALSE(FromVariant({{"float", 1.0f}}));
-  EXPECT_FALSE(FromVariant({{"listList", std::vector<std::vector<int>>{}}}));
-  EXPECT_FALSE(FromVariant({{"any", Any{}}}));
-  EXPECT_FALSE(FromVariant({{"null", nullptr}}));
-}
-
-TEST(DBusConversionTest, DBusRandomDictionaryConversion) {
-  auto dict = CreateRandomDictionary(10000);
-  auto varian_dict = ToVariant(*dict);
-  auto dict_restored = FromVariant(varian_dict);
-  EXPECT_PRED2(IsEqualValue, *dict, *dict_restored);
-}
-
-}  // namespace buffet
diff --git a/libweaved/command.cc b/libweaved/command.cc
index fa10955..fe49155 100644
--- a/libweaved/command.cc
+++ b/libweaved/command.cc
@@ -16,7 +16,6 @@
 
 #include "android/weave/IWeaveCommand.h"
 #include "common/binder_utils.h"
-#include "common/data_conversion.h"
 
 using weaved::binder_utils::ParseDictionary;
 using weaved::binder_utils::ToString;
@@ -120,29 +119,25 @@
   return Command::Origin::kLocal;
 }
 
-brillo::VariantDictionary Command::GetParameters() const {
-  brillo::VariantDictionary params;
-  android::String16 params_string16;
-  if (binder_proxy_->getParameters(&params_string16).isOk()) {
-    std::unique_ptr<base::DictionaryValue> dict;
-    if (ParseDictionary(params_string16, &dict).isOk())
-      params = details::DictionaryValueToVariantDictionary(*dict);
+const base::DictionaryValue& Command::GetParameters() const {
+  if (!parameter_cache_) {
+    android::String16 params_string16;
+    if (!binder_proxy_->getParameters(&params_string16).isOk() ||
+        !ParseDictionary(params_string16, &parameter_cache_).isOk()) {
+      parameter_cache_.reset(new base::DictionaryValue);
+    }
   }
-  return params;
+  return *parameter_cache_;
 }
 
-bool Command::SetProgress(const brillo::VariantDictionary& progress,
+bool Command::SetProgress(const base::DictionaryValue& progress,
                           brillo::ErrorPtr* error) {
-  auto dict = details::VariantDictionaryToDictionaryValue(progress, error);
-  return dict && StatusToError(binder_proxy_->setProgress(ToString16(*dict)),
-                               error);
+  return StatusToError(binder_proxy_->setProgress(ToString16(progress)), error);
 }
 
-bool Command::Complete(const brillo::VariantDictionary& results,
+bool Command::Complete(const base::DictionaryValue& results,
                        brillo::ErrorPtr* error) {
-  auto dict = details::VariantDictionaryToDictionaryValue(results, error);
-  return dict && StatusToError(binder_proxy_->complete(ToString16(*dict)),
-                               error);
+  return StatusToError(binder_proxy_->complete(ToString16(results)), error);
 }
 
 bool Command::Abort(const std::string& error_code,
diff --git a/libweaved/command.h b/libweaved/command.h
index 4f7bf7c..518438c 100644
--- a/libweaved/command.h
+++ b/libweaved/command.h
@@ -20,7 +20,7 @@
 #include <base/macros.h>
 #include <binder/Status.h>
 #include <brillo/errors/error.h>
-#include <brillo/variant_dictionary.h>
+#include <brillo/value_conversion.h>
 #include <libweaved/export.h>
 #include <utils/StrongPointer.h>
 
@@ -34,30 +34,6 @@
 
 class ServiceImpl;
 
-namespace detail {
-
-// Helper function for Command::GetParameter<T>. Allows specialization.
-template <typename T>
-inline bool GetValue(const brillo::Any& any, T* value) {
-  return any.GetValue<T>(value);
-}
-
-// Specialization for double, allow to extract a double from an int.
-template <>
-inline bool GetValue<double>(const brillo::Any& any, double* value) {
-  if (any.GetValue<double>(value))
-    return true;
-
-  int int_val = 0;
-  if (!any.GetValue<int>(&int_val))
-    return false;
-
-  *value = static_cast<double>(int_val);
-  return true;
-}
-
-}  // namespace detail
-
 class LIBWEAVED_EXPORT Command final {
  public:
   enum class State {
@@ -91,7 +67,7 @@
   Command::Origin GetOrigin() const;
 
   // Returns the command parameters.
-  brillo::VariantDictionary GetParameters() const;
+  const base::DictionaryValue& GetParameters() const;
 
   // Helper function to get a command parameter of particular type T from the
   // command parameter list. Returns default value for type T (e.g. 0 for int or
@@ -99,23 +75,23 @@
   // is of incorrect type.
   template <typename T>
   T GetParameter(const std::string& name) const {
-    const brillo::VariantDictionary& parameters = GetParameters();
-    T value{};
-    auto p = parameters.find(name);
-    if (p != parameters.end())
-      detail::GetValue<T>(p->second, &value);
-    return value;
+    const base::DictionaryValue& parameters = GetParameters();
+    T param_value{};
+    const base::Value* value = nullptr;
+    if (parameters.Get(name, &value))
+      brillo::FromValue(*value, &param_value);
+    return param_value;
   }
 
   // Updates the command progress. The |progress| should match the schema.
   // Returns false if |progress| value is incorrect.
-  bool SetProgress(const brillo::VariantDictionary& progress,
+  bool SetProgress(const base::DictionaryValue& progress,
                    brillo::ErrorPtr* error);
 
   // Sets command into terminal "done" state.
   // Updates the command results. The |results| should match the schema.
   // Returns false if |results| value is incorrect.
-  bool Complete(const brillo::VariantDictionary& results,
+  bool Complete(const base::DictionaryValue& results,
                 brillo::ErrorPtr* error);
 
   // Aborts command execution.
@@ -166,6 +142,7 @@
  private:
   friend class ServiceImpl;
   android::sp<android::weave::IWeaveCommand> binder_proxy_;
+  mutable std::unique_ptr<base::DictionaryValue> parameter_cache_;
 
   DISALLOW_COPY_AND_ASSIGN(Command);
 };
diff --git a/libweaved/service.cc b/libweaved/service.cc
index c48fb41..2f9db9c 100644
--- a/libweaved/service.cc
+++ b/libweaved/service.cc
@@ -29,7 +29,6 @@
 #include "android/weave/IWeaveServiceManager.h"
 #include "common/binder_constants.h"
 #include "common/binder_utils.h"
-#include "common/data_conversion.h"
 
 using weaved::binder_utils::StatusToError;
 using weaved::binder_utils::ToString;
@@ -185,12 +184,12 @@
                          const std::string& command_name,
                          const CommandHandlerCallback& callback) override;
   bool SetStateProperties(const std::string& component,
-                          const brillo::VariantDictionary& dict,
+                          const base::DictionaryValue& dict,
                           brillo::ErrorPtr* error) override;
   bool SetStateProperty(const std::string& component,
                         const std::string& trait_name,
                         const std::string& property_name,
-                        const brillo::Any& value,
+                        const base::Value& value,
                         brillo::ErrorPtr* error) override;
   void SetPairingInfoListener(const PairingInfoCallback& callback) override;
 
@@ -337,27 +336,25 @@
 }
 
 bool ServiceImpl::SetStateProperties(const std::string& component,
-                                     const brillo::VariantDictionary& dict,
+                                     const base::DictionaryValue& dict,
                                      brillo::ErrorPtr* error) {
   CHECK(!component.empty());
   CHECK(weave_service_.get());
-  auto properties = details::VariantDictionaryToDictionaryValue(dict, error);
-  if (!properties)
-    return false;
   return StatusToError(weave_service_->updateState(ToString16(component),
-                                                   ToString16(*properties)),
+                                                   ToString16(dict)),
                        error);
 }
 
 bool ServiceImpl::SetStateProperty(const std::string& component,
                                    const std::string& trait_name,
                                    const std::string& property_name,
-                                   const brillo::Any& value,
+                                   const base::Value& value,
                                    brillo::ErrorPtr* error) {
   std::string name =
       base::StringPrintf("%s.%s", trait_name.c_str(), property_name.c_str());
-  return SetStateProperties(component, brillo::VariantDictionary{{name, value}},
-                            error);
+  base::DictionaryValue dict;
+  dict.Set(name, value.DeepCopy());
+  return SetStateProperties(component, dict, error);
 }
 
 void ServiceImpl::SetPairingInfoListener(const PairingInfoCallback& callback) {
diff --git a/libweaved/service.h b/libweaved/service.h
index 02cc509..26edb7a 100644
--- a/libweaved/service.h
+++ b/libweaved/service.h
@@ -74,7 +74,7 @@
   // Sets a number of state properties for a given |component|.
   // |dict| is a dictionary containing property-name/property-value pairs.
   virtual bool SetStateProperties(const std::string& component,
-                                  const brillo::VariantDictionary& dict,
+                                  const base::DictionaryValue& dict,
                                   brillo::ErrorPtr* error) = 0;
 
   // Sets value of the single property.
@@ -84,7 +84,7 @@
   virtual bool SetStateProperty(const std::string& component,
                                 const std::string& trait_name,
                                 const std::string& property_name,
-                                const brillo::Any& value,
+                                const base::Value& value,
                                 brillo::ErrorPtr* error) = 0;
 
   // Specifies a callback to be invoked when the device enters/exist pairing