1 /*
2 * Copyright (C) 2021 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/logging.h>
22 #include <health-storage-impl/common.h>
23
24 using ::android::hardware::health::storage::DebugDump;
25 using ::android::hardware::health::storage::GarbageCollect;
26
27 using HResult = android::hardware::health::storage::V1_0::Result;
28 using AResult = aidl::android::hardware::health::storage::Result;
29 // Ensure static_cast<AResult>(any HResult) works
30 static_assert(static_cast<AResult>(HResult::SUCCESS) == AResult::SUCCESS);
31 static_assert(static_cast<AResult>(HResult::IO_ERROR) == AResult::IO_ERROR);
32 static_assert(static_cast<AResult>(HResult::UNKNOWN_ERROR) == AResult::UNKNOWN_ERROR);
33
34 namespace aidl::android::hardware::health::storage {
35
garbageCollect(int64_t timeout_seconds,const std::shared_ptr<IGarbageCollectCallback> & callback)36 ndk::ScopedAStatus Storage::garbageCollect(
37 int64_t timeout_seconds, const std::shared_ptr<IGarbageCollectCallback>& callback) {
38 AResult result = static_cast<AResult>(GarbageCollect(static_cast<uint64_t>(timeout_seconds)));
39 if (callback != nullptr) {
40 auto status = callback->onFinish(result);
41 if (!status.isOk()) {
42 LOG(WARNING) << "Cannot return result " << toString(result)
43 << " to callback: " << status.getDescription();
44 }
45 }
46 return ndk::ScopedAStatus::ok();
47 }
48
dump(int fd,const char **,uint32_t)49 binder_status_t Storage::dump(int fd, const char**, uint32_t) {
50 DebugDump(fd);
51 return STATUS_OK;
52 }
53
54 } // namespace aidl::android::hardware::health::storage
55