Skip to content

Commit a1e1dca

Browse files
authored
added pending intent mutability (#3811)
1 parent a2502fe commit a1e1dca

File tree

1 file changed

+13
-2
lines changed
  • transport/transport-runtime/src/main/java/com/google/android/datatransport/runtime/scheduling/jobscheduling

1 file changed

+13
-2
lines changed

transport/transport-runtime/src/main/java/com/google/android/datatransport/runtime/scheduling/jobscheduling/AlarmManagerScheduler.java

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
import android.content.Context;
2020
import android.content.Intent;
2121
import android.net.Uri;
22+
import android.os.Build;
2223
import android.util.Base64;
2324
import androidx.annotation.VisibleForTesting;
2425
import com.google.android.datatransport.runtime.TransportContext;
@@ -74,7 +75,12 @@ public AlarmManagerScheduler(
7475

7576
@VisibleForTesting
7677
boolean isJobServiceOn(Intent intent) {
77-
return (PendingIntent.getBroadcast(context, 0, intent, PendingIntent.FLAG_NO_CREATE) != null);
78+
int flags =
79+
Build.VERSION.SDK_INT >= Build.VERSION_CODES.M
80+
? PendingIntent.FLAG_NO_CREATE | PendingIntent.FLAG_IMMUTABLE
81+
: PendingIntent.FLAG_NO_CREATE;
82+
83+
return (PendingIntent.getBroadcast(context, 0, intent, flags) != null);
7884
}
7985

8086
@Override
@@ -121,7 +127,12 @@ public void schedule(TransportContext transportContext, int attemptNumber, boole
121127
backendTime,
122128
attemptNumber);
123129

124-
PendingIntent pendingIntent = PendingIntent.getBroadcast(context, 0, intent, 0);
130+
PendingIntent pendingIntent =
131+
PendingIntent.getBroadcast(
132+
context,
133+
0,
134+
intent,
135+
Build.VERSION.SDK_INT >= Build.VERSION_CODES.M ? PendingIntent.FLAG_IMMUTABLE : 0);
125136
this.alarmManager.set(
126137
AlarmManager.ELAPSED_REALTIME, clock.getTime() + scheduleDelay, pendingIntent);
127138
}

0 commit comments

Comments
 (0)