From 9af33201ec90298b1866581f9ac786805047f214 Mon Sep 17 00:00:00 2001 From: arifBurakDemiray Date: Wed, 27 Sep 2023 14:28:16 +0300 Subject: [PATCH] fix: remove unnecessary block --- .../java/internal/ImmediateRequestMaker.java | 4 +- .../ly/count/sdk/java/internal/Transport.java | 82 ++----------------- 2 files changed, 8 insertions(+), 78 deletions(-) diff --git a/sdk-java/src/main/java/ly/count/sdk/java/internal/ImmediateRequestMaker.java b/sdk-java/src/main/java/ly/count/sdk/java/internal/ImmediateRequestMaker.java index 60b35fd54..8d2edcd65 100644 --- a/sdk-java/src/main/java/ly/count/sdk/java/internal/ImmediateRequestMaker.java +++ b/sdk-java/src/main/java/ly/count/sdk/java/internal/ImmediateRequestMaker.java @@ -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 diff --git a/sdk-java/src/main/java/ly/count/sdk/java/internal/Transport.java b/sdk-java/src/main/java/ly/count/sdk/java/internal/Transport.java index 721733e08..f431d1349 100644 --- a/sdk-java/src/main/java/ly/count/sdk/java/internal/Transport.java +++ b/sdk-java/src/main/java/ly/count/sdk/java/internal/Transport.java @@ -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; @@ -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 { @@ -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 */ @@ -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) { @@ -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(); @@ -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; } @@ -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)) {