blob: 48518ff9233399d8930d2a66cb02820353013b0c [file] [log] [blame]
Alice Wangfb46ee12022-09-30 13:08:52 +00001/*
2 * Copyright (C) 2022 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#pragma once
18
Andrew Scull102067a2022-10-07 00:34:40 +000019#include <stdbool.h>
20#include <stddef.h>
Alan Stokesd4ea5a82022-11-10 12:17:42 +000021#include <sys/cdefs.h>
Andrew Scull102067a2022-10-07 00:34:40 +000022
Alan Stokes52d3c722022-10-04 17:27:13 +010023#include "vm_main.h"
24
Alan Stokesd4ea5a82022-11-10 12:17:42 +000025__BEGIN_DECLS
Alice Wangfb46ee12022-09-30 13:08:52 +000026
Alice Wang2be64f32022-10-13 14:37:35 +000027struct AIBinder;
28typedef struct AIBinder AIBinder;
29
Andrew Sculld64ae7d2022-10-05 17:41:43 +000030/**
31 * Notifies the host that the payload is ready.
Andrew Scull655e98e2022-10-10 22:24:58 +000032 *
33 * \return true if the notification succeeds else false.
Andrew Sculld64ae7d2022-10-05 17:41:43 +000034 */
Andrew Scull655e98e2022-10-10 22:24:58 +000035bool AVmPayload_notifyPayloadReady(void);
Alice Wangfb46ee12022-09-30 13:08:52 +000036
Andrew Sculld64ae7d2022-10-05 17:41:43 +000037/**
Alice Wang2be64f32022-10-13 14:37:35 +000038 * Runs a binder RPC server, serving the supplied binder service implementation on the given vsock
39 * port.
40 *
41 * If and when the server is ready for connections (it is listening on the port), `on_ready` is
42 * called to allow appropriate action to be taken - e.g. to notify clients that they may now
43 * attempt to connect with `AVmPayload_notifyPayloadReady`.
44 *
45 * The current thread is joined to the binder thread pool to handle incoming messages.
46 *
47 * \param service the service to bind to the given port.
48 * \param port vsock port.
49 * \param on_ready the callback to execute once the server is ready for connections. The callback
50 * will be called at most once.
51 * \param param param for the `on_ready` callback.
52 *
53 * \return true if the server has shutdown normally, false if it failed in some way.
54 */
55bool AVmPayload_runVsockRpcServer(AIBinder *service, unsigned int port,
56 void (*on_ready)(void *param), void *param);
57
58/**
Alan Stokes0cbfdf92022-11-21 17:17:53 +000059 * Get a secret that is uniquely bound to this VM instance. The secrets are
60 * values up to 32 bytes long and the value associated with an identifier will
61 * not change over the lifetime of the VM instance.
Andrew Scull102067a2022-10-07 00:34:40 +000062 *
63 * \param identifier identifier of the secret to return.
64 * \param identifier_size size of the secret identifier.
65 * \param secret pointer to size bytes where the secret is written.
66 * \param size number of bytes of the secret to get, up to the secret size.
67 *
68 * \return true on success and false on failure.
69 */
Andrew Scull655e98e2022-10-10 22:24:58 +000070bool AVmPayload_getVmInstanceSecret(const void *identifier, size_t identifier_size, void *secret,
71 size_t size);
Andrew Scull102067a2022-10-07 00:34:40 +000072
73/**
Alice Wang6bbb6da2022-10-26 12:44:06 +000074 * Gets the path to the APK contents. It is a directory, under which are
75 * the unzipped contents of the APK containing the payload, all read-only
76 * but accessible to the payload.
77 *
78 * \return the path to the APK contents. The returned string should not be
79 * deleted or freed by the application. The string remains valid for the
80 * lifetime of the VM.
81 */
82const char *AVmPayload_getApkContentsPath(void);
83
Alan Stokes78d24702022-11-21 15:28:31 +000084/**
85 * Gets the path to the encrypted persistent storage for the VM, if any. This is
86 * a directory under which any files or directories created will be stored on
87 * behalf of the VM by the host app. All data is encrypted using a key known
88 * only to the VM, so the host cannot decrypt it, but may delete it.
89 *
90 * \return the path to the APK contents, or NULL if no encrypted storage was
91 * requested in the VM configuration. If non-null the returned string should not
92 * be deleted or freed by the application and remains valid for the lifetime of
93 * the VM.
94 */
95const char *AVmPayload_getEncryptedStoragePath(void);
96
Alan Stokesd4ea5a82022-11-10 12:17:42 +000097__END_DECLS