mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-11-05 08:35:26 +00:00
Bug 1215353 - Move TabReceivedBroadcastReceiver notifications to IntentService. r=nalexander
--HG-- rename : mobile/android/base/sync/TabReceivedBroadcastReceiver.java => mobile/android/base/sync/TabReceivedService.java extra : commitid : BiorrdiQT71 extra : rebase_source : aa51743b45fd9cfaa9b837a2ffbab8e8d6beef14
This commit is contained in:
parent
0fe6353498
commit
3cf4ca52de
@ -499,7 +499,7 @@
|
||||
#include ../services/manifests/HealthReportAndroidManifest_services.xml.in
|
||||
#include ../services/manifests/SyncAndroidManifest_services.xml.in
|
||||
|
||||
<receiver android:name="org.mozilla.gecko.sync.TabReceivedBroadcastReceiver"
|
||||
<service android:name="org.mozilla.gecko.sync.TabReceivedService"
|
||||
android:exported="false"/>
|
||||
|
||||
#ifdef MOZ_ANDROID_SEARCH_ACTIVITY
|
||||
|
@ -472,7 +472,7 @@ gbjar.sources += [
|
||||
'sqlite/SQLiteBridgeException.java',
|
||||
'SuggestClient.java',
|
||||
'SurfaceBits.java',
|
||||
'sync/TabReceivedBroadcastReceiver.java',
|
||||
'sync/TabReceivedService.java',
|
||||
'Tab.java',
|
||||
'tabqueue/TabQueueDispatcher.java',
|
||||
'tabqueue/TabQueueHelper.java',
|
||||
|
@ -12,7 +12,6 @@ import java.util.concurrent.atomic.AtomicInteger;
|
||||
|
||||
import org.json.simple.JSONArray;
|
||||
import org.json.simple.JSONObject;
|
||||
import org.mozilla.gecko.R;
|
||||
import org.mozilla.gecko.background.common.log.Logger;
|
||||
import org.mozilla.gecko.sync.repositories.NullCursorException;
|
||||
import org.mozilla.gecko.sync.repositories.android.ClientsDatabaseAccessor;
|
||||
@ -253,9 +252,9 @@ public class CommandProcessor {
|
||||
title = args.get(2);
|
||||
}
|
||||
|
||||
final Intent sendTabNotificationIntent = new Intent(context, TabReceivedBroadcastReceiver.class);
|
||||
final Intent sendTabNotificationIntent = new Intent(context, TabReceivedService.class);
|
||||
sendTabNotificationIntent.setData(Uri.parse(uri));
|
||||
sendTabNotificationIntent.putExtra(TabReceivedBroadcastReceiver.EXTRA_TITLE, title);
|
||||
context.sendBroadcast(sendTabNotificationIntent);
|
||||
sendTabNotificationIntent.putExtra(TabReceivedService.EXTRA_TITLE, title);
|
||||
context.startService(sendTabNotificationIntent);
|
||||
}
|
||||
}
|
||||
|
@ -9,9 +9,8 @@ import org.mozilla.gecko.GeckoSharedPrefs;
|
||||
import org.mozilla.gecko.R;
|
||||
import org.mozilla.gecko.tabqueue.TabQueueDispatcher;
|
||||
|
||||
import android.app.IntentService;
|
||||
import android.app.PendingIntent;
|
||||
import android.content.BroadcastReceiver;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.content.res.Resources;
|
||||
import android.content.SharedPreferences;
|
||||
@ -20,14 +19,14 @@ import android.support.v4.app.NotificationManagerCompat;
|
||||
import android.util.Log;
|
||||
|
||||
/**
|
||||
* A BroadcastReceiver that displays a notification for a tab sent to this device.
|
||||
* An IntentService 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 TabReceivedBroadcastReceiver extends BroadcastReceiver {
|
||||
private static final String LOGTAG = TabReceivedBroadcastReceiver.class.getSimpleName();
|
||||
public class TabReceivedService extends IntentService {
|
||||
private static final String LOGTAG = "Gecko" + TabReceivedService.class.getSimpleName();
|
||||
|
||||
private static final String PREF_NOTIFICATION_ID = "tab_received_notification_id";
|
||||
|
||||
@ -35,12 +34,16 @@ public class TabReceivedBroadcastReceiver extends BroadcastReceiver {
|
||||
|
||||
private static final int MAX_NOTIFICATION_COUNT = 1000;
|
||||
|
||||
public TabReceivedService() {
|
||||
super(LOGTAG);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onReceive(final Context context, final Intent intent) {
|
||||
// BroadcastReceivers don't keep the process alive so
|
||||
protected void onHandleIntent(final Intent intent) {
|
||||
// IntentServices don't keep the process alive so
|
||||
// we need to do this every time. Ideally, we wouldn't.
|
||||
final Resources res = context.getResources();
|
||||
BrowserLocaleManager.getInstance().correctLocale(context, res, res.getConfiguration());
|
||||
final Resources res = getResources();
|
||||
BrowserLocaleManager.getInstance().correctLocale(this, res, res.getConfiguration());
|
||||
|
||||
final String uri = intent.getDataString();
|
||||
if (uri == null) {
|
||||
@ -49,16 +52,16 @@ public class TabReceivedBroadcastReceiver extends BroadcastReceiver {
|
||||
}
|
||||
|
||||
final String title = intent.getStringExtra(EXTRA_TITLE);
|
||||
String notificationTitle = context.getString(R.string.sync_new_tab);
|
||||
String notificationTitle = this.getString(R.string.sync_new_tab);
|
||||
if (title != null) {
|
||||
notificationTitle = notificationTitle.concat(": " + title);
|
||||
}
|
||||
|
||||
final Intent notificationIntent = new Intent(Intent.ACTION_VIEW, intent.getData());
|
||||
notificationIntent.putExtra(TabQueueDispatcher.SKIP_TAB_QUEUE_FLAG, true);
|
||||
final PendingIntent contentIntent = PendingIntent.getActivity(context, 0, notificationIntent, 0);
|
||||
final PendingIntent contentIntent = PendingIntent.getActivity(this, 0, notificationIntent, 0);
|
||||
|
||||
final NotificationCompat.Builder builder = new NotificationCompat.Builder(context);
|
||||
final NotificationCompat.Builder builder = new NotificationCompat.Builder(this);
|
||||
builder.setSmallIcon(R.drawable.flat_icon);
|
||||
builder.setContentTitle(notificationTitle);
|
||||
builder.setWhen(System.currentTimeMillis());
|
||||
@ -66,14 +69,12 @@ public class TabReceivedBroadcastReceiver extends BroadcastReceiver {
|
||||
builder.setContentText(uri);
|
||||
builder.setContentIntent(contentIntent);
|
||||
|
||||
final SharedPreferences prefs = GeckoSharedPrefs.forApp(context);
|
||||
final SharedPreferences prefs = GeckoSharedPrefs.forApp(this);
|
||||
final int notificationId = getNextNotificationId(prefs.getInt(PREF_NOTIFICATION_ID, 0));
|
||||
final NotificationManagerCompat notificationManager = NotificationManagerCompat.from(context);
|
||||
final NotificationManagerCompat notificationManager = NotificationManagerCompat.from(this);
|
||||
notificationManager.notify(notificationId, builder.build());
|
||||
|
||||
// BroadcastReceivers do not continue async methods
|
||||
// once onReceive returns so we must commit synchronously.
|
||||
prefs.edit().putInt(PREF_NOTIFICATION_ID, notificationId).commit();
|
||||
prefs.edit().putInt(PREF_NOTIFICATION_ID, notificationId).apply();
|
||||
}
|
||||
|
||||
/**
|
Loading…
Reference in New Issue
Block a user