yro | 947fbce | 2017-11-15 22:50:23 -0800 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2017 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 STORAGE_MANAGER_H |
| 18 | #define STORAGE_MANAGER_H |
| 19 | |
| 20 | #include <android/util/ProtoOutputStream.h> |
| 21 | #include <utils/Log.h> |
| 22 | #include <utils/RefBase.h> |
| 23 | |
| 24 | #include "packages/UidMap.h" |
| 25 | |
| 26 | namespace android { |
| 27 | namespace os { |
| 28 | namespace statsd { |
| 29 | |
| 30 | using android::util::ProtoOutputStream; |
| 31 | |
| 32 | class StorageManager : public virtual RefBase { |
| 33 | public: |
| 34 | /** |
| 35 | * Writes a given byte array as a file to the specified file path. |
| 36 | */ |
| 37 | static void writeFile(const char* file, const void* buffer, int numBytes); |
| 38 | |
| 39 | /** |
| 40 | * Deletes a single file given a file name. |
| 41 | */ |
| 42 | static void deleteFile(const char* file); |
| 43 | |
| 44 | /** |
| 45 | * Deletes all files in a given directory. |
| 46 | */ |
| 47 | static void deleteAllFiles(const char* path); |
| 48 | |
| 49 | /** |
yro | e5f8292 | 2018-01-22 18:37:27 -0800 | [diff] [blame] | 50 | * Deletes all files whose name matches with a provided suffix. |
yro | 947fbce | 2017-11-15 22:50:23 -0800 | [diff] [blame] | 51 | */ |
yro | e5f8292 | 2018-01-22 18:37:27 -0800 | [diff] [blame] | 52 | static void deleteSuffixedFiles(const char* path, const char* suffix); |
yro | 947fbce | 2017-11-15 22:50:23 -0800 | [diff] [blame] | 53 | |
| 54 | /** |
| 55 | * Send broadcasts to relevant receiver for each data stored on disk. |
| 56 | */ |
| 57 | static void sendBroadcast(const char* path, |
| 58 | const std::function<void(const ConfigKey&)>& sendBroadcast); |
| 59 | |
| 60 | /** |
| 61 | * Appends ConfigMetricsReport found on disk to the specific proto and |
| 62 | * delete it. |
| 63 | */ |
yro | 98a2850 | 2018-01-18 17:00:14 -0800 | [diff] [blame] | 64 | static void appendConfigMetricsReport(ProtoOutputStream& proto); |
yro | 947fbce | 2017-11-15 22:50:23 -0800 | [diff] [blame] | 65 | |
| 66 | /** |
| 67 | * Call to load the saved configs from disk. |
| 68 | */ |
Yao Chen | f09569f | 2017-12-13 17:00:51 -0800 | [diff] [blame] | 69 | static void readConfigFromDisk(std::map<ConfigKey, StatsdConfig>& configsMap); |
yro | 98a2850 | 2018-01-18 17:00:14 -0800 | [diff] [blame] | 70 | |
| 71 | /** |
| 72 | * Trims files in the provided directory to limit the total size, number of |
| 73 | * files, accumulation of outdated files. |
| 74 | */ |
| 75 | static void trimToFit(const char* dir); |
yro | 947fbce | 2017-11-15 22:50:23 -0800 | [diff] [blame] | 76 | }; |
| 77 | |
| 78 | } // namespace statsd |
| 79 | } // namespace os |
| 80 | } // namespace android |
| 81 | |
| 82 | #endif // STORAGE_MANAGER_H |