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

Commit 405fe4e8 authored by Automerger Merge Worker's avatar Automerger Merge Worker
Browse files

Merge "Introduce thread-local allowBlocking flag" into rvc-dev am: 2a594c9e am: f8353d26

Change-Id: Id7fbdaa4a11001a58894e1999a1dd65f11072be2
parents c1874207 f8353d26
Loading
Loading
Loading
Loading
+21 −0
Original line number Diff line number Diff line
@@ -248,6 +248,27 @@ public class Binder implements IBinder {
        }
    }

    static ThreadLocal<Boolean> sWarnOnBlockingOnCurrentThread =
            ThreadLocal.withInitial(() -> sWarnOnBlocking);

    /**
     * Allow blocking calls for the current thread.  See {@link #allowBlocking}.
     *
     * @hide
     */
    public static void allowBlockingForCurrentThread() {
        sWarnOnBlockingOnCurrentThread.set(false);
    }

    /**
     * Reset the current thread to the default blocking behavior.  See {@link #defaultBlocking}.
     *
     * @hide
     */
    public static void defaultBlockingForCurrentThread() {
        sWarnOnBlockingOnCurrentThread.set(sWarnOnBlocking);
    }

    /**
     * Raw native pointer to JavaBBinderHolder object. Owned by this Java object. Not null.
     */
+8 −3
Original line number Diff line number Diff line
@@ -479,16 +479,21 @@ public final class BinderProxy implements IBinder {
    public boolean transact(int code, Parcel data, Parcel reply, int flags) throws RemoteException {
        Binder.checkParcel(this, code, data, "Unreasonably large binder buffer");

        if (mWarnOnBlocking && ((flags & FLAG_ONEWAY) == 0)) {
        if (mWarnOnBlocking && ((flags & FLAG_ONEWAY) == 0)
                && Binder.sWarnOnBlockingOnCurrentThread.get()) {

            // For now, avoid spamming the log by disabling after we've logged
            // about this interface at least once
            mWarnOnBlocking = false;

            if (Build.IS_USERDEBUG) {
                // Log this as a WTF on userdebug builds.
                Log.wtf(Binder.TAG, "Outgoing transactions from this process must be FLAG_ONEWAY",
                Log.wtf(Binder.TAG,
                        "Outgoing transactions from this process must be FLAG_ONEWAY",
                        new Throwable());
            } else {
                Log.w(Binder.TAG, "Outgoing transactions from this process must be FLAG_ONEWAY",
                Log.w(Binder.TAG,
                        "Outgoing transactions from this process must be FLAG_ONEWAY",
                        new Throwable());
            }
        }
+7 −1
Original line number Diff line number Diff line
@@ -20,6 +20,7 @@ import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.net.Uri;
import android.os.Binder;
import android.util.EventLog;
import android.util.Slog;

@@ -134,7 +135,12 @@ public class ConfigUpdateInstallReceiver extends BroadcastReceiver {

    private BufferedInputStream getAltContent(Context c, Intent i) throws IOException {
        Uri content = getContentFromIntent(i);
        Binder.allowBlockingForCurrentThread();
        try {
            return new BufferedInputStream(c.getContentResolver().openInputStream(content));
        } finally {
            Binder.defaultBlockingForCurrentThread();
        }
    }

    private byte[] getCurrentContent() {