Skip to content

Commit

Permalink
fix: remove unnecessary block
Browse files Browse the repository at this point in the history
  • Loading branch information
arifBurakDemiray committed Sep 27, 2023
1 parent ba494ce commit 9af3320
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 78 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -67,9 +67,9 @@ private JSONObject doInBackground(String requestData, String customEndpoint, Tra
request.endpoint(customEndpoint);
//getting connection ready
try {
connection = cp.connection(request);
connection = cp.connection(request, null);
} catch (IOException e) {
L.e("[ImmediateRequestMaker] IOException while preparing remote config update request :[" + e.toString() + "]");
L.e("[ImmediateRequestMaker] IOException while preparing remote config update request :[" + e + "]");
return null;
}
//connecting
Expand Down
82 changes: 6 additions & 76 deletions sdk-java/src/main/java/ly/count/sdk/java/internal/Transport.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
import java.net.HttpURLConnection;
import java.net.URI;
import java.net.URL;
import java.nio.charset.StandardCharsets;
import java.security.KeyFactory;
import java.security.KeyStore;
import java.security.NoSuchAlgorithmException;
Expand Down Expand Up @@ -67,8 +66,8 @@ public Transport() {
}

/**
* @param config
* @throws IllegalArgumentException
* @param config configuration to use
* @throws IllegalArgumentException if certificate exception happens
* @see ModuleBase#init(InternalConfig, Log)
*/
public void init(InternalConfig config, Log logger) throws IllegalArgumentException {
Expand All @@ -92,13 +91,6 @@ public void init(InternalConfig config, Log logger) throws IllegalArgumentExcept
}
}

// void onContext(android.content.Ctx context) {
// ConnectivityManager connectivityManager = (ConnectivityManager) context.getSystemService(android.content.Ctx.CONNECTIVITY_SERVICE);
// NetworkInfo activeNetInfo = connectivityManager.getActiveNetworkInfo();
// NetworkInfo mobNetInfo = connectivityManager.getNetworkInfo( ConnectivityManager.TYPE_MOBILE );
// https://stackoverflow.com/questions/1783117/network-listener-android
// }

/**
* For testing purposes
*/
Expand Down Expand Up @@ -213,69 +205,6 @@ HttpURLConnection connection(final Request request, final User user) throws IOEx
return connection;
}

/**
* Open connection for particular request: choose GET or POST, choose multipart or urlencoded if POST,
* set SSL context, calculate and add checksum, load and send user picture if needed.
*
* @param request request to send
* @return connection, not {@link HttpURLConnection} yet
* @throws IOException from {@link HttpURLConnection} in case of error
*/
HttpURLConnection connection(final Request request) throws IOException {
String endpoint = request.params.remove(Request.ENDPOINT);
if (endpoint == null) {
endpoint = "/i?";
}

String path = config.getServerURL().toString() + endpoint;
boolean usingGET = !config.isUsePOST() && request.isGettable(config.getServerURL());

if (usingGET && config.getParameterTamperingProtectionSalt() != null) {
request.params.add(CHECKSUM, Utils.digestHex(PARAMETER_TAMPERING_DIGEST, request.params + config.getParameterTamperingProtectionSalt(), L));
}

HttpURLConnection connection = openConnection(path, request.params.toString(), usingGET);
connection.setConnectTimeout(1000 * config.getNetworkConnectionTimeout());
connection.setReadTimeout(1000 * config.getNetworkReadTimeout());

if (connection instanceof HttpsURLConnection && sslContext != null) {
HttpsURLConnection https = (HttpsURLConnection) connection;
https.setSSLSocketFactory(sslContext.getSocketFactory());
}

if (!usingGET) {
OutputStream output = null;
PrintWriter writer = null;
try {
if (config.getParameterTamperingProtectionSalt() != null) {
request.params.add(CHECKSUM, Utils.digestHex(PARAMETER_TAMPERING_DIGEST, request.params + config.getParameterTamperingProtectionSalt(), L));
}
connection.setRequestProperty("Content-Type", "application/x-www-form-urlencoded");

output = connection.getOutputStream();
writer = new PrintWriter(new OutputStreamWriter(output, StandardCharsets.UTF_8), true);

writer.write(request.params.toString());
writer.flush();
} finally {
if (writer != null) {
try {
writer.close();
} catch (Throwable ignored) {
}
}
if (output != null) {
try {
output.close();
} catch (Throwable ignored) {
}
}
}
}

return connection;
}

void addMultipart(OutputStream output, PrintWriter writer, String boundary, String contentType, String name, String value, Object file) throws IOException {
writer.append("--").append(boundary).append(Utils.CRLF);
if (file != null) {
Expand All @@ -294,6 +223,7 @@ void addMultipart(OutputStream output, PrintWriter writer, String boundary, Stri
}

byte[] pictureData(User user, String picture) throws IOException {
if (user == null) return null;
byte[] data;
if (UserEditorImpl.PICTURE_IN_USER_PROFILE.equals(picture)) {
data = user.picture();
Expand Down Expand Up @@ -534,7 +464,7 @@ public void checkClientTrusted(X509Certificate[] chain, String authType) throws

@Override
public void checkServerTrusted(X509Certificate[] chain, String authType) throws CertificateException {
if (keyPins.size() == 0 && certPins.size() == 0) {
if (keyPins.isEmpty() && certPins.isEmpty()) {
return;
}

Expand All @@ -555,8 +485,8 @@ public void checkServerTrusted(X509Certificate[] chain, String authType) throws
defaultTrustManager.checkServerTrusted(chain, authType);
}

byte serverPublicKey[] = chain[0].getPublicKey().getEncoded();
byte serverCertificate[] = chain[0].getEncoded();
byte[] serverPublicKey = chain[0].getPublicKey().getEncoded();
byte[] serverCertificate = chain[0].getEncoded();

for (byte[] key : keyPins) {
if (Arrays.equals(key, serverPublicKey)) {
Expand Down

0 comments on commit 9af3320

Please sign in to comment.