Commit aea44785 authored by danielng's avatar danielng Committed by Commit Bot

borealis: preventing installations when offline

Test images don't actually download the DLC, so installing while
offline works. Normal images, however, do need to download the
DLC when installing Borealis. Adding an extra check to ensure
that users are online and also attached a new error to this case.

Bug: b/171672034
Change-Id: I351c23f361a9857b4783973820d9f2c4f244a64d
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2539866
Commit-Queue: Daniel Ng <danielng@google.com>
Reviewed-by: default avatarScott Violet <sky@chromium.org>
Reviewed-by: default avatarNic Hollingum <hollingum@google.com>
Cr-Commit-Position: refs/heads/master@{#828105}
parent 9cec76f3
...@@ -5588,6 +5588,9 @@ ...@@ -5588,6 +5588,9 @@
<message name="IDS_BOREALIS_INSTALLER_NOT_ALLOWED_MESSAGE" desc="" translateable="false"> <message name="IDS_BOREALIS_INSTALLER_NOT_ALLOWED_MESSAGE" desc="" translateable="false">
<ph name="APP_NAME">$1<ex>BOREALIS</ex></ph> isn't allowed on this device. Contact your administrator. Error code: <ph name="ERROR_CODE">$2<ex>7</ex></ph>. <ph name="APP_NAME">$1<ex>BOREALIS</ex></ph> isn't allowed on this device. Contact your administrator. Error code: <ph name="ERROR_CODE">$2<ex>7</ex></ph>.
</message> </message>
<message name="IDS_BOREALIS_INSTALLER_OFFLINE_MESSAGE" desc="" translateable="false">
Your device is offline, please connect to the internet and try again.
</message>
<message name="IDS_BOREALIS_DLC_INTERNAL_FAILED_MESSAGE" desc="" translateable="false"> <message name="IDS_BOREALIS_DLC_INTERNAL_FAILED_MESSAGE" desc="" translateable="false">
Your device needs to be updated before you can use <ph name="APP_NAME">$1<ex>BOREALIS</ex></ph>. Your device needs to be updated before you can use <ph name="APP_NAME">$1<ex>BOREALIS</ex></ph>.
</message> </message>
......
...@@ -12,6 +12,7 @@ ...@@ -12,6 +12,7 @@
#include "chrome/browser/profiles/profile.h" #include "chrome/browser/profiles/profile.h"
#include "components/prefs/pref_service.h" #include "components/prefs/pref_service.h"
#include "content/public/browser/browser_thread.h" #include "content/public/browser/browser_thread.h"
#include "content/public/browser/network_service_instance.h"
namespace borealis { namespace borealis {
...@@ -41,6 +42,12 @@ void BorealisInstallerImpl::Start() { ...@@ -41,6 +42,12 @@ void BorealisInstallerImpl::Start() {
InstallationEnded(BorealisInstallResult::kBorealisInstallInProgress); InstallationEnded(BorealisInstallResult::kBorealisInstallInProgress);
return; return;
} }
if (content::GetNetworkConnectionTracker()->IsOffline()) {
InstallationEnded(BorealisInstallResult::kOffline);
return;
}
installation_start_tick_ = base::TimeTicks::Now(); installation_start_tick_ = base::TimeTicks::Now();
progress_ = 0; progress_ = 0;
......
...@@ -19,7 +19,9 @@ ...@@ -19,7 +19,9 @@
#include "chromeos/dbus/dbus_thread_manager.h" #include "chromeos/dbus/dbus_thread_manager.h"
#include "chromeos/dbus/dlcservice/fake_dlcservice_client.h" #include "chromeos/dbus/dlcservice/fake_dlcservice_client.h"
#include "components/prefs/pref_service.h" #include "components/prefs/pref_service.h"
#include "content/public/browser/network_service_instance.h"
#include "content/public/test/browser_task_environment.h" #include "content/public/test/browser_task_environment.h"
#include "services/network/test/test_network_connection_tracker.h"
#include "testing/gmock/include/gmock/gmock.h" #include "testing/gmock/include/gmock/gmock.h"
namespace borealis { namespace borealis {
...@@ -147,6 +149,23 @@ TEST_F(BorealisInstallerTest, BorealisNotAllowed) { ...@@ -147,6 +149,23 @@ TEST_F(BorealisInstallerTest, BorealisNotAllowed) {
BorealisService::GetForProfile(profile_.get())->Features().IsEnabled()); BorealisService::GetForProfile(profile_.get())->Features().IsEnabled());
} }
TEST_F(BorealisInstallerTest, DeviceOfflineInstallationFails) {
feature_list_.InitAndEnableFeature(features::kBorealis);
std::unique_ptr<network::TestNetworkConnectionTracker>
network_connection_tracker =
network::TestNetworkConnectionTracker::CreateInstance();
network::TestNetworkConnectionTracker::GetInstance()->SetConnectionType(
network::mojom::ConnectionType::CONNECTION_NONE);
EXPECT_CALL(*observer_, OnInstallationEnded(BorealisInstallResult::kOffline));
StartAndRunToCompletion();
UpdateCurrentDlcs();
ASSERT_EQ(current_dlcs_.dlc_infos_size(), 0);
EXPECT_FALSE(
BorealisService::GetForProfile(profile_.get())->Features().IsEnabled());
}
TEST_F(BorealisInstallerTest, SucessfulInstallation) { TEST_F(BorealisInstallerTest, SucessfulInstallation) {
feature_list_.InitAndEnableFeature(features::kBorealis); feature_list_.InitAndEnableFeature(features::kBorealis);
fake_dlcservice_client_->set_install_error(dlcservice::kErrorNone); fake_dlcservice_client_->set_install_error(dlcservice::kErrorNone);
......
...@@ -29,7 +29,8 @@ enum class BorealisInstallResult { ...@@ -29,7 +29,8 @@ enum class BorealisInstallResult {
kDlcNeedRebootError = 7, kDlcNeedRebootError = 7,
kDlcNeedSpaceError = 8, kDlcNeedSpaceError = 8,
kDlcUnknownError = 9, kDlcUnknownError = 9,
kMaxValue = kDlcUnknownError, kOffline = 10,
kMaxValue = kOffline,
}; };
// These values are persisted to logs. Entries should not be renumbered and // These values are persisted to logs. Entries should not be renumbered and
......
...@@ -296,6 +296,9 @@ base::string16 BorealisInstallerView::GetSecondaryMessage() const { ...@@ -296,6 +296,9 @@ base::string16 BorealisInstallerView::GetSecondaryMessage() const {
IDS_BOREALIS_INSTALLER_NOT_ALLOWED_MESSAGE, app_name_, IDS_BOREALIS_INSTALLER_NOT_ALLOWED_MESSAGE, app_name_,
base::NumberToString16( base::NumberToString16(
static_cast<std::underlying_type_t<ResultEnum>>(*result_))); static_cast<std::underlying_type_t<ResultEnum>>(*result_)));
case ResultEnum::kOffline:
return l10n_util::GetStringUTF16(
IDS_BOREALIS_INSTALLER_OFFLINE_MESSAGE);
// DLC Failures. // DLC Failures.
case ResultEnum::kDlcInternalError: case ResultEnum::kDlcInternalError:
return l10n_util::GetStringFUTF16( return l10n_util::GetStringFUTF16(
......
...@@ -8739,6 +8739,7 @@ Called by update_bad_message_reasons.py.--> ...@@ -8739,6 +8739,7 @@ Called by update_bad_message_reasons.py.-->
Borealis DLC"/> Borealis DLC"/>
<int value="8" label="Device needs more space to use Borealis DLC"/> <int value="8" label="Device needs more space to use Borealis DLC"/>
<int value="9" label="DLC faced an unknown error"/> <int value="9" label="DLC faced an unknown error"/>
<int value="10" label="Device is offline"/>
</enum> </enum>
<enum name="BorealisStartupResult"> <enum name="BorealisStartupResult">
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment