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      * Complete a GSI installation and mark it as bootable. The caller is
78      * responsible for rebooting the device as soon as possible.
79      *
80      * @param oneShot       If true, the GSI will boot once and then disable itself.
81      *                      It can still be re-enabled again later with setGsiBootable.
82      * @param dsuSlot       The DSU slot to be enabled. Possible values are available
83      *                      with the getInstalledDsuSlots()
84      *
85      * @return              INSTALL_* error code.
86      */
enableGsi(boolean oneShot, @utf8InCpp String dsuSlot)87     int enableGsi(boolean oneShot, @utf8InCpp String dsuSlot);
88 
89     /**
90      * Asynchronous enableGsi
91      * @param result        callback for result
92      */
enableGsiAsync(boolean oneShot, @utf8InCpp String dsuSlot, IGsiServiceCallback result)93     oneway void enableGsiAsync(boolean oneShot, @utf8InCpp String dsuSlot, IGsiServiceCallback result);
94 
95     /**
96      * @return              True if Gsi is enabled
97      */
isGsiEnabled()98     boolean isGsiEnabled();
99 
100     /**
101      * Cancel an in-progress GSI install.
102      */
cancelGsiInstall()103     boolean cancelGsiInstall();
104 
105     /**
106      * Return if a GSI installation is currently in-progress.
107      */
isGsiInstallInProgress()108     boolean isGsiInstallInProgress();
109 
110     /**
111      * Remove a GSI install. This will completely remove and reclaim space used
112      * by the GSI and its userdata. If currently running a GSI, space will be
113      * reclaimed on the reboot.
114      *
115      * @return              true on success, false otherwise.
116      */
removeGsi()117     boolean removeGsi();
118 
119     /**
120      * Asynchronous removeGsi
121      * @param result        callback for result
122      */
removeGsiAsync(IGsiServiceCallback result)123     oneway void removeGsiAsync(IGsiServiceCallback result);
124 
125     /**
126      * Disables a GSI install. The image and userdata will be retained, but can
127      * be re-enabled at any time with setGsiBootable.
128      */
disableGsi()129     boolean disableGsi();
130 
131     /**
132      * Returns true if a gsi is installed.
133      */
isGsiInstalled()134     boolean isGsiInstalled();
135     /**
136      * Returns true if the gsi is currently running, false otherwise.
137      */
isGsiRunning()138     boolean isGsiRunning();
139 
140     /**
141      * Returns the active DSU slot if there is any DSU installed, empty string otherwise.
142      */
getActiveDsuSlot()143     @utf8InCpp String getActiveDsuSlot();
144 
145     /**
146      * If a GSI is installed, returns the directory where the installed images
147      * are located. Otherwise, returns an empty string.
148      */
getInstalledGsiImageDir()149     @utf8InCpp String getInstalledGsiImageDir();
150 
151     /**
152      * Returns all installed DSU slots.
153      */
getInstalledDsuSlots()154     @utf8InCpp List<String> getInstalledDsuSlots();
155 
156     /**
157      * Open a DSU installation
158      *
159      * @param installDir The directory to install DSU images under. This must be
160      *     either an empty string (which will use the default /data/gsi),
161      *     "/data/gsi", or a mount under /mnt/media_rw. It may end in a trailing slash.
162      *
163      * @return              0 on success, an error code on failure.
164      */
openInstall(in @tf8InCpp String installDir)165     int openInstall(in @utf8InCpp String installDir);
166 
167     /**
168      * Close a DSU installation. An installation is complete after the close been invoked.
169      */
closeInstall()170     int closeInstall();
171 
172     /**
173      * Create a DSU partition within the current installation
174      *
175      * @param name The DSU partition name
176      * @param size Bytes in the partition
177      * @param readOnly True if the partition is readOnly when DSU is running
178      */
createPartition(in @tf8InCpp String name, long size, boolean readOnly)179     int createPartition(in @utf8InCpp String name, long size, boolean readOnly);
180 
181     /**
182      * Wipe a partition. This will not work if the GSI is currently running.
183      * The partition will not be removed, but the first block will be zeroed.
184      *
185      * @param name The DSU partition name
186      *
187      * @return              0 on success, an error code on failure.
188      */
zeroPartition(in @tf8InCpp String name)189     int zeroPartition(in @utf8InCpp String name);
190 
191     /**
192      * Open a handle to an IImageService for the given metadata and data storage paths.
193      *
194      * @param prefix        A prefix used to organize images. The data path will become
195      *                      /data/gsi/{prefix} and the metadata path will become
196      *                      /metadata/gsi/{prefix}.
197      */
openImageService(@tf8InCpp String prefix)198     IImageService openImageService(@utf8InCpp String prefix);
199 
200     /**
201      * Dump diagnostic information about device-mapper devices. This is intended
202      * for dumpstate.
203      */
dumpDeviceMapperDevices()204     @utf8InCpp String dumpDeviceMapperDevices();
205 
206     /**
207      * Retrieve AVB public key from the current mapped partition.
208      * This works only while partition device is mapped and the end-of-partition
209      * AVB footer has been written.
210      * A call to createPartition() does the following things:
211      * 1. Close the previous partition installer, thus unmap the partition.
212      * 2. Open a new partition installer.
213      * 3. Create and map the new partition.
214      *
215      * In other words, getAvbPublicKey() works between two createPartition() calls.
216      *
217      * @param dst           Output the AVB public key.
218      * @return              0 on success, an error code on failure.
219      */
getAvbPublicKey(out AvbPublicKey dst)220     int getAvbPublicKey(out AvbPublicKey dst);
221 }
222