Merge "Make VPN more testable and update NC during network change"
diff --git a/core/java/android/app/ActivityThread.java b/core/java/android/app/ActivityThread.java
index b601420..8bdc54c 100644
--- a/core/java/android/app/ActivityThread.java
+++ b/core/java/android/app/ActivityThread.java
@@ -273,11 +273,6 @@
public static final boolean DEBUG_ORDER = false;
private static final long MIN_TIME_BETWEEN_GCS = 5*1000;
/**
- * If the activity doesn't become idle in time, the timeout will ensure to apply the pending top
- * process state.
- */
- private static final long PENDING_TOP_PROCESS_STATE_TIMEOUT = 1000;
- /**
* The delay to release the provider when it has no more references. It reduces the number of
* transactions for acquiring and releasing provider if the client accesses the provider
* frequently in a short time.
@@ -361,8 +356,6 @@
private final AtomicInteger mNumLaunchingActivities = new AtomicInteger();
@GuardedBy("mAppThread")
private int mLastProcessState = PROCESS_STATE_UNKNOWN;
- @GuardedBy("mAppThread")
- private int mPendingProcessState = PROCESS_STATE_UNKNOWN;
ArrayList<WeakReference<AssistStructure>> mLastAssistStructures = new ArrayList<>();
private int mLastSessionId;
final ArrayMap<IBinder, CreateServiceData> mServicesData = new ArrayMap<>();
@@ -2319,7 +2312,6 @@
if (stopProfiling) {
mProfiler.stopProfiling();
}
- applyPendingProcessState();
return false;
}
}
@@ -3366,16 +3358,7 @@
}
wasCached = isCachedProcessState();
mLastProcessState = processState;
- // Defer the top state for VM to avoid aggressive JIT compilation affecting activity
- // launch time.
- if (processState == ActivityManager.PROCESS_STATE_TOP
- && mNumLaunchingActivities.get() > 0) {
- mPendingProcessState = processState;
- mH.postDelayed(this::applyPendingProcessState, PENDING_TOP_PROCESS_STATE_TIMEOUT);
- } else {
- mPendingProcessState = PROCESS_STATE_UNKNOWN;
- updateVmProcessState(processState);
- }
+ updateVmProcessState(processState);
if (localLOGV) {
Slog.i(TAG, "******************* PROCESS STATE CHANGED TO: " + processState
+ (fromIpc ? " (from ipc" : ""));
@@ -3409,20 +3392,6 @@
VMRuntime.getRuntime().updateProcessState(state);
}
- private void applyPendingProcessState() {
- synchronized (mAppThread) {
- if (mPendingProcessState == PROCESS_STATE_UNKNOWN) {
- return;
- }
- final int pendingState = mPendingProcessState;
- mPendingProcessState = PROCESS_STATE_UNKNOWN;
- // Only apply the pending state if the last state doesn't change.
- if (pendingState == mLastProcessState) {
- updateVmProcessState(pendingState);
- }
- }
- }
-
@Override
public void countLaunchingActivities(int num) {
mNumLaunchingActivities.getAndAdd(num);
diff --git a/core/jni/com_android_internal_os_Zygote.cpp b/core/jni/com_android_internal_os_Zygote.cpp
index 1122c20..3622029 100644
--- a/core/jni/com_android_internal_os_Zygote.cpp
+++ b/core/jni/com_android_internal_os_Zygote.cpp
@@ -94,6 +94,10 @@
#include "nativebridge/native_bridge.h"
+#if defined(__BIONIC__)
+extern "C" void android_reset_stack_guards();
+#endif
+
namespace {
// TODO (chriswailes): Add a function to initialize native Zygote data.
@@ -412,6 +416,7 @@
}
// This signal handler is for zygote mode, since the zygote must reap its children
+NO_STACK_PROTECTOR
static void SigChldHandler(int /*signal_number*/, siginfo_t* info, void* /*ucontext*/) {
pid_t pid;
int status;
@@ -2042,6 +2047,7 @@
static bool gPreloadFdsExtracted = false;
// Utility routine to fork a process from the zygote.
+NO_STACK_PROTECTOR
pid_t zygote::ForkCommon(JNIEnv* env, bool is_system_server,
const std::vector<int>& fds_to_close,
const std::vector<int>& fds_to_ignore,
@@ -2098,6 +2104,11 @@
setpriority(PRIO_PROCESS, 0, PROCESS_PRIORITY_MIN);
}
+#if defined(__BIONIC__)
+ // Reset the stack guard for the new process.
+ android_reset_stack_guards();
+#endif
+
// The child process.
PreApplicationInit();
@@ -2130,6 +2141,7 @@
PreApplicationInit();
}
+NO_STACK_PROTECTOR
static jint com_android_internal_os_Zygote_nativeForkAndSpecialize(
JNIEnv* env, jclass, jint uid, jint gid, jintArray gids, jint runtime_flags,
jobjectArray rlimits, jint mount_external, jstring se_info, jstring nice_name,
@@ -2184,6 +2196,7 @@
return pid;
}
+NO_STACK_PROTECTOR
static jint com_android_internal_os_Zygote_nativeForkSystemServer(
JNIEnv* env, jclass, uid_t uid, gid_t gid, jintArray gids,
jint runtime_flags, jobjectArray rlimits, jlong permitted_capabilities,
@@ -2255,6 +2268,7 @@
* @param is_priority_fork Controls the nice level assigned to the newly created process
* @return child pid in the parent, 0 in the child
*/
+NO_STACK_PROTECTOR
static jint com_android_internal_os_Zygote_nativeForkApp(JNIEnv* env,
jclass,
jint read_pipe_fd,
@@ -2269,6 +2283,7 @@
args_known == JNI_TRUE, is_priority_fork == JNI_TRUE, true);
}
+NO_STACK_PROTECTOR
int zygote::forkApp(JNIEnv* env,
int read_pipe_fd,
int write_pipe_fd,
diff --git a/core/jni/com_android_internal_os_Zygote.h b/core/jni/com_android_internal_os_Zygote.h
index b87396c..15f53e0 100644
--- a/core/jni/com_android_internal_os_Zygote.h
+++ b/core/jni/com_android_internal_os_Zygote.h
@@ -20,6 +20,14 @@
#define LOG_TAG "Zygote"
#define ATRACE_TAG ATRACE_TAG_DALVIK
+/*
+ * All functions that lead to ForkCommon must be marked with the
+ * no_stack_protector attributed. Because ForkCommon changes the stack
+ * protector cookie, all of the guard checks on the frames above ForkCommon
+ * would fail when they are popped.
+ */
+#define NO_STACK_PROTECTOR __attribute__((no_stack_protector))
+
#include <jni.h>
#include <vector>
#include <android-base/stringprintf.h>
diff --git a/core/jni/com_android_internal_os_ZygoteCommandBuffer.cpp b/core/jni/com_android_internal_os_ZygoteCommandBuffer.cpp
index add645de..2b5b8f7 100644
--- a/core/jni/com_android_internal_os_ZygoteCommandBuffer.cpp
+++ b/core/jni/com_android_internal_os_ZygoteCommandBuffer.cpp
@@ -377,6 +377,7 @@
// We only process fork commands if the peer uid matches expected_uid.
// For every fork command after the first, we check that the requested uid is at
// least minUid.
+NO_STACK_PROTECTOR
jboolean com_android_internal_os_ZygoteCommandBuffer_nativeForkRepeatedly(
JNIEnv* env,
jclass,