Merge branch 'master' into usage

Conflicts:
	app/src/main/java/eu/faircode/netguard/SinkholeService.java
This commit is contained in:
M66B 2016-02-16 07:38:53 +01:00
commit 6ea46b47c1
3 changed files with 53 additions and 26 deletions

View File

@ -80,6 +80,7 @@ public class ActivityMain extends AppCompatActivity implements SharedPreferences
private static final int MIN_SDK = Build.VERSION_CODES.ICE_CREAM_SANDWICH; private static final int MIN_SDK = Build.VERSION_CODES.ICE_CREAM_SANDWICH;
public static final String ACTION_RULES_CHANGED = "eu.faircode.netguard.ACTION_RULES_CHANGED"; public static final String ACTION_RULES_CHANGED = "eu.faircode.netguard.ACTION_RULES_CHANGED";
public static final String EXTRA_REFRESH = "Refresh";
public static final String EXTRA_SEARCH = "Search"; public static final String EXTRA_SEARCH = "Search";
public static final String EXTRA_APPROVE = "Approve"; public static final String EXTRA_APPROVE = "Approve";
public static final String EXTRA_LOGCAT = "Logcat"; public static final String EXTRA_LOGCAT = "Logcat";
@ -296,7 +297,10 @@ public class ActivityMain extends AppCompatActivity implements SharedPreferences
super.onNewIntent(intent); super.onNewIntent(intent);
if (Build.VERSION.SDK_INT >= MIN_SDK) { if (Build.VERSION.SDK_INT >= MIN_SDK) {
if (intent.hasExtra(EXTRA_REFRESH))
updateApplicationList(intent.getStringExtra(EXTRA_SEARCH)); updateApplicationList(intent.getStringExtra(EXTRA_SEARCH));
else
updateSearch(intent.getStringExtra(EXTRA_SEARCH));
checkExtras(intent); checkExtras(intent);
} }
} }
@ -511,15 +515,7 @@ public class ActivityMain extends AppCompatActivity implements SharedPreferences
if (running) { if (running) {
if (adapter != null) { if (adapter != null) {
adapter.set(result); adapter.set(result);
updateSearch(search);
SearchView searchView = (SearchView) MenuItemCompat.getActionView(menuSearch);
if (search == null) {
if (menuSearch != null && menuSearch.isActionViewExpanded())
adapter.getFilter().filter(searchView.getQuery().toString());
} else {
MenuItemCompat.expandActionView(menuSearch);
searchView.setQuery(search, true);
}
} }
if (swipeRefresh != null) { if (swipeRefresh != null) {
@ -531,6 +527,19 @@ public class ActivityMain extends AppCompatActivity implements SharedPreferences
}.execute(); }.execute();
} }
private void updateSearch(String search) {
if (menuSearch != null) {
SearchView searchView = (SearchView) MenuItemCompat.getActionView(menuSearch);
if (search == null) {
if (menuSearch.isActionViewExpanded())
adapter.getFilter().filter(searchView.getQuery().toString());
} else {
MenuItemCompat.expandActionView(menuSearch);
searchView.setQuery(search, true);
}
}
}
@Override @Override
public boolean onCreateOptionsMenu(Menu menu) { public boolean onCreateOptionsMenu(Menu menu) {
if (Build.VERSION.SDK_INT < MIN_SDK) if (Build.VERSION.SDK_INT < MIN_SDK)

View File

@ -116,6 +116,7 @@ public class Receiver extends BroadcastReceiver {
// Build notification // Build notification
Intent main = new Intent(context, ActivityMain.class); Intent main = new Intent(context, ActivityMain.class);
main.putExtra(ActivityMain.EXTRA_REFRESH, true);
main.putExtra(ActivityMain.EXTRA_SEARCH, Integer.toString(uid)); main.putExtra(ActivityMain.EXTRA_SEARCH, Integer.toString(uid));
PendingIntent pi = PendingIntent.getActivity(context, uid, main, PendingIntent.FLAG_UPDATE_CURRENT); PendingIntent pi = PendingIntent.getActivity(context, uid, main, PendingIntent.FLAG_UPDATE_CURRENT);

View File

@ -371,17 +371,32 @@ public class SinkholeService extends VpnService implements SharedPreferences.OnS
List<Rule> listRule = Rule.getRules(true, SinkholeService.this); List<Rule> listRule = Rule.getRules(true, SinkholeService.this);
List<Rule> listAllowed = getAllowedRules(listRule); List<Rule> listAllowed = getAllowedRules(listRule);
// Attempt seamless handover if (Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP_MR1) {
ParcelFileDescriptor prev = vpn; if (vpn != null) {
vpn = startVPN(listAllowed); stopNative(vpn, false);
if (prev != null && vpn == null) { stopVPN(vpn);
Log.w(TAG, "Handover failed"); vpn = null;
stopVPN(prev);
try { try {
Thread.sleep(3000); Thread.sleep(3000);
} catch (InterruptedException ignored) { } catch (InterruptedException ignored) {
} }
}
vpn = startVPN(listAllowed);
} else {
// Attempt seamless handover
ParcelFileDescriptor prev = vpn;
vpn = startVPN(listAllowed);
if (prev != null && vpn == null) {
Log.w(TAG, "Handover failed");
stopNative(prev, false);
stopVPN(prev);
prev = null; prev = null;
try {
Thread.sleep(3000);
} catch (InterruptedException ignored) {
}
vpn = startVPN(listAllowed); vpn = startVPN(listAllowed);
if (vpn == null) if (vpn == null)
throw new IllegalStateException("Handover failed"); throw new IllegalStateException("Handover failed");
@ -391,6 +406,8 @@ public class SinkholeService extends VpnService implements SharedPreferences.OnS
stopNative(prev, false); stopNative(prev, false);
stopVPN(prev); stopVPN(prev);
} }
}
if (vpn == null) if (vpn == null)
throw new IllegalStateException("VPN start failed"); throw new IllegalStateException("VPN start failed");