Implemented local hosts resolver on boot

This commit is contained in:
PeratX 2017-04-26 22:02:06 +08:00
parent b6ea6ff647
commit 59d080b217

View File

@ -1,13 +1,18 @@
package org.itxtech.daedalus.receiver;
import android.Manifest;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.content.pm.PackageManager;
import android.net.VpnService;
import android.os.Build;
import android.support.v4.app.ActivityCompat;
import android.util.Log;
import org.itxtech.daedalus.Daedalus;
import org.itxtech.daedalus.service.DaedalusVpnService;
import org.itxtech.daedalus.util.DnsServer;
import org.itxtech.daedalus.util.HostsResolver;
/**
* Daedalus Project
@ -24,6 +29,16 @@ public class BootBroadcastReceiver extends BroadcastReceiver {
public void onReceive(Context context, Intent intent) {
if (Daedalus.getPrefs().getBoolean("settings_boot", false)) {
if (Daedalus.getPrefs().getBoolean("settings_local_host_resolve", false)) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
int permission = ActivityCompat.checkSelfPermission(context, Manifest.permission.WRITE_EXTERNAL_STORAGE);
if (permission != PackageManager.PERMISSION_GRANTED) {
return;
}
}
HostsResolver.startLoad(context.getExternalFilesDir(null).getPath() + "/hosts");
}
Intent vIntent = VpnService.prepare(context);
if (vIntent != null) {
context.startActivity(vIntent);