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 #pragma once
17 
18 #include "aemu/base/c_header.h"
19 
20 #include "host-common/vm_operations.h"
21 #include "host-common/window_agent.h"
22 
23 #ifndef USING_ANDROID_BP
24 ANDROID_BEGIN_HEADER
25 #endif
26 
27 typedef enum {
28     SNAPSHOT_STATUS_NOT_STARTED,
29     SNAPSHOT_STATUS_OK,
30     SNAPSHOT_STATUS_ERROR,
31     SNAPSHOT_STATUS_ERROR_NOT_CHANGED,
32     SNAPSHOT_STATUS_CANCELED,
33 } AndroidSnapshotStatus;
34 
35 void androidSnapshot_initialize(const QAndroidVmOperations* vmOperations,
36                                 const QAndroidEmulatorWindowAgent* windowAgent);
37 void androidSnapshot_setDiskSpaceCheck(bool enable);
38 void androidSnapshot_finalize();
39 
40 AndroidSnapshotStatus androidSnapshot_prepareForLoading(const char* name);
41 AndroidSnapshotStatus androidSnapshot_load(const char* name);
42 
43 int64_t androidSnapshot_lastLoadUptimeMs();
44 
45 AndroidSnapshotStatus androidSnapshot_prepareForSaving(const char* name);
46 AndroidSnapshotStatus androidSnapshot_save(const char* name);
47 
48 void androidSnapshot_cancelSave();
49 
50 void androidSnapshot_delete(const char* name);
51 
52 // androidSnapshot_delete, but keeps the protobuf around as an epitaph.
53 void androidSnapshot_invalidate(const char* name);
54 
55 bool androidSnapshot_areSavesSlow(const char* name);
56 
57 // Returns the name of the snapshot file that was loaded to start
58 // the current image.
59 // Returns an empty string if the AVD was cold-booted.
60 const char* androidSnapshot_loadedSnapshotFile();
61 
62 // These two functions implement a quickboot feature: load() tries to load from
63 // the |name| snapshot (or default one if it is null or empty) and save() saves
64 // the current state into it.
65 // Return value is |true| if the feature is enabled,
66 // and the function has at least tried to do something, |false| otherwise.
67 bool androidSnapshot_quickbootLoad(const char* name);
68 bool androidSnapshot_quickbootSave(const char* name);
69 
70 // For when we want to skip quickboot AND skip loading it next time, such as
71 // in the case of a power-off and restart.
72 void androidSnapshot_quickbootInvalidate(const char* name);
73 
74 // List snapshots to stdout.
75 void androidSnapshot_listStdout();
76 
77 // List snapshots with a custom callback for consuming the lines.
78 void androidSnapshot_list(void* opaque,
79                           int (*cbOut)(void* opaque, const char* buf, int strlen),
80                           int (*cbErr)(void* opaque, const char* buf, int strlen));
81 
82 // Notify snapshot interface that we are using file-backed RAM.
83 void androidSnapshot_setRamFile(const char* path, int shared);
84 
85 // Marks the current RAM file as dirty; i.e.,
86 // any failure to save completely will cause deletion next time
87 // androidSnapshot_prepareAutosave is called.
88 // |isDirty| determines whether the RAM file is set to dirty.
89 void androidSnapshot_setRamFileDirty(const char* name, bool isDirty);
90 bool androidSnapshot_isRamFileDirty(const char* name);
91 
92 // Retrieves path to potential RAM map of snapshot.
93 // Creates the directory if needed.
94 // Resulting pointer must be freed.
95 // If there is insufficient disk space, returns NULL.
96 // If the RAM size is now configured differently,
97 // deletes the RAM file.
98 // If the RAM file is still marked dirty,
99 // deletes the entire snapshot.
100 const char* androidSnapshot_prepareAutosave(int memSizeMb, const char* name);
101 
102 typedef enum {
103     SNAPSHOT_RAM_FILE_NONE,
104     SNAPSHOT_RAM_FILE_SHARED,
105     SNAPSHOT_RAM_FILE_PRIVATE,
106 } AndroidSnapshotRamFileMode;
107 
108 AndroidSnapshotRamFileMode androidSnapshot_getRamFileInfo();
109 
110 void androidSnapshot_writeQuickbootChoice(bool save);
111 bool androidSnapshot_getQuickbootChoice();
112 
113 void androidSnapshot_quickbootSetShortRunCheck(bool enable);
114 
115 void androidSnapshot_setUsingHdd(bool usingHdd);
116 bool androidSnapshot_isUsingHdd();
117 
118 bool androidSnapshot_protoExists(const char* name);
119 
120 #ifndef USING_ANDROID_BP
121 ANDROID_END_HEADER
122 #endif
123