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

Commit af78b27f authored by Marco Ballesio's avatar Marco Ballesio Committed by Android (Google) Code Review
Browse files

Merge "CachedAppOptimizer: freeze/unfreeze binder" into rvc-qpr-dev

parents ebef1b92 3e91d35f
Loading
Loading
Loading
Loading
+30 −0
Original line number Diff line number Diff line
@@ -478,6 +478,21 @@ public final class CachedAppOptimizer {
     */
    private static native void enableFreezerInternal(boolean enable);

    /**
     * Informs binder that a process is about to be frozen. If freezer is enabled on a process via
     * this method, this method will synchronously dispatch all pending transactions to the
     * specified pid. This method will not add significant latencies when unfreezing.
     * After freezing binder calls, binder will block all transaction to the frozen pid, and return
     * an error to the sending process.
     *
     * @param pid the target pid for which binder transactions are to be frozen
     * @param freeze specifies whether to flush transactions and then freeze (true) or unfreeze
     * binder for the specificed pid.
     *
     * @throws RuntimeException in case a flush/freeze operation could not complete successfully.
     */
    private static native void freezeBinder(int pid, boolean freeze);

    /**
     * Determines whether the freezer is supported by this system
     */
@@ -727,6 +742,13 @@ public final class CachedAppOptimizer {
        }

        if (!app.frozen) {
            try {
                freezeBinder(app.pid, false);
            } catch (RuntimeException e) {
                // TODO: it might be preferable to kill the target pid in this case
                Slog.e(TAG_AM, "Unable to unfreeze binder for " + app.pid + " " + app.processName);
            }

            if (DEBUG_FREEZER) {
                Slog.d(TAG_AM, "sync unfroze " + app.pid + " " + app.processName);
            }
@@ -1039,6 +1061,14 @@ public final class CachedAppOptimizer {
                    return;
                }

                try {
                    freezeBinder(pid, true);
                } catch (RuntimeException e) {
                    // TODO: it might be preferable to kill the target pid in this case
                    Slog.e(TAG_AM, "Unable to freeze binder for " + pid + " " + name);
                    return;
                }

                if (pid == 0 || proc.frozen) {
                    // Already frozen or not a real process, either one being
                    // launched or one being killed
+10 −0
Original line number Diff line number Diff line
@@ -29,6 +29,7 @@

#include <nativehelper/JNIHelp.h>
#include <android_runtime/AndroidRuntime.h>
#include <binder/IPCThreadState.h>
#include <jni.h>
#include <processgroup/processgroup.h>

@@ -90,11 +91,20 @@ static void com_android_server_am_CachedAppOptimizer_enableFreezerInternal(
    }
}

static void com_android_server_am_CachedAppOptimizer_freezeBinder(
        JNIEnv *env, jobject clazz, jint pid, jboolean freeze) {

    if (IPCThreadState::freeze(pid, freeze, 100 /* timeout [ms] */) != 0) {
        jniThrowException(env, "java/lang/RuntimeException", "Unable to freeze/unfreeze binder");
    }
}

static const JNINativeMethod sMethods[] = {
    /* name, signature, funcPtr */
    {"compactSystem", "()V", (void*)com_android_server_am_CachedAppOptimizer_compactSystem},
    {"enableFreezerInternal", "(Z)V",
        (void*)com_android_server_am_CachedAppOptimizer_enableFreezerInternal},
    {"freezeBinder", "(IZ)V", (void*)com_android_server_am_CachedAppOptimizer_freezeBinder}
};

int register_android_server_am_CachedAppOptimizer(JNIEnv* env)