weaved: set system property 'weave.state' with the current GCD state

In order for other Brillo system components to know when the device is
fully provisioned/connected to the cloud, add 'weave.state' system
property which has one of the following states:

- unconfigured
- connecting
- connected
- invalid_credentials

Initially (OOB) the device is "unconfigured". When the bootstrap
process finished, the device will be in "connected" state. If the
device is later deleted from the cloud by the user, it will go into
"invalid_credentials" state.

BUG: 24142361
Change-Id: If83e151940a81d5e379e1b0199a9813733c12fdf
diff --git a/Android.mk b/Android.mk
index 345a5d5..9d75d9d 100644
--- a/Android.mk
+++ b/Android.mk
@@ -43,6 +43,7 @@
 	libbrillo-stream \
 	libchrome \
 	libchrome-dbus \
+	libcutils \
 	libdbus \
 	libshill-client \
 	libweave \
@@ -96,6 +97,21 @@
 
 include $(BUILD_STATIC_LIBRARY)
 
+# weaved-brillo-api
+# ========================================================
+include $(CLEAR_VARS)
+LOCAL_MODULE := weaved-brillo-api
+LOCAL_CPP_EXTENSION := $(buffetCommonCppExtension)
+LOCAL_CFLAGS := $(buffetCommonCFlags)
+LOCAL_CPPFLAGS := $(buffetCommonCppFlags)
+LOCAL_CLANG := true
+LOCAL_EXPORT_C_INCLUDE_DIRS := $(LOCAL_PATH)
+
+LOCAL_SRC_FILES := \
+	brillo/weaved_system_properties.cc \
+
+include $(BUILD_STATIC_LIBRARY)
+
 # weaved
 # ========================================================
 include $(CLEAR_VARS)
@@ -112,6 +128,7 @@
 LOCAL_C_INCLUDES := $(buffetCommonCIncludes)
 LOCAL_INIT_RC := weaved.rc
 LOCAL_SHARED_LIBRARIES := $(buffetSharedLibraries)
+LOCAL_STATIC_LIBRARIES := weaved-brillo-api
 LOCAL_WHOLE_STATIC_LIBRARIES := buffet-common
 LOCAL_CLANG := true
 LOCAL_RTTI_FLAG := -frtti
@@ -182,6 +199,7 @@
 	libgtest \
 	libgmock \
 	libweave-test \
+	weaved-brillo-api \
 
 LOCAL_RTTI_FLAG := -frtti
 LOCAL_CLANG := true
diff --git a/brillo/weaved_system_properties.cc b/brillo/weaved_system_properties.cc
new file mode 100644
index 0000000..628c2d9
--- /dev/null
+++ b/brillo/weaved_system_properties.cc
@@ -0,0 +1,23 @@
+// 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 "brillo/weaved_system_properties.h"
+
+namespace weaved {
+namespace system_properties {
+
+const char kState[] = "weave.state";
+
+}  // namespace system_properties
+}  // namespace weaved
diff --git a/brillo/weaved_system_properties.h b/brillo/weaved_system_properties.h
new file mode 100644
index 0000000..248eb01
--- /dev/null
+++ b/brillo/weaved_system_properties.h
@@ -0,0 +1,26 @@
+// 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 BRILLO_WEAVED_SYSTEM_PROPERTIES_H_
+#define BRILLO_WEAVED_SYSTEM_PROPERTIES_H_
+
+namespace weaved {
+namespace system_properties {
+
+extern const char kState[];
+
+}  // namespace system_properties
+}  // namespace weaved
+
+#endif  // BRILLO_WEAVED_SYSTEM_PROPERTIES_H_
diff --git a/buffet/manager.cc b/buffet/manager.cc
index 3d5e450..00e6dc8 100644
--- a/buffet/manager.cc
+++ b/buffet/manager.cc
@@ -26,6 +26,7 @@
 #include <base/json/json_writer.h>
 #include <base/message_loop/message_loop.h>
 #include <base/time/time.h>
+#include <cutils/properties.h>
 #include <brillo/bind_lambda.h>
 #include <brillo/dbus/async_event_sequencer.h>
 #include <brillo/dbus/exported_object_manager.h>
@@ -40,6 +41,7 @@
 #include <dbus/values_util.h>
 #include <weave/enum_to_string.h>
 
+#include "brillo/weaved_system_properties.h"
 #include "buffet/bluetooth_client.h"
 #include "buffet/buffet_config.h"
 #include "buffet/dbus_command_dispatcher.h"
@@ -329,7 +331,9 @@
 }
 
 void Manager::OnGcdStateChanged(weave::GcdState state) {
-  dbus_adaptor_.SetStatus(weave::EnumToString(state));
+  std::string state_string = weave::EnumToString(state);
+  dbus_adaptor_.SetStatus(state_string);
+  property_set(weaved::system_properties::kState, state_string.c_str());
 }
 
 void Manager::OnConfigChanged(const weave::Settings& settings) {