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 {
if (intent == null)
return START_NOT_STICKY;
synchronized (MediaParsingService.this) {
// Set 1s delay before displaying scan icon
// Except for Android 8+ which expects startForeground immediatly
if (mLastNotificationTime <= 0L)
mLastNotificationTime = System.currentTimeMillis();
mLastNotificationTime = VLCApplication.isForeground() ? System.currentTimeMillis() : 0L;
}
switch (intent.getAction()) {
case ACTION_INIT:
......
......@@ -1214,7 +1214,7 @@ public class PlaybackService extends MediaBrowserServiceCompat implements IVLCVo
@Override
public void onPlayFromSearch(final String query, final Bundle extras) {
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() {
@Override
public void onReceive(Context context, Intent intent) {
......@@ -1538,7 +1538,7 @@ public class PlaybackService extends MediaBrowserServiceCompat implements IVLCVo
}
};
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
public void connect() {
if (mBound)
throw new IllegalStateException("already connected");
startService(mContext);
mBound = mContext.bindService(getServiceIntent(mContext), mServiceConnection, BIND_AUTO_CREATE);
final Intent serviceIntent = getServiceIntent(mContext);
mContext.startService(serviceIntent);
mBound = mContext.bindService(serviceIntent, mServiceConnection, BIND_AUTO_CREATE);
}
@MainThread
......@@ -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) {
result.detach();
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;
}
VLCApplication.runBackground(new Runnable() {
......
......@@ -26,6 +26,7 @@ import android.support.v4.media.session.MediaButtonReceiver;
import android.view.KeyEvent;
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, ...)
......@@ -84,8 +85,8 @@ public class RemoteControlClientReceiver extends MediaButtonReceiver {
}
break;
case KeyEvent.KEYCODE_MEDIA_PLAY:
context.startService(new Intent(PlaybackService.ACTION_REMOTE_PLAY, null, context, PlaybackService.class));
return;
i = new Intent(PlaybackService.ACTION_REMOTE_PLAY, null, context, PlaybackService.class);
break;
case KeyEvent.KEYCODE_MEDIA_PAUSE:
i = new Intent(PlaybackService.ACTION_REMOTE_PAUSE, null, context, PlaybackService.class);
break;
......@@ -103,7 +104,7 @@ public class RemoteControlClientReceiver extends MediaButtonReceiver {
if (isOrderedBroadcast())
abortBroadcast();
if (i != null) {
context.startService(i);
Util.startService(context, i);
return;
}
} 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