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

Change-Id: I7f4f3ecf1fcaad360210f778641522f89e405946
This commit is contained in:
Automerger Merge Worker
2020-03-09 20:24:58 +00:00
3 changed files with 36 additions and 4 deletions

View File

@@ -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.
*/

View File

@@ -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());
}
}

View File

@@ -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);
return new BufferedInputStream(c.getContentResolver().openInputStream(content));
Binder.allowBlockingForCurrentThread();
try {
return new BufferedInputStream(c.getContentResolver().openInputStream(content));
} finally {
Binder.defaultBlockingForCurrentThread();
}
}
private byte[] getCurrentContent() {