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