blob: caf5b8b42887d89de63823d398098dd81d4a6be1 [file] [log] [blame]
yro947fbce2017-11-15 22:50:23 -08001/*
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
26namespace android {
27namespace os {
28namespace statsd {
29
30using android::util::ProtoOutputStream;
31
32class StorageManager : public virtual RefBase {
33public:
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 /**
50 * Deletes all files whose name matches with a provided prefix.
51 */
52 static void deletePrefixedFiles(const char* path, const char* prefix);
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 */
64 static void appendConfigMetricsReport(const char* path, ProtoOutputStream& proto);
65
66 /**
67 * Call to load the saved configs from disk.
68 */
Yao Chenf09569f2017-12-13 17:00:51 -080069 static void readConfigFromDisk(std::map<ConfigKey, StatsdConfig>& configsMap);
yro947fbce2017-11-15 22:50:23 -080070};
71
72} // namespace statsd
73} // namespace os
74} // namespace android
75
76#endif // STORAGE_MANAGER_H