fix(Spotify): Ignore optional attributes if not present (#4688)

This commit is contained in:
LisoUseInAIKyrios 2025-03-28 19:34:00 +01:00 committed by GitHub
parent 58ffbf40a5
commit 84f585492e
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -1,54 +1,87 @@
package app.revanced.extension.spotify.misc; package app.revanced.extension.spotify.misc;
import static java.lang.Boolean.FALSE;
import static java.lang.Boolean.TRUE;
import com.spotify.remoteconfig.internal.AccountAttribute; import com.spotify.remoteconfig.internal.AccountAttribute;
import java.util.HashMap; import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.Objects;
import app.revanced.extension.shared.Logger; import app.revanced.extension.shared.Logger;
/** @SuppressWarnings("unused")
* @noinspection unused
*/
public final class UnlockPremiumPatch { public final class UnlockPremiumPatch {
private static final Map<String, Object> OVERRIDES = new HashMap<>() {{ private static class OverrideAttribute {
/**
* Account attribute key.
*/
final String key;
/**
* Override value.
*/
final Object overrideValue;
/**
* If this attribute is expected to be present in all situations.
* If false, then no error is raised if the attribute is missing.
*/
final boolean isExpected;
OverrideAttribute(String key, Object overrideValue) {
this(key, overrideValue, true);
}
OverrideAttribute(String key, Object overrideValue, boolean isExpected) {
this.key = Objects.requireNonNull(key);
this.overrideValue = Objects.requireNonNull(overrideValue);
this.isExpected = isExpected;
}
}
private static final List<OverrideAttribute> OVERRIDES = List.of(
// Disables player and app ads. // Disables player and app ads.
put("ads", false); new OverrideAttribute("ads", FALSE),
// Works along on-demand, allows playing any song without restriction. // Works along on-demand, allows playing any song without restriction.
put("player-license", "premium"); new OverrideAttribute("player-license", "premium"),
// Disables shuffle being initially enabled when first playing a playlist. // Disables shuffle being initially enabled when first playing a playlist.
put("shuffle", false); new OverrideAttribute("shuffle", FALSE),
// Allows playing any song on-demand, without a shuffled order. // Allows playing any song on-demand, without a shuffled order.
put("on-demand", true); new OverrideAttribute("on-demand", TRUE),
// Make sure playing songs is not disabled remotely and playlists show up. // Make sure playing songs is not disabled remotely and playlists show up.
put("streaming", true); new OverrideAttribute("streaming", TRUE),
// Allows adding songs to queue and removes the smart shuffle mode restriction, // Allows adding songs to queue and removes the smart shuffle mode restriction,
// allowing to pick any of the other modes. // allowing to pick any of the other modes.
put("pick-and-shuffle", false); new OverrideAttribute("pick-and-shuffle", FALSE),
// Disables shuffle-mode streaming-rule, which forces songs to be played shuffled // Disables shuffle-mode streaming-rule, which forces songs to be played shuffled
// and breaks the player when other patches are applied. // and breaks the player when other patches are applied.
put("streaming-rules", ""); new OverrideAttribute("streaming-rules", ""),
// Enables premium UI in settings and removes the premium button in the nav-bar. // Enables premium UI in settings and removes the premium button in the nav-bar.
put("nft-disabled", "1"); new OverrideAttribute("nft-disabled", "1"),
// Enable Cross-Platform Spotify Car Thing. // Enable Spotify Car Thing hardware device.
put("can_use_superbird", true); // Device is discontinued and no longer works with the latest releases,
// but it might still work with older app targets.
new OverrideAttribute("can_use_superbird", TRUE, false),
// Removes the premium button in the nav-bar for tablet users. // Removes the premium button in the nav-bar for tablet users.
put("tablet-free", false); new OverrideAttribute("tablet-free", FALSE, false)
}}; );
/** /**
* Injection point. * Injection point.
*/ */
public static void overrideAttribute(Map<String, AccountAttribute> attributes) { public static void overrideAttribute(Map<String, AccountAttribute> attributes) {
try { try {
for (var entry : OVERRIDES.entrySet()) { for (var override : OVERRIDES) {
var key = entry.getKey(); var attribute = attributes.get(override.key);
var attribute = attributes.get(key);
if (attribute == null) { if (attribute == null) {
Logger.printException(() -> "Account attribute not found: " + key); if (override.isExpected) {
Logger.printException(() -> "''" + override.key + "' expected but not found");
}
} else { } else {
attribute.value_ = entry.getValue(); attribute.value_ = override.overrideValue;
} }
} }
} catch (Exception ex) { } catch (Exception ex) {