Skip to content

Commit

Permalink
Remaining changes; minSdk 19 (#573)
Browse files Browse the repository at this point in the history
  • Loading branch information
gthea authored Dec 11, 2023
2 parents 53d9f19 + afee180 commit 7cf78bc
Show file tree
Hide file tree
Showing 12 changed files with 174 additions and 35 deletions.
6 changes: 2 additions & 4 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ apply plugin: 'signing'
apply plugin: 'kotlin-android'

ext {
splitVersion = '3.5.0'
splitVersion = '3.5.1-alpha-1'
}

android {
Expand All @@ -31,7 +31,7 @@ android {

defaultConfig {

minSdk 15
minSdk 19
targetSdk 31
multiDexEnabled true

Expand Down Expand Up @@ -100,7 +100,6 @@ dependencies {
def gsonVersion = '2.10.1'
def guavaVersion = '32.1.3-android'
def snakeYamlVersion = '2.2'
def okHttpVersion = '3.12.13'
def playServicesVersion = '18.2.0'
def multidexVersion = '2.0.1'

Expand Down Expand Up @@ -131,7 +130,6 @@ dependencies {
implementation "com.google.guava:guava:$guavaVersion"

implementation "org.yaml:snakeyaml:$snakeYamlVersion"
implementation "com.squareup.okhttp3:okhttp:$okHttpVersion"
implementation "com.google.android.gms:play-services-base:$playServicesVersion"
implementation "androidx.multidex:multidex:$multidexVersion"

Expand Down
2 changes: 0 additions & 2 deletions deps.txt
Original file line number Diff line number Diff line change
Expand Up @@ -64,8 +64,6 @@ releaseRuntimeClasspath - Runtime classpath of /release.
| +--- org.checkerframework:checker-qual:3.37.0
| \--- com.google.errorprone:error_prone_annotations:2.21.1
+--- org.yaml:snakeyaml:2.2
+--- com.squareup.okhttp3:okhttp:3.12.13
| \--- com.squareup.okio:okio:1.15.0
+--- com.google.android.gms:play-services-base:18.2.0
| +--- androidx.collection:collection:1.0.0 (*)
| +--- androidx.core:core:1.2.0 -> 1.6.0 (*)
Expand Down
3 changes: 1 addition & 2 deletions src/androidTest/java/tests/integration/ProxyFactoryTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
import android.content.Context;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.test.platform.app.InstrumentationRegistry;

import org.junit.After;
Expand Down Expand Up @@ -207,7 +206,7 @@ public MockResponse dispatch(RecordedRequest request) {
return new MockResponse().setResponseCode((request.getHeader("Proxy-Authorization") != null) ? 200 : 407).setBody(mSplitChanges);
} else if (requestLine.contains("auth")) {
authLatch.countDown();
return new MockResponse().setResponseCode((request.getHeader("Proxy-Authorization") != null) ? 200 : 407).setBody("{}");
return new MockResponse().setResponseCode((request.getHeader("Proxy-Authorization") != null) ? 200 : 407).setBody(IntegrationHelper.streamingDisabledToken());
} else if (requestLine.contains("Impressions")) {
eventsLatch.countDown();
return new MockResponse().setResponseCode((request.getHeader("Proxy-Authorization") != null) ? 200 : 407).setBody("{}");
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package io.split.android.client.network;
package tests.service;

import org.junit.Assert;
import org.junit.Before;
Expand All @@ -7,6 +7,8 @@
import java.net.URI;
import java.net.URISyntaxException;

import io.split.android.client.network.UrlSanitizerImpl;

public class UrlSanitizerTest {

private static final String ORIGIN_URI_STRING = "https://api.split.io:8001/path/Segment/test%2Fuser?queryParam1=value1&queryParam2=value2#fragment";
Expand Down
3 changes: 2 additions & 1 deletion src/main/java/io/split/android/client/SplitFactoryImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,8 @@ private SplitFactoryImpl(String apiToken, Key key, SplitClientConfig config,
.setProxy(config.proxy())
.setDevelopmentSslConfig(config.developmentSslConfig())
.setContext(context)
.setProxyAuthenticator(config.authenticator()).build();
.setProxyAuthenticator(config.authenticator())
.build();
} else {
defaultHttpClient = httpClient;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,21 +1,22 @@
package io.split.android.client.network;

public abstract class BaseHttpResponseImpl implements BaseHttpResponse {
private static final int HTTP_OK = 200;

private static final int HTTP_OK = 200;
protected static final int HTTP_MULTIPLE_CHOICES = 300;
protected static final int HTTP_UNAUTHORIZED = 401;
protected static final int HTTP_BAD_REQUEST = 400;
protected static final int HTTP_INTERNAL_SERVER_ERROR = 500;

private int mHttpStatus;
private final int mHttpStatus;

protected BaseHttpResponseImpl(int httpStatus) {
mHttpStatus = httpStatus;
}

@Override
public boolean isSuccess() {
return mHttpStatus >= HTTP_OK && mHttpStatus< HTTP_MULTIPLE_CHOICES;
return mHttpStatus >= HTTP_OK && mHttpStatus < HTTP_MULTIPLE_CHOICES;
}

@Override
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
package io.split.android.client.network;

import androidx.annotation.Nullable;

import java.net.URI;
import java.net.URL;

public interface UrlSanitizer {

@Nullable
URL getUrl(URI uri);
}
26 changes: 12 additions & 14 deletions src/main/java/io/split/android/client/network/UrlSanitizerImpl.java
Original file line number Diff line number Diff line change
@@ -1,25 +1,27 @@
package io.split.android.client.network;

import android.net.Uri;

import java.net.MalformedURLException;
import java.net.URI;
import java.net.URL;

import io.split.android.client.utils.logger.Logger;
import okhttp3.HttpUrl;

public class UrlSanitizerImpl implements UrlSanitizer {

private final HttpUrl.Builder mUrlBuilder;
private final Uri.Builder mUrlBuilder;

public UrlSanitizerImpl() {
mUrlBuilder = new HttpUrl.Builder();
mUrlBuilder = new Uri.Builder();
}

@Override
public URL getUrl(URI uri) {

mUrlBuilder
.fragment(uri.getFragment())
.host(uri.getHost())
.encodedAuthority(uri.getAuthority())
.encodedFragment(uri.getFragment())
.scheme(uri.getScheme())
.encodedQuery(uri.getQuery());

Expand All @@ -29,15 +31,11 @@ public URL getUrl(URI uri) {
Logger.e(exception);
}

int port = uri.getPort();
if (port > 0 && port <= 65535) {
try {
mUrlBuilder.port(port);
} catch (IllegalArgumentException exception) {
Logger.e(exception);
}
try {
return new URL(mUrlBuilder.build().toString());
} catch (MalformedURLException e) {
Logger.e(e.getMessage());
return null;
}

return mUrlBuilder.build().url();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ public T execute(@NonNull Map<String, Object> params,
}
URI builtUri = uriBuilder.build();
HttpResponse response = mClient.request(builtUri, HttpMethod.GET, null, headers).execute();
Logger.d("Received from: " + builtUri.toString() + " -> " + response.getData());
Logger.v("Received from: " + builtUri.toString() + " -> " + response.getData());
if (!response.isSuccess()) {
throw new IllegalStateException("http return code " + response.getHttpStatus());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ public class EventStreamParser {
* if the line contains any.
* @return Returns true if a blank line meaning the final of an event if found.
*/
@VisibleForTesting
public boolean parseLineAndAppendValue(String streamLine, Map<String, String> messageValues) {

if (streamLine == null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,9 @@ public int status() {

@Override
public void disconnect() {
mIsDisconnectCalled.set(true);
close();
if (!mIsDisconnectCalled.getAndSet(true)) {
close();
}
}

private void close() {
Expand Down Expand Up @@ -101,8 +102,8 @@ public void connect(SseJwtToken token, ConnectionListener connectionListener) {
Map<String, String> values = new HashMap<>();
while ((inputLine = bufferedReader.readLine()) != null) {
if (mEventStreamParser.parseLineAndAppendValue(inputLine, values)) {
if(!isConnectionConfirmed) {
if(mEventStreamParser.isKeepAlive(values) || mSseHandler.isConnectionConfirmed(values)) {
if (!isConnectionConfirmed) {
if (mEventStreamParser.isKeepAlive(values) || mSseHandler.isConnectionConfirmed(values)) {
Logger.d("Streaming connection success");
isConnectionConfirmed = true;
connectionListener.onConnectionSuccess();
Expand Down Expand Up @@ -130,7 +131,7 @@ public void connect(SseJwtToken token, ConnectionListener connectionListener) {
logError("An error has occurred while creating stream Url ", e);
isErrorRetryable = false;
} catch (IOException e) {
logError("An error has occurred while parsing stream from: ", e);
Logger.d("An error has occurred while parsing stream: " + e.getLocalizedMessage());
isErrorRetryable = true;
} catch (Exception e) {
logError("An unexpected error has occurred while receiving stream events from: ", e);
Expand Down
Loading

0 comments on commit 7cf78bc

Please sign in to comment.