diff options
author | Scott Jackson <daneren2005@gmail.com> | 2016-01-15 17:22:45 -0800 |
---|---|---|
committer | Scott Jackson <daneren2005@gmail.com> | 2016-01-15 17:22:45 -0800 |
commit | ac690bf6ecea345aa77e2d71355542d000aba9b7 (patch) | |
tree | a0b469668d1c4b22f9ab1433bee5d68bbad4d6c7 | |
parent | 1a017dd3dc248ddf6096bc05be12a6faa1a7bb82 (diff) | |
download | dsub-ac690bf6ecea345aa77e2d71355542d000aba9b7.tar.gz dsub-ac690bf6ecea345aa77e2d71355542d000aba9b7.tar.bz2 dsub-ac690bf6ecea345aa77e2d71355542d000aba9b7.zip |
#588 Post logs to Pastebin
-rw-r--r-- | app/src/main/java/github/daneren2005/dsub/fragments/MainFragment.java | 95 | ||||
-rw-r--r-- | app/src/main/java/github/daneren2005/dsub/util/EnvironmentVariables.java | 20 |
2 files changed, 104 insertions, 11 deletions
diff --git a/app/src/main/java/github/daneren2005/dsub/fragments/MainFragment.java b/app/src/main/java/github/daneren2005/dsub/fragments/MainFragment.java index 5daf3d7a..f048587b 100644 --- a/app/src/main/java/github/daneren2005/dsub/fragments/MainFragment.java +++ b/app/src/main/java/github/daneren2005/dsub/fragments/MainFragment.java @@ -1,11 +1,11 @@ package github.daneren2005.dsub.fragments; -import android.content.res.Resources; -import android.os.Environment; import android.content.Intent; -import android.content.SharedPreferences; +import android.content.res.Resources; import android.net.Uri; import android.os.Build; +import android.os.Environment; +import android.content.SharedPreferences; import android.os.Bundle; import android.os.StatFs; import android.util.Log; @@ -18,6 +18,7 @@ import github.daneren2005.dsub.adapter.MainAdapter; import github.daneren2005.dsub.adapter.SectionAdapter; import github.daneren2005.dsub.domain.ServerInfo; import github.daneren2005.dsub.util.Constants; +import github.daneren2005.dsub.util.EnvironmentVariables; import github.daneren2005.dsub.util.FileUtil; import github.daneren2005.dsub.util.LoadingTask; import github.daneren2005.dsub.util.ProgressListener; @@ -28,11 +29,21 @@ import github.daneren2005.dsub.service.MusicServiceFactory; import github.daneren2005.dsub.view.ChangeLog; import github.daneren2005.dsub.view.UpdateView; +import java.io.BufferedReader; +import java.io.BufferedWriter; import java.io.File; +import java.io.FileInputStream; +import java.io.InputStreamReader; +import java.io.OutputStream; +import java.io.OutputStreamWriter; +import java.net.URL; +import java.net.URLEncoder; import java.util.ArrayList; import java.util.Arrays; import java.util.List; +import javax.net.ssl.HttpsURLConnection; + public class MainFragment extends SelectRecyclerFragment<Integer> { private static final String TAG = MainFragment.class.getSimpleName(); @@ -238,9 +249,9 @@ public class MainFragment extends SelectRecyclerFragment<Integer> { private void getLogs() { try { final String version = context.getPackageManager().getPackageInfo(context.getPackageName(), 0).versionName; - new LoadingTask<File>(context) { + new LoadingTask<String>(context) { @Override - protected File doInBackground() throws Throwable { + protected String doInBackground() throws Throwable { updateProgress("Gathering Logs"); File logcat = new File(Environment.getExternalStorageDirectory(), "dsub-logcat.txt"); Util.delete(logcat); @@ -258,30 +269,92 @@ public class MainFragment extends SelectRecyclerFragment<Integer> { logcatProc = Runtime.getRuntime().exec(progs.toArray(new String[progs.size()])); logcatProc.waitFor(); - } catch(Exception e) { - Util.toast(context, "Failed to gather logs"); } finally { if(logcatProc != null) { logcatProc.destroy(); } } - return logcat; + URL url = new URL("https://pastebin.com/api/api_post.php"); + HttpsURLConnection urlConnection = (HttpsURLConnection) url.openConnection(); + try { + urlConnection.setReadTimeout(10000); + urlConnection.setConnectTimeout(15000); + urlConnection.setRequestMethod("POST"); + urlConnection.setDoInput(true); + urlConnection.setDoOutput(true); + + OutputStream os = urlConnection.getOutputStream(); + BufferedWriter writer = new BufferedWriter(new OutputStreamWriter(os, Constants.UTF_8)); + writer.write("api_dev_key=" + URLEncoder.encode(EnvironmentVariables.PASTEBIN_DEV_KEY, Constants.UTF_8) + "&api_option=paste&api_paste_private=1&api_paste_code="); + + BufferedReader reader = null; + try { + reader = new BufferedReader(new InputStreamReader(new FileInputStream(logcat))); + String line; + while ((line = reader.readLine()) != null) { + writer.write(URLEncoder.encode(line + "\n", Constants.UTF_8)); + } + } finally { + Util.close(reader); + } + + File stacktrace = new File(Environment.getExternalStorageDirectory(), "dsub-stacktrace.txt"); + if(stacktrace.exists() && stacktrace.isFile()) { + writer.write("\n\nMost Recent Stacktrace:\n\n"); + + reader = null; + try { + reader = new BufferedReader(new InputStreamReader(new FileInputStream(stacktrace))); + String line; + while ((line = reader.readLine()) != null) { + writer.write(URLEncoder.encode(line + "\n", Constants.UTF_8)); + } + } finally { + Util.close(reader); + } + } + + writer.flush(); + writer.close(); + os.close(); + } finally { + urlConnection.disconnect(); + } + + BufferedReader in = new BufferedReader(new InputStreamReader(urlConnection.getInputStream())); + String inputLine; + StringBuffer responseBuffer = new StringBuffer(); + while ((inputLine = in.readLine()) != null) { + responseBuffer.append(inputLine); + } + in.close(); + + String response = responseBuffer.toString(); + if(response.indexOf("http") == 0) { + return response.replace("http:", "https:"); + } else { + throw new Exception("Pastebin Error: " + response); + } + } + + @Override + protected void error(Throwable error) { + Util.toast(context, "Failed to gather logs"); } @Override - protected void done(File logcat) { + protected void done(String logcat) { String footer = "Android SDK: " + Build.VERSION.SDK; footer += "\nDevice Model: " + Build.MODEL; footer += "\nDevice Name: " + Build.MANUFACTURER + " " + Build.PRODUCT; footer += "\nROM: " + Build.DISPLAY; + footer += "\nLogs: " + logcat; Intent email = new Intent(Intent.ACTION_SENDTO, Uri.fromParts("mailto", "dsub.android@gmail.com", null)); email.putExtra(Intent.EXTRA_SUBJECT, "DSub " + version + " Error Logs"); email.putExtra(Intent.EXTRA_TEXT, "Describe the problem here\n\n\n" + footer); - Uri attachment = Uri.fromFile(logcat); - email.putExtra(Intent.EXTRA_STREAM, attachment); startActivity(email); } }.execute(); diff --git a/app/src/main/java/github/daneren2005/dsub/util/EnvironmentVariables.java b/app/src/main/java/github/daneren2005/dsub/util/EnvironmentVariables.java new file mode 100644 index 00000000..d8046d1b --- /dev/null +++ b/app/src/main/java/github/daneren2005/dsub/util/EnvironmentVariables.java @@ -0,0 +1,20 @@ +/* + This file is part of Subsonic. + Subsonic is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + Subsonic is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + You should have received a copy of the GNU General Public License + along with Subsonic. If not, see <http://www.gnu.org/licenses/>. + Copyright 2016 (C) Scott Jackson +*/ + +package github.daneren2005.dsub.util; + +public final class EnvironmentVariables { + public static final String PASTEBIN_DEV_KEY = ""; +} |