Commit 8008b7af authored by Geoffrey Métais's avatar Geoffrey Métais

Oreo: Start services in foreground when needed

parent 227ef2e8
...@@ -120,8 +120,10 @@ public class MediaParsingService extends Service implements DevicesDiscoveryCb { ...@@ -120,8 +120,10 @@ public class MediaParsingService extends Service implements DevicesDiscoveryCb {
if (intent == null) if (intent == null)
return START_NOT_STICKY; return START_NOT_STICKY;
synchronized (MediaParsingService.this) { synchronized (MediaParsingService.this) {
// Set 1s delay before displaying scan icon
// Except for Android 8+ which expects startForeground immediatly
if (mLastNotificationTime <= 0L) if (mLastNotificationTime <= 0L)
mLastNotificationTime = System.currentTimeMillis(); mLastNotificationTime = VLCApplication.isForeground() ? System.currentTimeMillis() : 0L;
} }
switch (intent.getAction()) { switch (intent.getAction()) {
case ACTION_INIT: case ACTION_INIT:
......
...@@ -1214,7 +1214,7 @@ public class PlaybackService extends MediaBrowserServiceCompat implements IVLCVo ...@@ -1214,7 +1214,7 @@ public class PlaybackService extends MediaBrowserServiceCompat implements IVLCVo
@Override @Override
public void onPlayFromSearch(final String query, final Bundle extras) { public void onPlayFromSearch(final String query, final Bundle extras) {
if (!mMedialibrary.isInitiated()) { if (!mMedialibrary.isInitiated()) {
startService(new Intent(MediaParsingService.ACTION_INIT, null, PlaybackService.this, MediaParsingService.class)); Util.startService(PlaybackService.this, new Intent(MediaParsingService.ACTION_INIT, null, PlaybackService.this, MediaParsingService.class));
final BroadcastReceiver libraryReadyReceiver = new BroadcastReceiver() { final BroadcastReceiver libraryReadyReceiver = new BroadcastReceiver() {
@Override @Override
public void onReceive(Context context, Intent intent) { public void onReceive(Context context, Intent intent) {
...@@ -1538,7 +1538,7 @@ public class PlaybackService extends MediaBrowserServiceCompat implements IVLCVo ...@@ -1538,7 +1538,7 @@ public class PlaybackService extends MediaBrowserServiceCompat implements IVLCVo
} }
}; };
lbm.registerReceiver(mLibraryReceiver, new IntentFilter(VLCApplication.ACTION_MEDIALIBRARY_READY)); lbm.registerReceiver(mLibraryReceiver, new IntentFilter(VLCApplication.ACTION_MEDIALIBRARY_READY));
startService(new Intent(MediaParsingService.ACTION_INIT, null, this, MediaParsingService.class)); Util.startService(PlaybackService.this, new Intent(MediaParsingService.ACTION_INIT, null, this, MediaParsingService.class));
} }
} }
...@@ -2563,8 +2563,9 @@ public class PlaybackService extends MediaBrowserServiceCompat implements IVLCVo ...@@ -2563,8 +2563,9 @@ public class PlaybackService extends MediaBrowserServiceCompat implements IVLCVo
public void connect() { public void connect() {
if (mBound) if (mBound)
throw new IllegalStateException("already connected"); throw new IllegalStateException("already connected");
startService(mContext); final Intent serviceIntent = getServiceIntent(mContext);
mBound = mContext.bindService(getServiceIntent(mContext), mServiceConnection, BIND_AUTO_CREATE); mContext.startService(serviceIntent);
mBound = mContext.bindService(serviceIntent, mServiceConnection, BIND_AUTO_CREATE);
} }
@MainThread @MainThread
...@@ -2596,7 +2597,7 @@ public class PlaybackService extends MediaBrowserServiceCompat implements IVLCVo ...@@ -2596,7 +2597,7 @@ public class PlaybackService extends MediaBrowserServiceCompat implements IVLCVo
public void onLoadChildren(@NonNull final String parentId, @NonNull final Result<List<MediaBrowserCompat.MediaItem>> result) { public void onLoadChildren(@NonNull final String parentId, @NonNull final Result<List<MediaBrowserCompat.MediaItem>> result) {
result.detach(); result.detach();
if (!mMLInitializing && !mMedialibrary.isInitiated() && BrowserProvider.ID_ROOT.equals(parentId)) { if (!mMLInitializing && !mMedialibrary.isInitiated() && BrowserProvider.ID_ROOT.equals(parentId)) {
startService(new Intent(MediaParsingService.ACTION_INIT, null, this, MediaParsingService.class)); Util.startService(PlaybackService.this, new Intent(MediaParsingService.ACTION_INIT, null, this, MediaParsingService.class));
mMLInitializing = true; mMLInitializing = true;
} }
VLCApplication.runBackground(new Runnable() { VLCApplication.runBackground(new Runnable() {
......
...@@ -26,6 +26,7 @@ import android.support.v4.media.session.MediaButtonReceiver; ...@@ -26,6 +26,7 @@ import android.support.v4.media.session.MediaButtonReceiver;
import android.view.KeyEvent; import android.view.KeyEvent;
import org.videolan.vlc.util.AndroidDevices; import org.videolan.vlc.util.AndroidDevices;
import org.videolan.vlc.util.Util;
/** /**
* Small class to receive events passed out by the remote controls (wired, bluetooth, lock screen, ...) * Small class to receive events passed out by the remote controls (wired, bluetooth, lock screen, ...)
...@@ -84,8 +85,8 @@ public class RemoteControlClientReceiver extends MediaButtonReceiver { ...@@ -84,8 +85,8 @@ public class RemoteControlClientReceiver extends MediaButtonReceiver {
} }
break; break;
case KeyEvent.KEYCODE_MEDIA_PLAY: case KeyEvent.KEYCODE_MEDIA_PLAY:
context.startService(new Intent(PlaybackService.ACTION_REMOTE_PLAY, null, context, PlaybackService.class)); i = new Intent(PlaybackService.ACTION_REMOTE_PLAY, null, context, PlaybackService.class);
return; break;
case KeyEvent.KEYCODE_MEDIA_PAUSE: case KeyEvent.KEYCODE_MEDIA_PAUSE:
i = new Intent(PlaybackService.ACTION_REMOTE_PAUSE, null, context, PlaybackService.class); i = new Intent(PlaybackService.ACTION_REMOTE_PAUSE, null, context, PlaybackService.class);
break; break;
...@@ -103,7 +104,7 @@ public class RemoteControlClientReceiver extends MediaButtonReceiver { ...@@ -103,7 +104,7 @@ public class RemoteControlClientReceiver extends MediaButtonReceiver {
if (isOrderedBroadcast()) if (isOrderedBroadcast())
abortBroadcast(); abortBroadcast();
if (i != null) { if (i != null) {
context.startService(i); Util.startService(context, i);
return; return;
} }
} else if (action.equals(PlaybackService.ACTION_REMOTE_PLAYPAUSE)) { } else if (action.equals(PlaybackService.ACTION_REMOTE_PLAYPAUSE)) {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment