Beispiel #1
0
  @Override
  public void onCreate() {
    super.onCreate();

    try {
      cacheManager = createCacheManager(getApplication());
    } catch (CacheCreationException e) {
      Ln.e(e);
      stopSelf();
      return;
    }
    if (cacheManager == null) {
      Ln.e(new CacheCreationException("createCacheManager() can't create a null cacheManager"));
      stopSelf();
      return;
    }

    progressReporter = createRequestRequestListenerNotifier();
    spiceServiceListenerNotifier = createSpiceServiceListenerNotifier();

    final ExecutorService executorService = getExecutorService();
    final NetworkStateChecker networkStateChecker = getNetworkStateChecker();

    requestProcessor = createRequestProcessor(executorService, networkStateChecker);
    requestProcessor.setFailOnCacheError(DEFAULT_FAIL_ON_CACHE_ERROR);

    notification = createDefaultNotification();

    Ln.d("SpiceService instance created.");
  }
Beispiel #2
0
 private void startForeground(final Notification notification) {
   try {
     final Method setForegroundMethod =
         Service.class.getMethod("startForeground", int.class, Notification.class);
     setForegroundMethod.invoke(this, getNotificationId(), notification);
   } catch (final SecurityException e) {
     Ln.e(e, "Unable to start a service in foreground");
   } catch (final NoSuchMethodException e) {
     Ln.e(e, "Unable to start a service in foreground");
   } catch (final IllegalArgumentException e) {
     Ln.e(e, "Unable to start a service in foreground");
   } catch (final IllegalAccessException e) {
     Ln.e(e, "Unable to start a service in foreground");
   } catch (final InvocationTargetException e) {
     Ln.e(e, "Unable to start a service in foreground");
   }
 }
 @Override
 public boolean onCreate() {
   MatcherController controller = new MatcherController();
   for (Class<?> clazz : getExposedClasses()) {
     try {
       if (!clazz.isAnnotationPresent(Contract.class)) {
         throw new Exception(
             "Class " + clazz + " is not annotated with the @Contract annotation.");
       }
       Class<?> contractClazz = ContractHelper.getContractClassForClass(clazz);
       int contentUriPatternMany = ContractHelper.getContentUriPatternMany(contractClazz);
       int contentUriPatternOne = ContractHelper.getContentUriPatternOne(contractClazz);
       controller.add(clazz, SubType.DIRECTORY, "", contentUriPatternMany);
       controller.add(clazz, SubType.ITEM, "#", contentUriPatternOne);
     } catch (Exception e) {
       Ln.e(e);
     }
   }
   setMatcherController(controller);
   return true;
 }