Skip to content

Commit 3501cc9

Browse files
committed
fix: timing sync crash above Android 12
We need explicitly specify the mutability of PendingIntent above Android 12 and it's better to use immutable flag (added in API level 23, M) as we just use the intent directly.
1 parent ac654e3 commit 3501cc9

File tree

3 files changed

+13
-3
lines changed

3 files changed

+13
-3
lines changed

app/src/main/java/com/osfans/trime/ime/broadcast/IntentReceiver.kt

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,11 @@ class IntentReceiver : BroadcastReceiver(), CoroutineScope by MainScope() {
7272
context,
7373
0,
7474
Intent("com.osfans.trime.timing.sync"),
75-
PendingIntent.FLAG_UPDATE_CURRENT,
75+
if (VERSION.SDK_INT >= VERSION_CODES.M) {
76+
PendingIntent.FLAG_UPDATE_CURRENT or PendingIntent.FLAG_IMMUTABLE
77+
} else {
78+
PendingIntent.FLAG_UPDATE_CURRENT
79+
},
7680
)
7781
if (VERSION.SDK_INT >= VERSION_CODES.M) { // 根据SDK设置alarm任务
7882
alarmManager.setExactAndAllowWhileIdle(

app/src/main/java/com/osfans/trime/ime/core/Trime.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -339,7 +339,9 @@ public void restartSystemStartTimingSync() { // 防止重启系统 强行停止
339339
this,
340340
0,
341341
new Intent("com.osfans.trime.timing.sync"),
342-
PendingIntent.FLAG_UPDATE_CURRENT);
342+
VERSION.SDK_INT >= VERSION_CODES.M
343+
? (PendingIntent.FLAG_UPDATE_CURRENT | PendingIntent.FLAG_IMMUTABLE)
344+
: PendingIntent.FLAG_UPDATE_CURRENT);
343345
if (VERSION.SDK_INT >= VERSION_CODES.M) { // 根据SDK设置alarm任务
344346
alarmManager.setExactAndAllowWhileIdle(AlarmManager.RTC_WAKEUP, triggerTime, pendingIntent);
345347
} else {

app/src/main/java/com/osfans/trime/ui/fragments/ProfileFragment.kt

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,11 @@ class ProfileFragment :
114114
context,
115115
0,
116116
Intent("com.osfans.trime.timing.sync"),
117-
PendingIntent.FLAG_UPDATE_CURRENT,
117+
if (VERSION.SDK_INT >= VERSION_CODES.M) {
118+
PendingIntent.FLAG_UPDATE_CURRENT or PendingIntent.FLAG_IMMUTABLE
119+
} else {
120+
PendingIntent.FLAG_UPDATE_CURRENT
121+
},
118122
)
119123
val cal = Calendar.getInstance()
120124
if (get<SwitchPreferenceCompat>("profile_timing_sync")?.isChecked == true) { // 当定时同步偏好打开时

0 commit comments

Comments
 (0)