Enhanced channel changing behavior
This CL adds a new DBUS API to UpdateEngine called SetTargetChannel to
change the current channel of the device with an option to indicate
whether to do eventually or immediately.
The API will be called with the option to do it immediately in a
subsequent CL in Chrome UI. For now the old API (set_track) has been
wired up to call the new API to produce the old behavior (i.e. change
eventually). The old API will be removed after Chrome UI code stops
using it.
It's the UI's responsibility to ask the user for confirmation for the
powerwash that may happen in some cases and call the API with the
appropriate value whether or not the powerwash should happen.
For now, we're restricting the changing of channels to only those
devices that are on canary-channel or running test builds. This
restriction will be lifted off once the UI work is ready to give
warning to the users about the powerwash that may happen when they move
to a more stable channel.
We also enforce ReleaseChannelDelegated and ReleaseChannel policies
correctly now as follows:
* If ReleaseChannelDelegated is false, SetTargetChannel will fail as we
need to honor (only) the ReleaseChannel value in this case.
* If ReleaseChannelDelegated is true, we'll allow the SetTargetChannel
call to specify. In this case, we'll ignore the value of ReleaseChannel,
if any.
BUG=chromium-os:39095
TEST=Tested on ZGB by going from canary to dev-channel with and without
powerwash.
TEST=Existing unit tests have been updated and they pass.
TEST=New unit tests have been added.
Change-Id: Ifbf806a06e1c30d2f318e94d73735d1812049abd
Reviewed-on: https://gerrit.chromium.org/gerrit/44619
Commit-Queue: Jay Srinivasan <jaysri@chromium.org>
Reviewed-by: Jay Srinivasan <jaysri@chromium.org>
Tested-by: Jay Srinivasan <jaysri@chromium.org>
diff --git a/dbus_service.cc b/dbus_service.cc
index 7d3d39d..b4cc7c8 100644
--- a/dbus_service.cc
+++ b/dbus_service.cc
@@ -94,16 +94,16 @@
LOG(INFO) << "Attempt update: app_version=\"" << update_app_version << "\" "
<< "omaha_url=\"" << update_omaha_url << "\" "
<< "interactive=" << (interactive? "yes" : "no");
- self->update_attempter_->CheckForUpdate(update_app_version,
- update_omaha_url,
- interactive);
+ self->system_state_->update_attempter()->CheckForUpdate(update_app_version,
+ update_omaha_url,
+ interactive);
return TRUE;
}
gboolean update_engine_service_reset_status(UpdateEngineService* self,
GError **error) {
*error = NULL;
- return self->update_attempter_->ResetStatus();
+ return self->system_state_->update_attempter()->ResetStatus();
}
@@ -117,11 +117,11 @@
string current_op;
string new_version_str;
- CHECK(self->update_attempter_->GetStatus(last_checked_time,
- progress,
- ¤t_op,
- &new_version_str,
- new_size));
+ CHECK(self->system_state_->update_attempter()->GetStatus(last_checked_time,
+ progress,
+ ¤t_op,
+ &new_version_str,
+ new_size));
*current_operation = g_strdup(current_op.c_str());
*new_version = g_strdup(new_version_str.c_str());
@@ -132,18 +132,9 @@
return TRUE;
}
-gboolean update_engine_service_get_track(UpdateEngineService* self,
- gchar** track,
- GError **error) {
- string track_str =
- chromeos_update_engine::OmahaRequestDeviceParams::GetDeviceTrack();
- *track = g_strdup(track_str.c_str());
- return TRUE;
-}
-
gboolean update_engine_service_reboot_if_needed(UpdateEngineService* self,
GError **error) {
- if (!self->update_attempter_->RebootIfNeeded()) {
+ if (!self->system_state_->update_attempter()->RebootIfNeeded()) {
*error = NULL;
return FALSE;
}
@@ -153,14 +144,62 @@
gboolean update_engine_service_set_track(UpdateEngineService* self,
gchar* track,
GError **error) {
- if (track) {
- LOG(INFO) << "Setting track to: " << track;
- if (!chromeos_update_engine::OmahaRequestDeviceParams::SetDeviceTrack(
- track)) {
- *error = NULL;
- return FALSE;
- }
+ // track == target channel.
+ return update_engine_service_set_channel(self, track, false, error);
+}
+
+gboolean update_engine_service_get_track(UpdateEngineService* self,
+ gchar** track,
+ GError **error) {
+ // track == target channel.
+ return update_engine_service_get_channel(self, false, track, error);
+}
+
+gboolean update_engine_service_set_channel(UpdateEngineService* self,
+ gchar* target_channel,
+ bool is_powerwash_allowed,
+ GError **error) {
+ if (!target_channel)
+ return FALSE;
+
+ if (!self->system_state_->device_policy()) {
+ LOG(INFO) << "Cannot set target channel until device policy/settings are "
+ "known";
+ return FALSE;
}
+
+ bool delegated = false;
+ self->system_state_->device_policy()->GetReleaseChannelDelegated(&delegated);
+ if (!delegated) {
+ // Note: This message will appear in UE logs with the current UI code
+ // because UI hasn't been modified to call this method only if
+ // delegated is set to true. chromium-os:219292 tracks this work item.
+ LOG(INFO) << "Cannot set target channel explicitly when channel "
+ "policy/settings is not delegated";
+ return FALSE;
+ }
+
+ LOG(INFO) << "Setting destination channel to: " << target_channel;
+ if (!self->system_state_->request_params()->SetTargetChannel(
+ target_channel, is_powerwash_allowed)) {
+ *error = NULL;
+ return FALSE;
+ }
+
+ return TRUE;
+}
+
+gboolean update_engine_service_get_channel(UpdateEngineService* self,
+ bool get_current_channel,
+ gchar** channel,
+ GError **error) {
+ chromeos_update_engine::OmahaRequestParams* rp =
+ self->system_state_->request_params();
+
+ string channel_str = get_current_channel ?
+ rp->current_channel() : rp->target_channel();
+
+ *channel = g_strdup(channel_str.c_str());
return TRUE;
}