Add a remote binder service for executing commands
To summarize, three binaries are involved to run a command remotely:
- pvm_exec: the client executable on the host side to wrap the
executable command with hints of FD passing
- compsvc: listen to requests, spin off and sandbox a worker for
execution setup
- compsvc_worker: set up authfs, prepare the fds and exec the actual
task
Please see the code documentation for details.
Bug: 171316742
Test: [shell 1] adb shell compsvc /system/bin/sleep
[shell 2] adb shell exec 8</dev/zero 7<>/dev/null pvm_exec
--in-fd 8 --out-fd 7 -- sleep 300
# Saw FDs in /proc/${sleep_pid}/fd
Change-Id: I4758a4dc7bc70b6e5cce79e151c84c9990d9bc89
diff --git a/compos/aidl/Android.bp b/compos/aidl/Android.bp
new file mode 100644
index 0000000..8737d63
--- /dev/null
+++ b/compos/aidl/Android.bp
@@ -0,0 +1,12 @@
+aidl_interface {
+ name: "compos_aidl_interface",
+ unstable: true,
+ srcs: [
+ "com/android/compos/*.aidl",
+ ],
+ backend: {
+ rust: {
+ enabled: true,
+ },
+ },
+}
diff --git a/compos/aidl/com/android/compos/ICompService.aidl b/compos/aidl/com/android/compos/ICompService.aidl
new file mode 100644
index 0000000..0e18442
--- /dev/null
+++ b/compos/aidl/com/android/compos/ICompService.aidl
@@ -0,0 +1,35 @@
+/*
+ * Copyright (C) 2021 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package com.android.compos;
+
+import com.android.compos.Metadata;
+
+/** {@hide} */
+interface ICompService {
+ /**
+ * Execute a command composed of the args, in a context that may be specified in the Metadata,
+ * e.g. with file descriptors pre-opened. The service is responsible to decide what executables
+ * it may run.
+ *
+ * @param args The command line arguments to run. The 0-th args is normally the program name,
+ * which may not be used by the service. The service may be configured to always use
+ * a fixed executable, or possibly use the 0-th args are the executable lookup hint.
+ * @param metadata Additional information of the execution
+ * @return exit code of the program
+ */
+ byte execute(in String[] args, in Metadata metadata);
+}
diff --git a/compos/aidl/com/android/compos/InputFdAnnotation.aidl b/compos/aidl/com/android/compos/InputFdAnnotation.aidl
new file mode 100644
index 0000000..44a5591
--- /dev/null
+++ b/compos/aidl/com/android/compos/InputFdAnnotation.aidl
@@ -0,0 +1,29 @@
+/*
+ * Copyright (C) 2021 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package com.android.compos;
+
+/** {@hide} */
+parcelable InputFdAnnotation {
+ /**
+ * File descriptor number to be passed to the program. This is also the same file descriptor
+ * number used in the backend server.
+ */
+ int fd;
+
+ /** The actual file size in bytes of the backing file to be read. */
+ long file_size;
+}
diff --git a/compos/aidl/com/android/compos/Metadata.aidl b/compos/aidl/com/android/compos/Metadata.aidl
new file mode 100644
index 0000000..a15214d
--- /dev/null
+++ b/compos/aidl/com/android/compos/Metadata.aidl
@@ -0,0 +1,26 @@
+/*
+ * Copyright (C) 2021 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package com.android.compos;
+
+import com.android.compos.InputFdAnnotation;
+import com.android.compos.OutputFdAnnotation;
+
+/** {@hide} */
+parcelable Metadata {
+ InputFdAnnotation[] input_fd_annotations;
+ OutputFdAnnotation[] output_fd_annotations;
+}
diff --git a/compos/aidl/com/android/compos/OutputFdAnnotation.aidl b/compos/aidl/com/android/compos/OutputFdAnnotation.aidl
new file mode 100644
index 0000000..95ce425
--- /dev/null
+++ b/compos/aidl/com/android/compos/OutputFdAnnotation.aidl
@@ -0,0 +1,26 @@
+/*
+ * Copyright (C) 2021 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package com.android.compos;
+
+/** {@hide} */
+parcelable OutputFdAnnotation {
+ /**
+ * File descriptor number to be passed to the program. This is currently assumed to be same as
+ * the file descriptor number used in the backend server.
+ */
+ int fd;
+}