Просмотр исходного кода

Minor refactoring of the feedback sending code:
- Change `stopSendFeedback` signature to void since we never inspect the result.
- Change `ExecutorService.submit()` calls to `ExecutorService.execute()` for the same reason as above.

Eugene Fryntov 3 лет назад
Родитель
Сommit
14fa339cd0
1 измененных файлов с 9 добавлено и 18 удалено
  1. 9 18
      MobileLibrary/Android/PsiphonTunnel/PsiphonTunnel.java

+ 9 - 18
MobileLibrary/Android/PsiphonTunnel/PsiphonTunnel.java

@@ -390,7 +390,7 @@ public class PsiphonTunnel {
             workQueue = Executors.newSingleThreadExecutor();
             workQueue = Executors.newSingleThreadExecutor();
             callbackQueue = Executors.newSingleThreadExecutor();
             callbackQueue = Executors.newSingleThreadExecutor();
 
 
-            workQueue.submit(new Runnable() {
+            workQueue.execute(new Runnable() {
                 @Override
                 @Override
                 public void run() {
                 public void run() {
                     try {
                     try {
@@ -403,7 +403,7 @@ public class PsiphonTunnel {
                                     @Override
                                     @Override
                                     public void sendFeedbackCompleted(java.lang.Exception e) {
                                     public void sendFeedbackCompleted(java.lang.Exception e) {
                                         try {
                                         try {
-                                            callbackQueue.submit(new Runnable() {
+                                            callbackQueue.execute(new Runnable() {
                                                 @Override
                                                 @Override
                                                 public void run() {
                                                 public void run() {
                                                     feedbackHandler.sendFeedbackCompleted(e);
                                                     feedbackHandler.sendFeedbackCompleted(e);
@@ -486,7 +486,7 @@ public class PsiphonTunnel {
 
 
                                             String diagnosticMessage = noticeType + ": " + data.toString();
                                             String diagnosticMessage = noticeType + ": " + data.toString();
                                             try {
                                             try {
-                                                callbackQueue.submit(new Runnable() {
+                                                callbackQueue.execute(new Runnable() {
                                                     @Override
                                                     @Override
                                                     public void run() {
                                                     public void run() {
                                                         logger.onDiagnosticMessage(diagnosticMessage);
                                                         logger.onDiagnosticMessage(diagnosticMessage);
@@ -496,7 +496,7 @@ public class PsiphonTunnel {
                                             }
                                             }
                                         } catch (java.lang.Exception e) {
                                         } catch (java.lang.Exception e) {
                                             try {
                                             try {
-                                                callbackQueue.submit(new Runnable() {
+                                                callbackQueue.execute(new Runnable() {
                                                     @Override
                                                     @Override
                                                     public void run() {
                                                     public void run() {
                                                         logger.onDiagnosticMessage("Error handling notice " + e.toString());
                                                         logger.onDiagnosticMessage("Error handling notice " + e.toString());
@@ -512,7 +512,7 @@ public class PsiphonTunnel {
                                 );
                                 );
                     } catch (java.lang.Exception e) {
                     } catch (java.lang.Exception e) {
                         try {
                         try {
-                            callbackQueue.submit(new Runnable() {
+                            callbackQueue.execute(new Runnable() {
                                 @Override
                                 @Override
                                 public void run() {
                                 public void run() {
                                     feedbackHandler.sendFeedbackCompleted(new Exception("Error sending feedback", e));
                                     feedbackHandler.sendFeedbackCompleted(new Exception("Error sending feedback", e));
@@ -525,22 +525,18 @@ public class PsiphonTunnel {
             });
             });
         }
         }
 
 
-        // Interrupt an in-progress feedback upload operation started with startSendFeedback(). This
-        // call is asynchronous and returns a future which is fulfilled when the underlying stop
-        // operation completes.
-        public Future<Void> stopSendFeedback() {
-            Future<Void> result = workQueue.submit(new Runnable() {
+        // Interrupt an in-progress feedback upload operation started with startSendFeedback().
+        public void stopSendFeedback() {
+            workQueue.execute(new Runnable() {
                 @Override
                 @Override
                 public void run() {
                 public void run() {
                     Psi.stopSendFeedback();
                     Psi.stopSendFeedback();
                 }
                 }
-            }, null);
+            });
 
 
             // Also shutdown executor queues
             // Also shutdown executor queues
             shutdownAndAwaitTermination(workQueue);
             shutdownAndAwaitTermination(workQueue);
             shutdownAndAwaitTermination(callbackQueue);
             shutdownAndAwaitTermination(callbackQueue);
-
-            return result;
         }
         }
     }
     }
 
 
@@ -802,9 +798,7 @@ public class PsiphonTunnel {
         ConnectivityManager connectivityManager = (ConnectivityManager)context.getSystemService(Context.CONNECTIVITY_SERVICE);
         ConnectivityManager connectivityManager = (ConnectivityManager)context.getSystemService(Context.CONNECTIVITY_SERVICE);
 
 
         if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
         if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
-
             if (!isVpnMode) {
             if (!isVpnMode) {
-
                 NetworkCapabilities capabilities = null;
                 NetworkCapabilities capabilities = null;
                 try {
                 try {
                     Network nw = connectivityManager.getActiveNetwork();
                     Network nw = connectivityManager.getActiveNetwork();
@@ -819,15 +813,12 @@ public class PsiphonTunnel {
                 if (capabilities != null && capabilities.hasTransport(NetworkCapabilities.TRANSPORT_VPN)) {
                 if (capabilities != null && capabilities.hasTransport(NetworkCapabilities.TRANSPORT_VPN)) {
                     return "VPN";
                     return "VPN";
                 }
                 }
-
             }
             }
-
         }
         }
 
 
         NetworkInfo activeNetworkInfo = null;
         NetworkInfo activeNetworkInfo = null;
         try {
         try {
             activeNetworkInfo = connectivityManager.getActiveNetworkInfo();
             activeNetworkInfo = connectivityManager.getActiveNetworkInfo();
-
         } catch (java.lang.Exception e) {
         } catch (java.lang.Exception e) {
             // May get exceptions due to missing permissions like android.permission.ACCESS_NETWORK_STATE.
             // May get exceptions due to missing permissions like android.permission.ACCESS_NETWORK_STATE.