Switch to blocking, add action toggle all
|
@ -120,25 +120,35 @@ public class ActivityMain extends AppCompatActivity implements SharedPreferences
|
||||||
MenuInflater inflater = getMenuInflater();
|
MenuInflater inflater = getMenuInflater();
|
||||||
inflater.inflate(R.menu.main, menu);
|
inflater.inflate(R.menu.main, menu);
|
||||||
|
|
||||||
|
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this);
|
||||||
|
|
||||||
|
MenuItem wifiItem = menu.findItem(R.id.menu_wifi);
|
||||||
|
MenuItem otherItem = menu.findItem(R.id.menu_other);
|
||||||
|
wifiItem.setIcon(prefs.getBoolean("wifi", true) ? R.drawable.ic_network_wifi_white_24dp : R.drawable.ic_signal_wifi_off_white_24dp);
|
||||||
|
otherItem.setIcon(prefs.getBoolean("other", true) ? R.drawable.ic_network_cell_white_24dp : R.drawable.ic_signal_cellular_off_white_24dp);
|
||||||
|
|
||||||
MenuItem searchItem = menu.findItem(R.id.menu_search);
|
MenuItem searchItem = menu.findItem(R.id.menu_search);
|
||||||
SearchView searchView = (SearchView) MenuItemCompat.getActionView(searchItem);
|
SearchView searchView = (SearchView) MenuItemCompat.getActionView(searchItem);
|
||||||
searchView.setOnQueryTextListener(new SearchView.OnQueryTextListener() {
|
searchView.setOnQueryTextListener(new SearchView.OnQueryTextListener() {
|
||||||
@Override
|
@Override
|
||||||
public boolean onQueryTextSubmit(String query) {
|
public boolean onQueryTextSubmit(String query) {
|
||||||
applyFilter(query);
|
if (adapter != null)
|
||||||
|
adapter.getFilter().filter(query);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean onQueryTextChange(String newText) {
|
public boolean onQueryTextChange(String newText) {
|
||||||
applyFilter(newText);
|
if (adapter != null)
|
||||||
|
adapter.getFilter().filter(newText);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
searchView.setOnCloseListener(new SearchView.OnCloseListener() {
|
searchView.setOnCloseListener(new SearchView.OnCloseListener() {
|
||||||
@Override
|
@Override
|
||||||
public boolean onClose() {
|
public boolean onClose() {
|
||||||
applyFilter(null);
|
if (adapter != null)
|
||||||
|
adapter.getFilter().filter(null);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
@ -146,15 +156,27 @@ public class ActivityMain extends AppCompatActivity implements SharedPreferences
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void applyFilter(String query) {
|
|
||||||
if (adapter != null)
|
|
||||||
adapter.getFilter().filter(query);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean onOptionsItemSelected(MenuItem item) {
|
public boolean onOptionsItemSelected(MenuItem item) {
|
||||||
// Handle item selection
|
// Handle item selection
|
||||||
|
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this);
|
||||||
switch (item.getItemId()) {
|
switch (item.getItemId()) {
|
||||||
|
case R.id.menu_wifi:
|
||||||
|
boolean wifi = !prefs.getBoolean("wifi", true);
|
||||||
|
prefs.edit().putBoolean("wifi", wifi).apply();
|
||||||
|
if (adapter != null)
|
||||||
|
adapter.set("wifi", wifi, this);
|
||||||
|
invalidateOptionsMenu();
|
||||||
|
return true;
|
||||||
|
|
||||||
|
case R.id.menu_other:
|
||||||
|
boolean other = !prefs.getBoolean("other", true);
|
||||||
|
prefs.edit().putBoolean("other", other).apply();
|
||||||
|
if (adapter != null)
|
||||||
|
adapter.set("other", other, this);
|
||||||
|
invalidateOptionsMenu();
|
||||||
|
return true;
|
||||||
|
|
||||||
case R.id.menu_vpn_settings:
|
case R.id.menu_vpn_settings:
|
||||||
Intent intent = new Intent("android.net.vpn.SETTINGS");
|
Intent intent = new Intent("android.net.vpn.SETTINGS");
|
||||||
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
|
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
|
||||||
|
|
|
@ -115,7 +115,7 @@ public class BlackHoleService extends VpnService implements Runnable {
|
||||||
builder.setSession("BlackHoleService");
|
builder.setSession("BlackHoleService");
|
||||||
builder.addAddress("10.1.10.1", 32);
|
builder.addAddress("10.1.10.1", 32);
|
||||||
builder.addRoute("0.0.0.0", 0);
|
builder.addRoute("0.0.0.0", 0);
|
||||||
builder.setBlocking(true);
|
builder.setBlocking(false);
|
||||||
|
|
||||||
// Add list of allowed applications
|
// Add list of allowed applications
|
||||||
for (Rule rule : Rule.getRules(this))
|
for (Rule rule : Rule.getRules(this))
|
||||||
|
@ -135,7 +135,11 @@ public class BlackHoleService extends VpnService implements Runnable {
|
||||||
Log.i(TAG, "Loop start thread=" + Thread.currentThread());
|
Log.i(TAG, "Loop start thread=" + Thread.currentThread());
|
||||||
FileInputStream in = new FileInputStream(pfd.getFileDescriptor());
|
FileInputStream in = new FileInputStream(pfd.getFileDescriptor());
|
||||||
while (!Thread.currentThread().isInterrupted() && pfd.getFileDescriptor().valid())
|
while (!Thread.currentThread().isInterrupted() && pfd.getFileDescriptor().valid())
|
||||||
in.skip(32768);
|
if (in.skip(32768) < 0)
|
||||||
|
try {
|
||||||
|
Thread.sleep(1000);
|
||||||
|
} catch (InterruptedException ignored) {
|
||||||
|
}
|
||||||
Log.i(TAG, "Loop exit thread=" + Thread.currentThread());
|
Log.i(TAG, "Loop exit thread=" + Thread.currentThread());
|
||||||
|
|
||||||
} catch (Throwable ex) {
|
} catch (Throwable ex) {
|
||||||
|
|
|
@ -30,7 +30,7 @@ public class Rule implements Comparable<Rule> {
|
||||||
for (PackageInfo info : context.getPackageManager().getInstalledPackages(0))
|
for (PackageInfo info : context.getPackageManager().getInstalledPackages(0))
|
||||||
listRules.add(new Rule(
|
listRules.add(new Rule(
|
||||||
info,
|
info,
|
||||||
wifi.getBoolean(info.packageName, false),
|
wifi.getBoolean(info.packageName, true),
|
||||||
other.getBoolean(info.packageName, true),
|
other.getBoolean(info.packageName, true),
|
||||||
context
|
context
|
||||||
));
|
));
|
||||||
|
|
|
@ -124,6 +124,24 @@ public class RuleAdapter extends RecyclerView.Adapter<RuleAdapter.ViewHolder> im
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void set(String name, boolean blocked, Context context) {
|
||||||
|
SharedPreferences.Editor editor = context.getSharedPreferences(name, Context.MODE_PRIVATE).edit();
|
||||||
|
for (Rule rule : listSelected) {
|
||||||
|
if ("wifi".equals(name))
|
||||||
|
rule.wifi_blocked = blocked;
|
||||||
|
else
|
||||||
|
rule.other_blocked = blocked;
|
||||||
|
editor.putBoolean(rule.info.packageName, blocked);
|
||||||
|
}
|
||||||
|
editor.apply();
|
||||||
|
|
||||||
|
Intent intent = new Intent(context, BlackHoleService.class);
|
||||||
|
intent.putExtra(BlackHoleService.EXTRA_COMMAND, BlackHoleService.Command.reload);
|
||||||
|
context.startService(intent);
|
||||||
|
|
||||||
|
notifyDataSetChanged();
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public RuleAdapter.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
|
public RuleAdapter.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
|
||||||
return new ViewHolder(LayoutInflater.from(parent.getContext()).inflate(R.layout.rule, parent, false));
|
return new ViewHolder(LayoutInflater.from(parent.getContext()).inflate(R.layout.rule, parent, false));
|
||||||
|
|
Before Width: | Height: | Size: 161 B |
After Width: | Height: | Size: 162 B |
Before Width: | Height: | Size: 394 B |
After Width: | Height: | Size: 427 B |
Before Width: | Height: | Size: 261 B |
After Width: | Height: | Size: 282 B |
Before Width: | Height: | Size: 391 B |
After Width: | Height: | Size: 421 B |
Before Width: | Height: | Size: 131 B |
After Width: | Height: | Size: 139 B |
Before Width: | Height: | Size: 273 B |
After Width: | Height: | Size: 299 B |
Before Width: | Height: | Size: 195 B |
After Width: | Height: | Size: 201 B |
Before Width: | Height: | Size: 291 B |
After Width: | Height: | Size: 308 B |
Before Width: | Height: | Size: 193 B |
After Width: | Height: | Size: 191 B |
Before Width: | Height: | Size: 491 B |
After Width: | Height: | Size: 538 B |
Before Width: | Height: | Size: 289 B |
After Width: | Height: | Size: 309 B |
Before Width: | Height: | Size: 481 B |
After Width: | Height: | Size: 528 B |
Before Width: | Height: | Size: 244 B |
After Width: | Height: | Size: 263 B |
Before Width: | Height: | Size: 715 B |
After Width: | Height: | Size: 786 B |
Before Width: | Height: | Size: 388 B |
After Width: | Height: | Size: 435 B |
Before Width: | Height: | Size: 727 B |
After Width: | Height: | Size: 795 B |
Before Width: | Height: | Size: 278 B |
After Width: | Height: | Size: 293 B |
Before Width: | Height: | Size: 945 B |
After Width: | Height: | Size: 1.0 KiB |
Before Width: | Height: | Size: 463 B |
After Width: | Height: | Size: 524 B |
Before Width: | Height: | Size: 899 B |
After Width: | Height: | Size: 994 B |
|
@ -1,4 +1,4 @@
|
||||||
<?xml version="1.0" encoding="utf-8"?>
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
<bitmap xmlns:android="http://schemas.android.com/apk/res/android"
|
<bitmap xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
android:src="@drawable/ic_signal_cellular_off_black_24dp"
|
android:src="@drawable/ic_signal_cellular_off_white_24dp"
|
||||||
android:tint="@color/colorAccent" />
|
android:tint="@color/colorAccent" />
|
|
@ -1,4 +1,4 @@
|
||||||
<?xml version="1.0" encoding="utf-8"?>
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
<bitmap xmlns:android="http://schemas.android.com/apk/res/android"
|
<bitmap xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
android:src="@drawable/ic_network_cell_black_24dp"
|
android:src="@drawable/ic_network_cell_white_24dp"
|
||||||
android:tint="@color/colorPrimary" />
|
android:tint="@color/colorPrimary" />
|
|
@ -1,4 +1,4 @@
|
||||||
<?xml version="1.0" encoding="utf-8"?>
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
<bitmap xmlns:android="http://schemas.android.com/apk/res/android"
|
<bitmap xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
android:src="@drawable/ic_signal_wifi_off_black_24dp"
|
android:src="@drawable/ic_signal_wifi_off_white_24dp"
|
||||||
android:tint="@color/colorAccent" />
|
android:tint="@color/colorAccent" />
|
|
@ -1,4 +1,4 @@
|
||||||
<?xml version="1.0" encoding="utf-8"?>
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
<bitmap xmlns:android="http://schemas.android.com/apk/res/android"
|
<bitmap xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
android:src="@drawable/ic_network_wifi_black_24dp"
|
android:src="@drawable/ic_network_wifi_white_24dp"
|
||||||
android:tint="@color/colorPrimary" />
|
android:tint="@color/colorPrimary" />
|
|
@ -1,11 +1,12 @@
|
||||||
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
android:layout_width="wrap_content"
|
android:layout_width="wrap_content"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:background="@color/colorPrimary">
|
android:background="@color/colorPrimary"
|
||||||
|
android:orientation="horizontal">
|
||||||
|
|
||||||
<Switch
|
<Switch
|
||||||
android:id="@+id/swEnabled"
|
android:id="@+id/swEnabled"
|
||||||
android:layout_width="wrap_content"
|
android:layout_width="wrap_content"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:layout_marginLeft="16dp" />
|
android:layout_marginLeft="12dp" />
|
||||||
</RelativeLayout>
|
</LinearLayout>
|
|
@ -6,7 +6,17 @@
|
||||||
android:icon="@drawable/ic_search_white_24dp"
|
android:icon="@drawable/ic_search_white_24dp"
|
||||||
android:title="@string/menu_search"
|
android:title="@string/menu_search"
|
||||||
netguard:actionViewClass="android.support.v7.widget.SearchView"
|
netguard:actionViewClass="android.support.v7.widget.SearchView"
|
||||||
netguard:showAsAction="ifRoom|collapseActionView" />
|
netguard:showAsAction="always|collapseActionView" />
|
||||||
|
<item
|
||||||
|
android:id="@+id/menu_wifi"
|
||||||
|
android:icon="@drawable/ic_network_wifi_white_24dp"
|
||||||
|
android:title="@string/menu_wifi"
|
||||||
|
netguard:showAsAction="always" />
|
||||||
|
<item
|
||||||
|
android:id="@+id/menu_other"
|
||||||
|
android:icon="@drawable/ic_network_cell_white_24dp"
|
||||||
|
android:title="@string/menu_other"
|
||||||
|
netguard:showAsAction="always" />
|
||||||
<item
|
<item
|
||||||
android:id="@+id/menu_vpn_settings"
|
android:id="@+id/menu_vpn_settings"
|
||||||
android:title="@string/menu_vpn_settings" />
|
android:title="@string/menu_vpn_settings" />
|
||||||
|
|
|
@ -2,6 +2,8 @@
|
||||||
<string name="app_name">NetGuard</string>
|
<string name="app_name">NetGuard</string>
|
||||||
<string name="app_copyright">Copyright \u00A9 2015 by M. Bokhorst (M66B)</string>
|
<string name="app_copyright">Copyright \u00A9 2015 by M. Bokhorst (M66B)</string>
|
||||||
<string name="menu_search">Search</string>
|
<string name="menu_search">Search</string>
|
||||||
|
<string name="menu_wifi">Toggle Wi-Fi</string>
|
||||||
|
<string name="menu_other">Toggle other</string>
|
||||||
<string name="menu_vpn_settings">VPN settings</string>
|
<string name="menu_vpn_settings">VPN settings</string>
|
||||||
<string name="menu_about">About</string>
|
<string name="menu_about">About</string>
|
||||||
</resources>
|
</resources>
|
||||||
|
|