Skip to content

Commit

Permalink
fix: timing sync crash above Android 12
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
zzndb committed Oct 18, 2023
1 parent ac654e3 commit 3501cc9
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,11 @@ class IntentReceiver : BroadcastReceiver(), CoroutineScope by MainScope() {
context,
0,
Intent("com.osfans.trime.timing.sync"),
PendingIntent.FLAG_UPDATE_CURRENT,
if (VERSION.SDK_INT >= VERSION_CODES.M) {
PendingIntent.FLAG_UPDATE_CURRENT or PendingIntent.FLAG_IMMUTABLE
} else {
PendingIntent.FLAG_UPDATE_CURRENT
},
)
if (VERSION.SDK_INT >= VERSION_CODES.M) { // 根据SDK设置alarm任务
alarmManager.setExactAndAllowWhileIdle(
Expand Down
4 changes: 3 additions & 1 deletion app/src/main/java/com/osfans/trime/ime/core/Trime.java
Original file line number Diff line number Diff line change
Expand Up @@ -339,7 +339,9 @@ public void restartSystemStartTimingSync() { // 防止重启系统 强行停止
this,
0,
new Intent("com.osfans.trime.timing.sync"),
PendingIntent.FLAG_UPDATE_CURRENT);
VERSION.SDK_INT >= VERSION_CODES.M
? (PendingIntent.FLAG_UPDATE_CURRENT | PendingIntent.FLAG_IMMUTABLE)
: PendingIntent.FLAG_UPDATE_CURRENT);
if (VERSION.SDK_INT >= VERSION_CODES.M) { // 根据SDK设置alarm任务
alarmManager.setExactAndAllowWhileIdle(AlarmManager.RTC_WAKEUP, triggerTime, pendingIntent);
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,11 @@ class ProfileFragment :
context,
0,
Intent("com.osfans.trime.timing.sync"),
PendingIntent.FLAG_UPDATE_CURRENT,
if (VERSION.SDK_INT >= VERSION_CODES.M) {
PendingIntent.FLAG_UPDATE_CURRENT or PendingIntent.FLAG_IMMUTABLE
} else {
PendingIntent.FLAG_UPDATE_CURRENT
},
)
val cal = Calendar.getInstance()
if (get<SwitchPreferenceCompat>("profile_timing_sync")?.isChecked == true) { // 当定时同步偏好打开时
Expand Down

0 comments on commit 3501cc9

Please sign in to comment.