use of org.awesomeapp.messenger.service.adapters.ImConnectionAdapter in project Zom-Android by zom.
the class RemoteImService method do_createConnection.
private IImConnection do_createConnection(long providerId, long accountId) {
if (providerId == -1)
return null;
Map<String, String> settings = loadProviderSettings(providerId);
// make sure OTR is init'd before you create your first connection
initOtrChatManager();
ConnectionFactory factory = ConnectionFactory.getInstance();
try {
ImConnection conn = factory.createConnection(settings, this);
conn.initUser(providerId, accountId);
ImConnectionAdapter imConnectionAdapter = new ImConnectionAdapter(providerId, accountId, conn, this);
conn.addConnectionListener(new ConnectionListener() {
@Override
public void onStateChanged(int state, ImErrorInfo error) {
}
@Override
public void onUserPresenceUpdated() {
}
@Override
public void onUpdatePresenceError(ImErrorInfo error) {
}
});
ContentResolver contentResolver = getContentResolver();
Cursor cursor = contentResolver.query(Imps.ProviderSettings.CONTENT_URI, new String[] { Imps.ProviderSettings.NAME, Imps.ProviderSettings.VALUE }, Imps.ProviderSettings.PROVIDER + "=?", new String[] { Long.toString(providerId) }, null);
if (cursor == null)
throw new ImException("unable to query the provider settings");
Imps.ProviderSettings.QueryMap providerSettings = new Imps.ProviderSettings.QueryMap(cursor, contentResolver, providerId, false, null);
String userName = Imps.Account.getUserName(contentResolver, accountId);
String domain = providerSettings.getDomain();
providerSettings.close();
mConnections.put(providerId + "." + accountId, imConnectionAdapter);
mConnectionsByUser.put(imConnectionAdapter.getLoginUser().getAddress().getBareAddress(), imConnectionAdapter);
Debug.recordTrail(this, CONNECTIONS_TRAIL_TAG, "" + mConnections.size());
synchronized (mRemoteListeners) {
try {
final int N = mRemoteListeners.beginBroadcast();
for (int i = 0; i < N; i++) {
IConnectionCreationListener listener = mRemoteListeners.getBroadcastItem(i);
try {
listener.onConnectionCreated(imConnectionAdapter);
} catch (RemoteException e) {
// The RemoteCallbackList will take care of removing the
// dead listeners.
}
}
} finally {
mRemoteListeners.finishBroadcast();
}
}
return imConnectionAdapter;
} catch (ImException e) {
debug("Error creating connection", e);
return null;
}
}
use of org.awesomeapp.messenger.service.adapters.ImConnectionAdapter in project Zom-Android by zom.
the class RemoteImService method networkStateChanged.
void networkStateChanged(NetworkInfo networkInfo, NetworkConnectivityReceiver.State networkState) {
int networkType = networkInfo != null ? networkInfo.getType() : -1;
debug("networkStateChanged: type=" + networkInfo + " state=" + networkState);
boolean networkChanged = false;
if (mNetworkType != networkType || mNetworkState != networkState) {
mNetworkState = networkState;
mNetworkType = networkType;
networkChanged = true;
if (isNetworkAvailable()) {
if (mNeedCheckAutoLogin) {
mNeedCheckAutoLogin = !autoLogin();
}
for (ImConnectionAdapter conn : mConnections.values()) {
conn.networkTypeChanged();
}
} else {
suspendConnections();
}
// update the notification
if (mNotifyBuilder != null) {
String message = "";
if (!isNetworkAvailable()) {
message = getString(R.string.error_suspended_connection);
mNotifyBuilder.setSmallIcon(R.drawable.notify_zom);
} else {
message = getString(R.string.app_unlocked);
mNotifyBuilder.setSmallIcon(R.drawable.notify_zom);
}
mNotifyBuilder.setContentText(message);
// Because the ID remains unchanged, the existing notification is
// updated.
mNotifyManager.notify(notifyId, mNotifyBuilder.build());
}
}
}
use of org.awesomeapp.messenger.service.adapters.ImConnectionAdapter in project Zom-Android by zom.
the class RemoteImService method reestablishConnections.
// package private for inner class access
boolean reestablishConnections() {
// restart transports if needed
if (Preferences.useAdvancedNetworking()) {
if (aNetworking != null) {
aNetworking.stopTransport();
}
aNetworking = new AdvancedNetworking();
aNetworking.installTransport(this, "ss");
aNetworking.startTransport();
}
for (ImConnectionAdapter conn : mConnections.values()) {
int connState = conn.getState();
if (connState == ImConnection.SUSPENDED) {
conn.reestablishSession();
}
}
return mConnections.values().size() > 0;
}
use of org.awesomeapp.messenger.service.adapters.ImConnectionAdapter in project Zom-Android by zom.
the class RemoteImService method shutdown.
private void shutdown() {
Debug.recordTrail(this, SERVICE_DESTROY_TRAIL_TAG, new Date());
HeartbeatService.stopBeating(getApplicationContext());
debug("ImService stopped.");
for (ImConnectionAdapter conn : mConnections.values()) {
if (conn.getState() == ImConnection.LOGGED_IN)
conn.logout();
}
stopForeground(true);
/* ignore unmount errors and quit ASAP. Threads actively using the VFS will
* cause IOCipher's VirtualFileSystem.unmount() to throw an IllegalStateException */
try {
if (SecureMediaStore.isMounted())
SecureMediaStore.unmount();
} catch (IllegalStateException e) {
debug("there was a problem unmount secure media store: " + e.getMessage());
}
if (mCacheWord != null && (!mCacheWord.isLocked())) {
mCacheWord.lock();
mCacheWord.disconnectFromService();
}
}
use of org.awesomeapp.messenger.service.adapters.ImConnectionAdapter in project Zom-Android by zom.
the class RemoteImService method onCreate.
@Override
public void onCreate() {
debug("ImService started");
final String prev = Debug.getTrail(this, SERVICE_CREATE_TRAIL_KEY);
if (prev != null)
Debug.recordTrail(this, PREV_SERVICE_CREATE_TRAIL_TAG, prev);
Debug.recordTrail(this, SERVICE_CREATE_TRAIL_KEY, new Date());
final String prevConnections = Debug.getTrail(this, CONNECTIONS_TRAIL_TAG);
if (prevConnections != null)
Debug.recordTrail(this, PREV_CONNECTIONS_TRAIL_TAG, prevConnections);
Debug.recordTrail(this, CONNECTIONS_TRAIL_TAG, "0");
mConnections = new Hashtable<String, ImConnectionAdapter>();
mConnectionsByUser = new Hashtable<String, ImConnectionAdapter>();
mHandler = new Handler();
Debug.onServiceStart();
PowerManager powerManager = (PowerManager) getSystemService(Context.POWER_SERVICE);
mWakeLock = powerManager.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, "IM_WAKELOCK");
// Clear all account statii to logged-out, since we just got started and we don't want
// leftovers from any previous crash.
clearConnectionStatii();
mStatusBarNotifier = new StatusBarNotifier(this);
mServiceHandler = new ServiceHandler();
mPluginHelper = ImPluginHelper.getInstance(this);
mPluginHelper.loadAvailablePlugins();
// Have the heartbeat start autoLogin, unless onStart turns this off
mNeedCheckAutoLogin = true;
HeartbeatService.startBeating(getApplicationContext());
if (Preferences.getUseForegroundPriority()) {
startForeground(notifyId, getForegroundNotification());
}
installTransports(this);
}
Aggregations