aboutsummaryrefslogtreecommitdiff
path: root/app/src/main
diff options
context:
space:
mode:
authorScott Jackson <daneren2005@gmail.com>2016-09-09 16:36:10 -0700
committerScott Jackson <daneren2005@gmail.com>2016-09-09 16:36:10 -0700
commit328d80f0dfd9c6057e65b948b9bd9d52968cc4a8 (patch)
treee2eedd601b3146e6e995fc8f21c162cf954cd320 /app/src/main
parent2a3f49f2b61042cd57dbcc6d0acd7f8754fe534b (diff)
downloaddsub-328d80f0dfd9c6057e65b948b9bd9d52968cc4a8.tar.gz
dsub-328d80f0dfd9c6057e65b948b9bd9d52968cc4a8.tar.bz2
dsub-328d80f0dfd9c6057e65b948b9bd9d52968cc4a8.zip
Reintroduce tokens for Subsonic 6+ with a check for error code 41
Diffstat (limited to 'app/src/main')
-rw-r--r--app/src/main/java/github/daneren2005/dsub/domain/ServerInfo.java12
-rw-r--r--app/src/main/java/github/daneren2005/dsub/service/parser/AbstractParser.java6
-rw-r--r--app/src/main/java/github/daneren2005/dsub/util/Constants.java1
-rw-r--r--app/src/main/java/github/daneren2005/dsub/util/Util.java12
4 files changed, 29 insertions, 2 deletions
diff --git a/app/src/main/java/github/daneren2005/dsub/domain/ServerInfo.java b/app/src/main/java/github/daneren2005/dsub/domain/ServerInfo.java
index 7f538484..dd41bcac 100644
--- a/app/src/main/java/github/daneren2005/dsub/domain/ServerInfo.java
+++ b/app/src/main/java/github/daneren2005/dsub/domain/ServerInfo.java
@@ -24,6 +24,7 @@ import java.io.Serializable;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
+import github.daneren2005.dsub.util.Constants;
import github.daneren2005.dsub.util.FileUtil;
import github.daneren2005.dsub.util.Util;
@@ -231,8 +232,15 @@ public class ServerInfo implements Serializable {
return canUseToken(context, Util.getActiveServer(context));
}
public static boolean canUseToken(Context context, int instance) {
- return false; /*isStockSubsonic(context, instance) && checkServerVersion(context, "1.13", instance) ||
- isMadsonic(context, instance) && checkServerVersion(context, "2.0", instance);*/
+ if(isStockSubsonic(context, instance) && checkServerVersion(context, "1.14", instance)) {
+ if(Util.getBlockTokenUse(context, instance)) {
+ return false;
+ } else {
+ return true;
+ }
+ } else {
+ return false;
+ }
}
public static boolean hasSimilarArtists(Context context) {
return !ServerInfo.isMadsonic(context) || ServerInfo.checkServerVersion(context, "2.0");
diff --git a/app/src/main/java/github/daneren2005/dsub/service/parser/AbstractParser.java b/app/src/main/java/github/daneren2005/dsub/service/parser/AbstractParser.java
index d6e1a002..d4c090c1 100644
--- a/app/src/main/java/github/daneren2005/dsub/service/parser/AbstractParser.java
+++ b/app/src/main/java/github/daneren2005/dsub/service/parser/AbstractParser.java
@@ -18,6 +18,7 @@
*/
package github.daneren2005.dsub.service.parser;
+import java.io.IOException;
import java.io.Reader;
import org.xmlpull.v1.XmlPullParser;
@@ -72,6 +73,11 @@ public abstract class AbstractParser {
case 40:
message = context.getResources().getString(R.string.parser_not_authenticated);
break;
+ case 41:
+ Util.setBlockTokenUse(context, instance, true);
+
+ // Throw IOException so RESTMusicService knows to retry
+ throw new IOException();
case 50:
message = context.getResources().getString(R.string.parser_not_authorized);
break;
diff --git a/app/src/main/java/github/daneren2005/dsub/util/Constants.java b/app/src/main/java/github/daneren2005/dsub/util/Constants.java
index b7a68962..7fa05a2c 100644
--- a/app/src/main/java/github/daneren2005/dsub/util/Constants.java
+++ b/app/src/main/java/github/daneren2005/dsub/util/Constants.java
@@ -189,6 +189,7 @@ public final class Constants {
public static final String CACHE_KEY_IGNORE = "ignoreArticles";
public static final String CACHE_AUDIO_SESSION_ID = "audioSessionId";
+ public static final String CACHE_BLOCK_TOKEN_USE = "blockTokenUse";
public static final String MAIN_BACK_STACK = "backStackIds";
public static final String MAIN_BACK_STACK_SIZE = "backStackIdsSize";
diff --git a/app/src/main/java/github/daneren2005/dsub/util/Util.java b/app/src/main/java/github/daneren2005/dsub/util/Util.java
index b1f1617d..5151c5d6 100644
--- a/app/src/main/java/github/daneren2005/dsub/util/Util.java
+++ b/app/src/main/java/github/daneren2005/dsub/util/Util.java
@@ -421,6 +421,18 @@ public final class Util {
return builder.toString().hashCode();
}
+ public static String getBlockTokenUsePref(Context context, int instance) {
+ return Constants.CACHE_BLOCK_TOKEN_USE + Util.getRestUrl(context, null, instance, false);
+ }
+ public static boolean getBlockTokenUse(Context context, int instance) {
+ return getPreferences(context).getBoolean(getBlockTokenUsePref(context, instance), false);
+ }
+ public static void setBlockTokenUse(Context context, int instance, boolean block) {
+ SharedPreferences.Editor editor = getPreferences(context).edit();
+ editor.putBoolean(getBlockTokenUsePref(context, instance), block);
+ editor.commit();
+ }
+
public static String replaceInternalUrl(Context context, String url) {
// Only change to internal when using https
if(url.indexOf("https") != -1) {