Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 8be28505 authored by Treehugger Robot's avatar Treehugger Robot Committed by Gerrit Code Review
Browse files

Merge "Create the WebViewZygote and implement WebViewZygoteInit."

parents 03f14bef ded20984
Loading
Loading
Loading
Loading
+49 −0
Original line number Diff line number Diff line
#
# Copyright (C) 2016 The Android Open Source Project
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#      http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#

LOCAL_PATH := $(call my-dir)
include $(CLEAR_VARS)

LOCAL_MODULE := webview_zygote

LOCAL_SRC_FILES := webview_zygote.cpp

LOCAL_SHARED_LIBRARIES := \
	libandroid_runtime \
	libbinder \
	liblog \
	libcutils \
	libutils

LOCAL_LDFLAGS_32 := -Wl,--version-script,art/sigchainlib/version-script32.txt -Wl,--export-dynamic
LOCAL_LDFLAGS_64 := -Wl,--version-script,art/sigchainlib/version-script64.txt -Wl,--export-dynamic

LOCAL_WHOLE_STATIC_LIBRARIES := libsigchain

LOCAL_INIT_RC := webview_zygote32.rc

# Always include the 32-bit version of webview_zygote. If the target is 64-bit,
# also include the 64-bit webview_zygote.
ifeq ($(TARGET_SUPPORTS_64_BIT_APPS),true)
	LOCAL_INIT_RC += webview_zygote64.rc
endif

LOCAL_MULTILIB := both

LOCAL_MODULE_STEM_32 := webview_zygote32
LOCAL_MODULE_STEM_64 := webview_zygote64

include $(BUILD_EXECUTABLE)
+76 −0
Original line number Diff line number Diff line
/*
 * Copyright (C) 2016 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */


#define LOG_TAG "WebViewZygote"

#include <sys/prctl.h>

#include <android_runtime/AndroidRuntime.h>
#include <binder/IPCThreadState.h>
#include <binder/ProcessState.h>
#include <utils/Log.h>
#include <utils/String8.h>
#include <utils/Vector.h>

namespace android {

class WebViewRuntime : public AndroidRuntime {
public:
    WebViewRuntime(char* argBlockStart, size_t argBlockSize)
        : AndroidRuntime(argBlockStart, argBlockSize) {}

    ~WebViewRuntime() override {}

    void onStarted() override {
        // Nothing to do since this is a zygote server.
    }

    void onVmCreated(JNIEnv*) override {
        // Nothing to do when the VM is created in the zygote.
    }

    void onZygoteInit() override {
        // Called after a new process is forked.
        sp<ProcessState> proc = ProcessState::self();
        proc->startThreadPool();
    }

    void onExit(int code) override {
        IPCThreadState::self()->stopProcess();
        AndroidRuntime::onExit(code);
    }
};

}  // namespace android

int main(int argc, char* const argv[]) {
    if (prctl(PR_SET_NO_NEW_PRIVS, 1, 0, 0, 0) < 0) {
        LOG_ALWAYS_FATAL("PR_SET_NO_NEW_PRIVS failed: %s", strerror(errno));
        return 12;
    }

    size_t argBlockSize = 0;
    for (int i = 0; i < argc; ++i) {
        argBlockSize += strlen(argv[i]) + 1;
    }

    android::WebViewRuntime runtime(argv[0], argBlockSize);
    runtime.addOption("-Xzygote");

    android::Vector<android::String8> args;
    runtime.start("com.android.internal.os.WebViewZygoteInit", args, /*zygote=*/ true);
}
+22 −0
Original line number Diff line number Diff line
#
# Copyright (C) 2016 The Android Open Source Project
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#      http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#

service webview_zygote32 /system/bin/webview_zygote32
    user webview_zygote
    socket webview_zygote stream 660 webview_zygote system

on property:init.svc.zygote=stopped
    stop webview_zygote32
+22 −0
Original line number Diff line number Diff line
#
# Copyright (C) 2016 The Android Open Source Project
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#      http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#

service webview_zygote64 /system/bin/webview_zygote64
    user webview_zygote
    socket webview_zygote stream 660 webview_zygote system

on property:init.svc.zygote=stopped
    stop webview_zygote64
+23 −0
Original line number Diff line number Diff line
@@ -18,6 +18,7 @@ package android.os;

import android.system.Os;
import android.util.Log;
import android.webkit.WebViewZygote;
import dalvik.system.VMRuntime;

/**
@@ -130,6 +131,12 @@ public class Process {
     */
    public static final int CAMERASERVER_UID = 1047;

    /**
     * Defines the UID/GID for the WebView zygote process.
     * @hide
     */
    public static final int WEBVIEW_ZYGOTE_UID = 1051;

    /**
     * Defines the start of a range of UIDs (and GIDs), going from this
     * number to {@link #LAST_APPLICATION_UID} that are reserved for assigning
@@ -417,6 +424,22 @@ public class Process {
                    abi, instructionSet, appDataDir, zygoteArgs);
    }

    /** @hide */
    public static final ProcessStartResult startWebView(final String processClass,
                                  final String niceName,
                                  int uid, int gid, int[] gids,
                                  int debugFlags, int mountExternal,
                                  int targetSdkVersion,
                                  String seInfo,
                                  String abi,
                                  String instructionSet,
                                  String appDataDir,
                                  String[] zygoteArgs) {
        return WebViewZygote.getProcess().start(processClass, niceName, uid, gid, gids,
                    debugFlags, mountExternal, targetSdkVersion, seInfo,
                    abi, instructionSet, appDataDir, zygoteArgs);
    }

    /**
     * Returns elapsed milliseconds of the time this process has run.
     * @return  Returns the number of milliseconds this process has return.
Loading