diff --git a/app/src/main/java/com/cappielloantonio/play/App.java b/app/src/main/java/com/cappielloantonio/play/App.java index f8d0a7ed..60de8455 100644 --- a/app/src/main/java/com/cappielloantonio/play/App.java +++ b/app/src/main/java/com/cappielloantonio/play/App.java @@ -54,6 +54,7 @@ public class App extends Application { SubsonicPreferences preferences = new SubsonicPreferences(); preferences.setServerUrl(server); preferences.setUsername(username); + preferences.setPassword(password); preferences.setAuthentication(password, token, salt); return new Subsonic(context, preferences); diff --git a/app/src/main/java/com/cappielloantonio/play/database/AppDatabase.java b/app/src/main/java/com/cappielloantonio/play/database/AppDatabase.java index e4ae3cda..0fde7988 100644 --- a/app/src/main/java/com/cappielloantonio/play/database/AppDatabase.java +++ b/app/src/main/java/com/cappielloantonio/play/database/AppDatabase.java @@ -21,9 +21,9 @@ import com.cappielloantonio.play.model.Server; @SuppressLint("RestrictedApi") @Database( - version = 30, + version = 31, entities = {Queue.class, Server.class, RecentSearch.class, Download.class, Playlist.class}, - autoMigrations = { @AutoMigration(from = 29, to = 30) } + autoMigrations = { @AutoMigration(from = 30, to = 31) } ) public abstract class AppDatabase extends RoomDatabase { private static final String TAG = "AppDatabase"; diff --git a/app/src/main/java/com/cappielloantonio/play/model/Server.java b/app/src/main/java/com/cappielloantonio/play/model/Server.java index 8addd0fd..d5153ea1 100644 --- a/app/src/main/java/com/cappielloantonio/play/model/Server.java +++ b/app/src/main/java/com/cappielloantonio/play/model/Server.java @@ -33,7 +33,10 @@ public class Server implements Parcelable { @ColumnInfo(name = "timestamp") private long timestamp; - public Server(@NonNull String serverId, String serverName, String username, String address, String token, String salt, long timestamp) { + @ColumnInfo(name = "low_security", defaultValue = "false") + private boolean lowSecurity; + + public Server(@NonNull String serverId, String serverName, String username, String address, String token, String salt, long timestamp, boolean lowSecurity) { this.serverId = serverId; this.serverName = serverName; this.username = username; @@ -41,6 +44,7 @@ public class Server implements Parcelable { this.token = token; this.salt = salt; this.timestamp = timestamp; + this.lowSecurity = lowSecurity; } @NonNull @@ -100,6 +104,14 @@ public class Server implements Parcelable { this.timestamp = timestamp; } + public boolean isLowSecurity() { + return lowSecurity; + } + + public void setLowSecurity(boolean lowSecurity) { + this.lowSecurity = lowSecurity; + } + @Override public boolean equals(Object o) { if (this == o) return true; diff --git a/app/src/main/java/com/cappielloantonio/play/subsonic/Subsonic.java b/app/src/main/java/com/cappielloantonio/play/subsonic/Subsonic.java index 39b0c131..cac25f16 100644 --- a/app/src/main/java/com/cappielloantonio/play/subsonic/Subsonic.java +++ b/app/src/main/java/com/cappielloantonio/play/subsonic/Subsonic.java @@ -100,7 +100,7 @@ public class Subsonic { public String getUrl() { String url = preferences.getServerUrl() + "/rest/"; - return url.replace("//rest","/rest"); + return url.replace("//rest", "/rest"); } public Map getParams() { @@ -112,6 +112,8 @@ public class Subsonic { params.put("c", preferences.getClientName()); params.put("f", "xml"); + if (preferences.getPassword() != null && !preferences.getPassword().trim().equals("")) params.put("p", preferences.getPassword()); + return params; } } diff --git a/app/src/main/java/com/cappielloantonio/play/subsonic/SubsonicPreferences.java b/app/src/main/java/com/cappielloantonio/play/subsonic/SubsonicPreferences.java index fa680943..65cb7e33 100644 --- a/app/src/main/java/com/cappielloantonio/play/subsonic/SubsonicPreferences.java +++ b/app/src/main/java/com/cappielloantonio/play/subsonic/SubsonicPreferences.java @@ -7,6 +7,7 @@ import java.util.UUID; public class SubsonicPreferences { private String serverUrl; private String username; + private String password; private String clientName = "Play"; private SubsonicAuthentication authentication; @@ -18,6 +19,10 @@ public class SubsonicPreferences { return username; } + public String getPassword() { + return password; + } + public String getClientName() { return clientName; } @@ -34,6 +39,10 @@ public class SubsonicPreferences { this.username = username; } + public void setPassword(String password) { + this.password = password; + } + public void setClientName(String clientName) { this.clientName = clientName; } diff --git a/app/src/main/java/com/cappielloantonio/play/ui/dialog/ServerSignupDialog.java b/app/src/main/java/com/cappielloantonio/play/ui/dialog/ServerSignupDialog.java index a6793367..1ce2c416 100644 --- a/app/src/main/java/com/cappielloantonio/play/ui/dialog/ServerSignupDialog.java +++ b/app/src/main/java/com/cappielloantonio/play/ui/dialog/ServerSignupDialog.java @@ -41,6 +41,7 @@ public class ServerSignupDialog extends DialogFragment { private String password; private String server; private boolean directAccess = false; + private boolean lowSecurity = false; @NonNull @Override @@ -90,7 +91,10 @@ public class ServerSignupDialog extends DialogFragment { bind.passwordTextView.setText(""); bind.serverTextView.setText(loginViewModel.getServerToEdit().getAddress()); bind.directAccessCheckbox.setChecked(false); + bind.lowSecurityCheckbox.setChecked(loginViewModel.getServerToEdit().isLowSecurity()); } + } else { + loginViewModel.setServerToEdit(null); } } @@ -115,6 +119,7 @@ public class ServerSignupDialog extends DialogFragment { password = Objects.requireNonNull(bind.passwordTextView.getText()).toString(); server = Objects.requireNonNull(bind.serverTextView.getText()).toString().trim(); directAccess = bind.directAccessCheckbox.isChecked(); + lowSecurity = bind.lowSecurityCheckbox.isChecked(); if (TextUtils.isEmpty(serverName)) { bind.serverNameTextView.setError(getString(R.string.error_required)); @@ -162,14 +167,13 @@ public class ServerSignupDialog extends DialogFragment { if (token != null && salt != null) { String serverID = loginViewModel.getServerToEdit() != null ? loginViewModel.getServerToEdit().getServerId() : UUID.randomUUID().toString(); - PreferenceUtil.getInstance(context).setPassword(null); PreferenceUtil.getInstance(context).setToken(token); PreferenceUtil.getInstance(context).setSalt(salt); PreferenceUtil.getInstance(context).setServerId(serverID); - loginViewModel.addServer(new Server(serverID, this.serverName, this.username, this.server, token, salt, System.currentTimeMillis())); + if (!lowSecurity) PreferenceUtil.getInstance(context).setPassword(null); - return; + loginViewModel.addServer(new Server(serverID, this.serverName, this.username, this.server, token, salt, System.currentTimeMillis(), this.lowSecurity)); } App.getSubsonicClientInstance(context, true); diff --git a/app/src/main/res/layout/dialog_server_signup.xml b/app/src/main/res/layout/dialog_server_signup.xml index 12955f4f..e38f8e5d 100644 --- a/app/src/main/res/layout/dialog_server_signup.xml +++ b/app/src/main/res/layout/dialog_server_signup.xml @@ -60,8 +60,6 @@ app:endIconTint="?android:textColorSecondary" app:errorEnabled="true"> - - + + \ No newline at end of file diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 7e82048c..5d31a039 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -198,4 +198,5 @@ Sync starred tracks Transcoding Priority given to the transcoding mode. If set to \"Direct play\" the bitrate of the file will not be changed. + Low security \ No newline at end of file