Skip to content

Commit

Permalink
bugfix
Browse files Browse the repository at this point in the history
  • Loading branch information
isayan committed Apr 12, 2020
1 parent 9e6e010 commit d68818a
Show file tree
Hide file tree
Showing 9 changed files with 52 additions and 47 deletions.
6 changes: 3 additions & 3 deletions Readme-ja.md
Original file line number Diff line number Diff line change
Expand Up @@ -65,10 +65,10 @@ Disallowed Application と Allowed Application の2つのモードがありま
* order by desc
* 降順にソートします

* filter by asc
* filter by app name
* アプリケーション名に指定したキーワードを含むものを検索します。

* filter by desc
* filter by package name
* パッケージ名に指定したキーワードを含むものを検索します。

* sort by app name
Expand Down Expand Up @@ -113,7 +113,7 @@ SSLを復号化するには、ローカルプロキシツールのRoot証明書
* Android 5.0 (API Level 21) 以降

### ビルド
gradlew build
gradlew build

## 謝辞

Expand Down
7 changes: 5 additions & 2 deletions Readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -63,10 +63,10 @@ The application list can be sorted from the menu icon (![Menu](images/Menu.png)
* order by desc
* Sorting in descending order

* filter by asc
* filter by app name
* Search for the application name that contains the keyword you specified.

* filter by desc
* filter by package name
* Search for the package name that contains the keyword you specified.

* sort by app name
Expand Down Expand Up @@ -108,6 +108,9 @@ Display application version

* Android 5.0 (API Level 21) or later

### ビルド
gradlew build

## base application

Most of the code was created based on the following applications for creating applications.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,15 @@
import androidx.test.platform.app.InstrumentationRegistry;
import androidx.test.ext.junit.runners.AndroidJUnit4;

import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;

import java.util.List;

import tun.utils.Util;

import static org.junit.Assert.*;

/**
Expand All @@ -16,12 +22,29 @@
* @see <a href="http://d.android.com/tools/testing">Testing documentation</a>
*/
@RunWith(AndroidJUnit4.class)
public class ExampleInstrumentedTest {
public class AppInstrumentedTest {

@Before
public void setUp() {
System.loadLibrary("tun2http");
}

@After
public void tearDown() {

}

@Test
public void useAppContext() {
// Context of the app under test.
Context appContext = InstrumentationRegistry.getInstrumentation().getTargetContext();

assertEquals("tun.proxy", appContext.getPackageName());

List<String> dnsList = Util.getDefaultDNS(appContext);
System.out.println("dnsList:" + dnsList.size());
for (String dns: dnsList) {
System.out.println("dns:" + dns);
}

}
}
21 changes: 10 additions & 11 deletions android_app/app/src/main/java/tun/proxy/MainActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,6 @@ public class MainActivity extends AppCompatActivity implements
Button start;
Button stop;
EditText hostEditText;
MenuItem menuSetting;
Handler statusHandler = new Handler();

private Tun2HttpVpnService service;
Expand Down Expand Up @@ -83,9 +82,9 @@ public boolean onPreferenceStartFragment(PreferenceFragmentCompat caller, Prefer
fragment.setArguments(args);
fragment.setTargetFragment(caller, 0);
getSupportFragmentManager().beginTransaction()
.replace(R.id.activity_settings, fragment)
.addToBackStack(null)
.commit();
.replace(R.id.activity_settings, fragment)
.addToBackStack(null)
.commit();
setTitle(pref.getTitle());
return true;
}
Expand Down Expand Up @@ -116,9 +115,9 @@ public boolean onOptionsItemSelected(MenuItem item) {
break;
case R.id.action_show_about:
new AlertDialog.Builder(this)
.setTitle(getString(R.string.app_name) + getVersionName())
.setMessage(R.string.app_name)
.show();
.setTitle(getString(R.string.app_name) + getVersionName())
.setMessage(R.string.app_name)
.show();
break;
default:
return super.onOptionsItemSelected(item);
Expand Down Expand Up @@ -170,8 +169,8 @@ boolean isRunning() {
Runnable statusRunnable = new Runnable() {
@Override
public void run() {
updateStatus();
statusHandler.post(statusRunnable);
updateStatus();
statusHandler.post(statusRunnable);
}
};

Expand Down Expand Up @@ -226,8 +225,8 @@ protected void onActivityResult(int requestCode, int resultCode, Intent data) {
}

private void loadHostPort() {
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this);
String proxyHost = prefs.getString(Tun2HttpVpnService.PREF_PROXY_HOST, "");
final SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this);
final String proxyHost = prefs.getString(Tun2HttpVpnService.PREF_PROXY_HOST, "");
int proxyPort = prefs.getInt(Tun2HttpVpnService.PREF_PROXY_PORT, 0);

if (TextUtils.isEmpty(proxyHost)) {
Expand Down
6 changes: 3 additions & 3 deletions android_app/app/src/main/java/tun/proxy/MyApplication.java
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,8 @@ public enum AppOrderBy {ASC, DESC};
public enum AppFiltertBy {APPNAME, PKGNAME};

public VPNMode loadVPNMode() {
SharedPreferences sharedPreferences = PreferenceManager.getDefaultSharedPreferences(getApplicationContext());
String vpn_mode = sharedPreferences.getString(PREF_VPN_MODE, MyApplication.VPNMode.DISALLOW.name());
final SharedPreferences sharedPreferences = PreferenceManager.getDefaultSharedPreferences(getApplicationContext());
final String vpn_mode = sharedPreferences.getString(PREF_VPN_MODE, MyApplication.VPNMode.DISALLOW.name());
return VPNMode.valueOf(vpn_mode);
}

Expand All @@ -43,7 +43,7 @@ public void storeVPNMode(VPNMode mode) {

public Set<String> loadVPNApplication(VPNMode mode) {
final SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(getApplicationContext());
Set<String> preference = prefs.getStringSet(PREF_APP_KEY[mode.ordinal()], new HashSet<String>());
final Set<String> preference = prefs.getStringSet(PREF_APP_KEY[mode.ordinal()], new HashSet<String>());
return preference;
}

Expand Down
4 changes: 2 additions & 2 deletions android_app/app/src/main/java/tun/proxy/SettingsActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -430,7 +430,7 @@ private void setSelectedPackageSet(Set<String> selected) {
}

private void clearAllSelectedPackageSet() {
Set<String> selected = this.getFilterSelectedPackageSet();
final Set<String> selected = this.getFilterSelectedPackageSet();
for (Map.Entry<String, Boolean> value : this.mAllPackageInfoMap
.entrySet()) {
if (value.getValue()) {
Expand All @@ -440,7 +440,7 @@ private void clearAllSelectedPackageSet() {
}

private Set<String> getAllSelectedPackageSet() {
Set<String> selected = this.getFilterSelectedPackageSet();
final Set<String> selected = this.getFilterSelectedPackageSet();
for (Map.Entry<String, Boolean> value : this.mAllPackageInfoMap.entrySet()) {
if (value.getValue()) {
selected.add(value.getKey());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import android.net.VpnService;
import androidx.preference.PreferenceManager;
import android.util.Log;
import tun.proxy.R;

import tun.proxy.service.Tun2HttpVpnService;

Expand All @@ -18,15 +19,15 @@ public void onReceive(final Context context, Intent intent) {
return;
}

SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context);
final SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context);
boolean isRunning = prefs.getBoolean(Tun2HttpVpnService.PREF_RUNNING, false);
if (isRunning) {
Intent prepare = VpnService.prepare(context);
if (prepare == null) {
Log.d("Tun2Http.Boot", "Starting vpn");
Log.d(context.getString(R.string.app_name) + ".Boot", "Starting vpn");
Tun2HttpVpnService.start(context);
} else {
Log.d("Tun2Http.Boot", "Not prepared");
Log.d(context.getString(R.string.app_name) + ".Boot", "Not prepared");
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,6 @@
import android.content.Intent;
import android.content.SharedPreferences;
import android.content.pm.PackageManager;
import android.net.ConnectivityManager;
import android.net.Network;
import android.net.NetworkCapabilities;
import android.net.VpnService;
import android.os.Binder;
import android.os.Build;
Expand All @@ -20,7 +17,6 @@
import android.util.Log;

import java.io.IOException;
import java.net.Inet4Address;
import java.net.InetAddress;
import java.util.ArrayList;
import java.util.Arrays;
Expand Down
17 changes: 0 additions & 17 deletions android_app/app/src/test/java/tun/proxy/ExampleUnitTest.java

This file was deleted.

0 comments on commit d68818a

Please sign in to comment.