Skip to content

Commit 66ccb35

Browse files
committed
Merge pull request #12 from DroidPlanner/droneapi_update
Droneapi update
2 parents 4f7da5d + e40cc70 commit 66ccb35

File tree

17 files changed

+288
-45
lines changed

17 files changed

+288
-45
lines changed

AidlLib/build.gradle

+2-2
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@ android {
77
defaultConfig {
88
minSdkVersion 14
99
targetSdkVersion 21
10-
versionCode 200016
11-
versionName '2.0.16'
10+
versionCode 200018
11+
versionName '2.0.18'
1212
}
1313

1414
defaultPublishConfig "release"
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
package com.o3dr.services.android.lib.model;
2+
3+
import com.o3dr.services.android.lib.drone.connection.ConnectionResult;
4+
5+
/**
6+
* DroneAPI event listener. A valid instance must be provided at api registration.
7+
*/
8+
interface IApiListener {
9+
10+
/**
11+
* Ping the api listener to make sure it's still up and connected.
12+
*/
13+
boolean ping();
14+
15+
/**
16+
* Called when the connection attempt fails.
17+
* @param result Describe why the connection failed.
18+
*/
19+
oneway void onConnectionFailed(in ConnectionResult result);
20+
21+
/**
22+
* Retrieve the version code for the connected client.
23+
*/
24+
int getClientVersionCode();
25+
}

AidlLib/src/com/o3dr/services/android/lib/model/IDroidPlannerServices.aidl

+15
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
package com.o3dr.services.android.lib.model;
33

44
import com.o3dr.services.android.lib.model.IDroneApi;
5+
import com.o3dr.services.android.lib.model.IApiListener;
56

67
/**
78
* Used to establish connection with a drone.
@@ -14,9 +15,11 @@ interface IDroidPlannerServices {
1415
boolean ping();
1516

1617
/**
18+
* TODO: left now for backward compatibility. To be removed in next version.
1719
* Acquire an handle to the droidplanner api.
1820
* @param appId application id for the application acquiring the drone api handle.
1921
* @return IDroneApi object used to interact with the drone.
22+
* @deprecated use {@link #registerDroneApi(IApiListener listener, String appId)} instead.
2023
*/
2124
IDroneApi acquireDroneApi(String appId);
2225

@@ -27,4 +30,16 @@ interface IDroidPlannerServices {
2730
*/
2831
void releaseDroneApi(IDroneApi droneApi);
2932

33+
/**
34+
* Retrieve the version code for the api.
35+
*/
36+
int getApiVersionCode();
37+
38+
/**
39+
* Acquire an handle to the droidplanner api.
40+
* @param listener listener for the DroneAPI events.
41+
* @param appId application id for the application acquiring the drone api handle.
42+
* @return IDroneApi object used to interact with the drone.
43+
*/
44+
IDroneApi registerDroneApi(IApiListener listener, String appId);
3045
}

AidlLib/src/com/o3dr/services/android/lib/model/IObserver.aidl

+1
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ oneway interface IObserver {
1717
void onAttributeUpdated(String attributeEvent, in Bundle eventExtras);
1818

1919
/**
20+
* TODO: left now for backward compatibility. To be removed in next version.
2021
* Called when the connection attempt fails.
2122
* @param result Describe why the connection failed.
2223
*/

ClientLib/mobile/build.gradle

+2-2
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ apply plugin: 'com.android.library'
22

33
ext {
44
PUBLISH_ARTIFACT_ID = '3dr-services-lib'
5-
PUBLISH_VERSION = '2.1.10'
5+
PUBLISH_VERSION = '2.1.14'
66
PROJECT_DESCRIPTION = "3DR Services client library"
77
PROJECT_LABELS = ['3DR', '3DR Services', 'DroneAPI', 'Android']
88
PROJECT_LICENSES = ['Apache-2.0']
@@ -15,7 +15,7 @@ android {
1515
defaultConfig {
1616
minSdkVersion 14
1717
targetSdkVersion 21
18-
versionCode 20110
18+
versionCode 20114
1919
versionName PUBLISH_VERSION
2020
}
2121

ClientLib/mobile/libs/AidlLib.jar

5.58 KB
Binary file not shown.

ClientLib/mobile/src/main/AndroidManifest.xml

+7
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,13 @@
88
android:noHistory="true"
99
android:excludeFromRecents="true"
1010
android:launchMode="singleTask"/>
11+
12+
<activity
13+
android:name=".utils.UpdateServiceDialog"
14+
android:theme="@android:style/Theme.Holo.Light.Dialog.NoActionBar.MinWidth"
15+
android:noHistory="true"
16+
android:excludeFromRecents="true"
17+
android:launchMode="singleTask"/>
1118
</application>
1219

1320
</manifest>

ClientLib/mobile/src/main/java/com/o3dr/android/client/Drone.java

+16-16
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77
import android.os.SystemClock;
88
import android.util.Log;
99

10-
import com.MAVLink.Messages.MAVLinkMessage;
1110
import com.o3dr.android.client.interfaces.DroneListener;
1211
import com.o3dr.services.android.lib.coordinate.LatLong;
1312
import com.o3dr.services.android.lib.drone.attribute.AttributeEvent;
@@ -17,8 +16,6 @@
1716
import com.o3dr.services.android.lib.drone.mission.Mission;
1817
import com.o3dr.services.android.lib.drone.mission.MissionItemType;
1918
import com.o3dr.services.android.lib.drone.mission.item.MissionItem;
20-
import com.o3dr.services.android.lib.drone.mission.item.complex.StructureScanner;
21-
import com.o3dr.services.android.lib.drone.mission.item.complex.Survey;
2219
import com.o3dr.services.android.lib.drone.property.Altitude;
2320
import com.o3dr.services.android.lib.drone.property.Attitude;
2421
import com.o3dr.services.android.lib.drone.property.Battery;
@@ -65,6 +62,7 @@ public class Drone {
6562
private final Handler handler;
6663
private final ServiceManager serviceMgr;
6764
private final DroneObserver droneObserver;
65+
private final DroneApiListener apiListener;
6866
private IDroneApi droneApi;
6967

7068
private ConnectionParameter connectionParameter;
@@ -78,6 +76,7 @@ public class Drone {
7876
public Drone(ServiceManager serviceManager, Handler handler) {
7977
this.handler = handler;
8078
this.serviceMgr = serviceManager;
79+
this.apiListener = new DroneApiListener(this);
8180
this.droneObserver = new DroneObserver(this);
8281
}
8382

@@ -89,7 +88,8 @@ public void start() {
8988
return;
9089

9190
try {
92-
this.droneApi = serviceMgr.get3drServices().acquireDroneApi(serviceMgr.getApplicationId());
91+
this.droneApi = serviceMgr.get3drServices().registerDroneApi(this.apiListener,
92+
serviceMgr.getApplicationId());
9393
} catch (RemoteException e) {
9494
throw new IllegalStateException("Unable to retrieve a valid drone handle.");
9595
}
@@ -178,7 +178,7 @@ public long getFlightTime() {
178178
}
179179

180180
public Gps getGps() {
181-
Gps gps = getAttribute(AttributeType.GPS, Gps.class.getClassLoader());
181+
Gps gps = getAttribute(AttributeType.GPS, Gps.class.getClassLoader());
182182
return gps == null ? new Gps() : gps;
183183
}
184184

@@ -205,7 +205,7 @@ private <T extends Parcelable> T getAttribute(String type, ClassLoader classLoad
205205
T attribute = null;
206206
if (isStarted()) {
207207
Bundle carrier = getAttribute(type);
208-
if(carrier != null) {
208+
if (carrier != null) {
209209
carrier.setClassLoader(classLoader);
210210
attribute = carrier.getParcelable(type);
211211
}
@@ -311,12 +311,12 @@ public ConnectionParameter getConnectionParameter() {
311311
}
312312

313313
public <T extends MissionItem> void buildComplexMissionItem(MissionItem.ComplexItem<T>
314-
complexItem){
315-
if(isStarted()){
316-
try{
314+
complexItem) {
315+
if (isStarted()) {
316+
try {
317317
T missionItem = (T) complexItem;
318318
Bundle payload = missionItem.getType().storeMissionItem(missionItem);
319-
if(payload == null)
319+
if (payload == null)
320320
return;
321321

322322
droneApi.buildComplexMissionItem(payload);
@@ -345,8 +345,8 @@ private void addAttributesObserver(IObserver observer) {
345345
}
346346
}
347347

348-
public void addMavlinkObserver(MavlinkObserver observer){
349-
if(isStarted()){
348+
public void addMavlinkObserver(MavlinkObserver observer) {
349+
if (isStarted()) {
350350
try {
351351
droneApi.addMavlinkObserver(observer);
352352
} catch (RemoteException e) {
@@ -355,8 +355,8 @@ public void addMavlinkObserver(MavlinkObserver observer){
355355
}
356356
}
357357

358-
public void removeMavlinkObserver(MavlinkObserver observer){
359-
if(isStarted()){
358+
public void removeMavlinkObserver(MavlinkObserver observer) {
359+
if (isStarted()) {
360360
try {
361361
droneApi.removeMavlinkObserver(observer);
362362
} catch (RemoteException e) {
@@ -508,8 +508,8 @@ public void sendGuidedPoint(LatLong point, boolean force) {
508508
}
509509
}
510510

511-
public void sendMavlinkMessage(MavlinkMessageWrapper messageWrapper){
512-
if(messageWrapper != null && isStarted()){
511+
public void sendMavlinkMessage(MavlinkMessageWrapper messageWrapper) {
512+
if (messageWrapper != null && isStarted()) {
513513
try {
514514
droneApi.sendMavlinkMessage(messageWrapper);
515515
} catch (RemoteException e) {
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
package com.o3dr.android.client;
2+
3+
import android.os.RemoteException;
4+
5+
import com.o3dr.services.android.lib.BuildConfig;
6+
import com.o3dr.services.android.lib.drone.connection.ConnectionResult;
7+
import com.o3dr.services.android.lib.model.IApiListener;
8+
9+
/**
10+
* Created by fhuya on 12/15/14.
11+
*/
12+
public class DroneApiListener extends IApiListener.Stub {
13+
14+
private final Drone drone;
15+
16+
public DroneApiListener(Drone drone){
17+
this.drone = drone;
18+
}
19+
20+
@Override
21+
public boolean ping() throws RemoteException {
22+
return true;
23+
}
24+
25+
@Override
26+
public void onConnectionFailed(ConnectionResult connectionResult) throws RemoteException {
27+
drone.notifyDroneConnectionFailed(connectionResult);
28+
}
29+
30+
@Override
31+
public int getClientVersionCode() throws RemoteException {
32+
return BuildConfig.VERSION_CODE;
33+
}
34+
}

ClientLib/mobile/src/main/java/com/o3dr/android/client/DroneObserver.java

+1-3
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,7 @@ public DroneObserver(Drone drone) {
1818
}
1919

2020
@Override
21-
public void onConnectionFailed(ConnectionResult result) throws RemoteException {
22-
drone.notifyDroneConnectionFailed(result);
23-
}
21+
public void onConnectionFailed(ConnectionResult result) throws RemoteException {}
2422

2523
@Override
2624
public void onAttributeUpdated(String attributeEvent, Bundle eventExtras) throws

ClientLib/mobile/src/main/java/com/o3dr/android/client/ServiceManager.java

+37-17
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,9 @@
1111

1212
import com.o3dr.android.client.interfaces.ServiceListener;
1313
import com.o3dr.android.client.utils.InstallServiceDialog;
14+
import com.o3dr.android.client.utils.UpdateServiceDialog;
15+
import com.o3dr.services.android.lib.*;
16+
import com.o3dr.services.android.lib.BuildConfig;
1417
import com.o3dr.services.android.lib.model.IDroidPlannerServices;
1518

1619
/**
@@ -26,8 +29,21 @@ public class ServiceManager {
2629

2730
@Override
2831
public void onServiceConnected(ComponentName name, IBinder service) {
29-
o3drServices = IDroidPlannerServices.Stub.asInterface(service);
30-
notifyServiceConnected();
32+
o3drServices = IDroidPlannerServices.Stub.asInterface(service);
33+
try {
34+
final int libVersionCode = o3drServices.getApiVersionCode();
35+
if(libVersionCode < BuildConfig.VERSION_CODE){
36+
//Prompt the user to update the 3DR Services app.
37+
o3drServices = null;
38+
promptFor3DRServicesUpdate();
39+
context.unbindService(o3drServicesConnection);
40+
}
41+
else {
42+
notifyServiceConnected();
43+
}
44+
} catch (RemoteException e) {
45+
notifyServiceInterrupted();
46+
}
3147
}
3248

3349
@Override
@@ -40,7 +56,7 @@ public void onServiceDisconnected(ComponentName name) {
4056
private ServiceListener serviceListener;
4157
private IDroidPlannerServices o3drServices;
4258

43-
public ServiceManager(Context context){
59+
public ServiceManager(Context context) {
4460
this.context = context;
4561
}
4662

@@ -56,60 +72,64 @@ public boolean isServiceConnected() {
5672
}
5773
}
5874

59-
public void notifyServiceConnected(){
60-
if(serviceListener == null)
75+
public void notifyServiceConnected() {
76+
if (serviceListener == null)
6177
return;
6278

6379
serviceListener.onServiceConnected();
6480
}
6581

66-
public void notifyServiceInterrupted(){
67-
if(serviceListener == null)
82+
public void notifyServiceInterrupted() {
83+
if (serviceListener == null)
6884
return;
6985

7086
serviceListener.onServiceInterrupted();
7187
}
7288

7389
public void connect(ServiceListener listener) {
74-
if(serviceListener != null && isServiceConnected())
90+
if (serviceListener != null && isServiceConnected())
7591
throw new IllegalStateException("Service is already connected.");
7692

77-
if(listener == null) {
93+
if (listener == null) {
7894
throw new IllegalArgumentException("ServiceListener argument cannot be null.");
7995
}
8096

8197
serviceListener = listener;
8298

83-
if(is3DRServicesInstalled())
99+
if (is3DRServicesInstalled())
84100
context.bindService(serviceIntent, o3drServicesConnection, Context.BIND_AUTO_CREATE);
85101
else
86102
promptFor3DRServicesInstall();
87103
}
88104

89-
public void disconnect() {
105+
public void disconnect() {
90106
serviceListener = null;
91107
o3drServices = null;
92108
try {
93109
context.unbindService(o3drServicesConnection);
94-
}catch(Exception e){
110+
} catch (Exception e) {
95111
Log.e(TAG, "Error occurred while unbinding from 3DR Services.", e);
96112
}
97-
}
113+
}
98114

99-
String getApplicationId(){
115+
String getApplicationId() {
100116
return context.getPackageName();
101117
}
102118

103-
private boolean is3DRServicesInstalled(){
119+
private boolean is3DRServicesInstalled() {
104120
final ResolveInfo info = context.getPackageManager().resolveService(serviceIntent, 0);
105-
if(info == null)
121+
if (info == null)
106122
return false;
107123

108124
this.serviceIntent.setClassName(info.serviceInfo.packageName, info.serviceInfo.name);
109125
return true;
110126
}
111127

112-
private void promptFor3DRServicesInstall(){
128+
private void promptFor3DRServicesInstall() {
113129
context.startActivity(new Intent(context, InstallServiceDialog.class).addFlags(Intent.FLAG_ACTIVITY_NEW_TASK));
114130
}
131+
132+
private void promptFor3DRServicesUpdate(){
133+
context.startActivity(new Intent(context, UpdateServiceDialog.class).addFlags(Intent.FLAG_ACTIVITY_NEW_TASK));
134+
}
115135
}

0 commit comments

Comments
 (0)