Skip to content

Commit

Permalink
improved service manager connection logic.
Browse files Browse the repository at this point in the history
  • Loading branch information
m4gr3d committed Jan 12, 2015
1 parent f644fd6 commit 6efb283
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 11 deletions.
4 changes: 2 additions & 2 deletions ClientLib/mobile/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ apply plugin: 'com.android.library'

ext {
PUBLISH_ARTIFACT_ID = '3dr-services-lib'
PUBLISH_VERSION = '2.1.37'
PUBLISH_VERSION = '2.1.39'
PROJECT_DESCRIPTION = "3DR Services Client Library"
PROJECT_LABELS = ['3DR', '3DR Services', 'DroneAPI', 'Android']
PROJECT_LICENSES = ['Apache-2.0']
Expand All @@ -15,7 +15,7 @@ android {
defaultConfig {
minSdkVersion 14
targetSdkVersion 21
versionCode 20137
versionCode 20139
versionName PUBLISH_VERSION
}

Expand Down
Binary file modified ClientLib/mobile/libs/AidlLib.jar
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@
import com.o3dr.services.android.lib.BuildConfig;
import com.o3dr.services.android.lib.model.IDroidPlannerServices;

import java.util.concurrent.atomic.AtomicBoolean;

/**
* Created by fhuya on 11/12/14.
*/
Expand All @@ -36,12 +38,12 @@ public void binderDied() {

@Override
public void onServiceConnected(ComponentName name, IBinder service) {
isServiceConnecting.set(false);

o3drServices = IDroidPlannerServices.Stub.asInterface(service);
try {
final int libVersionCode = o3drServices.getApiVersionCode();
//FIXME: Remove check for the 200010-200020 version range on stable release.
if((libVersionCode >= 200010 && libVersionCode < 200020) ||
(libVersionCode < BuildConfig.VERSION_CODE)){
if(libVersionCode < BuildConfig.VERSION_CODE){
//Prompt the user to update the 3DR Services app.
o3drServices = null;
promptFor3DRServicesUpdate();
Expand All @@ -58,10 +60,13 @@ public void onServiceConnected(ComponentName name, IBinder service) {

@Override
public void onServiceDisconnected(ComponentName name) {
isServiceConnecting.set(false);
notifyServiceInterrupted();
}
};

private final AtomicBoolean isServiceConnecting = new AtomicBoolean(false);

private final Context context;
private ServiceListener serviceListener;
private IDroidPlannerServices o3drServices;
Expand Down Expand Up @@ -93,19 +98,23 @@ public void notifyServiceInterrupted() {
}

public void connect(ServiceListener listener) {
if (serviceListener != null && isServiceConnected())
throw new IllegalStateException("Service is already connected.");
if (serviceListener != null && (isServiceConnecting.get() || isServiceConnected()))
return;

if (listener == null) {
throw new IllegalArgumentException("ServiceListener argument cannot be null.");
}

serviceListener = listener;

if (is3DRServicesInstalled())
context.bindService(serviceIntent, o3drServicesConnection, Context.BIND_AUTO_CREATE);
else
promptFor3DRServicesInstall();
if(!isServiceConnected() && !isServiceConnecting.get()) {
if (is3DRServicesInstalled()) {
isServiceConnecting.set(context.bindService(serviceIntent, o3drServicesConnection,
Context.BIND_AUTO_CREATE));
}
else
promptFor3DRServicesInstall();
}
}

public void disconnect() {
Expand Down

0 comments on commit 6efb283

Please sign in to comment.