Commit 7ec3f148 authored by Jia's avatar Jia Committed by Commit Bot

[On-device adaptive brightness] Remove the need of VerifyAlsConfig from AlsReaderImpl

AlsReaderImpl previously checked number of ALS config steps to determine if a
device should be supported. We now use ModelConfigLoader to load model config
that will tell us if a device is supported, hence this cl removes config
verification from AlsReaderImpl.

Bug: 881215
Change-Id: I273a1b1b518970ae49632622acb25a8cfd69c5f2
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1505747
Commit-Queue: Jia Meng <jiameng@chromium.org>
Reviewed-by: default avatarMichael Martis <martis@chromium.org>
Cr-Commit-Position: refs/heads/master@{#638524}
parent 6318b470
......@@ -41,32 +41,6 @@ bool IsAlsEnabled() {
return exit_code == 0;
}
// Returns whether the ALS step config is what we need. This function is only
// called if an ALS is enabled. This should run in another thread to be
// non-blocking to the main thread.
// TODO(jiameng): we assume one specific device now, and only check if the
// number of steps is 7.
bool VerifyAlsConfig() {
DCHECK(!content::BrowserThread::CurrentlyOn(content::BrowserThread::UI));
base::CommandLine command_line{
base::FilePath(FILE_PATH_LITERAL("check_powerd_config"))};
command_line.AppendArg("--internal_backlight_ambient_light_steps");
int exit_code = 0;
std::string output;
const bool result =
base::GetAppOutputWithExitCode(command_line, &output, &exit_code);
if (!result || exit_code != 0) {
LOG(ERROR) << "Cannot run check_powerd_config "
"--internal_backlight_ambient_light_steps";
return false;
}
const std::vector<base::StringPiece> num_steps = base::SplitStringPiece(
output, "\n", base::TRIM_WHITESPACE, base::SPLIT_WANT_NONEMPTY);
return num_steps.size() == 7;
}
// Returns ALS path. This should run in another thread to be non-blocking to the
// main thread.
std::string GetAlsPath() {
......@@ -158,7 +132,6 @@ void AlsReaderImpl::InitForTesting(const base::FilePath& ambient_light_path) {
}
void AlsReaderImpl::FailForTesting() {
OnAlsConfigCheckDone(false);
OnAlsEnableCheckDone(false);
for (int i = 0; i <= kMaxInitialAttempts; i++)
OnAlsPathReadAttempted("");
......@@ -172,20 +145,6 @@ void AlsReaderImpl::OnAlsEnableCheckDone(const bool is_enabled) {
return;
}
base::PostTaskAndReplyWithResult(
blocking_task_runner_.get(), FROM_HERE, base::BindOnce(&VerifyAlsConfig),
base::BindOnce(&AlsReaderImpl::OnAlsConfigCheckDone,
weak_ptr_factory_.GetWeakPtr()));
}
void AlsReaderImpl::OnAlsConfigCheckDone(const bool is_config_valid) {
DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
if (!is_config_valid) {
status_ = AlsInitStatus::kIncorrectConfig;
OnInitializationComplete();
return;
}
RetryAlsPath();
}
......
......@@ -66,9 +66,6 @@ class AlsReaderImpl : public AlsReader {
// Called when we've checked whether ALS is enabled.
void OnAlsEnableCheckDone(bool is_enabled);
// Called when we've checked whether ALS config is valid.
void OnAlsConfigCheckDone(bool is_config_valid);
// Called when we've tried to read ALS path. If |path| is empty, it would
// reschedule another attempt up to |kMaxInitialAttempts|.
void OnAlsPathReadAttempted(const std::string& path);
......
......@@ -108,13 +108,10 @@ TEST_F(AlsReaderImplTest, ErrorMetrics) {
als_reader_.FailForTesting();
histogram_tester_.ExpectBucketCount(
histogram, static_cast<int>(AlsReader::AlsInitStatus::kDisabled), 1);
histogram_tester_.ExpectBucketCount(
histogram, static_cast<int>(AlsReader::AlsInitStatus::kIncorrectConfig),
1);
histogram_tester_.ExpectBucketCount(
histogram, static_cast<int>(AlsReader::AlsInitStatus::kMissingPath), 1);
// Expect 3 errors from above + 1 success from before |FailForTesting|.
histogram_tester_.ExpectTotalCount(histogram, 4);
// Expect 2 errors from above + 1 success from before |FailForTesting|.
histogram_tester_.ExpectTotalCount(histogram, 3);
}
TEST_F(AlsReaderImplTest, OneAlsValue) {
......
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