clashMap = new HashMap<>();
23 | String[] text;
24 | String[] hosts;
25 | String arrayString[];
26 | File file = context.getCacheDir();
27 | final String CACHE_PATH = file.getAbsolutePath();
28 | try {
29 |
30 | BufferedReader in;
31 | in = new BufferedReader(new FileReader(CACHE_PATH + Consistent.CLASH_FILE));
32 | String lineText;
33 | int count = 0;
34 | while ((in.readLine()) != null) {
35 | count++;
36 | }
37 | text = new String[count];
38 | hosts = new String[count];
39 |
40 | count = 0;
41 | in.close();
42 | in = new BufferedReader(new FileReader(CACHE_PATH + Consistent.CLASH_FILE));
43 | while ((lineText = in.readLine()) != null) {
44 |
45 | arrayString = lineText.split(CLASH_SPLIT);
46 | text[count] = arrayString[0].replace(";", "\n");
47 | hosts[count] = arrayString[1].replace(";", "\n");
48 | count++;
49 |
50 |
51 | }
52 | in.close();
53 | clashMap.put(text, hosts);
54 |
55 | } catch (Exception e) {
56 | e.printStackTrace();
57 | }
58 |
59 |
60 | return clashMap;
61 |
62 | }
63 | }
64 |
65 |
--------------------------------------------------------------------------------
/code/V7.00/app/src/main/java/com/lack006/hosts_l/Consistent/ConsistentHtml.java:
--------------------------------------------------------------------------------
1 | package com.lack006.hosts_l.Consistent;
2 |
3 | /**
4 | * Created by lack on 2016/12/11.
5 | * AndroidHosts-LV7
6 | */
7 |
8 | public class ConsistentHtml {
9 | public final static String EXPLANATION_HTML = "\n" +
10 | "\u3000\u3000这是一个以修改 Android 手机内置 hosts 文件为主功能,集“快速替换重定向 IP”、 “去除网络图标符号”、“激活谷歌位置报告”和“自动修改 DNS 服务器”等子功能于一体的软件。\n" +
11 | "
\n" +
12 | "\n" +
13 | "\u3000\u3000本软件包含一个“广播接收器”(用于“激活谷歌位置报告”)与两个“服务”(用于“自动修改 DNS 服务器”),若希望正常使用以上两个功能请不要禁用他们。\n" +
14 | "
\n" +
15 | "\n" +
16 | "开源地址:Github\n" +
17 | "
\n" +
18 | "\n" +
19 | "代码参考:\n" +
20 | "
\n" +
21 | "\n" +
22 | "LocationReportEnabler\n" +
23 | "
\n" +
24 | "\n" +
25 | "关于 android 5.0 网络图标上的感叹号及其解决办法\n" +
26 | "
\n" +
27 | "\n" +
28 | "DNSSetter\n" +
29 | "
\n" +
30 | "\n" +
31 | "第三方库:libsuperuser\n" +
32 | "
\n" +
33 | "\n" +
34 | "Open Source Licenses:GPL V3\n" +
35 | "
";
36 | }
37 |
--------------------------------------------------------------------------------
/code/V7.00/app/src/main/java/com/lack006/hosts_l/Copy/CopyHelper.java:
--------------------------------------------------------------------------------
1 | package com.lack006.hosts_l.Copy;
2 |
3 | import java.io.File;
4 | import java.io.FileInputStream;
5 | import java.io.FileOutputStream;
6 | import java.io.InputStream;
7 |
8 | /**
9 | * Created by lack on 2016/12/7.
10 | * AndroidHosts-LV7
11 | */
12 |
13 | public class CopyHelper {
14 | public boolean copyFile(String oldPath, String newPath) {
15 | boolean completeFlag = false;
16 | try {
17 | int byteRead;
18 | File oldFile = new File(oldPath);
19 | if (oldFile.exists()) { //文件存在时
20 | InputStream inStream = new FileInputStream(oldPath); //读入原文件
21 | FileOutputStream fs = new FileOutputStream(newPath);
22 | byte[] buffer = new byte[1024];
23 | while ((byteRead = inStream.read(buffer)) != -1) {
24 | fs.write(buffer, 0, byteRead);
25 | }
26 | fs.flush();
27 | fs.close();
28 | inStream.close();
29 | completeFlag = true;
30 | }
31 | } catch (Exception e) {
32 | e.printStackTrace();
33 | }
34 | return completeFlag;
35 |
36 | }
37 | }
38 |
--------------------------------------------------------------------------------
/code/V7.00/app/src/main/java/com/lack006/hosts_l/DNS/ChangeDNSReceiver.java:
--------------------------------------------------------------------------------
1 | package com.lack006.hosts_l.DNS;
2 |
3 | import android.content.BroadcastReceiver;
4 | import android.content.Context;
5 | import android.content.Intent;
6 | import android.net.ConnectivityManager;
7 | import android.net.NetworkInfo;
8 |
9 | /**
10 | * Created by lack on 2016/12/10.
11 | * AndroidHosts-LV7
12 | */
13 |
14 | public class ChangeDNSReceiver extends BroadcastReceiver {
15 | @Override
16 | public void onReceive(Context context, Intent intent) {
17 |
18 | ConnectivityManager connectivityManager = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
19 |
20 | NetworkInfo mActiveNetInfo = connectivityManager.getActiveNetworkInfo();
21 | if (mActiveNetInfo != null) {
22 | Intent startIntent = new Intent(context, DNSShellService.class);
23 | context.startService(startIntent);
24 | }
25 |
26 |
27 | }
28 |
29 |
30 | }
31 |
32 |
--------------------------------------------------------------------------------
/code/V7.00/app/src/main/java/com/lack006/hosts_l/DNS/ChangeDNSService.java:
--------------------------------------------------------------------------------
1 | package com.lack006.hosts_l.DNS;
2 |
3 | import android.app.Service;
4 | import android.content.Intent;
5 | import android.content.IntentFilter;
6 | import android.os.IBinder;
7 |
8 | import com.lack006.hosts_l.Consistent.Consistent;
9 |
10 | /**
11 | * Created by lack on 2016/12/10.
12 | * AndroidHosts-LV7
13 | */
14 |
15 | public class ChangeDNSService extends Service {
16 | private ChangeDNSReceiver mChangeDNSReceiver;
17 |
18 | @Override
19 | public void onCreate() {
20 | super.onCreate();
21 | }
22 |
23 | @Override
24 | public int onStartCommand(Intent intent, int flags, int startId) {
25 | IntentFilter intentFilter;
26 | intentFilter = new IntentFilter();
27 | intentFilter.addAction(Consistent.NETWORK_CONNECT_CHANGE_ACTION);
28 | intentFilter.setPriority(Integer.MAX_VALUE);
29 | mChangeDNSReceiver = new ChangeDNSReceiver();
30 | registerReceiver(mChangeDNSReceiver, intentFilter);
31 |
32 |
33 | return super.onStartCommand(intent, flags, startId);
34 | }
35 |
36 |
37 | @Override
38 | public IBinder onBind(Intent intent) {
39 | return null;
40 | }
41 |
42 |
43 | @Override
44 | public void onDestroy() {
45 | IntentFilter intentFilter;
46 | intentFilter = new IntentFilter();
47 | intentFilter.addAction(Consistent.NETWORK_CONNECT_CHANGE_ACTION);
48 | intentFilter.setPriority(Integer.MAX_VALUE);
49 |
50 | try {
51 | unregisterReceiver(mChangeDNSReceiver);
52 | } catch (Exception ignored) {
53 |
54 | }
55 |
56 | super.onDestroy();
57 | }
58 | }
59 |
--------------------------------------------------------------------------------
/code/V7.00/app/src/main/java/com/lack006/hosts_l/DNS/DNSShellService.java:
--------------------------------------------------------------------------------
1 | package com.lack006.hosts_l.DNS;
2 |
3 | import android.app.Service;
4 | import android.content.Context;
5 | import android.content.Intent;
6 | import android.os.AsyncTask;
7 | import android.os.IBinder;
8 |
9 | /**
10 | * Created by lack on 2016/12/11.
11 | * AndroidHosts-LV7
12 | */
13 |
14 | public class DNSShellService extends Service {
15 | private Context mContext = null;
16 |
17 | @Override
18 | public void onCreate() {
19 | super.onCreate();
20 | DNSShellTask dnsShellTask = new DNSShellTask();
21 | dnsShellTask.execute();
22 | mContext = this;
23 |
24 | }
25 |
26 | @Override
27 | public int onStartCommand(Intent intent, int flags, int startId) {
28 |
29 | return super.onStartCommand(intent, flags, startId);
30 | }
31 |
32 | @Override
33 | public IBinder onBind(Intent intent) {
34 | return null;
35 | }
36 |
37 | @Override
38 | public void onDestroy() {
39 | super.onDestroy();
40 | }
41 |
42 | private class DNSShellTask extends AsyncTask