Skip to content
This repository was archived by the owner on Feb 17, 2022. It is now read-only.

Commit fe9480d

Browse files
committed
Merge branch 'demo'
2 parents fc44ea4 + b0efa34 commit fe9480d

File tree

9 files changed

+88
-25
lines changed

9 files changed

+88
-25
lines changed

build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ buildscript {
55
google()
66
}
77
dependencies {
8-
classpath 'com.android.tools.build:gradle:3.1.2'
8+
classpath 'com.android.tools.build:gradle:3.1.4'
99
classpath 'org.jfrog.buildinfo:build-info-extractor-gradle:4.7.0'
1010
}
1111
}

sensorsframework_app/build.gradle

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,8 @@ configurations.all {
103103

104104
dependencies {
105105
implementation fileTree(include: '*.jar', dir: 'libs')
106+
implementation 'com.android.support:appcompat-v7:27.1.1'
107+
implementation 'com.android.support:preference-v7:27.1.1'
106108

107109
if (libraryProjectPath.exists() && gradle.useLocal) { // Local project is favoured
108110
implementation project(libraryProjectName)
Lines changed: 62 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,66 @@
11
package org.opendatakit.sensors;
22

3-
import android.app.Application;
4-
import android.test.ApplicationTestCase;
5-
6-
/**
7-
* <a href="http://d.android.com/tools/testing/testing_android.html">Testing Fundamentals</a>
8-
*/
9-
public class ApplicationTest extends ApplicationTestCase<Application> {
10-
public ApplicationTest() {
11-
super(Application.class);
3+
import android.content.Context;
4+
import android.content.Intent;
5+
import android.os.IBinder;
6+
import android.support.test.InstrumentationRegistry;
7+
import android.support.test.rule.ServiceTestRule;
8+
import android.support.test.runner.AndroidJUnit4;
9+
import android.util.Log;
10+
import org.junit.Rule;
11+
import org.junit.Test;
12+
import org.junit.runner.RunWith;
13+
import org.opendatakit.sensors.service.IODKSensorService;
14+
15+
import java.util.concurrent.TimeoutException;
16+
17+
import static org.junit.Assert.assertNotNull;
18+
19+
20+
@RunWith(AndroidJUnit4.class)
21+
public class ApplicationTest {
22+
23+
private final static String LOGTAG = ApplicationTest.class.getCanonicalName();
24+
25+
@Rule
26+
public final ServiceTestRule mServiceRule = new ServiceTestRule();
27+
28+
private IODKSensorService bindToService() {
29+
Context context = InstrumentationRegistry.getContext();
30+
Intent bind_intent = new Intent();
31+
bind_intent.setClassName(SensorsConsts.frameworkPackage, SensorsConsts.frameworkService);
32+
33+
int count = 0;
34+
IODKSensorService sensorService;
35+
try {
36+
IBinder service = null;
37+
while ( service == null ) {
38+
try {
39+
service = mServiceRule.bindService(bind_intent);
40+
} catch (TimeoutException e) {
41+
service = null;
42+
}
43+
if ( service == null ) {
44+
++count;
45+
if ( count % 20 == 0 ) {
46+
Log.i(LOGTAG, "bindToDbService failed for " + count);
47+
}
48+
try {
49+
Thread.sleep(10);
50+
} catch (InterruptedException e) {
51+
}
52+
}
53+
}
54+
sensorService = IODKSensorService.Stub.asInterface(service);
55+
} catch (IllegalArgumentException e) {
56+
sensorService = null;
57+
}
58+
return sensorService;
59+
}
60+
61+
@Test
62+
public void testBinding() {
63+
IODKSensorService serviceInterface = bindToService();
64+
assertNotNull( "bind did not succeed", serviceInterface);
1265
}
1366
}

sensorsframework_app/src/androidTest/java/org/opendatakit/sensors/service/DummySensorTest.java

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ public class DummySensorTest {
3939

4040
@Rule public final ODKServiceTestRule mServiceRule = new ODKServiceTestRule();
4141

42-
public ODKSensorService boundService;
42+
public IODKSensorService boundService;
4343

4444
@Before public void bindToSensorService() {
4545

@@ -56,7 +56,7 @@ public class DummySensorTest {
5656
}
5757

5858
try {
59-
boundService = ODKSensorService.Stub.asInterface(srv);
59+
boundService = IODKSensorService.Stub.asInterface(srv);
6060
} catch (IllegalArgumentException e) {
6161
boundService = null;
6262
}
@@ -75,12 +75,12 @@ public class DummySensorTest {
7575
}
7676

7777
@Test public void testBinding() {
78-
ODKSensorService serviceInterface = boundService;
78+
IODKSensorService serviceInterface = boundService;
7979
assertNotNull(serviceInterface);
8080
}
8181

8282
@Test public void testDummyBuiltInSensorExists() {
83-
ODKSensorService srv = boundService;
83+
IODKSensorService srv = boundService;
8484
assertNotNull(srv);
8585

8686
try {
@@ -91,7 +91,7 @@ public class DummySensorTest {
9191
}
9292

9393
@Test public void testDummyInternalSensorConnected() {
94-
ODKSensorService srv = boundService;
94+
IODKSensorService srv = boundService;
9595
assertNotNull(srv);
9696

9797
try {
@@ -108,7 +108,7 @@ public class DummySensorTest {
108108
}
109109

110110
@Test public void testAccelerometerInternalSensorConnected() {
111-
ODKSensorService srv = boundService;
111+
IODKSensorService srv = boundService;
112112
assertNotNull(srv);
113113

114114
try {
@@ -126,7 +126,7 @@ public class DummySensorTest {
126126

127127
@Test public void testDummyInternalSensorGetSingleDataPoint() {
128128

129-
ODKSensorService srv = boundService;
129+
IODKSensorService srv = boundService;
130130
assertNotNull(srv);
131131

132132
try {
@@ -165,7 +165,7 @@ public class DummySensorTest {
165165

166166
@Test public void testDummyInternalSensorGetSingleDataPointVaryingDelaysInGeneration() {
167167

168-
ODKSensorService srv = boundService;
168+
IODKSensorService srv = boundService;
169169
assertNotNull(srv);
170170

171171
try {

sensorsframework_app/src/main/java/org/opendatakit/sensors/GenericDriverProxy.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
import java.util.ArrayList;
1919
import java.util.List;
2020

21-
import org.opendatakit.sensors.drivers.ODKSensorDriver;
21+
import org.opendatakit.sensors.drivers.IODKSensorDriver;
2222

2323
import android.content.ComponentName;
2424
import android.content.Context;
@@ -39,7 +39,7 @@ public class GenericDriverProxy implements ServiceConnection, DriverCommunicator
3939

4040
public static final String TAG = "GenericDriverProxy";
4141
private Context componentContext;
42-
private ODKSensorDriver sensorDriverProxy;
42+
private IODKSensorDriver sensorDriverProxy;
4343
private boolean isBoundToService;
4444

4545
public GenericDriverProxy(String packageName, String className,
@@ -72,7 +72,7 @@ public void shutdown() {
7272
@Override
7373
public void onServiceConnected(ComponentName className, IBinder service) {
7474
Log.d(TAG, "Bound to SensorDriver");
75-
sensorDriverProxy = ODKSensorDriver.Stub.asInterface(service);
75+
sensorDriverProxy = IODKSensorDriver.Stub.asInterface(service);
7676
isBoundToService = true;
7777
}
7878

sensorsframework_app/src/main/java/org/opendatakit/sensors/manager/WorkerThread.java

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,12 @@
2929
import org.opendatakit.database.data.ColumnDefinition;
3030
import org.opendatakit.database.data.ColumnList;
3131
import org.opendatakit.database.data.OrderedColumns;
32-
import org.opendatakit.database.service.*;
32+
import org.opendatakit.database.service.DbHandle;
33+
import org.opendatakit.database.service.IDbInterface;
34+
import org.opendatakit.database.service.InternalUserDbInterface;
35+
import org.opendatakit.database.service.InternalUserDbInterfaceAidlWrapperImpl;
36+
import org.opendatakit.database.service.UserDbInterface;
37+
import org.opendatakit.database.service.UserDbInterfaceImpl;
3338
import org.opendatakit.exception.ServicesAvailabilityException;
3439
import org.opendatakit.provider.DataTableColumns;
3540
import org.opendatakit.sensors.DataSeries;
@@ -121,7 +126,7 @@ private void doServiceConnected(ComponentName className, IBinder service) {
121126

122127
try {
123128
InternalUserDbInterface internalUserDbInterface = new InternalUserDbInterfaceAidlWrapperImpl
124-
(AidlDbInterface.Stub.asInterface(service));
129+
(IDbInterface.Stub.asInterface(service));
125130
databaseService = new UserDbInterfaceImpl(internalUserDbInterface);
126131
} catch (IllegalArgumentException e) {
127132
databaseService = null;

sensorsframework_app/src/main/java/org/opendatakit/sensors/service/SensorServiceInterface.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@
3333
3434
3535
*/
36-
public class SensorServiceInterface extends ODKSensorService.Stub {
36+
public class SensorServiceInterface extends IODKSensorService.Stub {
3737

3838
private static final String TAG = SensorServiceInterface.class.getSimpleName();
3939

sensorsframework_app/src/test/java/org/opendatakit/sensors/ExampleUnitTest.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,15 @@
11
package org.opendatakit.sensors;
22

33
import org.junit.Test;
4+
import org.junit.runner.RunWith;
5+
import org.junit.runners.JUnit4;
46

57
import static org.junit.Assert.*;
68

79
/**
810
* To work on unit tests, switch the Test Artifact in the Build Variants view.
911
*/
12+
@RunWith(JUnit4.class)
1013
public class ExampleUnitTest {
1114
@Test public void addition_isCorrect() throws Exception {
1215
assertEquals(4, 2 + 2);

settings.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
gradle.ext.gradleConfigVersion = 107
1+
gradle.ext.gradleConfigVersion = 112
22

33
if (!gradle.ext.has('workspacePath')) {
44
def env = System.getProperties();

0 commit comments

Comments
 (0)