1 // Copyright 2017 The Android Open Source Project 2 // 3 // This software is licensed under the terms of the GNU General Public 4 // License version 2, as published by the Free Software Foundation, and 5 // may be copied, distributed, and modified under those terms. 6 // 7 // This program is distributed in the hope that it will be useful, 8 // but WITHOUT ANY WARRANTY; without even the implied warranty of 9 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 10 // GNU General Public License for more details. 11 #pragma once 12 13 #include "host-common/vm_operations.h" 14 // #include "host-common/window_agent.h" 15 16 typedef enum { 17 SNAPSHOT_STATUS_NOT_STARTED, 18 SNAPSHOT_STATUS_OK, 19 SNAPSHOT_STATUS_ERROR, 20 SNAPSHOT_STATUS_ERROR_NOT_CHANGED, 21 SNAPSHOT_STATUS_CANCELED, 22 } AndroidSnapshotStatus; 23 24 // void androidSnapshot_initialize(const QAndroidVmOperations* vmOperations, 25 // const QAndroidEmulatorWindowAgent* windowAgent); 26 void androidSnapshot_setDiskSpaceCheck(bool enable); 27 void androidSnapshot_finalize(); 28 29 AndroidSnapshotStatus androidSnapshot_prepareForLoading(const char* name); 30 AndroidSnapshotStatus androidSnapshot_load(const char* name); 31 32 int64_t androidSnapshot_lastLoadUptimeMs(); 33 34 AndroidSnapshotStatus androidSnapshot_prepareForSaving(const char* name); 35 AndroidSnapshotStatus androidSnapshot_save(const char* name); 36 37 void androidSnapshot_cancelSave(); 38 39 void androidSnapshot_delete(const char* name); 40 41 // androidSnapshot_delete, but keeps the protobuf around as an epitaph. 42 void androidSnapshot_invalidate(const char* name); 43 44 bool androidSnapshot_areSavesSlow(const char* name); 45 46 // Returns the name of the snapshot file that was loaded to start 47 // the current image. 48 // Returns an empty string if the AVD was cold-booted. 49 const char* androidSnapshot_loadedSnapshotFile(); 50 51 // These two functions implement a quickboot feature: load() tries to load from 52 // the |name| snapshot (or default one if it is null or empty) and save() saves 53 // the current state into it. 54 // Return value is |true| if the feature is enabled, 55 // and the function has at least tried to do something, |false| otherwise. 56 bool androidSnapshot_quickbootLoad(const char* name); 57 bool androidSnapshot_quickbootSave(const char* name); 58 59 // For when we want to skip quickboot AND skip loading it next time, such as 60 // in the case of a power-off and restart. 61 void androidSnapshot_quickbootInvalidate(const char* name); 62 63 // List snapshots to stdout. 64 void androidSnapshot_listStdout(); 65 66 // List snapshots with a custom callback for consuming the lines. 67 void androidSnapshot_list(void* opaque, 68 int (*cbOut)(void* opaque, const char* buf, int strlen), 69 int (*cbErr)(void* opaque, const char* buf, int strlen)); 70 71 // Notify snapshot interface that we are using file-backed RAM. 72 void androidSnapshot_setRamFile(const char* path, int shared); 73 74 // Marks the current RAM file as dirty; i.e., 75 // any failure to save completely will cause deletion next time 76 // androidSnapshot_prepareAutosave is called. 77 // |isDirty| determines whether the RAM file is set to dirty. 78 void androidSnapshot_setRamFileDirty(const char* name, bool isDirty); 79 bool androidSnapshot_isRamFileDirty(const char* name); 80 81 // Retrieves path to potential RAM map of snapshot. 82 // Creates the directory if needed. 83 // Resulting pointer must be freed. 84 // If there is insufficient disk space, returns NULL. 85 // If the RAM size is now configured differently, 86 // deletes the RAM file. 87 // If the RAM file is still marked dirty, 88 // deletes the entire snapshot. 89 const char* androidSnapshot_prepareAutosave(int memSizeMb, const char* name); 90 91 typedef enum { 92 SNAPSHOT_RAM_FILE_NONE, 93 SNAPSHOT_RAM_FILE_SHARED, 94 SNAPSHOT_RAM_FILE_PRIVATE, 95 } AndroidSnapshotRamFileMode; 96 97 AndroidSnapshotRamFileMode androidSnapshot_getRamFileInfo(); 98 99 void androidSnapshot_writeQuickbootChoice(bool save); 100 bool androidSnapshot_getQuickbootChoice(); 101 102 void androidSnapshot_quickbootSetShortRunCheck(bool enable); 103 104 void androidSnapshot_setUsingHdd(bool usingHdd); 105 bool androidSnapshot_isUsingHdd(); 106 107 bool androidSnapshot_protoExists(const char* name); 108