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

Commit faf3e024 authored by Li Li's avatar Li Li
Browse files

dump sender stack for failed binder txn

Currently it's hard to debug why a binder transaction fails and who's
causing the issue. To help debugging this kind of issues, dump the stack
of the sender when the transaction fails.

Bug: 331005349
Test: logcat
Change-Id: I1a032784932ebe10af5f355ec1364a5d68831f2b
parent 0bd33674
Loading
Loading
Loading
Loading
+3 −2
Original line number Diff line number Diff line
@@ -355,7 +355,7 @@ public final class ActivityThread extends ClientTransactionHandler

    private static final String DEFAULT_FULL_BACKUP_AGENT = "android.app.backup.FullBackupAgent";

    private static final long BINDER_CALLBACK_THROTTLE = 10_100L;
    private static final long BINDER_CALLBACK_THROTTLE_MS = 10_100L;
    private long mBinderCallbackLast = -1;

    /**
@@ -7551,12 +7551,13 @@ public final class ActivityThread extends ClientTransactionHandler
            @Override
            public void onTransactionError(int pid, int code, int flags, int err) {
                final long now = SystemClock.uptimeMillis();
                if (now < mBinderCallbackLast + BINDER_CALLBACK_THROTTLE) {
                if (now < mBinderCallbackLast + BINDER_CALLBACK_THROTTLE_MS) {
                    Slog.d(TAG, "Too many transaction errors, throttling freezer binder callback.");
                    return;
                }
                mBinderCallbackLast = now;
                try {
                    Log.wtfStack(TAG, "Binder Transaction Error");
                    mgr.frozenBinderTransactionDetected(pid, code, flags, err);
                } catch (RemoteException ex) {
                    throw ex.rethrowFromSystemServer();
+4 −2
Original line number Diff line number Diff line
@@ -1411,8 +1411,10 @@ static jboolean android_os_BinderProxy_transact(JNIEnv* env, jobject obj,
        return JNI_TRUE;
    }

    env->CallStaticVoidMethod(gBinderOffsets.mClass, gBinderOffsets.mTransactionCallback, getpid(),
                              code, flags, err);
    if (err == FAILED_TRANSACTION) {
        env->CallStaticVoidMethod(gBinderOffsets.mClass, gBinderOffsets.mTransactionCallback,
                                  getpid(), code, flags, err);
    }

    if (err == UNKNOWN_TRANSACTION) {
        return JNI_FALSE;
+3 −3
Original line number Diff line number Diff line
@@ -83,6 +83,8 @@ import com.android.internal.os.ProcLocksReader;
import com.android.internal.util.FrameworkStatsLog;
import com.android.server.ServiceThread;

import dalvik.annotation.optimization.NeverCompile;

import java.io.FileReader;
import java.io.IOException;
import java.io.PrintWriter;
@@ -98,8 +100,6 @@ import java.util.Map;
import java.util.Random;
import java.util.Set;

import dalvik.annotation.optimization.NeverCompile;

public final class CachedAppOptimizer {

    // Flags stored in the DeviceConfig API.
@@ -2633,7 +2633,7 @@ public final class CachedAppOptimizer {
    public void binderError(int debugPid, ProcessRecord app, int code, int flags, int err) {
        Slog.w(TAG_AM, "pid " + debugPid + " " + (app == null ? "null" : app.processName)
                + " sent binder code " + code + " with flags " + flags
                + " to frozen apps and got error " + err);
                + " and got error " + err);

        // Do nothing if the binder error callback is not enabled.
        // That means the frozen apps in a wrong state will be killed when they are unfrozen later.
+11 −0
Original line number Diff line number Diff line
@@ -761,6 +761,9 @@ public final class SystemServer implements Dumpable {
        }
    }

    private static final long BINDER_CALLBACK_THROTTLE_MS = 10_100L;
    private long mBinderCallbackLast = -1;

    private void run() {
        TimingsTraceAndSlog t = new TimingsTraceAndSlog();
        try {
@@ -965,6 +968,14 @@ public final class SystemServer implements Dumpable {
        Binder.setTransactionCallback(new IBinderCallback() {
            @Override
            public void onTransactionError(int pid, int code, int flags, int err) {

                final long now = SystemClock.uptimeMillis();
                if (now < mBinderCallbackLast + BINDER_CALLBACK_THROTTLE_MS) {
                    Slog.d(TAG, "Too many transaction errors, throttling freezer binder callback.");
                    return;
                }
                mBinderCallbackLast = now;
                Slog.wtfStack(TAG, "Binder Transaction Error");
                mActivityManagerService.frozenBinderTransactionDetected(pid, code, flags, err);
            }
        });