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

Commit eca476b

Browse files
committed
Fix crash on close via VPN-popup, issue #12
1 parent 612c5fd commit eca476b

File tree

3 files changed

+27
-14
lines changed

3 files changed

+27
-14
lines changed

src/org/xapek/andiodine/FragmentStatus.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,9 @@ public void onReceive(Context context, Intent intent) {
4646
} else if (IodineVpnService.ACTION_STATUS_CONNECT.equals(intent.getAction())) {
4747
mStatus.setText("Connect");
4848
} else if (IodineVpnService.ACTION_STATUS_CONNECTED.equals(intent.getAction())) {
49-
mStatus.setText("Connected");
49+
mStatus.setText("Connected: " + IodineClient.getIp() + '/'
50+
+ IodineClient.getNetbits() + " MTU: "
51+
+ IodineClient.getMtu() + '\n');
5052
} else if (IodineVpnService.ACTION_STATUS_DISCONNECT.equals(intent.getAction())) {
5153
mStatus.setText("Disconnect");
5254
}

src/org/xapek/andiodine/IodineMain.java

Lines changed: 23 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,8 @@ public void onReceive(Context context, Intent intent) {
3939
ft.replace(R.id.main_fragment_status, fragmentList);
4040
ft.setTransition(FragmentTransaction.TRANSIT_FRAGMENT_FADE);
4141
ft.commit();
42-
} else if (IodineVpnService.ACTION_STATUS_CONNECT.equals(intent.getAction())) {
42+
} else if (IodineVpnService.ACTION_STATUS_CONNECT.equals(intent.getAction())
43+
|| IodineVpnService.ACTION_STATUS_CONNECTED.equals(intent.getAction())) {
4344
// Switch to Status Fragment
4445
FragmentTransaction ft = getFragmentManager().beginTransaction();
4546
ft.replace(R.id.main_fragment_status, fragmentStatus);
@@ -57,12 +58,6 @@ protected void onCreate(Bundle savedInstanceState) {
5758

5859
mConfigDatabase = new ConfigDatabase(this);
5960

60-
IntentFilter intentFilterStatusUpdates = new IntentFilter();
61-
intentFilterStatusUpdates.addAction(IodineVpnService.ACTION_STATUS_CONNECT);
62-
intentFilterStatusUpdates.addAction(IodineVpnService.ACTION_STATUS_ERROR);
63-
intentFilterStatusUpdates.addAction(IodineVpnService.ACTION_STATUS_IDLE);
64-
registerReceiver(broadcastReceiverStatusUpdates, intentFilterStatusUpdates);
65-
6661
startService(new Intent(this, IodineVpnService.class));
6762
}
6863

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

7570
@Override
76-
protected void onDestroy() {
71+
protected void onResume() {
72+
super.onResume();
73+
IntentFilter intentFilterStatusUpdates = new IntentFilter();
74+
intentFilterStatusUpdates.addAction(IodineVpnService.ACTION_STATUS_CONNECT);
75+
intentFilterStatusUpdates.addAction(IodineVpnService.ACTION_STATUS_CONNECTED);
76+
intentFilterStatusUpdates.addAction(IodineVpnService.ACTION_STATUS_ERROR);
77+
intentFilterStatusUpdates.addAction(IodineVpnService.ACTION_STATUS_IDLE);
78+
registerReceiver(broadcastReceiverStatusUpdates, intentFilterStatusUpdates);
79+
80+
Log.d(TAG, "Request CONTROL_UPDATE");
81+
sendBroadcast(new Intent(IodineVpnService.ACTION_CONTROL_UPDATE));
82+
}
83+
84+
@Override
85+
protected void onPause() {
7786
unregisterReceiver(broadcastReceiverStatusUpdates);
87+
super.onPause();
88+
}
89+
90+
@Override
91+
protected void onDestroy() {
7892
mConfigDatabase.close();
7993
super.onDestroy();
8094
}
@@ -89,14 +103,10 @@ public boolean onOptionsItemSelected(MenuItem item) {
89103
.setCancelable(true)//
90104
.create() //
91105
.show();
106+
scanner.close();
92107
} else if (item.getItemId() == R.id.menu_main_add) {
93108
startActivity(new Intent(this, IodinePref.class));
94109
}
95110
return super.onOptionsItemSelected(item);
96111
}
97-
98-
99-
private void vpnServiceDisconnect() {
100-
sendBroadcast(new Intent(IodineVpnService.ACTION_CONTROL_DISCONNECT));
101-
}
102112
}

src/org/xapek/andiodine/IodineVpnService.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -188,6 +188,7 @@ private void setStatus(String ACTION_STATUS, Long configurationId, String messag
188188
}
189189

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

0 commit comments

Comments
 (0)