X-Git-Url: http://git.osdn.net/view?a=blobdiff_plain;f=core%2Fjni%2FAndroidRuntime.cpp;h=2fad2f60f32c5e8b26047bf866c8d4b8b506a3d4;hb=ce2e9d8716a0c56f7a7dae0eadbd014dd8b83b23;hp=c174d37d13802f8d8909c13cc9988f803becc8f4;hpb=bd23716585bd21b4dc4bf87bd56ce588c8d457df;p=android-x86%2Fframeworks-base.git diff --git a/core/jni/AndroidRuntime.cpp b/core/jni/AndroidRuntime.cpp index c174d37d1380..2fad2f60f32c 100644 --- a/core/jni/AndroidRuntime.cpp +++ b/core/jni/AndroidRuntime.cpp @@ -43,6 +43,9 @@ #include #include +#include +#include + using namespace android; @@ -81,6 +84,7 @@ extern int register_android_hardware_camera2_CameraMetadata(JNIEnv *env); extern int register_android_hardware_camera2_legacy_LegacyCameraDevice(JNIEnv *env); extern int register_android_hardware_camera2_legacy_PerfMeasurement(JNIEnv *env); extern int register_android_hardware_camera2_DngCreator(JNIEnv *env); +extern int register_android_hardware_Radio(JNIEnv *env); extern int register_android_hardware_SensorManager(JNIEnv *env); extern int register_android_hardware_SerialPort(JNIEnv *env); extern int register_android_hardware_SoundTrigger(JNIEnv *env); @@ -127,16 +131,16 @@ extern int register_android_graphics_pdf_PdfDocument(JNIEnv* env); extern int register_android_graphics_pdf_PdfEditor(JNIEnv* env); extern int register_android_graphics_pdf_PdfRenderer(JNIEnv* env); extern int register_android_view_DisplayEventReceiver(JNIEnv* env); -extern int register_android_view_RenderNode(JNIEnv* env); -extern int register_android_view_RenderNodeAnimator(JNIEnv* env); +extern int register_android_view_DisplayListCanvas(JNIEnv* env); extern int register_android_view_GraphicBuffer(JNIEnv* env); -extern int register_android_view_GLES20Canvas(JNIEnv* env); extern int register_android_view_HardwareLayer(JNIEnv* env); -extern int register_android_view_ThreadedRenderer(JNIEnv* env); +extern int register_android_view_RenderNode(JNIEnv* env); +extern int register_android_view_RenderNodeAnimator(JNIEnv* env); extern int register_android_view_Surface(JNIEnv* env); extern int register_android_view_SurfaceControl(JNIEnv* env); extern int register_android_view_SurfaceSession(JNIEnv* env); extern int register_android_view_TextureView(JNIEnv* env); +extern int register_android_view_ThreadedRenderer(JNIEnv* env); extern int register_com_android_internal_view_animation_NativeInterpolatorFactoryHelper(JNIEnv *env); extern int register_android_database_CursorWindow(JNIEnv* env); extern int register_android_database_SQLiteConnection(JNIEnv* env); @@ -237,8 +241,8 @@ AndroidRuntime::AndroidRuntime(char* argBlockStart, const size_t argBlockLength) mArgBlockLength(argBlockLength) { SkGraphics::Init(); - // There is also a global font cache, but its budget is specified in code - // see SkFontHost_android.cpp + // There is also a global font cache, but its budget is specified by + // SK_DEFAULT_FONT_CACHE_COUNT_LIMIT and SK_DEFAULT_FONT_CACHE_LIMIT. // Pre-allocate enough space to hold a fair number of options. mOptions.setCapacity(20); @@ -356,38 +360,66 @@ static bool hasFile(const char* file) { return false; } +// Convenience wrapper over the property API that returns an +// std::string. +std::string getProperty(const char* key, const char* defaultValue) { + std::vector temp(PROPERTY_VALUE_MAX); + const int len = property_get(key, &temp[0], defaultValue); + if (len < 0) { + return ""; + } + return std::string(&temp[0], len); +} + /* - * Read the persistent locale. Attempts to read to persist.sys.locale - * and falls back to the default locale (ro.product.locale) if - * persist.sys.locale is empty. + * Read the persistent locale. Inspects the following system properties + * (in order) and returns the first non-empty property in the list : + * + * (1) persist.sys.locale + * (2) persist.sys.language/country/localevar (country and localevar are + * inspected iff. language is non-empty. + * (3) ro.product.locale + * (4) ro.product.locale.language/region + * + * Note that we need to inspect persist.sys.language/country/localevar to + * preserve language settings for devices that are upgrading from Lollipop + * to M. The same goes for ro.product.locale.language/region as well. */ -static void readLocale(char* locale) +const std::string readLocale() { - // Allocate 4 extra bytes because we might read a property into - // this array at offset 4. - char propLocale[PROPERTY_VALUE_MAX + 4]; - - property_get("persist.sys.locale", propLocale, ""); - if (propLocale[0] == 0) { - property_get("ro.product.locale", propLocale, ""); - - if (propLocale[0] == 0) { - // If persist.sys.locale and ro.product.locale are missing, - // construct a locale value from the individual locale components. - property_get("ro.product.locale.language", propLocale, "en"); - - // The language code is either two or three chars in length. If it - // isn't 2 chars long, assume three. Anything else is an error - // anyway. - const int offset = (propLocale[2] == 0) ? 2 : 3; - propLocale[offset] = '-'; - - property_get("ro.product.locale.region", propLocale + offset + 1, "US"); + const std::string locale = getProperty("persist.sys.locale", ""); + if (!locale.empty()) { + return locale; + } + + const std::string language = getProperty("persist.sys.language", ""); + if (!language.empty()) { + const std::string country = getProperty("persist.sys.country", ""); + const std::string variant = getProperty("persist.sys.localevar", ""); + + std::string out = language; + if (!country.empty()) { + out = out + "-" + country; + } + + if (!variant.empty()) { + out = out + "-" + variant; } + + return out; + } + + const std::string productLocale = getProperty("ro.product.locale", ""); + if (!productLocale.empty()) { + return productLocale; } - strncat(locale, propLocale, PROPERTY_VALUE_MAX); - // ALOGD("[DEBUG] locale=%s", locale); + // If persist.sys.locale and ro.product.locale are missing, + // construct a locale value from the individual locale components. + const std::string productLanguage = getProperty("ro.product.locale.language", "en"); + const std::string productRegion = getProperty("ro.product.locale.region", "US"); + + return productLanguage + "-" + productRegion; } void AndroidRuntime::addOption(const char* optionString, void* extraInfo) @@ -587,6 +619,9 @@ int AndroidRuntime::startVm(JavaVM** pJavaVM, JNIEnv** pEnv, bool zygote) char lockProfThresholdBuf[sizeof("-Xlockprofthreshold:")-1 + PROPERTY_VALUE_MAX]; char nativeBridgeLibrary[sizeof("-XX:NativeBridge=") + PROPERTY_VALUE_MAX]; char cpuAbiListBuf[sizeof("--cpu-abilist=") + PROPERTY_VALUE_MAX]; + char methodTraceFileBuf[sizeof("-Xmethod-trace-file:") + PROPERTY_VALUE_MAX]; + char methodTraceFileSizeBuf[sizeof("-Xmethod-trace-file-size:") + PROPERTY_VALUE_MAX]; + char fingerprintBuf[sizeof("-Xfingerprint:") + PROPERTY_VALUE_MAX]; bool checkJni = false; property_get("dalvik.vm.checkjni", propBuf, ""); @@ -793,7 +828,8 @@ int AndroidRuntime::startVm(JavaVM** pJavaVM, JNIEnv** pEnv, bool zygote) /* Set the properties for locale */ { strcpy(localeOption, "-Duser.locale="); - readLocale(localeOption); + const std::string locale = readLocale(); + strncat(localeOption, locale.c_str(), PROPERTY_VALUE_MAX); addOption(localeOption); } @@ -851,6 +887,24 @@ int AndroidRuntime::startVm(JavaVM** pJavaVM, JNIEnv** pEnv, bool zygote) profileMaxStackDepth, "-Xprofile-max-stack-depth:"); + /* + * Tracing options. + */ + property_get("dalvik.vm.method-trace", propBuf, "false"); + if (strcmp(propBuf, "true") == 0) { + addOption("-Xmethod-trace"); + parseRuntimeOption("dalvik.vm.method-trace-file", + methodTraceFileBuf, + "-Xmethod-trace-file:"); + parseRuntimeOption("dalvik.vm.method-trace-file-siz", + methodTraceFileSizeBuf, + "-Xmethod-trace-file-size:"); + property_get("dalvik.vm.method-trace-stream", propBuf, "false"); + if (strcmp(propBuf, "true") == 0) { + addOption("-Xmethod-trace-stream"); + } + } + // Native bridge library. "0" means that native bridge is disabled. property_get("ro.dalvik.vm.native.bridge", propBuf, ""); if (propBuf[0] == '\0') { @@ -861,9 +915,6 @@ int AndroidRuntime::startVm(JavaVM** pJavaVM, JNIEnv** pEnv, bool zygote) addOption(nativeBridgeLibrary); } - // Dalvik-cache pruning counter. - parseRuntimeOption("dalvik.vm.zygote.max-boot-retry", cachePruneBuf, - "-Xzygote-max-boot-retry="); #if defined(__LP64__) const char* cpu_abilist_property_name = "ro.product.cpu.abilist64"; #else @@ -877,6 +928,29 @@ int AndroidRuntime::startVm(JavaVM** pJavaVM, JNIEnv** pEnv, bool zygote) snprintf(cpuAbiListBuf, sizeof(cpuAbiListBuf), "--cpu-abilist=%s", propBuf); addOption(cpuAbiListBuf); + // Dalvik-cache pruning counter. + parseRuntimeOption("dalvik.vm.zygote.max-boot-retry", cachePruneBuf, + "-Xzygote-max-boot-retry="); + + /* + * When running with debug.generate-debug-info, add --generate-debug-info to + * the compiler options so that the boot image, if it is compiled on device, + * will include native debugging information. + */ + property_get("debug.generate-debug-info", propBuf, ""); + if (strcmp(propBuf, "true") == 0) { + addOption("-Xcompiler-option"); + addOption("--generate-debug-info"); + addOption("-Ximage-compiler-option"); + addOption("--generate-debug-info"); + } + + /* + * Retrieve the build fingerprint and provide it to the runtime. That way, ANR dumps will + * contain the fingerprint and can be parsed. + */ + parseRuntimeOption("ro.build.fingerprint", fingerprintBuf, "-Xfingerprint:"); + initArgs.version = JNI_VERSION_1_4; initArgs.options = mOptions.editArray(); initArgs.nOptions = mOptions.size(); @@ -1243,7 +1317,7 @@ static const RegJNIRec gRegJNI[] = { REG_JNI(register_android_view_RenderNode), REG_JNI(register_android_view_RenderNodeAnimator), REG_JNI(register_android_view_GraphicBuffer), - REG_JNI(register_android_view_GLES20Canvas), + REG_JNI(register_android_view_DisplayListCanvas), REG_JNI(register_android_view_HardwareLayer), REG_JNI(register_android_view_ThreadedRenderer), REG_JNI(register_android_view_Surface), @@ -1318,6 +1392,7 @@ static const RegJNIRec gRegJNI[] = { REG_JNI(register_android_hardware_camera2_legacy_LegacyCameraDevice), REG_JNI(register_android_hardware_camera2_legacy_PerfMeasurement), REG_JNI(register_android_hardware_camera2_DngCreator), + REG_JNI(register_android_hardware_Radio), REG_JNI(register_android_hardware_SensorManager), REG_JNI(register_android_hardware_SerialPort), REG_JNI(register_android_hardware_SoundTrigger),