use of com.optimizely.ab.android.shared.OptlyStorage in project android-sdk by optimizely.
the class ServiceSchedulerTest method setup.
@RequiresApi(api = Build.VERSION_CODES.LOLLIPOP)
@Before
public void setup() {
context = mock(Context.class);
optlyStorage = mock(OptlyStorage.class);
alarmManager = mock(AlarmManager.class);
jobScheduler = mock(JobScheduler.class);
when(context.getApplicationContext()).thenReturn(context);
when(context.getSystemService(Context.ALARM_SERVICE)).thenReturn(alarmManager);
when(context.getSystemService(Context.JOB_SCHEDULER_SERVICE)).thenReturn(jobScheduler);
pendingIntentFactory = mock(ServiceScheduler.PendingIntentFactory.class);
logger = mock(Logger.class);
serviceScheduler = new ServiceScheduler(context, pendingIntentFactory, logger);
}
use of com.optimizely.ab.android.shared.OptlyStorage in project android-sdk by optimizely.
the class DatafileService method onStartCommand.
/**
* @hide
* @see Service#onStartCommand(Intent, int, int)
*/
@Override
public int onStartCommand(Intent intent, int flags, int startId) {
if (intent != null) {
if (intent.hasExtra(EXTRA_DATAFILE_CONFIG)) {
String extraDatafileConfig = intent.getStringExtra(EXTRA_DATAFILE_CONFIG);
DatafileConfig datafileConfig = DatafileConfig.fromJSONString(extraDatafileConfig);
DatafileClient datafileClient = new DatafileClient(new Client(new OptlyStorage(this.getApplicationContext()), LoggerFactory.getLogger(OptlyStorage.class)), LoggerFactory.getLogger(DatafileClient.class));
DatafileCache datafileCache = new DatafileCache(datafileConfig.getKey(), new Cache(this.getApplicationContext(), LoggerFactory.getLogger(Cache.class)), LoggerFactory.getLogger(DatafileCache.class));
String datafileUrl = datafileConfig.getUrl();
DatafileLoader datafileLoader = new DatafileLoader(this, datafileClient, datafileCache, LoggerFactory.getLogger(DatafileLoader.class));
datafileLoader.getDatafile(datafileUrl, null);
} else {
logger.warn("Data file service received an intent with no project id extra");
}
} else {
logger.warn("Data file service received a null intent");
}
return super.onStartCommand(intent, flags, startId);
}
use of com.optimizely.ab.android.shared.OptlyStorage in project android-sdk by optimizely.
the class DatafileServiceConnection method onServiceConnected.
/**
* Get the bound {@link DatafileService} and set it up for download.
*
* @see ServiceConnection#onServiceConnected(ComponentName, IBinder)
*/
@Override
public void onServiceConnected(ComponentName className, IBinder service) {
if (!(service instanceof DatafileService.LocalBinder)) {
return;
}
// We've bound to DatafileService, cast the IBinder and get DatafileService instance
DatafileService.LocalBinder binder = (DatafileService.LocalBinder) service;
final DatafileService datafileService = binder.getService();
if (datafileService != null) {
DatafileClient datafileClient = new DatafileClient(new Client(new OptlyStorage(context.getApplicationContext()), LoggerFactory.getLogger(OptlyStorage.class)), LoggerFactory.getLogger(DatafileClient.class));
DatafileCache datafileCache = new DatafileCache(datafileConfig.getKey(), new Cache(context.getApplicationContext(), LoggerFactory.getLogger(Cache.class)), LoggerFactory.getLogger(DatafileCache.class));
DatafileLoader datafileLoader = new DatafileLoader(context, datafileClient, datafileCache, LoggerFactory.getLogger(DatafileLoader.class));
datafileService.getDatafile(datafileConfig.getUrl(), datafileLoader, listener);
}
bound = true;
}
use of com.optimizely.ab.android.shared.OptlyStorage in project android-sdk by optimizely.
the class DefaultDatafileHandler method downloadDatafile.
/**
* Synchronous call to download the datafile.
* Gets the file on the current thread from the Optimizely CDN.
*
* @param context application context
* @param datafileConfig DatafileConfig for the datafile
* @return a valid datafile or null
*/
public String downloadDatafile(Context context, DatafileConfig datafileConfig) {
DatafileClient datafileClient = new DatafileClient(new Client(new OptlyStorage(context), LoggerFactory.getLogger(OptlyStorage.class)), LoggerFactory.getLogger(DatafileClient.class));
String datafileUrl = datafileConfig.getUrl();
return datafileClient.request(datafileUrl);
}
use of com.optimizely.ab.android.shared.OptlyStorage in project android-sdk by optimizely.
the class DefaultDatafileHandler method storeInterval.
private static void storeInterval(Context context, long interval) {
OptlyStorage storage = new OptlyStorage(context);
storage.saveLong("DATAFILE_INTERVAL", interval);
}
Aggregations