Request VPN approval after autostart fail

Refs #243
This commit is contained in:
M66B 2016-02-02 08:43:53 +01:00
parent 262f07e69a
commit 7f9e435504
2 changed files with 14 additions and 4 deletions

View File

@ -79,6 +79,7 @@ public class ActivityMain extends AppCompatActivity implements SharedPreferences
public static final String ACTION_RULES_CHANGED = "eu.faircode.netguard.ACTION_RULES_CHANGED";
public static final String EXTRA_SEARCH = "Search";
public static final String EXTRA_APPROVE = "Approve";
@Override
protected void onCreate(Bundle savedInstanceState) {
@ -103,10 +104,12 @@ public class ActivityMain extends AppCompatActivity implements SharedPreferences
// Upgrade
Receiver.upgrade(initialized, this);
if (enabled)
SinkholeService.start("UI", this);
else
SinkholeService.stop("UI", this);
if (!getIntent().hasExtra(EXTRA_APPROVE)) {
if (enabled)
SinkholeService.start("UI", this);
else
SinkholeService.stop("UI", this);
}
// Action bar
View actionView = getLayoutInflater().inflate(R.layout.action, null);
@ -277,6 +280,12 @@ public class ActivityMain extends AppCompatActivity implements SharedPreferences
} catch (Throwable ex) {
Log.e(TAG, ex.toString() + "\n" + Log.getStackTraceString(ex));
}
// Approve request
if (getIntent().hasExtra(EXTRA_APPROVE) && !enabled) {
Log.i(TAG, "Requesting VPN approval");
swEnabled.toggle();
}
}
@Override

View File

@ -1528,6 +1528,7 @@ public class SinkholeService extends VpnService implements SharedPreferences.OnS
private void showAutoStartNotification() {
Intent main = new Intent(this, ActivityMain.class);
main.putExtra(ActivityMain.EXTRA_APPROVE, true);
PendingIntent pi = PendingIntent.getActivity(this, 0, main, PendingIntent.FLAG_UPDATE_CURRENT);
TypedValue tv = new TypedValue();