Commit 855363c7 authored by Bo Liu's avatar Bo Liu Committed by Commit Bot

android: Upstream app zygote implementation

Enable zygote in chromium code in chrome and content shell.

Requires crrev.com/i/2340835 for private code to build.

Change-Id: I99a3f550a81b0c877389ccb839b59afba8a7d447
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1976015
Commit-Queue: Bo <boliu@chromium.org>
Reviewed-by: default avatarAndrew Grieve <agrieve@chromium.org>
Cr-Commit-Position: refs/heads/master@{#726444}
parent e58c26dc
...@@ -131,9 +131,7 @@ by a child template that "extends" this file. ...@@ -131,9 +131,7 @@ by a child template that "extends" this file.
android:largeHeap="false" android:largeHeap="false"
android:manageSpaceActivity="@string/manage_space_activity" android:manageSpaceActivity="@string/manage_space_activity"
android:supportsRtl="true" android:supportsRtl="true"
{% if (use_zygote|default(false) == 'true') %}
android:zygotePreloadName="org.chromium.content.app.ZygotePreload" android:zygotePreloadName="org.chromium.content.app.ZygotePreload"
{% endif %}
{% if backup_key is defined %} {% if backup_key is defined %}
android:allowBackup="true" android:allowBackup="true"
android:backupAgent="org.chromium.chrome.browser.ChromeBackupAgent" android:backupAgent="org.chromium.chrome.browser.ChromeBackupAgent"
...@@ -1193,7 +1191,7 @@ by a child template that "extends" this file. ...@@ -1193,7 +1191,7 @@ by a child template that "extends" this file.
android:permission="{{ manifest_package }}.permission.CHILD_SERVICE" android:permission="{{ manifest_package }}.permission.CHILD_SERVICE"
android:isolatedProcess="true" android:isolatedProcess="true"
android:exported="{{sandboxed_service_exported|default(false)}}" android:exported="{{sandboxed_service_exported|default(false)}}"
{% if (use_zygote|default(false) == 'true') and (i == 0) %} {% if (i == 0) %}
android:useAppZygote="true" android:useAppZygote="true"
{% endif %} {% endif %}
{% if (sandboxed_service_exported|default(false)) == 'true' %} {% if (sandboxed_service_exported|default(false)) == 'true' %}
......
...@@ -90,7 +90,8 @@ ...@@ -90,7 +90,8 @@
android:networkSecurityConfig="@xml/network_security_config" android:networkSecurityConfig="@xml/network_security_config"
android:roundIcon="@drawable/ic_launcher_round" android:roundIcon="@drawable/ic_launcher_round"
android:supportsRtl="true" android:supportsRtl="true"
android:use32bitAbi="true"> android:use32bitAbi="true"
android:zygotePreloadName="org.chromium.content.app.ZygotePreload">
<activity <activity
android:autoRemoveFromRecents="false" android:autoRemoveFromRecents="false"
android:configChanges="orientation|keyboardHidden|keyboard|screenSize|mcc|mnc|screenLayout|smallestScreenSize|uiMode|density" android:configChanges="orientation|keyboardHidden|keyboard|screenSize|mcc|mnc|screenLayout|smallestScreenSize|uiMode|density"
...@@ -1672,6 +1673,7 @@ ...@@ -1672,6 +1673,7 @@
android:name="org.chromium.content.app.SandboxedProcessService0" android:name="org.chromium.content.app.SandboxedProcessService0"
android:permission="org.chromium.chrome.permission.CHILD_SERVICE" android:permission="org.chromium.chrome.permission.CHILD_SERVICE"
android:process=":sandboxed_process0" android:process=":sandboxed_process0"
android:useAppZygote="true"
android:visibleToInstantApps="true" android:visibleToInstantApps="true"
tools:ignore="ExportedService"/> tools:ignore="ExportedService"/>
<service <service
......
...@@ -118,6 +118,7 @@ android_library("content_java") { ...@@ -118,6 +118,7 @@ android_library("content_java") {
"java/src/org/chromium/content/app/PrivilegedProcessService3.java", "java/src/org/chromium/content/app/PrivilegedProcessService3.java",
"java/src/org/chromium/content/app/PrivilegedProcessService4.java", "java/src/org/chromium/content/app/PrivilegedProcessService4.java",
"java/src/org/chromium/content/app/SandboxedProcessService.java", "java/src/org/chromium/content/app/SandboxedProcessService.java",
"java/src/org/chromium/content/app/ZygotePreload.java",
"java/src/org/chromium/content/browser/AppWebMessagePort.java", "java/src/org/chromium/content/browser/AppWebMessagePort.java",
"java/src/org/chromium/content/browser/AudioFocusDelegate.java", "java/src/org/chromium/content/browser/AudioFocusDelegate.java",
"java/src/org/chromium/content/browser/BackgroundSyncNetworkObserver.java", "java/src/org/chromium/content/browser/BackgroundSyncNetworkObserver.java",
......
// Copyright 2019 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
package org.chromium.content.app;
import android.annotation.SuppressLint;
import android.annotation.TargetApi;
import android.content.pm.ApplicationInfo;
import android.os.Build;
import org.chromium.base.JNIUtils;
import org.chromium.base.Log;
import org.chromium.base.library_loader.LibraryLoader;
/**
* Class used in android:zygotePreloadName attribute of manifest.
* Code in this class runs in the zygote. It runs in a limited environment
* (eg no application) and cannot communicate with any other app process,
* so care must be taken when writing code in this class. Eg it should not
* create any thread.
*/
@TargetApi(Build.VERSION_CODES.Q)
public class ZygotePreload implements android.app.ZygotePreload {
private static final String TAG = "ZygotePreload";
@SuppressLint("Override")
@Override
public void doPreload(ApplicationInfo appInfo) {
try {
JNIUtils.enableSelectiveJniRegistration();
LibraryLoader.getInstance().loadNowInZygote(appInfo);
} catch (Throwable e) {
// Ignore any exception. Child service can continue loading.
Log.w(TAG, "Exception in zygote", e);
}
}
}
...@@ -24,6 +24,7 @@ ...@@ -24,6 +24,7 @@
<application android:name="org.chromium.content_shell_apk.ContentShellApplication" <application android:name="org.chromium.content_shell_apk.ContentShellApplication"
android:icon="@mipmap/app_icon" android:icon="@mipmap/app_icon"
android:zygotePreloadName="org.chromium.content.app.ZygotePreload"
android:label="{% block application_label %}Content Shell{% endblock %}"> android:label="{% block application_label %}Content Shell{% endblock %}">
<activity android:name="org.chromium.content_shell_apk.ContentShellActivity" <activity android:name="org.chromium.content_shell_apk.ContentShellActivity"
android:launchMode="singleTask" android:launchMode="singleTask"
...@@ -54,6 +55,9 @@ ...@@ -54,6 +55,9 @@
{% for i in range(num_sandboxed_services) %} {% for i in range(num_sandboxed_services) %}
<service android:name="org.chromium.content.app.SandboxedProcessService{{ i }}" <service android:name="org.chromium.content.app.SandboxedProcessService{{ i }}"
android:process=":sandboxed_process{{ i }}" android:process=":sandboxed_process{{ i }}"
{% if (i == 0) %}
android:useAppZygote="true"
{% endif %}
android:isolatedProcess="true" android:isolatedProcess="true"
android:exported="false" /> android:exported="false" />
{% endfor %} {% endfor %}
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment