Ready for release

This commit is contained in:
topjohnwu
2016-09-29 23:24:31 +08:00
parent 692b993eee
commit e4cba70008
30 changed files with 541 additions and 414 deletions

View File

@@ -90,10 +90,7 @@ public class LogFragment extends Fragment {
reloadErrorLog();
return true;
case R.id.menu_send:
try {
send();
} catch (NullPointerException ignored) {
}
send();
return true;
case R.id.menu_save:
save();
@@ -117,11 +114,23 @@ public class LogFragment extends Fragment {
}
private void send() {
Intent sendIntent = new Intent();
sendIntent.setAction(Intent.ACTION_SEND);
sendIntent.putExtra(Intent.EXTRA_STREAM, Uri.fromFile(save()));
sendIntent.setType("application/html");
startActivity(Intent.createChooser(sendIntent, getResources().getString(R.string.menuSend)));
new SaveLog() {
@Override
protected void onPostExecute(Boolean bool) {
super.onPostExecute(bool);
if (bool) {
Intent sendIntent = new Intent();
sendIntent.setAction(Intent.ACTION_SEND);
sendIntent.putExtra(Intent.EXTRA_STREAM, Uri.fromFile(targetFile));
sendIntent.setType("application/html");
startActivity(Intent.createChooser(sendIntent, getResources().getString(R.string.menuSend)));
} else {
Toast.makeText(getActivity(), getString(R.string.logs_save_failed), Toast.LENGTH_LONG).show();
}
}
}.executeOnExecutor(AsyncTask.SERIAL_EXECUTOR);
}
@Override
@@ -138,45 +147,66 @@ public class LogFragment extends Fragment {
}
}
@SuppressLint("DefaultLocale")
private File save() {
if (ActivityCompat.checkSelfPermission(getActivity(), Manifest.permission.WRITE_EXTERNAL_STORAGE) != PackageManager.PERMISSION_GRANTED) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
requestPermissions(new String[]{Manifest.permission.WRITE_EXTERNAL_STORAGE}, 0);
private void save() {
new SaveLog(){
@Override
protected void onPostExecute(Boolean bool) {
super.onPostExecute(bool);
if (bool) {
Toast.makeText(getActivity(), targetFile.toString(), Toast.LENGTH_LONG).show();
} else {
Toast.makeText(getActivity(), getString(R.string.logs_save_failed), Toast.LENGTH_LONG).show();
}
}
return null;
}
}.executeOnExecutor(AsyncTask.SERIAL_EXECUTOR);
}
if (!Environment.getExternalStorageState().equals(Environment.MEDIA_MOUNTED)) {
Snackbar.make(txtLog, R.string.sdcard_not_writable, Snackbar.LENGTH_LONG).show();
return null;
}
private class SaveLog extends AsyncTask<Void, Void, Boolean> {
Calendar now = Calendar.getInstance();
String filename = String.format(
"magisk_%s_%04d%02d%02d_%02d%02d%02d.log", "error",
now.get(Calendar.YEAR), now.get(Calendar.MONTH) + 1,
now.get(Calendar.DAY_OF_MONTH), now.get(Calendar.HOUR_OF_DAY),
now.get(Calendar.MINUTE), now.get(Calendar.SECOND));
File targetFile;
File dir = new File(Environment.getExternalStorageDirectory().getAbsolutePath() + "/Magisk/");
dir.mkdir();
File targetFile = new File(dir, filename);
List<String> in = Utils.readFile(MAGISK_LOG);
try {
FileWriter out = new FileWriter(targetFile);
for (String line : in) {
out.write(line + "\n");
@SuppressLint("DefaultLocale")
@Override
protected Boolean doInBackground(Void... voids) {
if (ActivityCompat.checkSelfPermission(getActivity(), Manifest.permission.WRITE_EXTERNAL_STORAGE) != PackageManager.PERMISSION_GRANTED) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
requestPermissions(new String[]{Manifest.permission.WRITE_EXTERNAL_STORAGE}, 0);
}
return false;
}
out.close();
Toast.makeText(getActivity(), targetFile.toString(), Toast.LENGTH_LONG).show();
return targetFile;
} catch (IOException e) {
Toast.makeText(getActivity(), getResources().getString(R.string.logs_save_failed) + "\n" + e.getMessage(), Toast.LENGTH_LONG).show();
return null;
if (!Environment.getExternalStorageState().equals(Environment.MEDIA_MOUNTED)) {
return false;
}
Calendar now = Calendar.getInstance();
String filename = String.format(
"magisk_%s_%04d%02d%02d_%02d%02d%02d.log", "error",
now.get(Calendar.YEAR), now.get(Calendar.MONTH) + 1,
now.get(Calendar.DAY_OF_MONTH), now.get(Calendar.HOUR_OF_DAY),
now.get(Calendar.MINUTE), now.get(Calendar.SECOND));
targetFile = new File(Environment.getExternalStorageDirectory().getAbsolutePath() + "/MagiskManager/" + filename);
if ((!targetFile.getParentFile().exists() && !targetFile.getParentFile().mkdirs()) || (targetFile.exists() && !targetFile.delete())) {
return false;
}
List<String> in = Utils.readFile(MAGISK_LOG);
try {
FileWriter out = new FileWriter(targetFile);
for (String line : in) {
out.write(line + "\n");
}
out.close();
return true;
} catch (IOException e) {
e.printStackTrace();
return false;
}
}
}