Bug 882136 - Remove notifications created by NotificationHelper when Fennec is killed. r=lucasr

This commit is contained in:
Wes Johnston 2013-06-19 13:29:48 -07:00
Родитель 1f86f35684
Коммит 5fe6767477
2 изменённых файлов: 39 добавлений и 2 удалений

Просмотреть файл

@ -1749,6 +1749,11 @@ abstract public class GeckoApp
alertCookie = "";
}
handleNotification(ACTION_ALERT_CALLBACK, alertName, alertCookie);
if (intent.hasExtra(NotificationHelper.NOTIFICATION_ID)) {
String id = intent.getStringExtra(NotificationHelper.NOTIFICATION_ID);
mNotificationHelper.hideNotification(id);
}
}
@Override
@ -1991,6 +1996,8 @@ abstract public class GeckoApp
if (mTextSelection != null)
mTextSelection.destroy();
SiteIdentityPopup.clearInstance();
if (mNotificationHelper != null)
mNotificationHelper.destroy();
Tabs.getInstance().detachFromActivity(this);

Просмотреть файл

@ -21,12 +21,18 @@ import android.net.Uri;
import android.support.v4.app.NotificationCompat;
import android.util.Log;
import java.util.Set;
import java.util.HashSet;
public class NotificationHelper implements GeckoEventListener {
public static final String NOTIFICATION_ID = "NotificationHelper_ID";
private static final String LOGTAG = "GeckoNotificationManager";
private Context mContext;
private Context mContext;
private Set<String> mShowing;
public NotificationHelper(Context context) {
mContext = context;
mShowing = new HashSet<String>();
registerEventListener("Notification:Show");
registerEventListener("Notification:Hide");
}
@ -48,7 +54,7 @@ public class NotificationHelper implements GeckoEventListener {
NotificationCompat.Builder builder = new NotificationCompat.Builder(mContext);
// These attributes are required
String id;
final String id;
try {
builder.setContentTitle(message.getString("title"));
builder.setContentText(message.getString("text"));
@ -91,12 +97,20 @@ public class NotificationHelper implements GeckoEventListener {
String app = mContext.getClass().getName();
notificationIntent.setClassName(AppConstants.ANDROID_PACKAGE_NAME, app);
notificationIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
// if this isn't an ongoing notification, add the id to the intent so that we
// can remove the notification from our list of active notifications if its clicked
if (!ongoing) {
notificationIntent.putExtra(NOTIFICATION_ID, id);
}
PendingIntent pi = PendingIntent.getActivity(mContext, 0, notificationIntent, 0);
builder.setContentIntent(pi);
NotificationManager manager = (NotificationManager) mContext.getSystemService(Context.NOTIFICATION_SERVICE);
manager.notify(id.hashCode(), builder.build());
if (!mShowing.contains(id)) {
mShowing.add(id);
}
}
private void hideNotification(JSONObject message) {
@ -107,7 +121,23 @@ public class NotificationHelper implements GeckoEventListener {
Log.i(LOGTAG, "Error parsing", ex);
return;
}
hideNotification(id);
}
public void hideNotification(String id) {
NotificationManager manager = (NotificationManager) mContext.getSystemService(Context.NOTIFICATION_SERVICE);
manager.cancel(id.hashCode());
mShowing.remove(id);
}
private void clearAll() {
for (String id : mShowing) {
hideNotification(id);
}
}
public void destroy() {
clearAll();
}
}