diff options
author | Scott Jackson <daneren2005@gmail.com> | 2016-10-26 17:10:11 -0700 |
---|---|---|
committer | Scott Jackson <daneren2005@gmail.com> | 2016-10-26 17:10:11 -0700 |
commit | 52899f56b3af87f16c57450d718b7230667f6d49 (patch) | |
tree | e7cf6f8f5067c16aff166b9fd8f94167bc42ab9d /app/src | |
parent | d27f3b1729a89df021204f54005c284e4f967907 (diff) | |
download | dsub-52899f56b3af87f16c57450d718b7230667f6d49.tar.gz dsub-52899f56b3af87f16c57450d718b7230667f6d49.tar.bz2 dsub-52899f56b3af87f16c57450d718b7230667f6d49.zip |
Android 7 no longer accepts session id's from previous versions
Diffstat (limited to 'app/src')
-rw-r--r-- | app/src/main/java/github/daneren2005/dsub/service/DownloadService.java | 13 | ||||
-rw-r--r-- | app/src/main/java/github/daneren2005/dsub/util/Constants.java | 1 |
2 files changed, 11 insertions, 3 deletions
diff --git a/app/src/main/java/github/daneren2005/dsub/service/DownloadService.java b/app/src/main/java/github/daneren2005/dsub/service/DownloadService.java index 1cf482ca..a99613b4 100644 --- a/app/src/main/java/github/daneren2005/dsub/service/DownloadService.java +++ b/app/src/main/java/github/daneren2005/dsub/service/DownloadService.java @@ -197,13 +197,16 @@ public class DownloadService extends Service { mediaPlayer = new MediaPlayer(); mediaPlayer.setWakeMode(DownloadService.this, PowerManager.PARTIAL_WAKE_LOCK); + // We want to change audio session id's between upgrading Android versions. Upgrading to Android 7.0 is broken (probably updated session id format) audioSessionId = -1; - Integer id = prefs.getInt(Constants.CACHE_AUDIO_SESSION_ID, -1); - if(id != -1) { + int id = prefs.getInt(Constants.CACHE_AUDIO_SESSION_ID, -1); + int versionCode = prefs.getInt(Constants.CACHE_AUDIO_SESSION_VERSION_CODE, -1); + if(versionCode == Build.VERSION.SDK_INT && id != -1) { try { audioSessionId = id; mediaPlayer.setAudioSessionId(audioSessionId); } catch (Throwable e) { + Log.w(TAG, "Failed to use cached audio session", e); audioSessionId = -1; } } @@ -212,7 +215,11 @@ public class DownloadService extends Service { mediaPlayer.setAudioStreamType(AudioManager.STREAM_MUSIC); try { audioSessionId = mediaPlayer.getAudioSessionId(); - prefs.edit().putInt(Constants.CACHE_AUDIO_SESSION_ID, audioSessionId).commit(); + + SharedPreferences.Editor editor = prefs.edit(); + editor.putInt(Constants.CACHE_AUDIO_SESSION_ID, audioSessionId); + editor.putInt(Constants.CACHE_AUDIO_SESSION_VERSION_CODE, Build.VERSION.SDK_INT); + editor.commit(); } catch (Throwable t) { // Froyo or lower } 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 2d4301d9..b62729ab 100644 --- a/app/src/main/java/github/daneren2005/dsub/util/Constants.java +++ b/app/src/main/java/github/daneren2005/dsub/util/Constants.java @@ -190,6 +190,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_AUDIO_SESSION_VERSION_CODE = "audioSessionVersionCode"; public static final String CACHE_BLOCK_TOKEN_USE = "blockTokenUse"; public static final String MAIN_BACK_STACK = "backStackIds"; |