From 6af2989ab82bff30ad45f14a40dfe15a4f787ddc Mon Sep 17 00:00:00 2001 From: Sathyanarayanan Gunasekaran Date: Sat, 4 Jun 2011 02:12:06 +0530 Subject: [PATCH] Permissions screen added --- AUTHORS | 2 +- AndroidManifest.xml | 1 + res/layout/layout_wizard_permissions.xml | 67 ++++++++ res/values/strings.xml | 3 + src/org/torproject/android/LotsaText.java | 17 +- src/org/torproject/android/Permissions.java | 176 ++++++++++++++++++++ 6 files changed, 256 insertions(+), 10 deletions(-) create mode 100644 res/layout/layout_wizard_permissions.xml create mode 100644 src/org/torproject/android/Permissions.java diff --git a/AUTHORS b/AUTHORS index f99ac6f9..135d9b46 100644 --- a/AUTHORS +++ b/AUTHORS @@ -27,7 +27,7 @@ provided guidance in the entire effort. Adam Langley made the original valiant effort to port Tor to Android. -Sathyanarayanan created a patch for the wizard +Sathyanarayanan created a patch for the wizard which updated the icon and link for the secure chat app info to point to Gibberbot, and hopefully will continue to contribute useful patches. diff --git a/AndroidManifest.xml b/AndroidManifest.xml index 59c2cca7..be3c43f5 100644 --- a/AndroidManifest.xml +++ b/AndroidManifest.xml @@ -30,6 +30,7 @@ + diff --git a/res/layout/layout_wizard_permissions.xml b/res/layout/layout_wizard_permissions.xml new file mode 100644 index 00000000..b861d7a4 --- /dev/null +++ b/res/layout/layout_wizard_permissions.xml @@ -0,0 +1,67 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/res/values/strings.xml b/res/values/strings.xml index 2212f494..f4ca03c4 100644 --- a/res/values/strings.xml +++ b/res/values/strings.xml @@ -137,6 +137,9 @@ Simply installing Orbot will not automatically anonymize your mobile traffic.\nPlease follow the following steps to get started Permissions + Orbot has detected that you have root permissions enabled. To enable \'Transparent Proxying\', please grant superuser privileges to Orbot + If you choose to continue without providing superuser privileges, make sure to use apps made to work with orbot + Orbot has detected that you do not have root permissions.\nTransparent Proxying is not possible without superuser privileges.\nMake sure to use apps that have been configured to work with Orbot diff --git a/src/org/torproject/android/LotsaText.java b/src/org/torproject/android/LotsaText.java index d044c576..e9fc556b 100644 --- a/src/org/torproject/android/LotsaText.java +++ b/src/org/torproject/android/LotsaText.java @@ -2,6 +2,7 @@ package org.torproject.android; import android.app.Activity; import android.content.Context; +import android.content.Intent; import android.os.Bundle; import android.view.View; import android.widget.Button; @@ -24,13 +25,10 @@ public class LotsaText extends Activity implements TorConstants{ protected void onStart() { super.onStart(); + setContentView(R.layout.scrollingtext_buttons_view); - - if (step == -1) - { - setContentView(R.layout.scrollingtext_buttons_view); - stepOne(); - } + stepOne(); + } @Override @@ -52,7 +50,6 @@ public class LotsaText extends Activity implements TorConstants{ */ private void stepOne() { - step++; //setContentView(R.layout.scrollingtext_buttons_view); String title = context.getString(R.string.wizard_title); @@ -82,7 +79,7 @@ public class LotsaText extends Activity implements TorConstants{ } private void stepTwo() { - step++; + step=0; setContentView(R.layout.scrollingtext_buttons_view); String title = context.getString(R.string.wizard_warning_title); @@ -114,9 +111,11 @@ public class LotsaText extends Activity implements TorConstants{ @Override public void onClick(View v) { - //stepThree(); + startActivityForResult(new Intent(getBaseContext(), Permissions.class), 1); } }); } + + } \ No newline at end of file diff --git a/src/org/torproject/android/Permissions.java b/src/org/torproject/android/Permissions.java new file mode 100644 index 00000000..bd96e56b --- /dev/null +++ b/src/org/torproject/android/Permissions.java @@ -0,0 +1,176 @@ +package org.torproject.android; + +import org.torproject.android.service.TorService; +import org.torproject.android.service.TorServiceUtils; +import org.torproject.android.service.TorTransProxy; + +import android.app.Activity; +import android.content.Context; +import android.content.Intent; +import android.content.SharedPreferences; +import android.content.SharedPreferences.Editor; +import android.os.Bundle; +import android.preference.PreferenceManager; +import android.util.Log; +import android.view.View; +import android.widget.Button; +import android.widget.TextView; +import android.widget.Toast; + +public class Permissions extends Activity implements TorConstants { + + private Context context; + + protected void onCreate(Bundle savedInstanceState) + { + super.onCreate(savedInstanceState); + context = this; + + } + + @Override + protected void onStart() { + + super.onStart(); + setContentView(R.layout.layout_wizard_permissions); + + stepThree(); + + } + + @Override + protected void onResume() { + super.onResume(); + + + } + + private void stepThree(){ + + boolean hasRoot = TorServiceUtils.checkRootAccess(); + + if (hasRoot) + { + try { + int resp = TorTransProxy.testOwnerModule(context); + + if (resp < 0) + { + hasRoot = false; + Toast.makeText(context, "ERROR: IPTables OWNER module not available", Toast.LENGTH_LONG).show(); + + Log.i(TorService.TAG,"ERROR: IPTables OWNER module not available"); + } + + } catch (Exception e) { + + hasRoot = false; + Log.d(TorService.TAG,"ERROR: IPTables OWNER module not available",e); + } + } + + SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context); + + Editor pEdit = prefs.edit(); + pEdit.putBoolean("has_root",hasRoot); + pEdit.commit(); + + if (hasRoot) + { + Toast.makeText(context, "Has Root", Toast.LENGTH_SHORT).show(); + stepFourRoot(); + } + else + { + Toast.makeText(context, "Unable to get root access", Toast.LENGTH_LONG).show(); + stepFour(); + } + + } + + private void stepFourRoot(){ + + String title = context.getString(R.string.wizard_permissions_title); + String msg1 = context.getString(R.string.wizard_permissions_root_msg1); + String msg2 = context.getString(R.string.wizard_permissions_root_msg2); + + TextView txtTitle = ((TextView)findViewById(R.id.WizardTextTitle)); + txtTitle.setText(title); + + TextView txtBody1 = ((TextView)findViewById(R.id.WizardTextBody1)); + txtBody1.setText(msg1); + + + TextView txtBody2 = ((TextView)findViewById(R.id.WizardTextBody2)); + txtBody2.setText(msg2); + txtBody2.setVisibility(TextView.VISIBLE); + + Button grantPermissions = ((Button)findViewById(R.id.grantPermissions)); + grantPermissions.setVisibility(Button.VISIBLE); + + Button back = ((Button)findViewById(R.id.btnWizard1)); + Button next = ((Button)findViewById(R.id.btnWizard2)); + + grantPermissions.setOnClickListener(new View.OnClickListener() { + + @Override + public void onClick(View v) { + //Check and Install iptables + + } + }); + + back.setOnClickListener(new View.OnClickListener() { + + @Override + public void onClick(View v) { + + startActivityForResult(new Intent(getBaseContext(), LotsaText.class), 1); + } + }); + + next.setOnClickListener(new View.OnClickListener() { + + @Override + public void onClick(View v) { + //Tips Screen + } + }); + + } + + private void stepFour(){ + + + String title = context.getString(R.string.wizard_permissions_title); + String msg = context.getString(R.string.wizard_permissions_msg); + + TextView txtTitle = ((TextView)findViewById(R.id.WizardTextTitle)); + txtTitle.setText(title); + + TextView txtBody = ((TextView)findViewById(R.id.WizardTextBody)); + txtBody.setText(msg); + + Button btn1 = ((Button)findViewById(R.id.btnWizard1)); + Button btn2 = ((Button)findViewById(R.id.btnWizard2)); + + btn1.setOnClickListener(new View.OnClickListener() { + + @Override + public void onClick(View v) { + + startActivityForResult(new Intent(getBaseContext(), LotsaText.class), 1); + } + }); + + btn2.setOnClickListener(new View.OnClickListener() { + + @Override + public void onClick(View v) { + //Tips Screen + } + }); + } + + +} \ No newline at end of file