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

Commit c02f068b authored by Riddle Hsu's avatar Riddle Hsu
Browse files

Print exception log of activity task related transaction

If a binder call is not one-way, the exception will be written to the
reply parcel without logging on server side.

If the client catches the exception silently, there is no information
about what is wrong. Even if the client prints the stack trace, the
trace is truncated by Parcel#writeStackTrace that may miss the
important calling path.

Bug: 178438487
Test: build
Change-Id: Icecd4891da8b480cc8a3bf3ae2bd7df24ed4ce45
parent 5f6672f1
Loading
Loading
Loading
Loading
+12 −0
Original line number Diff line number Diff line
@@ -54,6 +54,7 @@ import android.content.res.Configuration;
import android.os.Binder;
import android.os.Bundle;
import android.os.IBinder;
import android.os.Parcel;
import android.os.PersistableBundle;
import android.os.RemoteException;
import android.os.SystemClock;
@@ -99,6 +100,17 @@ class ActivityClientController extends IActivityClientController.Stub {
        mAssistUtils = new AssistUtils(mContext);
    }

    @Override
    public boolean onTransact(int code, Parcel data, Parcel reply, int flags)
            throws RemoteException {
        try {
            return super.onTransact(code, data, reply, flags);
        } catch (RuntimeException e) {
            throw ActivityTaskManagerService.logAndRethrowRuntimeExceptionOnTransact(
                    "ActivityClientController", e);
        }
    }

    @Override
    public void activityIdle(IBinder token, Configuration config, boolean stopProfiling) {
        final long origId = Binder.clearCallingIdentity();
+12 −6
Original line number Diff line number Diff line
@@ -4842,14 +4842,20 @@ public class ActivityTaskManagerService extends IActivityTaskManager.Stub {
        try {
            return super.onTransact(code, data, reply, flags);
        } catch (RuntimeException e) {
            throw logAndRethrowRuntimeExceptionOnTransact(TAG, e);
        }
    }

    /** Provides the full stack traces of non-security exception that occurs in onTransact. */
    static RuntimeException logAndRethrowRuntimeExceptionOnTransact(String name,
            RuntimeException e) {
        if (!(e instanceof SecurityException)) {
                Slog.w(TAG, "Activity Task Manager onTransact aborts "
            Slog.w(TAG, name + " onTransact aborts"
                    + " UID:" + Binder.getCallingUid()
                    + " PID:" + Binder.getCallingPid(), e);
        }
        throw e;
    }
    }

    /**
     * Sets the corresponding {@link DisplayArea} information for the process global
+10 −2
Original line number Diff line number Diff line
@@ -20,6 +20,7 @@ import static android.app.WindowConfiguration.WINDOWING_MODE_FREEFORM;
import static android.app.WindowConfiguration.WINDOWING_MODE_UNDEFINED;

import static com.android.internal.protolog.ProtoLogGroup.WM_DEBUG_WINDOW_ORGANIZER;
import static com.android.server.wm.ActivityTaskManagerService.enforceTaskPermission;
import static com.android.server.wm.DisplayContent.IME_TARGET_LAYERING;
import static com.android.server.wm.WindowOrganizerController.CONTROLLABLE_CONFIGS;
import static com.android.server.wm.WindowOrganizerController.CONTROLLABLE_WINDOW_CONFIGS;
@@ -33,6 +34,7 @@ import android.content.pm.ActivityInfo;
import android.content.pm.ParceledListSlice;
import android.os.Binder;
import android.os.IBinder;
import android.os.Parcel;
import android.os.RemoteException;
import android.util.Slog;
import android.view.SurfaceControl;
@@ -357,8 +359,14 @@ class TaskOrganizerController extends ITaskOrganizerController.Stub {
        mGlobalLock = atm.mGlobalLock;
    }

    private void enforceTaskPermission(String func) {
        mService.enforceTaskPermission(func);
    @Override
    public boolean onTransact(int code, Parcel data, Parcel reply, int flags)
            throws RemoteException {
        try {
            return super.onTransact(code, data, reply, flags);
        } catch (RuntimeException e) {
            throw ActivityTaskManagerService.logAndRethrowRuntimeExceptionOnTransact(TAG, e);
        }
    }

    /**
+11 −0
Original line number Diff line number Diff line
@@ -40,6 +40,7 @@ import android.graphics.PixelFormat;
import android.graphics.Rect;
import android.os.Binder;
import android.os.IBinder;
import android.os.Parcel;
import android.os.RemoteException;
import android.util.ArraySet;
import android.util.Slog;
@@ -111,6 +112,16 @@ class WindowOrganizerController extends IWindowOrganizerController.Stub
        return mTransitionController;
    }

    @Override
    public boolean onTransact(int code, Parcel data, Parcel reply, int flags)
            throws RemoteException {
        try {
            return super.onTransact(code, data, reply, flags);
        } catch (RuntimeException e) {
            throw ActivityTaskManagerService.logAndRethrowRuntimeExceptionOnTransact(TAG, e);
        }
    }

    @Override
    public void applyTransaction(WindowContainerTransaction t) {
        enforceTaskPermission("applyTransaction()");