From aeabf68e4be9f2240bfb9133b5d9727aada419d0 Mon Sep 17 00:00:00 2001 From: Patrik Johanson Date: Sat, 26 Sep 2020 01:15:30 +0200 Subject: Adds a checkbox for including Authorization headers to the server settings to fix issues described in daneren2005/Subsonic#870 --- .../daneren2005/dsub/fragments/SettingsFragment.java | 7 +++++++ .../github/daneren2005/dsub/service/RESTMusicService.java | 15 ++++++++++----- .../main/java/github/daneren2005/dsub/util/Constants.java | 1 + app/src/main/java/github/daneren2005/dsub/util/Util.java | 5 +++++ 4 files changed, 23 insertions(+), 5 deletions(-) (limited to 'app/src/main/java/github') diff --git a/app/src/main/java/github/daneren2005/dsub/fragments/SettingsFragment.java b/app/src/main/java/github/daneren2005/dsub/fragments/SettingsFragment.java index 326cebb4..1789ad15 100644 --- a/app/src/main/java/github/daneren2005/dsub/fragments/SettingsFragment.java +++ b/app/src/main/java/github/daneren2005/dsub/fragments/SettingsFragment.java @@ -575,6 +575,12 @@ public class SettingsFragment extends PreferenceCompatFragment implements Shared serverSyncPreference.setSummary(R.string.settings_server_sync_summary); serverSyncPreference.setTitle(R.string.settings_server_sync); + final CheckBoxPreference serverAuthHeaderPreference = new CheckBoxPreference(context); + serverAuthHeaderPreference.setKey(Constants.PREFERENCES_KEY_SERVER_AUTHHEADER + instance); + serverAuthHeaderPreference.setChecked(Util.isAuthHeaderEnabled(context, instance)); + serverAuthHeaderPreference.setSummary(R.string.settings_server_authheaders_summary); + serverAuthHeaderPreference.setTitle(R.string.settings_server_authheaders); + final Preference serverOpenBrowser = new Preference(context); serverOpenBrowser.setKey(Constants.PREFERENCES_KEY_OPEN_BROWSER); serverOpenBrowser.setPersistent(false); @@ -649,6 +655,7 @@ public class SettingsFragment extends PreferenceCompatFragment implements Shared screen.addPreference(serverPasswordPreference); screen.addPreference(serverTagPreference); screen.addPreference(serverSyncPreference); + screen.addPreference(serverAuthHeaderPreference); screen.addPreference(serverTestConnectionPreference); screen.addPreference(serverOpenBrowser); screen.addPreference(serverRemoveServerPreference); diff --git a/app/src/main/java/github/daneren2005/dsub/service/RESTMusicService.java b/app/src/main/java/github/daneren2005/dsub/service/RESTMusicService.java index 100224e8..8fdafc11 100644 --- a/app/src/main/java/github/daneren2005/dsub/service/RESTMusicService.java +++ b/app/src/main/java/github/daneren2005/dsub/service/RESTMusicService.java @@ -1911,11 +1911,16 @@ public class RESTMusicService implements MusicService { SharedPreferences prefs = Util.getPreferences(context); int instance = getInstance(context); - String username = prefs.getString(Constants.PREFERENCES_KEY_USERNAME + instance, null); - String password = prefs.getString(Constants.PREFERENCES_KEY_PASSWORD + instance, null); - if (prefs.getBoolean(Constants.PREFERENCES_KEY_ENCRYPTED_PASSWORD + instance, false)) password = KeyStoreUtil.decrypt(password); - String encoded = Base64.encodeToString((username + ":" + password).getBytes("UTF-8"), Base64.NO_WRAP);; - connection.setRequestProperty("Authorization", "Basic " + encoded); + boolean authHeader = prefs.getBoolean(Constants.PREFERENCES_KEY_SERVER_AUTHHEADER + instance, true); + if(authHeader) { + String username = prefs.getString(Constants.PREFERENCES_KEY_USERNAME + instance, null); + String password = prefs.getString(Constants.PREFERENCES_KEY_PASSWORD + instance, null); + if (prefs.getBoolean(Constants.PREFERENCES_KEY_ENCRYPTED_PASSWORD + instance, false)) { + password = KeyStoreUtil.decrypt(password); + } + String encoded = Base64.encodeToString((username + ":" + password).getBytes("UTF-8"), Base64.NO_WRAP); + connection.setRequestProperty("Authorization", "Basic " + encoded); + } // Force the connection to initiate if(connection.getResponseCode() >= 500) { 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 933f531f..9e6708be 100644 --- a/app/src/main/java/github/daneren2005/dsub/util/Constants.java +++ b/app/src/main/java/github/daneren2005/dsub/util/Constants.java @@ -85,6 +85,7 @@ public final class Constants { public static final String PREFERENCES_KEY_MUSIC_FOLDER_ID = "musicFolderId"; public static final String PREFERENCES_KEY_USERNAME = "username"; public static final String PREFERENCES_KEY_PASSWORD = "password"; + public static final String PREFERENCES_KEY_SERVER_AUTHHEADER = "authHeader"; public static final String PREFERENCES_KEY_ENCRYPTED_PASSWORD = "encryptedPassword"; public static final String PREFERENCES_KEY_INSTALL_TIME = "installTime"; public static final String PREFERENCES_KEY_THEME = "theme"; 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 b58a81e4..872e9561 100644 --- a/app/src/main/java/github/daneren2005/dsub/util/Util.java +++ b/app/src/main/java/github/daneren2005/dsub/util/Util.java @@ -460,6 +460,11 @@ public final class Util { return prefs.getBoolean(Constants.PREFERENCES_KEY_SERVER_SYNC + instance, true); } + public static boolean isAuthHeaderEnabled(Context context, int instance) { + SharedPreferences prefs = getPreferences(context); + return prefs.getBoolean(Constants.PREFERENCES_KEY_SERVER_AUTHHEADER + instance, true); + } + public static String getParentFromEntry(Context context, MusicDirectory.Entry entry) { if(Util.isTagBrowsing(context)) { if(!entry.isDirectory()) { -- cgit v1.2.3 From 72bef3c7ae8fd72fdba25d41df7e7c517cf50e8c Mon Sep 17 00:00:00 2001 From: Moritz Maxeiner Date: Mon, 21 Sep 2020 20:03:11 +0200 Subject: Use applicationId for preferences und offline sync file names --- app/src/main/java/github/daneren2005/dsub/util/Constants.java | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) (limited to 'app/src/main/java/github') 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 9e6708be..744c2469 100644 --- a/app/src/main/java/github/daneren2005/dsub/util/Constants.java +++ b/app/src/main/java/github/daneren2005/dsub/util/Constants.java @@ -18,6 +18,8 @@ */ package github.daneren2005.dsub.util; +import github.daneren2005.dsub.BuildConfig; + /** * @author Sindre Mehus * @version $Id$ @@ -214,8 +216,8 @@ public final class Constants { public static final String FRAGMENT_POSITION = "fragmentPosition"; // Name of the preferences file. - public static final String PREFERENCES_FILE_NAME = "github.daneren2005.dsub_preferences"; - public static final String OFFLINE_SYNC_NAME = "github.daneren2005.dsub.offline"; + public static final String PREFERENCES_FILE_NAME = BuildConfig.APPLICATION_ID + "_preferences"; + public static final String OFFLINE_SYNC_NAME = BuildConfig.APPLICATION_ID + ".offline"; public static final String OFFLINE_SYNC_DEFAULT = "syncDefaults"; // Account prefs -- cgit v1.2.3 From 45dfb9653cf5fcfe7ca5e3a20437aeee64b9ecb1 Mon Sep 17 00:00:00 2001 From: Moritz Maxeiner Date: Mon, 21 Sep 2020 21:02:22 +0200 Subject: Derive subsonic account type descriptor from applicationId --- app/build.gradle | 1 + app/src/main/java/github/daneren2005/dsub/util/Constants.java | 2 +- app/src/main/res/xml/authenticator.xml | 2 +- app/src/main/res/xml/mostrecent_syncadapter.xml | 2 +- app/src/main/res/xml/playlists_syncadapter.xml | 2 +- app/src/main/res/xml/podcasts_syncadapter.xml | 2 +- app/src/main/res/xml/starred_syncadapter.xml | 2 +- 7 files changed, 7 insertions(+), 6 deletions(-) (limited to 'app/src/main/java/github') diff --git a/app/build.gradle b/app/build.gradle index 1edbc5e2..f96f3051 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -12,6 +12,7 @@ android { setProperty("archivesBaseName", "DSub $versionName") resConfigs "de", "es", "fr", "hu", "nl", "pt-rPT", "ru", "sv" vectorDrawables.useSupportLibrary = true + resValue 'string', 'account_type.subsonic', applicationId + ".subsonic" } buildTypes { release { 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 744c2469..e62b93f9 100644 --- a/app/src/main/java/github/daneren2005/dsub/util/Constants.java +++ b/app/src/main/java/github/daneren2005/dsub/util/Constants.java @@ -222,7 +222,7 @@ public final class Constants { // Account prefs public static final String SYNC_ACCOUNT_NAME = "Subsonic Account"; - public static final String SYNC_ACCOUNT_TYPE = "subsonic.org"; + public static final String SYNC_ACCOUNT_TYPE = BuildConfig.APPLICATION_ID + ".subsonic"; public static final String SYNC_ACCOUNT_PLAYLIST_AUTHORITY = "github.daneren2005.dsub.playlists.provider"; public static final String SYNC_ACCOUNT_PODCAST_AUTHORITY = "github.daneren2005.dsub.podcasts.provider"; public static final String SYNC_ACCOUNT_STARRED_AUTHORITY = "github.daneren2005.dsub.starred.provider"; diff --git a/app/src/main/res/xml/authenticator.xml b/app/src/main/res/xml/authenticator.xml index 3055240b..23e4621a 100644 --- a/app/src/main/res/xml/authenticator.xml +++ b/app/src/main/res/xml/authenticator.xml @@ -1,7 +1,7 @@ \ No newline at end of file diff --git a/app/src/main/res/xml/mostrecent_syncadapter.xml b/app/src/main/res/xml/mostrecent_syncadapter.xml index 0195edeb..8c6dada2 100644 --- a/app/src/main/res/xml/mostrecent_syncadapter.xml +++ b/app/src/main/res/xml/mostrecent_syncadapter.xml @@ -1,7 +1,7 @@ Date: Mon, 21 Sep 2020 22:04:51 +0200 Subject: Derive provider descriptors from applicationId --- app/build.gradle | 5 +++++ app/src/main/AndroidManifest.xml | 10 +++++----- app/src/main/java/github/daneren2005/dsub/util/Constants.java | 8 ++++---- app/src/main/res/xml/mostrecent_syncadapter.xml | 2 +- app/src/main/res/xml/playlists_syncadapter.xml | 2 +- app/src/main/res/xml/podcasts_syncadapter.xml | 2 +- app/src/main/res/xml/searchable.xml | 2 +- app/src/main/res/xml/starred_syncadapter.xml | 2 +- 8 files changed, 19 insertions(+), 14 deletions(-) (limited to 'app/src/main/java/github') diff --git a/app/build.gradle b/app/build.gradle index f96f3051..38401e63 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -13,6 +13,11 @@ android { resConfigs "de", "es", "fr", "hu", "nl", "pt-rPT", "ru", "sv" vectorDrawables.useSupportLibrary = true resValue 'string', 'account_type.subsonic', applicationId + ".subsonic" + resValue 'string', 'provider.search', applicationId + ".provider.DSubSearchProvider" + resValue 'string', 'provider.playlist', applicationId + ".playlists.provider" + resValue 'string', 'provider.podcast', applicationId + ".podcasts.provider" + resValue 'string', 'provider.starred', applicationId + ".starred.provider" + resValue 'string', 'provider.recently_added', applicationId + ".mostrecent.provider" } buildTypes { release { diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index 52756534..ffefe19e 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -214,24 +214,24 @@ + android:authorities="@string/provider.search"/> 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 e62b93f9..0ce58d73 100644 --- a/app/src/main/java/github/daneren2005/dsub/util/Constants.java +++ b/app/src/main/java/github/daneren2005/dsub/util/Constants.java @@ -223,10 +223,10 @@ public final class Constants { // Account prefs public static final String SYNC_ACCOUNT_NAME = "Subsonic Account"; public static final String SYNC_ACCOUNT_TYPE = BuildConfig.APPLICATION_ID + ".subsonic"; - public static final String SYNC_ACCOUNT_PLAYLIST_AUTHORITY = "github.daneren2005.dsub.playlists.provider"; - public static final String SYNC_ACCOUNT_PODCAST_AUTHORITY = "github.daneren2005.dsub.podcasts.provider"; - public static final String SYNC_ACCOUNT_STARRED_AUTHORITY = "github.daneren2005.dsub.starred.provider"; - public static final String SYNC_ACCOUNT_MOST_RECENT_AUTHORITY = "github.daneren2005.dsub.mostrecent.provider"; + public static final String SYNC_ACCOUNT_PLAYLIST_AUTHORITY = BuildConfig.APPLICATION_ID + ".playlists.provider"; + public static final String SYNC_ACCOUNT_PODCAST_AUTHORITY = BuildConfig.APPLICATION_ID + ".podcasts.provider"; + public static final String SYNC_ACCOUNT_STARRED_AUTHORITY = BuildConfig.APPLICATION_ID + ".starred.provider"; + public static final String SYNC_ACCOUNT_MOST_RECENT_AUTHORITY = BuildConfig.APPLICATION_ID + ".mostrecent.provider"; public static final String TASKER_EXTRA_BUNDLE = "com.twofortyfouram.locale.intent.extra.BUNDLE"; diff --git a/app/src/main/res/xml/mostrecent_syncadapter.xml b/app/src/main/res/xml/mostrecent_syncadapter.xml index 8c6dada2..a0172501 100644 --- a/app/src/main/res/xml/mostrecent_syncadapter.xml +++ b/app/src/main/res/xml/mostrecent_syncadapter.xml @@ -1,6 +1,6 @@ \ No newline at end of file diff --git a/app/src/main/res/xml/starred_syncadapter.xml b/app/src/main/res/xml/starred_syncadapter.xml index f325da26..1d855057 100644 --- a/app/src/main/res/xml/starred_syncadapter.xml +++ b/app/src/main/res/xml/starred_syncadapter.xml @@ -1,6 +1,6 @@ Date: Mon, 21 Sep 2020 23:50:15 +0200 Subject: Don't hardcode the package name --- .../main/java/github/daneren2005/dsub/activity/SubsonicActivity.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'app/src/main/java/github') diff --git a/app/src/main/java/github/daneren2005/dsub/activity/SubsonicActivity.java b/app/src/main/java/github/daneren2005/dsub/activity/SubsonicActivity.java index 5948064d..4d8dfb59 100644 --- a/app/src/main/java/github/daneren2005/dsub/activity/SubsonicActivity.java +++ b/app/src/main/java/github/daneren2005/dsub/activity/SubsonicActivity.java @@ -1248,7 +1248,7 @@ public class SubsonicActivity extends AppCompatActivity implements OnItemSelecte PrintWriter printWriter = null; try { - PackageInfo packageInfo = context.getPackageManager().getPackageInfo("github.daneren2005.dsub", 0); + PackageInfo packageInfo = context.getPackageManager().getPackageInfo(context.getPackageName(), 0); file = new File(Environment.getExternalStorageDirectory(), "dsub-stacktrace.txt"); printWriter = new PrintWriter(file); printWriter.println("Android API level: " + Build.VERSION.SDK); -- cgit v1.2.3