Skip to content

Commit

Permalink
Revert "Workaround for Strict mode socket issue: (#443)"
Browse files Browse the repository at this point in the history
This reverts commit 40b8f44
  • Loading branch information
Harsha Sura committed Mar 12, 2020
1 parent 309155f commit e131996
Show file tree
Hide file tree
Showing 3 changed files with 3 additions and 55 deletions.
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
libcore/1.4.1-SNAPSHOT
libcore/1.4.0-SNAPSHOT
v1
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@
import android.support.v4.content.LocalBroadcastManager;

import android.util.Log;

import okhttp3.Call;
import okhttp3.Callback;
import okhttp3.OkHttpClient;
Expand Down Expand Up @@ -226,16 +225,8 @@ private boolean isUserAgentValid(String userAgent) {

private void initializeTelemetryClient() {
if (configurationClient == null) {
if (BuildConfig.DEBUG) {
// Strict mode work around : https://github.com/square/okhttp/issues/3537
this.configurationClient = new ConfigurationClient(applicationContext,
TelemetryUtils.createFullUserAgent(userAgent, applicationContext), sAccessToken.get(),
TelemetryUtils.createOkHttpClientWithStrictModeWorkAround());
} else {
this.configurationClient = new ConfigurationClient(applicationContext,
TelemetryUtils.createFullUserAgent(userAgent, applicationContext), sAccessToken.get(),
new OkHttpClient());
}
this.configurationClient = new ConfigurationClient(applicationContext,
TelemetryUtils.createFullUserAgent(userAgent, applicationContext), sAccessToken.get(), new OkHttpClient());
}

if (certificateBlacklist == null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,17 +8,12 @@
import android.content.pm.ApplicationInfo;
import android.content.pm.PackageInfo;
import android.content.pm.PackageManager;
import android.net.TrafficStats;
import android.os.BatteryManager;
import android.os.Build;
import android.support.annotation.Nullable;
import android.telephony.TelephonyManager;
import android.text.TextUtils;

import java.io.IOException;
import java.net.InetAddress;
import java.net.Socket;
import java.net.UnknownHostException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.HashMap;
Expand All @@ -31,9 +26,6 @@

import com.mapbox.android.core.MapboxSdkInfoForUserAgentGenerator;

import javax.net.SocketFactory;

import okhttp3.OkHttpClient;
import okio.Buffer;

import static com.mapbox.android.telemetry.MapboxTelemetryConstants.MAPBOX_SHARED_PREFERENCES;
Expand Down Expand Up @@ -300,39 +292,4 @@ static boolean adjustWakeUpMode(Context context) {
}
return false;
}

static OkHttpClient createOkHttpClientWithStrictModeWorkAround() {
return new OkHttpClient().newBuilder()
.socketFactory(new SocketFactory() {
SocketFactory socketFactory = SocketFactory.getDefault();
private static final int THREAD_ID = 10000;

@Override
public Socket createSocket(String host, int port) throws IOException, UnknownHostException {
TrafficStats.setThreadStatsTag(THREAD_ID);
return socketFactory.createSocket(host, port);
}

@Override
public Socket createSocket(String host, int port, InetAddress localHost, int localPort) throws
IOException, UnknownHostException {
TrafficStats.setThreadStatsTag(THREAD_ID);
return socketFactory.createSocket(host, port, localHost, localPort);
}

@Override
public Socket createSocket(InetAddress host, int port) throws IOException {
TrafficStats.setThreadStatsTag(THREAD_ID);
return socketFactory.createSocket(host, port);
}

@Override
public Socket createSocket(InetAddress address, int port, InetAddress localAddress, int localPort) throws
IOException {
TrafficStats.setThreadStatsTag(THREAD_ID);
return socketFactory.createSocket(address, port, localAddress, localPort);
}
})
.build();
}
}

0 comments on commit e131996

Please sign in to comment.