/** * Retrieves a reference to the Gibberish bundle, stops it and uninstalls it and then reinstalls * it in order to make sure that accounts are not reloaded once removed. * * @throws java.lang.Exception if something goes wrong while manipulating the bundles. */ public void testAccountUninstallationPersistence() throws Exception { Bundle providerBundle = GibberishSlickFixture.providerBundle; providerBundle.stop(); assertTrue( "Couldn't stop the protocol provider bundle. State was " + providerBundle.getState(), Bundle.ACTIVE != providerBundle.getState() && Bundle.STOPPING != providerBundle.getState()); providerBundle.uninstall(); assertEquals( "Couldn't stop the protocol provider bundle.", Bundle.UNINSTALLED, providerBundle.getState()); // Now reinstall the bundle and restart the provider providerBundle = GibberishSlickFixture.bc.installBundle(providerBundle.getLocation()); assertEquals( "Couldn't re-install protocol provider bundle.", Bundle.INSTALLED, providerBundle.getState()); AccountManagerUtils.startBundleAndWaitStoredAccountsLoaded( GibberishSlickFixture.bc, providerBundle, "Gibberish"); assertEquals( "Couldn't re-start protocol provider bundle.", Bundle.ACTIVE, providerBundle.getState()); // verify that the provider is not reinstalled ServiceReference[] gibberishProviderRefs = null; try { gibberishProviderRefs = GibberishSlickFixture.bc.getServiceReferences( ProtocolProviderService.class.getName(), "(" + ProtocolProviderFactory.PROTOCOL + "=Gibberish)"); } catch (InvalidSyntaxException ex) { fail("We apparently got our filter wrong " + ex.getMessage()); } // make sure we didn't retrieve a service assertTrue( "A Gibberish Protocol Provider Service was still regged " + "as an osgi service after it was explicitly uninstalled", gibberishProviderRefs == null || gibberishProviderRefs.length == 0); // and a nasty hack at the end - delete the configuration file so that // we get a fresh start on next run. ServiceReference confReference = GibberishSlickFixture.bc.getServiceReference(ConfigurationService.class.getName()); ConfigurationService configurationService = (ConfigurationService) GibberishSlickFixture.bc.getService(confReference); configurationService.purgeStoredConfiguration(); }
/** * Initializes a new <tt>RecordButton</tt> instance which is to record the audio stream. * * @param call the <tt>Call</tt> to be associated with the new instance and to have its audio * stream recorded * @param selected <tt>true</tt> if the new toggle button is to be initially selected; otherwise, * <tt>false</tt> */ public RecordButton(Call call, boolean selected) { super(call, true, selected, ImageLoader.RECORD_BUTTON, ImageLoader.RECORD_BUTTON_PRESSED, null); String toolTip = resources.getI18NString("service.gui.RECORD_BUTTON_TOOL_TIP"); String saveDir = configuration.getString(Recorder.SAVED_CALLS_PATH); if ((saveDir != null) && (saveDir.length() != 0)) toolTip += " (" + saveDir + ")"; setToolTipText(toolTip); }
/** * Returns the last contact status saved in the configuration. * * @param protocolProvider the protocol provider to which the status corresponds * @return the last contact status saved in the configuration. */ public String getLastStatusString(ProtocolProviderService protocolProvider) { // find the last contact status saved in the configuration. String lastStatus = null; ConfigurationService configService = GuiActivator.getConfigurationService(); String prefix = "net.java.sip.communicator.impl.gui.accounts"; List<String> accounts = configService.getPropertyNamesByPrefix(prefix, true); String protocolProviderAccountUID = protocolProvider.getAccountID().getAccountUniqueID(); for (String accountRootPropName : accounts) { String accountUID = configService.getString(accountRootPropName); if (accountUID.equals(protocolProviderAccountUID)) { lastStatus = configService.getString(accountRootPropName + ".lastAccountStatus"); if (lastStatus != null) break; } } return lastStatus; }
/** * Saves the last status for all accounts. This information is used on loging. Each time user logs * in he's logged with the same status as he was the last time before closing the application. * * @param protocolProvider the protocol provider to save status information for * @param statusName the name of the status to save */ private void saveStatusInformation(ProtocolProviderService protocolProvider, String statusName) { ConfigurationService configService = GuiActivator.getConfigurationService(); String prefix = "net.java.sip.communicator.impl.gui.accounts"; List<String> accounts = configService.getPropertyNamesByPrefix(prefix, true); boolean savedAccount = false; for (String accountRootPropName : accounts) { String accountUID = configService.getString(accountRootPropName); if (accountUID.equals(protocolProvider.getAccountID().getAccountUniqueID())) { configService.setProperty(accountRootPropName + ".lastAccountStatus", statusName); savedAccount = true; } } if (!savedAccount) { String accNodeName = "acc" + Long.toString(System.currentTimeMillis()); String accountPackage = "net.java.sip.communicator.impl.gui.accounts." + accNodeName; configService.setProperty( accountPackage, protocolProvider.getAccountID().getAccountUniqueID()); configService.setProperty(accountPackage + ".lastAccountStatus", statusName); } }
/** Constructs MessageSourceService. */ MessageSourceService(MessageHistoryServiceImpl messageHistoryService) { this.messageHistoryService = messageHistoryService; ConfigurationService conf = MessageHistoryActivator.getConfigurationService(); if (conf.getBoolean(IN_HISTORY_PROPERTY, false)) { sourceServiceType = HISTORY_TYPE; } MESSAGE_HISTORY_NAME = MessageHistoryActivator.getResources().getI18NString("service.gui.RECENT_MESSAGES"); numberOfMessages = conf.getInt(NUMBER_OF_RECENT_MSGS_PROP, numberOfMessages); isSMSEnabled = conf.getBoolean(IS_MESSAGE_SUBTYPE_SMS_PROP, isSMSEnabled); RECENT_MSGS_VER = conf.getString(VER_OF_RECENT_MSGS_PROP, RECENT_MSGS_VER); MessageSourceContactPresenceStatus.MSG_SRC_CONTACT_ONLINE.setStatusIcon( MessageHistoryActivator.getResources() .getImageInBytes("service.gui.icons.SMS_STATUS_ICON")); }
/** * Creates a full filename for the call by combining the directory, file prefix and extension. If * the directory is <tt>null</tt> user's home directory is used. * * @param savedCallsPath the path to the directory in which the generated file name is to be * placed * @return a full filename for the call */ private String createDefaultFilename(String savedCallsPath) { // set to user's home when null if (savedCallsPath == null) { try { savedCallsPath = GuiActivator.getFileAccessService().getDefaultDownloadDirectory().getAbsolutePath(); } catch (IOException ioex) { // Leave it in the current directory. } } String ext = configuration.getString(Recorder.FORMAT); // Use a default format when the configured one seems invalid. if ((ext == null) || (ext.length() == 0) || !isSupportedFormat(ext)) ext = SoundFileUtils.DEFAULT_CALL_RECORDING_FORMAT; return ((savedCallsPath == null) ? "" : (savedCallsPath + File.separator)) + generateCallFilename(ext); }
/** Starts this manager for given <tt>hostName</tt>. */ public void start() { expireThread.start(); ConfigurationService config = FocusBundleActivator.getConfigService(); String hostName = config.getString(HOSTNAME_PNAME); String xmppDomain = config.getString(XMPP_DOMAIN_PNAME); focusUserDomain = config.getString(FOCUS_USER_DOMAIN_PNAME); focusUserName = config.getString(FOCUS_USER_NAME_PNAME); String focusUserPassword = config.getString(FOCUS_USER_PASSWORD_PNAME); protocolProviderHandler.start(hostName, focusUserDomain, focusUserPassword, focusUserName); jitsiMeetServices = new JitsiMeetServices( protocolProviderHandler.getOperationSet(OperationSetSubscription.class)); String statsPubSubNode = config.getString(SHARED_STATS_PUBSUB_NODE_PNAME); componentsDiscovery = new ComponentsDiscovery(jitsiMeetServices); componentsDiscovery.start(xmppDomain, statsPubSubNode, protocolProviderHandler); meetExtensionsHandler = new MeetExtensionsHandler(this); ProviderManager.getInstance() .addExtensionProvider( LogPacketExtension.LOG_ELEM_NAME, LogPacketExtension.NAMESPACE, new LogExtensionProvider()); FocusBundleActivator.bundleContext.registerService( JitsiMeetServices.class, jitsiMeetServices, null); protocolProviderHandler.addRegistrationListener(this); protocolProviderHandler.register(); }
/** Installs an account and verifies whether the installation has gone well. */ public void testInstallAccount() { // first obtain a reference to the provider factory ServiceReference[] serRefs = null; String osgiFilter = "(" + ProtocolProviderFactory.PROTOCOL + "=" + ProtocolNames.JABBER + ")"; try { serRefs = JabberSlickFixture.bc.getServiceReferences( ProtocolProviderFactory.class.getName(), osgiFilter); } catch (InvalidSyntaxException ex) { // this really shouldhn't occur as the filter expression is static. fail(osgiFilter + " is not a valid osgi filter"); } assertTrue( "Failed to find a provider factory service for protocol Jabber", serRefs != null && serRefs.length > 0); // Enable always trust mode for testing tls jabber connections ServiceReference confReference = JabberSlickFixture.bc.getServiceReference(ConfigurationService.class.getName()); ConfigurationService configurationService = (ConfigurationService) JabberSlickFixture.bc.getService(confReference); configurationService.setProperty(CertificateService.PNAME_ALWAYS_TRUST, Boolean.TRUE); // Keep the reference for later usage. ProtocolProviderFactory jabberProviderFactory = (ProtocolProviderFactory) JabberSlickFixture.bc.getService(serRefs[0]); // make sure the account is empty assertTrue( "There was an account registered with the account mananger " + "before we've installed any", jabberProviderFactory.getRegisteredAccounts().size() == 0); // Prepare the properties of the first jabber account. Hashtable<String, String> jabberAccount1Properties = getAccountProperties(JabberProtocolProviderServiceLick.ACCOUNT_1_PREFIX); Hashtable<String, String> jabberAccount2Properties = getAccountProperties(JabberProtocolProviderServiceLick.ACCOUNT_2_PREFIX); Hashtable<String, String> jabberAccount3Properties = getAccountProperties(JabberProtocolProviderServiceLick.ACCOUNT_3_PREFIX); // try to install an account with a null account id try { jabberProviderFactory.installAccount(null, jabberAccount1Properties); fail( "installing an account with a null account id must result " + "in a NullPointerException"); } catch (NullPointerException exc) { // that's what had to happen } // now really install the accounts jabberProviderFactory.installAccount( jabberAccount1Properties.get(ProtocolProviderFactory.USER_ID), jabberAccount1Properties); jabberProviderFactory.installAccount( jabberAccount2Properties.get(ProtocolProviderFactory.USER_ID), jabberAccount2Properties); jabberProviderFactory.installAccount( jabberAccount3Properties.get(ProtocolProviderFactory.USER_ID), jabberAccount3Properties); // try to install one of the accounts one more time and verify that an // excepion is thrown. try { jabberProviderFactory.installAccount( jabberAccount1Properties.get(ProtocolProviderFactory.USER_ID), jabberAccount1Properties); fail( "An IllegalStateException must be thrown when trying to " + "install a duplicate account"); } catch (IllegalStateException exc) { // that's what supposed to happen. } // Verify that the provider factory is aware of our installation assertTrue( "The newly installed account was not in the acc man's " + "registered accounts!", jabberProviderFactory.getRegisteredAccounts().size() == 3); // Verify protocol providers corresponding to the new account have // been properly registered with the osgi framework. osgiFilter = "(&(" + ProtocolProviderFactory.PROTOCOL + "=" + ProtocolNames.JABBER + ")" + "(" + ProtocolProviderFactory.USER_ID + "=" + jabberAccount1Properties.get(ProtocolProviderFactory.USER_ID) + "))"; try { serRefs = JabberSlickFixture.bc.getServiceReferences( ProtocolProviderService.class.getName(), osgiFilter); } catch (InvalidSyntaxException ex) { // this really shouldhn't occur as the filter expression is static. fail(osgiFilter + "is not a valid osgi filter"); } assertTrue( "An protocol provider was apparently not installed as " + "requested.", serRefs != null && serRefs.length > 0); Object jabberProtocolProvider = JabberSlickFixture.bc.getService(serRefs[0]); assertTrue( "The installed protocol provider does not implement " + "the protocol provider service.", jabberProtocolProvider instanceof ProtocolProviderService); }
/** * Starts recording {@link #call} creating {@link #recorder} first and asking the user for the * recording format and file if they are not configured in the "Call Recording" configuration * form. * * @return <tt>true</tt> if the recording has been started successfully; otherwise, <tt>false</tt> */ private boolean startRecording() { String savedCallsPath = configuration.getString(Recorder.SAVED_CALLS_PATH); String callFormat; // Ask the user where to save the call. if ((savedCallsPath == null) || (savedCallsPath.length() == 0)) { /* * Delay the initialization of callFileChooser in order to delay the * creation of the recorder. */ if (callFileChooser == null) { callFileChooser = GenericFileDialog.create( null, resources.getI18NString("plugin.callrecordingconfig.SAVE_CALL"), SipCommFileChooser.SAVE_FILE_OPERATION); callFileChooser.addFilter( new SipCommFileFilter() { @Override public boolean accept(File f) { return f.isDirectory() || isSupportedFormat(f); } @Override public String getDescription() { StringBuilder description = new StringBuilder(); description.append("Recorded call"); Recorder recorder; try { recorder = getRecorder(); } catch (OperationFailedException ofex) { logger.error("Failed to get Recorder", ofex); recorder = null; } if (recorder != null) { List<String> supportedFormats = recorder.getSupportedFormats(); if (supportedFormats != null) { description.append(" ("); boolean firstSupportedFormat = true; for (String supportedFormat : supportedFormats) { if (firstSupportedFormat) firstSupportedFormat = false; else description.append(", "); description.append("*."); description.append(supportedFormat); } description.append(')'); } } return description.toString(); } }); } // Offer a default name for the file to record into. callFileChooser.setStartPath(createDefaultFilename(null)); File selectedFile = callFileChooser.getFileFromDialog(); if (selectedFile != null) { callFilename = selectedFile.getAbsolutePath(); /* * If the user specified no extension (which seems common on Mac * OS X at least) i.e. no format, then it is not obvious that we * have to override the set Recorder.CALL_FORMAT. */ callFormat = SoundFileUtils.getExtension(selectedFile); if ((callFormat != null) && (callFormat.length() != 0)) { /* * If the use has specified an extension and thus a format * which is not supported, use a default format instead. */ if (!isSupportedFormat(selectedFile)) { /* * If what appears to be an extension seems a lot like * an extension, then it should be somewhat safer to * replace it. */ if (SoundFileUtils.isSoundFile(selectedFile)) { callFilename = callFilename.substring(0, callFilename.lastIndexOf('.')); } String configuredFormat = configuration.getString(Recorder.FORMAT); callFormat = (configuredFormat != null && configuredFormat.length() != 0) ? configuredFormat : SoundFileUtils.DEFAULT_CALL_RECORDING_FORMAT; callFilename += '.' + callFormat; } configuration.setProperty(Recorder.FORMAT, callFormat); } } else { // user canceled the recording return false; } } else { callFilename = createDefaultFilename(savedCallsPath); callFormat = SoundFileUtils.getExtension(new File(callFilename)); } Throwable exception = null; try { Recorder recorder = getRecorder(); if (recorder != null) { if ((callFormat == null) || (callFormat.length() <= 0)) callFormat = SoundFileUtils.DEFAULT_CALL_RECORDING_FORMAT; recorder.start(callFormat, callFilename); } this.recorder = recorder; } catch (IOException ioex) { exception = ioex; } catch (MediaException mex) { exception = mex; } catch (OperationFailedException ofex) { exception = ofex; } if ((recorder == null) || (exception != null)) { logger.error( "Failed to start recording call " + call + " into file " + callFilename, exception); return false; } else return true; }
/** * Retrieve DiscoverInfo for a specific node. * * @param caps the <tt>Caps</tt> i.e. the node, the hash and the ver * @return The corresponding DiscoverInfo or null if none is known. */ public static DiscoverInfo getDiscoverInfoByCaps(Caps caps) { synchronized (caps2discoverInfo) { DiscoverInfo discoverInfo = caps2discoverInfo.get(caps); /* * If we don't have the discoverInfo in the runtime cache yet, we * may have it remembered in a previous application instance. */ if (discoverInfo == null) { ConfigurationService configurationService = getConfigService(); String capsPropertyName = getCapsPropertyName(caps); String xml = configurationService.getString(capsPropertyName); if ((xml != null) && (xml.length() != 0)) { IQProvider discoverInfoProvider = (IQProvider) ProviderManager.getInstance() .getIQProvider("query", "http://jabber.org/protocol/disco#info"); if (discoverInfoProvider != null) { XmlPullParser parser = new MXParser(); try { parser.setFeature(XmlPullParser.FEATURE_PROCESS_NAMESPACES, true); parser.setInput(new StringReader(xml)); // Start the parser. parser.next(); } catch (XmlPullParserException xppex) { parser = null; } catch (IOException ioex) { parser = null; } if (parser != null) { try { discoverInfo = (DiscoverInfo) discoverInfoProvider.parseIQ(parser); } catch (Exception ex) { } if (discoverInfo != null) { if (caps.isValid(discoverInfo)) caps2discoverInfo.put(caps, discoverInfo); else { logger.error( "Invalid DiscoverInfo for " + caps.getNodeVer() + ": " + discoverInfo); /* * The discoverInfo doesn't seem valid * according to the caps which means that we * must have stored invalid information. * Delete the invalid information in order * to not try to validate it again. */ configurationService.removeProperty(capsPropertyName); } } } } } } return discoverInfo; } }