Set default updater URL and version per platform.

Chrome OS and Brillo devices require different production update URL
and updater string ID sent to Omaha. This patch moves these constants
to a platform-dependent file with the definition of the constants.

Bug: brillo:587,brillo:588
Test: FEATURES=test emerge-link update_engine; `mma`; deployed on a dragonboard.

Change-Id: Ibe3b30c32c2fb2caf3ed10a4198272dc13a44d12
diff --git a/Android.mk b/Android.mk
index 70cbdce..35b7cc0 100644
--- a/Android.mk
+++ b/Android.mk
@@ -155,6 +155,7 @@
     payload_constants.cc \
     payload_state.cc \
     payload_verifier.cc \
+    platform_constants_android.cc \
     postinstall_runner_action.cc \
     prefs.cc \
     proxy_resolver.cc \
diff --git a/omaha_request_action.cc b/omaha_request_action.cc
index 2be66af..05d950f 100644
--- a/omaha_request_action.cc
+++ b/omaha_request_action.cc
@@ -40,6 +40,7 @@
 #include "update_engine/omaha_request_params.h"
 #include "update_engine/p2p_manager.h"
 #include "update_engine/payload_state_interface.h"
+#include "update_engine/platform_constants.h"
 #include "update_engine/prefs_interface.h"
 #include "update_engine/utils.h"
 
@@ -71,9 +72,9 @@
 static const char* kTagDisableP2PForSharing = "DisableP2PForSharing";
 static const char* kTagPublicKeyRsa = "PublicKeyRsa";
 
-namespace {
+static const char* kOmahaUpdaterVersion = "0.1.0.0";
 
-static const char* const kGupdateVersion = "ChromeOSUpdateEngine-0.1.0.0";
+namespace {
 
 // Returns an XML ping element attribute assignment with attribute
 // |name| and value |ping_days| if |ping_days| has a value that needs
@@ -289,12 +290,15 @@
   string install_source = base::StringPrintf("installsource=\"%s\" ",
       (params->interactive() ? "ondemandupdate" : "scheduler"));
 
+  string updater_version = XmlEncodeWithDefault(
+      base::StringPrintf("%s-%s",
+                         constants::kOmahaUpdaterID,
+                         kOmahaUpdaterVersion), "");
   string request_xml =
       "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"
       "<request protocol=\"3.0\" " + (
-          "version=\"" + XmlEncodeWithDefault(kGupdateVersion, "") + "\" "
-          "updaterversion=\"" + XmlEncodeWithDefault(kGupdateVersion,
-                                                     "") + "\" " +
+          "version=\"" + updater_version + "\" "
+          "updaterversion=\"" + updater_version + "\" " +
           install_source +
           "ismachine=\"1\">\n") +
       os_xml +
diff --git a/omaha_request_action_unittest.cc b/omaha_request_action_unittest.cc
index f22c137..55eb02f 100644
--- a/omaha_request_action_unittest.cc
+++ b/omaha_request_action_unittest.cc
@@ -40,6 +40,7 @@
 #include "update_engine/mock_payload_state.h"
 #include "update_engine/omaha_hash_calculator.h"
 #include "update_engine/omaha_request_params.h"
+#include "update_engine/platform_constants.h"
 #include "update_engine/prefs.h"
 #include "update_engine/test_utils.h"
 #include "update_engine/utils.h"
@@ -211,7 +212,7 @@
   // fake_system_state_.
   OmahaRequestParams request_params_ = OmahaRequestParams{
       &fake_system_state_,
-      OmahaRequestParams::kOsPlatform,
+      constants::kOmahaPlatformName,
       OmahaRequestParams::kOsVersion,
       "service_pack",
       "x86-generic",
@@ -1043,7 +1044,7 @@
 
   // Make sure XML Encode is being called on the params
   OmahaRequestParams params(&fake_system_state_,
-                            OmahaRequestParams::kOsPlatform,
+                            constants::kOmahaPlatformName,
                             OmahaRequestParams::kOsVersion,
                             "testtheservice_pack>",
                             "x86 generic<id",
@@ -1236,7 +1237,7 @@
     const char* delta_okay_str = delta_okay ? "true" : "false";
     chromeos::Blob post_data;
     OmahaRequestParams params(&fake_system_state_,
-                              OmahaRequestParams::kOsPlatform,
+                              constants::kOmahaPlatformName,
                               OmahaRequestParams::kOsVersion,
                               "service_pack",
                               "x86-generic",
@@ -1277,7 +1278,7 @@
     chromeos::Blob post_data;
     FakeSystemState fake_system_state;
     OmahaRequestParams params(&fake_system_state_,
-                              OmahaRequestParams::kOsPlatform,
+                              constants::kOmahaPlatformName,
                               OmahaRequestParams::kOsVersion,
                               "service_pack",
                               "x86-generic",
diff --git a/omaha_request_params.cc b/omaha_request_params.cc
index 6e8d636..4118a11 100644
--- a/omaha_request_params.cc
+++ b/omaha_request_params.cc
@@ -31,6 +31,7 @@
 
 #include "update_engine/constants.h"
 #include "update_engine/hardware_interface.h"
+#include "update_engine/platform_constants.h"
 #include "update_engine/system_state.h"
 #include "update_engine/utils.h"
 
@@ -42,14 +43,8 @@
 
 namespace chromeos_update_engine {
 
-const char kProductionOmahaUrl[] =
-    "https://tools.google.com/service/update2";
-const char kAUTestOmahaUrl[] =
-    "https://omaha.sandbox.google.com/service/update2";
-
 const char OmahaRequestParams::kAppId[] =
     "{87efface-864d-49a5-9bb3-4b050a7c227a}";
-const char OmahaRequestParams::kOsPlatform[] = "Chrome OS";
 const char OmahaRequestParams::kOsVersion[] = "Indy";
 const char OmahaRequestParams::kUpdateChannelKey[] = "CHROMEOS_RELEASE_TRACK";
 const char OmahaRequestParams::kIsPowerwashAllowedKey[] =
@@ -70,7 +65,7 @@
   LOG(INFO) << "Initializing parameters for this update attempt";
   InitFromLsbValue();
   bool stateful_override = !ShouldLockDown();
-  os_platform_ = OmahaRequestParams::kOsPlatform;
+  os_platform_ = constants::kOmahaPlatformName;
   os_version_ = OmahaRequestParams::kOsVersion;
   app_version_ = in_app_version.empty() ?
       GetLsbValue("CHROMEOS_RELEASE_VERSION", "", nullptr, stateful_override) :
@@ -117,7 +112,8 @@
   }
 
   if (in_update_url.empty())
-    update_url_ = GetLsbValue(kAutoUpdateServerKey, kProductionOmahaUrl,
+    update_url_ = GetLsbValue(kAutoUpdateServerKey,
+                              constants::kOmahaDefaultProductionURL,
                               nullptr, stateful_override);
   else
     update_url_ = in_update_url;
@@ -128,8 +124,9 @@
 }
 
 bool OmahaRequestParams::IsUpdateUrlOfficial() const {
-  return (update_url_ == kAUTestOmahaUrl ||
-          update_url_ == GetLsbValue(kAutoUpdateServerKey, kProductionOmahaUrl,
+  return (update_url_ == constants::kOmahaDefaultAUTestURL ||
+          update_url_ == GetLsbValue(kAutoUpdateServerKey,
+                                     constants::kOmahaDefaultProductionURL,
                                      nullptr, !ShouldLockDown()));
 }
 
diff --git a/omaha_request_params.h b/omaha_request_params.h
index 7109518..099c07c 100644
--- a/omaha_request_params.h
+++ b/omaha_request_params.h
@@ -25,17 +25,13 @@
 #include <base/time/time.h>
 #include <gtest/gtest_prod.h>  // for FRIEND_TEST
 
+#include "update_engine/platform_constants.h"
+
 // This gathers local system information and prepares info used by the
 // Omaha request action.
 
 namespace chromeos_update_engine {
 
-// The default "official" Omaha update URL.
-extern const char kProductionOmahaUrl[];
-
-// The autoupdate test Omaha update URL.
-extern const char kAUTestOmahaUrl[];
-
 class SystemState;
 
 // This class encapsulates the data Omaha gets for the request, along with
@@ -48,7 +44,7 @@
  public:
   explicit OmahaRequestParams(SystemState* system_state)
       : system_state_(system_state),
-        os_platform_(kOsPlatform),
+        os_platform_(constants::kOmahaPlatformName),
         os_version_(kOsVersion),
         board_app_id_(kAppId),
         canary_app_id_(kAppId),
@@ -192,9 +188,7 @@
 
   // Suggested defaults
   static const char kAppId[];
-  static const char kOsPlatform[];
   static const char kOsVersion[];
-  static const char kUpdateUrl[];
   static const char kUpdateChannelKey[];
   static const char kIsPowerwashAllowedKey[];
   static const char kAutoUpdateServerKey[];
diff --git a/omaha_request_params_unittest.cc b/omaha_request_params_unittest.cc
index 90d8519..a4aeeec 100644
--- a/omaha_request_params_unittest.cc
+++ b/omaha_request_params_unittest.cc
@@ -26,6 +26,7 @@
 #include "update_engine/constants.h"
 #include "update_engine/fake_system_state.h"
 #include "update_engine/install_plan.h"
+#include "update_engine/platform_constants.h"
 #include "update_engine/test_utils.h"
 #include "update_engine/utils.h"
 
@@ -247,7 +248,7 @@
   EXPECT_EQ("en-US", out.app_lang());
   EXPECT_TRUE(out.delta_okay());
   EXPECT_EQ("dev-channel", out.target_channel());
-  EXPECT_EQ(kProductionOmahaUrl, out.update_url());
+  EXPECT_EQ(constants::kOmahaDefaultProductionURL, out.update_url());
 }
 
 TEST_F(OmahaRequestParamsTest, NoDeltasTest) {
diff --git a/omaha_response_handler_action_unittest.cc b/omaha_response_handler_action_unittest.cc
index 20d0166..5e14511 100644
--- a/omaha_response_handler_action_unittest.cc
+++ b/omaha_response_handler_action_unittest.cc
@@ -23,6 +23,7 @@
 #include "update_engine/constants.h"
 #include "update_engine/fake_system_state.h"
 #include "update_engine/mock_payload_state.h"
+#include "update_engine/platform_constants.h"
 #include "update_engine/test_utils.h"
 #include "update_engine/utils.h"
 
@@ -408,7 +409,7 @@
   // We're using a real OmahaRequestParams object here so we can't mock
   // IsUpdateUrlOfficial(), but setting the update URL to the AutoUpdate test
   // server will cause IsUpdateUrlOfficial() to return true.
-  params.set_update_url(kAUTestOmahaUrl);
+  params.set_update_url(constants::kOmahaDefaultAUTestURL);
   fake_system_state_.set_request_params(&params);
 
   EXPECT_CALL(*fake_system_state_.mock_payload_state(),
diff --git a/platform_constants.h b/platform_constants.h
new file mode 100644
index 0000000..9f8778e
--- /dev/null
+++ b/platform_constants.h
@@ -0,0 +1,39 @@
+//
+// Copyright (C) 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 UPDATE_ENGINE_PLATFORM_CONSTANTS_H_
+#define UPDATE_ENGINE_PLATFORM_CONSTANTS_H_
+
+namespace chromeos_update_engine {
+namespace constants {
+
+// The default URL used by all products when running in normal mode. The AUTest
+// URL is used when testing normal images against the alternative AUTest server.
+// Note that the URL can be override in run-time in certain cases.
+extern const char kOmahaDefaultProductionURL[];
+extern const char kOmahaDefaultAUTestURL[];
+
+// Our product name used in Omaha. This value must match the one configured in
+// the server side and is sent on every request.
+extern const char kOmahaUpdaterID[];
+
+// The name of the platform as sent to Omaha.
+extern const char kOmahaPlatformName[];
+
+}  // namespace constants
+}  // namespace chromeos_update_engine
+
+#endif  // UPDATE_ENGINE_PLATFORM_CONSTANTS_H_
diff --git a/platform_constants_android.cc b/platform_constants_android.cc
new file mode 100644
index 0000000..55ec974
--- /dev/null
+++ b/platform_constants_android.cc
@@ -0,0 +1,30 @@
+//
+// Copyright (C) 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 "update_engine/platform_constants.h"
+
+namespace chromeos_update_engine {
+namespace constants {
+
+const char kOmahaDefaultProductionURL[] =
+    "https://clients2.google.com/service/update2/brillo";
+const char kOmahaDefaultAUTestURL[] =
+    "https://clients2.google.com/service/update2/brillo";
+const char kOmahaUpdaterID[] = "Brillo";
+const char kOmahaPlatformName[] = "Brillo";
+
+}  // namespace constants
+}  // namespace chromeos_update_engine
diff --git a/platform_constants_chromeos.cc b/platform_constants_chromeos.cc
new file mode 100644
index 0000000..62c1720
--- /dev/null
+++ b/platform_constants_chromeos.cc
@@ -0,0 +1,30 @@
+//
+// Copyright (C) 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 "update_engine/platform_constants.h"
+
+namespace chromeos_update_engine {
+namespace constants {
+
+const char kOmahaDefaultProductionURL[] =
+    "https://tools.google.com/service/update2";
+const char kOmahaDefaultAUTestURL[] =
+    "https://omaha.sandbox.google.com/service/update2";
+const char kOmahaUpdaterID[] = "ChromeOSUpdateEngine";
+const char kOmahaPlatformName[] = "Chrome OS";
+
+}  // namespace constants
+}  // namespace chromeos_update_engine
diff --git a/update_attempter.cc b/update_attempter.cc
index 6152992..f1eff95 100644
--- a/update_attempter.cc
+++ b/update_attempter.cc
@@ -56,6 +56,7 @@
 #include "update_engine/omaha_response_handler_action.h"
 #include "update_engine/p2p_manager.h"
 #include "update_engine/payload_state_interface.h"
+#include "update_engine/platform_constants.h"
 #include "update_engine/postinstall_runner_action.h"
 #include "update_engine/prefs_interface.h"
 #include "update_engine/subprocess.h"
@@ -819,13 +820,13 @@
     forced_omaha_url_ = omaha_url;
   }
   if (omaha_url == kScheduledAUTestURLRequest) {
-    forced_omaha_url_ = chromeos_update_engine::kAUTestOmahaUrl;
+    forced_omaha_url_ = constants::kOmahaDefaultAUTestURL;
     // Pretend that it's not user-initiated even though it is,
     // so as to test scattering logic, etc. which get kicked off
     // only in scheduled update checks.
     interactive = false;
   } else if (omaha_url == kAUTestURLRequest) {
-    forced_omaha_url_ = chromeos_update_engine::kAUTestOmahaUrl;
+    forced_omaha_url_ = constants::kOmahaDefaultAUTestURL;
   }
 
   if (forced_update_pending_callback_.get()) {
@@ -1232,8 +1233,10 @@
   if (!system_state_->hardware()->IsOfficialBuild())
     flags |= static_cast<uint32_t>(ErrorCode::kTestImageFlag);
 
-  if (omaha_request_params_->update_url() != kProductionOmahaUrl)
+  if (omaha_request_params_->update_url() !=
+      constants::kOmahaDefaultProductionURL) {
     flags |= static_cast<uint32_t>(ErrorCode::kTestOmahaUrlFlag);
+  }
 
   return flags;
 }
diff --git a/update_attempter_unittest.cc b/update_attempter_unittest.cc
index 4e48d0b..1726585 100644
--- a/update_attempter_unittest.cc
+++ b/update_attempter_unittest.cc
@@ -47,6 +47,7 @@
 #include "update_engine/mock_p2p_manager.h"
 #include "update_engine/mock_payload_state.h"
 #include "update_engine/mock_prefs.h"
+#include "update_engine/platform_constants.h"
 #include "update_engine/postinstall_runner_action.h"
 #include "update_engine/prefs.h"
 #include "update_engine/test_utils.h"
@@ -1009,16 +1010,14 @@
   fake_system_state_.fake_hardware()->SetIsOfficialBuild(true);
   fake_system_state_.fake_hardware()->SetIsNormalBootMode(true);
   attempter_.CheckForUpdate("", "autest", true);
-  EXPECT_EQ(chromeos_update_engine::kAUTestOmahaUrl,
-            attempter_.forced_omaha_url());
+  EXPECT_EQ(constants::kOmahaDefaultAUTestURL, attempter_.forced_omaha_url());
 }
 
 TEST_F(UpdateAttempterTest, CheckForUpdateScheduledAUTest) {
   fake_system_state_.fake_hardware()->SetIsOfficialBuild(true);
   fake_system_state_.fake_hardware()->SetIsNormalBootMode(true);
   attempter_.CheckForUpdate("", "autest-scheduled", true);
-  EXPECT_EQ(chromeos_update_engine::kAUTestOmahaUrl,
-            attempter_.forced_omaha_url());
+  EXPECT_EQ(constants::kOmahaDefaultAUTestURL, attempter_.forced_omaha_url());
 }
 
 }  // namespace chromeos_update_engine
diff --git a/update_engine.gyp b/update_engine.gyp
index e2a8de0..6138b87 100644
--- a/update_engine.gyp
+++ b/update_engine.gyp
@@ -189,6 +189,7 @@
         'payload_constants.cc',
         'payload_state.cc',
         'payload_verifier.cc',
+        'platform_constants_chromeos.cc',
         'postinstall_runner_action.cc',
         'prefs.cc',
         'proxy_resolver.cc',