-
Notifications
You must be signed in to change notification settings - Fork 4
/
tmp
155 lines (145 loc) · 7.12 KB
/
tmp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
private void setupXmlEncrypt() {
if (!Settings.getRootAccess()) {
enXmlM_en.setEnabled(false);
}
enXmlM_rg.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener() {
@Override
public void onCheckedChanged(RadioGroup radioGroup, int i) {
switch (i) {
case R.id.xml_encrypt_rb_need_sn:
enXmlM_arg.setVisibility(View.VISIBLE);
break;
case R.id.xml_encrypt_rb_noneed_sn:
enXmlM_arg.setVisibility(View.GONE);
break;
}
}
});
enXmlM_key_random.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
enXmlM_key.setText(RandomUtils.getAlphaNumericString(16));
}
});
enXmlM_en.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
// 16 length key is necessary
if (enXmlM_key.getText().toString().length()<16){
enXmlM_log.append("Key must length 16 or longer\n");
return;
}
//do en xml
if (enXmlM_path.getText().toString().isEmpty()) {
enXmlM_log.append("Path is must\n");
return;
}
String path=enXmlM_path.getText().toString();
String key = enXmlM_key.getText().toString();
Log.d(TAG.XML_MANAGER_TAG, "d1");
boolean sn_isChecked=enXmlM_NeedSn.isChecked();
String sn=enXmlM_arg.getText().toString();
new Thread(new Runnable() {
@Override
public void run() {
String en_xml="";
String orig_xml=FileUtils.forceReadFileWithRoot(getActivity(),path);
Log.d(TAG.XML_MANAGER_TAG, "d2");
if (orig_xml.isEmpty()) {
getActivity().runOnUiThread(new Runnable() {
@Override
public void run() {
enXmlM_log.append("Error read xml");
}
});
return;
}
//no need sn
if (!sn_isChecked){
en_xml=XmlProcessor.encryptXml(orig_xml
,
key,
0,""
);
Log.d(TAG.XML_MANAGER_TAG, "d3");
}else{
//need sn
if (sn.isEmpty()) {
getActivity().runOnUiThread(new Runnable() {
@Override
public void run() {
enXmlM_log.append("Please enter sn\n");
}
});
return;
}
en_xml = XmlProcessor.encryptXml(orig_xml, key, 1, sn);
Log.d(TAG.XML_MANAGER_TAG, "d4");
}
if (en_xml == null || en_xml.isEmpty()) {
getActivity().runOnUiThread(new Runnable() {
@Override
public void run() {
enXmlM_log.append("Error encrypt xml\n");
}
});
return;
}
String new_path = path.replaceAll(".xml", ".enXmlM");
FileUtils.forceWriteToFileWithRoot(getActivity(), en_xml, new_path, new FileForceWriteListener() {
@Override
public void onWriteFailed(String resaon) {
getActivity().runOnUiThread(new Runnable() {
@Override
public void run() {
enXmlM_en.setEnabled(true);
enXmlM_log.append("Failed:"+resaon+"\n");
}
});
}
@Override
public void onWriteSuccess() {
getActivity().runOnUiThread(new Runnable() {
@Override
public void run() {
enXmlM_en.setEnabled(true);
enXmlM_log.append("Success:"+new_path+"\n");
enXmlM_log.append("WARNING:Your key is updated to clipboard!!! You are now must share this updated key!!!\n");
if (sn_isChecked) {
ClipboardUtil.copyToClipboard(getContext(),"1"+key);
return;
}
ClipboardUtil.copyToClipboard(getContext(),"0"+key);
}
});
}
});
}
}).start();
}
});
enXmlM_openfile_bt.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
//如果没有权限会自动申请权限
PathSelector.build(getActivity(), MConstants.BUILD_DIALOG)//Dialog构建方式
.setSelectFileTypes("xml")
.setShowFileTypes("xml","enXmlM")
.setRadio()
.setTitlebarMainTitle(new FontBean("Choose Xml"))
.setAlwaysShowHandleFragment(false)
.setFileItemListener(//设置文件item点击回调(点击是文件才会回调,如果点击是文件夹则不会)
new FileItemListener() {
@Override
public boolean onClick(View v, FileBean file, String currentPath, BasePathSelectFragment pathSelectFragment) {
Mtools.toast(file.getPath());
enXmlM_path.setText(file.getPath());
pathSelectFragment.close();
return false;
}
}
)
.show();//开始构建
}
});
}