Improved permission request notice
This commit is contained in:
parent
db2fc4e569
commit
06274e7787
@ -22,12 +22,14 @@ This application can create a VPN tunnel to modify the DNS settings on Android.<
|
||||
No root access required, no ads contained and functional under data connection.<br>
|
||||
Through the DNS which are provided by third parties, users can visit Google, Twitter and so on via https directly without a VPN.<br>
|
||||
<br>
|
||||
Local hosts is located in SDCard/Android/data/org.itxtech.daedalus/files <br>
|
||||
<br>
|
||||
__Users must comply with local laws and regulations.__<br>
|
||||
|
||||
DNS providers
|
||||
-------------
|
||||
* __CuteDNS!__ - *Stop service due to police intervention.*
|
||||
* __[Pure DNS](http://puredns.cn/)__ - *I DO NOT KNOW HOW TO DESCIBE~~~*
|
||||
* __[Pure DNS](http://puredns.cn/)__ - *I DO NOT KNOW HOW TO DESCRIBE~~~*
|
||||
* __[AIXYZ DNS](https://aixyz.com/)__ - __*For academic purposes only.*__
|
||||
|
||||
Requirements
|
||||
|
@ -1,15 +1,18 @@
|
||||
package org.itxtech.daedalus;
|
||||
|
||||
import android.Manifest;
|
||||
import android.app.ActivityManager;
|
||||
import android.app.Application;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.content.SharedPreferences;
|
||||
import android.content.pm.PackageManager;
|
||||
import android.content.pm.ShortcutInfo;
|
||||
import android.content.pm.ShortcutManager;
|
||||
import android.graphics.drawable.Icon;
|
||||
import android.os.Build;
|
||||
import android.preference.PreferenceManager;
|
||||
import android.support.v4.app.ActivityCompat;
|
||||
import android.util.Log;
|
||||
import org.itxtech.daedalus.activity.MainActivity;
|
||||
import org.itxtech.daedalus.service.DaedalusVpnService;
|
||||
@ -71,6 +74,27 @@ public class Daedalus extends Application {
|
||||
prefs = PreferenceManager.getDefaultSharedPreferences(this);
|
||||
}
|
||||
|
||||
public static final int REQUEST_EXTERNAL_STORAGE = 1;
|
||||
public static String[] PERMISSIONS_STORAGE = {
|
||||
Manifest.permission.READ_EXTERNAL_STORAGE,
|
||||
Manifest.permission.WRITE_EXTERNAL_STORAGE
|
||||
};
|
||||
|
||||
public static void initHostsResolver() {
|
||||
if (Daedalus.getPrefs().getBoolean("settings_local_host_resolve", false)) {
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
|
||||
if (MainActivity.getInstance() != null) {
|
||||
int permission = ActivityCompat.checkSelfPermission(Daedalus.getInstance(), Manifest.permission.WRITE_EXTERNAL_STORAGE);
|
||||
if (permission != PackageManager.PERMISSION_GRANTED) {
|
||||
ActivityCompat.requestPermissions(MainActivity.getInstance(), PERMISSIONS_STORAGE, REQUEST_EXTERNAL_STORAGE);
|
||||
}
|
||||
} else {
|
||||
return;
|
||||
}
|
||||
}
|
||||
HostsResolver.startLoad(instance.getExternalFilesDir(null).getPath() + "/hosts");
|
||||
}
|
||||
}
|
||||
public static SharedPreferences getPrefs() {
|
||||
return prefs;
|
||||
}
|
||||
|
@ -10,6 +10,7 @@ import android.os.Build;
|
||||
import android.os.Bundle;
|
||||
import android.support.annotation.NonNull;
|
||||
import android.support.design.widget.NavigationView;
|
||||
import android.support.design.widget.Snackbar;
|
||||
import android.support.v4.app.ActivityCompat;
|
||||
import android.support.v4.view.GravityCompat;
|
||||
import android.support.v4.widget.DrawerLayout;
|
||||
@ -27,7 +28,6 @@ import org.itxtech.daedalus.fragment.AboutFragment;
|
||||
import org.itxtech.daedalus.fragment.DnsTestFragment;
|
||||
import org.itxtech.daedalus.fragment.MainFragment;
|
||||
import org.itxtech.daedalus.fragment.SettingsFragment;
|
||||
import org.itxtech.daedalus.util.HostsResolver;
|
||||
|
||||
/**
|
||||
* Daedalus Project
|
||||
@ -55,12 +55,6 @@ public class MainActivity extends AppCompatActivity implements NavigationView.On
|
||||
public static final int FRAGMENT_SETTINGS = 2;
|
||||
public static final int FRAGMENT_ABOUT = 3;
|
||||
|
||||
private static final int REQUEST_EXTERNAL_STORAGE = 1;
|
||||
private static String[] PERMISSIONS_STORAGE = {
|
||||
Manifest.permission.READ_EXTERNAL_STORAGE,
|
||||
Manifest.permission.WRITE_EXTERNAL_STORAGE
|
||||
};
|
||||
|
||||
private static MainActivity instance = null;
|
||||
|
||||
private MainFragment mMain;
|
||||
@ -84,8 +78,6 @@ public class MainActivity extends AppCompatActivity implements NavigationView.On
|
||||
setTheme(R.style.AppTheme_NoActionBar_TransparentStatusBar);
|
||||
super.onCreate(savedInstanceState);
|
||||
|
||||
initHostsResolver();
|
||||
|
||||
instance = this;
|
||||
|
||||
setContentView(R.layout.activity_main);
|
||||
@ -118,21 +110,29 @@ public class MainActivity extends AppCompatActivity implements NavigationView.On
|
||||
Log.d(TAG, "onCreate");
|
||||
}
|
||||
|
||||
public void initHostsResolver() {
|
||||
if (Daedalus.getPrefs().getBoolean("settings_local_host_resolve", false)) {
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
|
||||
int permission = ActivityCompat.checkSelfPermission(this.getApplicationContext(), Manifest.permission.WRITE_EXTERNAL_STORAGE);
|
||||
if (permission != PackageManager.PERMISSION_GRANTED) {
|
||||
ActivityCompat.requestPermissions(this, PERMISSIONS_STORAGE, REQUEST_EXTERNAL_STORAGE);
|
||||
}
|
||||
private void checkStorage() {
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
|
||||
int permission = ActivityCompat.checkSelfPermission(getApplicationContext(), Manifest.permission.WRITE_EXTERNAL_STORAGE);
|
||||
if (permission != PackageManager.PERMISSION_GRANTED) {
|
||||
ActivityCompat.requestPermissions(this, Daedalus.PERMISSIONS_STORAGE, Daedalus.REQUEST_EXTERNAL_STORAGE);
|
||||
}
|
||||
HostsResolver.startLoad(getExternalFilesDir(null).getPath() + "/hosts");
|
||||
}
|
||||
getExternalFilesDir(null);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions, @NonNull int[] grantResults) {
|
||||
super.onRequestPermissionsResult(requestCode, permissions, grantResults);
|
||||
switch (requestCode) {
|
||||
case Daedalus.REQUEST_EXTERNAL_STORAGE:
|
||||
if (grantResults[0] != PackageManager.PERMISSION_GRANTED) {
|
||||
Snackbar.make(findViewById(R.id.id_content), R.string.notice_need_storage_perm, Snackbar.LENGTH_LONG)
|
||||
.setAction("Action", null).show();
|
||||
}
|
||||
break;
|
||||
default:
|
||||
super.onRequestPermissionsResult(requestCode, permissions, grantResults);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -141,6 +141,8 @@ public class MainActivity extends AppCompatActivity implements NavigationView.On
|
||||
|
||||
updateTitle();
|
||||
updateNavigationMenu();
|
||||
|
||||
checkStorage();
|
||||
}
|
||||
|
||||
private void updateNavigationMenu() {
|
||||
|
@ -11,7 +11,6 @@ import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import org.itxtech.daedalus.Daedalus;
|
||||
import org.itxtech.daedalus.R;
|
||||
import org.itxtech.daedalus.activity.MainActivity;
|
||||
import org.itxtech.daedalus.util.DnsServer;
|
||||
|
||||
/**
|
||||
@ -84,12 +83,21 @@ public class SettingsFragment extends PreferenceFragment {
|
||||
}
|
||||
});
|
||||
|
||||
SwitchPreference localHosts = (SwitchPreference) findPreference("settings_local_host_resolve");
|
||||
localHosts.setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener() {
|
||||
ListPreference checkUpdate = (ListPreference) findPreference("settings_check_update");
|
||||
checkUpdate.setOnPreferenceClickListener(new Preference.OnPreferenceClickListener() {
|
||||
@Override
|
||||
public boolean onPreferenceChange(Preference preference, Object newValue) {
|
||||
MainActivity.getInstance().initHostsResolver();
|
||||
return true;
|
||||
public boolean onPreferenceClick(Preference preference) {
|
||||
startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse("https://github.com/iTXTech/Daedalus/releases")));
|
||||
return false;
|
||||
}
|
||||
});
|
||||
|
||||
ListPreference issueTracker = (ListPreference) findPreference("settings_issue_tracker");
|
||||
issueTracker.setOnPreferenceClickListener(new Preference.OnPreferenceClickListener() {
|
||||
@Override
|
||||
public boolean onPreferenceClick(Preference preference) {
|
||||
startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse("https://github.com/iTXTech/Daedalus/issues")));
|
||||
return false;
|
||||
}
|
||||
});
|
||||
|
||||
@ -114,25 +122,6 @@ public class SettingsFragment extends PreferenceFragment {
|
||||
@Override
|
||||
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
|
||||
view = super.onCreateView(inflater, container, savedInstanceState);
|
||||
|
||||
ListPreference checkUpdate = (ListPreference) findPreference("settings_check_update");
|
||||
checkUpdate.setOnPreferenceClickListener(new Preference.OnPreferenceClickListener() {
|
||||
@Override
|
||||
public boolean onPreferenceClick(Preference preference) {
|
||||
startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse("https://github.com/iTXTech/Daedalus/releases")));
|
||||
return false;
|
||||
}
|
||||
});
|
||||
|
||||
ListPreference issueTracker = (ListPreference) findPreference("settings_issue_tracker");
|
||||
issueTracker.setOnPreferenceClickListener(new Preference.OnPreferenceClickListener() {
|
||||
@Override
|
||||
public boolean onPreferenceClick(Preference preference) {
|
||||
startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse("https://github.com/iTXTech/Daedalus/issues")));
|
||||
return false;
|
||||
}
|
||||
});
|
||||
|
||||
return view;
|
||||
}
|
||||
|
||||
|
@ -1,18 +1,13 @@
|
||||
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
|
||||
@ -28,17 +23,6 @@ public class BootBroadcastReceiver extends BroadcastReceiver {
|
||||
@Override
|
||||
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);
|
||||
|
@ -9,7 +9,6 @@ import android.content.Intent;
|
||||
import android.net.VpnService;
|
||||
import android.os.Build;
|
||||
import android.os.ParcelFileDescriptor;
|
||||
import android.preference.PreferenceManager;
|
||||
import android.support.v7.app.NotificationCompat;
|
||||
import android.system.ErrnoException;
|
||||
import android.system.Os;
|
||||
@ -90,7 +89,7 @@ public class DaedalusVpnService extends VpnService implements Runnable {
|
||||
if (intent != null) {
|
||||
switch (intent.getAction()) {
|
||||
case ACTION_ACTIVATE:
|
||||
if (PreferenceManager.getDefaultSharedPreferences(this).getBoolean("settings_notification", true)) {
|
||||
if (Daedalus.getPrefs().getBoolean("settings_notification", true)) {
|
||||
|
||||
NotificationManager manager = (NotificationManager) this.getSystemService(Context.NOTIFICATION_SERVICE);
|
||||
|
||||
@ -120,6 +119,8 @@ public class DaedalusVpnService extends VpnService implements Runnable {
|
||||
DaedalusVpnService.notification = builder;
|
||||
}
|
||||
|
||||
Daedalus.initHostsResolver();
|
||||
|
||||
dnsQueryTimes = 0;
|
||||
if (this.mThread == null) {
|
||||
this.mThread = new Thread(this, "DaedalusVpn");
|
||||
|
@ -46,6 +46,7 @@
|
||||
<string name="nav_github">GitHub</string>
|
||||
<string name="settings_advanced">高级系统设置</string>
|
||||
<string name="settings_advanced_on">开启</string>
|
||||
<string name="settings_local_hosts_resolve">本地 hosts 解析 (TODO)</string>
|
||||
<string name="settings_local_hosts_resolve">本地 hosts 解析</string>
|
||||
<string name="notice_need_restart">重新启用 Daedalus 以应用设置。</string>
|
||||
<string name="notice_need_storage_perm">本应用需要访问外部储存以实现本地 hosts 解析。</string>
|
||||
</resources>
|
@ -45,6 +45,9 @@
|
||||
<string name="nav_github">GitHub</string>
|
||||
<string name="settings_advanced">Advanced system settings</string>
|
||||
<string name="settings_advanced_on">On</string>
|
||||
<string name="settings_local_hosts_resolve">Local hosts resolve (TODO)</string>
|
||||
<string name="settings_local_hosts_resolve">Local hosts resolution</string>
|
||||
<string name="notice_need_restart">Re-activate Daedalus to make the settings take effect.</string>
|
||||
<string name="notice_need_storage_perm">This application requires access to external storage for local host
|
||||
resolution.
|
||||
</string>
|
||||
</resources>
|
||||
|
Loading…
x
Reference in New Issue
Block a user