Commit 440290e9 authored by n8fr8's avatar n8fr8
Browse files

show warning about removal of transproxy support

- also make app selection more streamlining
parent 9140ba6a
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);
}
}
......@@ -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();
}
}
......
......@@ -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();