Search in sources :

Example 1 with Service

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));
}
Also used : Configuration(android.content.res.Configuration) Service(android.app.Service) IntentService(android.app.IntentService)

Example 2 with Service

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));
}
Also used : Configuration(android.content.res.Configuration) Service(android.app.Service)

Example 3 with Service

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();
}
Also used : Handler(android.os.Handler) Service(android.app.Service) Activity(android.app.Activity) Application(android.app.Application) File(java.io.File)

Example 4 with Service

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());
}
Also used : Service(android.app.Service) SyncService(com.onesignal.SyncService) AlarmManager(android.app.AlarmManager) Intent(android.content.Intent) SyncService(com.onesignal.SyncService) Test(org.junit.Test)

Example 5 with Service

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"));
}
Also used : Service(android.app.Service) SyncService(com.onesignal.SyncService) Test(org.junit.Test)

Aggregations

Service (android.app.Service)24 ServiceInfo (android.content.pm.ServiceInfo)12 Intent (android.content.Intent)8 Handler (android.os.Handler)3 SyncService (com.onesignal.SyncService)3 EventManager (roboguice.event.EventManager)3 Activity (android.app.Activity)2 Application (android.app.Application)2 IntentService (android.app.IntentService)2 Context (android.content.Context)2 Configuration (android.content.res.Configuration)2 IBinder (android.os.IBinder)2 Injector (com.google.inject.Injector)2 Test (org.junit.Test)2 SuppressLint (android.annotation.SuppressLint)1 AlarmManager (android.app.AlarmManager)1 Notification (android.app.Notification)1 NotificationManager (android.app.NotificationManager)1 SearchManager (android.app.SearchManager)1 BroadcastReceiver (android.content.BroadcastReceiver)1