1 /* 2 * Copyright (C) 2019 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 package android.gsi; 18 19 import android.gsi.AvbPublicKey; 20 import android.gsi.GsiProgress; 21 import android.gsi.IGsiServiceCallback; 22 import android.gsi.IImageService; 23 import android.os.ParcelFileDescriptor; 24 25 /** {@hide} */ 26 interface IGsiService { 27 /* Status codes for GsiProgress.status */ 28 const int STATUS_NO_OPERATION = 0; 29 const int STATUS_WORKING = 1; 30 const int STATUS_COMPLETE = 2; 31 32 /* Install succeeded. */ 33 const int INSTALL_OK = 0; 34 /* Install failed with a generic system error. */ 35 const int INSTALL_ERROR_GENERIC = 1; 36 /* Install failed because there was no free space. */ 37 const int INSTALL_ERROR_NO_SPACE = 2; 38 /** 39 * Install failed because the file system was too fragmented or did not 40 * have enough additional free space. 41 */ 42 const int INSTALL_ERROR_FILE_SYSTEM_CLUTTERED = 3; 43 44 /** 45 * Write bytes from a stream to the on-disk GSI. 46 * 47 * @param stream Stream descriptor. 48 * @param bytes Number of bytes that can be read from stream. 49 * @return true on success, false otherwise. 50 */ commitGsiChunkFromStream(in ParcelFileDescriptor stream, long bytes)51 boolean commitGsiChunkFromStream(in ParcelFileDescriptor stream, long bytes); 52 53 /** 54 * Query the progress of the current asynchronous install operation. This 55 * can be called while another operation is in progress. 56 */ getInstallProgress()57 GsiProgress getInstallProgress(); 58 59 /** 60 * Set the file descriptor that points to a ashmem which will be used 61 * to fetch data during the commitGsiChunkFromAshmem. 62 * 63 * @param stream fd that points to a ashmem 64 * @param size size of the ashmem file 65 */ setGsiAshmem(in ParcelFileDescriptor stream, long size)66 boolean setGsiAshmem(in ParcelFileDescriptor stream, long size); 67 68 /** 69 * Write bytes from ashmem previously set with setGsiAshmem to GSI partition 70 * 71 * @param bytes Number of bytes to submit 72 * @return true on success, false otherwise. 73 */ commitGsiChunkFromAshmem(long bytes)74 boolean commitGsiChunkFromAshmem(long bytes); 75 76 /** 77 * Mark a completed DSU installation as bootable. The caller is responsible 78 * for rebooting the device as soon as possible. 79 * 80 * Could leave the installation in "disabled" state if failure. 81 * 82 * @param oneShot If true, the GSI will boot once and then disable itself. 83 * It can still be re-enabled again later with setGsiBootable. 84 * @param dsuSlot The DSU slot to be enabled. Possible values are available 85 * with the getInstalledDsuSlots() 86 * 87 * @return INSTALL_* error code. 88 */ enableGsi(boolean oneShot, @utf8InCpp String dsuSlot)89 int enableGsi(boolean oneShot, @utf8InCpp String dsuSlot); 90 91 /** 92 * Asynchronous enableGsi 93 * @param result callback for result 94 */ 95 @SuppressWarnings(value={"mixed-oneway"}) enableGsiAsync(boolean oneShot, @utf8InCpp String dsuSlot, IGsiServiceCallback result)96 oneway void enableGsiAsync(boolean oneShot, @utf8InCpp String dsuSlot, IGsiServiceCallback result); 97 98 /** 99 * @return True if Gsi is enabled 100 */ isGsiEnabled()101 boolean isGsiEnabled(); 102 103 /** 104 * Cancel an in-progress GSI install. 105 */ cancelGsiInstall()106 boolean cancelGsiInstall(); 107 108 /** 109 * Return if a GSI installation is currently in-progress. 110 */ isGsiInstallInProgress()111 boolean isGsiInstallInProgress(); 112 113 /** 114 * Remove a GSI install. This will completely remove and reclaim space used 115 * by the GSI and its userdata. If currently running a GSI, space will be 116 * reclaimed on the reboot. 117 * 118 * @return true on success, false otherwise. 119 */ removeGsi()120 boolean removeGsi(); 121 122 /** 123 * Asynchronous removeGsi 124 * @param result callback for result 125 */ 126 @SuppressWarnings(value={"mixed-oneway"}) removeGsiAsync(IGsiServiceCallback result)127 oneway void removeGsiAsync(IGsiServiceCallback result); 128 129 /** 130 * Disables a GSI install. The image and userdata will be retained, but can 131 * be re-enabled at any time with setGsiBootable. 132 */ disableGsi()133 boolean disableGsi(); 134 135 /** 136 * Returns true if a gsi is installed. 137 */ isGsiInstalled()138 boolean isGsiInstalled(); 139 /** 140 * Returns true if the gsi is currently running, false otherwise. 141 */ isGsiRunning()142 boolean isGsiRunning(); 143 144 /** 145 * Returns the active DSU slot if there is any DSU installed, empty string otherwise. 146 */ getActiveDsuSlot()147 @utf8InCpp String getActiveDsuSlot(); 148 149 /** 150 * If a GSI is installed, returns the directory where the installed images 151 * are located. Otherwise, returns an empty string. 152 */ getInstalledGsiImageDir()153 @utf8InCpp String getInstalledGsiImageDir(); 154 155 /** 156 * Returns all installed DSU slots. 157 */ getInstalledDsuSlots()158 @utf8InCpp List<String> getInstalledDsuSlots(); 159 160 /** 161 * Open a DSU installation 162 * 163 * @param installDir The directory to install DSU images under. This must be 164 * either an empty string (which will use the default /data/gsi), 165 * "/data/gsi", or a mount under /mnt/media_rw. It may end in a trailing slash. 166 * 167 * @return 0 on success, an error code on failure. 168 */ openInstall(in @tf8InCpp String installDir)169 int openInstall(in @utf8InCpp String installDir); 170 171 /** 172 * Close a DSU installation. An installation is complete after the close been invoked. 173 */ closeInstall()174 int closeInstall(); 175 176 /** 177 * Create a DSU partition within the current installation 178 * 179 * @param name The DSU partition name 180 * @param size Bytes in the partition 181 * @param readOnly True if the partition is readOnly when DSU is running 182 */ createPartition(in @tf8InCpp String name, long size, boolean readOnly)183 int createPartition(in @utf8InCpp String name, long size, boolean readOnly); 184 185 /** 186 * Complete the current partition installation. A partition installation is 187 * complete after all pending bytes are written successfully. 188 * Returns an error if current installation still have pending bytes. 189 * Returns an error if there is any internal filesystem error. 190 * 191 * @return 0 on success, an error code on failure. 192 */ closePartition()193 int closePartition(); 194 195 /** 196 * Wipe a partition. This will not work if the GSI is currently running. 197 * The partition will not be removed, but the first block will be zeroed. 198 * 199 * @param name The DSU partition name 200 * 201 * @return 0 on success, an error code on failure. 202 */ zeroPartition(in @tf8InCpp String name)203 int zeroPartition(in @utf8InCpp String name); 204 205 /** 206 * Open a handle to an IImageService for the given metadata and data storage paths. 207 * 208 * @param prefix A prefix used to organize images. The data path will become 209 * /data/gsi/{prefix} and the metadata path will become 210 * /metadata/gsi/{prefix}. 211 */ openImageService(@tf8InCpp String prefix)212 IImageService openImageService(@utf8InCpp String prefix); 213 214 /** 215 * Dump diagnostic information about device-mapper devices. This is intended 216 * for dumpstate. 217 */ dumpDeviceMapperDevices()218 @utf8InCpp String dumpDeviceMapperDevices(); 219 220 /** 221 * Retrieve AVB public key from the current mapped partition. 222 * This works only while partition device is mapped and the end-of-partition 223 * AVB footer has been written. 224 * A call to createPartition() does the following things: 225 * 1. Close the previous partition installer, thus unmap the partition. 226 * 2. Open a new partition installer. 227 * 3. Create and map the new partition. 228 * 229 * In other words, getAvbPublicKey() should be called after 230 * createPartition() is called and before closePartition() is called. 231 * 232 * @param dst Output the AVB public key. 233 * @return 0 on success, an error code on failure. 234 */ getAvbPublicKey(out AvbPublicKey dst)235 int getAvbPublicKey(out AvbPublicKey dst); 236 237 /** 238 * Returns the suggested scratch partition size for overlayFS. 239 */ suggestScratchSize()240 long suggestScratchSize(); 241 } 242