Skip to content

Commit e1fe640

Browse files
authored
Fix warning about using flag on API level < 23 (#4321)
1 parent 6732593 commit e1fe640

File tree

1 file changed

+9
-17
lines changed

1 file changed

+9
-17
lines changed

firebase-appdistribution/src/main/java/com/google/firebase/appdistribution/impl/FirebaseAppDistributionNotificationsManager.java

Lines changed: 9 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -112,21 +112,16 @@ private PendingIntent createAppLaunchIntent() {
112112
LogWrapper.getInstance().w(TAG, "No activity found to launch app");
113113
return null;
114114
}
115-
return PendingIntent.getActivity(
116-
context, 0, intent, getPendingIntentFlags(PendingIntent.FLAG_ONE_SHOT));
115+
return getPendingIntent(intent, PendingIntent.FLAG_ONE_SHOT);
117116
}
118117

119-
/**
120-
* Adds {@link PendingIntent#FLAG_IMMUTABLE} to a PendingIntent's flags since any PendingIntents
121-
* used here don't need to be modified.
122-
*
123-
* <p>Specifying mutability is required starting at SDK level 31.
124-
*/
125-
private static int getPendingIntentFlags(int baseFlags) {
126-
// Only add on platform levels that support FLAG_IMMUTABLE.
127-
return Build.VERSION.SDK_INT >= Build.VERSION_CODES.M
128-
? baseFlags | PendingIntent.FLAG_IMMUTABLE
129-
: baseFlags;
118+
private PendingIntent getPendingIntent(Intent intent, int extraFlags) {
119+
// Specify mutability because it is required starting at SDK level 31, but FLAG_IMMUTABLE is
120+
// only supported starting at SDK level 23
121+
int commonFlags =
122+
Build.VERSION.SDK_INT >= Build.VERSION_CODES.M ? PendingIntent.FLAG_IMMUTABLE : 0;
123+
return PendingIntent.getActivity(
124+
context, /* requestCode = */ 0, intent, extraFlags | commonFlags);
130125
}
131126

132127
public void showFeedbackNotification(
@@ -151,9 +146,6 @@ public void showFeedbackNotification(
151146
Intent intent = new Intent(context, TakeScreenshotAndStartFeedbackActivity.class);
152147
intent.addFlags(Intent.FLAG_ACTIVITY_NO_HISTORY);
153148
intent.putExtra(TakeScreenshotAndStartFeedbackActivity.INFO_TEXT_EXTRA_KEY, infoText);
154-
PendingIntent pendingIntent =
155-
PendingIntent.getActivity(
156-
context, /* requestCode = */ 0, intent, PendingIntent.FLAG_IMMUTABLE);
157149
ApplicationInfo applicationInfo = context.getApplicationInfo();
158150
PackageManager packageManager = context.getPackageManager();
159151
CharSequence appLabel = packageManager.getApplicationLabel(applicationInfo);
@@ -166,7 +158,7 @@ public void showFeedbackNotification(
166158
.setOngoing(true)
167159
.setOnlyAlertOnce(true)
168160
.setAutoCancel(false)
169-
.setContentIntent(pendingIntent);
161+
.setContentIntent(getPendingIntent(intent, /* extraFlags= */ 0));
170162
LogWrapper.getInstance().i(TAG, "Showing feedback notification");
171163
notificationManager.notify(
172164
Notification.FEEDBACK.tag, Notification.FEEDBACK.id, builder.build());

0 commit comments

Comments
 (0)