Make sure FlipperSocketImpl always sets thread TrafficStats tag
Summary: When looking at some of our logcats in logview, I noticed lots of StrictMode warnings related to a WebSocket not being tagged, and I figured out it was due to FlipperSocketImpl. By making sure TrafficStats stats tag is set no matter if the SSL factory is used or not, it reduces the amount of StrictMode warnings we see. Related diff: D38280819 Differential Revision: D46024367 fbshipit-source-id: 92a0bfcef8698a61ef9b27949a5bc0859e03448f
This commit is contained in:
committed by
Facebook GitHub Bot
parent
4dba523757
commit
03a5aaa3f7
@@ -37,10 +37,10 @@ import java.util.Arrays;
|
|||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
import java.util.concurrent.TimeUnit;
|
import java.util.concurrent.TimeUnit;
|
||||||
|
import javax.net.SocketFactory;
|
||||||
import javax.net.ssl.KeyManagerFactory;
|
import javax.net.ssl.KeyManagerFactory;
|
||||||
import javax.net.ssl.SSLContext;
|
import javax.net.ssl.SSLContext;
|
||||||
import javax.net.ssl.SSLParameters;
|
import javax.net.ssl.SSLParameters;
|
||||||
import javax.net.ssl.SSLSocketFactory;
|
|
||||||
import javax.net.ssl.TrustManager;
|
import javax.net.ssl.TrustManager;
|
||||||
import javax.net.ssl.X509TrustManager;
|
import javax.net.ssl.X509TrustManager;
|
||||||
import org.java_websocket.client.WebSocketClient;
|
import org.java_websocket.client.WebSocketClient;
|
||||||
@@ -79,6 +79,7 @@ class FlipperSocketImpl extends WebSocketClient implements FlipperSocket {
|
|||||||
* certificate exchange.
|
* certificate exchange.
|
||||||
*/
|
*/
|
||||||
FlipperObject authenticationObject = this.mEventHandler.onAuthenticationChallengeReceived();
|
FlipperObject authenticationObject = this.mEventHandler.onAuthenticationChallengeReceived();
|
||||||
|
SocketFactory socketFactory;
|
||||||
if (authenticationObject.contains("certificates_client_path")
|
if (authenticationObject.contains("certificates_client_path")
|
||||||
&& authenticationObject.contains("certificates_client_pass")) {
|
&& authenticationObject.contains("certificates_client_pass")) {
|
||||||
|
|
||||||
@@ -100,17 +101,19 @@ class FlipperSocketImpl extends WebSocketClient implements FlipperSocket {
|
|||||||
sslContext.init(
|
sslContext.init(
|
||||||
kmf.getKeyManagers(), new TrustManager[] {new FlipperTrustManager(cert_ca_path)}, null);
|
kmf.getKeyManagers(), new TrustManager[] {new FlipperTrustManager(cert_ca_path)}, null);
|
||||||
|
|
||||||
SSLSocketFactory factory = sslContext.getSocketFactory();
|
socketFactory = sslContext.getSocketFactory();
|
||||||
|
} else {
|
||||||
|
socketFactory = SocketFactory.getDefault();
|
||||||
|
}
|
||||||
|
|
||||||
this.setSocketFactory(
|
this.setSocketFactory(
|
||||||
new DelegatingSocketFactory(factory) {
|
new DelegatingSocketFactory(socketFactory) {
|
||||||
@Override
|
@Override
|
||||||
protected Socket configureSocket(Socket socket) {
|
protected Socket configureSocket(Socket socket) {
|
||||||
TrafficStats.setThreadStatsTag(SOCKET_TAG);
|
TrafficStats.setThreadStatsTag(SOCKET_TAG);
|
||||||
return socket;
|
return socket;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
|
||||||
|
|
||||||
this.connect();
|
this.connect();
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
|
|||||||
Reference in New Issue
Block a user