Skip to content

Commit 25f472b

Browse files
authored
fix: support datafile download and events upload for API-16 (#373)
1 parent d2ab6fc commit 25f472b

File tree

29 files changed

+168
-298
lines changed

29 files changed

+168
-298
lines changed

.travis.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ env:
88
- ADB_INSTALL_TIMEOUT=5 # minutes
99
- ANDROID_API=29 # api is same as gradle file
1010
matrix:
11+
- EMULATOR_API=19
1112
- EMULATOR_API=21
1213
- EMULATOR_API=22
1314
android:

android-sdk/src/androidTest/java/com/optimizely/ab/android/sdk/OptimizelyClientEngineTest.java

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/****************************************************************************
2-
* Copyright 2017, Optimizely, Inc. and contributors *
2+
* Copyright 2017,2021, Optimizely, Inc. and contributors *
33
* *
44
* Licensed under the Apache License, Version 2.0 (the "License"); *
55
* you may not use this file except in compliance with the License. *
@@ -34,7 +34,6 @@
3434

3535
@RunWith(AndroidJUnit4.class)
3636
public class OptimizelyClientEngineTest {
37-
@RequiresApi(api = Build.VERSION_CODES.HONEYCOMB_MR2)
3837
@Test
3938
public void testGetClientEngineFromContextAndroidTV() {
4039
Context context = mock(Context.class);
@@ -44,7 +43,6 @@ public void testGetClientEngineFromContextAndroidTV() {
4443
assertEquals(EventBatch.ClientEngine.ANDROID_TV_SDK, OptimizelyClientEngine.getClientEngineFromContext(context));
4544
}
4645

47-
@RequiresApi(api = Build.VERSION_CODES.HONEYCOMB_MR2)
4846
@Test
4947
public void testGetClientEngineFromContextAndroid() {
5048
Context context = mock(Context.class);

android-sdk/src/androidTest/java/com/optimizely/ab/android/sdk/OptimizelyManagerTest.java

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,8 @@
2323
import android.content.pm.PackageManager;
2424
import android.os.Build;
2525

26-
import androidx.annotation.RequiresApi;
2726
import androidx.test.ext.junit.runners.AndroidJUnit4;
27+
import androidx.test.filters.SdkSuppress;
2828
import androidx.test.platform.app.InstrumentationRegistry;
2929

3030
import com.optimizely.ab.android.datafile_handler.DatafileHandler;
@@ -356,7 +356,6 @@ public void stop() {
356356
assertNull(optimizelyManager.getOptimizelyStartListener());
357357
}
358358

359-
@RequiresApi(api = Build.VERSION_CODES.HONEYCOMB)
360359
@Test
361360
public void injectOptimizely() {
362361
Context context = mock(Context.class);
@@ -377,7 +376,6 @@ public void injectOptimizely() {
377376

378377
}
379378

380-
@RequiresApi(api = Build.VERSION_CODES.HONEYCOMB)
381379
@Test
382380
public void injectOptimizelyWithDatafileLisener() {
383381
Context context = mock(Context.class);
@@ -398,7 +396,7 @@ public void injectOptimizelyWithDatafileLisener() {
398396
}
399397

400398
@Test
401-
@RequiresApi(api = Build.VERSION_CODES.LOLLIPOP)
399+
@SdkSuppress(minSdkVersion = Build.VERSION_CODES.LOLLIPOP)
402400
public void injectOptimizelyNullListener() {
403401
Context context = mock(Context.class);
404402
PackageManager packageManager = mock(PackageManager.class);
@@ -442,7 +440,6 @@ public void injectOptimizelyNullListener() {
442440
assertEquals(optimizelyManager.getDatafileConfig().toJSONString(), intent2.getStringExtra(DatafileService.EXTRA_DATAFILE_CONFIG));
443441
}
444442

445-
@RequiresApi(api = Build.VERSION_CODES.HONEYCOMB)
446443
@Test
447444
public void injectOptimizelyHandlesInvalidDatafile() {
448445
Context context = mock(Context.class);
@@ -472,7 +469,6 @@ public void injectOptimizelyHandlesInvalidDatafile() {
472469
assertFalse(optimizelyManager.getOptimizely().isValid());
473470
}
474471

475-
@RequiresApi(api = Build.VERSION_CODES.HONEYCOMB)
476472
@Test
477473
public void injectOptimizelyDoesNotDuplicateCallback() {
478474
Context context = mock(Context.class);

android-sdk/src/main/java/com/optimizely/ab/android/sdk/OptimizelyManager.java

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -398,7 +398,6 @@ private String safeLoadResource(Context context, @RawRes final Integer datafileR
398398

399399
DatafileLoadedListener getDatafileLoadedListener(final Context context, @RawRes final Integer datafileRes) {
400400
return new DatafileLoadedListener() {
401-
@RequiresApi(api = Build.VERSION_CODES.HONEYCOMB)
402401
@Override
403402
public void onDatafileLoaded(@Nullable String datafile) {
404403
if (datafile != null && !datafile.isEmpty()) {
@@ -516,7 +515,6 @@ private void startDatafileHandler(Context context) {
516515
});
517516
}
518517

519-
@RequiresApi(api = Build.VERSION_CODES.HONEYCOMB)
520518
void injectOptimizely(@NonNull final Context context, final @NonNull UserProfileService userProfileService,
521519
@NonNull final String datafile) {
522520

android-sdk/src/test/java/com/optimizely/ab/android/sdk/OptimizelyManagerDatafileServiceConnectionTest.java

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/****************************************************************************
2-
* Copyright 2016, Optimizely, Inc. and contributors *
2+
* Copyright 2016,2021, Optimizely, Inc. and contributors *
33
* *
44
* Licensed under the Apache License, Version 2.0 (the "License"); *
55
* you may not use this file except in compliance with the License. *
@@ -18,7 +18,6 @@
1818

1919
import android.content.Context;
2020
import android.os.Build;
21-
import androidx.annotation.RequiresApi;
2221

2322
import org.junit.Before;
2423
import org.junit.Test;
@@ -55,7 +54,6 @@ public void setup() {
5554
datafileServiceConnection = new DatafileServiceConnection(optimizelyManager.getDatafileConfig(), context, optimizelyManager.getDatafileLoadedListener(context,null));
5655
}
5756

58-
@RequiresApi(api = Build.VERSION_CODES.HONEYCOMB)
5957
@Test
6058
public void onServiceConnected() {
6159
DatafileService.LocalBinder binder = mock(DatafileService.LocalBinder.class);
@@ -72,7 +70,6 @@ public void onServiceConnected() {
7270
verify(service).getDatafile(eq(sameString), any(DatafileLoader.class), any(DatafileLoadedListener.class));
7371
}
7472

75-
@RequiresApi(api = Build.VERSION_CODES.HONEYCOMB)
7673
@Test
7774
public void onServiceConnectedNullServiceFromBinder() {
7875
DatafileService.LocalBinder binder = mock(DatafileService.LocalBinder.class);

android-sdk/src/test/java/com/optimizely/ab/android/sdk/OptimizelyManagerOptlyActivityLifecycleCallbacksTest.java

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/****************************************************************************
2-
* Copyright 2016, Optimizely, Inc. and contributors *
2+
* Copyright 2016,2021, Optimizely, Inc. and contributors *
33
* *
44
* Licensed under the Apache License, Version 2.0 (the "License"); *
55
* you may not use this file except in compliance with the License. *
@@ -18,7 +18,6 @@
1818

1919
import android.app.Activity;
2020
import android.os.Build;
21-
import androidx.annotation.RequiresApi;
2221

2322
import org.junit.Before;
2423
import org.junit.Test;
@@ -38,13 +37,11 @@ public class OptimizelyManagerOptlyActivityLifecycleCallbacksTest {
3837
@Mock Activity activity;
3938
private OptimizelyManager.OptlyActivityLifecycleCallbacks optlyActivityLifecycleCallbacks;
4039

41-
@RequiresApi(api = Build.VERSION_CODES.ICE_CREAM_SANDWICH)
4240
@Before
4341
public void setup() {
4442
optlyActivityLifecycleCallbacks = new OptimizelyManager.OptlyActivityLifecycleCallbacks(optimizelyManager);
4543
}
4644

47-
@RequiresApi(api = Build.VERSION_CODES.ICE_CREAM_SANDWICH)
4845
@Test
4946
public void onActivityStopped() {
5047
optlyActivityLifecycleCallbacks.onActivityStopped(activity);

build.gradle

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/****************************************************************************
2-
* Copyright 2016-2020, Optimizely, Inc. and contributors *
2+
* Copyright 2016-2021, Optimizely, Inc. and contributors *
33
* *
44
* Licensed under the Apache License, Version 2.0 (the "License"); *
55
* you may not use this file except in compliance with the License. *
@@ -75,26 +75,23 @@ task clean(type: Delete) {
7575

7676
task cleanAllModules () {
7777
logger.info("Running clean for all modules")
78+
dependsOn(':android-sdk:clean', ':event-handler:clean',
79+
':user-profile:clean', ':shared:clean', ':datafile-handler:clean')
7880
}
7981

80-
cleanAllModules.dependsOn(':android-sdk:clean', ':event-handler:clean',
81-
':user-profile:clean', ':shared:clean', ':datafile-handler:clean')
82-
8382
task testAllModules () {
8483
logger.info("Running android tests for all modules")
84+
dependsOn('testAllModulesTravis', ':test-app:connectedAndroidTest')
8585
}
8686

8787
task testAllModulesTravis () {
8888
logger.info("Running android tests for Travis")
89+
dependsOn(':android-sdk:connectedAndroidTest', ':android-sdk:test',
90+
':event-handler:connectedAndroidTest', ':event-handler:test',
91+
':datafile-handler:connectedAndroidTest', ':datafile-handler:test',
92+
':user-profile:connectedAndroidTest', ':shared:connectedAndroidTest')
8993
}
9094

91-
testAllModulesTravis.dependsOn(':android-sdk:connectedAndroidTest', ':android-sdk:test',
92-
':event-handler:connectedAndroidTest', ':event-handler:test',
93-
':datafile-handler:connectedAndroidTest', ':datafile-handler:test',
94-
':user-profile:connectedAndroidTest', ':shared:connectedAndroidTest')
95-
96-
testAllModules.dependsOn('testAllModulesTravis', ':test-app:connectedAndroidTest')
97-
9895
// Publish to MavenCentral
9996

10097
task ship() {

datafile-handler/src/androidTest/java/com/optimizely/ab/android/datafile_handler/DatafileLoaderTest.java

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/****************************************************************************
2-
* Copyright 2016, Optimizely, Inc. and contributors *
2+
* Copyright 2016,2021, Optimizely, Inc. and contributors *
33
* *
44
* Licensed under the Apache License, Version 2.0 (the "License"); *
55
* you may not use this file except in compliance with the License. *
@@ -21,6 +21,7 @@
2121

2222
import androidx.annotation.RequiresApi;
2323
import androidx.test.ext.junit.runners.AndroidJUnit4;
24+
import androidx.test.filters.SdkSuppress;
2425
import androidx.test.platform.app.InstrumentationRegistry;
2526

2627
import com.optimizely.ab.android.shared.Cache;
@@ -57,7 +58,6 @@
5758
/**
5859
* Tests for {@link DatafileLoader}
5960
*/
60-
@RequiresApi(api = Build.VERSION_CODES.HONEYCOMB)
6161
@RunWith(AndroidJUnit4.class)
6262
public class DatafileLoaderTest {
6363

@@ -147,6 +147,8 @@ public void noCacheAndLoadFromCDNFails() {
147147
}
148148

149149
@Test
150+
// flacky with lower API
151+
@SdkSuppress(minSdkVersion = Build.VERSION_CODES.LOLLIPOP)
150152
public void warningsAreLogged() throws IOException {
151153
final ExecutorService executor = Executors.newSingleThreadExecutor();
152154
Cache cache = mock(Cache.class);
@@ -172,6 +174,8 @@ public void warningsAreLogged() throws IOException {
172174
}
173175

174176
@Test
177+
// flacky with lower API
178+
@SdkSuppress(minSdkVersion = Build.VERSION_CODES.LOLLIPOP)
175179
public void debugLogged() throws IOException {
176180
final ExecutorService executor = Executors.newSingleThreadExecutor();
177181
Cache cache = mock(Cache.class);

datafile-handler/src/androidTest/java/com/optimizely/ab/android/datafile_handler/DatafileReschedulerTest.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/****************************************************************************
2-
* Copyright 2016, Optimizely, Inc. and contributors *
2+
* Copyright 2016,2021, Optimizely, Inc. and contributors *
33
* *
44
* Licensed under the Apache License, Version 2.0 (the "License"); *
55
* you may not use this file except in compliance with the License. *
@@ -81,7 +81,6 @@ public void receivedActionBootCompleted() {
8181
verify(logger).info("Received intent with action {}", Intent.ACTION_BOOT_COMPLETED);
8282
}
8383

84-
@TargetApi(Build.VERSION_CODES.HONEYCOMB_MR1)
8584
@Test
8685
public void receivedActionMyPackageReplaced() {
8786
Context context = InstrumentationRegistry.getInstrumentation().getTargetContext();

datafile-handler/src/androidTest/java/com/optimizely/ab/android/datafile_handler/DatafileServiceTest.java

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/****************************************************************************
2-
* Copyright 2016, Optimizely, Inc. and contributors *
2+
* Copyright 2016,2021, Optimizely, Inc. and contributors *
33
* *
44
* Licensed under the Apache License, Version 2.0 (the "License"); *
55
* you may not use this file except in compliance with the License. *
@@ -71,7 +71,6 @@ public void setup() {
7171
executor = Executors.newSingleThreadExecutor();
7272
}
7373

74-
@RequiresApi(api = Build.VERSION_CODES.HONEYCOMB)
7574
@Test
7675
@Ignore
7776
public void testBinding() throws TimeoutException {
@@ -99,7 +98,6 @@ public void testBinding() throws TimeoutException {
9998
assertTrue(datafileService.isBound());
10099
}
101100

102-
@RequiresApi(api = Build.VERSION_CODES.HONEYCOMB)
103101
@Test
104102
public void testValidStart() throws TimeoutException {
105103
Context context = InstrumentationRegistry.getInstrumentation().getTargetContext();
@@ -119,7 +117,6 @@ public void testValidStart() throws TimeoutException {
119117
assertEquals(val, START_FLAG_REDELIVERY);
120118
}
121119

122-
@RequiresApi(api = Build.VERSION_CODES.HONEYCOMB)
123120
@Test
124121
@Ignore
125122
public void testNullIntentStart() throws TimeoutException {
@@ -139,7 +136,6 @@ public void testNullIntentStart() throws TimeoutException {
139136
verify(logger).warn("Data file service received a null intent");
140137
}
141138

142-
@RequiresApi(api = Build.VERSION_CODES.HONEYCOMB)
143139
@Test
144140
@Ignore
145141
public void testNoProjectIdIntentStart() throws TimeoutException {
@@ -159,7 +155,6 @@ public void testNoProjectIdIntentStart() throws TimeoutException {
159155
verify(logger).warn("Data file service received an intent with no project id extra");
160156
}
161157

162-
@RequiresApi(api = Build.VERSION_CODES.HONEYCOMB)
163158
@Test
164159
@Ignore
165160
public void testUnbind() throws TimeoutException {
@@ -180,7 +175,6 @@ public void testUnbind() throws TimeoutException {
180175
verify(logger).info("All clients are unbound from data file service");
181176
}
182177

183-
@RequiresApi(api = Build.VERSION_CODES.HONEYCOMB)
184178
@Test
185179
@Ignore
186180
public void testIntentExtraData(){
@@ -209,7 +203,6 @@ public void testIntentExtraData(){
209203
assertTrue(intent2.getComponent().getShortClassName().contains("DatafileService"));
210204
}
211205

212-
@RequiresApi(api = Build.VERSION_CODES.HONEYCOMB)
213206
@Test
214207
public void testGetDatafileUrl(){
215208
// HARD-CODING link here to make sure we don't unintentionally mess up the datafile version
@@ -218,8 +211,7 @@ public void testGetDatafileUrl(){
218211
String datafileUrl = new DatafileConfig("1", null).getUrl();
219212
assertEquals("https://cdn.optimizely.com/json/1.json", datafileUrl);
220213
}
221-
@
222-
RequiresApi(api = Build.VERSION_CODES.HONEYCOMB)
214+
223215
@Test
224216
public void testGetDatafileEnvironmentUrl(){
225217
// HARD-CODING link here to make sure we don't unintentionally mess up the datafile version

0 commit comments

Comments
 (0)