Skip to content

Commit 9e6e010

Browse files
author
isayan
committed
support filter by
1 parent 573dbab commit 9e6e010

File tree

7 files changed

+135
-49
lines changed

7 files changed

+135
-49
lines changed

Readme-ja.md

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -55,22 +55,28 @@ Disallowed Application と Allowed Application の2つのモードがありま
5555
![Menu Settings](images/Menu-Settings-Search.png) / ![Menu Settings](images/Menu-Settings-SortBy.png)
5656

5757
画面上部の検索アイコン(![Menu](images/Search.png))から、アプリケーションを絞り込めます。
58-
アプリケーション名に指定したキーワードを含む、アプリケーションのみが表示されます
58+
アプリケーション名または、パッケージ名に指定したキーワードを含むアプリケーションのみが表示されます
5959

6060
プリケーションリストは、画面上部のメニューアイコン(![Menu](images/Menu.png))からソートできます。
6161

62-
* sort by app name
63-
* アプリケーション名でアプリケーションリストを並べ替えます。
64-
65-
* sort by package name
66-
* パッケージ名でアプリケーションリストを並べ替えます。
67-
6862
* order by asc
6963
* 昇順にソートします
7064

7165
* order by desc
7266
* 降順にソートします
7367

68+
* filter by asc
69+
* アプリケーション名に指定したキーワードを含むものを検索します。
70+
71+
* filter by desc
72+
* パッケージ名に指定したキーワードを含むものを検索します。
73+
74+
* sort by app name
75+
* アプリケーション名でアプリケーションリストを並べ替えます。
76+
77+
* sort by package name
78+
* パッケージ名でアプリケーションリストを並べ替えます。
79+
7480
### MITM (SSL 復号化)
7581

7682
TunProxyはSSL復号化を実行しません。TunProxyは透過プロキシのように機能します。
@@ -106,6 +112,9 @@ SSLを復号化するには、ローカルプロキシツールのRoot証明書
106112

107113
* Android 5.0 (API Level 21) 以降
108114

115+
### ビルド
116+
gradlew build
117+
109118
## 謝辞
110119

111120
アプリ作成にあたりコードの大部分は以下のアプリをベースとして作成しました。

Readme.md

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -53,22 +53,28 @@ The default is **Disallowed Application** selected.
5353
![Menu Settings](images/Menu-Settings-Search.png) / ![Menu Settings](images/Menu-Settings-SortBy.png)
5454

5555
You can narrow down the applications from the search icon.(![Menu](images/Search.png))
56-
Only applications that contain the keyword specified in the application name are displayed.
56+
Only applications that contain the keyword specified in the application name or package name will be displayed.
5757

5858
The application list can be sorted from the menu icon (![Menu](images/Menu.png)) at the top of the screen.
5959

60-
* sort by app name
61-
* Sort application list by application name
62-
63-
* sort by package name
64-
* Sort application list by package name
65-
6660
* order by asc
6761
* Sorting in ascending order
6862

6963
* order by desc
7064
* Sorting in descending order
7165

66+
* filter by asc
67+
* Search for the application name that contains the keyword you specified.
68+
69+
* filter by desc
70+
* Search for the package name that contains the keyword you specified.
71+
72+
* sort by app name
73+
* Sort application list by application name
74+
75+
* sort by package name
76+
* Sort application list by package name
77+
7278
### MITM (SSL decrypt)
7379

7480
TunProxy does not perform SSL decryption. TunProxy acts like a transparent proxy.

android_app/app/build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ android {
88
applicationId "tun.proxy"
99
minSdkVersion 21
1010
targetSdkVersion 29
11-
versionCode 100240
11+
versionCode 100250
1212
versionName VERSION_NAME
1313
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
1414
externalNativeBuild {

android_app/app/src/main/java/tun/proxy/SettingsActivity.java

Lines changed: 73 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -185,14 +185,16 @@ public AllowedPackageListFragment() {
185185
protected static class PackageListFragment extends PreferenceFragmentCompat
186186
implements SearchView.OnQueryTextListener, SearchView.OnCloseListener {
187187
private final Map<String, Boolean> mAllPackageInfoMap = new HashMap<>();
188-
private final static String PREF_VPN_APPLICATION_SORTBY = "pref_vpn_application_app_sortby";
189188
private final static String PREF_VPN_APPLICATION_ORDERBY = "pref_vpn_application_app_orderby";
189+
private final static String PREF_VPN_APPLICATION_FILTERBY = "pref_vpn_application_app_filterby";
190+
private final static String PREF_VPN_APPLICATION_SORTBY = "pref_vpn_application_app_sortby";
190191

191-
private final AsyncTaskProgress task;
192+
private AsyncTaskProgress task;
192193

193194
private MyApplication.VPNMode mode;
194195
private MyApplication.AppSortBy appSortBy = MyApplication.AppSortBy.APPNAME;
195196
private MyApplication.AppOrderBy appOrderBy = MyApplication.AppOrderBy.ASC;
197+
private MyApplication.AppSortBy appFilterBy = MyApplication.AppSortBy.APPNAME;
196198
private PreferenceScreen mFilterPreferenceScreen;
197199

198200
public PackageListFragment(MyApplication.VPNMode mode) {
@@ -221,56 +223,73 @@ public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
221223
this.searchView.setOnCloseListener(this);
222224
this.searchView.setSubmitButtonEnabled(false);
223225

224-
switch (this.appSortBy) {
226+
switch (this.appOrderBy) {
227+
case ASC: {
228+
final MenuItem menuItem = menu.findItem(R.id.menu_sort_order_asc);
229+
menuItem.setChecked(true);
230+
break;
231+
}
232+
case DESC: {
233+
final MenuItem menuItem = menu.findItem(R.id.menu_sort_order_desc);
234+
menuItem.setChecked(true);
235+
break;
236+
}
237+
}
238+
239+
switch (this.appFilterBy) {
225240
case APPNAME: {
226-
final MenuItem menuItem = menu.findItem(R.id.menu_sort_app_name);
241+
final MenuItem menuItem = menu.findItem(R.id.menu_filter_app_name);
227242
menuItem.setChecked(true);
228243
break;
229244
}
230245
case PKGNAME: {
231-
final MenuItem menuItem = menu.findItem(R.id.menu_sort_pkg_name);
246+
final MenuItem menuItem = menu.findItem(R.id.menu_filter_pkg_name);
232247
menuItem.setChecked(true);
233248
break;
234249
}
235250
}
236251

237-
switch (this.appOrderBy) {
238-
case ASC: {
239-
final MenuItem menuItem = menu.findItem(R.id.menu_sort_order_asc);
252+
switch (this.appSortBy) {
253+
case APPNAME: {
254+
final MenuItem menuItem = menu.findItem(R.id.menu_sort_app_name);
240255
menuItem.setChecked(true);
241256
break;
242257
}
243-
case DESC: {
244-
final MenuItem menuItem = menu.findItem(R.id.menu_sort_order_desc);
258+
case PKGNAME: {
259+
final MenuItem menuItem = menu.findItem(R.id.menu_sort_pkg_name);
245260
menuItem.setChecked(true);
246261
break;
247262
}
248263
}
249-
250264
}
251265

252266
private String searchFilter = "";
253267
private SearchView searchView;
254268

255269
protected void filter(String filter) {
256-
this.filter(filter, this.appSortBy, this.appOrderBy);
270+
this.filter(filter, this.appFilterBy, this.appOrderBy, this.appSortBy);
257271
}
258272

259-
protected void filter(String filter, final MyApplication.AppSortBy sortBy, final MyApplication.AppOrderBy orderBy) {
273+
protected void filter(String filter, final MyApplication.AppSortBy filterBy, final MyApplication.AppOrderBy orderBy, final MyApplication.AppSortBy sortBy) {
260274
if (filter == null) {
261275
filter = searchFilter;
262276
} else {
263277
searchFilter = filter;
264278
}
265-
this.appSortBy = sortBy;
279+
this.appFilterBy = filterBy;
266280
this.appOrderBy = orderBy;
281+
this.appSortBy = sortBy;
267282

268283
Set<String> selected = this.getAllSelectedPackageSet();
269284
storeSelectedPackageSet(selected);
270285

271286
this.removeAllPreferenceScreen();
272-
//final AsyncTaskProgress task = new AsyncTaskProgress(this);
273-
if (task.getStatus() == AsyncTask.Status.PENDING) {
287+
288+
if (task != null && task.getStatus() == AsyncTask.Status.PENDING) {
289+
task.execute();
290+
}
291+
else {
292+
task = new AsyncTaskProgress(this);
274293
task.execute();
275294
}
276295
// this.filterPackagesPreferences(filter, sortBy, orderBy);
@@ -281,16 +300,17 @@ public void onPause() {
281300
super.onPause();
282301
if (this.task != null) {
283302
this.task.cancel(true);
303+
this.task = null;
284304
}
285305

286306
Set<String> selected = this.getAllSelectedPackageSet();
287307
storeSelectedPackageSet(selected);
288308
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(MyApplication.getInstance().getApplicationContext());
289309
SharedPreferences.Editor edit = prefs.edit();
290-
edit.putString(PREF_VPN_APPLICATION_SORTBY, this.appSortBy.name());
291310
edit.putString(PREF_VPN_APPLICATION_ORDERBY, this.appOrderBy.name());
311+
edit.putString(PREF_VPN_APPLICATION_FILTERBY, this.appFilterBy.name());
312+
edit.putString(PREF_VPN_APPLICATION_SORTBY, this.appSortBy.name());
292313
edit.apply();
293-
Log.i("onPause", this.appSortBy.name());
294314
}
295315

296316
@Override
@@ -301,11 +321,12 @@ public void onResume() {
301321
this.mAllPackageInfoMap.put(pkgName, loadMap.contains(pkgName));
302322
}
303323
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(MyApplication.getInstance().getApplicationContext());
304-
String appSortBy = prefs.getString(PREF_VPN_APPLICATION_SORTBY, MyApplication.AppSortBy.APPNAME.name());
305324
String appOrderBy = prefs.getString(PREF_VPN_APPLICATION_ORDERBY, MyApplication.AppOrderBy.ASC.name());
306-
this.appSortBy = Enum.valueOf(MyApplication.AppSortBy.class, appSortBy);
325+
String appFilterBy = prefs.getString(PREF_VPN_APPLICATION_FILTERBY, MyApplication.AppSortBy.APPNAME.name());
326+
String appSortBy = prefs.getString(PREF_VPN_APPLICATION_SORTBY, MyApplication.AppSortBy.APPNAME.name());
307327
this.appOrderBy = Enum.valueOf(MyApplication.AppOrderBy.class, appOrderBy);
308-
Log.i("onResume", this.appSortBy.name());
328+
this.appFilterBy = Enum.valueOf(MyApplication.AppSortBy.class, appFilterBy);
329+
this.appSortBy = Enum.valueOf(MyApplication.AppSortBy.class, appSortBy);
309330
filter(null);
310331
}
311332

@@ -440,21 +461,31 @@ public boolean onOptionsItemSelected(MenuItem item) {
440461
case android.R.id.home:
441462
startActivity(new Intent(getActivity(), SettingsActivity.class));
442463
return true;
443-
case R.id.menu_sort_app_name:
464+
case R.id.menu_sort_order_asc:
444465
item.setChecked(!item.isChecked());
445-
filter(null, MyApplication.AppSortBy.APPNAME, appOrderBy);
466+
filter(null, appFilterBy, MyApplication.AppOrderBy.ASC, appSortBy);
446467
break;
447-
case R.id.menu_sort_pkg_name:
468+
case R.id.menu_sort_order_desc:
448469
item.setChecked(!item.isChecked());
449-
filter(null, MyApplication.AppSortBy.PKGNAME, appOrderBy);
470+
filter(null, appFilterBy, MyApplication.AppOrderBy.DESC, appSortBy);
450471
break;
451-
case R.id.menu_sort_order_asc:
472+
case R.id.menu_filter_app_name:
452473
item.setChecked(!item.isChecked());
453-
filter(null, appSortBy, MyApplication.AppOrderBy.ASC);
474+
this.appFilterBy = MyApplication.AppSortBy.APPNAME;
475+
//filter(null, MyApplication.AppSortBy.APPNAME, appOrderBy, appSortBy);
454476
break;
455-
case R.id.menu_sort_order_desc:
477+
case R.id.menu_filter_pkg_name:
456478
item.setChecked(!item.isChecked());
457-
filter(null, appSortBy, MyApplication.AppOrderBy.DESC);
479+
this.appFilterBy = MyApplication.AppSortBy.PKGNAME;
480+
//filter(null, MyApplication.AppSortBy.PKGNAME, appOrderBy, appSortBy);
481+
break;
482+
case R.id.menu_sort_app_name:
483+
item.setChecked(!item.isChecked());
484+
filter(null, appFilterBy, appOrderBy, MyApplication.AppSortBy.APPNAME);
485+
break;
486+
case R.id.menu_sort_pkg_name:
487+
item.setChecked(!item.isChecked());
488+
filter(null, appFilterBy, appOrderBy, MyApplication.AppSortBy.PKGNAME);
458489
break;
459490
}
460491
return super.onOptionsItemSelected(item);
@@ -506,10 +537,10 @@ protected void onPreExecute() {
506537

507538
@Override
508539
protected List<PackageInfo> doInBackground(String... params) {
509-
return filterPackages(packageFragment.searchFilter, packageFragment.appSortBy, packageFragment.appOrderBy);
540+
return filterPackages(packageFragment.searchFilter, packageFragment.appFilterBy, packageFragment.appOrderBy, packageFragment.appSortBy);
510541
}
511542

512-
private List<PackageInfo> filterPackages(String filter, final MyApplication.AppSortBy sortBy, final MyApplication.AppOrderBy orderBy) {
543+
private List<PackageInfo> filterPackages(String filter, final MyApplication.AppSortBy filterBy, final MyApplication.AppOrderBy orderBy, final MyApplication.AppSortBy sortBy) {
513544
final Context context = MyApplication.getInstance().getApplicationContext();
514545
final PackageManager pm = context.getPackageManager();
515546
final List<PackageInfo> installedPackages = pm.getInstalledPackages(PackageManager.GET_META_DATA);
@@ -564,8 +595,17 @@ protected void onPostExecute(List<PackageInfo> installedPackages) {
564595
if (pi.packageName.equals(MyApplication.getInstance().getPackageName())) {
565596
continue;
566597
}
567-
String t1 = pi.applicationInfo.loadLabel(pm).toString();
568-
if (packageFragment.searchFilter.trim().isEmpty() || t1.toLowerCase().contains(packageFragment.searchFilter.toLowerCase())) {
598+
String t1 = "";
599+
String t2 = packageFragment.searchFilter.trim();
600+
switch (packageFragment.appFilterBy) {
601+
case APPNAME:
602+
t1 = pi.applicationInfo.loadLabel(pm).toString();
603+
break;
604+
case PKGNAME:
605+
t1 = pi.packageName;
606+
break;
607+
}
608+
if (t2.isEmpty() || t1.toLowerCase().contains(t2.toLowerCase())) {
569609
final Preference preference = packageFragment.buildPackagePreferences(pm, pi);
570610
packageFragment.mFilterPreferenceScreen.addPreference(preference);
571611
}

android_app/app/src/main/res/menu/menu_search.xml

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
android:orderInCategory="112"
2828
app:showAsAction="never" />
2929
</group>
30+
<!-- sort by -->
3031
<item
3132
android:id="@+id/menu_sort_by"
3233
android:title="order by"
@@ -54,4 +55,34 @@
5455
</group>
5556
</menu>
5657
</item>
58+
<!-- filter by -->
59+
<item
60+
android:id="@+id/menu_filter_by"
61+
android:title="filter by"
62+
android:orderInCategory="200"
63+
app:showAsAction="never">
64+
<menu>
65+
<group
66+
android:id="@+id/menu_filter_group"
67+
android:checkableBehavior="single"
68+
android:enabled="true"
69+
android:menuCategory="container"
70+
android:orderInCategory="210"
71+
android:visible="true">
72+
<item
73+
android:id="@+id/menu_filter_app_name"
74+
android:checked="true"
75+
android:title="filter by app name"
76+
android:orderInCategory="211"
77+
app:showAsAction="never" />
78+
<item
79+
android:id="@+id/menu_filter_pkg_name"
80+
android:title="filter by package name"
81+
android:orderInCategory="212"
82+
app:showAsAction="never" />
83+
</group>
84+
</menu>
85+
</item>
86+
87+
5788
</menu>

android_app/gradle.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ android.useAndroidX=true
1919
android.enableJetifier=true
2020

2121
APP_NAME=TunProxy
22-
VERSION_NAME=1.2.4
22+
VERSION_NAME=1.2.5
2323

2424
productKeyStore=../changeit.jks
2525
productKeyAlias=key0

images/Menu-Settings-SortBy.png

-2.03 KB
Loading

0 commit comments

Comments
 (0)