Merge "Introduce thread-local allowBlocking flag" into rvc-dev am: 2a594c9e64 am: f8353d2653 am: 09c46b77fb
Change-Id: I6bb4b16e4ee1189c22ae4ac2bf923876a7bc34d9
This commit is contained in:
@@ -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.
|
||||
*/
|
||||
|
||||
@@ -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());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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() {
|
||||
|
||||
Reference in New Issue
Block a user