Skip to content
This repository has been archived by the owner on Sep 3, 2024. It is now read-only.

Commit

Permalink
Fix crash on close via VPN-popup, issue #12
Browse files Browse the repository at this point in the history
  • Loading branch information
yvesf committed Sep 9, 2014
1 parent 612c5fd commit eca476b
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 14 deletions.
4 changes: 3 additions & 1 deletion src/org/xapek/andiodine/FragmentStatus.java
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,9 @@ public void onReceive(Context context, Intent intent) {
} else if (IodineVpnService.ACTION_STATUS_CONNECT.equals(intent.getAction())) {
mStatus.setText("Connect");
} else if (IodineVpnService.ACTION_STATUS_CONNECTED.equals(intent.getAction())) {
mStatus.setText("Connected");
mStatus.setText("Connected: " + IodineClient.getIp() + '/'
+ IodineClient.getNetbits() + " MTU: "
+ IodineClient.getMtu() + '\n');
} else if (IodineVpnService.ACTION_STATUS_DISCONNECT.equals(intent.getAction())) {
mStatus.setText("Disconnect");
}
Expand Down
36 changes: 23 additions & 13 deletions src/org/xapek/andiodine/IodineMain.java
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,8 @@ public void onReceive(Context context, Intent intent) {
ft.replace(R.id.main_fragment_status, fragmentList);
ft.setTransition(FragmentTransaction.TRANSIT_FRAGMENT_FADE);
ft.commit();
} else if (IodineVpnService.ACTION_STATUS_CONNECT.equals(intent.getAction())) {
} else if (IodineVpnService.ACTION_STATUS_CONNECT.equals(intent.getAction())
|| IodineVpnService.ACTION_STATUS_CONNECTED.equals(intent.getAction())) {
// Switch to Status Fragment
FragmentTransaction ft = getFragmentManager().beginTransaction();
ft.replace(R.id.main_fragment_status, fragmentStatus);
Expand All @@ -57,12 +58,6 @@ protected void onCreate(Bundle savedInstanceState) {

mConfigDatabase = new ConfigDatabase(this);

IntentFilter intentFilterStatusUpdates = new IntentFilter();
intentFilterStatusUpdates.addAction(IodineVpnService.ACTION_STATUS_CONNECT);
intentFilterStatusUpdates.addAction(IodineVpnService.ACTION_STATUS_ERROR);
intentFilterStatusUpdates.addAction(IodineVpnService.ACTION_STATUS_IDLE);
registerReceiver(broadcastReceiverStatusUpdates, intentFilterStatusUpdates);

startService(new Intent(this, IodineVpnService.class));
}

Expand All @@ -73,8 +68,27 @@ public boolean onCreateOptionsMenu(Menu menu) {
}

@Override
protected void onDestroy() {
protected void onResume() {
super.onResume();
IntentFilter intentFilterStatusUpdates = new IntentFilter();
intentFilterStatusUpdates.addAction(IodineVpnService.ACTION_STATUS_CONNECT);
intentFilterStatusUpdates.addAction(IodineVpnService.ACTION_STATUS_CONNECTED);
intentFilterStatusUpdates.addAction(IodineVpnService.ACTION_STATUS_ERROR);
intentFilterStatusUpdates.addAction(IodineVpnService.ACTION_STATUS_IDLE);
registerReceiver(broadcastReceiverStatusUpdates, intentFilterStatusUpdates);

Log.d(TAG, "Request CONTROL_UPDATE");
sendBroadcast(new Intent(IodineVpnService.ACTION_CONTROL_UPDATE));
}

@Override
protected void onPause() {
unregisterReceiver(broadcastReceiverStatusUpdates);
super.onPause();
}

@Override
protected void onDestroy() {
mConfigDatabase.close();
super.onDestroy();
}
Expand All @@ -89,14 +103,10 @@ public boolean onOptionsItemSelected(MenuItem item) {
.setCancelable(true)//
.create() //
.show();
scanner.close();
} else if (item.getItemId() == R.id.menu_main_add) {
startActivity(new Intent(this, IodinePref.class));
}
return super.onOptionsItemSelected(item);
}


private void vpnServiceDisconnect() {
sendBroadcast(new Intent(IodineVpnService.ACTION_CONTROL_DISCONNECT));
}
}
1 change: 1 addition & 0 deletions src/org/xapek/andiodine/IodineVpnService.java
Original file line number Diff line number Diff line change
Expand Up @@ -188,6 +188,7 @@ private void setStatus(String ACTION_STATUS, Long configurationId, String messag
}

private void sendStatus() {
Log.d(TAG, "Send status: " + currentActionStatus);
if (currentActionStatus != null) {
Intent intent = new Intent(currentActionStatus);

Expand Down

0 comments on commit eca476b

Please sign in to comment.