commit da0fb101f3b56588c2b92137fc770120eedb1cab Author: Nathan Freitas nathan@freitas.net Date: Wed Oct 12 16:01:09 2016 -0400
multiple fixes to re-enable VPN mode and pdnsd daemon --- .../org/torproject/android/OnBootReceiver.java | 5 +- .../org/torproject/android/OrbotMainActivity.java | 60 +++--- .../torproject/android/vpn/VPNEnableActivity.java | 1 - app/src/main/res/layout/layout_main.xml | 225 ++++++++++----------- external/Makefile | 2 +- .../org/torproject/android/service/TorService.java | 62 +++--- .../android/service/TorServiceConstants.java | 5 +- .../android/service/vpn/OrbotVpnManager.java | 19 +- orbotservice/src/main/jni/Application.mk | 3 +- orbotservice/src/main/res/values/pdnsd.xml | 6 +- 10 files changed, 195 insertions(+), 193 deletions(-)
diff --git a/app/src/main/java/org/torproject/android/OnBootReceiver.java b/app/src/main/java/org/torproject/android/OnBootReceiver.java index 91d6beb..722f4f1 100644 --- a/app/src/main/java/org/torproject/android/OnBootReceiver.java +++ b/app/src/main/java/org/torproject/android/OnBootReceiver.java @@ -16,10 +16,9 @@ public class OnBootReceiver extends BroadcastReceiver {
@Override public void onReceive(Context context, Intent intent) { - Prefs.setContext(context); - if (Prefs.startOnBoot() && (!sReceivedBoot)) - {
+ if (Prefs.startOnBoot() && (!sReceivedBoot)) + { if (Prefs.useVpn()) startVpnService(context); //VPN will start Tor once it is done else diff --git a/app/src/main/java/org/torproject/android/OrbotMainActivity.java b/app/src/main/java/org/torproject/android/OrbotMainActivity.java index c243c67..8b9cb5b 100644 --- a/app/src/main/java/org/torproject/android/OrbotMainActivity.java +++ b/app/src/main/java/org/torproject/android/OrbotMainActivity.java @@ -52,6 +52,7 @@ import android.support.v4.content.LocalBroadcastManager; import android.support.v4.widget.DrawerLayout; import android.support.v7.app.ActionBarDrawerToggle; import android.support.v7.app.AppCompatActivity; +import android.support.v7.widget.SwitchCompat; import android.support.v7.widget.Toolbar; import android.util.AttributeSet; import android.util.Log; @@ -70,10 +71,10 @@ import android.widget.AdapterView; import android.widget.AdapterView.OnItemSelectedListener; import android.widget.ArrayAdapter; import android.widget.Button; +import android.widget.CompoundButton; import android.widget.Spinner; import android.widget.TextView; import android.widget.Toast; -import android.widget.ToggleButton;
import com.google.zxing.integration.android.IntentIntegrator; import com.google.zxing.integration.android.IntentResult; @@ -89,9 +90,9 @@ public class OrbotMainActivity extends AppCompatActivity private TextView uploadText = null; private TextView mTxtOrbotLog = null;
- private Button mBtnBrowser = null; - private ToggleButton mBtnVPN = null; - private ToggleButton mBtnBridges = null; + // private Button mBtnBrowser = null; + private SwitchCompat mBtnVPN = null; + private SwitchCompat mBtnBridges = null;
private Spinner spnCountries = null;
@@ -257,7 +258,7 @@ public class OrbotMainActivity extends AppCompatActivity
// Gesture detection mGestureDetector = new GestureDetector(this, new MyGestureDetector()); - + /** mBtnBrowser = (Button)findViewById(R.id.btnBrowser); mBtnBrowser.setOnClickListener(new View.OnClickListener () { @@ -271,8 +272,9 @@ public class OrbotMainActivity extends AppCompatActivity }); mBtnBrowser.setEnabled(false); - - mBtnVPN = (ToggleButton)findViewById(R.id.btnVPN); + */ + + mBtnVPN = (SwitchCompat)findViewById(R.id.btnVPN); boolean canDoVPN = Build.VERSION.SDK_INT >= Build.VERSION_CODES.ICE_CREAM_SANDWICH;
@@ -292,24 +294,23 @@ public class OrbotMainActivity extends AppCompatActivity startActivity(new Intent(OrbotMainActivity.this,VPNEnableActivity.class)); } - mBtnVPN.setOnClickListener(new View.OnClickListener () - { - - @Override - public void onClick(View v) { - - if (mBtnVPN.isChecked()) - startActivity(new Intent(OrbotMainActivity.this,VPNEnableActivity.class)); - else - stopVpnService(); - - } - - }); + mBtnVPN.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() + { + @Override + public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) + { + if (isChecked) + startActivity(new Intent(OrbotMainActivity.this,VPNEnableActivity.class)); + else + stopVpnService(); + } + }); + + } - mBtnBridges = (ToggleButton)findViewById(R.id.btnBridges); + mBtnBridges = (SwitchCompat)findViewById(R.id.btnBridges); mBtnBridges.setChecked(Prefs.bridgesEnabled()); mBtnBridges.setOnClickListener(new View.OnClickListener () { @@ -323,7 +324,6 @@ public class OrbotMainActivity extends AppCompatActivity } else { - Toast.makeText(OrbotMainActivity.this, R.string.note_only_standard_tor_bridges_work_on_intel_x86_atom_devices, Toast.LENGTH_LONG).show(); showGetBridgePrompt(""); //if other chip ar, only stock bridges are supported } } @@ -1063,11 +1063,7 @@ public class OrbotMainActivity extends AppCompatActivity protected void onResume() { super.onResume();
- if (mPrefs != null) - { - mBtnVPN.setChecked(Prefs.useVpn()); - mBtnBridges.setChecked(Prefs.bridgesEnabled()); - } + mBtnBridges.setChecked(Prefs.bridgesEnabled());
requestTorStatus();
@@ -1124,7 +1120,7 @@ public class OrbotMainActivity extends AppCompatActivity imgStatus.setImageResource(R.drawable.toron);
- mBtnBrowser.setEnabled(true); + //mBtnBrowser.setEnabled(true);
if (torServiceMsg != null) { @@ -1170,7 +1166,7 @@ public class OrbotMainActivity extends AppCompatActivity else lblStatus.setText(getString(R.string.status_starting_up));
- mBtnBrowser.setEnabled(false); + // mBtnBrowser.setEnabled(false);
} else if (torStatus == TorServiceConstants.STATUS_STOPPING) {
@@ -1179,13 +1175,13 @@ public class OrbotMainActivity extends AppCompatActivity imgStatus.setImageResource(R.drawable.torstarting); lblStatus.setText(torServiceMsg); - mBtnBrowser.setEnabled(false); + // mBtnBrowser.setEnabled(false);
} else if (torStatus == TorServiceConstants.STATUS_OFF) {
imgStatus.setImageResource(R.drawable.toroff); lblStatus.setText(getString(R.string.press_to_start)); - mBtnBrowser.setEnabled(false); +// mBtnBrowser.setEnabled(false); }
if (torServiceMsg != null && torServiceMsg.length() > 0) diff --git a/app/src/main/java/org/torproject/android/vpn/VPNEnableActivity.java b/app/src/main/java/org/torproject/android/vpn/VPNEnableActivity.java index 6bbae30..9ed87d6 100644 --- a/app/src/main/java/org/torproject/android/vpn/VPNEnableActivity.java +++ b/app/src/main/java/org/torproject/android/vpn/VPNEnableActivity.java @@ -71,7 +71,6 @@ public class VPNEnableActivity extends Activity { @Override public void onClick(DialogInterface dialog, int which) { Prefs.putUseVpn(true); - startVpnService(); } diff --git a/app/src/main/res/layout/layout_main.xml b/app/src/main/res/layout/layout_main.xml index 35dddc4..b834135 100644 --- a/app/src/main/res/layout/layout_main.xml +++ b/app/src/main/res/layout/layout_main.xml @@ -30,92 +30,7 @@ android:layout_height="wrap_content"
> - - <LinearLayout - android:layout_width="match_parent" - android:layout_height="match_parent" - android:orientation="vertical" - - > - - - <!-- - <TextView android:id="@+id/lblStatus" - android:text="status status status" - android:gravity="center_horizontal" - android:textSize="20sp" - android:layout_width="match_parent" - android:layout_height="wrap_content" - android:layout_marginBottom="10dp" - android:layout_marginTop="10dp" - android:layout_marginLeft="40dp" - android:layout_marginRight="40dp" - android:textColor="#ffffff" - android:maxLines="1" - android:fontFamily="sans-serif-light" - /> - --> - - <RelativeLayout - android:id="@+id/rowTrafficDown" - android:layout_width="match_parent" - android:layout_height="wrap_content" - android:orientation="horizontal" - android:paddingLeft="3sp" - android:paddingRight="3sp" - - > - <TextView - android:id="@+id/trafficLabelDown" - android:layout_width="wrap_content" - android:layout_height="wrap_content" - android:layout_alignParentLeft="true" - android:textSize="15sp" - android:text="@string/main_layout_download" - android:gravity="center_vertical" - android:fontFamily="sans-serif-light" /> - <TextView - android:id="@+id/trafficLabelUp" - android:layout_width="wrap_content" - android:layout_height="wrap_content" - android:layout_alignParentRight="true" - android:text="@string/main_layout_upload" - android:textSize="15sp" - android:gravity="center_vertical" - android:fontFamily="sans-serif-light" /> - - </RelativeLayout> - <RelativeLayout - android:id="@+id/rowTrafficUp" - android:layout_width="fill_parent" - android:layout_height="wrap_content" - android:paddingLeft="3sp" - android:paddingRight="3sp" - android:paddingBottom="3sp" - - > - <TextView - android:id="@+id/trafficDown" - android:layout_width="wrap_content" - android:layout_height="wrap_content" - android:layout_alignParentLeft="true" - android:textSize="15sp" - android:gravity="center_vertical" - android:fontFamily="sans-serif-light" - /> - - <TextView - android:id="@+id/trafficUp" - android:layout_width="wrap_content" - android:layout_height="wrap_content" - android:layout_alignParentRight="true" - android:textSize="15sp" - android:gravity="center_vertical" - android:fontFamily="sans-serif-light" - /> - </RelativeLayout> - </LinearLayout> - +
<ProgressBar android:id="@+id/pbConnecting" @@ -138,10 +53,9 @@ android:layout_gravity="center_horizontal|center_vertical"/> <org.torproject.android.ui.ImageProgressView android:id="@+id/imgStatus" android:layout_width="match_parent" - android:layout_height="0dp" - android:layout_weight=".8" - - android:padding="0dp" + android:layout_height="275dp" + + android:padding="0dp" android:layout_margin="0dp" android:src="@drawable/toroff" /> @@ -154,20 +68,20 @@ android:layout_gravity="center_horizontal|center_vertical"/> android:fontFamily="sans-serif-light" android:text="" android:lines="2" - android:maxLines="2" + android:maxLines="2" android:layout_gravity="center_horizontal" android:layout_margin="0dp" - android:layout_marginLeft="5dp" + android:layout_marginLeft="5dp" android:layout_marginRight="5dp" /> <LinearLayout android:gravity="center_horizontal" android:orientation="horizontal" android:layout_width="match_parent" android:layout_height="wrap_content" - - android:layout_gravity="bottom" + > - + + <!-- <Button android:id="@+id/btnBrowser" android:layout_width="wrap_content" @@ -177,44 +91,129 @@ android:layout_gravity="center_horizontal|center_vertical"/> android:layout_marginBottom="3dp" android:ellipsize="end" android:singleLine="true" - /> + />--> - <ToggleButton + <android.support.v7.widget.SwitchCompat android:id="@+id/btnVPN" - android:layout_width="wrap_content" + android:layout_width="100dp" android:layout_height="wrap_content" - android:textOff="@string/menu_vpn" - android:textOn="@string/menu_vpn" + android:text="@string/menu_vpn" android:layout_margin="3dp" android:ellipsize="end" android:singleLine="true" /> - <ToggleButton + <android.support.v7.widget.SwitchCompat android:id="@+id/btnBridges" - android:layout_width="wrap_content" + android:layout_width="100dp" android:layout_height="wrap_content" - android:textOff="@string/bridges" - android:textOn="@string/bridges" + android:text="@string/bridges" android:layout_marginTop="3dp" + android:layout_marginLeft="25dp" android:layout_marginBottom="3dp" android:ellipsize="end" android:singleLine="true" />
- <Spinner - android:id="@+id/spinnerCountry" - android:layout_width="wrap_content" - android:layout_height="wrap_content" - android:layout_weight="1" - /> - + </LinearLayout> </LinearLayout> - - </LinearLayout> + <Spinner + android:id="@+id/spinnerCountry" + android:layout_width="200dp" + android:layout_height="wrap_content" + android:layout_weight="1" + /> + + </LinearLayout> + + <LinearLayout + android:layout_width="match_parent" + android:layout_height="match_parent" + android:orientation="vertical" + android:gravity="bottom" + android:padding="6dp" + > + + + <!-- + <TextView android:id="@+id/lblStatus" + android:text="status status status" + android:gravity="center_horizontal" + android:textSize="20sp" + android:layout_width="match_parent" + android:layout_height="wrap_content" + android:layout_marginBottom="10dp" + android:layout_marginTop="10dp" + android:layout_marginLeft="40dp" + android:layout_marginRight="40dp" + android:textColor="#ffffff" + android:maxLines="1" + android:fontFamily="sans-serif-light" + /> + --> + + <RelativeLayout + android:id="@+id/rowTrafficDown" + android:layout_width="match_parent" + android:layout_height="wrap_content" + android:orientation="horizontal" + android:paddingLeft="3sp" + android:paddingRight="3sp" + + > + <TextView + android:id="@+id/trafficLabelDown" + android:layout_width="wrap_content" + android:layout_height="wrap_content" + android:layout_alignParentLeft="true" + android:textSize="15sp" + android:text="@string/main_layout_download" + android:gravity="center_vertical" + android:fontFamily="sans-serif-light" /> + <TextView + android:id="@+id/trafficLabelUp" + android:layout_width="wrap_content" + android:layout_height="wrap_content" + android:layout_alignParentRight="true" + android:text="@string/main_layout_upload" + android:textSize="15sp" + android:gravity="center_vertical" + android:fontFamily="sans-serif-light" /> + + </RelativeLayout> + <RelativeLayout + android:id="@+id/rowTrafficUp" + android:layout_width="fill_parent" + android:layout_height="wrap_content" + android:paddingLeft="3sp" + android:paddingRight="3sp" + android:paddingBottom="3sp" + + > + <TextView + android:id="@+id/trafficDown" + android:layout_width="wrap_content" + android:layout_height="wrap_content" + android:layout_alignParentLeft="true" + android:textSize="15sp" + android:gravity="center_vertical" + android:fontFamily="sans-serif-light" + /> + + <TextView + android:id="@+id/trafficUp" + android:layout_width="wrap_content" + android:layout_height="wrap_content" + android:layout_alignParentRight="true" + android:textSize="15sp" + android:gravity="center_vertical" + android:fontFamily="sans-serif-light" + /> + </RelativeLayout> + </LinearLayout> </LinearLayout> <LinearLayout diff --git a/external/Makefile b/external/Makefile index 21c87a1..850e92c 100644 --- a/external/Makefile +++ b/external/Makefile @@ -314,7 +314,7 @@ assets: tor polipo iptables pluto -zip ../orbotservice/src/main/assets/$(APP_ABI)/xtables.mp3 bin/xtables -$(STRIP) bin/obfs4proxy -zip ../orbotservice/src/main/assets/$(APP_ABI)/obfs4proxy.mp3 bin/obfs4proxy - -$(STRIP) ../app/src/main/libs/$(APP_ABI)/pdnsd + -$(STRIP) ../orbotservice/src/main/libs/$(APP_ABI)/pdnsd -zip ../orbotservice/src/main/assets/$(APP_ABI)/pdnsd.mp3 ../orbotservice/src/main/libs/$(APP_ABI)/pdnsd -rm ../orbotservice/src/main/libs/$(APP_ABI)/pdnsd
diff --git a/orbotservice/src/main/java/org/torproject/android/service/TorService.java b/orbotservice/src/main/java/org/torproject/android/service/TorService.java index 2cff209..fc06e2e 100644 --- a/orbotservice/src/main/java/org/torproject/android/service/TorService.java +++ b/orbotservice/src/main/java/org/torproject/android/service/TorService.java @@ -121,7 +121,6 @@ public class TorService extends Service implements TorServiceConstants, OrbotCon public static File fileObfsclient; public static File fileXtables; public static File fileTorRc; - public static File filePdnsd;
public void debug(String msg) @@ -227,8 +226,11 @@ public class TorService extends Service implements TorServiceConstants, OrbotCon }
mNotifyBuilder.setOngoing(Prefs.persistNotifications()); - - mNotification = mNotifyBuilder.build(); + mNotifyBuilder.setPriority(Notification.PRIORITY_LOW); + mNotifyBuilder.setCategory(Notification.CATEGORY_SERVICE); + + + mNotification = mNotifyBuilder.build();
if (Build.VERSION.SDK_INT >= 16 && Prefs.expandedNotifications()) { // Create remote view that needs to be set as bigContentView for the notification. @@ -531,7 +533,6 @@ public class TorService extends Service implements TorServiceConstants, OrbotCon fileObfsclient = new File(appBinHome, TorServiceConstants.OBFSCLIENT_ASSET_KEY); fileXtables = new File(appBinHome, TorServiceConstants.IPTABLES_ASSET_KEY); fileTorRc = new File(appBinHome, TorServiceConstants.TORRC_ASSET_KEY); - filePdnsd = new File(appBinHome, TorServiceConstants.PDNSD_ASSET_KEY);
mEventHandler = new TorEventHandler(this);
@@ -726,7 +727,7 @@ public class TorService extends Service implements TorServiceConstants, OrbotCon // these states should probably be handled better sendCallbackLogMessage("Ignoring start request, currently " + mCurrentStatus); return; - } else if (mCurrentStatus == STATUS_ON && findExistingTorDaemon()) { + } else if (mCurrentStatus == STATUS_ON) {
sendCallbackLogMessage("Ignoring start request, already started.");
@@ -1444,7 +1445,7 @@ public class TorService extends Service implements TorServiceConstants, OrbotCon @Override public void onReceive(Context context, Intent intent) {
- if (mCurrentStatus != STATUS_ON) + if (mCurrentStatus == STATUS_OFF) return; SharedPreferences prefs = TorServiceUtils.getSharedPrefs(getApplicationContext()); @@ -1484,39 +1485,36 @@ public class TorService extends Service implements TorServiceConstants, OrbotCon { logNotice(context.getString(R.string.no_network_connectivity_putting_tor_to_sleep_)); showToolbarNotification(getString(R.string.no_internet_connection_tor),NOTIFY_ID,R.drawable.ic_stat_tor_off); - + } else { logNotice(context.getString(R.string.network_connectivity_is_good_waking_tor_up_)); showToolbarNotification(getString(R.string.status_activated),NOTIFY_ID,R.drawable.ic_stat_tor); } - - //is this a change in state? - if (isChanged) - { - try { - - if (mCurrentStatus != STATUS_OFF) - { - if (mConnectivity) - { - if (Prefs.useRoot() && Prefs.useTransparentProxying() && Prefs.transProxyNetworkRefresh()) - { - - - disableTransparentProxy(); - enableTransparentProxy(); - - } - } - } - - } catch (Exception e) { - logException ("error updating state after network restart",e); - } + + try { + + if (mCurrentStatus != STATUS_OFF) + { + if (mConnectivity) + { + if (Prefs.useRoot() && Prefs.useTransparentProxying() && Prefs.transProxyNetworkRefresh()) + { + + + disableTransparentProxy(); + enableTransparentProxy(); + + } + } + } + + } catch (Exception e) { + logException ("error updating state after network restart",e); + } - } + }
diff --git a/orbotservice/src/main/java/org/torproject/android/service/TorServiceConstants.java b/orbotservice/src/main/java/org/torproject/android/service/TorServiceConstants.java index e2f0964..f431b0c 100644 --- a/orbotservice/src/main/java/org/torproject/android/service/TorServiceConstants.java +++ b/orbotservice/src/main/java/org/torproject/android/service/TorServiceConstants.java @@ -133,9 +133,8 @@ public interface TorServiceConstants { public static final String CMD_UPDATE_TRANS_PROXY = "update"; public static final String CMD_SET_EXIT = "setexit";
- - - public static final String BINARY_TOR_VERSION = "0.2.7.5-020120160125"; + + public static final String BINARY_TOR_VERSION = "0.2.8.1-1"; public static final String PREF_BINARY_TOR_VERSION_INSTALLED = "BINARY_TOR_VERSION_INSTALLED";
//obfsproxy diff --git a/orbotservice/src/main/java/org/torproject/android/service/vpn/OrbotVpnManager.java b/orbotservice/src/main/java/org/torproject/android/service/vpn/OrbotVpnManager.java index ae03881..5830a85 100644 --- a/orbotservice/src/main/java/org/torproject/android/service/vpn/OrbotVpnManager.java +++ b/orbotservice/src/main/java/org/torproject/android/service/vpn/OrbotVpnManager.java @@ -86,7 +86,9 @@ public class OrbotVpnManager implements Handler.Callback { public OrbotVpnManager (VpnService service) { mService = service; - filePdnsd = mService.getDir(TorServiceConstants.DIRECTORY_TOR_BINARY, Application.MODE_PRIVATE); + + File fileBinHome = mService.getDir(TorServiceConstants.DIRECTORY_TOR_BINARY, Application.MODE_PRIVATE); + filePdnsd = new File(fileBinHome,TorServiceConstants.PDNSD_ASSET_KEY);
}
@@ -428,8 +430,19 @@ public class OrbotVpnManager implements Handler.Callback { ps.close(); //f.withWriter { out -> out.print conf }; - - + + /** + * + + server { + label= "upstream"; + ip = %s; + port = %d; + uptest = none; + } + */ + + File cache = new File(fileDir,"pdnsd.cache");
if (!cache.exists()) { diff --git a/orbotservice/src/main/jni/Application.mk b/orbotservice/src/main/jni/Application.mk index 25058c1..a356ed7 100644 --- a/orbotservice/src/main/jni/Application.mk +++ b/orbotservice/src/main/jni/Application.mk @@ -1,5 +1,4 @@ -#APP_ABI := armeabi x86 APP_ABI := armeabi -APP_PLATFORM := android-14 +APP_PLATFORM := android-16 APP_STL := stlport_static NDK_TOOLCHAIN_VERSION := 4.8 diff --git a/orbotservice/src/main/res/values/pdnsd.xml b/orbotservice/src/main/res/values/pdnsd.xml index 522f765..a9ba34d 100644 --- a/orbotservice/src/main/res/values/pdnsd.xml +++ b/orbotservice/src/main/res/values/pdnsd.xml @@ -1,6 +1,6 @@ <?xml version="1.0" encoding="utf-8"?> <resources> - <string name="pdnsd_conf" formatted="false"> + <string name="pdnsd_conf" formatted="true"> global { perm_cache=0; cache_dir="/data/data/org.torproject.android/app_bin"; @@ -17,8 +17,8 @@ global {
server { label= "upstream"; - ip = %s; - port = %d; + ip = %1$s; + port = %2$d; uptest = none; }