diff options
author | Hunter Knepshield <hknepshield@google.com> | 2020-01-15 17:48:01 -0800 |
---|---|---|
committer | Hunter Knepshield <hknepshield@google.com> | 2020-01-22 17:25:24 -0800 |
commit | 1b92d26c0831d68c6950990f430f880b1dd68e81 (patch) | |
tree | 3cfbe7409641f59f5c38417de9df7bf4b2639540 /dumpstate/1.1 | |
parent | 81626dc493edfd75c696793bd606326db58b83f0 (diff) | |
download | platform_hardware_interfaces-1b92d26c0831d68c6950990f430f880b1dd68e81.tar.gz platform_hardware_interfaces-1b92d26c0831d68c6950990f430f880b1dd68e81.tar.bz2 platform_hardware_interfaces-1b92d26c0831d68c6950990f430f880b1dd68e81.zip |
Make IDumpstateDevice 1.1
Add dumpstateBoard_1_1 to accept a mode parameter (e.g. for limiting
vendor logs to the right bug reports).
Add setDeviceLoggingEnabled for the user to toggle vendor logging on and
off.
Bug: 143183758
Bug: 143184495
Test: atest VtsHalDumpstateV1_1TargetTest
Change-Id: I5420e5e4ce88619c7e40cf967382f98babc3c3d5
Merged-In: I5420e5e4ce88619c7e40cf967382f98babc3c3d5
(cherry picked from commit c9e2c6d31967e1d164ad724812032192196f026c)
Diffstat (limited to 'dumpstate/1.1')
-rw-r--r-- | dumpstate/1.1/Android.bp | 18 | ||||
-rw-r--r-- | dumpstate/1.1/IDumpstateDevice.hal | 53 | ||||
-rw-r--r-- | dumpstate/1.1/types.hal | 62 | ||||
-rw-r--r-- | dumpstate/1.1/vts/functional/Android.bp | 29 | ||||
-rw-r--r-- | dumpstate/1.1/vts/functional/VtsHalDumpstateV1_1TargetTest.cpp | 171 |
5 files changed, 333 insertions, 0 deletions
diff --git a/dumpstate/1.1/Android.bp b/dumpstate/1.1/Android.bp new file mode 100644 index 0000000000..2aa8c82dc7 --- /dev/null +++ b/dumpstate/1.1/Android.bp @@ -0,0 +1,18 @@ +// This file is autogenerated by hidl-gen -Landroidbp. + +hidl_interface { + name: "android.hardware.dumpstate@1.1", + root: "android.hardware", + vndk: { + enabled: true, + }, + srcs: [ + "types.hal", + "IDumpstateDevice.hal", + ], + interfaces: [ + "android.hardware.dumpstate@1.0", + "android.hidl.base@1.0", + ], + gen_java: true, +} diff --git a/dumpstate/1.1/IDumpstateDevice.hal b/dumpstate/1.1/IDumpstateDevice.hal new file mode 100644 index 0000000000..24831b37b2 --- /dev/null +++ b/dumpstate/1.1/IDumpstateDevice.hal @@ -0,0 +1,53 @@ +/* + * Copyright (C) 2020 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. + */ +package android.hardware.dumpstate@1.1; + +import @1.0::IDumpstateDevice; + +interface IDumpstateDevice extends @1.0::IDumpstateDevice { + /** + * Extension of dumpstateBoard which also accepts a mode parameter to limit dumped data. + * + * For an example of when this is relevant, consider a bug report being generated with + * DumpstateMode::CONNECTIVITY - there is no reason to include camera or USB logs in this type + * of report. + * + * The 1.0 version of #dumpstateBoard(handle) should just delegate to this new method and pass + * DumpstateMode::DEFAULT and a timeout of 30,000ms (30 seconds). + * + * @param h A native handle with one or two valid file descriptors. The first FD is for text + * output, the second (if present) is for binary output. + * @param mode A mode value to restrict dumped content. + * @param timeoutMillis An approximate "budget" for how much time this call has been allotted. + * If execution runs longer than this, the IDumpstateDevice service may be killed and only + * partial information will be included in the report. + */ + dumpstateBoard_1_1(handle h, DumpstateMode mode, uint64_t timeoutMillis); + + /** + * Turns device vendor logging on or off. + * + * The setting should be persistent across reboots. Underlying implementations may need to start + * vendor logging daemons, set system properties, or change logging masks, for example. Given + * that many vendor logs contain significant amounts of private information and may come with + * memory/storage/battery impacts, calling this method on a user build should only be done after + * user consent has been obtained, e.g. from a toggle in developer settings. + * + * @param enable Whether to enable or disable device vendor logging. + * @return success Whether or not the change took effect. + */ + setDeviceLoggingEnabled(bool enable) generates (bool success); +}; diff --git a/dumpstate/1.1/types.hal b/dumpstate/1.1/types.hal new file mode 100644 index 0000000000..a6f391aded --- /dev/null +++ b/dumpstate/1.1/types.hal @@ -0,0 +1,62 @@ +/* + * Copyright (C) 2020 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. + */ +package android.hardware.dumpstate@1.1; + +/** + * Constants that define the type of bug report being taken to restrict content appropriately. + */ +enum DumpstateMode : uint32_t { + /** + * Takes a bug report without user interference. + */ + FULL = 0, + + /** + * Interactive bug report, i.e. triggered by the user. + */ + INTERACTIVE = 1, + + /** + * Remote bug report triggered by DevicePolicyManager, for example. + */ + REMOTE = 2, + + /** + * Bug report triggered on a wear device. + */ + WEAR = 3, + + /** + * Bug report limited to only connectivity info (cellular, wifi, and networking). Sometimes + * called "telephony" in legacy contexts. + * + * All reported information MUST directly relate to connectivity debugging or customer support + * and MUST NOT contain unrelated private information. This information MUST NOT identify + * user-installed packages (UIDs are OK, package names are not), and MUST NOT contain logs of + * user application traffic. + */ + CONNECTIVITY = 4, + + /** + * Bug report limited to only wifi info. + */ + WIFI = 5, + + /** + * Default mode. + */ + DEFAULT = 6 +}; diff --git a/dumpstate/1.1/vts/functional/Android.bp b/dumpstate/1.1/vts/functional/Android.bp new file mode 100644 index 0000000000..5267706c0b --- /dev/null +++ b/dumpstate/1.1/vts/functional/Android.bp @@ -0,0 +1,29 @@ +// +// Copyright (C) 2020 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. +// + +cc_test { + name: "VtsHalDumpstateV1_1TargetTest", + defaults: ["VtsHalTargetTestDefaults"], + srcs: ["VtsHalDumpstateV1_1TargetTest.cpp"], + static_libs: [ + "android.hardware.dumpstate@1.0", + "android.hardware.dumpstate@1.1", + ], + test_suites: [ + "general-tests", + "vts-core", + ], +} diff --git a/dumpstate/1.1/vts/functional/VtsHalDumpstateV1_1TargetTest.cpp b/dumpstate/1.1/vts/functional/VtsHalDumpstateV1_1TargetTest.cpp new file mode 100644 index 0000000000..3b6051cb7b --- /dev/null +++ b/dumpstate/1.1/vts/functional/VtsHalDumpstateV1_1TargetTest.cpp @@ -0,0 +1,171 @@ +/* + * Copyright (C) 2020 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. + */ + +#define LOG_TAG "dumpstate_1_1_hidl_hal_test" + +#include <fcntl.h> +#include <unistd.h> +#include <vector> + +#include <android/hardware/dumpstate/1.1/IDumpstateDevice.h> +#include <android/hardware/dumpstate/1.1/types.h> +#include <cutils/native_handle.h> +#include <gtest/gtest.h> +#include <hidl/GtestPrinter.h> +#include <hidl/ServiceManagement.h> +#include <log/log.h> + +using ::android::sp; +using ::android::hardware::Return; +using ::android::hardware::dumpstate::V1_1::DumpstateMode; +using ::android::hardware::dumpstate::V1_1::IDumpstateDevice; + +class DumpstateHidl1_1Test : public ::testing::TestWithParam<std::string> { + public: + virtual void SetUp() override { + dumpstate = IDumpstateDevice::getService(GetParam()); + ASSERT_NE(dumpstate, nullptr) << "Could not get HIDL instance"; + } + + sp<IDumpstateDevice> dumpstate; +}; + +#define TEST_FOR_DUMPSTATE_MODE(name, body, mode) \ + TEST_P(DumpstateHidl1_1Test, name##_##mode) { body(DumpstateMode::mode); } + +#define TEST_FOR_ALL_DUMPSTATE_MODES(name, body) \ + TEST_FOR_DUMPSTATE_MODE(name, body, FULL); \ + TEST_FOR_DUMPSTATE_MODE(name, body, INTERACTIVE); \ + TEST_FOR_DUMPSTATE_MODE(name, body, REMOTE); \ + TEST_FOR_DUMPSTATE_MODE(name, body, WEAR); \ + TEST_FOR_DUMPSTATE_MODE(name, body, CONNECTIVITY); \ + TEST_FOR_DUMPSTATE_MODE(name, body, WIFI); \ + TEST_FOR_DUMPSTATE_MODE(name, body, DEFAULT); + +const uint64_t kDefaultTimeoutMillis = 30 * 1000; // 30 seconds + +// Negative test: make sure dumpstateBoard() doesn't crash when passed a null pointer. +TEST_FOR_ALL_DUMPSTATE_MODES(TestNullHandle, [this](DumpstateMode mode) { + Return<void> status = dumpstate->dumpstateBoard_1_1(nullptr, mode, kDefaultTimeoutMillis); + + ASSERT_TRUE(status.isOk()) << "Status should be ok: " << status.description(); +}); + +// Negative test: make sure dumpstateBoard() ignores a handle with no FD. +TEST_FOR_ALL_DUMPSTATE_MODES(TestHandleWithNoFd, [this](DumpstateMode mode) { + native_handle_t* handle = native_handle_create(0, 0); + ASSERT_NE(handle, nullptr) << "Could not create native_handle"; + + Return<void> status = dumpstate->dumpstateBoard_1_1(handle, mode, kDefaultTimeoutMillis); + + ASSERT_TRUE(status.isOk()) << "Status should be ok: " << status.description(); + + native_handle_close(handle); + native_handle_delete(handle); +}); + +// Positive test: make sure dumpstateBoard() writes something to the FD. +TEST_FOR_ALL_DUMPSTATE_MODES(TestOk, [this](DumpstateMode mode) { + // Index 0 corresponds to the read end of the pipe; 1 to the write end. + int fds[2]; + ASSERT_EQ(0, pipe2(fds, O_NONBLOCK)) << errno; + + native_handle_t* handle = native_handle_create(1, 0); + ASSERT_NE(handle, nullptr) << "Could not create native_handle"; + handle->data[0] = fds[1]; + + Return<void> status = dumpstate->dumpstateBoard_1_1(handle, mode, kDefaultTimeoutMillis); + ASSERT_TRUE(status.isOk()) << "Status should be ok: " << status.description(); + + // Check that at least one byte was written + char buff; + ASSERT_EQ(1, read(fds[0], &buff, 1)) << "dumped nothing"; + + native_handle_close(handle); + native_handle_delete(handle); +}); + +// Positive test: make sure dumpstateBoard() doesn't crash with two FDs. +TEST_FOR_ALL_DUMPSTATE_MODES(TestHandleWithTwoFds, [this](DumpstateMode mode) { + int fds1[2]; + int fds2[2]; + ASSERT_EQ(0, pipe2(fds1, O_NONBLOCK)) << errno; + ASSERT_EQ(0, pipe2(fds2, O_NONBLOCK)) << errno; + + native_handle_t* handle = native_handle_create(2, 0); + ASSERT_NE(handle, nullptr) << "Could not create native_handle"; + handle->data[0] = fds1[1]; + handle->data[1] = fds2[1]; + + Return<void> status = dumpstate->dumpstateBoard_1_1(handle, mode, kDefaultTimeoutMillis); + ASSERT_TRUE(status.isOk()) << "Status should be ok: " << status.description(); + + native_handle_close(handle); + native_handle_delete(handle); +}); + +// Make sure dumpstateBoard_1_1 actually validates its arguments. +TEST_P(DumpstateHidl1_1Test, TestInvalidModeArgument_Negative) { + int fds[2]; + ASSERT_EQ(0, pipe2(fds, O_NONBLOCK)) << errno; + + native_handle_t* handle = native_handle_create(1, 0); + ASSERT_NE(handle, nullptr) << "Could not create native_handle"; + handle->data[0] = fds[1]; + + Return<void> status = dumpstate->dumpstateBoard_1_1(handle, static_cast<DumpstateMode>(-100), + kDefaultTimeoutMillis); + ASSERT_FALSE(status.isOk()) << "Status should not be ok with invalid mode param: " + << status.description(); + + native_handle_close(handle); + native_handle_delete(handle); +} + +TEST_P(DumpstateHidl1_1Test, TestInvalidModeArgument_Undefined) { + int fds[2]; + ASSERT_EQ(0, pipe2(fds, O_NONBLOCK)) << errno; + + native_handle_t* handle = native_handle_create(1, 0); + ASSERT_NE(handle, nullptr) << "Could not create native_handle"; + handle->data[0] = fds[1]; + + Return<void> status = dumpstate->dumpstateBoard_1_1(handle, static_cast<DumpstateMode>(9001), + kDefaultTimeoutMillis); + ASSERT_FALSE(status.isOk()) << "Status should not be ok with invalid mode param: " + << status.description(); + + native_handle_close(handle); + native_handle_delete(handle); +} + +// Make sure toggling device logging doesn't crash. +TEST_P(DumpstateHidl1_1Test, TestEnableDeviceLogging) { + Return<bool> status = dumpstate->setDeviceLoggingEnabled(true); + + ASSERT_TRUE(status.isOk()) << "Status should be ok: " << status.description(); +} + +TEST_P(DumpstateHidl1_1Test, TestDisableDeviceLogging) { + Return<bool> status = dumpstate->setDeviceLoggingEnabled(false); + + ASSERT_TRUE(status.isOk()) << "Status should be ok: " << status.description(); +} + +INSTANTIATE_TEST_SUITE_P( + PerInstance, DumpstateHidl1_1Test, + testing::ValuesIn(android::hardware::getAllHalInstanceNames(IDumpstateDevice::descriptor)), + android::hardware::PrintInstanceNameToString); |