Robert Sesek | 8f8d187 | 2016-03-18 16:52:57 -0400 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2016 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.os; |
| 18 | |
Sudheer Shanka | d81b1d7 | 2018-09-05 16:37:30 -0700 | [diff] [blame] | 19 | import android.annotation.NonNull; |
| 20 | import android.annotation.Nullable; |
Martijn Coenen | 7e6fa67 | 2018-11-05 11:45:26 +0100 | [diff] [blame] | 21 | import android.content.pm.ApplicationInfo; |
Robert Sesek | 8f8d187 | 2016-03-18 16:52:57 -0400 | [diff] [blame] | 22 | import android.net.LocalSocket; |
| 23 | import android.net.LocalSocketAddress; |
Mathieu Chartier | 0bccbf7 | 2019-01-30 15:56:17 -0800 | [diff] [blame] | 24 | import android.provider.DeviceConfig; |
Robert Sesek | 8f8d187 | 2016-03-18 16:52:57 -0400 | [diff] [blame] | 25 | import android.util.Log; |
Gustav Sennton | f0c52b5 | 2017-04-27 17:00:50 +0100 | [diff] [blame] | 26 | import android.util.Slog; |
Nicolas Geoffray | 81edac4 | 2017-09-07 14:13:29 +0100 | [diff] [blame] | 27 | |
Robert Sesek | ded2098 | 2016-08-15 13:59:13 -0400 | [diff] [blame] | 28 | import com.android.internal.annotations.GuardedBy; |
Robert Sesek | 8f8d187 | 2016-03-18 16:52:57 -0400 | [diff] [blame] | 29 | import com.android.internal.os.Zygote; |
Nicolas Geoffray | 81edac4 | 2017-09-07 14:13:29 +0100 | [diff] [blame] | 30 | |
Robert Sesek | 8f8d187 | 2016-03-18 16:52:57 -0400 | [diff] [blame] | 31 | import java.io.BufferedWriter; |
| 32 | import java.io.DataInputStream; |
| 33 | import java.io.IOException; |
| 34 | import java.io.OutputStreamWriter; |
| 35 | import java.nio.charset.StandardCharsets; |
| 36 | import java.util.ArrayList; |
| 37 | import java.util.Arrays; |
Martijn Coenen | 7e6fa67 | 2018-11-05 11:45:26 +0100 | [diff] [blame] | 38 | import java.util.Base64; |
Mathew Inwood | 8faeab8 | 2018-03-16 14:26:08 +0000 | [diff] [blame] | 39 | import java.util.Collections; |
Robert Sesek | 8f8d187 | 2016-03-18 16:52:57 -0400 | [diff] [blame] | 40 | import java.util.List; |
Robert Sesek | d0a190df | 2018-02-12 18:46:01 -0500 | [diff] [blame] | 41 | import java.util.UUID; |
Robert Sesek | 8f8d187 | 2016-03-18 16:52:57 -0400 | [diff] [blame] | 42 | |
| 43 | /*package*/ class ZygoteStartFailedEx extends Exception { |
| 44 | ZygoteStartFailedEx(String s) { |
| 45 | super(s); |
| 46 | } |
| 47 | |
| 48 | ZygoteStartFailedEx(Throwable cause) { |
| 49 | super(cause); |
| 50 | } |
| 51 | |
| 52 | ZygoteStartFailedEx(String s, Throwable cause) { |
| 53 | super(s, cause); |
| 54 | } |
| 55 | } |
| 56 | |
| 57 | /** |
| 58 | * Maintains communication state with the zygote processes. This class is responsible |
| 59 | * for the sockets opened to the zygotes and for starting processes on behalf of the |
| 60 | * {@link android.os.Process} class. |
| 61 | * |
| 62 | * {@hide} |
| 63 | */ |
| 64 | public class ZygoteProcess { |
Chris Wailes | efce929 | 2019-01-11 13:19:20 -0800 | [diff] [blame] | 65 | |
| 66 | /** |
| 67 | * @hide for internal use only. |
| 68 | */ |
Martijn Coenen | 82dc85a | 2019-01-28 13:12:28 +0100 | [diff] [blame] | 69 | public static final int ZYGOTE_CONNECT_TIMEOUT_MS = 20000; |
| 70 | |
| 71 | /** |
| 72 | * @hide for internal use only. |
| 73 | * |
| 74 | * Use a relatively short delay, because for app zygote, this is in the critical path of |
| 75 | * service launch. |
| 76 | */ |
| 77 | public static final int ZYGOTE_CONNECT_RETRY_DELAY_MS = 50; |
| 78 | |
| 79 | /** |
Chris Wailes | efce929 | 2019-01-11 13:19:20 -0800 | [diff] [blame] | 80 | * @hide for internal use only |
| 81 | */ |
Robert Sesek | 8f8d187 | 2016-03-18 16:52:57 -0400 | [diff] [blame] | 82 | private static final String LOG_TAG = "ZygoteProcess"; |
| 83 | |
| 84 | /** |
Chris Wailes | 7e797b6 | 2019-02-22 18:29:22 -0800 | [diff] [blame] | 85 | * The default value for enabling the unspecialized app process (USAP) pool. |
Mathieu Chartier | 0bccbf7 | 2019-01-30 15:56:17 -0800 | [diff] [blame] | 86 | */ |
Chris Wailes | 7e797b6 | 2019-02-22 18:29:22 -0800 | [diff] [blame] | 87 | private static final String USAP_POOL_ENABLED_DEFAULT = "false"; |
Mathieu Chartier | 0bccbf7 | 2019-01-30 15:56:17 -0800 | [diff] [blame] | 88 | |
| 89 | /** |
Robert Sesek | 8f8d187 | 2016-03-18 16:52:57 -0400 | [diff] [blame] | 90 | * The name of the socket used to communicate with the primary zygote. |
| 91 | */ |
Chris Wailes | efce929 | 2019-01-11 13:19:20 -0800 | [diff] [blame] | 92 | private final LocalSocketAddress mZygoteSocketAddress; |
Robert Sesek | 8f8d187 | 2016-03-18 16:52:57 -0400 | [diff] [blame] | 93 | |
| 94 | /** |
| 95 | * The name of the secondary (alternate ABI) zygote socket. |
| 96 | */ |
Chris Wailes | efce929 | 2019-01-11 13:19:20 -0800 | [diff] [blame] | 97 | private final LocalSocketAddress mZygoteSecondarySocketAddress; |
Mathieu Chartier | 0bccbf7 | 2019-01-30 15:56:17 -0800 | [diff] [blame] | 98 | |
Chris Wailes | ba4c2eb | 2019-01-11 17:13:00 -0800 | [diff] [blame] | 99 | /** |
Chris Wailes | 7e797b6 | 2019-02-22 18:29:22 -0800 | [diff] [blame] | 100 | * The name of the socket used to communicate with the primary USAP pool. |
Chris Wailes | ba4c2eb | 2019-01-11 17:13:00 -0800 | [diff] [blame] | 101 | */ |
Chris Wailes | 7e797b6 | 2019-02-22 18:29:22 -0800 | [diff] [blame] | 102 | private final LocalSocketAddress mUsapPoolSocketAddress; |
Chris Wailes | ba4c2eb | 2019-01-11 17:13:00 -0800 | [diff] [blame] | 103 | |
| 104 | /** |
Chris Wailes | 7e797b6 | 2019-02-22 18:29:22 -0800 | [diff] [blame] | 105 | * The name of the socket used to communicate with the secondary (alternate ABI) USAP pool. |
Chris Wailes | ba4c2eb | 2019-01-11 17:13:00 -0800 | [diff] [blame] | 106 | */ |
Chris Wailes | 7e797b6 | 2019-02-22 18:29:22 -0800 | [diff] [blame] | 107 | private final LocalSocketAddress mUsapPoolSecondarySocketAddress; |
Robert Sesek | 8f8d187 | 2016-03-18 16:52:57 -0400 | [diff] [blame] | 108 | |
Chris Wailes | efce929 | 2019-01-11 13:19:20 -0800 | [diff] [blame] | 109 | public ZygoteProcess() { |
| 110 | mZygoteSocketAddress = |
Mathieu Chartier | 0bccbf7 | 2019-01-30 15:56:17 -0800 | [diff] [blame] | 111 | new LocalSocketAddress(Zygote.PRIMARY_SOCKET_NAME, |
| 112 | LocalSocketAddress.Namespace.RESERVED); |
Chris Wailes | efce929 | 2019-01-11 13:19:20 -0800 | [diff] [blame] | 113 | mZygoteSecondarySocketAddress = |
Mathieu Chartier | 0bccbf7 | 2019-01-30 15:56:17 -0800 | [diff] [blame] | 114 | new LocalSocketAddress(Zygote.SECONDARY_SOCKET_NAME, |
Chris Wailes | efce929 | 2019-01-11 13:19:20 -0800 | [diff] [blame] | 115 | LocalSocketAddress.Namespace.RESERVED); |
Chris Wailes | ba4c2eb | 2019-01-11 17:13:00 -0800 | [diff] [blame] | 116 | |
Chris Wailes | 7e797b6 | 2019-02-22 18:29:22 -0800 | [diff] [blame] | 117 | mUsapPoolSocketAddress = |
| 118 | new LocalSocketAddress(Zygote.USAP_POOL_PRIMARY_SOCKET_NAME, |
Chris Wailes | ba4c2eb | 2019-01-11 17:13:00 -0800 | [diff] [blame] | 119 | LocalSocketAddress.Namespace.RESERVED); |
Chris Wailes | 7e797b6 | 2019-02-22 18:29:22 -0800 | [diff] [blame] | 120 | mUsapPoolSecondarySocketAddress = |
| 121 | new LocalSocketAddress(Zygote.USAP_POOL_SECONDARY_SOCKET_NAME, |
Chris Wailes | ba4c2eb | 2019-01-11 17:13:00 -0800 | [diff] [blame] | 122 | LocalSocketAddress.Namespace.RESERVED); |
Mathieu Chartier | 0bccbf7 | 2019-01-30 15:56:17 -0800 | [diff] [blame] | 123 | |
Chris Wailes | 7e797b6 | 2019-02-22 18:29:22 -0800 | [diff] [blame] | 124 | if (fetchUsapPoolEnabledProp()) { |
| 125 | informZygotesOfUsapPoolStatus(); |
Chris Wailes | db132a3 | 2019-02-20 10:49:27 -0800 | [diff] [blame] | 126 | } |
Robert Sesek | 5ac8abf | 2018-01-26 14:26:53 -0500 | [diff] [blame] | 127 | } |
| 128 | |
Chris Wailes | efce929 | 2019-01-11 13:19:20 -0800 | [diff] [blame] | 129 | public ZygoteProcess(LocalSocketAddress primarySocketAddress, |
| 130 | LocalSocketAddress secondarySocketAddress) { |
| 131 | mZygoteSocketAddress = primarySocketAddress; |
| 132 | mZygoteSecondarySocketAddress = secondarySocketAddress; |
Chris Wailes | ba4c2eb | 2019-01-11 17:13:00 -0800 | [diff] [blame] | 133 | |
Chris Wailes | 7e797b6 | 2019-02-22 18:29:22 -0800 | [diff] [blame] | 134 | mUsapPoolSocketAddress = null; |
| 135 | mUsapPoolSecondarySocketAddress = null; |
Robert Sesek | 8f8d187 | 2016-03-18 16:52:57 -0400 | [diff] [blame] | 136 | } |
| 137 | |
Robert Sesek | 5ac8abf | 2018-01-26 14:26:53 -0500 | [diff] [blame] | 138 | public LocalSocketAddress getPrimarySocketAddress() { |
Chris Wailes | efce929 | 2019-01-11 13:19:20 -0800 | [diff] [blame] | 139 | return mZygoteSocketAddress; |
Robert Sesek | 5ac8abf | 2018-01-26 14:26:53 -0500 | [diff] [blame] | 140 | } |
| 141 | |
Robert Sesek | 8f8d187 | 2016-03-18 16:52:57 -0400 | [diff] [blame] | 142 | /** |
| 143 | * State for communicating with the zygote process. |
| 144 | */ |
| 145 | public static class ZygoteState { |
Chris Wailes | efce929 | 2019-01-11 13:19:20 -0800 | [diff] [blame] | 146 | final LocalSocketAddress mZygoteSocketAddress; |
Chris Wailes | 7e797b6 | 2019-02-22 18:29:22 -0800 | [diff] [blame] | 147 | final LocalSocketAddress mUsapSocketAddress; |
Robert Sesek | 8f8d187 | 2016-03-18 16:52:57 -0400 | [diff] [blame] | 148 | |
Chris Wailes | efce929 | 2019-01-11 13:19:20 -0800 | [diff] [blame] | 149 | private final LocalSocket mZygoteSessionSocket; |
Robert Sesek | 8f8d187 | 2016-03-18 16:52:57 -0400 | [diff] [blame] | 150 | |
Chris Wailes | efce929 | 2019-01-11 13:19:20 -0800 | [diff] [blame] | 151 | final DataInputStream mZygoteInputStream; |
| 152 | final BufferedWriter mZygoteOutputWriter; |
| 153 | |
| 154 | private final List<String> mABIList; |
| 155 | |
| 156 | private boolean mClosed; |
| 157 | |
| 158 | private ZygoteState(LocalSocketAddress zygoteSocketAddress, |
Chris Wailes | 7e797b6 | 2019-02-22 18:29:22 -0800 | [diff] [blame] | 159 | LocalSocketAddress usapSocketAddress, |
Chris Wailes | efce929 | 2019-01-11 13:19:20 -0800 | [diff] [blame] | 160 | LocalSocket zygoteSessionSocket, |
| 161 | DataInputStream zygoteInputStream, |
| 162 | BufferedWriter zygoteOutputWriter, |
| 163 | List<String> abiList) { |
| 164 | this.mZygoteSocketAddress = zygoteSocketAddress; |
Chris Wailes | 7e797b6 | 2019-02-22 18:29:22 -0800 | [diff] [blame] | 165 | this.mUsapSocketAddress = usapSocketAddress; |
Chris Wailes | efce929 | 2019-01-11 13:19:20 -0800 | [diff] [blame] | 166 | this.mZygoteSessionSocket = zygoteSessionSocket; |
| 167 | this.mZygoteInputStream = zygoteInputStream; |
| 168 | this.mZygoteOutputWriter = zygoteOutputWriter; |
| 169 | this.mABIList = abiList; |
Robert Sesek | 8f8d187 | 2016-03-18 16:52:57 -0400 | [diff] [blame] | 170 | } |
| 171 | |
Chris Wailes | efce929 | 2019-01-11 13:19:20 -0800 | [diff] [blame] | 172 | /** |
Chris Wailes | ba4c2eb | 2019-01-11 17:13:00 -0800 | [diff] [blame] | 173 | * Create a new ZygoteState object by connecting to the given Zygote socket and saving the |
Chris Wailes | 7e797b6 | 2019-02-22 18:29:22 -0800 | [diff] [blame] | 174 | * given USAP socket address. |
Chris Wailes | efce929 | 2019-01-11 13:19:20 -0800 | [diff] [blame] | 175 | * |
| 176 | * @param zygoteSocketAddress Zygote socket to connect to |
Chris Wailes | 7e797b6 | 2019-02-22 18:29:22 -0800 | [diff] [blame] | 177 | * @param usapSocketAddress USAP socket address to save for later |
Chris Wailes | efce929 | 2019-01-11 13:19:20 -0800 | [diff] [blame] | 178 | * @return A new ZygoteState object containing a session socket for the given Zygote socket |
| 179 | * address |
| 180 | * @throws IOException |
| 181 | */ |
Chris Wailes | ba4c2eb | 2019-01-11 17:13:00 -0800 | [diff] [blame] | 182 | public static ZygoteState connect(LocalSocketAddress zygoteSocketAddress, |
Chris Wailes | 7e797b6 | 2019-02-22 18:29:22 -0800 | [diff] [blame] | 183 | LocalSocketAddress usapSocketAddress) |
Chris Wailes | efce929 | 2019-01-11 13:19:20 -0800 | [diff] [blame] | 184 | throws IOException { |
| 185 | |
Robert Sesek | 8f8d187 | 2016-03-18 16:52:57 -0400 | [diff] [blame] | 186 | DataInputStream zygoteInputStream = null; |
Chris Wailes | efce929 | 2019-01-11 13:19:20 -0800 | [diff] [blame] | 187 | BufferedWriter zygoteOutputWriter = null; |
| 188 | final LocalSocket zygoteSessionSocket = new LocalSocket(); |
Robert Sesek | 8f8d187 | 2016-03-18 16:52:57 -0400 | [diff] [blame] | 189 | |
| 190 | try { |
Chris Wailes | efce929 | 2019-01-11 13:19:20 -0800 | [diff] [blame] | 191 | zygoteSessionSocket.connect(zygoteSocketAddress); |
| 192 | zygoteInputStream = new DataInputStream(zygoteSessionSocket.getInputStream()); |
| 193 | zygoteOutputWriter = |
| 194 | new BufferedWriter( |
| 195 | new OutputStreamWriter(zygoteSessionSocket.getOutputStream()), |
Chris Wailes | ba4c2eb | 2019-01-11 17:13:00 -0800 | [diff] [blame] | 196 | Zygote.SOCKET_BUFFER_SIZE); |
Robert Sesek | 8f8d187 | 2016-03-18 16:52:57 -0400 | [diff] [blame] | 197 | } catch (IOException ex) { |
| 198 | try { |
Chris Wailes | efce929 | 2019-01-11 13:19:20 -0800 | [diff] [blame] | 199 | zygoteSessionSocket.close(); |
| 200 | } catch (IOException ignore) { } |
Robert Sesek | 8f8d187 | 2016-03-18 16:52:57 -0400 | [diff] [blame] | 201 | |
| 202 | throw ex; |
| 203 | } |
| 204 | |
Chris Wailes | 7e797b6 | 2019-02-22 18:29:22 -0800 | [diff] [blame] | 205 | return new ZygoteState(zygoteSocketAddress, usapSocketAddress, |
Chris Wailes | efce929 | 2019-01-11 13:19:20 -0800 | [diff] [blame] | 206 | zygoteSessionSocket, zygoteInputStream, zygoteOutputWriter, |
| 207 | getAbiList(zygoteOutputWriter, zygoteInputStream)); |
Robert Sesek | 8f8d187 | 2016-03-18 16:52:57 -0400 | [diff] [blame] | 208 | } |
| 209 | |
Chris Wailes | 7e797b6 | 2019-02-22 18:29:22 -0800 | [diff] [blame] | 210 | LocalSocket getUsapSessionSocket() throws IOException { |
| 211 | final LocalSocket usapSessionSocket = new LocalSocket(); |
| 212 | usapSessionSocket.connect(this.mUsapSocketAddress); |
Chris Wailes | ba4c2eb | 2019-01-11 17:13:00 -0800 | [diff] [blame] | 213 | |
Chris Wailes | 7e797b6 | 2019-02-22 18:29:22 -0800 | [diff] [blame] | 214 | return usapSessionSocket; |
Chris Wailes | ba4c2eb | 2019-01-11 17:13:00 -0800 | [diff] [blame] | 215 | } |
| 216 | |
Robert Sesek | 8f8d187 | 2016-03-18 16:52:57 -0400 | [diff] [blame] | 217 | boolean matches(String abi) { |
Chris Wailes | efce929 | 2019-01-11 13:19:20 -0800 | [diff] [blame] | 218 | return mABIList.contains(abi); |
Robert Sesek | 8f8d187 | 2016-03-18 16:52:57 -0400 | [diff] [blame] | 219 | } |
| 220 | |
| 221 | public void close() { |
| 222 | try { |
Chris Wailes | efce929 | 2019-01-11 13:19:20 -0800 | [diff] [blame] | 223 | mZygoteSessionSocket.close(); |
Robert Sesek | 8f8d187 | 2016-03-18 16:52:57 -0400 | [diff] [blame] | 224 | } catch (IOException ex) { |
| 225 | Log.e(LOG_TAG,"I/O exception on routine close", ex); |
| 226 | } |
| 227 | |
| 228 | mClosed = true; |
| 229 | } |
| 230 | |
| 231 | boolean isClosed() { |
| 232 | return mClosed; |
| 233 | } |
| 234 | } |
| 235 | |
| 236 | /** |
Robert Sesek | ded2098 | 2016-08-15 13:59:13 -0400 | [diff] [blame] | 237 | * Lock object to protect access to the two ZygoteStates below. This lock must be |
| 238 | * acquired while communicating over the ZygoteState's socket, to prevent |
| 239 | * interleaved access. |
| 240 | */ |
| 241 | private final Object mLock = new Object(); |
| 242 | |
| 243 | /** |
Mathew Inwood | 8faeab8 | 2018-03-16 14:26:08 +0000 | [diff] [blame] | 244 | * List of exemptions to the API blacklist. These are prefix matches on the runtime format |
| 245 | * symbol signature. Any matching symbol is treated by the runtime as being on the light grey |
| 246 | * list. |
| 247 | */ |
| 248 | private List<String> mApiBlacklistExemptions = Collections.emptyList(); |
| 249 | |
| 250 | /** |
Mathew Inwood | 04194fe | 2018-04-04 14:48:03 +0100 | [diff] [blame] | 251 | * Proportion of hidden API accesses that should be logged to the event log; 0 - 0x10000. |
| 252 | */ |
| 253 | private int mHiddenApiAccessLogSampleRate; |
| 254 | |
| 255 | /** |
Andrei Onea | e8e150d | 2019-02-18 18:27:11 +0000 | [diff] [blame] | 256 | * Proportion of hidden API accesses that should be logged to statslog; 0 - 0x10000. |
| 257 | */ |
| 258 | private int mHiddenApiAccessStatslogSampleRate; |
| 259 | |
| 260 | /** |
Robert Sesek | 8f8d187 | 2016-03-18 16:52:57 -0400 | [diff] [blame] | 261 | * The state of the connection to the primary zygote. |
| 262 | */ |
| 263 | private ZygoteState primaryZygoteState; |
| 264 | |
| 265 | /** |
| 266 | * The state of the connection to the secondary zygote. |
| 267 | */ |
| 268 | private ZygoteState secondaryZygoteState; |
| 269 | |
| 270 | /** |
Chris Wailes | 7e797b6 | 2019-02-22 18:29:22 -0800 | [diff] [blame] | 271 | * If the USAP pool should be created and used to start applications. |
Mathieu Chartier | 0bccbf7 | 2019-01-30 15:56:17 -0800 | [diff] [blame] | 272 | * |
Chris Wailes | 7e797b6 | 2019-02-22 18:29:22 -0800 | [diff] [blame] | 273 | * Setting this value to false will disable the creation, maintenance, and use of the USAP |
| 274 | * pool. When the USAP pool is disabled the application lifecycle will be identical to |
Mathieu Chartier | 0bccbf7 | 2019-01-30 15:56:17 -0800 | [diff] [blame] | 275 | * previous versions of Android. |
| 276 | */ |
Chris Wailes | 7e797b6 | 2019-02-22 18:29:22 -0800 | [diff] [blame] | 277 | private boolean mUsapPoolEnabled = false; |
Mathieu Chartier | 0bccbf7 | 2019-01-30 15:56:17 -0800 | [diff] [blame] | 278 | |
| 279 | /** |
Robert Sesek | 8f8d187 | 2016-03-18 16:52:57 -0400 | [diff] [blame] | 280 | * Start a new process. |
| 281 | * |
| 282 | * <p>If processes are enabled, a new process is created and the |
| 283 | * static main() function of a <var>processClass</var> is executed there. |
| 284 | * The process will continue running after this function returns. |
| 285 | * |
| 286 | * <p>If processes are not enabled, a new thread in the caller's |
Mathew Inwood | 8faeab8 | 2018-03-16 14:26:08 +0000 | [diff] [blame] | 287 | * process is created and main() of <var>processclass</var> called there. |
Robert Sesek | 8f8d187 | 2016-03-18 16:52:57 -0400 | [diff] [blame] | 288 | * |
| 289 | * <p>The niceName parameter, if not an empty string, is a custom name to |
| 290 | * give to the process instead of using processClass. This allows you to |
| 291 | * make easily identifyable processes even if you are using the same base |
| 292 | * <var>processClass</var> to start them. |
| 293 | * |
Tamas Berghammer | b8f7c35 | 2016-11-11 16:08:26 +0000 | [diff] [blame] | 294 | * When invokeWith is not null, the process will be started as a fresh app |
Tamas Berghammer | 0ca16fa | 2016-11-11 16:08:26 +0000 | [diff] [blame] | 295 | * and not a zygote fork. Note that this is only allowed for uid 0 or when |
Nicolas Geoffray | 81edac4 | 2017-09-07 14:13:29 +0100 | [diff] [blame] | 296 | * runtimeFlags contains DEBUG_ENABLE_DEBUGGER. |
Tamas Berghammer | b8f7c35 | 2016-11-11 16:08:26 +0000 | [diff] [blame] | 297 | * |
Robert Sesek | 8f8d187 | 2016-03-18 16:52:57 -0400 | [diff] [blame] | 298 | * @param processClass The class to use as the process's main entry |
| 299 | * point. |
| 300 | * @param niceName A more readable name to use for the process. |
| 301 | * @param uid The user-id under which the process will run. |
| 302 | * @param gid The group-id under which the process will run. |
| 303 | * @param gids Additional group-ids associated with the process. |
Nicolas Geoffray | 81edac4 | 2017-09-07 14:13:29 +0100 | [diff] [blame] | 304 | * @param runtimeFlags Additional flags. |
Robert Sesek | 8f8d187 | 2016-03-18 16:52:57 -0400 | [diff] [blame] | 305 | * @param targetSdkVersion The target SDK version for the app. |
| 306 | * @param seInfo null-ok SELinux information for the new process. |
| 307 | * @param abi non-null the ABI this app should be started with. |
| 308 | * @param instructionSet null-ok the instruction set to use. |
| 309 | * @param appDataDir null-ok the data directory of the app. |
Tamas Berghammer | b8f7c35 | 2016-11-11 16:08:26 +0000 | [diff] [blame] | 310 | * @param invokeWith null-ok the command to invoke with. |
Sudheer Shanka | d81b1d7 | 2018-09-05 16:37:30 -0700 | [diff] [blame] | 311 | * @param packageName null-ok the name of the package this process belongs to. |
Sudheer Shanka | 3f0645b | 2018-09-18 13:07:59 -0700 | [diff] [blame] | 312 | * @param packagesForUid null-ok all the packages with the same uid as this process. |
Robert Sesek | 8f8d187 | 2016-03-18 16:52:57 -0400 | [diff] [blame] | 313 | * @param zygoteArgs Additional arguments to supply to the zygote process. |
| 314 | * |
| 315 | * @return An object that describes the result of the attempt to start the process. |
| 316 | * @throws RuntimeException on fatal start failure |
| 317 | */ |
Sudheer Shanka | d81b1d7 | 2018-09-05 16:37:30 -0700 | [diff] [blame] | 318 | public final Process.ProcessStartResult start(@NonNull final String processClass, |
Robert Sesek | 8f8d187 | 2016-03-18 16:52:57 -0400 | [diff] [blame] | 319 | final String niceName, |
Sudheer Shanka | d81b1d7 | 2018-09-05 16:37:30 -0700 | [diff] [blame] | 320 | int uid, int gid, @Nullable int[] gids, |
Nicolas Geoffray | 81edac4 | 2017-09-07 14:13:29 +0100 | [diff] [blame] | 321 | int runtimeFlags, int mountExternal, |
Robert Sesek | 8f8d187 | 2016-03-18 16:52:57 -0400 | [diff] [blame] | 322 | int targetSdkVersion, |
Sudheer Shanka | d81b1d7 | 2018-09-05 16:37:30 -0700 | [diff] [blame] | 323 | @Nullable String seInfo, |
| 324 | @NonNull String abi, |
| 325 | @Nullable String instructionSet, |
| 326 | @Nullable String appDataDir, |
| 327 | @Nullable String invokeWith, |
| 328 | @Nullable String packageName, |
Sudheer Shanka | 3f0645b | 2018-09-18 13:07:59 -0700 | [diff] [blame] | 329 | @Nullable String[] packagesForUid, |
Sudheer Shanka | 03fd40b | 2019-02-06 12:39:14 -0800 | [diff] [blame] | 330 | @Nullable String sandboxId, |
Chris Wailes | 7e797b6 | 2019-02-22 18:29:22 -0800 | [diff] [blame] | 331 | boolean useUsapPool, |
Sudheer Shanka | d81b1d7 | 2018-09-05 16:37:30 -0700 | [diff] [blame] | 332 | @Nullable String[] zygoteArgs) { |
Chris Wailes | db132a3 | 2019-02-20 10:49:27 -0800 | [diff] [blame] | 333 | // TODO (chriswailes): Is there a better place to check this value? |
Chris Wailes | 7e797b6 | 2019-02-22 18:29:22 -0800 | [diff] [blame] | 334 | if (fetchUsapPoolEnabledPropWithMinInterval()) { |
| 335 | informZygotesOfUsapPoolStatus(); |
Mathieu Chartier | 0bccbf7 | 2019-01-30 15:56:17 -0800 | [diff] [blame] | 336 | } |
| 337 | |
Robert Sesek | 8f8d187 | 2016-03-18 16:52:57 -0400 | [diff] [blame] | 338 | try { |
| 339 | return startViaZygote(processClass, niceName, uid, gid, gids, |
Nicolas Geoffray | 81edac4 | 2017-09-07 14:13:29 +0100 | [diff] [blame] | 340 | runtimeFlags, mountExternal, targetSdkVersion, seInfo, |
Chris Wailes | efce929 | 2019-01-11 13:19:20 -0800 | [diff] [blame] | 341 | abi, instructionSet, appDataDir, invokeWith, /*startChildZygote=*/false, |
Sudheer Shanka | e51005d | 2019-02-24 10:24:09 -0800 | [diff] [blame] | 342 | packageName, packagesForUid, sandboxId, |
Chris Wailes | 7e797b6 | 2019-02-22 18:29:22 -0800 | [diff] [blame] | 343 | useUsapPool, zygoteArgs); |
Robert Sesek | 8f8d187 | 2016-03-18 16:52:57 -0400 | [diff] [blame] | 344 | } catch (ZygoteStartFailedEx ex) { |
| 345 | Log.e(LOG_TAG, |
| 346 | "Starting VM process through Zygote failed"); |
| 347 | throw new RuntimeException( |
| 348 | "Starting VM process through Zygote failed", ex); |
| 349 | } |
| 350 | } |
| 351 | |
| 352 | /** retry interval for opening a zygote socket */ |
| 353 | static final int ZYGOTE_RETRY_MILLIS = 500; |
| 354 | |
| 355 | /** |
| 356 | * Queries the zygote for the list of ABIS it supports. |
| 357 | * |
| 358 | * @throws ZygoteStartFailedEx if the query failed. |
| 359 | */ |
Robert Sesek | ded2098 | 2016-08-15 13:59:13 -0400 | [diff] [blame] | 360 | @GuardedBy("mLock") |
Chris Wailes | efce929 | 2019-01-11 13:19:20 -0800 | [diff] [blame] | 361 | private static List<String> getAbiList(BufferedWriter writer, DataInputStream inputStream) |
Robert Sesek | 8f8d187 | 2016-03-18 16:52:57 -0400 | [diff] [blame] | 362 | throws IOException { |
| 363 | // Each query starts with the argument count (1 in this case) |
| 364 | writer.write("1"); |
| 365 | // ... followed by a new-line. |
| 366 | writer.newLine(); |
| 367 | // ... followed by our only argument. |
| 368 | writer.write("--query-abi-list"); |
| 369 | writer.newLine(); |
| 370 | writer.flush(); |
| 371 | |
| 372 | // The response is a length prefixed stream of ASCII bytes. |
| 373 | int numBytes = inputStream.readInt(); |
| 374 | byte[] bytes = new byte[numBytes]; |
| 375 | inputStream.readFully(bytes); |
| 376 | |
Chris Wailes | efce929 | 2019-01-11 13:19:20 -0800 | [diff] [blame] | 377 | String rawList = new String(bytes, StandardCharsets.US_ASCII); |
| 378 | |
| 379 | return Arrays.asList(rawList.split(",")); |
Robert Sesek | 8f8d187 | 2016-03-18 16:52:57 -0400 | [diff] [blame] | 380 | } |
| 381 | |
| 382 | /** |
| 383 | * Sends an argument list to the zygote process, which starts a new child |
| 384 | * and returns the child's pid. Please note: the present implementation |
| 385 | * replaces newlines in the argument list with spaces. |
| 386 | * |
| 387 | * @throws ZygoteStartFailedEx if process start failed for any reason |
| 388 | */ |
Robert Sesek | ded2098 | 2016-08-15 13:59:13 -0400 | [diff] [blame] | 389 | @GuardedBy("mLock") |
Chris Wailes | db132a3 | 2019-02-20 10:49:27 -0800 | [diff] [blame] | 390 | private Process.ProcessStartResult zygoteSendArgsAndGetResult( |
Chris Wailes | 7e797b6 | 2019-02-22 18:29:22 -0800 | [diff] [blame] | 391 | ZygoteState zygoteState, boolean useUsapPool, ArrayList<String> args) |
Robert Sesek | 8f8d187 | 2016-03-18 16:52:57 -0400 | [diff] [blame] | 392 | throws ZygoteStartFailedEx { |
Chris Wailes | ba4c2eb | 2019-01-11 17:13:00 -0800 | [diff] [blame] | 393 | // Throw early if any of the arguments are malformed. This means we can |
| 394 | // avoid writing a partial response to the zygote. |
| 395 | for (String arg : args) { |
| 396 | if (arg.indexOf('\n') >= 0) { |
| 397 | throw new ZygoteStartFailedEx("embedded newlines not allowed"); |
| 398 | } |
| 399 | } |
| 400 | |
Chris Wailes | b13bfc5 | 2019-02-20 11:19:48 -0800 | [diff] [blame] | 401 | /* |
| 402 | * See com.android.internal.os.ZygoteArguments.parseArgs() |
Chris Wailes | ba4c2eb | 2019-01-11 17:13:00 -0800 | [diff] [blame] | 403 | * Presently the wire format to the zygote process is: |
| 404 | * a) a count of arguments (argc, in essence) |
| 405 | * b) a number of newline-separated argument strings equal to count |
| 406 | * |
| 407 | * After the zygote process reads these it will write the pid of |
| 408 | * the child or -1 on failure, followed by boolean to |
| 409 | * indicate whether a wrapper process was used. |
| 410 | */ |
| 411 | String msgStr = Integer.toString(args.size()) + "\n" |
| 412 | + String.join("\n", args) + "\n"; |
| 413 | |
| 414 | // Should there be a timeout on this? |
| 415 | Process.ProcessStartResult result = new Process.ProcessStartResult(); |
| 416 | |
| 417 | // TODO (chriswailes): Move branch body into separate function. |
Chris Wailes | 7e797b6 | 2019-02-22 18:29:22 -0800 | [diff] [blame] | 418 | if (useUsapPool && mUsapPoolEnabled && isValidUsapCommand(args)) { |
| 419 | LocalSocket usapSessionSocket = null; |
Chris Wailes | ba4c2eb | 2019-01-11 17:13:00 -0800 | [diff] [blame] | 420 | |
| 421 | try { |
Chris Wailes | 7e797b6 | 2019-02-22 18:29:22 -0800 | [diff] [blame] | 422 | usapSessionSocket = zygoteState.getUsapSessionSocket(); |
Chris Wailes | ba4c2eb | 2019-01-11 17:13:00 -0800 | [diff] [blame] | 423 | |
Chris Wailes | 7e797b6 | 2019-02-22 18:29:22 -0800 | [diff] [blame] | 424 | final BufferedWriter usapWriter = |
Chris Wailes | ba4c2eb | 2019-01-11 17:13:00 -0800 | [diff] [blame] | 425 | new BufferedWriter( |
Chris Wailes | 7e797b6 | 2019-02-22 18:29:22 -0800 | [diff] [blame] | 426 | new OutputStreamWriter(usapSessionSocket.getOutputStream()), |
Chris Wailes | ba4c2eb | 2019-01-11 17:13:00 -0800 | [diff] [blame] | 427 | Zygote.SOCKET_BUFFER_SIZE); |
Chris Wailes | 7e797b6 | 2019-02-22 18:29:22 -0800 | [diff] [blame] | 428 | final DataInputStream usapReader = |
| 429 | new DataInputStream(usapSessionSocket.getInputStream()); |
Chris Wailes | ba4c2eb | 2019-01-11 17:13:00 -0800 | [diff] [blame] | 430 | |
Chris Wailes | 7e797b6 | 2019-02-22 18:29:22 -0800 | [diff] [blame] | 431 | usapWriter.write(msgStr); |
| 432 | usapWriter.flush(); |
Chris Wailes | ba4c2eb | 2019-01-11 17:13:00 -0800 | [diff] [blame] | 433 | |
Chris Wailes | 7e797b6 | 2019-02-22 18:29:22 -0800 | [diff] [blame] | 434 | result.pid = usapReader.readInt(); |
| 435 | // USAPs can't be used to spawn processes that need wrappers. |
Chris Wailes | ba4c2eb | 2019-01-11 17:13:00 -0800 | [diff] [blame] | 436 | result.usingWrapper = false; |
| 437 | |
| 438 | if (result.pid < 0) { |
Chris Wailes | 7e797b6 | 2019-02-22 18:29:22 -0800 | [diff] [blame] | 439 | throw new ZygoteStartFailedEx("USAP specialization failed"); |
Chris Wailes | ba4c2eb | 2019-01-11 17:13:00 -0800 | [diff] [blame] | 440 | } |
| 441 | |
| 442 | return result; |
| 443 | } catch (IOException ex) { |
Chris Wailes | 7e797b6 | 2019-02-22 18:29:22 -0800 | [diff] [blame] | 444 | // If there was an IOException using the USAP pool we will log the error and |
Chris Wailes | ba4c2eb | 2019-01-11 17:13:00 -0800 | [diff] [blame] | 445 | // attempt to start the process through the Zygote. |
Chris Wailes | 7e797b6 | 2019-02-22 18:29:22 -0800 | [diff] [blame] | 446 | Log.e(LOG_TAG, "IO Exception while communicating with USAP pool - " |
Chris Wailes | ae93714 | 2019-01-24 12:57:33 -0800 | [diff] [blame] | 447 | + ex.getMessage()); |
Chris Wailes | ba4c2eb | 2019-01-11 17:13:00 -0800 | [diff] [blame] | 448 | } finally { |
| 449 | try { |
Chris Wailes | 7e797b6 | 2019-02-22 18:29:22 -0800 | [diff] [blame] | 450 | usapSessionSocket.close(); |
Chris Wailes | ba4c2eb | 2019-01-11 17:13:00 -0800 | [diff] [blame] | 451 | } catch (IOException ex) { |
Chris Wailes | 7e797b6 | 2019-02-22 18:29:22 -0800 | [diff] [blame] | 452 | Log.e(LOG_TAG, "Failed to close USAP session socket: " + ex.getMessage()); |
Robert Sesek | 0b58f19 | 2016-10-10 18:34:42 -0400 | [diff] [blame] | 453 | } |
| 454 | } |
Chris Wailes | ba4c2eb | 2019-01-11 17:13:00 -0800 | [diff] [blame] | 455 | } |
Robert Sesek | 0b58f19 | 2016-10-10 18:34:42 -0400 | [diff] [blame] | 456 | |
Chris Wailes | ba4c2eb | 2019-01-11 17:13:00 -0800 | [diff] [blame] | 457 | try { |
| 458 | final BufferedWriter zygoteWriter = zygoteState.mZygoteOutputWriter; |
| 459 | final DataInputStream zygoteInputStream = zygoteState.mZygoteInputStream; |
Robert Sesek | 8f8d187 | 2016-03-18 16:52:57 -0400 | [diff] [blame] | 460 | |
Chris Wailes | ba4c2eb | 2019-01-11 17:13:00 -0800 | [diff] [blame] | 461 | zygoteWriter.write(msgStr); |
| 462 | zygoteWriter.flush(); |
Robert Sesek | 0b58f19 | 2016-10-10 18:34:42 -0400 | [diff] [blame] | 463 | |
| 464 | // Always read the entire result from the input stream to avoid leaving |
| 465 | // bytes in the stream for future process starts to accidentally stumble |
| 466 | // upon. |
Chris Wailes | ba4c2eb | 2019-01-11 17:13:00 -0800 | [diff] [blame] | 467 | result.pid = zygoteInputStream.readInt(); |
| 468 | result.usingWrapper = zygoteInputStream.readBoolean(); |
Robert Sesek | 8f8d187 | 2016-03-18 16:52:57 -0400 | [diff] [blame] | 469 | } catch (IOException ex) { |
| 470 | zygoteState.close(); |
Chris Wailes | ba4c2eb | 2019-01-11 17:13:00 -0800 | [diff] [blame] | 471 | Log.e(LOG_TAG, "IO Exception while communicating with Zygote - " |
| 472 | + ex.toString()); |
Robert Sesek | 8f8d187 | 2016-03-18 16:52:57 -0400 | [diff] [blame] | 473 | throw new ZygoteStartFailedEx(ex); |
| 474 | } |
Chris Wailes | ba4c2eb | 2019-01-11 17:13:00 -0800 | [diff] [blame] | 475 | |
| 476 | if (result.pid < 0) { |
| 477 | throw new ZygoteStartFailedEx("fork() failed"); |
| 478 | } |
| 479 | |
| 480 | return result; |
| 481 | } |
| 482 | |
| 483 | /** |
Chris Wailes | 7e797b6 | 2019-02-22 18:29:22 -0800 | [diff] [blame] | 484 | * Flags that may not be passed to a USAP. |
Chris Wailes | ba4c2eb | 2019-01-11 17:13:00 -0800 | [diff] [blame] | 485 | */ |
Chris Wailes | 7e797b6 | 2019-02-22 18:29:22 -0800 | [diff] [blame] | 486 | private static final String[] INVALID_USAP_FLAGS = { |
Chris Wailes | ba4c2eb | 2019-01-11 17:13:00 -0800 | [diff] [blame] | 487 | "--query-abi-list", |
| 488 | "--get-pid", |
| 489 | "--preload-default", |
| 490 | "--preload-package", |
| 491 | "--preload-app", |
| 492 | "--start-child-zygote", |
| 493 | "--set-api-blacklist-exemptions", |
| 494 | "--hidden-api-log-sampling-rate", |
Andrei Onea | e8e150d | 2019-02-18 18:27:11 +0000 | [diff] [blame] | 495 | "--hidden-api-statslog-sampling-rate", |
Chris Wailes | ba4c2eb | 2019-01-11 17:13:00 -0800 | [diff] [blame] | 496 | "--invoke-with" |
| 497 | }; |
| 498 | |
| 499 | /** |
Chris Wailes | 7e797b6 | 2019-02-22 18:29:22 -0800 | [diff] [blame] | 500 | * Tests a command list to see if it is valid to send to a USAP. |
| 501 | * @param args Zygote/USAP command arguments |
| 502 | * @return True if the command can be passed to a USAP; false otherwise |
Chris Wailes | ba4c2eb | 2019-01-11 17:13:00 -0800 | [diff] [blame] | 503 | */ |
Chris Wailes | 7e797b6 | 2019-02-22 18:29:22 -0800 | [diff] [blame] | 504 | private static boolean isValidUsapCommand(ArrayList<String> args) { |
Chris Wailes | ba4c2eb | 2019-01-11 17:13:00 -0800 | [diff] [blame] | 505 | for (String flag : args) { |
Chris Wailes | 7e797b6 | 2019-02-22 18:29:22 -0800 | [diff] [blame] | 506 | for (String badFlag : INVALID_USAP_FLAGS) { |
Chris Wailes | ba4c2eb | 2019-01-11 17:13:00 -0800 | [diff] [blame] | 507 | if (flag.startsWith(badFlag)) { |
| 508 | return false; |
| 509 | } |
| 510 | } |
| 511 | } |
| 512 | |
| 513 | return true; |
Robert Sesek | 8f8d187 | 2016-03-18 16:52:57 -0400 | [diff] [blame] | 514 | } |
| 515 | |
| 516 | /** |
| 517 | * Starts a new process via the zygote mechanism. |
| 518 | * |
| 519 | * @param processClass Class name whose static main() to run |
| 520 | * @param niceName 'nice' process name to appear in ps |
| 521 | * @param uid a POSIX uid that the new process should setuid() to |
| 522 | * @param gid a POSIX gid that the new process shuold setgid() to |
| 523 | * @param gids null-ok; a list of supplementary group IDs that the |
| 524 | * new process should setgroup() to. |
Nicolas Geoffray | 81edac4 | 2017-09-07 14:13:29 +0100 | [diff] [blame] | 525 | * @param runtimeFlags Additional flags for the runtime. |
Robert Sesek | 8f8d187 | 2016-03-18 16:52:57 -0400 | [diff] [blame] | 526 | * @param targetSdkVersion The target SDK version for the app. |
| 527 | * @param seInfo null-ok SELinux information for the new process. |
| 528 | * @param abi the ABI the process should use. |
| 529 | * @param instructionSet null-ok the instruction set to use. |
| 530 | * @param appDataDir null-ok the data directory of the app. |
Robert Sesek | d0a190df | 2018-02-12 18:46:01 -0500 | [diff] [blame] | 531 | * @param startChildZygote Start a sub-zygote. This creates a new zygote process |
| 532 | * that has its state cloned from this zygote process. |
Sudheer Shanka | d81b1d7 | 2018-09-05 16:37:30 -0700 | [diff] [blame] | 533 | * @param packageName null-ok the name of the package this process belongs to. |
Sudheer Shanka | 3f0645b | 2018-09-18 13:07:59 -0700 | [diff] [blame] | 534 | * @param packagesForUid null-ok all the packages with the same uid as this process. |
Robert Sesek | 8f8d187 | 2016-03-18 16:52:57 -0400 | [diff] [blame] | 535 | * @param extraArgs Additional arguments to supply to the zygote process. |
| 536 | * @return An object that describes the result of the attempt to start the process. |
| 537 | * @throws ZygoteStartFailedEx if process start failed for any reason |
| 538 | */ |
Sudheer Shanka | d81b1d7 | 2018-09-05 16:37:30 -0700 | [diff] [blame] | 539 | private Process.ProcessStartResult startViaZygote(@NonNull final String processClass, |
| 540 | @Nullable final String niceName, |
Robert Sesek | 8f8d187 | 2016-03-18 16:52:57 -0400 | [diff] [blame] | 541 | final int uid, final int gid, |
Sudheer Shanka | d81b1d7 | 2018-09-05 16:37:30 -0700 | [diff] [blame] | 542 | @Nullable final int[] gids, |
Nicolas Geoffray | 81edac4 | 2017-09-07 14:13:29 +0100 | [diff] [blame] | 543 | int runtimeFlags, int mountExternal, |
Robert Sesek | 8f8d187 | 2016-03-18 16:52:57 -0400 | [diff] [blame] | 544 | int targetSdkVersion, |
Sudheer Shanka | d81b1d7 | 2018-09-05 16:37:30 -0700 | [diff] [blame] | 545 | @Nullable String seInfo, |
| 546 | @NonNull String abi, |
| 547 | @Nullable String instructionSet, |
| 548 | @Nullable String appDataDir, |
| 549 | @Nullable String invokeWith, |
Robert Sesek | d0a190df | 2018-02-12 18:46:01 -0500 | [diff] [blame] | 550 | boolean startChildZygote, |
Sudheer Shanka | d81b1d7 | 2018-09-05 16:37:30 -0700 | [diff] [blame] | 551 | @Nullable String packageName, |
Sudheer Shanka | 3f0645b | 2018-09-18 13:07:59 -0700 | [diff] [blame] | 552 | @Nullable String[] packagesForUid, |
Sudheer Shanka | 03fd40b | 2019-02-06 12:39:14 -0800 | [diff] [blame] | 553 | @Nullable String sandboxId, |
Chris Wailes | 7e797b6 | 2019-02-22 18:29:22 -0800 | [diff] [blame] | 554 | boolean useUnspecializedAppProcessPool, |
Sudheer Shanka | d81b1d7 | 2018-09-05 16:37:30 -0700 | [diff] [blame] | 555 | @Nullable String[] extraArgs) |
Robert Sesek | 8f8d187 | 2016-03-18 16:52:57 -0400 | [diff] [blame] | 556 | throws ZygoteStartFailedEx { |
Robert Sesek | ded2098 | 2016-08-15 13:59:13 -0400 | [diff] [blame] | 557 | ArrayList<String> argsForZygote = new ArrayList<String>(); |
Robert Sesek | 8f8d187 | 2016-03-18 16:52:57 -0400 | [diff] [blame] | 558 | |
Robert Sesek | ded2098 | 2016-08-15 13:59:13 -0400 | [diff] [blame] | 559 | // --runtime-args, --setuid=, --setgid=, |
| 560 | // and --setgroups= must go first |
| 561 | argsForZygote.add("--runtime-args"); |
| 562 | argsForZygote.add("--setuid=" + uid); |
| 563 | argsForZygote.add("--setgid=" + gid); |
Nicolas Geoffray | 81edac4 | 2017-09-07 14:13:29 +0100 | [diff] [blame] | 564 | argsForZygote.add("--runtime-flags=" + runtimeFlags); |
Robert Sesek | ded2098 | 2016-08-15 13:59:13 -0400 | [diff] [blame] | 565 | if (mountExternal == Zygote.MOUNT_EXTERNAL_DEFAULT) { |
| 566 | argsForZygote.add("--mount-external-default"); |
| 567 | } else if (mountExternal == Zygote.MOUNT_EXTERNAL_READ) { |
| 568 | argsForZygote.add("--mount-external-read"); |
| 569 | } else if (mountExternal == Zygote.MOUNT_EXTERNAL_WRITE) { |
| 570 | argsForZygote.add("--mount-external-write"); |
Sudheer Shanka | 98cb3f0 | 2018-08-17 16:10:29 -0700 | [diff] [blame] | 571 | } else if (mountExternal == Zygote.MOUNT_EXTERNAL_FULL) { |
| 572 | argsForZygote.add("--mount-external-full"); |
Sudheer Shanka | 3a0df3b | 2018-12-12 12:43:43 -0800 | [diff] [blame] | 573 | } else if (mountExternal == Zygote.MOUNT_EXTERNAL_INSTALLER) { |
| 574 | argsForZygote.add("--mount-external-installer"); |
Sudheer Shanka | 0b6da53 | 2019-01-09 12:06:51 -0800 | [diff] [blame] | 575 | } else if (mountExternal == Zygote.MOUNT_EXTERNAL_LEGACY) { |
| 576 | argsForZygote.add("--mount-external-legacy"); |
Robert Sesek | ded2098 | 2016-08-15 13:59:13 -0400 | [diff] [blame] | 577 | } |
Sudheer Shanka | 98cb3f0 | 2018-08-17 16:10:29 -0700 | [diff] [blame] | 578 | |
Robert Sesek | ded2098 | 2016-08-15 13:59:13 -0400 | [diff] [blame] | 579 | argsForZygote.add("--target-sdk-version=" + targetSdkVersion); |
Robert Sesek | 8f8d187 | 2016-03-18 16:52:57 -0400 | [diff] [blame] | 580 | |
Robert Sesek | ded2098 | 2016-08-15 13:59:13 -0400 | [diff] [blame] | 581 | // --setgroups is a comma-separated list |
| 582 | if (gids != null && gids.length > 0) { |
| 583 | StringBuilder sb = new StringBuilder(); |
| 584 | sb.append("--setgroups="); |
Robert Sesek | 8f8d187 | 2016-03-18 16:52:57 -0400 | [diff] [blame] | 585 | |
Robert Sesek | ded2098 | 2016-08-15 13:59:13 -0400 | [diff] [blame] | 586 | int sz = gids.length; |
| 587 | for (int i = 0; i < sz; i++) { |
| 588 | if (i != 0) { |
| 589 | sb.append(','); |
Robert Sesek | 8f8d187 | 2016-03-18 16:52:57 -0400 | [diff] [blame] | 590 | } |
Robert Sesek | ded2098 | 2016-08-15 13:59:13 -0400 | [diff] [blame] | 591 | sb.append(gids[i]); |
Robert Sesek | 8f8d187 | 2016-03-18 16:52:57 -0400 | [diff] [blame] | 592 | } |
| 593 | |
Robert Sesek | ded2098 | 2016-08-15 13:59:13 -0400 | [diff] [blame] | 594 | argsForZygote.add(sb.toString()); |
| 595 | } |
| 596 | |
| 597 | if (niceName != null) { |
| 598 | argsForZygote.add("--nice-name=" + niceName); |
| 599 | } |
| 600 | |
| 601 | if (seInfo != null) { |
| 602 | argsForZygote.add("--seinfo=" + seInfo); |
| 603 | } |
| 604 | |
| 605 | if (instructionSet != null) { |
| 606 | argsForZygote.add("--instruction-set=" + instructionSet); |
| 607 | } |
| 608 | |
| 609 | if (appDataDir != null) { |
| 610 | argsForZygote.add("--app-data-dir=" + appDataDir); |
| 611 | } |
| 612 | |
Tamas Berghammer | b8f7c35 | 2016-11-11 16:08:26 +0000 | [diff] [blame] | 613 | if (invokeWith != null) { |
| 614 | argsForZygote.add("--invoke-with"); |
| 615 | argsForZygote.add(invokeWith); |
| 616 | } |
| 617 | |
Robert Sesek | d0a190df | 2018-02-12 18:46:01 -0500 | [diff] [blame] | 618 | if (startChildZygote) { |
| 619 | argsForZygote.add("--start-child-zygote"); |
| 620 | } |
| 621 | |
Sudheer Shanka | 154fe3f | 2018-07-30 14:44:26 -0700 | [diff] [blame] | 622 | if (packageName != null) { |
| 623 | argsForZygote.add("--package-name=" + packageName); |
| 624 | } |
| 625 | |
Sudheer Shanka | 3f0645b | 2018-09-18 13:07:59 -0700 | [diff] [blame] | 626 | if (packagesForUid != null && packagesForUid.length > 0) { |
| 627 | final StringBuilder sb = new StringBuilder(); |
| 628 | sb.append("--packages-for-uid="); |
| 629 | |
Mathieu Chartier | 0bccbf7 | 2019-01-30 15:56:17 -0800 | [diff] [blame] | 630 | // TODO (chriswailes): Replace with String.join |
Sudheer Shanka | 3f0645b | 2018-09-18 13:07:59 -0700 | [diff] [blame] | 631 | for (int i = 0; i < packagesForUid.length; ++i) { |
| 632 | if (i != 0) { |
| 633 | sb.append(','); |
| 634 | } |
| 635 | sb.append(packagesForUid[i]); |
| 636 | } |
| 637 | argsForZygote.add(sb.toString()); |
| 638 | } |
| 639 | |
Sudheer Shanka | 03fd40b | 2019-02-06 12:39:14 -0800 | [diff] [blame] | 640 | if (sandboxId != null) { |
| 641 | argsForZygote.add("--sandbox-id=" + sandboxId); |
| 642 | } |
| 643 | |
Robert Sesek | ded2098 | 2016-08-15 13:59:13 -0400 | [diff] [blame] | 644 | argsForZygote.add(processClass); |
| 645 | |
| 646 | if (extraArgs != null) { |
| 647 | for (String arg : extraArgs) { |
| 648 | argsForZygote.add(arg); |
Robert Sesek | 8f8d187 | 2016-03-18 16:52:57 -0400 | [diff] [blame] | 649 | } |
Robert Sesek | ded2098 | 2016-08-15 13:59:13 -0400 | [diff] [blame] | 650 | } |
Robert Sesek | 8f8d187 | 2016-03-18 16:52:57 -0400 | [diff] [blame] | 651 | |
Robert Sesek | ded2098 | 2016-08-15 13:59:13 -0400 | [diff] [blame] | 652 | synchronized(mLock) { |
Chris Wailes | ba4c2eb | 2019-01-11 17:13:00 -0800 | [diff] [blame] | 653 | return zygoteSendArgsAndGetResult(openZygoteSocketIfNeeded(abi), |
Chris Wailes | 7e797b6 | 2019-02-22 18:29:22 -0800 | [diff] [blame] | 654 | useUnspecializedAppProcessPool, |
Chris Wailes | ba4c2eb | 2019-01-11 17:13:00 -0800 | [diff] [blame] | 655 | argsForZygote); |
Robert Sesek | 8f8d187 | 2016-03-18 16:52:57 -0400 | [diff] [blame] | 656 | } |
| 657 | } |
| 658 | |
Chris Wailes | 7e797b6 | 2019-02-22 18:29:22 -0800 | [diff] [blame] | 659 | private boolean fetchUsapPoolEnabledProp() { |
| 660 | boolean origVal = mUsapPoolEnabled; |
Mathieu Chartier | 0bccbf7 | 2019-01-30 15:56:17 -0800 | [diff] [blame] | 661 | |
| 662 | final String propertyString = |
| 663 | Zygote.getSystemProperty( |
Chris Wailes | 7e797b6 | 2019-02-22 18:29:22 -0800 | [diff] [blame] | 664 | DeviceConfig.RuntimeNative.USAP_POOL_ENABLED, |
| 665 | USAP_POOL_ENABLED_DEFAULT); |
Mathieu Chartier | 0bccbf7 | 2019-01-30 15:56:17 -0800 | [diff] [blame] | 666 | |
| 667 | if (!propertyString.isEmpty()) { |
Chris Wailes | 7e797b6 | 2019-02-22 18:29:22 -0800 | [diff] [blame] | 668 | mUsapPoolEnabled = |
Mathieu Chartier | 0bccbf7 | 2019-01-30 15:56:17 -0800 | [diff] [blame] | 669 | Zygote.getSystemPropertyBoolean( |
Chris Wailes | 7e797b6 | 2019-02-22 18:29:22 -0800 | [diff] [blame] | 670 | DeviceConfig.RuntimeNative.USAP_POOL_ENABLED, |
| 671 | Boolean.parseBoolean(USAP_POOL_ENABLED_DEFAULT)); |
Mathieu Chartier | 0bccbf7 | 2019-01-30 15:56:17 -0800 | [diff] [blame] | 672 | } |
| 673 | |
Chris Wailes | 7e797b6 | 2019-02-22 18:29:22 -0800 | [diff] [blame] | 674 | if (origVal != mUsapPoolEnabled) { |
| 675 | Log.i(LOG_TAG, "usapPoolEnabled = " + mUsapPoolEnabled); |
Chris Wailes | db132a3 | 2019-02-20 10:49:27 -0800 | [diff] [blame] | 676 | } |
| 677 | |
Chris Wailes | 7e797b6 | 2019-02-22 18:29:22 -0800 | [diff] [blame] | 678 | return origVal != mUsapPoolEnabled; |
Mathieu Chartier | 0bccbf7 | 2019-01-30 15:56:17 -0800 | [diff] [blame] | 679 | } |
| 680 | |
| 681 | private long mLastPropCheckTimestamp = 0; |
| 682 | |
Chris Wailes | 7e797b6 | 2019-02-22 18:29:22 -0800 | [diff] [blame] | 683 | private boolean fetchUsapPoolEnabledPropWithMinInterval() { |
Mathieu Chartier | 0bccbf7 | 2019-01-30 15:56:17 -0800 | [diff] [blame] | 684 | final long currentTimestamp = SystemClock.elapsedRealtime(); |
| 685 | |
| 686 | if (currentTimestamp - mLastPropCheckTimestamp >= Zygote.PROPERTY_CHECK_INTERVAL) { |
| 687 | mLastPropCheckTimestamp = currentTimestamp; |
Chris Wailes | 7e797b6 | 2019-02-22 18:29:22 -0800 | [diff] [blame] | 688 | return fetchUsapPoolEnabledProp(); |
Mathieu Chartier | 0bccbf7 | 2019-01-30 15:56:17 -0800 | [diff] [blame] | 689 | } |
| 690 | |
| 691 | return false; |
| 692 | } |
| 693 | |
Robert Sesek | 8f8d187 | 2016-03-18 16:52:57 -0400 | [diff] [blame] | 694 | /** |
Robert Sesek | d0a190df | 2018-02-12 18:46:01 -0500 | [diff] [blame] | 695 | * Closes the connections to the zygote, if they exist. |
| 696 | */ |
| 697 | public void close() { |
| 698 | if (primaryZygoteState != null) { |
| 699 | primaryZygoteState.close(); |
| 700 | } |
| 701 | if (secondaryZygoteState != null) { |
| 702 | secondaryZygoteState.close(); |
| 703 | } |
| 704 | } |
| 705 | |
| 706 | /** |
Robert Sesek | 8f8d187 | 2016-03-18 16:52:57 -0400 | [diff] [blame] | 707 | * Tries to establish a connection to the zygote that handles a given {@code abi}. Might block |
| 708 | * and retry if the zygote is unresponsive. This method is a no-op if a connection is |
| 709 | * already open. |
| 710 | */ |
| 711 | public void establishZygoteConnectionForAbi(String abi) { |
| 712 | try { |
Robert Sesek | ded2098 | 2016-08-15 13:59:13 -0400 | [diff] [blame] | 713 | synchronized(mLock) { |
| 714 | openZygoteSocketIfNeeded(abi); |
| 715 | } |
Robert Sesek | 8f8d187 | 2016-03-18 16:52:57 -0400 | [diff] [blame] | 716 | } catch (ZygoteStartFailedEx ex) { |
| 717 | throw new RuntimeException("Unable to connect to zygote for abi: " + abi, ex); |
| 718 | } |
| 719 | } |
| 720 | |
| 721 | /** |
Andreas Gampe | 8444dca | 2018-05-01 13:31:28 -0700 | [diff] [blame] | 722 | * Attempt to retrieve the PID of the zygote serving the given abi. |
| 723 | */ |
| 724 | public int getZygotePid(String abi) { |
| 725 | try { |
| 726 | synchronized (mLock) { |
| 727 | ZygoteState state = openZygoteSocketIfNeeded(abi); |
| 728 | |
| 729 | // Each query starts with the argument count (1 in this case) |
Chris Wailes | efce929 | 2019-01-11 13:19:20 -0800 | [diff] [blame] | 730 | state.mZygoteOutputWriter.write("1"); |
Andreas Gampe | 8444dca | 2018-05-01 13:31:28 -0700 | [diff] [blame] | 731 | // ... followed by a new-line. |
Chris Wailes | efce929 | 2019-01-11 13:19:20 -0800 | [diff] [blame] | 732 | state.mZygoteOutputWriter.newLine(); |
Andreas Gampe | 8444dca | 2018-05-01 13:31:28 -0700 | [diff] [blame] | 733 | // ... followed by our only argument. |
Chris Wailes | efce929 | 2019-01-11 13:19:20 -0800 | [diff] [blame] | 734 | state.mZygoteOutputWriter.write("--get-pid"); |
| 735 | state.mZygoteOutputWriter.newLine(); |
| 736 | state.mZygoteOutputWriter.flush(); |
Andreas Gampe | 8444dca | 2018-05-01 13:31:28 -0700 | [diff] [blame] | 737 | |
| 738 | // The response is a length prefixed stream of ASCII bytes. |
Chris Wailes | efce929 | 2019-01-11 13:19:20 -0800 | [diff] [blame] | 739 | int numBytes = state.mZygoteInputStream.readInt(); |
Andreas Gampe | 8444dca | 2018-05-01 13:31:28 -0700 | [diff] [blame] | 740 | byte[] bytes = new byte[numBytes]; |
Chris Wailes | efce929 | 2019-01-11 13:19:20 -0800 | [diff] [blame] | 741 | state.mZygoteInputStream.readFully(bytes); |
Andreas Gampe | 8444dca | 2018-05-01 13:31:28 -0700 | [diff] [blame] | 742 | |
| 743 | return Integer.parseInt(new String(bytes, StandardCharsets.US_ASCII)); |
| 744 | } |
| 745 | } catch (Exception ex) { |
| 746 | throw new RuntimeException("Failure retrieving pid", ex); |
| 747 | } |
| 748 | } |
| 749 | |
| 750 | /** |
Mathew Inwood | 8faeab8 | 2018-03-16 14:26:08 +0000 | [diff] [blame] | 751 | * Push hidden API blacklisting exemptions into the zygote process(es). |
| 752 | * |
| 753 | * <p>The list of exemptions will take affect for all new processes forked from the zygote after |
| 754 | * this call. |
| 755 | * |
Mathew Inwood | 33d5138 | 2018-04-05 13:56:39 +0100 | [diff] [blame] | 756 | * @param exemptions List of hidden API exemption prefixes. Any matching members are treated as |
| 757 | * whitelisted/public APIs (i.e. allowed, no logging of usage). |
Mathew Inwood | 8faeab8 | 2018-03-16 14:26:08 +0000 | [diff] [blame] | 758 | */ |
Mathew Inwood | 9f6bb5b | 2018-04-09 17:29:12 +0100 | [diff] [blame] | 759 | public boolean setApiBlacklistExemptions(List<String> exemptions) { |
Mathew Inwood | 8faeab8 | 2018-03-16 14:26:08 +0000 | [diff] [blame] | 760 | synchronized (mLock) { |
| 761 | mApiBlacklistExemptions = exemptions; |
Mathew Inwood | 9f6bb5b | 2018-04-09 17:29:12 +0100 | [diff] [blame] | 762 | boolean ok = maybeSetApiBlacklistExemptions(primaryZygoteState, true); |
| 763 | if (ok) { |
| 764 | ok = maybeSetApiBlacklistExemptions(secondaryZygoteState, true); |
| 765 | } |
| 766 | return ok; |
Mathew Inwood | 8faeab8 | 2018-03-16 14:26:08 +0000 | [diff] [blame] | 767 | } |
| 768 | } |
| 769 | |
Mathew Inwood | 04194fe | 2018-04-04 14:48:03 +0100 | [diff] [blame] | 770 | /** |
| 771 | * Set the precentage of detected hidden API accesses that are logged to the event log. |
| 772 | * |
| 773 | * <p>This rate will take affect for all new processes forked from the zygote after this call. |
| 774 | * |
| 775 | * @param rate An integer between 0 and 0x10000 inclusive. 0 means no event logging. |
| 776 | */ |
| 777 | public void setHiddenApiAccessLogSampleRate(int rate) { |
| 778 | synchronized (mLock) { |
| 779 | mHiddenApiAccessLogSampleRate = rate; |
| 780 | maybeSetHiddenApiAccessLogSampleRate(primaryZygoteState); |
| 781 | maybeSetHiddenApiAccessLogSampleRate(secondaryZygoteState); |
| 782 | } |
| 783 | } |
| 784 | |
Andrei Onea | e8e150d | 2019-02-18 18:27:11 +0000 | [diff] [blame] | 785 | /** |
| 786 | * Set the precentage of detected hidden API accesses that are logged to the new event log. |
| 787 | * |
| 788 | * <p>This rate will take affect for all new processes forked from the zygote after this call. |
| 789 | * |
| 790 | * @param rate An integer between 0 and 0x10000 inclusive. 0 means no event logging. |
| 791 | */ |
| 792 | public void setHiddenApiAccessStatslogSampleRate(int rate) { |
| 793 | synchronized (mLock) { |
| 794 | mHiddenApiAccessStatslogSampleRate = rate; |
| 795 | maybeSetHiddenApiAccessStatslogSampleRate(primaryZygoteState); |
| 796 | maybeSetHiddenApiAccessStatslogSampleRate(secondaryZygoteState); |
| 797 | } |
| 798 | } |
| 799 | |
Mathew Inwood | 8faeab8 | 2018-03-16 14:26:08 +0000 | [diff] [blame] | 800 | @GuardedBy("mLock") |
Mathew Inwood | 9f6bb5b | 2018-04-09 17:29:12 +0100 | [diff] [blame] | 801 | private boolean maybeSetApiBlacklistExemptions(ZygoteState state, boolean sendIfEmpty) { |
Mathew Inwood | 8faeab8 | 2018-03-16 14:26:08 +0000 | [diff] [blame] | 802 | if (state == null || state.isClosed()) { |
Mathew Inwood | 9f6bb5b | 2018-04-09 17:29:12 +0100 | [diff] [blame] | 803 | Slog.e(LOG_TAG, "Can't set API blacklist exemptions: no zygote connection"); |
| 804 | return false; |
Mathew Inwood | 8faeab8 | 2018-03-16 14:26:08 +0000 | [diff] [blame] | 805 | } |
| 806 | if (!sendIfEmpty && mApiBlacklistExemptions.isEmpty()) { |
Mathew Inwood | 9f6bb5b | 2018-04-09 17:29:12 +0100 | [diff] [blame] | 807 | return true; |
Mathew Inwood | 8faeab8 | 2018-03-16 14:26:08 +0000 | [diff] [blame] | 808 | } |
| 809 | try { |
Chris Wailes | efce929 | 2019-01-11 13:19:20 -0800 | [diff] [blame] | 810 | state.mZygoteOutputWriter.write(Integer.toString(mApiBlacklistExemptions.size() + 1)); |
| 811 | state.mZygoteOutputWriter.newLine(); |
| 812 | state.mZygoteOutputWriter.write("--set-api-blacklist-exemptions"); |
| 813 | state.mZygoteOutputWriter.newLine(); |
Mathew Inwood | 8faeab8 | 2018-03-16 14:26:08 +0000 | [diff] [blame] | 814 | for (int i = 0; i < mApiBlacklistExemptions.size(); ++i) { |
Chris Wailes | efce929 | 2019-01-11 13:19:20 -0800 | [diff] [blame] | 815 | state.mZygoteOutputWriter.write(mApiBlacklistExemptions.get(i)); |
| 816 | state.mZygoteOutputWriter.newLine(); |
Mathew Inwood | 8faeab8 | 2018-03-16 14:26:08 +0000 | [diff] [blame] | 817 | } |
Chris Wailes | efce929 | 2019-01-11 13:19:20 -0800 | [diff] [blame] | 818 | state.mZygoteOutputWriter.flush(); |
| 819 | int status = state.mZygoteInputStream.readInt(); |
Mathew Inwood | 8faeab8 | 2018-03-16 14:26:08 +0000 | [diff] [blame] | 820 | if (status != 0) { |
| 821 | Slog.e(LOG_TAG, "Failed to set API blacklist exemptions; status " + status); |
| 822 | } |
Mathew Inwood | 9f6bb5b | 2018-04-09 17:29:12 +0100 | [diff] [blame] | 823 | return true; |
Mathew Inwood | 8faeab8 | 2018-03-16 14:26:08 +0000 | [diff] [blame] | 824 | } catch (IOException ioe) { |
| 825 | Slog.e(LOG_TAG, "Failed to set API blacklist exemptions", ioe); |
Mathew Inwood | 9f6bb5b | 2018-04-09 17:29:12 +0100 | [diff] [blame] | 826 | mApiBlacklistExemptions = Collections.emptyList(); |
| 827 | return false; |
Mathew Inwood | 8faeab8 | 2018-03-16 14:26:08 +0000 | [diff] [blame] | 828 | } |
| 829 | } |
| 830 | |
Mathew Inwood | 04194fe | 2018-04-04 14:48:03 +0100 | [diff] [blame] | 831 | private void maybeSetHiddenApiAccessLogSampleRate(ZygoteState state) { |
| 832 | if (state == null || state.isClosed()) { |
| 833 | return; |
| 834 | } |
| 835 | if (mHiddenApiAccessLogSampleRate == -1) { |
| 836 | return; |
| 837 | } |
| 838 | try { |
Chris Wailes | efce929 | 2019-01-11 13:19:20 -0800 | [diff] [blame] | 839 | state.mZygoteOutputWriter.write(Integer.toString(1)); |
| 840 | state.mZygoteOutputWriter.newLine(); |
| 841 | state.mZygoteOutputWriter.write("--hidden-api-log-sampling-rate=" |
Mathew Inwood | 04194fe | 2018-04-04 14:48:03 +0100 | [diff] [blame] | 842 | + Integer.toString(mHiddenApiAccessLogSampleRate)); |
Chris Wailes | efce929 | 2019-01-11 13:19:20 -0800 | [diff] [blame] | 843 | state.mZygoteOutputWriter.newLine(); |
| 844 | state.mZygoteOutputWriter.flush(); |
| 845 | int status = state.mZygoteInputStream.readInt(); |
Mathew Inwood | 04194fe | 2018-04-04 14:48:03 +0100 | [diff] [blame] | 846 | if (status != 0) { |
| 847 | Slog.e(LOG_TAG, "Failed to set hidden API log sampling rate; status " + status); |
| 848 | } |
| 849 | } catch (IOException ioe) { |
| 850 | Slog.e(LOG_TAG, "Failed to set hidden API log sampling rate", ioe); |
| 851 | } |
| 852 | } |
| 853 | |
Andrei Onea | e8e150d | 2019-02-18 18:27:11 +0000 | [diff] [blame] | 854 | private void maybeSetHiddenApiAccessStatslogSampleRate(ZygoteState state) { |
| 855 | if (state == null || state.isClosed()) { |
| 856 | return; |
| 857 | } |
| 858 | if (mHiddenApiAccessStatslogSampleRate == -1) { |
| 859 | return; |
| 860 | } |
| 861 | try { |
| 862 | state.mZygoteOutputWriter.write(Integer.toString(1)); |
| 863 | state.mZygoteOutputWriter.newLine(); |
| 864 | state.mZygoteOutputWriter.write("--hidden-api-statslog-sampling-rate=" |
| 865 | + Integer.toString(mHiddenApiAccessStatslogSampleRate)); |
| 866 | state.mZygoteOutputWriter.newLine(); |
| 867 | state.mZygoteOutputWriter.flush(); |
| 868 | int status = state.mZygoteInputStream.readInt(); |
| 869 | if (status != 0) { |
| 870 | Slog.e(LOG_TAG, "Failed to set hidden API statslog sampling rate; status " |
| 871 | + status); |
| 872 | } |
| 873 | } catch (IOException ioe) { |
| 874 | Slog.e(LOG_TAG, "Failed to set hidden API statslog sampling rate", ioe); |
| 875 | } |
| 876 | } |
| 877 | |
Mathew Inwood | 8faeab8 | 2018-03-16 14:26:08 +0000 | [diff] [blame] | 878 | /** |
Chris Wailes | db132a3 | 2019-02-20 10:49:27 -0800 | [diff] [blame] | 879 | * Creates a ZygoteState for the primary zygote if it doesn't exist or has been disconnected. |
| 880 | */ |
| 881 | @GuardedBy("mLock") |
| 882 | private void attemptConnectionToPrimaryZygote() throws IOException { |
| 883 | if (primaryZygoteState == null || primaryZygoteState.isClosed()) { |
| 884 | primaryZygoteState = |
Chris Wailes | 7e797b6 | 2019-02-22 18:29:22 -0800 | [diff] [blame] | 885 | ZygoteState.connect(mZygoteSocketAddress, mUsapPoolSocketAddress); |
Chris Wailes | db132a3 | 2019-02-20 10:49:27 -0800 | [diff] [blame] | 886 | |
| 887 | maybeSetApiBlacklistExemptions(primaryZygoteState, false); |
| 888 | maybeSetHiddenApiAccessLogSampleRate(primaryZygoteState); |
| 889 | } |
| 890 | } |
| 891 | |
| 892 | /** |
| 893 | * Creates a ZygoteState for the secondary zygote if it doesn't exist or has been disconnected. |
| 894 | */ |
| 895 | @GuardedBy("mLock") |
| 896 | private void attemptConnectionToSecondaryZygote() throws IOException { |
| 897 | if (secondaryZygoteState == null || secondaryZygoteState.isClosed()) { |
| 898 | secondaryZygoteState = |
| 899 | ZygoteState.connect(mZygoteSecondarySocketAddress, |
Chris Wailes | 7e797b6 | 2019-02-22 18:29:22 -0800 | [diff] [blame] | 900 | mUsapPoolSecondarySocketAddress); |
Chris Wailes | db132a3 | 2019-02-20 10:49:27 -0800 | [diff] [blame] | 901 | |
| 902 | maybeSetApiBlacklistExemptions(secondaryZygoteState, false); |
| 903 | maybeSetHiddenApiAccessLogSampleRate(secondaryZygoteState); |
| 904 | } |
| 905 | } |
| 906 | |
| 907 | /** |
Chris Wailes | efce929 | 2019-01-11 13:19:20 -0800 | [diff] [blame] | 908 | * Tries to open a session socket to a Zygote process with a compatible ABI if one is not |
| 909 | * already open. If a compatible session socket is already open that session socket is returned. |
| 910 | * This function may block and may have to try connecting to multiple Zygotes to find the |
| 911 | * appropriate one. Requires that mLock be held. |
Robert Sesek | 8f8d187 | 2016-03-18 16:52:57 -0400 | [diff] [blame] | 912 | */ |
Robert Sesek | ded2098 | 2016-08-15 13:59:13 -0400 | [diff] [blame] | 913 | @GuardedBy("mLock") |
Chris Wailes | db132a3 | 2019-02-20 10:49:27 -0800 | [diff] [blame] | 914 | private ZygoteState openZygoteSocketIfNeeded(String abi) throws ZygoteStartFailedEx { |
| 915 | try { |
| 916 | attemptConnectionToPrimaryZygote(); |
Chris Wailes | efce929 | 2019-01-11 13:19:20 -0800 | [diff] [blame] | 917 | |
Chris Wailes | db132a3 | 2019-02-20 10:49:27 -0800 | [diff] [blame] | 918 | if (primaryZygoteState.matches(abi)) { |
| 919 | return primaryZygoteState; |
Robert Sesek | 8f8d187 | 2016-03-18 16:52:57 -0400 | [diff] [blame] | 920 | } |
Chris Wailes | efce929 | 2019-01-11 13:19:20 -0800 | [diff] [blame] | 921 | |
Chris Wailes | db132a3 | 2019-02-20 10:49:27 -0800 | [diff] [blame] | 922 | // The primary zygote didn't match. Try the secondary. |
| 923 | attemptConnectionToSecondaryZygote(); |
Chris Wailes | efce929 | 2019-01-11 13:19:20 -0800 | [diff] [blame] | 924 | |
Chris Wailes | db132a3 | 2019-02-20 10:49:27 -0800 | [diff] [blame] | 925 | if (secondaryZygoteState.matches(abi)) { |
| 926 | return secondaryZygoteState; |
Robert Sesek | 8f8d187 | 2016-03-18 16:52:57 -0400 | [diff] [blame] | 927 | } |
Chris Wailes | db132a3 | 2019-02-20 10:49:27 -0800 | [diff] [blame] | 928 | } catch (IOException ioe) { |
| 929 | throw new ZygoteStartFailedEx("Error connecting to zygote", ioe); |
Robert Sesek | 8f8d187 | 2016-03-18 16:52:57 -0400 | [diff] [blame] | 930 | } |
| 931 | |
| 932 | throw new ZygoteStartFailedEx("Unsupported zygote ABI: " + abi); |
| 933 | } |
Robert Sesek | ded2098 | 2016-08-15 13:59:13 -0400 | [diff] [blame] | 934 | |
| 935 | /** |
Martijn Coenen | 7e6fa67 | 2018-11-05 11:45:26 +0100 | [diff] [blame] | 936 | * Instructs the zygote to pre-load the application code for the given Application. |
| 937 | * Only the app zygote supports this function. |
| 938 | * TODO preloadPackageForAbi() can probably be removed and the callers an use this instead. |
| 939 | */ |
| 940 | public boolean preloadApp(ApplicationInfo appInfo, String abi) throws ZygoteStartFailedEx, |
| 941 | IOException { |
| 942 | synchronized (mLock) { |
| 943 | ZygoteState state = openZygoteSocketIfNeeded(abi); |
Chris Wailes | efce929 | 2019-01-11 13:19:20 -0800 | [diff] [blame] | 944 | state.mZygoteOutputWriter.write("2"); |
| 945 | state.mZygoteOutputWriter.newLine(); |
Martijn Coenen | 7e6fa67 | 2018-11-05 11:45:26 +0100 | [diff] [blame] | 946 | |
Chris Wailes | efce929 | 2019-01-11 13:19:20 -0800 | [diff] [blame] | 947 | state.mZygoteOutputWriter.write("--preload-app"); |
| 948 | state.mZygoteOutputWriter.newLine(); |
Martijn Coenen | 7e6fa67 | 2018-11-05 11:45:26 +0100 | [diff] [blame] | 949 | |
| 950 | // Zygote args needs to be strings, so in order to pass ApplicationInfo, |
| 951 | // write it to a Parcel, and base64 the raw Parcel bytes to the other side. |
| 952 | Parcel parcel = Parcel.obtain(); |
| 953 | appInfo.writeToParcel(parcel, 0 /* flags */); |
| 954 | String encodedParcelData = Base64.getEncoder().encodeToString(parcel.marshall()); |
| 955 | parcel.recycle(); |
Chris Wailes | efce929 | 2019-01-11 13:19:20 -0800 | [diff] [blame] | 956 | state.mZygoteOutputWriter.write(encodedParcelData); |
| 957 | state.mZygoteOutputWriter.newLine(); |
Martijn Coenen | 7e6fa67 | 2018-11-05 11:45:26 +0100 | [diff] [blame] | 958 | |
Chris Wailes | efce929 | 2019-01-11 13:19:20 -0800 | [diff] [blame] | 959 | state.mZygoteOutputWriter.flush(); |
Martijn Coenen | 7e6fa67 | 2018-11-05 11:45:26 +0100 | [diff] [blame] | 960 | |
Chris Wailes | efce929 | 2019-01-11 13:19:20 -0800 | [diff] [blame] | 961 | return (state.mZygoteInputStream.readInt() == 0); |
Martijn Coenen | 7e6fa67 | 2018-11-05 11:45:26 +0100 | [diff] [blame] | 962 | } |
| 963 | } |
| 964 | |
| 965 | /** |
Robert Sesek | ded2098 | 2016-08-15 13:59:13 -0400 | [diff] [blame] | 966 | * Instructs the zygote to pre-load the classes and native libraries at the given paths |
| 967 | * for the specified abi. Not all zygotes support this function. |
| 968 | */ |
Torne (Richard Coles) | f4f647e | 2018-02-21 16:12:36 -0500 | [diff] [blame] | 969 | public boolean preloadPackageForAbi(String packagePath, String libsPath, String libFileName, |
| 970 | String cacheKey, String abi) throws ZygoteStartFailedEx, |
| 971 | IOException { |
Robert Sesek | ded2098 | 2016-08-15 13:59:13 -0400 | [diff] [blame] | 972 | synchronized(mLock) { |
| 973 | ZygoteState state = openZygoteSocketIfNeeded(abi); |
Chris Wailes | efce929 | 2019-01-11 13:19:20 -0800 | [diff] [blame] | 974 | state.mZygoteOutputWriter.write("5"); |
| 975 | state.mZygoteOutputWriter.newLine(); |
Robert Sesek | ded2098 | 2016-08-15 13:59:13 -0400 | [diff] [blame] | 976 | |
Chris Wailes | efce929 | 2019-01-11 13:19:20 -0800 | [diff] [blame] | 977 | state.mZygoteOutputWriter.write("--preload-package"); |
| 978 | state.mZygoteOutputWriter.newLine(); |
Robert Sesek | ded2098 | 2016-08-15 13:59:13 -0400 | [diff] [blame] | 979 | |
Chris Wailes | efce929 | 2019-01-11 13:19:20 -0800 | [diff] [blame] | 980 | state.mZygoteOutputWriter.write(packagePath); |
| 981 | state.mZygoteOutputWriter.newLine(); |
Robert Sesek | ded2098 | 2016-08-15 13:59:13 -0400 | [diff] [blame] | 982 | |
Chris Wailes | efce929 | 2019-01-11 13:19:20 -0800 | [diff] [blame] | 983 | state.mZygoteOutputWriter.write(libsPath); |
| 984 | state.mZygoteOutputWriter.newLine(); |
Robert Sesek | ded2098 | 2016-08-15 13:59:13 -0400 | [diff] [blame] | 985 | |
Chris Wailes | efce929 | 2019-01-11 13:19:20 -0800 | [diff] [blame] | 986 | state.mZygoteOutputWriter.write(libFileName); |
| 987 | state.mZygoteOutputWriter.newLine(); |
Torne (Richard Coles) | f4f647e | 2018-02-21 16:12:36 -0500 | [diff] [blame] | 988 | |
Chris Wailes | efce929 | 2019-01-11 13:19:20 -0800 | [diff] [blame] | 989 | state.mZygoteOutputWriter.write(cacheKey); |
| 990 | state.mZygoteOutputWriter.newLine(); |
Torne (Richard Coles) | 0452670 | 2017-01-13 14:19:39 +0000 | [diff] [blame] | 991 | |
Chris Wailes | efce929 | 2019-01-11 13:19:20 -0800 | [diff] [blame] | 992 | state.mZygoteOutputWriter.flush(); |
Narayan Kamath | bae484a | 2017-07-03 14:12:26 +0100 | [diff] [blame] | 993 | |
Chris Wailes | efce929 | 2019-01-11 13:19:20 -0800 | [diff] [blame] | 994 | return (state.mZygoteInputStream.readInt() == 0); |
Robert Sesek | ded2098 | 2016-08-15 13:59:13 -0400 | [diff] [blame] | 995 | } |
| 996 | } |
Narayan Kamath | 669afcc | 2017-02-06 20:24:08 +0000 | [diff] [blame] | 997 | |
| 998 | /** |
| 999 | * Instructs the zygote to preload the default set of classes and resources. Returns |
| 1000 | * {@code true} if a preload was performed as a result of this call, and {@code false} |
| 1001 | * otherwise. The latter usually means that the zygote eagerly preloaded at startup |
| 1002 | * or due to a previous call to {@code preloadDefault}. Note that this call is synchronous. |
| 1003 | */ |
| 1004 | public boolean preloadDefault(String abi) throws ZygoteStartFailedEx, IOException { |
| 1005 | synchronized (mLock) { |
| 1006 | ZygoteState state = openZygoteSocketIfNeeded(abi); |
| 1007 | // Each query starts with the argument count (1 in this case) |
Chris Wailes | efce929 | 2019-01-11 13:19:20 -0800 | [diff] [blame] | 1008 | state.mZygoteOutputWriter.write("1"); |
| 1009 | state.mZygoteOutputWriter.newLine(); |
| 1010 | state.mZygoteOutputWriter.write("--preload-default"); |
| 1011 | state.mZygoteOutputWriter.newLine(); |
| 1012 | state.mZygoteOutputWriter.flush(); |
Narayan Kamath | 669afcc | 2017-02-06 20:24:08 +0000 | [diff] [blame] | 1013 | |
Chris Wailes | efce929 | 2019-01-11 13:19:20 -0800 | [diff] [blame] | 1014 | return (state.mZygoteInputStream.readInt() == 0); |
Narayan Kamath | 669afcc | 2017-02-06 20:24:08 +0000 | [diff] [blame] | 1015 | } |
| 1016 | } |
Gustav Sennton | f0c52b5 | 2017-04-27 17:00:50 +0100 | [diff] [blame] | 1017 | |
| 1018 | /** |
| 1019 | * Try connecting to the Zygote over and over again until we hit a time-out. |
Mathieu Chartier | 0bccbf7 | 2019-01-30 15:56:17 -0800 | [diff] [blame] | 1020 | * @param zygoteSocketName The name of the socket to connect to. |
Gustav Sennton | f0c52b5 | 2017-04-27 17:00:50 +0100 | [diff] [blame] | 1021 | */ |
Chris Wailes | efce929 | 2019-01-11 13:19:20 -0800 | [diff] [blame] | 1022 | public static void waitForConnectionToZygote(String zygoteSocketName) { |
| 1023 | final LocalSocketAddress zygoteSocketAddress = |
| 1024 | new LocalSocketAddress(zygoteSocketName, LocalSocketAddress.Namespace.RESERVED); |
| 1025 | waitForConnectionToZygote(zygoteSocketAddress); |
Robert Sesek | 5ac8abf | 2018-01-26 14:26:53 -0500 | [diff] [blame] | 1026 | } |
| 1027 | |
| 1028 | /** |
| 1029 | * Try connecting to the Zygote over and over again until we hit a time-out. |
Mathieu Chartier | 0bccbf7 | 2019-01-30 15:56:17 -0800 | [diff] [blame] | 1030 | * @param zygoteSocketAddress The name of the socket to connect to. |
Robert Sesek | 5ac8abf | 2018-01-26 14:26:53 -0500 | [diff] [blame] | 1031 | */ |
Chris Wailes | efce929 | 2019-01-11 13:19:20 -0800 | [diff] [blame] | 1032 | public static void waitForConnectionToZygote(LocalSocketAddress zygoteSocketAddress) { |
Martijn Coenen | 82dc85a | 2019-01-28 13:12:28 +0100 | [diff] [blame] | 1033 | int numRetries = ZYGOTE_CONNECT_TIMEOUT_MS / ZYGOTE_CONNECT_RETRY_DELAY_MS; |
| 1034 | for (int n = numRetries; n >= 0; n--) { |
Gustav Sennton | f0c52b5 | 2017-04-27 17:00:50 +0100 | [diff] [blame] | 1035 | try { |
Chris Wailes | efce929 | 2019-01-11 13:19:20 -0800 | [diff] [blame] | 1036 | final ZygoteState zs = |
Chris Wailes | ba4c2eb | 2019-01-11 17:13:00 -0800 | [diff] [blame] | 1037 | ZygoteState.connect(zygoteSocketAddress, null); |
Gustav Sennton | f0c52b5 | 2017-04-27 17:00:50 +0100 | [diff] [blame] | 1038 | zs.close(); |
| 1039 | return; |
| 1040 | } catch (IOException ioe) { |
| 1041 | Log.w(LOG_TAG, |
| 1042 | "Got error connecting to zygote, retrying. msg= " + ioe.getMessage()); |
| 1043 | } |
| 1044 | |
| 1045 | try { |
Martijn Coenen | 82dc85a | 2019-01-28 13:12:28 +0100 | [diff] [blame] | 1046 | Thread.sleep(ZYGOTE_CONNECT_RETRY_DELAY_MS); |
Gustav Sennton | f0c52b5 | 2017-04-27 17:00:50 +0100 | [diff] [blame] | 1047 | } catch (InterruptedException ie) { |
| 1048 | } |
| 1049 | } |
Chris Wailes | efce929 | 2019-01-11 13:19:20 -0800 | [diff] [blame] | 1050 | Slog.wtf(LOG_TAG, "Failed to connect to Zygote through socket " |
| 1051 | + zygoteSocketAddress.getName()); |
Gustav Sennton | f0c52b5 | 2017-04-27 17:00:50 +0100 | [diff] [blame] | 1052 | } |
Robert Sesek | d0a190df | 2018-02-12 18:46:01 -0500 | [diff] [blame] | 1053 | |
| 1054 | /** |
Chris Wailes | 7e797b6 | 2019-02-22 18:29:22 -0800 | [diff] [blame] | 1055 | * Sends messages to the zygotes telling them to change the status of their USAP pools. If |
Chris Wailes | db132a3 | 2019-02-20 10:49:27 -0800 | [diff] [blame] | 1056 | * this notification fails the ZygoteProcess will fall back to the previous behavior. |
| 1057 | */ |
Chris Wailes | 7e797b6 | 2019-02-22 18:29:22 -0800 | [diff] [blame] | 1058 | private void informZygotesOfUsapPoolStatus() { |
| 1059 | final String command = "1\n--usap-pool-enabled=" + mUsapPoolEnabled + "\n"; |
Chris Wailes | db132a3 | 2019-02-20 10:49:27 -0800 | [diff] [blame] | 1060 | |
| 1061 | synchronized (mLock) { |
| 1062 | try { |
| 1063 | attemptConnectionToPrimaryZygote(); |
| 1064 | |
| 1065 | primaryZygoteState.mZygoteOutputWriter.write(command); |
| 1066 | primaryZygoteState.mZygoteOutputWriter.flush(); |
| 1067 | } catch (IOException ioe) { |
Chris Wailes | 7e797b6 | 2019-02-22 18:29:22 -0800 | [diff] [blame] | 1068 | mUsapPoolEnabled = !mUsapPoolEnabled; |
| 1069 | Log.w(LOG_TAG, "Failed to inform zygotes of USAP pool status: " |
Chris Wailes | db132a3 | 2019-02-20 10:49:27 -0800 | [diff] [blame] | 1070 | + ioe.getMessage()); |
| 1071 | return; |
| 1072 | } |
| 1073 | |
| 1074 | try { |
| 1075 | attemptConnectionToSecondaryZygote(); |
| 1076 | |
| 1077 | try { |
| 1078 | secondaryZygoteState.mZygoteOutputWriter.write(command); |
| 1079 | secondaryZygoteState.mZygoteOutputWriter.flush(); |
| 1080 | |
| 1081 | // Wait for the secondary Zygote to finish its work. |
| 1082 | secondaryZygoteState.mZygoteInputStream.readInt(); |
| 1083 | } catch (IOException ioe) { |
| 1084 | throw new IllegalStateException( |
Chris Wailes | 7e797b6 | 2019-02-22 18:29:22 -0800 | [diff] [blame] | 1085 | "USAP pool state change cause an irrecoverable error", |
Chris Wailes | db132a3 | 2019-02-20 10:49:27 -0800 | [diff] [blame] | 1086 | ioe); |
| 1087 | } |
| 1088 | } catch (IOException ioe) { |
| 1089 | // No secondary zygote present. This is expected on some devices. |
| 1090 | } |
| 1091 | |
| 1092 | // Wait for the response from the primary zygote here so the primary/secondary zygotes |
| 1093 | // can work concurrently. |
| 1094 | try { |
| 1095 | // Wait for the primary zygote to finish its work. |
| 1096 | primaryZygoteState.mZygoteInputStream.readInt(); |
| 1097 | } catch (IOException ioe) { |
| 1098 | throw new IllegalStateException( |
Chris Wailes | 7e797b6 | 2019-02-22 18:29:22 -0800 | [diff] [blame] | 1099 | "USAP pool state change cause an irrecoverable error", |
Chris Wailes | db132a3 | 2019-02-20 10:49:27 -0800 | [diff] [blame] | 1100 | ioe); |
| 1101 | } |
| 1102 | } |
| 1103 | } |
| 1104 | |
| 1105 | /** |
Robert Sesek | d0a190df | 2018-02-12 18:46:01 -0500 | [diff] [blame] | 1106 | * Starts a new zygote process as a child of this zygote. This is used to create |
| 1107 | * secondary zygotes that inherit data from the zygote that this object |
| 1108 | * communicates with. This returns a new ZygoteProcess representing a connection |
| 1109 | * to the newly created zygote. Throws an exception if the zygote cannot be started. |
Martijn Coenen | 7e6fa67 | 2018-11-05 11:45:26 +0100 | [diff] [blame] | 1110 | * |
| 1111 | * @param processClass The class to use as the child zygote's main entry |
| 1112 | * point. |
| 1113 | * @param niceName A more readable name to use for the process. |
| 1114 | * @param uid The user-id under which the child zygote will run. |
| 1115 | * @param gid The group-id under which the child zygote will run. |
| 1116 | * @param gids Additional group-ids associated with the child zygote process. |
| 1117 | * @param runtimeFlags Additional flags. |
| 1118 | * @param seInfo null-ok SELinux information for the child zygote process. |
| 1119 | * @param abi non-null the ABI of the child zygote |
| 1120 | * @param acceptedAbiList ABIs this child zygote will accept connections for; this |
| 1121 | * may be different from <code>abi</code> in case the children |
| 1122 | * spawned from this Zygote only communicate using ABI-safe methods. |
| 1123 | * @param instructionSet null-ok the instruction set to use. |
Martijn Coenen | 86f08a5 | 2019-01-03 16:23:01 +0100 | [diff] [blame] | 1124 | * @param uidRangeStart The first UID in the range the child zygote may setuid()/setgid() to |
| 1125 | * @param uidRangeEnd The last UID in the range the child zygote may setuid()/setgid() to |
Robert Sesek | d0a190df | 2018-02-12 18:46:01 -0500 | [diff] [blame] | 1126 | */ |
| 1127 | public ChildZygoteProcess startChildZygote(final String processClass, |
| 1128 | final String niceName, |
| 1129 | int uid, int gid, int[] gids, |
| 1130 | int runtimeFlags, |
| 1131 | String seInfo, |
| 1132 | String abi, |
Martijn Coenen | 7e6fa67 | 2018-11-05 11:45:26 +0100 | [diff] [blame] | 1133 | String acceptedAbiList, |
Martijn Coenen | 86f08a5 | 2019-01-03 16:23:01 +0100 | [diff] [blame] | 1134 | String instructionSet, |
| 1135 | int uidRangeStart, |
| 1136 | int uidRangeEnd) { |
Robert Sesek | d0a190df | 2018-02-12 18:46:01 -0500 | [diff] [blame] | 1137 | // Create an unguessable address in the global abstract namespace. |
| 1138 | final LocalSocketAddress serverAddress = new LocalSocketAddress( |
| 1139 | processClass + "/" + UUID.randomUUID().toString()); |
| 1140 | |
Martijn Coenen | 7e6fa67 | 2018-11-05 11:45:26 +0100 | [diff] [blame] | 1141 | final String[] extraArgs = {Zygote.CHILD_ZYGOTE_SOCKET_NAME_ARG + serverAddress.getName(), |
Martijn Coenen | 86f08a5 | 2019-01-03 16:23:01 +0100 | [diff] [blame] | 1142 | Zygote.CHILD_ZYGOTE_ABI_LIST_ARG + acceptedAbiList, |
| 1143 | Zygote.CHILD_ZYGOTE_UID_RANGE_START + uidRangeStart, |
| 1144 | Zygote.CHILD_ZYGOTE_UID_RANGE_END + uidRangeEnd}; |
Robert Sesek | d0a190df | 2018-02-12 18:46:01 -0500 | [diff] [blame] | 1145 | |
| 1146 | Process.ProcessStartResult result; |
| 1147 | try { |
| 1148 | result = startViaZygote(processClass, niceName, uid, gid, |
| 1149 | gids, runtimeFlags, 0 /* mountExternal */, 0 /* targetSdkVersion */, seInfo, |
| 1150 | abi, instructionSet, null /* appDataDir */, null /* invokeWith */, |
Sudheer Shanka | 3f0645b | 2018-09-18 13:07:59 -0700 | [diff] [blame] | 1151 | true /* startChildZygote */, null /* packageName */, |
Sudheer Shanka | e51005d | 2019-02-24 10:24:09 -0800 | [diff] [blame] | 1152 | null /* packagesForUid */, null /* sandboxId */, |
Chris Wailes | 7e797b6 | 2019-02-22 18:29:22 -0800 | [diff] [blame] | 1153 | false /* useUsapPool */, extraArgs); |
Robert Sesek | d0a190df | 2018-02-12 18:46:01 -0500 | [diff] [blame] | 1154 | } catch (ZygoteStartFailedEx ex) { |
| 1155 | throw new RuntimeException("Starting child-zygote through Zygote failed", ex); |
| 1156 | } |
| 1157 | |
| 1158 | return new ChildZygoteProcess(serverAddress, result.pid); |
| 1159 | } |
Robert Sesek | 8f8d187 | 2016-03-18 16:52:57 -0400 | [diff] [blame] | 1160 | } |