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 com.android.internal.os; 18 19 import android.os.SystemProperties; 20 import android.provider.DeviceConfig; 21 22 /** 23 * Flag names for configuring the zygote. 24 * 25 * @hide 26 */ 27 public class ZygoteConfig { 28 29 /** If {@code true}, enables the unspecialized app process (USAP) pool feature */ 30 public static final String USAP_POOL_ENABLED = "usap_pool_enabled"; 31 32 /** 33 * The default value for enabling the unspecialized app process (USAP) pool. This value will 34 * not be used if the devices has a DeviceConfig profile pushed to it that contains a value for 35 * this key or if the System Property dalvik.vm.usap_pool_enabled is set. 36 */ 37 public static final boolean USAP_POOL_ENABLED_DEFAULT = false; 38 39 40 41 /** The threshold used to determine if the pool should be refilled */ 42 public static final String USAP_POOL_REFILL_THRESHOLD = "usap_refill_threshold"; 43 44 public static final int USAP_POOL_REFILL_THRESHOLD_DEFAULT = 1; 45 46 47 48 /** The maximum number of processes to keep in the USAP pool */ 49 public static final String USAP_POOL_SIZE_MAX = "usap_pool_size_max"; 50 51 public static final int USAP_POOL_SIZE_MAX_DEFAULT = 3; 52 53 /** 54 * The maximim value that will be accepted from the USAP_POOL_SIZE_MAX device property. 55 * is a mirror of USAP_POOL_MAX_LIMIT found in com_android_internal_os_Zygote.cpp. 56 */ 57 public static final int USAP_POOL_SIZE_MAX_LIMIT = 100; 58 59 60 61 /** The minimum number of processes to keep in the USAP pool */ 62 public static final String USAP_POOL_SIZE_MIN = "usap_pool_size_min"; 63 64 public static final int USAP_POOL_SIZE_MIN_DEFAULT = 1; 65 66 /** 67 * The minimum value that will be accepted from the USAP_POOL_SIZE_MIN device property. 68 */ 69 public static final int USAP_POOL_SIZE_MIN_LIMIT = 1; 70 71 72 73 /** The number of milliseconds to delay before refilling the USAP pool */ 74 public static final String USAP_POOL_REFILL_DELAY_MS = "usap_pool_refill_delay_ms"; 75 76 public static final int USAP_POOL_REFILL_DELAY_MS_DEFAULT = 3000; 77 78 public static final String PROPERTY_PREFIX_DEVICE_CONFIG = "persist.device_config"; 79 public static final String PROPERTY_PREFIX_SYSTEM = "dalvik.vm."; 80 getDeviceConfig(String name)81 private static String getDeviceConfig(String name) { 82 return SystemProperties.get( 83 String.join( 84 ".", 85 PROPERTY_PREFIX_DEVICE_CONFIG, 86 DeviceConfig.NAMESPACE_RUNTIME_NATIVE, 87 name)); 88 } 89 90 /** 91 * Get a property value from SystemProperties and convert it to an integer value. 92 */ getInt(String name, int defaultValue)93 public static int getInt(String name, int defaultValue) { 94 final String propString = getDeviceConfig(name); 95 96 if (!propString.isEmpty()) { 97 return Integer.parseInt(propString); 98 } else { 99 return SystemProperties.getInt(PROPERTY_PREFIX_SYSTEM + name, defaultValue); 100 } 101 } 102 103 /** 104 * Get a property value from SystemProperties and convert it to a Boolean value. 105 */ getBool(String name, boolean defaultValue)106 public static boolean getBool(String name, boolean defaultValue) { 107 final String propString = getDeviceConfig(name); 108 109 if (!propString.isEmpty()) { 110 return Boolean.parseBoolean(propString); 111 } else { 112 return SystemProperties.getBoolean(PROPERTY_PREFIX_SYSTEM + name, defaultValue); 113 } 114 } 115 } 116