Cleanup
This commit is contained in:
parent
9b4cc35aa3
commit
50676b6079
|
@ -41,8 +41,6 @@ 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();
|
||||
public static final String SONGS_LIST_PREFIX = "songs-";
|
||||
|
@ -187,123 +185,6 @@ public class MainFragment extends SelectRecyclerFragment<Integer> {
|
|||
}.execute();
|
||||
}
|
||||
|
||||
private void getLogs() {
|
||||
try {
|
||||
final PackageInfo packageInfo = context.getPackageManager().getPackageInfo(context.getPackageName(), 0);
|
||||
new LoadingTask<String>(context) {
|
||||
@Override
|
||||
protected String doInBackground() throws Throwable {
|
||||
updateProgress("Gathering Logs");
|
||||
File logcat = new File(Environment.getExternalStorageDirectory(), "audinaut-logcat.txt");
|
||||
Util.delete(logcat);
|
||||
Process logcatProc = null;
|
||||
|
||||
try {
|
||||
List<String> progs = new ArrayList<String>();
|
||||
progs.add("logcat");
|
||||
progs.add("-v");
|
||||
progs.add("time");
|
||||
progs.add("-d");
|
||||
progs.add("-f");
|
||||
progs.add(logcat.getCanonicalPath());
|
||||
progs.add("*:I");
|
||||
|
||||
logcatProc = Runtime.getRuntime().exec(progs.toArray(new String[progs.size()]));
|
||||
logcatProc.waitFor();
|
||||
} finally {
|
||||
if(logcatProc != null) {
|
||||
logcatProc.destroy();
|
||||
}
|
||||
}
|
||||
|
||||
URL url = new URL("https://pastebin.com/api/api_post.php");
|
||||
HttpsURLConnection urlConnection = (HttpsURLConnection) url.openConnection();
|
||||
StringBuffer responseBuffer = new StringBuffer();
|
||||
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(), "audinaut-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();
|
||||
|
||||
BufferedReader in = new BufferedReader(new InputStreamReader(urlConnection.getInputStream()));
|
||||
String inputLine;
|
||||
while ((inputLine = in.readLine()) != null) {
|
||||
responseBuffer.append(inputLine);
|
||||
}
|
||||
in.close();
|
||||
} finally {
|
||||
urlConnection.disconnect();
|
||||
}
|
||||
|
||||
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) {
|
||||
Log.e(TAG, "Failed to gather logs", error);
|
||||
Util.toast(context, "Failed to gather logs");
|
||||
}
|
||||
|
||||
@Override
|
||||
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;
|
||||
footer += "\nBuild Number: " + packageInfo.versionCode;
|
||||
|
||||
Intent email = new Intent(Intent.ACTION_SENDTO,
|
||||
Uri.fromParts("mailto", "ar@nullsum.net", null));
|
||||
email.putExtra(Intent.EXTRA_SUBJECT, "Audinaut " + packageInfo.versionName + " Error Logs");
|
||||
email.putExtra(Intent.EXTRA_TEXT, "Describe the problem here\n\n\n" + footer);
|
||||
startActivity(email);
|
||||
}
|
||||
}.execute();
|
||||
} catch(Exception e) {}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onItemClicked(UpdateView<Integer> updateView, Integer item) {
|
||||
if (item == R.string.main_albums_random) {
|
||||
|
|
|
@ -596,11 +596,6 @@ public class CachedMusicService implements MusicService {
|
|||
return musicService.getRandomSongs(size, folder, genre, startYear, endYear, context, progressListener);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getCoverArtUrl(Context context, Entry entry) throws Exception {
|
||||
return musicService.getCoverArtUrl(context, entry);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Bitmap getCoverArt(Context context, Entry entry, int size, ProgressListener progressListener, SilentBackgroundTask task) throws Exception {
|
||||
return musicService.getCoverArt(context, entry, size, progressListener, task);
|
||||
|
@ -611,11 +606,6 @@ public class CachedMusicService implements MusicService {
|
|||
return musicService.getDownloadInputStream(context, song, offset, maxBitrate, task);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getMusicUrl(Context context, Entry song, int maxBitrate) throws Exception {
|
||||
return musicService.getMusicUrl(context, song, maxBitrate);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<Genre> getGenres(boolean refresh, Context context, ProgressListener progressListener) throws Exception {
|
||||
List<Genre> result = null;
|
||||
|
|
|
@ -83,14 +83,10 @@ public interface MusicService {
|
|||
MusicDirectory getRandomSongs(int size, String artistId, Context context, ProgressListener progressListener) throws Exception;
|
||||
MusicDirectory getRandomSongs(int size, String folder, String genre, String startYear, String endYear, Context context, ProgressListener progressListener) throws Exception;
|
||||
|
||||
String getCoverArtUrl(Context context, MusicDirectory.Entry entry) throws Exception;
|
||||
|
||||
Bitmap getCoverArt(Context context, MusicDirectory.Entry entry, int size, ProgressListener progressListener, SilentBackgroundTask task) throws Exception;
|
||||
|
||||
Response getDownloadInputStream(Context context, MusicDirectory.Entry song, long offset, int maxBitrate, SilentBackgroundTask task) throws Exception;
|
||||
|
||||
String getMusicUrl(Context context, MusicDirectory.Entry song, int maxBitrate) throws Exception;
|
||||
|
||||
List<Genre> getGenres(boolean refresh, Context context, ProgressListener progressListener) throws Exception;
|
||||
|
||||
MusicDirectory getSongsByGenre(String genre, int count, int offset, Context context, ProgressListener progressListener) throws Exception;
|
||||
|
|
|
@ -210,11 +210,6 @@ public class OfflineMusicService implements MusicService {
|
|||
throw new OfflineException(ERRORMSG);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getMusicUrl(Context context, Entry song, int maxBitrate) throws Exception {
|
||||
throw new OfflineException(ERRORMSG);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<MusicFolder> getMusicFolders(boolean refresh, Context context, ProgressListener progressListener) throws Exception {
|
||||
throw new OfflineException(ERRORMSG);
|
||||
|
@ -556,11 +551,6 @@ public class OfflineMusicService implements MusicService {
|
|||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getCoverArtUrl(Context context, Entry entry) throws Exception {
|
||||
throw new OfflineException(ERRORMSG);
|
||||
}
|
||||
|
||||
@Override
|
||||
public User getUser(boolean refresh, String username, Context context, ProgressListener progressListener) throws Exception {
|
||||
throw new OfflineException(ERRORMSG);
|
||||
|
|
|
@ -19,19 +19,9 @@
|
|||
package net.nullsum.audinaut.service;
|
||||
|
||||
import java.io.FileOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.io.InputStreamReader;
|
||||
import java.io.OutputStream;
|
||||
import java.io.Reader;
|
||||
import java.net.URLEncoder;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collections;
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
import java.util.concurrent.atomic.AtomicReference;
|
||||
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
import okhttp3.OkHttpClient;
|
||||
|
@ -46,9 +36,6 @@ import okhttp3.Credentials;
|
|||
import android.content.Context;
|
||||
import android.content.SharedPreferences;
|
||||
import android.graphics.Bitmap;
|
||||
import android.net.ConnectivityManager;
|
||||
import android.net.NetworkInfo;
|
||||
import android.os.Looper;
|
||||
import android.util.Log;
|
||||
|
||||
import net.nullsum.audinaut.R;
|
||||
|
@ -74,8 +61,6 @@ import net.nullsum.audinaut.util.FileUtil;
|
|||
import net.nullsum.audinaut.util.ProgressListener;
|
||||
import net.nullsum.audinaut.util.SongDBHandler;
|
||||
import net.nullsum.audinaut.util.Util;
|
||||
import java.io.*;
|
||||
import java.util.zip.GZIPInputStream;
|
||||
|
||||
/**
|
||||
* @author Sindre Mehus
|
||||
|
@ -85,27 +70,8 @@ public class RESTMusicService implements MusicService {
|
|||
private static OkHttpClient client = new OkHttpClient();
|
||||
private static final String TAG = RESTMusicService.class.getSimpleName();
|
||||
|
||||
private static final int SOCKET_CONNECT_TIMEOUT = 10 * 1000;
|
||||
private static final int SOCKET_READ_TIMEOUT_DEFAULT = 10 * 1000;
|
||||
private static final int SOCKET_READ_TIMEOUT_DOWNLOAD = 30 * 1000;
|
||||
private static final int SOCKET_READ_TIMEOUT_GET_RANDOM_SONGS = 60 * 1000;
|
||||
private static final int SOCKET_READ_TIMEOUT_GET_PLAYLIST = 60 * 1000;
|
||||
|
||||
// Allow 20 seconds extra timeout per MB offset.
|
||||
private static final double TIMEOUT_MILLIS_PER_OFFSET_BYTE = 20000.0 / 1000000.0;
|
||||
|
||||
private static final int HTTP_REQUEST_MAX_ATTEMPTS = 5;
|
||||
private static final long REDIRECTION_CHECK_INTERVAL_MILLIS = 60L * 60L * 1000L;
|
||||
|
||||
private long redirectionLastChecked;
|
||||
private int redirectionNetworkType = -1;
|
||||
private String redirectFrom;
|
||||
private String redirectTo;
|
||||
private Integer instance;
|
||||
|
||||
public RESTMusicService() {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void ping(Context context, ProgressListener progressListener) throws Exception {
|
||||
String url = getRestUrl(context, "ping");
|
||||
|
@ -616,15 +582,6 @@ public class RESTMusicService implements MusicService {
|
|||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getCoverArtUrl(Context context, MusicDirectory.Entry entry) throws Exception {
|
||||
StringBuilder builder = new StringBuilder(getRestUrl(context, "getCoverArt"));
|
||||
builder.append("&id=").append(entry.getCoverArt());
|
||||
String url = builder.toString();
|
||||
url = rewriteUrlWithRedirect(context, url);
|
||||
return url;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Bitmap getCoverArt(Context context, MusicDirectory.Entry entry, int size, ProgressListener progressListener, SilentBackgroundTask task) throws Exception {
|
||||
|
||||
|
@ -686,10 +643,6 @@ public class RESTMusicService implements MusicService {
|
|||
|
||||
String url = getRestUrl(context, "stream");
|
||||
|
||||
url += "&id=" + song.getId();
|
||||
|
||||
Log.i(TAG, "Using music URL: " + url);
|
||||
|
||||
Builder builder = new FormBody.Builder();
|
||||
builder.add("id", song.getId());
|
||||
builder.add("maxBitRate", Integer.toString(maxBitrate));
|
||||
|
@ -702,7 +655,7 @@ public class RESTMusicService implements MusicService {
|
|||
}
|
||||
|
||||
requestBuilder.url(url);
|
||||
// requestBuilder.post(formBody);
|
||||
requestBuilder.post(formBody);
|
||||
|
||||
Request request = requestBuilder.build();
|
||||
|
||||
|
@ -711,20 +664,6 @@ public class RESTMusicService implements MusicService {
|
|||
}
|
||||
|
||||
|
||||
@Override
|
||||
public String getMusicUrl(Context context, MusicDirectory.Entry song, int maxBitrate) throws Exception {
|
||||
StringBuilder builder = new StringBuilder(getRestUrl(context, "stream"));
|
||||
builder.append("&id=").append(song.getId());
|
||||
|
||||
// Allow user to specify to stream raw formats if available
|
||||
builder.append("&maxBitRate=").append(maxBitrate);
|
||||
|
||||
String url = builder.toString();
|
||||
url = rewriteUrlWithRedirect(context, url);
|
||||
Log.i(TAG, "Using music URL: " + stripUrlInfo(url));
|
||||
return url;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<Genre> getGenres(boolean refresh, Context context, ProgressListener progressListener) throws Exception {
|
||||
String url = getRestUrl(context, "getGenres");
|
||||
|
@ -893,35 +832,6 @@ public class RESTMusicService implements MusicService {
|
|||
this.instance = instance;
|
||||
}
|
||||
|
||||
private String rewriteUrlWithRedirect(Context context, String url) {
|
||||
|
||||
// Only cache for a certain time.
|
||||
if (System.currentTimeMillis() - redirectionLastChecked > REDIRECTION_CHECK_INTERVAL_MILLIS) {
|
||||
return url;
|
||||
}
|
||||
|
||||
// Ignore cache if network type has changed.
|
||||
if (redirectionNetworkType != getCurrentNetworkType(context)) {
|
||||
return url;
|
||||
}
|
||||
|
||||
if (redirectFrom == null || redirectTo == null) {
|
||||
return url;
|
||||
}
|
||||
|
||||
return url.replace(redirectFrom, redirectTo);
|
||||
}
|
||||
|
||||
private String stripUrlInfo(String url) {
|
||||
return url.substring(0, url.indexOf("?u=") + 1) + url.substring(url.indexOf("&v=") + 1);
|
||||
}
|
||||
|
||||
private int getCurrentNetworkType(Context context) {
|
||||
ConnectivityManager manager = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
|
||||
NetworkInfo networkInfo = manager.getActiveNetworkInfo();
|
||||
return networkInfo == null ? -1 : networkInfo.getType();
|
||||
}
|
||||
|
||||
public int getInstance(Context context) {
|
||||
if(instance == null) {
|
||||
return Util.getActiveServer(context);
|
||||
|
@ -930,6 +840,7 @@ public class RESTMusicService implements MusicService {
|
|||
}
|
||||
}
|
||||
|
||||
|
||||
public String getRestUrl(Context context, String method) {
|
||||
return getRestUrl(context, method, true);
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue