зеркало из https://github.com/mozilla/gecko-dev.git
Bug 1407046 - Migrate TabReceivedService to JobIntentService. r=JanH
MozReview-Commit-ID: 5CEfJtUfmHq --HG-- extra : rebase_source : 430bf2dde4dc7f52c954c404fa7bbec4641e9eb9
This commit is contained in:
Родитель
8830f08311
Коммит
198f113ef4
|
@ -455,6 +455,7 @@
|
|||
|
||||
<service
|
||||
android:name="org.mozilla.gecko.tabqueue.TabReceivedService"
|
||||
android:permission="android.permission.BIND_JOB_SERVICE"
|
||||
android:exported="false" />
|
||||
|
||||
|
||||
|
|
|
@ -27,6 +27,8 @@ public class JobIdsConstants {
|
|||
private static final int JOB_ID_DLC_SYNCHRONIZE = 1002;
|
||||
private static final int JOB_ID_DLC_CLEANUP = 1003;
|
||||
|
||||
private static final int JOB_ID_TAB_RECEIVED = 1004;
|
||||
|
||||
public static int getIdForDlcStudyJob() {
|
||||
return getIdWithOffset(JOB_ID_DLC_STUDY);
|
||||
}
|
||||
|
@ -43,6 +45,10 @@ public class JobIdsConstants {
|
|||
return getIdWithOffset(JOB_ID_DLC_CLEANUP);
|
||||
}
|
||||
|
||||
public static int getIdForTabReceivedJob() {
|
||||
return getIdWithOffset(JOB_ID_TAB_RECEIVED);
|
||||
}
|
||||
|
||||
private static boolean isReleaseBuild() {
|
||||
return AppConstants.RELEASE_OR_BETA;
|
||||
}
|
||||
|
|
|
@ -4,13 +4,6 @@
|
|||
|
||||
package org.mozilla.gecko.tabqueue;
|
||||
|
||||
import org.mozilla.gecko.AppConstants;
|
||||
import org.mozilla.gecko.BrowserLocaleManager;
|
||||
import org.mozilla.gecko.GeckoSharedPrefs;
|
||||
import org.mozilla.gecko.R;
|
||||
import org.mozilla.gecko.db.BrowserContract;
|
||||
|
||||
import android.app.IntentService;
|
||||
import android.app.PendingIntent;
|
||||
import android.content.Intent;
|
||||
import android.content.SharedPreferences;
|
||||
|
@ -18,34 +11,37 @@ import android.content.res.Resources;
|
|||
import android.database.Cursor;
|
||||
import android.media.RingtoneManager;
|
||||
import android.net.Uri;
|
||||
import android.support.annotation.NonNull;
|
||||
import android.support.annotation.Nullable;
|
||||
import android.support.annotation.WorkerThread;
|
||||
import android.support.v4.app.JobIntentService;
|
||||
import android.support.v4.app.NotificationCompat;
|
||||
import android.support.v4.app.NotificationManagerCompat;
|
||||
import android.util.Log;
|
||||
|
||||
import org.mozilla.gecko.AppConstants;
|
||||
import org.mozilla.gecko.BrowserLocaleManager;
|
||||
import org.mozilla.gecko.GeckoSharedPrefs;
|
||||
import org.mozilla.gecko.R;
|
||||
import org.mozilla.gecko.db.BrowserContract;
|
||||
|
||||
/**
|
||||
* An IntentService that displays a notification for a tab sent to this device.
|
||||
* A JobIntentService that displays a notification for a tab sent to this device.
|
||||
*
|
||||
* The expected Intent should contain:
|
||||
* * Data: URI to open in the notification
|
||||
* * EXTRA_TITLE: Page title of the URI to open
|
||||
*/
|
||||
public class TabReceivedService extends IntentService {
|
||||
public class TabReceivedService extends JobIntentService {
|
||||
private static final String LOGTAG = "Gecko" + TabReceivedService.class.getSimpleName();
|
||||
|
||||
private static final String PREF_NOTIFICATION_ID = "tab_received_notification_id";
|
||||
|
||||
private static final int MAX_NOTIFICATION_COUNT = 1000;
|
||||
|
||||
public TabReceivedService() {
|
||||
super(LOGTAG);
|
||||
setIntentRedelivery(true);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onHandleIntent(final Intent intent) {
|
||||
// IntentServices don't keep the process alive so
|
||||
protected void onHandleWork(@NonNull Intent intent) {
|
||||
// JobIntentServices doesn't keep the process alive so
|
||||
// we need to do this every time. Ideally, we wouldn't.
|
||||
final Resources res = getResources();
|
||||
BrowserLocaleManager.getInstance().correctLocale(this, res, res.getConfiguration());
|
||||
|
@ -88,6 +84,12 @@ public class TabReceivedService extends IntentService {
|
|||
prefs.edit().putInt(PREF_NOTIFICATION_ID, notificationId).apply();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onStopCurrentWork() {
|
||||
// Reschedule the work if it has been stopped before completing (shouldn't)
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param clientGUID the guid of the client in the clients table
|
||||
* @return the client's name from the clients table, if possible, else the brand name.
|
||||
|
|
|
@ -9,11 +9,13 @@ import android.content.Context;
|
|||
import android.content.Intent;
|
||||
import android.net.Uri;
|
||||
import android.support.annotation.Nullable;
|
||||
import android.support.v4.app.JobIntentService;
|
||||
import android.text.TextUtils;
|
||||
import android.util.Log;
|
||||
|
||||
import org.json.simple.JSONArray;
|
||||
import org.json.simple.JSONObject;
|
||||
import org.mozilla.gecko.JobIdsConstants;
|
||||
import org.mozilla.gecko.background.common.log.Logger;
|
||||
import org.mozilla.gecko.db.BrowserContract;
|
||||
import org.mozilla.gecko.fxa.authenticator.AndroidFxAccount;
|
||||
|
@ -311,10 +313,12 @@ public class CommandProcessor {
|
|||
}
|
||||
|
||||
final Intent sendTabNotificationIntent = new Intent();
|
||||
sendTabNotificationIntent.setClassName(context, BrowserContract.TAB_RECEIVED_SERVICE_CLASS_NAME);
|
||||
sendTabNotificationIntent.setData(Uri.parse(uri));
|
||||
sendTabNotificationIntent.putExtra(Intent.EXTRA_TITLE, title);
|
||||
sendTabNotificationIntent.putExtra(BrowserContract.EXTRA_CLIENT_GUID, clientId);
|
||||
final ComponentName componentName = context.startService(sendTabNotificationIntent);
|
||||
final ComponentName componentName = new ComponentName(context, BrowserContract.TAB_RECEIVED_SERVICE_CLASS_NAME);
|
||||
final int tabReceivedServiceJobId = JobIdsConstants.getIdForTabReceivedJob();
|
||||
|
||||
JobIntentService.enqueueWork(context, componentName, tabReceivedServiceJobId, sendTabNotificationIntent);
|
||||
}
|
||||
}
|
||||
|
|
Загрузка…
Ссылка в новой задаче