summaryrefslogtreecommitdiffstats
path: root/health
diff options
context:
space:
mode:
authorYifan Hong2018-08-08 19:50:48 -0500
committerYifan Hong2018-09-20 19:18:53 -0500
commitc0263aa0e4dd6ce6f39521314fa638b0a7f10d66 (patch)
treec82f539de4037f14a695c8ce5b03230df6677954 /health
parentc922f43176776391d15010c5552bd60161de5dc3 (diff)
downloadplatform-hardware-interfaces-c0263aa0e4dd6ce6f39521314fa638b0a7f10d66.tar.gz
platform-hardware-interfaces-c0263aa0e4dd6ce6f39521314fa638b0a7f10d66.tar.xz
platform-hardware-interfaces-c0263aa0e4dd6ce6f39521314fa638b0a7f10d66.zip
health.storage: Add default implementation.
Test: lshal show default implementation when installed Test: `lshal debug` (read and write successfully) Test: `adb shell sm idle-maint run` Bug: 111655771 Change-Id: Ibb09836b99310b6bc21e87be9c0177175efa29df
Diffstat (limited to 'health')
-rw-r--r--health/storage/1.0/default/Android.bp48
-rw-r--r--health/storage/1.0/default/Storage.cpp151
-rw-r--r--health/storage/1.0/default/Storage.h49
-rw-r--r--health/storage/1.0/default/android.hardware.health.storage@1.0-service.rc5
-rw-r--r--health/storage/1.0/default/manifest_android.hardware.health.storage@1.0.xml11
-rw-r--r--health/storage/1.0/default/service.cpp41
6 files changed, 305 insertions, 0 deletions
diff --git a/health/storage/1.0/default/Android.bp b/health/storage/1.0/default/Android.bp
new file mode 100644
index 00000000..4723443c
--- /dev/null
+++ b/health/storage/1.0/default/Android.bp
@@ -0,0 +1,48 @@
1/*
2 * Copyright (C) 2018 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17cc_binary {
18 name: "android.hardware.health.storage@1.0-service",
19 vendor: true,
20 defaults: ["hidl_defaults"],
21 relative_install_path: "hw",
22 init_rc: ["android.hardware.health.storage@1.0-service.rc"],
23 srcs: [
24 "Storage.cpp",
25 "service.cpp",
26 ],
27
28 cflags: [
29 "-Wall",
30 "-Werror",
31 ],
32
33 shared_libs: [
34 "libbase",
35 "libhidlbase",
36 "libhidltransport",
37 "libutils",
38 "android.hardware.health.storage@1.0",
39 ],
40
41 static_libs: [
42 "libfstab",
43 ],
44
45 vintf_fragments: [
46 "manifest_android.hardware.health.storage@1.0.xml",
47 ],
48}
diff --git a/health/storage/1.0/default/Storage.cpp b/health/storage/1.0/default/Storage.cpp
new file mode 100644
index 00000000..2e53c508
--- /dev/null
+++ b/health/storage/1.0/default/Storage.cpp
@@ -0,0 +1,151 @@
1/*
2 * Copyright (C) 2018 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17#include "Storage.h"
18
19#include <sstream>
20
21#include <android-base/chrono_utils.h>
22#include <android-base/file.h>
23#include <android-base/logging.h>
24#include <android-base/strings.h>
25#include <fstab/fstab.h>
26
27namespace android {
28namespace hardware {
29namespace health {
30namespace storage {
31namespace V1_0 {
32namespace implementation {
33
34using base::ReadFileToString;
35using base::Timer;
36using base::Trim;
37using base::WriteStringToFd;
38using base::WriteStringToFile;
39
40std::string getGarbageCollectPath() {
41 std::unique_ptr<fstab, decltype(&fs_mgr_free_fstab)> fstab(fs_mgr_read_fstab_default(),
42 fs_mgr_free_fstab);
43 struct fstab_rec* rec = NULL;
44
45 for (int i = 0; i < fstab->num_entries; i++) {
46 if (fs_mgr_has_sysfs_path(&fstab->recs[i])) {
47 rec = &fstab->recs[i];
48 break;
49 }
50 }
51 if (!rec) {
52 return "";
53 }
54
55 std::string path;
56 path.append(rec->sysfs_path);
57 path = path + "/manual_gc";
58
59 return path;
60}
61
62Return<void> Storage::garbageCollect(uint64_t timeoutSeconds,
63 const sp<IGarbageCollectCallback>& cb) {
64 Result result = Result::SUCCESS;
65 std::string path = getGarbageCollectPath();
66
67 if (path.empty()) {
68 LOG(WARNING) << "Cannot find Dev GC path";
69 result = Result::UNKNOWN_ERROR;
70 } else {
71 Timer timer;
72 LOG(INFO) << "Start Dev GC on " << path;
73 while (1) {
74 std::string require;
75 if (!ReadFileToString(path, &require)) {
76 PLOG(WARNING) << "Reading manual_gc failed in " << path;
77 result = Result::IO_ERROR;
78 break;
79 }
80 require = Trim(require);
81 if (require == "" || require == "off" || require == "disabled") {
82 LOG(DEBUG) << "No more to do Dev GC";
83 break;
84 }
85 LOG(DEBUG) << "Trigger Dev GC on " << path;
86 if (!WriteStringToFile("1", path)) {
87 PLOG(WARNING) << "Start Dev GC failed on " << path;
88 result = Result::IO_ERROR;
89 break;
90 }
91 if (timer.duration() >= std::chrono::seconds(timeoutSeconds)) {
92 LOG(WARNING) << "Dev GC timeout";
93 // Timeout is not treated as an error. Try next time.
94 break;
95 }
96 sleep(2);
97 }
98 LOG(INFO) << "Stop Dev GC on " << path;
99 if (!WriteStringToFile("0", path)) {
100 PLOG(WARNING) << "Stop Dev GC failed on " << path;
101 result = Result::IO_ERROR;
102 }
103 }
104
105 if (cb != nullptr) {
106 auto ret = cb->onFinish(result);
107 if (!ret.isOk()) {
108 LOG(WARNING) << "Cannot return result to callback: " << ret.description();
109 }
110 }
111 return Void();
112}
113
114Return<void> Storage::debug(const hidl_handle& handle, const hidl_vec<hidl_string>&) {
115 if (handle == nullptr || handle->numFds < 1) {
116 return Void();
117 }
118
119 int fd = handle->data[0];
120 std::stringstream output;
121
122 std::string path = getGarbageCollectPath();
123 if (path.empty()) {
124 output << "Cannot find Dev GC path";
125 } else {
126 std::string require;
127
128 if (ReadFileToString(path, &require)) {
129 output << path << ":" << require << std::endl;
130 }
131
132 if (WriteStringToFile("0", path)) {
133 output << "stop success" << std::endl;
134 }
135 }
136
137 if (!WriteStringToFd(output.str(), fd)) {
138 PLOG(WARNING) << "debug: cannot write to fd";
139 }
140
141 fsync(fd);
142
143 return Void();
144}
145
146} // namespace implementation
147} // namespace V1_0
148} // namespace storage
149} // namespace health
150} // namespace hardware
151} // namespace android
diff --git a/health/storage/1.0/default/Storage.h b/health/storage/1.0/default/Storage.h
new file mode 100644
index 00000000..8c57ddb7
--- /dev/null
+++ b/health/storage/1.0/default/Storage.h
@@ -0,0 +1,49 @@
1/*
2 * Copyright (C) 2018 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17#ifndef ANDROID_HARDWARE_HEALTH_FILESYSTEM_V1_0_FILESYSTEM_H
18#define ANDROID_HARDWARE_HEALTH_FILESYSTEM_V1_0_FILESYSTEM_H
19
20#include <android/hardware/health/storage/1.0/IStorage.h>
21#include <hidl/Status.h>
22
23namespace android {
24namespace hardware {
25namespace health {
26namespace storage {
27namespace V1_0 {
28namespace implementation {
29
30using ::android::sp;
31using ::android::hardware::hidl_handle;
32using ::android::hardware::hidl_string;
33using ::android::hardware::hidl_vec;
34using ::android::hardware::Return;
35
36struct Storage : public IStorage {
37 Return<void> garbageCollect(uint64_t timeoutSeconds,
38 const sp<IGarbageCollectCallback>& cb) override;
39 Return<void> debug(const hidl_handle& handle, const hidl_vec<hidl_string>&) override;
40};
41
42} // namespace implementation
43} // namespace V1_0
44} // namespace storage
45} // namespace health
46} // namespace hardware
47} // namespace android
48
49#endif // ANDROID_HARDWARE_HEALTH_FILESYSTEM_V1_0_FILESYSTEM_H
diff --git a/health/storage/1.0/default/android.hardware.health.storage@1.0-service.rc b/health/storage/1.0/default/android.hardware.health.storage@1.0-service.rc
new file mode 100644
index 00000000..c6a14252
--- /dev/null
+++ b/health/storage/1.0/default/android.hardware.health.storage@1.0-service.rc
@@ -0,0 +1,5 @@
1service vendor.health-storage-hal-1-0 /vendor/bin/hw/android.hardware.health.storage@1.0-service
2 interface android.hardware.health.storage@1.0::IStorage default
3 class hal
4 user system
5 group system
diff --git a/health/storage/1.0/default/manifest_android.hardware.health.storage@1.0.xml b/health/storage/1.0/default/manifest_android.hardware.health.storage@1.0.xml
new file mode 100644
index 00000000..ffe854ea
--- /dev/null
+++ b/health/storage/1.0/default/manifest_android.hardware.health.storage@1.0.xml
@@ -0,0 +1,11 @@
1<manifest version="1.0" type="device">
2 <hal>
3 <name>android.hardware.health.storage</name>
4 <transport>hwbinder</transport>
5 <version>1.0</version>
6 <interface>
7 <name>IStorage</name>
8 <instance>default</instance>
9 </interface>
10 </hal>
11</manifest>
diff --git a/health/storage/1.0/default/service.cpp b/health/storage/1.0/default/service.cpp
new file mode 100644
index 00000000..a9450338
--- /dev/null
+++ b/health/storage/1.0/default/service.cpp
@@ -0,0 +1,41 @@
1/*
2 * Copyright 2018 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17#include <hidl/HidlTransportSupport.h>
18#include "Storage.h"
19
20using android::OK;
21using android::sp;
22using android::status_t;
23using android::UNKNOWN_ERROR;
24using android::hardware::configureRpcThreadpool;
25using android::hardware::joinRpcThreadpool;
26using android::hardware::health::storage::V1_0::IStorage;
27using android::hardware::health::storage::V1_0::implementation::Storage;
28
29int main() {
30 configureRpcThreadpool(1, true);
31
32 sp<IStorage> service = new Storage();
33 status_t result = service->registerAsService();
34
35 if (result != OK) {
36 return result;
37 }
38
39 joinRpcThreadpool();
40 return UNKNOWN_ERROR;
41}