[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]

[tor-commits] [snowflake-mobile/master] Used closeConnections function in onDestroy to clear connections



commit 7cac3c5b732f9bc97dc345e8cec9d34a266e481a
Author: Hashik Donthineni <HashikDonthineni@xxxxxxxxx>
Date:   Fri Jul 10 23:48:45 2020 +0530

    Used closeConnections function in onDestroy to clear connections
---
 .../torproject/snowflake/MyPersistentService.java  | 22 +++++++++-------------
 1 file changed, 9 insertions(+), 13 deletions(-)

diff --git a/app/src/main/java/org/torproject/snowflake/MyPersistentService.java b/app/src/main/java/org/torproject/snowflake/MyPersistentService.java
index 7654997..8d7da11 100644
--- a/app/src/main/java/org/torproject/snowflake/MyPersistentService.java
+++ b/app/src/main/java/org/torproject/snowflake/MyPersistentService.java
@@ -114,17 +114,8 @@ public class MyPersistentService extends Service {
     @Override
     public void onDestroy() {
         sharedPreferencesHelper(ForegroundServiceConstants.SERVICE_STOPPED);
-        if (compositeDisposable != null)
-            compositeDisposable.dispose(); //Disposing all the threads. Including network calls.
-        if (mainDataChannel != null) {
-            mainDataChannel.close();
-        }
-        if (mainPeerConnection != null) {
-            mainPeerConnection.close();
-            mainPeerConnection.dispose();
-        }
-        if (webSocket != null)
-            webSocket.close(1000, "Normal closure");
+        //Close and dispose off all connections
+        closeConnections(false);
         mNotificationManager.cancel(ForegroundServiceConstants.DEF_NOTIFICATION_ID);
         Log.d(TAG, "onDestroy: Service Destroyed");
         super.onDestroy();
@@ -484,15 +475,20 @@ public class MyPersistentService extends Service {
     private void closeConnections(boolean resend) {
         if (!resend) { //If you don't want to resend
             Log.d(TAG, "closeConnection: Closing connection");
-            //Closing both to avoid memory leak.
+            //Closing all to avoid memory leak.
             if (mainDataChannel != null)
                 mainDataChannel.close();
-            if (mainPeerConnection != null)
+
+            if (mainPeerConnection != null){
                 mainPeerConnection.close();
+                mainPeerConnection.dispose();
+            }
+
             if (webSocket != null && isWebSocketOpen) {
                 webSocket.close(1000, "Normal closure");
                 isWebSocketOpen = false;
             }
+
             if (compositeDisposable != null)
                 compositeDisposable.dispose(); //Disposing all the threads. Including network calls.
 

_______________________________________________
tor-commits mailing list
tor-commits@xxxxxxxxxxxxxxxxxxxx
https://lists.torproject.org/cgi-bin/mailman/listinfo/tor-commits