Commit 42f6f938 authored by Jun Mukai's avatar Jun Mukai Committed by Commit Bot

Do not use the accelerometer device file when it's failed to read

On some system / device configuration, the accelerometer device
file exists but can't be read by the browser process. When this
happens, it generates error log repeatedly, which is not great.

This CL tries to address this issue in a way. On initializing
accelerometer configuration, it tries to read the device file
at that time, and when it fails to read, it just stops the
initialization and reports an error message. This happens once,
and does not generate repeated logs.

Also, when an error happens, now it can obtain the errno and
print it as a part of the log, so it would be more understandable
why it fails. On my case, it is just permission denied, for some
reasons.

Bug: 1134527
Test: manually with nautilus device in the lab
Change-Id: Ib9823631a70fc54d3e3abc35067aff56a7d7ee50
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2454840Reviewed-by: default avatarMin Chen <minch@chromium.org>
Reviewed-by: default avatarJames Cook <jamescook@chromium.org>
Commit-Queue: Jun Mukai <mukai@chromium.org>
Cr-Commit-Position: refs/heads/master@{#814780}
parent fa5127d2
......@@ -17,6 +17,7 @@
#include "base/files/file_enumerator.h"
#include "base/files/file_util.h"
#include "base/location.h"
#include "base/logging.h"
#include "base/memory/singleton.h"
#include "base/numerics/math_constants.h"
#include "base/observer_list_threadsafe.h"
......@@ -615,12 +616,21 @@ bool AccelerometerFileReader::InitializeAccelerometer(
}
configuration_.scale[config_index][i] = scale;
}
base::FilePath path =
base::FilePath(kAccelerometerDevicePath).Append(name.BaseName());
char try_reading;
if (base::ReadFile(path, &try_reading, 1) < 0) {
logging::SystemErrorCode err_code = logging::GetLastSystemErrorCode();
LOG(ERROR) << "Failed to read " << path
<< " error: " << logging::SystemErrorCodeToString(err_code);
return false;
}
configuration_.has[config_index] = true;
configuration_.count++;
ReadingData reading_data;
reading_data.path =
base::FilePath(kAccelerometerDevicePath).Append(name.BaseName());
reading_data.path = path;
reading_data.sources.push_back(
static_cast<AccelerometerSource>(config_index));
......@@ -701,9 +711,11 @@ void AccelerometerFileReader::ReadFileAndNotify() {
char reading[reading_size];
int bytes_read = base::ReadFile(reading_data.path, reading, reading_size);
if (bytes_read < reading_size) {
logging::SystemErrorCode err_code = logging::GetLastSystemErrorCode();
LOG(ERROR) << "Accelerometer Read " << bytes_read << " byte(s), expected "
<< reading_size << " bytes from accelerometer "
<< reading_data.path.MaybeAsASCII();
<< reading_data.path.MaybeAsASCII()
<< " error: " << logging::SystemErrorCodeToString(err_code);
return;
}
for (AccelerometerSource source : reading_data.sources) {
......
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