@Override public void onCreate() { SmackAndroid.init(getApplicationContext()); configure(); // create the global wake lock PowerManager pwr = (PowerManager) getSystemService(Context.POWER_SERVICE); mWakeLock = pwr.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, Kontalk.TAG); mWakeLock.setReferenceCounted(false); mLocalBroadcastManager = LocalBroadcastManager.getInstance(this); mPushService = PushServiceManager.getInstance(this); // create idle handler HandlerThread thread = new HandlerThread("IdleThread", Process.THREAD_PRIORITY_BACKGROUND); thread.start(); mIdleHandler = new IdleConnectionHandler(this, thread.getLooper()); mHandler = new Handler(); }
public ConnectionManager(Context context, ConnectionStatusCallback statusCallback, CommunicationManager communicationManager) { this.statusCallback = statusCallback; this.communicationManager = communicationManager; smack = SmackAndroid.init(context); SASLAuthentication.registerSASLMechanism(GTalkOAuthSASLMechanism.NAME, GTalkOAuthSASLMechanism.class); SASLAuthentication .supportSASLMechanism(GTalkOAuthSASLMechanism.NAME, 0); ConnectionConfiguration configuration = new ConnectionConfiguration( "talk.google.com", 5222, "gmail.com"); configuration.setSASLAuthenticationEnabled(true); connection = new XMPPConnection(configuration); }
private void connectToServer() { ExecutorService executor = Executors.newSingleThreadExecutor(); if (isServerUrlNotNull()) { executor.execute(new Runnable() { @Override public void run() { logs.info("Getting xmpp connection configuration"); mSmackAndroid = SmackAndroid.init(XmppService.this); mConnection = getConfiguredConnection(HOST); try { mUserLogin = Prefs.getApiUsername(XmppService.this); mUserPassword = Prefs.getApiKey(XmppService.this); mUserJid = mUserLogin + "@" + HOST; logs.info("Connecting to xmpp server"); Log.i("XmppService", "login: " + mUserLogin + " password: " + mUserPassword + " jid: " + mUserJid); mConnection.connect(); mConnection.login(mUserLogin, mUserPassword); setMessageListener(mConnection); setPubsubListener(mConnection); } catch (Exception e) { Log.i(TAG, "Error during connection", e); e.printStackTrace(); //try again mConnection.disconnect(); connectToServer(); } } }); } }
public NumberValidator(Context context, EndpointServer server, String name, String phone, PersonalKey key, String passphrase) { mContext = context.getApplicationContext(); mServer = server; mName = name; mPhone = phone; mKey = key; mPassphrase = passphrase; mConnector = new XMPPConnectionHelper(mContext, mServer, true); mConnector.setRetryEnabled(false); SmackAndroid.init(context.getApplicationContext()); configure(); }
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_login); SmackAndroid.init(this); ButterKnife.inject(this); init(); }
private void logInToClient() { Log.i(TAG, "logInToClient"); if (hubCommandsClient != null) { Log.e(TAG, "Client is alerady connected"); return; } ImageButton connectBtn = (ImageButton) findViewById(R.id.connectButton); connectBtn.setEnabled(false); /* TODO - remove comment if for some reason you see that the hub is not responsive and might need to authenticate with the myharmony web service String loginToken = auth.getLoginToken(Configuration.myHarmonyUser, Configuration.myHarmonyPassword); if (loginToken == null) { return; } */ String loginToken = "testtesttesttest"; //this needs to be called before XMPP is used in the app SmackAndroid.init(this); //if on home wifi then use the home wifi IP and port, otherwise use the external ones String hubIP = Configuration.hubWifiAddress; int xmppPort = Configuration.hubWifiXmppPort; WifiManager wifiMgr = (WifiManager) getSystemService(Context.WIFI_SERVICE); WifiInfo mWifi = wifiMgr.getConnectionInfo(); String wifiName = mWifi.getSSID(); if (wifiName == null || !wifiName.equals(Configuration.homeWifiSSID)) { hubIP = Configuration.hubInternetAddress; xmppPort = Configuration.hubInternetXmppPort; } hubCommandsClient = new Client(hubIP, xmppPort, this, this); //if (!auth.getSessionToken(loginToken, "192.168.2.128", hubCommandsClient)) { if (!auth.getSessionToken(loginToken, hubIP, xmppPort, hubCommandsClient)) { connectBtn.setEnabled(true); } }
/** * XMPPClass Constructor * @param username : XMPP server username * @param password : XMPP server password * @param topicName : XMPP main topic name (RC topic name) * @param Server : XMPP Server name * @param appContext : The application context */ public XMPPCommunicator(String username, String password, String topicName, String Server, Context appContext){ NodeListeners = new HashMap<String, ItemEventCoordinator>(); Nodes = new HashMap<String, Node>(); Username = username; Password = password; Topic = topicName; ctx = appContext; flag = true; serverName = Server; msgPub = new MessagePublisher("XMPP"); //Init aSmack SmackAndroid.init(ctx); //Set the reply timeout of asmack in ms to avoid server not responding fast enough if busy //SmackConfiguration.setPacketReplyTimeout(10000); // XMPP CONNECTION connConfig = new ConnectionConfiguration(serverName,PORT); //connConfig.setSASLAuthenticationEnabled(true); connConfig.setCompressionEnabled(true); connConfig.setSecurityMode(SecurityMode.disabled); /* //Connection configuration - generates a warning on startup because the truststore path is set to null if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.ICE_CREAM_SANDWICH) { connConfig.setKeystoreType("AndroidCAStore"); //connConfig.setKeystorePassword(null); connConfig.setKeystorePath(null); //connConfig.set } else { connConfig.setKeystoreType("BKS"); String path = System.getProperty("javax.net.ssl.trustStore"); if (path == null) path = System.getProperty("java.home") + File.separatorChar + "etc" + File.separatorChar + "security" + File.separatorChar + "cacerts.bks"; connConfig.setKeystorePath(path); } */ xmpp = new XMPPTCPConnection(connConfig); }