Merge "Introduce thread-local allowBlocking flag" into rvc-dev
This commit is contained in:
committed by
Android (Google) Code Review
commit
2a594c9e64
@@ -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.
|
* 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 {
|
public boolean transact(int code, Parcel data, Parcel reply, int flags) throws RemoteException {
|
||||||
Binder.checkParcel(this, code, data, "Unreasonably large binder buffer");
|
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
|
// For now, avoid spamming the log by disabling after we've logged
|
||||||
// about this interface at least once
|
// about this interface at least once
|
||||||
mWarnOnBlocking = false;
|
mWarnOnBlocking = false;
|
||||||
|
|
||||||
if (Build.IS_USERDEBUG) {
|
if (Build.IS_USERDEBUG) {
|
||||||
// Log this as a WTF on userdebug builds.
|
// 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());
|
new Throwable());
|
||||||
} else {
|
} 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());
|
new Throwable());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -20,6 +20,7 @@ import android.content.BroadcastReceiver;
|
|||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
import android.net.Uri;
|
import android.net.Uri;
|
||||||
|
import android.os.Binder;
|
||||||
import android.util.EventLog;
|
import android.util.EventLog;
|
||||||
import android.util.Slog;
|
import android.util.Slog;
|
||||||
|
|
||||||
@@ -134,7 +135,12 @@ public class ConfigUpdateInstallReceiver extends BroadcastReceiver {
|
|||||||
|
|
||||||
private BufferedInputStream getAltContent(Context c, Intent i) throws IOException {
|
private BufferedInputStream getAltContent(Context c, Intent i) throws IOException {
|
||||||
Uri content = getContentFromIntent(i);
|
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() {
|
private byte[] getCurrentContent() {
|
||||||
|
|||||||
Reference in New Issue
Block a user