diff --git a/res/drawable-hdpi/ic_signal_downloading.png b/res/drawable-hdpi/ic_signal_downloading.png new file mode 100644 index 0000000000..ed2cf389a2 Binary files /dev/null and b/res/drawable-hdpi/ic_signal_downloading.png differ diff --git a/res/drawable-mdpi/ic_signal_downloading.png b/res/drawable-mdpi/ic_signal_downloading.png new file mode 100644 index 0000000000..02784ab3fc Binary files /dev/null and b/res/drawable-mdpi/ic_signal_downloading.png differ diff --git a/res/drawable-xhdpi/ic_signal_downloading.png b/res/drawable-xhdpi/ic_signal_downloading.png new file mode 100644 index 0000000000..f04e093f9c Binary files /dev/null and b/res/drawable-xhdpi/ic_signal_downloading.png differ diff --git a/res/drawable-xxhdpi/ic_signal_downloading.png b/res/drawable-xxhdpi/ic_signal_downloading.png new file mode 100644 index 0000000000..fa111e0a6f Binary files /dev/null and b/res/drawable-xxhdpi/ic_signal_downloading.png differ diff --git a/res/drawable-xxxhdpi/ic_signal_downloading.png b/res/drawable-xxxhdpi/ic_signal_downloading.png new file mode 100644 index 0000000000..188a654e05 Binary files /dev/null and b/res/drawable-xxxhdpi/ic_signal_downloading.png differ diff --git a/src/org/thoughtcrime/securesms/gcm/GcmBroadcastReceiver.java b/src/org/thoughtcrime/securesms/gcm/GcmBroadcastReceiver.java index 34c78818aa..7f57b6193d 100644 --- a/src/org/thoughtcrime/securesms/gcm/GcmBroadcastReceiver.java +++ b/src/org/thoughtcrime/securesms/gcm/GcmBroadcastReceiver.java @@ -3,6 +3,7 @@ package org.thoughtcrime.securesms.gcm; import android.content.Context; import android.content.Intent; import android.os.PowerManager; +import android.support.annotation.NonNull; import android.support.v4.content.WakefulBroadcastReceiver; import android.text.TextUtils; @@ -16,6 +17,7 @@ import com.google.android.gms.gcm.GoogleCloudMessaging; import org.thoughtcrime.securesms.ApplicationContext; import org.thoughtcrime.securesms.jobs.PushContentReceiveJob; import org.thoughtcrime.securesms.jobs.PushNotificationReceiveJob; +import org.thoughtcrime.securesms.notifications.NotificationChannels; import org.thoughtcrime.securesms.service.GenericForegroundService; import org.thoughtcrime.securesms.util.PowerManagerCompat; import org.thoughtcrime.securesms.util.TextSecurePreferences; @@ -87,7 +89,7 @@ public class GcmBroadcastReceiver extends WakefulBroadcastReceiver implements In if (doze || !network) { Log.i(TAG, "Starting a foreground task because we may be operating in a constrained environment. Doze: " + doze + " Network: " + network); - GenericForegroundService.startForegroundTask(context, context.getString(R.string.GcmBroadcastReceiver_retrieving_a_message)); + showForegroundNotification(context); foregroundRunning.set(true); callback.finish(); } @@ -123,7 +125,7 @@ public class GcmBroadcastReceiver extends WakefulBroadcastReceiver implements In synchronized (foregroundLock) { if (!taskCompleted.get() && !foregroundRunning.getAndSet(true)) { Log.i(TAG, "Starting a foreground task because the job is running long."); - GenericForegroundService.startForegroundTask(context, context.getString(R.string.GcmBroadcastReceiver_retrieving_a_message)); + showForegroundNotification(context); callback.finish(); } } @@ -132,6 +134,13 @@ public class GcmBroadcastReceiver extends WakefulBroadcastReceiver implements In } } + private void showForegroundNotification(@NonNull Context context) { + GenericForegroundService.startForegroundTask(context, + context.getString(R.string.GcmBroadcastReceiver_retrieving_a_message), + NotificationChannels.OTHER, + R.drawable.ic_signal_downloading); + } + private static synchronized boolean incrementActiveGcmCount() { if (activeCount < 2) { activeCount++; diff --git a/src/org/thoughtcrime/securesms/service/GenericForegroundService.java b/src/org/thoughtcrime/securesms/service/GenericForegroundService.java index f6ea036cd1..f2c02d2f13 100644 --- a/src/org/thoughtcrime/securesms/service/GenericForegroundService.java +++ b/src/org/thoughtcrime/securesms/service/GenericForegroundService.java @@ -6,6 +6,7 @@ import android.app.Service; import android.content.Context; import android.content.Intent; import android.os.IBinder; +import android.support.annotation.DrawableRes; import android.support.annotation.NonNull; import android.support.annotation.Nullable; import android.support.v4.app.NotificationCompat; @@ -24,6 +25,7 @@ public class GenericForegroundService extends Service { private static final int NOTIFICATION_ID = 827353982; private static final String EXTRA_TITLE = "extra_title"; private static final String EXTRA_CHANNEL_ID = "extra_channel_id"; + private static final String EXTRA_ICON_RES = "extra_icon_res"; private static final String ACTION_START = "start"; private static final String ACTION_STOP = "stop"; @@ -31,6 +33,7 @@ public class GenericForegroundService extends Service { private int foregroundCount; private String activeTitle; private String activeChannelId; + private int activeIconRes; @Override public void onCreate() { @@ -52,6 +55,7 @@ public class GenericForegroundService extends Service { private void handleStart(@NonNull Intent intent) { String title = Preconditions.checkNotNull(intent.getStringExtra(EXTRA_TITLE)); String channelId = Preconditions.checkNotNull(intent.getStringExtra(EXTRA_CHANNEL_ID)); + int iconRes = intent.getIntExtra(EXTRA_ICON_RES, R.drawable.ic_signal_grey_24dp); foregroundCount++; @@ -59,13 +63,14 @@ public class GenericForegroundService extends Service { Log.d(TAG, "First request. Title: " + title + " ChannelId: " + channelId); activeTitle = title; activeChannelId = channelId; + activeIconRes = iconRes; } - postObligatoryForegroundNotification(activeTitle, activeChannelId); + postObligatoryForegroundNotification(activeTitle, activeChannelId, activeIconRes); } private void handleStop() { - postObligatoryForegroundNotification(activeTitle, activeChannelId); + postObligatoryForegroundNotification(activeTitle, activeChannelId, activeIconRes); foregroundCount--; @@ -76,9 +81,9 @@ public class GenericForegroundService extends Service { } } - private void postObligatoryForegroundNotification(String title, String channelId) { + private void postObligatoryForegroundNotification(String title, String channelId, @DrawableRes int iconRes) { startForeground(NOTIFICATION_ID, new NotificationCompat.Builder(this, channelId) - .setSmallIcon(R.drawable.ic_signal_grey_24dp) + .setSmallIcon(iconRes) .setContentTitle(title) .setContentIntent(PendingIntent.getActivity(this, 0, new Intent(this, ConversationListActivity.class), 0)) .build()); @@ -95,10 +100,15 @@ public class GenericForegroundService extends Service { } public static void startForegroundTask(@NonNull Context context, @NonNull String task, @NonNull String channelId) { + startForegroundTask(context, task, channelId, R.drawable.ic_signal_grey_24dp); + } + + public static void startForegroundTask(@NonNull Context context, @NonNull String task, @NonNull String channelId, @DrawableRes int iconRes) { Intent intent = new Intent(context, GenericForegroundService.class); intent.setAction(ACTION_START); intent.putExtra(EXTRA_TITLE, task); intent.putExtra(EXTRA_CHANNEL_ID, channelId); + intent.putExtra(EXTRA_ICON_RES, iconRes); ContextCompat.startForegroundService(context, intent); }