@Override public void onCreate() { super.onCreate(); createServiceRosterStub(); createServiceChatStub(); mPAlarmIntent = PendingIntent.getBroadcast(this, 0, mAlarmIntent, PendingIntent.FLAG_UPDATE_CURRENT); registerReceiver(mAlarmReceiver, new IntentFilter(RECONNECT_ALARM)); // for the initial connection, check if autoConnect is set mConnectionDemanded.set(mConfig.autoConnect); YaximBroadcastReceiver.initNetworkStatus(getApplicationContext()); if (mConfig.autoConnect) { /* * start our own service so it remains in background even when * unbound */ Intent xmppServiceIntent = new Intent(this, XMPPService.class); xmppServiceIntent.setAction("org.yaxim.androidclient.XMPPSERVICE"); startService(xmppServiceIntent); } mServiceNotification = ServiceNotification.getInstance(); }
private void connectionFailed(String reason) { logInfo("connectionFailed: " + reason); mLastConnectionError = reason; mIsConnected.set(false); broadcastConnectionStatus(false, mConnectionDemanded.get()); if (!networkConnected()) { mLastConnectionError = null; mReconnectInfo = ""; updateServiceNotification(); if (mSmackable != null) { mSmackable.unRegisterCallback(); mSmackable = null; } } else if (mConnectionDemanded.get()) { mReconnectInfo = getString(R.string.conn_reconnect, mReconnectTimeout); updateServiceNotification(); logInfo("connectionFailed(): registering reconnect in " + mReconnectTimeout + "s"); ((AlarmManager) getSystemService(Context.ALARM_SERVICE)) .set( AlarmManager.RTC_WAKEUP, System.currentTimeMillis() + mReconnectTimeout * 1000, mPAlarmIntent); mReconnectTimeout = mReconnectTimeout * 2; if (mReconnectTimeout > RECONNECT_MAXIMUM) mReconnectTimeout = RECONNECT_MAXIMUM; } else { mReconnectInfo = ""; mServiceNotification.hideNotification(this, SERVICE_NOTIFICATION); } }
public void performDisconnect() { if (mConnectingThread != null) { synchronized (mConnectingThread) { try { mConnectingThread.interrupt(); mConnectingThread.join(50); } catch (InterruptedException e) { logError("doDisconnect: failed catching connecting thread"); } finally { mConnectingThread = null; } } } if (mSmackable != null) { mSmackable.unRegisterCallback(); mSmackable = null; } connectionFailed(getString(R.string.conn_offline)); mServiceNotification.hideNotification(this, SERVICE_NOTIFICATION); }
private void updateServiceNotification() { if (!mConfig.foregroundService) return; String title = getString(R.string.conn_title, mConfig.jabberID); Notification n = new Notification(R.drawable.ic_offline, title, System.currentTimeMillis()); n.flags = Notification.FLAG_ONGOING_EVENT | Notification.FLAG_NO_CLEAR; Intent notificationIntent = new Intent(this, MainWindow.class); notificationIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP); n.contentIntent = PendingIntent.getActivity(this, 0, notificationIntent, PendingIntent.FLAG_UPDATE_CURRENT); String message = mLastConnectionError; if (message != null) message += mReconnectInfo; if (mIsConnected.get()) { message = MainWindow.getStatusTitle(this, mConfig.statusMode, mConfig.statusMessage); n.icon = R.drawable.ic_online; } n.setLatestEventInfo(this, title, message, n.contentIntent); mServiceNotification.showNotification(this, SERVICE_NOTIFICATION, n); }