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

[MOB-9897] Feature/changes needed for notification #817

Closed
wants to merge 10 commits into from
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import android.content.Context;
import android.os.AsyncTask;
import android.os.Bundle;

import androidx.annotation.NonNull;

import com.google.android.gms.tasks.Tasks;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.os.Bundle;

import androidx.core.app.NotificationCompat;
import androidx.core.app.RemoteInput;

Expand Down Expand Up @@ -134,12 +135,12 @@ private PendingIntent getPendingIntent(Context context, IterableNotificationData
buttonIntent.setClass(context, IterableTrampolineActivity.class);
buttonIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK);
pendingButtonIntent = PendingIntent.getActivity(context, buttonIntent.hashCode(),
buttonIntent, PendingIntent.FLAG_UPDATE_CURRENT | PendingIntent.FLAG_IMMUTABLE);
buttonIntent, PendingIntent.FLAG_UPDATE_CURRENT | PendingIntent.FLAG_MUTABLE);
} else {
IterableLogger.d(TAG, "Go through IterablePushActionReceiver");
buttonIntent.setClass(context, IterablePushActionReceiver.class);
pendingButtonIntent = PendingIntent.getBroadcast(context, buttonIntent.hashCode(),
buttonIntent, PendingIntent.FLAG_UPDATE_CURRENT | PendingIntent.FLAG_IMMUTABLE);
buttonIntent, PendingIntent.FLAG_UPDATE_CURRENT | PendingIntent.FLAG_MUTABLE);
}

return pendingButtonIntent;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,7 @@ public IterableNotificationBuilder createNotification(Context context, Bundle ex
}

PendingIntent notificationClickedIntent = PendingIntent.getActivity(context, notificationBuilder.requestCode,
trampolineActivityIntent, PendingIntent.FLAG_UPDATE_CURRENT | PendingIntent.FLAG_IMMUTABLE);
trampolineActivityIntent, PendingIntent.FLAG_UPDATE_CURRENT | PendingIntent.FLAG_MUTABLE);

notificationBuilder.setContentIntent(notificationClickedIntent);
notificationBuilder.setIsGhostPush(isGhostPush(extras));
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
package com.iterable.iterableapi;

import static com.iterable.iterableapi.IterableTestUtils.getResourceString;
import static junit.framework.Assert.assertEquals;
import static junit.framework.Assert.assertTrue;
import static org.robolectric.Shadows.shadowOf;

import android.app.Notification;
import android.app.NotificationManager;
import android.app.PendingIntent;
Expand All @@ -19,11 +24,6 @@
import org.robolectric.RobolectricTestRunner;
import org.robolectric.shadows.ShadowPendingIntent;

import static com.iterable.iterableapi.IterableTestUtils.getResourceString;
import static junit.framework.Assert.assertEquals;
import static junit.framework.Assert.assertTrue;
import static org.robolectric.Shadows.shadowOf;

@RunWith(RobolectricTestRunner.class)
public class IterableNotificationTest {

Expand Down Expand Up @@ -93,18 +93,18 @@ public void testNoAction() throws Exception {
}

@Test
public void testPendingIntentImmutable() throws Exception {
public void testPendingIntentMutable() throws Exception {
Bundle notif = new Bundle();
notif.putString(IterableConstants.ITERABLE_DATA_KEY, getResourceString("push_payload_action_buttons.json"));

IterableNotificationBuilder iterableNotification = postNotification(notif);
StatusBarNotification statusBarNotification = mNotificationManager.getActiveNotifications()[0];
Notification notification = statusBarNotification.getNotification();

assertTrue((shadowOf(notification.contentIntent).getFlags() & PendingIntent.FLAG_IMMUTABLE) != 0);
assertTrue((shadowOf(notification.actions[0].actionIntent).getFlags() & PendingIntent.FLAG_IMMUTABLE) != 0);
assertTrue((shadowOf(notification.actions[1].actionIntent).getFlags() & PendingIntent.FLAG_IMMUTABLE) != 0);
assertTrue((shadowOf(notification.actions[2].actionIntent).getFlags() & PendingIntent.FLAG_IMMUTABLE) != 0);
assertTrue((shadowOf(notification.contentIntent).getFlags() & PendingIntent.FLAG_MUTABLE) != 0);
assertTrue((shadowOf(notification.actions[0].actionIntent).getFlags() & PendingIntent.FLAG_MUTABLE) != 0);
assertTrue((shadowOf(notification.actions[1].actionIntent).getFlags() & PendingIntent.FLAG_MUTABLE) != 0);
assertTrue((shadowOf(notification.actions[2].actionIntent).getFlags() & PendingIntent.FLAG_MUTABLE) != 0);
}

}
Loading