Skip to content

Commit a72c95f

Browse files
author
Josh Deffibaugh
committed
Remove bound check in manager
1 parent 7b28a2f commit a72c95f

File tree

2 files changed

+11
-35
lines changed

2 files changed

+11
-35
lines changed

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

Lines changed: 11 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -429,21 +429,18 @@ public void onDataFileLoaded(@Nullable String dataFile) {
429429
AlarmManager alarmManager = (AlarmManager) dataFileService.getApplicationContext().getSystemService(Context.ALARM_SERVICE);
430430
ServiceScheduler.PendingIntentFactory pendingIntentFactory = new ServiceScheduler.PendingIntentFactory(dataFileService.getApplicationContext());
431431
ServiceScheduler serviceScheduler = new ServiceScheduler(alarmManager, pendingIntentFactory, LoggerFactory.getLogger(ServiceScheduler.class));
432-
if (bound) {
433-
if (dataFile != null) {
434-
AndroidUserExperimentRecord userExperimentRecord =
435-
(AndroidUserExperimentRecord) AndroidUserExperimentRecord.newInstance(optimizelyManager.getProjectId(), dataFileService.getApplicationContext());
436-
optimizelyManager.injectOptimizely(dataFileService.getApplicationContext(), userExperimentRecord, serviceScheduler, dataFile);
437-
} else {
438-
// We should always call the callback even with the dummy
439-
// instances. Devs might gate the rest of their app
440-
// based on the loading of Optimizely
441-
OptimizelyStartListener optimizelyStartListener = optimizelyManager.getOptimizelyStartListener();
442-
if (optimizelyStartListener != null) {
443-
optimizelyStartListener.onStart(optimizelyManager.getOptimizely());
444-
}
432+
if (dataFile != null) {
433+
AndroidUserExperimentRecord userExperimentRecord =
434+
(AndroidUserExperimentRecord) AndroidUserExperimentRecord.newInstance(optimizelyManager.getProjectId(), dataFileService.getApplicationContext());
435+
optimizelyManager.injectOptimizely(dataFileService.getApplicationContext(), userExperimentRecord, serviceScheduler, dataFile);
436+
} else {
437+
// We should always call the callback even with the dummy
438+
// instances. Devs might gate the rest of their app
439+
// based on the loading of Optimizely
440+
OptimizelyStartListener optimizelyStartListener = optimizelyManager.getOptimizelyStartListener();
441+
if (optimizelyStartListener != null) {
442+
optimizelyStartListener.onStart(optimizelyManager.getOptimizely());
445443
}
446-
447444
}
448445
}
449446
});

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

Lines changed: 0 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -69,27 +69,6 @@ public void onServiceConnected() {
6969
verify(optimizelyManager).injectOptimizely(any(Context.class), any(AndroidUserExperimentRecord.class), any(ServiceScheduler.class), eq(""));
7070
}
7171

72-
@RequiresApi(api = Build.VERSION_CODES.HONEYCOMB)
73-
@Test
74-
public void onServiceConnectedNotBoundWhenDataFileLoaded() {
75-
DataFileService.LocalBinder binder = mock(DataFileService.LocalBinder.class);
76-
DataFileService service = mock(DataFileService.class);
77-
Context context = mock(Context.class);
78-
when(service.getApplicationContext()).thenReturn(context);
79-
when(binder.getService()).thenReturn(service);
80-
when(optimizelyManager.getProjectId()).thenReturn("1");
81-
ArgumentCaptor<DataFileLoadedListener> captor = ArgumentCaptor.forClass(DataFileLoadedListener.class);
82-
dataFileServiceConnection.onServiceConnected(null, binder);
83-
verify(service).getDataFile(same("1"), any(DataFileLoader.class), captor.capture());
84-
85-
dataFileServiceConnection.onServiceDisconnected(null);
86-
87-
DataFileLoadedListener listener = captor.getValue();
88-
listener.onDataFileLoaded("");
89-
90-
verify(optimizelyManager, never()).injectOptimizely(any(Context.class), any(AndroidUserExperimentRecord.class), any(ServiceScheduler.class), eq(""));
91-
}
92-
9372
@RequiresApi(api = Build.VERSION_CODES.HONEYCOMB)
9473
@Test
9574
public void onServiceConnectedNullServiceFromBinder() {

0 commit comments

Comments
 (0)