Eleven: Postpone initializing the queue until after boot
* If the service starts too early, which it does during boot now, we
get a crash due to VOLUME_EXTERNAL not yet being valid
* We can simply postpone this to after boot by simply just waiting
for ACTION_MEDIA_MOUNTED - which already does the reloading anyway
Change-Id: I78ce1fe3df8c88f6a6974d8d699c89c03d3d708d
diff --git a/src/org/lineageos/eleven/MusicPlaybackService.java b/src/org/lineageos/eleven/MusicPlaybackService.java
index 6f4aa0e..1e94333 100644
--- a/src/org/lineageos/eleven/MusicPlaybackService.java
+++ b/src/org/lineageos/eleven/MusicPlaybackService.java
@@ -1,7 +1,7 @@
/*
* Copyright (C) 2012 Andrew Neal
* Copyright (C) 2014-2016 The CyanogenMod Project
- * Copyright (C) 2018-2023 The LineageOS Project
+ * Copyright (C) 2018-2024 The LineageOS Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -589,6 +589,8 @@
private HashMap<String, List<MediaBrowser.MediaItem>> mMediaIdToChildren = new HashMap<>();
private ArrayList<Long> mSongs = new ArrayList<>(100);
+ private boolean mDidSetupSongRoot;
+
@Override
public IBinder onBind(final Intent intent) {
if (D) Log.d(TAG, "Service bound, intent = " + intent);
@@ -756,14 +758,8 @@
mShutdownIntent = PendingIntent.getService(this, 0, shutdownIntent,
PendingIntent.FLAG_IMMUTABLE);
- // Bring the queue back
- reloadQueue();
- notifyChange(QUEUE_CHANGED);
- notifyChange(META_CHANGED);
-
// Initialize the media tree. Only used for Android Auto
setupRootMediaItems();
- setupSongRoot();
}
private void setUpMediaSession() {
@@ -1084,6 +1080,10 @@
mQueueIsSaveable = true;
notifyChange(QUEUE_CHANGED);
notifyChange(META_CHANGED);
+
+ if (!mDidSetupSongRoot) {
+ setupSongRoot();
+ }
}
}
};
@@ -3188,6 +3188,7 @@
}
}
mMediaIdToChildren.put(CONTENT_BROWSER_SONGS, result);
+ mDidSetupSongRoot = true;
}
private final BroadcastReceiver mIntentReceiver = new BroadcastReceiver() {