示例#1
0
  /**
   * The dependent service is available and the bundle will start.
   *
   * @param dependentService the UIService this activator is waiting.
   */
  @Override
  public void start(Object dependentService) {
    if (logger.isDebugEnabled()) logger.debug("Update checker [STARTED]");

    ConfigurationService cfg = getConfiguration();

    if (OSUtils.IS_WINDOWS) {
      updateService = new Update();

      bundleContext.registerService(UpdateService.class.getName(), updateService, null);

      // Register the "Check for Updates" menu item if
      // the "Check for Updates" property isn't disabled.
      if (!cfg.getBoolean(CHECK_FOR_UPDATES_MENU_DISABLED_PROP, false)) {
        // Register the "Check for Updates" menu item.
        CheckForUpdatesMenuItemComponent checkForUpdatesMenuItemComponent =
            new CheckForUpdatesMenuItemComponent(Container.CONTAINER_HELP_MENU);

        Hashtable<String, String> toolsMenuFilter = new Hashtable<String, String>();
        toolsMenuFilter.put(Container.CONTAINER_ID, Container.CONTAINER_HELP_MENU.getID());

        bundleContext.registerService(
            PluginComponent.class.getName(), checkForUpdatesMenuItemComponent, toolsMenuFilter);
      }

      // Check for software update upon startup if enabled.
      if (cfg.getBoolean(UPDATE_ENABLED, true)) updateService.checkForUpdates(false);
    }

    if (cfg.getBoolean(CHECK_FOR_UPDATES_DAILY_ENABLED_PROP, false)) {
      logger.info("Scheduled update checking enabled");

      // Schedule a "check for updates" task that will run once a day
      int hoursToWait = calcHoursToWait();
      Runnable updateRunnable =
          new Runnable() {
            public void run() {
              logger.debug("Performing scheduled update check");
              getUpdateService().checkForUpdates(false);
            }
          };

      mUpdateExecutor = Executors.newSingleThreadScheduledExecutor();
      mUpdateExecutor.scheduleAtFixedRate(
          updateRunnable, hoursToWait, 24 * 60 * 60, TimeUnit.SECONDS);
    }

    if (logger.isDebugEnabled()) logger.debug("Update checker [REGISTERED]");
  }
示例#2
0
  /**
   * Starts the configuration service
   *
   * @param bundleContext the <tt>BundleContext</tt> as provided by the OSGi framework.
   * @throws Exception if anything goes wrong
   */
  public void start(BundleContext bundleContext) throws Exception {
    FileAccessService fas = ServiceUtils.getService(bundleContext, FileAccessService.class);

    if (fas != null) {
      File usePropFileConfig;
      try {
        usePropFileConfig =
            fas.getPrivatePersistentFile(".usepropfileconfig", FileCategory.PROFILE);
      } catch (Exception ise) {
        // There is somewhat of a chicken-and-egg dependency between
        // FileConfigurationServiceImpl and ConfigurationServiceImpl:
        // FileConfigurationServiceImpl throws IllegalStateException if
        // certain System properties are not set,
        // ConfigurationServiceImpl will make sure that these properties
        // are set but it will do that later.
        // A SecurityException is thrown when the destination
        // is not writable or we do not have access to that folder
        usePropFileConfig = null;
      }

      if (usePropFileConfig != null && usePropFileConfig.exists()) {
        logger.info("Using properties file configuration store.");
        this.cs = LibJitsi.getConfigurationService();
      }
    }

    if (this.cs == null) {
      this.cs = new JdbcConfigService(fas);
    }

    bundleContext.registerService(ConfigurationService.class.getName(), this.cs, null);

    fixPermissions(this.cs);
  }
 public AuthServiceTracker(BundleContext context) throws InvalidSyntaxException {
   super(context, getAuthFilter(), null);
   // TODO: Filters are case sensitive, we should be too
   if (NoneAuthenticationService.AUTH_TYPE.equalsIgnoreCase(getAuthName())) {
     Dictionary<String, String> properties = new Hashtable<String, String>();
     properties.put(ServerConstants.CONFIG_AUTH_NAME, getAuthName());
     // TODO: shouldn't we always register the none-auth service?
     context.registerService(
         IAuthenticationService.class, new NoneAuthenticationService(), properties);
   }
 }
  /**
   * Starts the Metacafe replacement source bundle
   *
   * @param context the <tt>BundleContext</tt> as provided from the OSGi framework
   * @throws Exception if anything goes wrong
   */
  public void start(BundleContext context) throws Exception {
    Hashtable<String, String> hashtable = new Hashtable<String, String>();
    hashtable.put(
        ReplacementService.SOURCE_NAME, ReplacementServiceMetacafeImpl.METACAFE_CONFIG_LABEL);
    metacafeSource = new ReplacementServiceMetacafeImpl();

    metacafeServReg =
        context.registerService(ReplacementService.class.getName(), metacafeSource, hashtable);

    logger.info("Metacafe source implementation [STARTED].");
  }
  /**
   * Initializes and creates an account corresponding to the specified accountProperties and
   * registers the resulting ProtocolProvider in the <tt>context</tt> BundleContext parameter.
   *
   * @param accountProperties a set of protocol (or implementation) specific properties defining the
   *     new account.
   * @return the AccountID of the newly created account
   */
  protected AccountID loadAccount(Map accountProperties) {
    BundleContext context = SipActivator.getBundleContext();
    if (context == null) throw new NullPointerException("The specified BundleContext was null");

    String userIDStr = (String) accountProperties.get(USER_ID);
    if (userIDStr == null)
      throw new NullPointerException("The account properties contained no user id.");

    if (accountProperties == null)
      throw new NullPointerException("The specified property map was null");

    String serverAddress = (String) accountProperties.get(SERVER_ADDRESS);

    if (serverAddress == null)
      throw new NullPointerException(serverAddress + " is not a valid ServerAddress");

    if (!accountProperties.containsKey(PROTOCOL))
      accountProperties.put(PROTOCOL, ProtocolNames.SIP);

    SipAccountID accountID = new SipAccountID(userIDStr, accountProperties, serverAddress);

    // get a reference to the configuration service and register whatever
    // properties we have in it.

    Hashtable properties = new Hashtable();
    properties.put(PROTOCOL, ProtocolNames.SIP);
    properties.put(USER_ID, userIDStr);

    ProtocolProviderServiceSipImpl sipProtocolProvider = new ProtocolProviderServiceSipImpl();

    try {
      sipProtocolProvider.initialize(userIDStr, accountID);

      // We store again the account in order to store all properties added
      // during the protocol provider initialization.
      this.storeAccount(SipActivator.getBundleContext(), accountID);
    } catch (OperationFailedException ex) {
      logger.error("Failed to initialize account", ex);
      throw new IllegalArgumentException("Failed to initialize account" + ex.getMessage());
    }

    ServiceRegistration registration =
        context.registerService(
            ProtocolProviderService.class.getName(), sipProtocolProvider, properties);

    registeredAccounts.put(accountID, registration);
    return accountID;
  }
  /**
   * Initializes and registers all tests that we'll run as a part of this slick.
   *
   * @param context a currently valid bundle context.
   */
  public void start(BundleContext context) {
    setName("JabberProtocolProviderSlick");

    Hashtable<String, String> properties = new Hashtable<String, String>();
    properties.put("service.pid", getName());

    JabberSlickFixture.bc = context;

    // verify whether the user wants to avoid online testing
    String offlineMode = System.getProperty(DISABLE_ONLINE_TESTS_PROPERTY_NAME, null);

    if (offlineMode != null && offlineMode.equalsIgnoreCase("true"))
      JabberSlickFixture.onlineTestingDisabled = true;

    addTestSuite(TestAccountInstallation.class);
    addTestSuite(TestProtocolProviderServiceJabberImpl.class);

    addTest(TestOperationSetPresence.suite());

    // the following should only be run when we want online testing.
    if (!JabberSlickFixture.onlineTestingDisabled) {
      addTest(TestOperationSetPersistentPresence.suite());

      addTest(TestOperationSetBasicInstantMessaging.suite());

      addTest(TestOperationSetInstantMessageTransformJabberImpl.suite());

      addTest(TestOperationSetTypingNotifications.suite());

      // tests currently fails due to jingle lib bugs.
      // will be activated as soon as bugs get fixed
      // addTestSuite(TestOperationSetBasicTelephonyJabberImpl.class);

      /** @todo UNCOMMENT */
      //            addTest(TestOperationSetMultiUserChat.suite());
      addTest(TestOperationSetMultiUserChat2.suite());

      addTestSuite(TestOperationSetFileTransferImpl.class);
    }

    addTest(TestAccountUninstallation.suite());
    addTestSuite(TestAccountUninstallationPersistence.class);

    context.registerService(getClass().getName(), this, properties);
  }
  /** implements BundleActivator.start() */
  public void start(BundleContext bc) throws Exception {
    logger.info("starting popup message test ");

    bundleContext = bc;

    setName("PopupMessageHandlerSLick");

    Hashtable<String, String> properties = new Hashtable<String, String>();

    properties.put("service.pid", getName());

    // we maybe are running on machine without WM and systray
    // (test server machine), skip tests
    if (ServiceUtils.getService(bc, SystrayService.class) != null) {
      addTest(TestPopupMessageHandler.suite());
    }

    bundleContext.registerService(getClass().getName(), this, properties);
  }
  /**
   * Creates a protocol provider for the given <tt>accountID</tt> and registers it in the bundle
   * context. This method has a persistent effect. Once created the resulting account will remain
   * installed until removed through the uninstallAccount method.
   *
   * @param accountID the account identifier
   * @return <tt>true</tt> if the account with the given <tt>accountID</tt> is successfully loaded,
   *     otherwise returns <tt>false</tt>
   */
  public boolean loadAccount(AccountID accountID) {
    // Need to obtain the original user id property, instead of calling
    // accountID.getUserID(), because this method could return a modified
    // version of the user id property.
    String userID = accountID.getAccountPropertyString(ProtocolProviderFactory.USER_ID);

    ProtocolProviderService service = createService(userID, accountID);

    Dictionary<String, String> properties = new Hashtable<String, String>();
    properties.put(PROTOCOL, protocolName);
    properties.put(USER_ID, userID);

    ServiceRegistration serviceRegistration =
        bundleContext.registerService(ProtocolProviderService.class.getName(), service, properties);

    if (serviceRegistration == null) return false;
    else {
      synchronized (registeredAccounts) {
        registeredAccounts.put(accountID, serviceRegistration);
      }
      return true;
    }
  }
示例#9
0
  /**
   * Registers/publishes services annotated with @OSGiServiceProvider.
   *
   * @param managedClass The managed class to instantiate and register as an OSGi service.
   * @param context The bundle context.
   * @param serviceRegs The list to save all service registrations to for later unregistration.
   * @throws Exception
   */
  protected void registerServices(
      Class managedClass, BundleContext context, List<ServiceRegistration> serviceRegs)
      throws Exception {
    OSGiServiceProvider serviceProvider =
        (OSGiServiceProvider) managedClass.getAnnotation(OSGiServiceProvider.class);
    if (serviceProvider != null) {
      List<Tuple3<Properties, Object, List<String>>> serviceInstData = new LinkedList<>();

      if (serviceProvider.properties().length > 0) {
        Tuple3<Properties, Object, List<String>> sd = new Tuple3<>();
        sd.t1 = osgiPropertiesToProperties(serviceProvider.properties());
        serviceInstData.add(sd);
      } else if (serviceProvider.instances().length > 0) {
        for (OSGiServiceInstance serviceInst : serviceProvider.instances()) {
          Tuple3<Properties, Object, List<String>> sd = new Tuple3<>();
          sd.t1 = osgiPropertiesToProperties(serviceInst.properties());
          serviceInstData.add(sd);
        }
      } else if (!serviceProvider.instanceFactoryClass().equals(InstanceFactory.class)) {
        InstanceFactory instanceFactory =
            (InstanceFactory) getManagedInstance(serviceProvider.instanceFactoryClass());
        if (instanceFactory == null) {
          instanceFactory = serviceProvider.instanceFactoryClass().newInstance();
        }
        for (Properties props : instanceFactory.getPropertiesPerInstance()) {
          Tuple3<Properties, Object, List<String>> sd = new Tuple3<>();
          sd.t1 = props;
          serviceInstData.add(sd);
        }
      } else {
        Tuple3<Properties, Object, List<String>> sd = new Tuple3<>();
        sd.t1 = new Properties();
        serviceInstData.add(sd);
      }

      // The number of managedInstances and serviceInstData will always be the same. They both
      // originate
      // from the same information.
      List<Object> managedInstances = getManagedInstances(managedClass);
      for (int i = 0; i < serviceInstData.size(); i++) {

        List<String> serviceAPIs = new LinkedList<>();

        if (serviceProvider.serviceAPIs().length > 0) {
          for (Class svcAPI : serviceProvider.serviceAPIs()) {
            serviceAPIs.add(svcAPI.getName());
          }
        } else if (serviceProvider.instances().length > 0) {
          OSGiServiceInstance svsInstAnn = serviceProvider.instances()[i];
          for (Class svcAPI : svsInstAnn.serviceAPIs()) {
            serviceAPIs.add(svcAPI.getName());
          }
        } else if (!serviceProvider.instanceFactoryClass().equals(InstanceFactory.class)) {
          String svcAPIList =
              serviceInstData.get(i).t1.getProperty(InstanceFactory.SERVICE_API_CLASSES_PROPERTY);
          if (svcAPIList != null) {
            for (String svcAPI : svcAPIList.split(":")) {
              serviceAPIs.add(svcAPI);
            }
          } else {
            Class[] interfaces = managedClass.getInterfaces();
            if (interfaces != null && interfaces.length > 0) {
              serviceAPIs.add(interfaces[0].getName());
            }
          }
        } else {
          Class[] interfaces = managedClass.getInterfaces();
          if (interfaces != null && interfaces.length > 0) {
            serviceAPIs.add(interfaces[0].getName());
          }
        }

        Tuple3<Properties, Object, List<String>> sd = serviceInstData.get(i);
        sd.t3 = serviceAPIs;
        sd.t2 = managedInstances.get(i);
      }

      for (Tuple3<Properties, Object, List<String>> sd : serviceInstData) {
        sd.t1.put(Constants.SERVICE_PID, managedClass.getName());
        if (!sd.t3.isEmpty()) {
          injectInstanceProps(sd.t2, sd.t1);
          for (String svcAPI : sd.t3) {
            ServiceRegistration serviceReg = context.registerService(svcAPI, sd.t2, sd.t1);

            serviceRegs.add(serviceReg);
            this.activatorLogger.info(
                "Registered '"
                    + managedClass.getName()
                    + "' as a service provider of '"
                    + svcAPI
                    + "' for bundle: "
                    + context.getBundle().getSymbolicName()
                    + "!");
          }
        } else {
          throw new IllegalArgumentException(
              "The @OSGiServiceProvider annotated service of class '"
                  + managedClass.getName()
                  + "' does not implement a service interface!");
        }
      }
    }
  }
  /**
   * Starts the execution of the neomedia bundle in the specified context.
   *
   * @param bundleContext the context in which the neomedia bundle is to start executing
   * @throws Exception if an error occurs while starting the execution of the neomedia bundle in the
   *     specified context
   */
  public void start(BundleContext bundleContext) throws Exception {
    if (logger.isDebugEnabled()) logger.debug("Started.");

    NeomediaActivator.bundleContext = bundleContext;

    // MediaService
    mediaServiceImpl = (MediaServiceImpl) LibJitsi.getMediaService();

    bundleContext.registerService(MediaService.class.getName(), mediaServiceImpl, null);
    if (logger.isDebugEnabled()) logger.debug("Media Service ... [REGISTERED]");

    //        mediaConfiguration = new MediaConfigurationImpl();
    //        bundleContext.registerService(
    //                MediaConfigurationService.class.getStatus(),
    //                getMediaConfiguration(),
    //                null);
    if (logger.isDebugEnabled()) logger.debug("Media Configuration ... [REGISTERED]");

    ConfigurationService cfg = NeomediaActivator.getConfigurationService();
    Dictionary<String, String> mediaProps = new Hashtable<String, String>();

    mediaProps.put(ConfigurationForm.FORM_TYPE, ConfigurationForm.GENERAL_TYPE);

    // If the audio configuration form is disabled don't register it.
    //        if ((cfg == null) || !cfg.getBoolean(AUDIO_CONFIG_DISABLED_PROP, false))
    //        {
    //            audioConfigurationForm
    //                = new LazyConfigurationForm(
    //                        AudioConfigurationPanel.class.getStatus(),
    //                        getClass().getClassLoader(),
    //                        "plugin.mediaconfig.AUDIO_ICON",
    //                        "impl.neomedia.configform.AUDIO",
    //                        3);
    //
    //            bundleContext.registerService(
    //                    ConfigurationForm.class.getStatus(),
    //                    audioConfigurationForm,
    //                    mediaProps);
    //
    //            if (deviceConfigurationPropertyChangeListener == null)
    //            {
    //                // Initializes and registers the changed device configuration
    //                // event ot the notification service.
    //                getNotificationService();
    //
    //                deviceConfigurationPropertyChangeListener
    //                    = new AudioDeviceConfigurationListener();
    //                mediaServiceImpl
    //                    .getDeviceConfiguration()
    //                        .addPropertyChangeListener(
    //                                deviceConfigurationPropertyChangeListener);
    //            }
    //        }

    // If the video configuration form is disabled don't register it.
    //        if ((cfg == null) || !cfg.getBoolean(VIDEO_CONFIG_DISABLED_PROP, false))
    //        {
    //            bundleContext.registerService(
    //                    ConfigurationForm.class.getStatus(),
    //                    new LazyConfigurationForm(
    //                            VideoConfigurationPanel.class.getStatus(),
    //                            getClass().getClassLoader(),
    //                            "plugin.mediaconfig.VIDEO_ICON",
    //                            "impl.neomedia.configform.VIDEO",
    //                            4),
    //                    mediaProps);
    //        }

    // H.264
    // If the H.264 configuration form is disabled don't register it.
    //        if ((cfg == null) || !cfg.getBoolean(H264_CONFIG_DISABLED_PROP, false))
    //        {
    //            Dictionary<String, String> h264Props
    //                = new Hashtable<String, String>();
    //
    //            h264Props.put(
    //                    ConfigurationForm.FORM_TYPE,
    //                    ConfigurationForm.ADVANCED_TYPE);
    //            bundleContext.registerService(
    //                    ConfigurationForm.class.getStatus(),
    //                    new LazyConfigurationForm(
    //                            ConfigurationPanel.class.getStatus(),
    //                            getClass().getClassLoader(),
    //                            "plugin.mediaconfig.VIDEO_ICON",
    //                            "impl.neomedia.configform.H264",
    //                            -1,
    //                            true),
    //                    h264Props);
    //        }

    // ZRTP
    // If the ZRTP configuration form is disabled don't register it.
    //        if ((cfg == null) || !cfg.getBoolean(ZRTP_CONFIG_DISABLED_PROP, false))
    //        {
    //            Dictionary<String, String> securityProps
    //                = new Hashtable<String, String>();
    //
    //            securityProps.put( ConfigurationForm.FORM_TYPE,
    //                            ConfigurationForm.SECURITY_TYPE);
    //            bundleContext.registerService(
    //                ConfigurationForm.class.getStatus(),
    //                new LazyConfigurationForm(
    //                    SecurityConfigForm.class.getStatus(),
    //                    getClass().getClassLoader(),
    //                    "impl.media.security.zrtp.CONF_ICON",
    //                    "impl.media.security.zrtp.TITLE",
    //                    0),
    //                securityProps);
    //        }

    // we use the nist-sdp stack to make parse sdp and we need to set the
    // following property to make sure that it would accept java generated
    // IPv6 addresses that contain address scope zones.
    System.setProperty("gov.nist.core.STRIP_ADDR_SCOPES", "true");

    // AudioNotifierService
    AudioNotifierService audioNotifierService = LibJitsi.getAudioNotifierService();

    audioNotifierService.setMute(
        (cfg == null)
            || !cfg.getBoolean("net.java.sip.communicator" + ".impl.sound.isSoundEnabled", true));
    bundleContext.registerService(AudioNotifierService.class.getName(), audioNotifierService, null);

    if (logger.isInfoEnabled()) logger.info("Audio Notifier Service ...[REGISTERED]");

    // Call Recording
    // If the call recording configuration form is disabled don't continue.
    //        if ((cfg == null)
    //                || !cfg.getBoolean(CALL_RECORDING_CONFIG_DISABLED_PROP, false))
    //        {
    //            Dictionary<String, String> callRecordingProps
    //                = new Hashtable<String, String>();
    //
    //            callRecordingProps.put(
    //                    ConfigurationForm.FORM_TYPE,
    //                    ConfigurationForm.ADVANCED_TYPE);
    //            bundleContext.registerService(
    //                    ConfigurationForm.class.getStatus(),
    //                    new LazyConfigurationForm(
    //                            CallRecordingConfigForm.class.getStatus(),
    //                            getClass().getClassLoader(),
    //                            null,
    //                            "plugin.callrecordingconfig.CALL_RECORDING_CONFIG",
    //                            1100,
    //                            true),
    //                    callRecordingProps);
    //        }
  }