Commits

rhynes committed d460ed2

Fix self-stopping tunnel. Added some translations.

Comments (0)

Files changed (5)

Android/PsiphonAndroid/src/com/psiphon3/StatusActivity.java

         // Auto-start on app first run
         if (m_firstRun)
         {
-        	m_firstRun = false;
-        	startUp();
+            m_firstRun = false;
+            startUp();
         }
     }
 
     
     public void onToggleClick(View v)
     {
-    	// TODO: use TunnelStartingReceiver/TunnelStoppingReceiver to track state?
-    	if (!isServiceRunning())
-    	{
-    		startUp();
-    	}
-    	else
-    	{
+        // TODO: use TunnelStartingReceiver/TunnelStoppingReceiver to track state?
+        if (!isServiceRunning())
+        {
+            startUp();
+        }
+        else
+        {
             stopTunnel(this);
-    	}
+        }
     }
 
     private void initToggleText()
     {
-    	// Only use this in onCreate. For updating the text when the activity
-    	// is showing and the service is stopping, it's more reliable to
-    	// use TunnelStoppingReceiver.
-    	m_toggleButton.setText(isServiceRunning() ? getText(R.string.stop) : getText(R.string.start));
+        // Only use this in onCreate. For updating the text when the activity
+        // is showing and the service is stopping, it's more reliable to
+        // use TunnelStoppingReceiver.
+        m_toggleButton.setText(isServiceRunning() ? getText(R.string.stop) : getText(R.string.start));
     }
     
     public class TunnelStartingReceiver extends BroadcastReceiver
         @Override
         public void onReceive(Context context, Intent intent)
         {
-        	m_toggleButton.setText(getText(R.string.stop));
+            m_toggleButton.setText(getText(R.string.stop));
         }
     }
 
         @Override
         public void onReceive(Context context, Intent intent)
         {
-        	m_toggleButton.setText(getText(R.string.start));
+            // When the tunnel self-stops, we also need to unbind to ensure the service is destroyed
+            unbindTunnelService();
+            m_toggleButton.setText(getText(R.string.start));
         }
     }
     
     public void onTunnelWholeDeviceToggle(View v)
     {
-    	boolean restart = false;
+        boolean restart = false;
 
-    	if (isServiceRunning())
+        if (isServiceRunning())
         {
-	        stopTunnel(this);
-	        restart = true;
+            stopTunnel(this);
+            restart = true;
         }
 
         boolean tunnelWholeDevicePreference = m_tunnelWholeDeviceToggle.isChecked();
         
         if (restart)
         {
-	        startTunnel(this);
+            startTunnel(this);
         }
     }
     
         else
         {
             upgradeListener.upgradeNotStarted();
-        }    	
+        }        
     }
     
     private void startTunnel(Context context)
     }
 
     private void doStopVpnTunnel(Context context)
-    {    	
-    	TunnelCore currentTunnelCore = PsiphonData.getPsiphonData().getCurrentTunnelCore();
-    	
-    	if (currentTunnelCore != null)
-    	{
-    		// See comments in stopVpnServiceHelper about stopService.
-    		currentTunnelCore.stopVpnServiceHelper();
-	        stopService(new Intent(context, TunnelVpnService.class));
-    	}
+    {        
+        TunnelCore currentTunnelCore = PsiphonData.getPsiphonData().getCurrentTunnelCore();
+        
+        if (currentTunnelCore != null)
+        {
+            // See comments in stopVpnServiceHelper about stopService.
+            currentTunnelCore.stopVpnServiceHelper();
+            stopService(new Intent(context, TunnelVpnService.class));
+        }
     }
     
     private void unbindTunnelService()
                 {
                     m_messagesScrollView.fullScroll(View.FOCUS_DOWN);
                 }
-            });    	
+            });
     }
     
     /**

Android/PsiphonAndroidLibrary/res/values-fa/strings.xml

   <string name="tun2socks_failed">وی پی ان به ساکس نا موفق بود</string>
   <string name="tun2socks_running">وی پی ان به ساکس فعال است</string>
   <string name="tun2socks_stopped">وی پی ان به ساکس متوقف شد</string>
+  <string name="check_tunnel_failed">تست برای تونل امکان پذیر نبود. گوشی شما قابلیت تونل تمام گوشی را پشتیبانی نمیکند.</string>
 </resources>

Android/PsiphonAndroidLibrary/res/values-zh/strings.xml

   <string name="tun2socks_failed">VPN至SOCKS已失败</string>
   <string name="tun2socks_running">VPN至SOCKS正在运行</string>
   <string name="tun2socks_stopped">VPN至SOCKS已停止</string>
+  <string name="check_tunnel_failed">检查隧道失败。您的设备可能不支持隧道整个设备的选项。</string>
 </resources>

Android/PsiphonAndroidLibrary/res/values/strings.xml

     <string name="tun2socks_stopped">VPN to SOCKS stopped</string>
     <string name="vpn_service_no_private_address_available">No private address available for VPN service</string>
     <string name="psiphon_running_generic">Running...</string>
-    <string name="check_tunnel_failed">Check tunnel request was not tunneled. Your device may not support the whole device tunnel option.</string>
+    <string name="check_tunnel_failed">Check tunnel failed. Your device may not support the whole device tunnel option.</string>
 </resources>

Android/PsiphonAndroidLibrary/src/com/psiphon3/psiphonlibrary/TunnelCore.java

                 {
                     try
                     {
-                        runTunnel();
+                        try
+                        {
+                            runTunnel();
+                        }
+                        catch (InterruptedException e)
+                        {
+                            Thread.currentThread().interrupt();
+                        }
+    
+                        if (m_eventsInterface != null)
+                        {
+                            m_eventsInterface.signalTunnelStopping(m_parentContext);
+                        }
+                        
+                        if (m_parentService != null)
+                        {
+                            // If the tunnel is stopping itself (e.g., due to a fatal error
+                            // where we don't try-next-server), then the service should stop itself.
+                            m_parentService.stopForeground(true);
+                            m_parentService.stopSelf();
+                        }
+    
+                        MyLog.v(R.string.stopped_tunnel, MyLog.Sensitivity.NOT_SENSITIVE);
+                        MyLog.e(R.string.psiphon_stopped, MyLog.Sensitivity.NOT_SENSITIVE);
                     }
-                    catch (InterruptedException e)
+                    finally
                     {
-                        Thread.currentThread().interrupt();
+                        m_signalQueue = null;
+                        m_tunnelThread = null;
                     }
                 }
             });
     public void signalUnexpectedDisconnect()
     {
         // Override STOP_TUNNEL; TODO: race condition?
-        m_signalQueue.clear();
-        m_signalQueue.offer(Signal.UNEXPECTED_DISCONNECT);
+        if (m_signalQueue != null)
+        {
+            m_signalQueue.clear();
+            m_signalQueue.offer(Signal.UNEXPECTED_DISCONNECT);
+        }
     }
     
     public void stopVpnServiceHelper()
     {
         if (m_tunnelThread != null)
         {
-            if (m_eventsInterface != null)
-            {
-                m_eventsInterface.signalTunnelStopping(m_parentContext);
-            }
+            MyLog.v(R.string.stopping_tunnel, MyLog.Sensitivity.NOT_SENSITIVE);
 
-            // TODO: ServerListReorder lifetime on Android isn't the same as on Windows
-            if (m_serverSelector != null)
-            {
-                m_serverSelector.Abort();
-                m_serverSelector = null;
-            }
+            // Wake up/interrupt the tunnel thread
             
             // Override UNEXPECTED_DISCONNECT; TODO: race condition?
             m_signalQueue.clear();
             m_signalQueue.offer(Signal.STOP_TUNNEL);
-
-            MyLog.v(R.string.stopping_tunnel, MyLog.Sensitivity.NOT_SENSITIVE);
+            
+            if (m_serverSelector != null)
+            {
+                m_serverSelector.Abort();
+            }
             
             // Tell the ServerInterface to stop (e.g., kill requests).
 
             {
                 Thread.currentThread().interrupt();
             }
-
-            MyLog.v(R.string.stopped_tunnel, MyLog.Sensitivity.NOT_SENSITIVE);
-            MyLog.e(R.string.psiphon_stopped, MyLog.Sensitivity.NOT_SENSITIVE);
         }
-        
-        m_signalQueue = null;
-        m_tunnelThread = null;
     }
     
     public void setEventsInterface(Events eventsInterface)