Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixes issue #1076 : Replaced IntentService with JobIntentService in RealtimeService #1294

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion onebusaway-android/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -305,7 +305,8 @@
android:authorities="${databaseAuthority}"/>

<service
android:name=".directions.realtime.RealtimeService">
android:name=".directions.realtime.RealtimeService"
android:permission="android.permission.BIND_JOB_SERVICE">
</service>

<service
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
/**
* Copyright (C) 2016 Cambridge Systematics, Inc.
*
* <p>
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* <p>
* http://www.apache.org/licenses/LICENSE-2.0
*
* <p>
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
Expand All @@ -17,7 +17,6 @@

import android.app.Activity;
import android.app.AlarmManager;
import android.app.IntentService;
import android.app.Notification;
import android.app.NotificationManager;
import android.app.PendingIntent;
Expand All @@ -27,6 +26,7 @@
import android.os.Bundle;
import android.util.Log;

import androidx.core.app.JobIntentService;
import androidx.core.app.NotificationCompat;

import org.onebusaway.android.R;
Expand All @@ -50,15 +50,15 @@
* and then the top result for that trip gets delayed by 20 minutes, the user will be notified
* that new trip results are available.
*/
public class RealtimeService extends IntentService {
public class RealtimeService extends JobIntentService {

private static final String TAG = "RealtimeService";

private static final String ITINERARY_DESC = ".ItineraryDesc";
private static final String ITINERARY_END_DATE = ".ItineraryEndDate";

public RealtimeService() {
super("RealtimeService");
super();
}

/**
Expand All @@ -77,11 +77,11 @@ public static void start(Activity source, Bundle bundle) {
bundle.putSerializable(OTPConstants.NOTIFICATION_TARGET, source.getClass());
Intent intent = new Intent(OTPConstants.INTENT_START_CHECKS);
intent.putExtras(bundle);
source.sendBroadcast(intent);
enqueueWork(source, RealtimeService.class, 1000, intent);
}

@Override
public void onHandleIntent(Intent intent) {
protected void onHandleWork(Intent intent) {
Bundle bundle = intent.getExtras();

if (intent.getAction().equals(OTPConstants.INTENT_START_CHECKS)) {
Expand All @@ -93,8 +93,6 @@ public void onHandleIntent(Intent intent) {
} else if (intent.getAction().equals(OTPConstants.INTENT_CHECK_TRIP_TIME)) {
checkForItineraryChange(bundle);
}

RealtimeWakefulReceiver.completeWakefulIntent(intent);
}

// Depending on preferences / whether there is realtime info, start updates.
Expand Down Expand Up @@ -332,7 +330,7 @@ private Class getNotificationTarget(Bundle bundle) {
String name = bundle.getString(OTPConstants.NOTIFICATION_TARGET);
try {
return Class.forName(name);
} catch(ClassNotFoundException e) {
} catch (ClassNotFoundException e) {
Log.e(TAG, "unable to find class for name " + name);
}
return null;
Expand All @@ -358,4 +356,4 @@ private Bundle getSimplifiedBundle(Bundle params) {
return extras;
}

}
}
Loading