commit 440290e9d7b3796d2ee72381cd865e677c8b1081 Author: n8fr8 nathan@freitas.net Date: Wed Oct 25 00:07:11 2017 -0400
show warning about removal of transproxy support - also make app selection more streamlining --- .../main/java/org/torproject/android/OrbotApp.java | 55 ++++ .../org/torproject/android/OrbotMainActivity.java | 11 +- .../java/org/torproject/android/ui/AppManager.java | 315 ++++++++++----------- app/src/main/res/layout/layout_apps.xml | 68 +---- app/src/main/res/layout/layout_apps_item.xml | 27 +- app/src/main/res/values/strings.xml | 3 + .../android/service/TorServiceConstants.java | 3 - .../org/torproject/android/service/util/Prefs.java | 4 + 8 files changed, 243 insertions(+), 243 deletions(-)
diff --git a/app/src/main/java/org/torproject/android/OrbotApp.java b/app/src/main/java/org/torproject/android/OrbotApp.java index e6fd014d..9ebcfa2b 100644 --- a/app/src/main/java/org/torproject/android/OrbotApp.java +++ b/app/src/main/java/org/torproject/android/OrbotApp.java @@ -1,21 +1,32 @@
package org.torproject.android;
+import android.annotation.SuppressLint; import android.annotation.TargetApi; import android.app.Activity; import android.app.Application; +import android.app.Notification; +import android.app.NotificationManager; +import android.app.PendingIntent; +import android.content.Context; import android.content.Intent; +import android.content.pm.PackageManager; import android.content.res.Configuration; import android.net.VpnService; import android.os.Build; +import android.support.v4.app.NotificationCompat; import android.util.Log; +import android.widget.RemoteViews;
import org.torproject.android.service.OrbotConstants; +import org.torproject.android.service.TorEventHandler; +import org.torproject.android.service.TorService; import org.torproject.android.service.util.Prefs;
import org.torproject.android.settings.Languages;
import java.util.Locale; +import java.util.Set;
public class OrbotApp extends Application implements OrbotConstants { @@ -30,6 +41,7 @@ public class OrbotApp extends Application implements OrbotConstants Languages.setup(OrbotMainActivity.class, R.string.menu_settings); Languages.setLanguage(this, Prefs.getDefaultLocale(), true);
+ checkTransparentProxyingLegacy(); }
@Override @@ -53,4 +65,47 @@ public class OrbotApp extends Application implements OrbotConstants public static Languages getLanguages(Activity activity) { return Languages.get(activity); } + + private void checkTransparentProxyingLegacy () + { + if (Prefs.useTransparentProxying()) + { + showToolbarNotification(getString(R.string.no_transproxy_warning_short),getString(R.string.no_transproxy_warning), 9999, org.torproject.android.service.R.drawable.ic_stat_notifyerr); + + } + } + + @SuppressLint("NewApi") + protected void showToolbarNotification (String shortMsg, String notifyMsg, int notifyId, int icon) + { + + NotificationCompat.Builder notifyBuilder; + + //Reusable code. + PackageManager pm = getPackageManager(); + Intent intent = pm.getLaunchIntentForPackage(getPackageName()); + PendingIntent pendIntent = PendingIntent.getActivity(this, 0, intent, 0); + + NotificationManager notificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE); + + notifyBuilder = new NotificationCompat.Builder(this) + .setContentTitle(getString(org.torproject.android.service.R.string.app_name)); + + + notifyBuilder.setContentIntent(pendIntent); + + notifyBuilder.setContentText(shortMsg); + notifyBuilder.setSmallIcon(icon); + notifyBuilder.setTicker(notifyMsg); + + notifyBuilder.setOngoing(false); + + notifyBuilder.setStyle(new NotificationCompat.BigTextStyle() + .bigText(notifyMsg).setBigContentTitle(getString(org.torproject.android.service.R.string.app_name))); + + Notification notification = notifyBuilder.build(); + + notificationManager.notify(notifyId, notification); + } + } diff --git a/app/src/main/java/org/torproject/android/OrbotMainActivity.java b/app/src/main/java/org/torproject/android/OrbotMainActivity.java index 354b4a05..b1e010a4 100644 --- a/app/src/main/java/org/torproject/android/OrbotMainActivity.java +++ b/app/src/main/java/org/torproject/android/OrbotMainActivity.java @@ -852,10 +852,6 @@ public class OrbotMainActivity extends AppCompatActivity //use the system browser since VPN is on startIntent(null,Intent.ACTION_VIEW, Uri.parse(browserLaunchUrl)); } - else if (Prefs.useTransparentProxying()) - { - startIntent(null,Intent.ACTION_VIEW, Uri.parse(browserLaunchUrl)); - } else { AlertDialog aDialog = new AlertDialog.Builder(OrbotMainActivity.this) @@ -1172,6 +1168,13 @@ public class OrbotMainActivity extends AppCompatActivity requestTorStatus();
updateStatus(null); + + if (Prefs.useTransparentProxying()) + { + showAlert(getString(R.string.no_transproxy_warning_short),getString(R.string.no_transproxy_warning),true); + Prefs.disableTransparentProxying(); + } + }
diff --git a/app/src/main/java/org/torproject/android/ui/AppManager.java b/app/src/main/java/org/torproject/android/ui/AppManager.java index 803061d3..e54898de 100644 --- a/app/src/main/java/org/torproject/android/ui/AppManager.java +++ b/app/src/main/java/org/torproject/android/ui/AppManager.java @@ -15,16 +15,20 @@ import org.torproject.android.R; import org.torproject.android.service.util.TorServiceUtils; import org.torproject.android.service.vpn.TorifiedApp;
+import android.app.Activity; import android.content.Context; import android.content.SharedPreferences; import android.content.SharedPreferences.Editor; import android.content.pm.ApplicationInfo; import android.content.pm.PackageInfo; import android.content.pm.PackageManager; +import android.content.pm.ResolveInfo; import android.os.Bundle; import android.support.v7.app.AppCompatActivity; import android.util.Log; import android.view.LayoutInflater; +import android.view.Menu; +import android.view.MenuInflater; import android.view.MenuItem; import android.view.View; import android.view.View.OnClickListener; @@ -34,6 +38,7 @@ import android.widget.Button; import android.widget.CheckBox; import android.widget.CompoundButton; import android.widget.CompoundButton.OnCheckedChangeListener; +import android.widget.GridView; import android.widget.ImageView; import android.widget.ListAdapter; import android.widget.ListView; @@ -41,112 +46,95 @@ import android.widget.TextView;
public class AppManager extends AppCompatActivity implements OnCheckedChangeListener, OnClickListener, OrbotConstants {
- private ListView listApps; + private GridView listApps; private final static String TAG = "Orbot"; - + PackageManager pMgr = null; + protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); - + + pMgr = getPackageManager(); + this.setContentView(R.layout.layout_apps); setTitle(R.string.apps_mode); getSupportActionBar().setDisplayHomeAsUpEnabled(true); - - View buttonSelectAll, buttonSelectNone, buttonInvert;
- buttonSelectAll = findViewById(R.id.button_proxy_all); - buttonSelectNone = findViewById(R.id.button_proxy_none); - buttonInvert = findViewById(R.id.button_invert_selection); - - buttonSelectAll.setOnClickListener(new OnAutoClickListener(0)); - buttonSelectNone.setOnClickListener(new OnAutoClickListener(1)); - buttonInvert.setOnClickListener(new OnAutoClickListener(2)); }
- class OnAutoClickListener implements Button.OnClickListener { - private int status; - public OnAutoClickListener(int status){ - this.status = status; - } - @SuppressWarnings("unchecked") - public void onClick(View button){ - ListView listView; - ViewGroup viewGroup; - View parentView, currentView; - ArrayAdapter<TorifiedApp> adapter; - TorifiedApp app; - CheckBox box; - float buttonId; - boolean[] isSelected; - int posI, selectedI, lvSz; - - buttonId = button.getId(); - listView = (ListView) findViewById(R.id.applistview); - lvSz = listView.getCount(); - isSelected = new boolean[lvSz]; - - selectedI = -1; - - if (this.status == 0){ - Log.d(TAG, "Proxifying ALL"); - }else if (this.status == 1){ - Log.d(TAG, "Proxifying NONE"); - }else { - Log.d(TAG, "Proxifying invert"); - } - - Context context = getApplicationContext(); - SharedPreferences prefs = TorServiceUtils.getSharedPrefs(context); - ArrayList<TorifiedApp> apps = getApps(context, prefs); - parentView = (View) findViewById(R.id.applistview); - viewGroup = (ViewGroup) listView; - - adapter = (ArrayAdapter<TorifiedApp>) listApps.getAdapter(); - if (adapter == null){ - Log.w(TAG, "List adapter is null. Getting apps."); - loadApps(prefs); - adapter = (ArrayAdapter<TorifiedApp>) listApps.getAdapter(); - } - - for (int i = 0 ; i < adapter.getCount(); ++i){ - app = (TorifiedApp) adapter.getItem(i); - currentView = adapter.getView(i, parentView, viewGroup); - box = (CheckBox) currentView.findViewById(R.id.itemcheck); - - if (this.status == 0){ - app.setTorified(true); - }else if (this.status == 1){ - app.setTorified(false); - }else { - app.setTorified(!app.isTorified()); - } - - if (box != null) - box.setChecked(app.isTorified()); - - } - saveAppSettings(context); - loadApps(prefs); - } - } - - @Override - public boolean onOptionsItemSelected(MenuItem item) { - switch (item.getItemId()) { - case android.R.id.home: - setResult(RESULT_OK); - finish(); - return true; - + /** + class OnAutoClickListener implements Button.OnClickListener { + private int status; + public OnAutoClickListener(int status){ + this.status = status; + } + @SuppressWarnings("unchecked") + public void onClick(View button){ + GridView listView; + ViewGroup viewGroup; + View parentView, currentView; + ArrayAdapter<TorifiedApp> adapter; + TorifiedApp app; + CheckBox box; + float buttonId; + boolean[] isSelected; + int posI, selectedI, lvSz; + + buttonId = button.getId(); + listView = (GridView) findViewById(R.id.applistview); + lvSz = listView.getCount(); + isSelected = new boolean[lvSz]; + + selectedI = -1; + + if (this.status == 0){ + Log.d(TAG, "Proxifying ALL"); + }else if (this.status == 1){ + Log.d(TAG, "Proxifying NONE"); + }else { + Log.d(TAG, "Proxifying invert"); + } + + Context context = getApplicationContext(); + SharedPreferences prefs = TorServiceUtils.getSharedPrefs(context); + ArrayList<TorifiedApp> apps = getApps(context, prefs); + parentView = (View) findViewById(R.id.applistview); + viewGroup = (ViewGroup) listView; + + adapter = (ArrayAdapter<TorifiedApp>) listApps.getAdapter(); + if (adapter == null){ + Log.w(TAG, "List adapter is null. Getting apps."); + loadApps(prefs); + adapter = (ArrayAdapter<TorifiedApp>) listApps.getAdapter(); + } + + for (int i = 0 ; i < adapter.getCount(); ++i){ + app = (TorifiedApp) adapter.getItem(i); + currentView = adapter.getView(i, parentView, viewGroup); + box = (CheckBox) currentView.findViewById(R.id.itemcheck); + + if (this.status == 0){ + app.setTorified(true); + }else if (this.status == 1){ + app.setTorified(false); + }else { + app.setTorified(!app.isTorified()); + } + + if (box != null) + box.setChecked(app.isTorified()); + + } + saveAppSettings(context); + loadApps(prefs); + } + }**/
- }
- return false; - }
@Override protected void onResume() { super.onResume(); - listApps = (ListView)findViewById(R.id.applistview); + listApps = (GridView)findViewById(R.id.applistview);
mPrefs = TorServiceUtils.getSharedPrefs(getApplicationContext()); loadApps(mPrefs); @@ -154,12 +142,12 @@ public class AppManager extends AppCompatActivity implements OnCheckedChangeList
SharedPreferences mPrefs = null; ArrayList<TorifiedApp> mApps = null; - + private void loadApps (SharedPreferences prefs) { - + mApps = getApps(getApplicationContext(), prefs); - + /* Arrays.sort(apps, new Comparator<TorifiedApp>() { public int compare(TorifiedApp o1, TorifiedApp o2) { @@ -168,9 +156,9 @@ public class AppManager extends AppCompatActivity implements OnCheckedChangeList return 1; } });*/ - + final LayoutInflater inflater = getLayoutInflater(); - + ListAdapter adapter = new ArrayAdapter<TorifiedApp>(this, R.layout.layout_apps_item, R.id.itemtext,mApps) {
public View getView(int position, View convertView, ViewGroup parent) { @@ -198,16 +186,23 @@ public class AppManager extends AppCompatActivity implements OnCheckedChangeList final TorifiedApp app = mApps.get(position);
if (entry.icon != null) { - if (app.getIcon() != null) - entry.icon.setImageDrawable(app.getIcon()); - else - entry.icon.setVisibility(View.GONE); + + try { + entry.icon.setImageDrawable(pMgr.getApplicationIcon(app.getPackageName())); + entry.icon.setOnClickListener(AppManager.this); + + if (entry.box != null) + entry.icon.setTag(entry.box); + } + catch (Exception e) + { + e.printStackTrace(); + } }
if (entry.text != null) { entry.text.setText(app.getName()); entry.text.setOnClickListener(AppManager.this); - entry.text.setOnClickListener(AppManager.this);
if (entry.box != null) entry.text.setTag(entry.box); @@ -219,39 +214,38 @@ public class AppManager extends AppCompatActivity implements OnCheckedChangeList entry.box.setTag(app); entry.box.setChecked(app.isTorified());
- }
return convertView; } }; - + listApps.setAdapter(adapter); - + } - + private static class ListEntry { private CheckBox box; private TextView text; private ImageView icon; } - + /* (non-Javadoc) * @see android.app.Activity#onStop() */ @Override protected void onStop() { super.onStop(); - + }
- - public static ArrayList<TorifiedApp> getApps (Context context, SharedPreferences prefs) + + public ArrayList<TorifiedApp> getApps (Context context, SharedPreferences prefs) {
String tordAppString = prefs.getString(PREFS_KEY_TORIFIED, ""); String[] tordApps; - + StringTokenizer st = new StringTokenizer(tordAppString,"|"); tordApps = new String[st.countTokens()]; int tordIdx = 0; @@ -259,32 +253,31 @@ public class AppManager extends AppCompatActivity implements OnCheckedChangeList { tordApps[tordIdx++] = st.nextToken(); } - + Arrays.sort(tordApps);
//else load the apps up - PackageManager pMgr = context.getPackageManager(); - + List<ApplicationInfo> lAppInfo = pMgr.getInstalledApplications(0); - + Iterator<ApplicationInfo> itAppInfo = lAppInfo.iterator(); - + ArrayList<TorifiedApp> apps = new ArrayList<TorifiedApp>(); - + ApplicationInfo aInfo = null; - + int appIdx = 0; TorifiedApp app = null; - + while (itAppInfo.hasNext()) { aInfo = itAppInfo.next(); - + app = new TorifiedApp(); - + try { PackageInfo pInfo = pMgr.getPackageInfo(aInfo.packageName, PackageManager.GET_PERMISSIONS); - + if (pInfo != null && pInfo.requestedPermissions != null) { for (String permInfo:pInfo.requestedPermissions) @@ -292,51 +285,51 @@ public class AppManager extends AppCompatActivity implements OnCheckedChangeList if (permInfo.equals("android.permission.INTERNET")) { app.setUsesInternet(true); - + } } - + } - - + + } catch (Exception e) { // TODO Auto-generated catch block e.printStackTrace(); } - - if ((aInfo.flags & ApplicationInfo.FLAG_SYSTEM) == 1) + + /** + if ((aInfo.flags & ApplicationInfo.FLAG_SYSTEM) == 1) + { + //System app + app.setUsesInternet(true); + }**/ + + + try + { + app.setName(pMgr.getApplicationLabel(aInfo).toString()); + } + catch (Exception e) { - //System app - app.setUsesInternet(true); - } - - + // no name + continue; //we only show apps with names + } + + if (!app.usesInternet()) continue; else { apps.add(app); } - - + app.setEnabled(aInfo.enabled); app.setUid(aInfo.uid); app.setUsername(pMgr.getNameForUid(app.getUid())); app.setProcname(aInfo.processName); app.setPackageName(aInfo.packageName); - - try - { - app.setName(pMgr.getApplicationLabel(aInfo).toString()); - } - catch (Exception e) - { - app.setName(aInfo.packageName); - } - - - //app.setIcon(pMgr.getApplicationIcon(aInfo)); - + + // check if this application is allowed if (Arrays.binarySearch(tordApps, app.getUsername()) >= 0) { app.setTorified(true); @@ -345,15 +338,15 @@ public class AppManager extends AppCompatActivity implements OnCheckedChangeList { app.setTorified(false); } - + appIdx++; } - + Collections.sort(apps); - + return apps; } - +
public void saveAppSettings (Context context) { @@ -368,13 +361,13 @@ public class AppManager extends AppCompatActivity implements OnCheckedChangeList tordApps.append("|"); } } - + Editor edit = mPrefs.edit(); edit.putString(PREFS_KEY_TORIFIED, tordApps.toString()); edit.commit(); - + } - +
/** * Called an application is check/unchecked @@ -384,29 +377,29 @@ public class AppManager extends AppCompatActivity implements OnCheckedChangeList if (app != null) { app.setTorified(isChecked); } - + saveAppSettings(this);
}
- +
public void onClick(View v) { - + CheckBox cbox = (CheckBox)v.getTag(); - + final TorifiedApp app = (TorifiedApp)cbox.getTag(); if (app != null) { app.setTorified(!app.isTorified()); cbox.setChecked(app.isTorified()); } - + saveAppSettings(this); - + }
- + } diff --git a/app/src/main/res/layout/layout_apps.xml b/app/src/main/res/layout/layout_apps.xml index 33e07485..b036503f 100644 --- a/app/src/main/res/layout/layout_apps.xml +++ b/app/src/main/res/layout/layout_apps.xml @@ -1,69 +1,17 @@ <?xml version="1.0" encoding="utf-8"?> <RelativeLayout - android:layout_width="match_parent" - android:layout_height="match_parent" - xmlns:android="http://schemas.android.com/apk/res/android" - android:duplicateParentState="true"> - - <!-- - <TextView android:text="Select apps to use with Tor:" - android:layout_width="fill_parent" - android:layout_height="wrap_content" - android:textSize="16sp" - android:padding="3px" - android:layout_above="@+id/applistview" - /> - --> + android:layout_width="match_parent" + android:layout_height="match_parent" + xmlns:android="http://schemas.android.com/apk/res/android" + android:duplicateParentState="true">
- <ListView + <GridView android:id="@+id/applistview" android:layout_width="match_parent" android:layout_height="match_parent" - android:layout_above="@+id/layout_button_filters" + android:numColumns="3" android:layout_alignParentTop="true" >
- </ListView> - - <LinearLayout - android:id="@+id/layout_button_filters" - android:layout_width="match_parent" - android:layout_height="wrap_content" - android:layout_alignParentBottom="true" - android:orientation="horizontal" > - - <android.support.v7.widget.AppCompatImageButton - android:id="@+id/button_proxy_all" - android:layout_width="wrap_content" - android:layout_height="wrap_content" - android:layout_alignParentLeft="true" - android:layout_alignParentStart="true" - android:layout_toLeftOf="@+id/button_proxy_none" - android:layout_toStartOf="@+id/button_proxy_none" - - android:layout_weight="1" - android:src="@drawable/ic_playlist_add_check_black_36dp"/> - - <android.support.v7.widget.AppCompatImageButton - android:id="@+id/button_invert_selection" - android:layout_width="wrap_content" - android:layout_height="wrap_content" - android:layout_alignParentRight="true" - android:layout_alignParentEnd="true" - android:layout_alignParentTop="true" - - android:layout_weight="1" - android:src="@drawable/ic_autorenew_black_36dp"/> - - <android.support.v7.widget.AppCompatImageButton - android:id="@+id/button_proxy_none" - android:layout_width="wrap_content" - android:layout_height="wrap_content" - android:layout_alignParentTop="true" - android:layout_weight="1" - android:layout_toLeftOf="@+id/button_invert_selection" - android:layout_toStartOf="@+id/button_invert_selection" - android:src='@drawable/ic_filter_none_black_36dp' /> - - </LinearLayout> + </GridView>
-</RelativeLayout> +</RelativeLayout> \ No newline at end of file diff --git a/app/src/main/res/layout/layout_apps_item.xml b/app/src/main/res/layout/layout_apps_item.xml index e1240139..83549121 100644 --- a/app/src/main/res/layout/layout_apps_item.xml +++ b/app/src/main/res/layout/layout_apps_item.xml @@ -1,18 +1,15 @@ <?xml version="1.0" encoding="utf-8"?>
-<TableLayout xmlns:android="http://schemas.android.com/apk/res/android" - android:layout_width="match_parent" - android:layout_height="40dp" - android:stretchColumns="1"> - <TableRow> - - <ImageView android:id="@+id/itemicon" android:layout_width="50dp" android:layout_height="50dp" android:padding="3dp" android:visibility="gone"></ImageView> - -<TextView android:layout_height="wrap_content" android:layout_width="150dp" android:id="@+id/itemtext" android:text="uid:packages" android:textSize="18sp" android:padding="3dip"></TextView> - -<CheckBox android:layout_width="wrap_content" android:layout_height="wrap_content" android:id="@+id/itemcheck" ></CheckBox> - - </TableRow> - -</TableLayout> +<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" + android:layout_width="120dp" + android:layout_height="120dp" + android:orientation="vertical" + android:gravity="center_horizontal" + > + <ImageView android:id="@+id/itemicon" android:layout_width="50dp" android:layout_height="50dp" android:padding="3dp" ></ImageView> + <TextView android:layout_height="20dp" android:layout_width="120dp" android:lines="1" android:id="@+id/itemtext" + android:text="uid:packages" android:textSize="12sp" android:gravity="center_horizontal" android:padding="3dip"></TextView> + <CheckBox android:layout_width="wrap_content" android:layout_height="wrap_content" android:id="@+id/itemcheck" ></CheckBox> + +</LinearLayout>
diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index c23e5507..d4636eda 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -380,4 +380,7 @@ <string name="enable">Enable</string> <string name="consider_disable_battery_optimizations">Consider disable battery optimizations</string> <string name="consider_enable_battery_optimizations">Consider enable battery optimizations</string> + + <string name="no_transproxy_warning_short">WARNING: Transproxying no longer supported</string> + <string name="no_transproxy_warning">WARNING: Transparent proxying not supported. Use Orbot Apps VPN instead.</string> </resources> 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 32bd9045..a757159d 100644 --- a/orbotservice/src/main/java/org/torproject/android/service/TorServiceConstants.java +++ b/orbotservice/src/main/java/org/torproject/android/service/TorServiceConstants.java @@ -142,9 +142,6 @@ public interface TorServiceConstants { public static final String OBFSCLIENT_ASSET_KEY = "obfs4proxy";
// public static final String MEEK_ASSET_KEY = "meek-client"; - - //name of the iptables binary - public final static String IPTABLES_ASSET_KEY = "xtables";
//DNS daemon for TCP DNS over TOr public final static String PDNSD_ASSET_KEY = "pdnsd"; diff --git a/orbotservice/src/main/java/org/torproject/android/service/util/Prefs.java b/orbotservice/src/main/java/org/torproject/android/service/util/Prefs.java index cf3489e6..9ceec989 100644 --- a/orbotservice/src/main/java/org/torproject/android/service/util/Prefs.java +++ b/orbotservice/src/main/java/org/torproject/android/service/util/Prefs.java @@ -76,6 +76,10 @@ public class Prefs { return prefs.getBoolean(PREF_TRANSPARENT, false); }
+ public static void disableTransparentProxying() { + prefs.getBoolean(PREF_TRANSPARENT, false); + } + public static boolean transparentProxyAll() { return prefs.getBoolean(PREF_TRANSPARENT_ALL, false); }
tor-commits@lists.torproject.org