Skip to content

Commit 9faa8ba

Browse files
authored
fix: clean up old codes for JobScheduler and Services. (#434)
1 parent 843f9c1 commit 9faa8ba

File tree

22 files changed

+19
-2068
lines changed

22 files changed

+19
-2068
lines changed

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

Lines changed: 3 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@
1616

1717
package com.optimizely.ab.android.sdk;
1818

19-
import android.app.AlarmManager;
2019
import android.content.Context;
2120
import android.content.Intent;
2221
import android.content.pm.PackageInfo;
@@ -29,11 +28,9 @@
2928

3029
import com.optimizely.ab.android.datafile_handler.DatafileHandler;
3130
import com.optimizely.ab.android.datafile_handler.DatafileLoadedListener;
32-
import com.optimizely.ab.android.datafile_handler.DatafileService;
3331
import com.optimizely.ab.android.datafile_handler.DefaultDatafileHandler;
3432
import com.optimizely.ab.android.event_handler.DefaultEventHandler;
3533
import com.optimizely.ab.android.shared.DatafileConfig;
36-
import com.optimizely.ab.android.shared.ServiceScheduler;
3734
import com.optimizely.ab.android.user_profile.DefaultUserProfileService;
3835
import com.optimizely.ab.bucketing.UserProfileService;
3936
import com.optimizely.ab.config.DatafileProjectConfig;
@@ -104,9 +101,9 @@ public void setup() throws Exception {
104101
EventProcessor eventProcessor = mock(EventProcessor.class);
105102
optimizelyManager = OptimizelyManager.builder(testProjectId)
106103
.withLogger(logger)
107-
.withDatafileDownloadInterval(3600L)
104+
.withDatafileDownloadInterval(3600L, TimeUnit.SECONDS)
108105
.withDatafileHandler(defaultDatafileHandler)
109-
.withEventDispatchInterval(3600L)
106+
.withEventDispatchInterval(3600L, TimeUnit.SECONDS)
110107
.withEventHandler(eventHandler)
111108
.withEventProcessor(eventProcessor)
112109
.build(InstrumentationRegistry.getInstrumentation().getTargetContext());
@@ -322,7 +319,7 @@ public void initializeWithNullDatafile() {
322319

323320
@Test
324321
public void initializeAsyncWithNullDatafile() {
325-
optimizelyManager.initialize(InstrumentationRegistry.getInstrumentation().getContext(), new OptimizelyStartListener() {
322+
optimizelyManager.initialize(InstrumentationRegistry.getInstrumentation().getContext(), null, new OptimizelyStartListener() {
326323
@Override
327324
public void onStart(OptimizelyClient optimizely) {
328325
assertNotNull(optimizely);
@@ -410,21 +407,12 @@ public void injectOptimizelyNullListener() {
410407
e.printStackTrace();
411408
}
412409
UserProfileService userProfileService = mock(UserProfileService.class);
413-
ServiceScheduler serviceScheduler = mock(ServiceScheduler.class);
414410
ArgumentCaptor<Intent> captor = ArgumentCaptor.forClass(Intent.class);
415411
ArgumentCaptor<DefaultUserProfileService.StartCallback> callbackArgumentCaptor =
416412
ArgumentCaptor.forClass(DefaultUserProfileService.StartCallback.class);
417413
optimizelyManager.setOptimizelyStartListener(null);
418414

419415
optimizelyManager.injectOptimizely(context, userProfileService, minDatafile);
420-
AlarmManager alarmManager = (AlarmManager) context
421-
.getSystemService(Context.ALARM_SERVICE);
422-
ServiceScheduler.PendingIntentFactory pendingIntentFactory = new ServiceScheduler
423-
.PendingIntentFactory(context);
424-
425-
Intent intent = new Intent(context, DatafileService.class);
426-
intent.putExtra(DatafileService.EXTRA_DATAFILE_CONFIG, optimizelyManager.getDatafileConfig().toJSONString());
427-
serviceScheduler.schedule(intent, optimizelyManager.getDatafileDownloadInterval() * 1000);
428416

429417
try {
430418
executor.awaitTermination(5, TimeUnit.SECONDS);
@@ -433,11 +421,6 @@ public void injectOptimizelyNullListener() {
433421
}
434422

435423
verify(logger).info("No listener to send Optimizely to");
436-
verify(serviceScheduler).schedule(captor.capture(), eq(TimeUnit.HOURS.toMillis(1L)));
437-
438-
Intent intent2 = captor.getValue();
439-
assertTrue(intent2.getComponent().getShortClassName().contains("DatafileService"));
440-
assertEquals(optimizelyManager.getDatafileConfig().toJSONString(), intent2.getStringExtra(DatafileService.EXTRA_DATAFILE_CONFIG));
441424
}
442425

443426
@Test

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

Lines changed: 6 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -32,11 +32,11 @@
3232

3333
import com.optimizely.ab.Optimizely;
3434
import com.optimizely.ab.android.datafile_handler.DatafileHandler;
35+
import com.optimizely.ab.android.datafile_handler.DatafileWorker;
3536
import com.optimizely.ab.android.datafile_handler.DatafileLoadedListener;
36-
import com.optimizely.ab.android.datafile_handler.DatafileService;
3737
import com.optimizely.ab.android.datafile_handler.DefaultDatafileHandler;
3838
import com.optimizely.ab.android.event_handler.DefaultEventHandler;
39-
import com.optimizely.ab.android.event_handler.EventIntentService;
39+
import com.optimizely.ab.android.event_handler.EventDispatcher;
4040
import com.optimizely.ab.android.shared.DatafileConfig;
4141
import com.optimizely.ab.android.user_profile.DefaultUserProfileService;
4242
import com.optimizely.ab.bucketing.UserProfileService;
@@ -425,13 +425,6 @@ void stop(@NonNull Activity activity, @NonNull OptlyActivityLifecycleCallbacks o
425425
activity.getApplication().unregisterActivityLifecycleCallbacks(optlyActivityLifecycleCallbacks);
426426
}
427427

428-
/**
429-
* Called after the {@link DatafileService} is unbound.
430-
* <p>
431-
* Here we just cancel the start listener.
432-
*
433-
* @param context any {@link Context} instance
434-
*/
435428
public void stop(@NonNull Context context) {
436429
if (!isAndroidVersionSupported()) {
437430
return;
@@ -779,7 +772,7 @@ public Builder withErrorHandler(ErrorHandler errorHandler) {
779772
}
780773

781774
/**
782-
* Sets the interval which {@link DatafileService} through the {@link DatafileHandler} will attempt to update the
775+
* Sets the interval which {@link DatafileWorker} will attempt to update the
783776
* cached datafile. If you set this to -1, you disable background updates. If you don't set
784777
* a download interval (or set to less than 0), then no background updates will be scheduled or occur.
785778
* The minimum interval is 15 minutes (enforced by the Android JobScheduler API. See {@link android.app.job.JobInfo})
@@ -794,7 +787,7 @@ public Builder withDatafileDownloadInterval(long interval, TimeUnit timeUnit) {
794787
}
795788

796789
/**
797-
* Sets the interval which {@link DatafileService} through the {@link DatafileHandler} will attempt to update the
790+
* Sets the interval which {@link DatafileWorker} will attempt to update the
798791
* cached datafile. If you set this to -1, you disable background updates. If you don't set
799792
* a download interval (or set to less than 0), then no background updates will be scheduled or occur.
800793
* The minimum interval is 900 secs (15 minutes) (enforced by the Android JobScheduler API. See {@link android.app.job.JobInfo})
@@ -822,7 +815,7 @@ public Builder withEventDispatchInterval(long interval, TimeUnit timeUnit) {
822815
}
823816

824817
/**
825-
* Sets the interval which {@link EventIntentService} will retry event dispatch periodically.
818+
* Sets the interval which {@link EventDispatcher} will retry event dispatch periodically.
826819
* If you don't set this value or set this to -1, periodic retries on event dispatch failures will be disabled (but still queued and retried on next event dispatch request)
827820
*
828821
* @param interval the interval
@@ -835,7 +828,7 @@ public Builder withEventDispatchRetryInterval(long interval, TimeUnit timeUnit)
835828
}
836829

837830
/**
838-
* Sets the interval which {@link EventIntentService} will retry event dispatch periodically.
831+
* Sets the interval which {@link EventDispatcher} will retry event dispatch periodically.
839832
* If you don't set this value or set this to -1, periodic retries on event dispatch failures will be disabled (but still queued and retried on next event dispatch request)
840833
*
841834
* @param interval the interval in milliseconds

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

Lines changed: 0 additions & 84 deletions
This file was deleted.

0 commit comments

Comments
 (0)