use of android.app.Service in project roboguice by roboguice.
the class RoboIntentService method onConfigurationChanged.
@Override
public void onConfigurationChanged(Configuration newConfig) {
final Configuration currentConfig = getResources().getConfiguration();
super.onConfigurationChanged(newConfig);
eventManager.fire(new OnConfigurationChangedEvent<Service>(this, currentConfig, newConfig));
}
use of android.app.Service in project roboguice by roboguice.
the class RoboService method onConfigurationChanged.
@Override
public void onConfigurationChanged(Configuration newConfig) {
final Configuration currentConfig = getResources().getConfiguration();
super.onConfigurationChanged(newConfig);
eventManager.fire(new OnConfigurationChangedEvent<Service>(this, currentConfig, newConfig));
}
use of android.app.Service in project Conversations by siacs.
the class MemorizingTrustManager method init.
void init(Context m) {
master = m;
masterHandler = new Handler(m.getMainLooper());
notificationManager = (NotificationManager) master.getSystemService(Context.NOTIFICATION_SERVICE);
Application app;
if (m instanceof Application) {
app = (Application) m;
} else if (m instanceof Service) {
app = ((Service) m).getApplication();
} else if (m instanceof Activity) {
app = ((Activity) m).getApplication();
} else
throw new ClassCastException("MemorizingTrustManager context must be either Activity or Service!");
File dir = app.getDir(KEYSTORE_DIR, Context.MODE_PRIVATE);
keyStoreFile = new File(dir + File.separator + KEYSTORE_FILE);
poshCacheDir = app.getFilesDir().getAbsolutePath() + "/posh_cache/";
appKeyStore = loadAppKeyStore();
}
use of android.app.Service in project OneSignal-Android-SDK by OneSignal.
the class MainOneSignalClassRunner method shouldSyncPendingChangesFromSyncService.
@Test
public void shouldSyncPendingChangesFromSyncService() throws Exception {
OneSignalInit();
threadAndTaskWait();
OneSignal.sendTag("key", "value");
// App is swiped away
Service service = Robolectric.buildService(SyncService.class).create().get();
OneSignalPackagePrivateHelper.SyncService_onTaskRemoved(service);
OneSignalPackagePrivateHelper.resetRunnables();
threadAndTaskWait();
Assert.assertEquals(2, ShadowOneSignalRestClient.networkCallCount);
StaticResetHelper.restSetStaticFields();
// There were unsynced changes so service should have been scheduled for a restart.
AlarmManager alarmManager = (AlarmManager) RuntimeEnvironment.application.getSystemService(Context.ALARM_SERVICE);
Assert.assertEquals(1, shadowOf(alarmManager).getScheduledAlarms().size());
Assert.assertEquals(SyncService.class, shadowOf(shadowOf(shadowOf(alarmManager).getNextScheduledAlarm().operation).getSavedIntent()).getIntentClass());
shadowOf(alarmManager).getScheduledAlarms().clear();
// Service is restarted
Intent intent = new Intent();
// TASK_SYNC
intent.putExtra("task", 1);
service = Robolectric.buildService(SyncService.class, intent).startCommand(0, 0).get();
threadAndTaskWait();
Assert.assertEquals("value", ShadowOneSignalRestClient.lastPost.getJSONObject("tags").getString("key"));
Assert.assertEquals(3, ShadowOneSignalRestClient.networkCallCount);
OneSignalInit();
threadAndTaskWait();
// No new changes, don't schedule another restart.
OneSignalPackagePrivateHelper.SyncService_onTaskRemoved(service);
Assert.assertEquals(0, shadowOf(alarmManager).getScheduledAlarms().size());
}
use of android.app.Service in project OneSignal-Android-SDK by OneSignal.
the class MainOneSignalClassRunner method shouldSaveToSyncIfKilledBeforeDelayedCompare.
@Test
public void shouldSaveToSyncIfKilledBeforeDelayedCompare() throws Exception {
OneSignalInit();
threadAndTaskWait();
Service service = Robolectric.buildService(SyncService.class).create().get();
OneSignal.sendTag("key", "value");
// Swipe app away from Recent Apps list, should save unsynced data.
OneSignalPackagePrivateHelper.SyncService_onTaskRemoved(service);
OneSignalPackagePrivateHelper.resetRunnables();
// Network call for android params and player create should have been made.
Assert.assertEquals(2, ShadowOneSignalRestClient.networkCallCount);
// App is re-opened.
StaticResetHelper.restSetStaticFields();
OneSignalInit();
threadAndTaskWait();
// Un-synced tag should now sync.
Assert.assertEquals("value", ShadowOneSignalRestClient.lastPost.getJSONObject("tags").getString("key"));
}
Aggregations