Skip to content

Commit

Permalink
Crash fixes and network check adjustments. (#123)
Browse files Browse the repository at this point in the history
* Crash fixes and mutation processing logic tweaks.

* Updated change log
  • Loading branch information
scb01 authored and Karthikeyan committed Feb 26, 2019
1 parent d1ab9d1 commit d2495aa
Show file tree
Hide file tree
Showing 7 changed files with 35 additions and 27 deletions.
10 changes: 10 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,15 @@
# Change Log - AWS AppSync SDK for Android

## [Release 2.7.8](https://github.com/awslabs/aws-mobile-appsync-sdk-android/releases/tag/release_v2.7.8)

### Misc. Updates
* `AWSAppSync` now depends on `AWSCore` version `2.12.1` instead of `2.11.0`.

### Bug Fixes

* Adjusted network connectivity check in mutation processing logic. See [issue #108](https://github.com/awslabs/aws-mobile-appsync-sdk-android/issues/108), [issue #121](https://github.com/awslabs/aws-mobile-appsync-sdk-android/issues/121)
* Fixed `NoSuchElementException` in Subscription Reconnection logic. See [issue #114](https://github.com/awslabs/aws-mobile-appsync-sdk-android/issues/114).

## [Release 2.7.7](https://github.com/awslabs/aws-mobile-appsync-sdk-android/releases/tag/release_v2.7.7)

### Bug Fixes
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
// Generated file. Do not edit!
package com.apollographql.android
val VERSION = "2.7.7"
val VERSION = "2.7.8"
4 changes: 2 additions & 2 deletions aws-android-sdk-appsync-tests/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,6 @@ dependencies {
androidTestImplementation project(':aws-android-sdk-appsync')

implementation "com.amazonaws:aws-android-sdk-s3:$aws_version"
compile 'org.eclipse.paho:org.eclipse.paho.client.mqttv3:1.+'
compile 'org.eclipse.paho:org.eclipse.paho.android.service:1.+'
compile 'org.eclipse.paho:org.eclipse.paho.client.mqttv3:1.2.0'
compile 'org.eclipse.paho:org.eclipse.paho.android.service:1.1.1'
}
Original file line number Diff line number Diff line change
Expand Up @@ -817,10 +817,11 @@ public void testMultipleOfflineMutations() {
public void run() {
//Set Wifi Network offline
WifiManager wifiManager = (WifiManager) InstrumentationRegistry.getContext().getSystemService(Context.WIFI_SERVICE);
for (int i = 0; i < 15; i++) {
for (int i = 0; i < 3; i++) {
assertTrue(wifiManager.setWifiEnabled(false));
sleep((int) (3 * 1000 ));
assertTrue(wifiManager.setWifiEnabled(true));
sleep((int) (7 * 1000 ));
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ class AppSyncOfflineMutationManager {
private NetworkUpdateHandler networkUpdateHandler;
private HandlerThread handlerThread;

private Object shouldProcessMutationsLock = new Object();
private final Object shouldProcessMutationsLock = new Object();
private boolean shouldProcessMutations;

InMemoryOfflineMutationManager inMemoryOfflineMutationManager;
Expand Down Expand Up @@ -158,19 +158,12 @@ void addMutationObjectInQueue(InMemoryOfflineMutationObject mutationObject) thro
}

public void processNextInQueueMutation() {
synchronized (shouldProcessMutationsLock) {
if (!shouldProcessMutations ) {
Log.v(TAG,"Thread:[" + Thread.currentThread().getId() +"]: Internet wasn't available. Exiting");
return;
}
}

//Double check to make sure we do have network connectivity, as there can be latency in
// the propagation of the network state through the broadcast receiver.
//Check to make sure we do have network connectivity.
final NetworkInfo info = ((ConnectivityManager) context
.getSystemService(Context.CONNECTIVITY_SERVICE)).getActiveNetworkInfo();

if (info != null && !info.isConnected()) {
if (info == null || !info.isConnected()) {
Log.v(TAG,"Thread:[" + Thread.currentThread().getId() +"]: Internet wasn't available. Exiting");
return;
}
Expand Down Expand Up @@ -263,8 +256,6 @@ public NetworkUpdateHandler(Looper looper) {
@Override
public void handleMessage(Message msg) {
if (msg.what == MSG_CHECK) {
// remove messages of the same type
networkUpdateHandler.removeMessages(MSG_CHECK);

// set shouldProcess to true
Log.d(TAG, "Thread:[" + Thread.currentThread().getId() +"]: Internet CONNECTED.");
Expand Down Expand Up @@ -319,7 +310,7 @@ public NetworkInfoReceiver(Context context, Handler handler) {
public void onReceive(Context context, Intent intent) {
if (ConnectivityManager.CONNECTIVITY_ACTION.equals(intent.getAction())) {
final boolean networkConnected = isNetworkConnected();
handler.sendEmptyMessage(networkConnected ? MSG_CHECK : MSG_DISCONNECT);
handler.sendEmptyMessage(networkConnected ? MSG_CHECK : MSG_DISCONNECT);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@

import java.util.ArrayList;
import java.util.HashSet;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Set;
Expand Down Expand Up @@ -418,7 +419,7 @@ public void setScalarTypeAdapters(ScalarTypeAdapters scalarTypeAdapters) {

//Reconnection management
Thread reconnectThread = null;
Object reconnectionLock = new Object();
final Object reconnectionLock = new Object();
boolean reconnectionInProgress = false;
private CountDownLatch reconnectCountdownLatch = null;

Expand All @@ -438,25 +439,30 @@ public void run() {
while (reconnectionInProgress) {
waitMillis = RetryInterceptor.calculateBackoff(retryCount);
try {
Log.v(TAG, "Subscription Infrastructure: Sleeping for [" + (waitMillis/1000)+ "] seconds");
Log.v(TAG, "Subscription Infrastructure: Sleeping for [" + (waitMillis)+ "] ms");
Thread.sleep(waitMillis);
}
catch (InterruptedException ie) {
Log.v(TAG, "SubscriptionInfrastructure: Thread.sleep was interrupted in the exponential backoff for reconnects");
}
//Grab any non canceled subscription object to retry.
SubscriptionObject subscriptionToRetry = null;
for (SubscriptionObject subscriptionObject : subscriptionsById.values()) {
if (!subscriptionObject.isCancelled()) {
subscriptionToRetry = subscriptionObject;
AppSyncSubscriptionCall.Callback callback = null;

synchronized (subscriptionsByIdLock) {
for (SubscriptionObject subscriptionObject : subscriptionsById.values()) {
if (!subscriptionObject.isCancelled() && !subscriptionObject.getListeners().isEmpty()) {
subscriptionToRetry = subscriptionObject;
callback = (AppSyncSubscriptionCall.Callback) subscriptionToRetry.getListeners().iterator().next();
break;
}
}
}

//Initiate Retry if required
if (subscriptionToRetry != null) {
if (subscriptionToRetry != null && callback != null ) {
Log.v(TAG, "Subscription Infrastructure: Attempting to reconnect");
reconnectCountdownLatch = new CountDownLatch(1);
mApolloClient.subscribe(subscriptionToRetry.subscription).execute((AppSyncSubscriptionCall.Callback) subscriptionToRetry.getListeners().iterator().next());
mApolloClient.subscribe(subscriptionToRetry.subscription).execute(callback);

try {
reconnectCountdownLatch.await(1, TimeUnit.MINUTES);
Expand Down
4 changes: 2 additions & 2 deletions gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ org.gradle.jvmargs=-Xmx1536m
org.gradle.parallel=true

GROUP=com.amazonaws
VERSION_NAME=2.7.7
AWS_CORE_SDK_VERSION=2.11.0
VERSION_NAME=2.7.8
AWS_CORE_SDK_VERSION=2.12.1

POM_URL=https://github.com/awslabs/aws-mobile-appsync-sdk-android
POM_SCM_URL=https://github.com/awslabs/aws-mobile-appsync-sdk-android
Expand Down

0 comments on commit d2495aa

Please sign in to comment.