Various bug fixes on Android 4.x

This commit is contained in:
PeratX 2017-05-04 21:38:12 +08:00
parent 7dcb8b2643
commit 0fd28c1e2b
3 changed files with 34 additions and 25 deletions

View File

@ -21,7 +21,7 @@ DNS server providers
Requirements Requirements
------------- -------------
* Minimum Android version: 4.0.4 (API 15) - __*Basic VPN functions*__ * Minimum Android version: 4.0.3 (API 15) - __*Basic VPN functions*__
* Recommended Android version: >= 5.0 (API 21) - __*Full features*__ * Recommended Android version: >= 5.0 (API 21) - __*Full features*__
* Best Android version: >= 7.1 (API 25) - __*Launcher shortcuts*__ * Best Android version: >= 7.1 (API 25) - __*Launcher shortcuts*__

View File

@ -52,6 +52,7 @@ public class DaedalusVpnService extends VpnService implements Runnable {
private long lastUpdate = 0; private long lastUpdate = 0;
private boolean statisticQuery; private boolean statisticQuery;
private DnsProvider provider; private DnsProvider provider;
private ParcelFileDescriptor descriptor;
private Thread mThread = null; private Thread mThread = null;
@ -121,14 +122,21 @@ public class DaedalusVpnService extends VpnService implements Runnable {
@TargetApi(Build.VERSION_CODES.LOLLIPOP) @TargetApi(Build.VERSION_CODES.LOLLIPOP)
private void stopThread() { private void stopThread() {
boolean shouldRefresh = false;
try { try {
if (this.descriptor != null) {
this.descriptor.close();
this.descriptor = null;
}
if (mThread != null) { if (mThread != null) {
running = false; running = false;
shouldRefresh = true; if (provider != null) {
provider.shutdown(); provider.shutdown();
mThread.interrupt(); mThread.interrupt();
provider.stop(); provider.stop();
} else {
mThread.interrupt();
}
mThread = null;
} }
if (notification != null) { if (notification != null) {
NotificationManager notificationManager = (NotificationManager) this.getSystemService(Context.NOTIFICATION_SERVICE); NotificationManager notificationManager = (NotificationManager) this.getSystemService(Context.NOTIFICATION_SERVICE);
@ -137,17 +145,18 @@ public class DaedalusVpnService extends VpnService implements Runnable {
} }
} catch (Exception e) { } catch (Exception e) {
Log.d(TAG, e.toString()); Log.d(TAG, e.toString());
} } finally {
stopSelf(); stopSelf();
if (shouldRefresh && MainActivity.getInstance() != null && Daedalus.getInstance().isAppOnForeground()) { if (MainActivity.getInstance() != null && Daedalus.getInstance().isAppOnForeground()) {
MainActivity.getInstance().startActivity(new Intent(getApplicationContext(), MainActivity.class).putExtra(MainActivity.LAUNCH_ACTION, MainActivity.LAUNCH_ACTION_AFTER_DEACTIVATE)); MainActivity.getInstance().startActivity(new Intent(getApplicationContext(), MainActivity.class).putExtra(MainActivity.LAUNCH_ACTION, MainActivity.LAUNCH_ACTION_AFTER_DEACTIVATE));
} else if (shouldRefresh) { } else {
Daedalus.updateShortcut(getApplicationContext()); Daedalus.updateShortcut(getApplicationContext());
} }
HostsResolver.clean(); HostsResolver.clean();
DnsServerHelper.cleanPortCache(); DnsServerHelper.cleanPortCache();
}
} }
@ -190,7 +199,7 @@ public class DaedalusVpnService extends VpnService implements Runnable {
.setBlocking(true); .setBlocking(true);
} }
ParcelFileDescriptor descriptor = builder.establish(); descriptor = builder.establish();
if (advanced) { if (advanced) {
if (Daedalus.getPrefs().getBoolean("settings_dns_over_tcp", false)) { if (Daedalus.getPrefs().getBoolean("settings_dns_over_tcp", false)) {

View File

@ -5,15 +5,6 @@
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="match_parent"> android:layout_height="match_parent">
<android.support.design.widget.FloatingActionButton
android:id="@+id/fab_add_server"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="bottom|end"
android:layout_margin="@dimen/fab_margin"
android:src="@drawable/ic_note_add"
android:tint="#FFFFFF"/>
<android.support.v7.widget.RecyclerView <android.support.v7.widget.RecyclerView
android:id="@+id/recyclerView_dns_servers" android:id="@+id/recyclerView_dns_servers"
android:layout_width="match_parent" android:layout_width="match_parent"
@ -23,4 +14,13 @@
android:layout_alignParentLeft="true" android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"/> android:layout_alignParentStart="true"/>
<android.support.design.widget.FloatingActionButton
android:id="@+id/fab_add_server"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="bottom|end"
android:layout_margin="@dimen/fab_margin"
android:src="@drawable/ic_note_add"
android:tint="#FFFFFF"/>
</android.support.design.widget.CoordinatorLayout> </android.support.design.widget.CoordinatorLayout>