From 328d80f0dfd9c6057e65b948b9bd9d52968cc4a8 Mon Sep 17 00:00:00 2001 From: Scott Jackson Date: Fri, 9 Sep 2016 16:36:10 -0700 Subject: Reintroduce tokens for Subsonic 6+ with a check for error code 41 --- .../main/java/github/daneren2005/dsub/domain/ServerInfo.java | 12 ++++++++++-- .../daneren2005/dsub/service/parser/AbstractParser.java | 6 ++++++ .../main/java/github/daneren2005/dsub/util/Constants.java | 1 + app/src/main/java/github/daneren2005/dsub/util/Util.java | 12 ++++++++++++ 4 files changed, 29 insertions(+), 2 deletions(-) (limited to 'app/src/main/java/github') 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) { -- cgit v1.2.3 From 5f0853a56d5214ab1c9d4238c500c8433d64e28e Mon Sep 17 00:00:00 2001 From: Scott Jackson Date: Tue, 13 Sep 2016 17:39:00 -0700 Subject: Fix error if adding a user with no current users --- app/src/main/java/github/daneren2005/dsub/fragments/AdminFragment.java | 2 +- app/src/main/java/github/daneren2005/dsub/util/UserUtil.java | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) (limited to 'app/src/main/java/github') diff --git a/app/src/main/java/github/daneren2005/dsub/fragments/AdminFragment.java b/app/src/main/java/github/daneren2005/dsub/fragments/AdminFragment.java index 187f0d55..552712f7 100644 --- a/app/src/main/java/github/daneren2005/dsub/fragments/AdminFragment.java +++ b/app/src/main/java/github/daneren2005/dsub/fragments/AdminFragment.java @@ -47,7 +47,7 @@ public class AdminFragment extends SelectRecyclerFragment { switch (item.getItemId()) { case R.id.menu_add_user: - UserUtil.addNewUser(context, this, objects.get(0)); + UserUtil.addNewUser(context, this, (objects.size() > 0) ? objects.get(0) : null); break; } diff --git a/app/src/main/java/github/daneren2005/dsub/util/UserUtil.java b/app/src/main/java/github/daneren2005/dsub/util/UserUtil.java index 24d3906b..db1c628f 100644 --- a/app/src/main/java/github/daneren2005/dsub/util/UserUtil.java +++ b/app/src/main/java/github/daneren2005/dsub/util/UserUtil.java @@ -406,7 +406,7 @@ public final class UserUtil { } } - if(sampleUser.getMusicFolderSettings() != null) { + if(sampleUser != null && sampleUser.getMusicFolderSettings() != null) { for(User.Setting setting: sampleUser.getMusicFolderSettings()) { User.MusicFolderSetting musicFolderSetting = (User.MusicFolderSetting) setting; user.addMusicFolder(musicFolderSetting, true); -- cgit v1.2.3