Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -129,17 +129,21 @@ private PendingIntent getPendingIntent(Context context, IterableNotificationData
buttonIntent.putExtra(IterableConstants.ITERABLE_DATA_ACTION_IDENTIFIER, button.identifier);
buttonIntent.putExtra(IterableConstants.ACTION_IDENTIFIER, button.identifier);

int pendingIntentFlag = button.buttonType.equals(IterableNotificationData.Button.BUTTON_TYPE_TEXT_INPUT) ?
PendingIntent.FLAG_UPDATE_CURRENT | PendingIntent.FLAG_MUTABLE :
PendingIntent.FLAG_UPDATE_CURRENT | PendingIntent.FLAG_IMMUTABLE;

if (button.openApp) {
IterableLogger.d(TAG, "Go through TrampolineActivity");
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, pendingIntentFlag);
} 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, pendingIntentFlag);
}

return pendingButtonIntent;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -93,18 +93,34 @@ public void testNoAction() throws Exception {
}

@Test
public void testPendingIntentImmutable() throws Exception {
public void testPendingIntentFlags() 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);
// Test contentIntent (default action)
int contentIntentFlags = shadowOf(notification.contentIntent).getFlags();
assertTrue((contentIntentFlags & PendingIntent.FLAG_UPDATE_CURRENT) != 0);
assertTrue((contentIntentFlags & PendingIntent.FLAG_IMMUTABLE) != 0); // Should be immutable for default action

// Test deeplink button (default type, openApp=true)
int deeplinkButtonFlags = shadowOf(notification.actions[0].actionIntent).getFlags();
assertTrue((deeplinkButtonFlags & PendingIntent.FLAG_UPDATE_CURRENT) != 0);
assertTrue((deeplinkButtonFlags & PendingIntent.FLAG_IMMUTABLE) != 0); // Should be immutable for default type

// Test silent action button (default type, openApp=false)
int silentActionFlags = shadowOf(notification.actions[1].actionIntent).getFlags();
assertTrue((silentActionFlags & PendingIntent.FLAG_UPDATE_CURRENT) != 0);
assertTrue((silentActionFlags & PendingIntent.FLAG_IMMUTABLE) != 0); // Should be immutable for default type

// Test text input button
int textInputFlags = shadowOf(notification.actions[2].actionIntent).getFlags();
assertTrue((textInputFlags & PendingIntent.FLAG_UPDATE_CURRENT) != 0);
assertTrue((textInputFlags & PendingIntent.FLAG_MUTABLE) != 0); // Should be mutable for text input

}

}
Loading